Skip to content

Commit 7bbf2ef

Browse files
authored
Implementing Asynchronous Advertising ID Retrieval for H5vccSystem (youtube#4794)
1. A new mojom interface for H5vccSystem is created, including an asynchronous API method to retrieve the advertising ID. 2. The mojom server implementation handles the request by calling JNI (Java Native Interface) functions. These JNI calls will interact with the StarboardBridge to fetch the actual advertising ID value. 3. The renderer client then utilizes the mojom interface to call the asynchronous method and retrieve the advertising ID. Tested on devtools, https://screenshot.googleplex.com/43HotkbLgJSQdx3 4. Added web_tests for the mojom interface. // Compile the web_test 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 && autoninja -C out/linux-x64x11_devel cobalt/browser/h5vcc_system/public/mojom:mojom_js // run the web_test third_party/blink/tools/run_web_tests.py -t linux-x64x11_devel wpt_internal/h5vcc/h5vcc-system b/377049113 --------- Co-authored-by: Colin Liang <colinliang@google.com>
1 parent affaaa6 commit 7bbf2ef

File tree

19 files changed

+341
-28
lines changed

19 files changed

+341
-28
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ files: |
1313
media/starboard/|
1414
starboard/|
1515
third_party/blink/renderer/modules/cobalt/|
16+
third_party/blink/web_tests/wpt_internal/h5vcc/|
1617
components/viz/service/display/starboard/|
1718
ui/ozone/platform/starboard/|
1819
.pre-commit-config.yaml|

cobalt/android/apk/app/src/main/java/dev/cobalt/coat/StarboardBridge.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ protected String getUserAgentAuxField() {
609609
// Used in starboard/android/shared/system_get_property.cc
610610
/** Returns string for kSbSystemPropertyAdvertisingId */
611611
@SuppressWarnings("unused")
612-
@UsedByNative
612+
@CalledByNative
613613
protected String getAdvertisingId() {
614614
return this.advertisingId.getId();
615615
}

cobalt/browser/BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ source_set("browser") {
3030
":embed_polyfilled_javascript",
3131
"//cobalt/browser/crash_annotator",
3232
"//cobalt/browser/crash_annotator/public/mojom",
33+
"//cobalt/browser/h5vcc_system",
34+
"//cobalt/browser/h5vcc_system/public/mojom",
3335
"//cobalt/user_agent",
3436
"//components/js_injection/browser:browser",
3537
"//content/public/browser",

cobalt/browser/cobalt_browser_interface_binders.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include "base/functional/bind.h"
1818
#include "cobalt/browser/crash_annotator/crash_annotator_impl.h"
1919
#include "cobalt/browser/crash_annotator/public/mojom/crash_annotator.mojom.h"
20+
#include "cobalt/browser/h5vcc_system/h5vcc_system_impl.h"
21+
#include "cobalt/browser/h5vcc_system/public/mojom/h5vcc_system.mojom.h"
2022

2123
namespace cobalt {
2224

@@ -25,6 +27,8 @@ void PopulateCobaltFrameBinders(
2527
mojo::BinderMapWithContext<content::RenderFrameHost*>* binder_map) {
2628
binder_map->Add<crash_annotator::mojom::CrashAnnotator>(
2729
base::BindRepeating(&crash_annotator::CrashAnnotatorImpl::Create));
30+
binder_map->Add<h5vcc_system::mojom::H5vccSystem>(
31+
base::BindRepeating(&h5vcc_system::H5vccSystemImpl::Create));
2832
}
2933

3034
} // namespace cobalt
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright 2025 The Cobalt Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
source_set("h5vcc_system") {
16+
sources = [
17+
"h5vcc_system_impl.cc",
18+
"h5vcc_system_impl.h",
19+
]
20+
21+
deps = [
22+
"//base",
23+
"//cobalt/browser/h5vcc_system/public/mojom",
24+
"//content/public/browser",
25+
"//mojo/public/cpp/bindings",
26+
]
27+
28+
# TODO (b/395154617) clean up
29+
if (is_android) {
30+
deps += [ "//starboard/android/shared:starboard_platform" ]
31+
}
32+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright 2025 The Cobalt Authors. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "cobalt/browser/h5vcc_system/h5vcc_system_impl.h"
16+
#include "base/functional/bind.h"
17+
#include "base/functional/callback.h"
18+
19+
#if BUILDFLAG(IS_ANDROID)
20+
#include "starboard/android/shared/starboard_bridge.h"
21+
22+
using starboard::android::shared::StarboardBridge;
23+
#endif
24+
25+
namespace h5vcc_system {
26+
27+
// TODO (b/395126160): refactor mojom implementation on Android
28+
H5vccSystemImpl::H5vccSystemImpl(
29+
content::RenderFrameHost& render_frame_host,
30+
mojo::PendingReceiver<mojom::H5vccSystem> receiver)
31+
: content::DocumentService<mojom::H5vccSystem>(render_frame_host,
32+
std::move(receiver)) {}
33+
34+
void H5vccSystemImpl::Create(
35+
content::RenderFrameHost* render_frame_host,
36+
mojo::PendingReceiver<mojom::H5vccSystem> receiver) {
37+
new H5vccSystemImpl(*render_frame_host, std::move(receiver));
38+
}
39+
40+
void H5vccSystemImpl::GetAdvertisingId(GetAdvertisingIdCallback callback) {
41+
std::string advertising_id;
42+
#if BUILDFLAG(IS_ANDROID)
43+
JNIEnv* env = base::android::AttachCurrentThread();
44+
StarboardBridge* starbooard_bridge = StarboardBridge::GetInstance();
45+
advertising_id = starbooard_bridge->GetAdvertisingId(env);
46+
#endif
47+
std::move(callback).Run(advertising_id);
48+
}
49+
50+
} // namespace h5vcc_system
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright 2025 The Cobalt Authors. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef COBALT_BROWSER_H5VCC_SYSTEM_H5VCC_SYSTEM_IMPL_H_
16+
#define COBALT_BROWSER_H5VCC_SYSTEM_H5VCC_SYSTEM_IMPL_H_
17+
18+
#include <string>
19+
20+
#include "cobalt/browser/h5vcc_system/public/mojom/h5vcc_system.mojom.h"
21+
#include "content/public/browser/document_service.h"
22+
#include "mojo/public/cpp/bindings/pending_receiver.h"
23+
24+
namespace content {
25+
class RenderFrameHost;
26+
} // namespace content
27+
28+
namespace h5vcc_system {
29+
30+
// Implements the H5vccSystem Mojo interface and extends
31+
// DocumentService so that an object's lifetime is scoped to the corresponding
32+
// document / RenderFrameHost (see DocumentService for details).
33+
class H5vccSystemImpl : public content::DocumentService<mojom::H5vccSystem> {
34+
public:
35+
// Creates a H5vccSystemImpl. The H5vccSystemImpl is bound to the
36+
// receiver and its lifetime is scoped to the render_frame_host.
37+
static void Create(content::RenderFrameHost* render_frame_host,
38+
mojo::PendingReceiver<mojom::H5vccSystem> receiver);
39+
40+
H5vccSystemImpl(const H5vccSystemImpl&) = delete;
41+
H5vccSystemImpl& operator=(const H5vccSystemImpl&) = delete;
42+
43+
void GetAdvertisingId(GetAdvertisingIdCallback) override;
44+
45+
private:
46+
H5vccSystemImpl(content::RenderFrameHost& render_frame_host,
47+
mojo::PendingReceiver<mojom::H5vccSystem> receiver);
48+
};
49+
50+
} // namespace h5vcc_system
51+
52+
#endif // COBALT_BROWSER_H5VCC_SYSTEM_H5VCC_SYSTEM_IMPL_H_
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright 2025 The Cobalt Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import("//mojo/public/tools/bindings/mojom.gni")
16+
17+
mojom("mojom") {
18+
sources = [ "h5vcc_system.mojom" ]
19+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2025 The Cobalt Authors. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
module h5vcc_system.mojom;
16+
17+
// The browser process must provide an implementation of this interface so that
18+
// the renderer process can implement the H5vccSystem Blink API.
19+
interface H5vccSystem {
20+
// Get the GetAdvertisingId for the device.
21+
GetAdvertisingId() => (string advertising_id);
22+
};

starboard/android/shared/starboard_bridge.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,14 @@ ScopedJavaLocalRef<jobject> StarboardBridge::GetTextToSpeechHelper(
235235
SB_DCHECK(env);
236236
return Java_StarboardBridge_getTextToSpeechHelper(env, j_starboard_bridge_);
237237
}
238+
239+
std::string StarboardBridge::GetAdvertisingId(JNIEnv* env) {
240+
SB_DCHECK(env);
241+
ScopedJavaLocalRef<jstring> advertising_id_java =
242+
Java_StarboardBridge_getAdvertisingId(env, j_starboard_bridge_);
243+
return ConvertJavaStringToUTF8(env, advertising_id_java);
244+
}
245+
238246
} // namespace shared
239247
} // namespace android
240248
} // namespace starboard

0 commit comments

Comments
 (0)