diff options
19 files changed, 55 insertions, 31 deletions
diff --git a/chrome/browser/resources/engagement/site_engagement.js b/chrome/browser/resources/engagement/site_engagement.js index 0efd9a1..0992b9e 100644 --- a/chrome/browser/resources/engagement/site_engagement.js +++ b/chrome/browser/resources/engagement/site_engagement.js @@ -7,7 +7,7 @@ define('main', [ 'mojo/public/js/connection', 'chrome/browser/ui/webui/engagement/site_engagement.mojom', - 'content/public/renderer/service_provider', + 'content/public/renderer/frame_service_registry', ], function(connection, siteEngagementMojom, serviceProvider) { return function() { var uiHandler = connection.bindHandleToProxy( diff --git a/chrome/browser/resources/omnibox/omnibox.js b/chrome/browser/resources/omnibox/omnibox.js index 8631c27..2920529 100644 --- a/chrome/browser/resources/omnibox/omnibox.js +++ b/chrome/browser/resources/omnibox/omnibox.js @@ -21,7 +21,7 @@ define('main', [ 'mojo/public/js/core', 'mojo/public/js/connection', 'chrome/browser/ui/webui/omnibox/omnibox.mojom', - 'content/public/renderer/service_provider', + 'content/public/renderer/frame_service_registry', ], function(bindings, core, connection, browser, serviceProvider) { 'use strict'; diff --git a/chrome/browser/resources/plugins.js b/chrome/browser/resources/plugins.js index 085aa32..746b192 100644 --- a/chrome/browser/resources/plugins.js +++ b/chrome/browser/resources/plugins.js @@ -276,7 +276,7 @@ var whenBrowserProxyReady = new Promise(function(resolve, reject) { 'mojo/public/js/core', 'mojo/public/js/connection', 'chrome/browser/ui/webui/plugins/plugins.mojom', - 'content/public/renderer/service_provider', + 'content/public/renderer/frame_service_registry', ], function(bindings, core, connection, pluginsMojom, serviceProvider) { var browserProxy = connection.bindHandleToProxy( serviceProvider.connectToService( diff --git a/content/renderer/mojo/service_registry_js_wrapper.cc b/content/renderer/mojo/service_registry_js_wrapper.cc index 094fb02..1ab8b86 100644 --- a/content/renderer/mojo/service_registry_js_wrapper.cc +++ b/content/renderer/mojo/service_registry_js_wrapper.cc @@ -16,8 +16,10 @@ namespace content { gin::WrapperInfo ServiceRegistryJsWrapper::kWrapperInfo = { gin::kEmbedderNativeGin}; -const char ServiceRegistryJsWrapper::kModuleName[] = - "content/public/renderer/service_provider"; +const char ServiceRegistryJsWrapper::kPerFrameModuleName[] = + "content/public/renderer/frame_service_registry"; +const char ServiceRegistryJsWrapper::kPerProcessModuleName[] = + "content/public/renderer/service_registry"; ServiceRegistryJsWrapper::~ServiceRegistryJsWrapper() { } @@ -57,8 +59,7 @@ mojo::Handle ServiceRegistryJsWrapper::ConnectToService( void ServiceRegistryJsWrapper::AddServiceOverrideForTesting( const std::string& service_name, v8::Local<v8::Function> service_factory) { - ServiceRegistryImpl* registry = - static_cast<ServiceRegistryImpl*>(service_registry_.get()); + ServiceRegistry* registry = service_registry_.get(); if (!registry) return; ScopedJsFactory factory(v8::Isolate::GetCurrent(), service_factory); diff --git a/content/renderer/mojo/service_registry_js_wrapper.h b/content/renderer/mojo/service_registry_js_wrapper.h index f199c63..5fc2f63 100644 --- a/content/renderer/mojo/service_registry_js_wrapper.h +++ b/content/renderer/mojo/service_registry_js_wrapper.h @@ -41,7 +41,8 @@ class CONTENT_EXPORT ServiceRegistryJsWrapper mojo::Handle ConnectToService(const std::string& service_name); static gin::WrapperInfo kWrapperInfo; - static const char kModuleName[]; + static const char kPerFrameModuleName[]; + static const char kPerProcessModuleName[]; private: using ScopedJsFactory = diff --git a/content/renderer/render_frame_impl.cc b/content/renderer/render_frame_impl.cc index a41cdb2..2465688 100644 --- a/content/renderer/render_frame_impl.cc +++ b/content/renderer/render_frame_impl.cc @@ -2320,9 +2320,14 @@ void RenderFrameImpl::EnsureMojoBuiltinsAreAvailable( registry->AddBuiltinModule(isolate, mojo::edk::js::Support::kModuleName, mojo::edk::js::Support::GetModule(isolate)); registry->AddBuiltinModule( - isolate, ServiceRegistryJsWrapper::kModuleName, + isolate, ServiceRegistryJsWrapper::kPerFrameModuleName, ServiceRegistryJsWrapper::Create(isolate, context, &service_registry_) .ToV8()); + registry->AddBuiltinModule( + isolate, ServiceRegistryJsWrapper::kPerProcessModuleName, + ServiceRegistryJsWrapper::Create( + isolate, context, RenderThread::Get()->GetServiceRegistry()) + .ToV8()); } void RenderFrameImpl::AddMessageToConsole(ConsoleMessageLevel level, diff --git a/content/test/data/web_ui_mojo.js b/content/test/data/web_ui_mojo.js index 978d068..ab9765c 100644 --- a/content/test/data/web_ui_mojo.js +++ b/content/test/data/web_ui_mojo.js @@ -5,7 +5,7 @@ define('main', [ 'mojo/public/js/router', 'content/test/data/web_ui_test_mojo_bindings.mojom', - 'content/public/renderer/service_provider', + 'content/public/renderer/frame_service_registry', ], function (router, bindings, serviceProvider) { var browserTarget; diff --git a/content/test/data/web_ui_mojo_shell_test.js b/content/test/data/web_ui_mojo_shell_test.js index f0337ba..219f47d 100644 --- a/content/test/data/web_ui_mojo_shell_test.js +++ b/content/test/data/web_ui_mojo_shell_test.js @@ -15,7 +15,7 @@ define('main', [ 'mojo/public/js/router', 'mojo/services/network/public/interfaces/url_loader.mojom', 'mojo/shell/public/interfaces/connector.mojom', - 'content/public/renderer/service_provider', + 'content/public/renderer/frame_service_registry', 'content/public/test/test_mojo_service.mojom', ], function (core, router, urlMojom, connectorMojom, serviceRegistry, testMojom) { diff --git a/extensions/renderer/api_test_base.cc b/extensions/renderer/api_test_base.cc index 79f95e2..81ec07f 100644 --- a/extensions/renderer/api_test_base.cc +++ b/extensions/renderer/api_test_base.cc @@ -165,7 +165,7 @@ void ApiTestEnvironment::RegisterModules() { service_provider_ = service_provider.get(); gin::ModuleRegistry::From(env()->context()->v8_context()) ->AddBuiltinModule(env()->isolate(), - "content/public/renderer/service_provider", + "content/public/renderer/frame_service_registry", service_provider.ToV8()); } diff --git a/extensions/renderer/resources/keep_alive.js b/extensions/renderer/resources/keep_alive.js index aa5f6a0..5269c30 100644 --- a/extensions/renderer/resources/keep_alive.js +++ b/extensions/renderer/resources/keep_alive.js @@ -3,7 +3,7 @@ // found in the LICENSE file. define('keep_alive', [ - 'content/public/renderer/service_provider', + 'content/public/renderer/frame_service_registry', 'extensions/common/mojo/keep_alive.mojom', 'mojo/public/js/core', ], function(serviceProvider, mojom, core) { diff --git a/extensions/renderer/resources/media_router_bindings.js b/extensions/renderer/resources/media_router_bindings.js index e7f32d8..85685c6 100644 --- a/extensions/renderer/resources/media_router_bindings.js +++ b/extensions/renderer/resources/media_router_bindings.js @@ -7,7 +7,7 @@ var mediaRouter; define('media_router_bindings', [ 'mojo/public/js/bindings', 'mojo/public/js/core', - 'content/public/renderer/service_provider', + 'content/public/renderer/frame_service_registry', 'chrome/browser/media/router/media_router.mojom', 'extensions/common/mojo/keep_alive.mojom', 'mojo/public/js/connection', diff --git a/extensions/renderer/resources/mime_handler_private_custom_bindings.js b/extensions/renderer/resources/mime_handler_private_custom_bindings.js index bd7eddd..8e9eb20 100644 --- a/extensions/renderer/resources/mime_handler_private_custom_bindings.js +++ b/extensions/renderer/resources/mime_handler_private_custom_bindings.js @@ -13,7 +13,7 @@ var NO_STREAM_ERROR = var STREAM_ABORTED_ERROR = 'Stream has been aborted.'; var servicePromise = Promise.all([ - requireAsync('content/public/renderer/service_provider'), + requireAsync('content/public/renderer/frame_service_registry'), requireAsync('extensions/common/api/mime_handler.mojom'), requireAsync('mojo/public/js/router'), ]).then(function(modules) { diff --git a/extensions/renderer/resources/serial_service.js b/extensions/renderer/resources/serial_service.js index 015a742..26b990b 100644 --- a/extensions/renderer/resources/serial_service.js +++ b/extensions/renderer/resources/serial_service.js @@ -3,7 +3,7 @@ // found in the LICENSE file. define('serial_service', [ - 'content/public/renderer/service_provider', + 'content/public/renderer/frame_service_registry', 'data_receiver', 'data_sender', 'device/serial/serial.mojom', diff --git a/extensions/renderer/resources/stash_client.js b/extensions/renderer/resources/stash_client.js index 56f289f..240a676 100644 --- a/extensions/renderer/resources/stash_client.js +++ b/extensions/renderer/resources/stash_client.js @@ -4,7 +4,7 @@ define('stash_client', [ 'async_waiter', - 'content/public/renderer/service_provider', + 'content/public/renderer/frame_service_registry', 'extensions/common/mojo/stash.mojom', 'mojo/public/js/buffer', 'mojo/public/js/codec', diff --git a/extensions/test/data/api_test_base_unittest.js b/extensions/test/data/api_test_base_unittest.js index 10c4792..77a9cb2 100644 --- a/extensions/test/data/api_test_base_unittest.js +++ b/extensions/test/data/api_test_base_unittest.js @@ -38,7 +38,7 @@ unittestBindings.exportTests([ Promise.all([ requireAsync('mojo/public/js/connection'), requireAsync('mojo/public/js/core'), - requireAsync('content/public/renderer/service_provider'), + requireAsync('content/public/renderer/frame_service_registry'), ]).then(test.callback(function(modules) { var connection = modules[0]; var core = modules[1]; diff --git a/extensions/test/data/data_sender_unittest.js b/extensions/test/data/data_sender_unittest.js index 0b6a5cf..48c1cec 100644 --- a/extensions/test/data/data_sender_unittest.js +++ b/extensions/test/data/data_sender_unittest.js @@ -24,7 +24,7 @@ function generateData(size, pattern) { // Returns a promise to a newly created DataSender. function createSender() { return Promise.all([ - requireAsync('content/public/renderer/service_provider'), + requireAsync('content/public/renderer/frame_service_registry'), requireAsync('data_sender'), requireAsync('device/serial/data_stream.mojom'), ]).then(function(modules) { diff --git a/third_party/WebKit/LayoutTests/harness-tests/mojo-helpers.html b/third_party/WebKit/LayoutTests/harness-tests/mojo-helpers.html index 5a869ba..41f0622 100644 --- a/third_party/WebKit/LayoutTests/harness-tests/mojo-helpers.html +++ b/third_party/WebKit/LayoutTests/harness-tests/mojo-helpers.html @@ -11,6 +11,7 @@ mojo_test(mojo => { assert_true(mojo instanceof Object); assert_true(mojo.core instanceof Object); assert_true(mojo.router instanceof Object); + assert_true(mojo.frameServiceRegistry instanceof Object); assert_true(mojo.serviceRegistry instanceof Object); }, 'Mojo system APIs should be available to layout tests.'); @@ -18,6 +19,22 @@ mojo_test(mojo => { return new Promise(resolve => { let calls = 0; // Complete the test as soon as two requests come in for a Frobinator service. + mojo.frameServiceRegistry.addServiceOverrideForTesting('Frobinator', () => { + if (++calls == 2) + resolve(); + }); + + // Try to connect to the browser's Frobinator service. This should be + // intercepted by the above override. + mojo.frameServiceRegistry.connectToService('Frobinator'); + mojo.frameServiceRegistry.connectToService('Frobinator'); + }); +}, 'Frame service registry overrides should be properly intercepted.'); + +mojo_test(mojo => { + return new Promise(resolve => { + let calls = 0; + // Complete the test as soon as two requests come in for a Frobinator service. mojo.serviceRegistry.addServiceOverrideForTesting('Frobinator', () => { if (++calls == 2) resolve(); diff --git a/third_party/WebKit/LayoutTests/resources/mojo-helpers.js b/third_party/WebKit/LayoutTests/resources/mojo-helpers.js index 6e3f7cd..db7a626 100644 --- a/third_party/WebKit/LayoutTests/resources/mojo-helpers.js +++ b/third_party/WebKit/LayoutTests/resources/mojo-helpers.js @@ -31,20 +31,20 @@ define('Mojo Helpers', [ 'mojo/public/js/core', 'mojo/public/js/router', 'mojo/public/js/support', - 'content/public/renderer/service_provider' -], (core, router, support, serviceProvider) => { + 'content/public/renderer/frame_service_registry', + 'content/public/renderer/service_registry', +], (core, router, support, frameServiceRegistry, serviceRegistry) => { add_completion_callback(() => { - serviceProvider.clearServiceOverridesForTesting(); + frameServiceRegistry.clearServiceOverridesForTesting(); + serviceRegistry.clearServiceOverridesForTesting(); }); return { - core: core, - router: router, - support: support, - - // |serviceProvider| is a bit of a misnomer. It should probably be - // called |serviceRegistry|, so let's call it that here. - serviceRegistry: serviceProvider, + core, + router, + support, + frameServiceRegistry, + serviceRegistry, }; }); diff --git a/third_party/WebKit/LayoutTests/usb/resources/usb-helpers.js b/third_party/WebKit/LayoutTests/usb/resources/usb-helpers.js index ccceef5..901719b 100644 --- a/third_party/WebKit/LayoutTests/usb/resources/usb-helpers.js +++ b/third_party/WebKit/LayoutTests/usb/resources/usb-helpers.js @@ -432,14 +432,14 @@ function usbMocks(mojo) { } let mockDeviceManager = new MockDeviceManager; - mojo.serviceRegistry.addServiceOverrideForTesting( + mojo.frameServiceRegistry.addServiceOverrideForTesting( deviceManager.DeviceManager.name, pipe => { mockDeviceManager.bindToPipe(pipe); }); let mockChooserService = new MockChooserService; - mojo.serviceRegistry.addServiceOverrideForTesting( + mojo.frameServiceRegistry.addServiceOverrideForTesting( chooserService.ChooserService.name, pipe => { mockChooserService.bindToPipe(pipe); |