Commit 07c01cf7 authored by Oksana Zhuravlova's avatar Oksana Zhuravlova Committed by Commit Bot

[mojo] Add JavaScript support for BrowserInterfaceBroker

This change updates Mojo::bindInterface() to use
BrowserInterfaceBrokerProxy if a script passes a new
"useBrowserInterfaceBroker" parameter.
Also converts an interceptor web test as a use case.

Bug: 985117
Change-Id: Ib4685210cf6c3cf2f371d69f5e12d85d6194904f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1760026
Commit-Queue: Oksana Zhuravlova <oksamyt@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#688745}
parent cc108652
......@@ -99,7 +99,8 @@ MojoCreateSharedBufferResult* Mojo::createSharedBuffer(unsigned num_bytes) {
void Mojo::bindInterface(ScriptState* script_state,
const String& interface_name,
MojoHandle* request_handle,
const String& scope) {
const String& scope,
bool use_browser_interface_broker) {
std::string name = interface_name.Utf8();
auto handle =
mojo::ScopedMessagePipeHandle::From(request_handle->TakeHandle());
......@@ -110,6 +111,19 @@ void Mojo::bindInterface(ScriptState* script_state,
return;
}
// This should replace InterfaceProvider usage below when all
// InterfaceProvider clients are converted to use BrowserInterfaceBroker. See
// crbug.com/936482.
if (use_browser_interface_broker) {
if (auto* browser_interface_broker_proxy =
ExecutionContext::From(script_state)
->GetBrowserInterfaceBrokerProxy()) {
browser_interface_broker_proxy->GetInterface(name, std::move(handle));
return;
}
}
// TODO(crbug.com/995556): remove when no longer used.
if (auto* interface_provider =
ExecutionContext::From(script_state)->GetInterfaceProvider()) {
interface_provider->GetInterfaceByName(name, std::move(handle));
......
......@@ -54,7 +54,8 @@ class Mojo final : public ScriptWrappable {
static void bindInterface(ScriptState*,
const String& interface_name,
MojoHandle*,
const String& scope);
const String& scope,
bool use_browser_interface_broker);
static MojoHandle* getDocumentInterfaceBrokerHandle(ScriptState*);
static MojoHandle* replaceDocumentInterfaceBrokerForTesting(ScriptState*,
MojoHandle*);
......
......@@ -46,7 +46,7 @@ enum MojoScope {
static MojoCreateDataPipeResult createDataPipe(MojoCreateDataPipeOptions options);
static MojoCreateSharedBufferResult createSharedBuffer(unsigned long numBytes);
[CallWith=ScriptState] static void bindInterface(DOMString interfaceName, MojoHandle request_handle, optional MojoScope scope = "context");
[CallWith=ScriptState] static void bindInterface(DOMString interfaceName, MojoHandle request_handle, optional MojoScope scope = "context", optional boolean useBrowserInterfaceBroker = false);
[CallWith=ScriptState] static MojoHandle getDocumentInterfaceBrokerHandle();
[CallWith=ScriptState] static MojoHandle replaceDocumentInterfaceBrokerForTesting(MojoHandle test_broker_handle);
};
......@@ -6,7 +6,7 @@ importScripts('helpers.js');
promise_test(async () => {
let helperImpl = new TestHelperImpl;
let interceptor =
new MojoInterfaceInterceptor(content.mojom.MojoWebTestHelper.name);
new MojoInterfaceInterceptor(content.mojom.MojoWebTestHelper.name, "context", true);
interceptor.oninterfacerequest = e => {
helperImpl.bindRequest(e.handle);
};
......@@ -14,7 +14,7 @@ promise_test(async () => {
let helper = new content.mojom.MojoWebTestHelperPtr;
Mojo.bindInterface(content.mojom.MojoWebTestHelper.name,
mojo.makeRequest(helper).handle);
mojo.makeRequest(helper).handle, "context", true);
let response = await helper.reverse('the string');
assert_equals(response.reversed, kTestReply);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment