Skip to content

Commit

Permalink
Add H5vccSystem web interface, set it as window.h5vcc.system (#4763)
Browse files Browse the repository at this point in the history
The readonly property advertisingId return a dummy value.

// command to compile all web tests
cobalt/build/gn.py -p linux-x64x11 -C devel && \
autoninja -C out/linux-x64x11_devel blink_wpt_tests && \
autoninja -C out/linux-x64x11_devel dump_syms && \
autoninja -C out/linux-x64x11_devel minidump_stackwalk

// command to run the test
third_party/blink/tools/run_web_tests.py -t linux-x64x11_devel
external/wpt/cobalt/h5vcc-system

b/377049113
  • Loading branch information
zhongqiliang authored Jan 28, 2025
2 parents 1b4f3c1 + 09c7b14 commit 93aa24d
Show file tree
Hide file tree
Showing 14 changed files with 164 additions and 12 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ files: |
media/base/starboard/|
media/starboard/|
starboard/|
third_party/blink/renderer/modules/cobalt/|
components/viz/service/display/starboard/|
ui/ozone/platform/starboard/|
.pre-commit-config.yaml|
Expand Down
2 changes: 2 additions & 0 deletions third_party/blink/renderer/bindings/generated_in_modules.gni
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
Expand Up @@ -42,11 +42,9 @@ ScriptPromise CrashAnnotator::setString(ScriptState* script_state,
EnsureReceiverIsBound();

remote_crash_annotator_->SetString(
key,
value,
WTF::BindOnce(
&CrashAnnotator::OnSetString,
WrapPersistent(this), WrapPersistent(resolver)));
key, value,
WTF::BindOnce(&CrashAnnotator::OnSetString, WrapPersistent(this),
WrapPersistent(resolver)));

return resolver->Promise();
}
Expand Down
22 changes: 22 additions & 0 deletions third_party/blink/renderer/modules/cobalt/h5vcc_system/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 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.

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,36 @@
// 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.

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

#include "third_party/blink/renderer/core/frame/local_dom_window.h"

namespace blink {

H5vccSystem::H5vccSystem(LocalDOMWindow& window) {}

const String H5vccSystem::advertisingId() const {
NOTIMPLEMENTED();

// TODO(b/377049113) add a mojom service and populate the value for
// advertising_id_.
// return advertising_id_;
return String("fake advertisingId");
}

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

} // namespace blink
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// 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.

#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_H5VCC_SYSTEM_H_5_VCC_SYSTEM_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_H5VCC_SYSTEM_H_5_VCC_SYSTEM_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/wtf/text/wtf_string.h"

namespace blink {

class LocalDOMWindow;
class ScriptState;

class MODULES_EXPORT H5vccSystem final : public ScriptWrappable {
DEFINE_WRAPPERTYPEINFO();

public:
explicit H5vccSystem(LocalDOMWindow&);

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

void Trace(Visitor*) const override;
};

} // namespace blink

#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_H5VCC_SYSTEM_H_5_VCC_SYSTEM_H_
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 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.

// This interface mirrors the H5vccSystem Web IDL defined in Cobalt LTS 25:
// https://github.com/youtube/cobalt/blob/25.lts.stable/cobalt/h5vcc/h5vcc_system.idl
[
Exposed=Window,
SecureContext
]
interface H5vccSystem {
readonly attribute DOMString advertisingId;
};
7 changes: 5 additions & 2 deletions third_party/blink/renderer/modules/cobalt/h_5_vcc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@

#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 {

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

//static
// static
H5vcc* H5vcc::h5vcc(LocalDOMWindow& window) {
H5vcc* h5vcc = Supplement<LocalDOMWindow>::From<H5vcc>(window);
if (!h5vcc && window.GetExecutionContext()) {
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)),
system_(MakeGarbageCollected<H5vccSystem>(window)) {}

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

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

public:
Expand All @@ -43,12 +43,15 @@ class MODULES_EXPORT H5vcc final

CrashAnnotator* crashAnnotator() { return crash_annotator_; }

H5vccSystem* system() { return system_; }

void Trace(Visitor*) const override;

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

}
} // namespace blink

#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_COBALT_H_5_VCC_H_
3 changes: 3 additions & 0 deletions third_party/blink/renderer/modules/cobalt/h_5_vcc.idl
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// This interface mirrors the H5vcc Web IDL defined in Cobalt LTS 25:
// https://github.com/youtube/cobalt/blob/25.lts.stable/cobalt/h5vcc/h5vcc.idl
[
Exposed=Window,
SecureContext
]
interface H5vcc {
readonly attribute CrashAnnotator crashAnnotator;
readonly attribute H5vccSystem system;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test H5vccSystem web API.</title>
<script src='/resources/testharness.js'></script>
<script src='/resources/testharnessreport.js'></script>
</head>
<body>
<script>
test(() => {
assert_equals(window.h5vcc.system.advertisingId, "fake advertisingId");
}, "H5vccSystem has the right property value");
</script>
</body>
</html>

0 comments on commit 93aa24d

Please sign in to comment.