Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add H5vccSystem web interface, set window.h5vcc.h5vccSystem object #4764

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2797,6 +2797,8 @@ if (is_cobalt) {
"$root_gen_dir/third_party/blink/renderer/bindings/modules/v8/v8_crash_annotator.h",
"$root_gen_dir/third_party/blink/renderer/bindings/modules/v8/v8_h_5_vcc.cc",
"$root_gen_dir/third_party/blink/renderer/bindings/modules/v8/v8_h_5_vcc.h",
"$root_gen_dir/third_party/blink/renderer/bindings/modules/v8/v8_h_5_vcc_system.cc",
"$root_gen_dir/third_party/blink/renderer/bindings/modules/v8/v8_h_5_vcc_system.h",
]
}

Expand Down
1 change: 1 addition & 0 deletions third_party/blink/renderer/bindings/idl_in_modules.gni
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,7 @@ if (is_cobalt) {
"//third_party/blink/renderer/modules/cobalt/crash_annotator/crash_annotator.idl",
"//third_party/blink/renderer/modules/cobalt/h_5_vcc.idl",
"//third_party/blink/renderer/modules/cobalt/window_h_5_vcc.idl",
"//third_party/blink/renderer/modules/cobalt/h5vcc_system/h_5_vcc_system.idl",
],
"abspath")
}
Expand Down
1 change: 1 addition & 0 deletions third_party/blink/renderer/modules/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ component("modules") {
sub_modules += [
"//third_party/blink/renderer/modules/cobalt:h_5_vcc",
"//third_party/blink/renderer/modules/cobalt/crash_annotator",
"//third_party/blink/renderer/modules/cobalt/h5vcc_system",
]
}

Expand Down
5 changes: 4 additions & 1 deletion third_party/blink/renderer/modules/cobalt/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@ blink_modules_sources("h_5_vcc") {
"h_5_vcc.cc",
"h_5_vcc.h",
]
deps = ["//third_party/blink/renderer/modules/cobalt/crash_annotator"]
deps = [
"//third_party/blink/renderer/modules/cobalt/crash_annotator",
"//third_party/blink/renderer/modules/cobalt/h5vcc_system",
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import("//third_party/blink/renderer/modules/modules.gni")
blink_modules_sources("h5vcc_system") {
sources = [
"h_5_vcc_system.cc",
"h_5_vcc_system.h",
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright 2024 The Cobalt Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "third_party/blink/renderer/modules/cobalt/h5vcc_system/h_5_vcc_system.h"

#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"

namespace blink {

// static
const char H5vccSystem::kSupplementName[] = "H5vccSystem";

//static
H5vccSystem* H5vccSystem::h5vccSystem(LocalDOMWindow& window) {
H5vccSystem* h5vccSystem = Supplement<LocalDOMWindow>::From<H5vccSystem>(window);
if (!h5vccSystem && window.GetExecutionContext()) {
h5vccSystem = MakeGarbageCollected<H5vccSystem>(window);
}
return h5vccSystem;
}

H5vccSystem::H5vccSystem(LocalDOMWindow& window)
: Supplement<LocalDOMWindow>(window),
ExecutionContextLifecycleObserver(window.GetExecutionContext()) {}

void H5vccSystem::ContextDestroyed() {}

const String H5vccSystem::advertisingId() const {
// TODO populate the value here.
// return advertising_id_;
return String("fake advertisingId");
}

void H5vccSystem::Trace(Visitor* visitor) const {
ExecutionContextLifecycleObserver::Trace(visitor);
ScriptWrappable::Trace(visitor);
}

} // namespace blink
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright 2024 The Cobalt Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_H_5_VCC_SYSTEM_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_H_5_VCC_SYSTEM_H_

#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/core/execution_context/execution_context_lifecycle_observer.h"
#include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "third_party/blink/renderer/platform/mojo/heap_mojo_receiver.h"
#include "third_party/blink/renderer/platform/mojo/heap_mojo_remote.h"
#include "third_party/blink/renderer/platform/mojo/heap_mojo_wrapper_mode.h"
#include "third_party/blink/renderer/platform/supplementable.h"

namespace blink {

class ExecutionContext;
class LocalDOMWindow;
class ScriptPromiseResolver;
class ScriptState;

class MODULES_EXPORT H5vccSystem final
: public ScriptWrappable,
public Supplement<LocalDOMWindow>,
public ExecutionContextLifecycleObserver {
DEFINE_WRAPPERTYPEINFO();

public:
static const char kSupplementName[];

// For window.h5vccSystem
static H5vccSystem* h5vccSystem(LocalDOMWindow&);

explicit H5vccSystem(LocalDOMWindow&);

void ContextDestroyed() override;

// Web-exposed interface:
const String advertisingId() const;

void Trace(Visitor*) const override;

private:
String advertising_id_;
};

} // namespace blink

#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_H_5_VCC_SYSTEM_H_
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2025 The Cobalt Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

[
Exposed=Window,
SecureContext
]
interface H5vccSystem {
readonly attribute DOMString advertisingId;
};
5 changes: 4 additions & 1 deletion third_party/blink/renderer/modules/cobalt/h_5_vcc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/modules/cobalt/crash_annotator/crash_annotator.h"
#include "third_party/blink/renderer/modules/cobalt/h5vcc_system/h_5_vcc_system.h"

namespace blink {

Expand All @@ -34,10 +35,12 @@ H5vcc* H5vcc::h5vcc(LocalDOMWindow& window) {

H5vcc::H5vcc(LocalDOMWindow& window)
: Supplement<LocalDOMWindow>(window),
crash_annotator_(MakeGarbageCollected<CrashAnnotator>(window)) {}
crash_annotator_(MakeGarbageCollected<CrashAnnotator>(window)),
h5vcc_system_(MakeGarbageCollected<H5vccSystem>(window)) {}

void H5vcc::Trace(Visitor* visitor) const {
visitor->Trace(crash_annotator_);
visitor->Trace(h5vcc_system_);
Supplement<LocalDOMWindow>::Trace(visitor);
ScriptWrappable::Trace(visitor);
}
Expand Down
4 changes: 4 additions & 0 deletions third_party/blink/renderer/modules/cobalt/h_5_vcc.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace blink {
class ScriptState;
class CrashAnnotator;
class LocalDOMWindow;
class H5vccSystem;

class MODULES_EXPORT H5vcc final
: public ScriptWrappable,
Expand All @@ -43,10 +44,13 @@ class MODULES_EXPORT H5vcc final

CrashAnnotator* crashAnnotator() { return crash_annotator_; }

H5vccSystem* h5vccSystem() { return h5vcc_system_; }

void Trace(Visitor*) const override;

private:
Member<CrashAnnotator> crash_annotator_;
Member<H5vccSystem> h5vcc_system_;
};

}
Expand Down
1 change: 1 addition & 0 deletions third_party/blink/renderer/modules/cobalt/h_5_vcc.idl
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
]
interface H5vcc {
readonly attribute CrashAnnotator crashAnnotator;
readonly attribute H5vccSystem h5vccSystem;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test h5vcc_system web API.</title>
<script src='/resources/testharness.js'></script>
<script src='/resources/testharnessreport.js'></script>
</head>
<body>
<script>
test(() => {
assert_equals(window.h5vcc.h5vccSystem.advertisingId, "fake advertisingId");
}, "h5vccSystem has the right property value");
</script>
</body>
</html>
Loading