| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "extensions/renderer/dispatcher.h" | 5 #include "extensions/renderer/dispatcher.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 { | 353 { |
| 354 std::unique_ptr<ModuleSystem> module_system( | 354 std::unique_ptr<ModuleSystem> module_system( |
| 355 new ModuleSystem(context, &source_map_)); | 355 new ModuleSystem(context, &source_map_)); |
| 356 context->set_module_system(std::move(module_system)); | 356 context->set_module_system(std::move(module_system)); |
| 357 } | 357 } |
| 358 ModuleSystem* module_system = context->module_system(); | 358 ModuleSystem* module_system = context->module_system(); |
| 359 | 359 |
| 360 // Enable natives in startup. | 360 // Enable natives in startup. |
| 361 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system); | 361 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system); |
| 362 | 362 |
| 363 RegisterNativeHandlers(module_system, context, | 363 RegisterNativeHandlers(module_system, context, bindings_system_.get(), |
| 364 bindings_system_->GetRequestSender(), | |
| 365 v8_schema_registry_.get()); | 364 v8_schema_registry_.get()); |
| 366 | 365 |
| 367 bindings_system_->DidCreateScriptContext(context); | 366 bindings_system_->DidCreateScriptContext(context); |
| 368 UpdateBindingsForContext(context); | 367 UpdateBindingsForContext(context); |
| 369 | 368 |
| 370 // Inject custom JS into the platform app context. | 369 // Inject custom JS into the platform app context. |
| 371 if (IsWithinPlatformApp()) { | 370 if (IsWithinPlatformApp()) { |
| 372 module_system->Require("platformApp"); | 371 module_system->Require("platformApp"); |
| 373 } | 372 } |
| 374 | 373 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 // TODO(lazyboy): Make sure accessing |source_map_| in worker thread is | 463 // TODO(lazyboy): Make sure accessing |source_map_| in worker thread is |
| 465 // safe. | 464 // safe. |
| 466 context->set_module_system( | 465 context->set_module_system( |
| 467 base::MakeUnique<ModuleSystem>(context, &source_map_)); | 466 base::MakeUnique<ModuleSystem>(context, &source_map_)); |
| 468 | 467 |
| 469 ModuleSystem* module_system = context->module_system(); | 468 ModuleSystem* module_system = context->module_system(); |
| 470 // Enable natives in startup. | 469 // Enable natives in startup. |
| 471 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system); | 470 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system); |
| 472 ExtensionBindingsSystem* worker_bindings_system = | 471 ExtensionBindingsSystem* worker_bindings_system = |
| 473 WorkerThreadDispatcher::GetBindingsSystem(); | 472 WorkerThreadDispatcher::GetBindingsSystem(); |
| 474 RegisterNativeHandlers(module_system, context, | 473 RegisterNativeHandlers(module_system, context, worker_bindings_system, |
| 475 worker_bindings_system->GetRequestSender(), | |
| 476 WorkerThreadDispatcher::GetV8SchemaRegistry()); | 474 WorkerThreadDispatcher::GetV8SchemaRegistry()); |
| 477 | 475 |
| 478 worker_bindings_system->DidCreateScriptContext(context); | 476 worker_bindings_system->DidCreateScriptContext(context); |
| 479 worker_bindings_system->UpdateBindingsForContext(context); | 477 worker_bindings_system->UpdateBindingsForContext(context); |
| 480 | 478 |
| 481 // TODO(lazyboy): Get rid of RequireGuestViewModules() as this doesn't seem | 479 // TODO(lazyboy): Get rid of RequireGuestViewModules() as this doesn't seem |
| 482 // necessary for Extension SW. | 480 // necessary for Extension SW. |
| 483 RequireGuestViewModules(context); | 481 RequireGuestViewModules(context); |
| 484 delegate_->RequireAdditionalModules(context); | 482 delegate_->RequireAdditionalModules(context); |
| 485 } | 483 } |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 789 resources.emplace_back("guestViewIframe", IDR_GUEST_VIEW_IFRAME_JS); | 787 resources.emplace_back("guestViewIframe", IDR_GUEST_VIEW_IFRAME_JS); |
| 790 resources.emplace_back("guestViewIframeContainer", | 788 resources.emplace_back("guestViewIframeContainer", |
| 791 IDR_GUEST_VIEW_IFRAME_CONTAINER_JS); | 789 IDR_GUEST_VIEW_IFRAME_CONTAINER_JS); |
| 792 } | 790 } |
| 793 | 791 |
| 794 return resources; | 792 return resources; |
| 795 } | 793 } |
| 796 | 794 |
| 797 // NOTE: please use the naming convention "foo_natives" for these. | 795 // NOTE: please use the naming convention "foo_natives" for these. |
| 798 // static | 796 // static |
| 799 void Dispatcher::RegisterNativeHandlers(ModuleSystem* module_system, | 797 void Dispatcher::RegisterNativeHandlers( |
| 800 ScriptContext* context, | 798 ModuleSystem* module_system, |
| 801 Dispatcher* dispatcher, | 799 ScriptContext* context, |
| 802 RequestSender* request_sender, | 800 Dispatcher* dispatcher, |
| 803 V8SchemaRegistry* v8_schema_registry) { | 801 ExtensionBindingsSystem* bindings_system, |
| 802 V8SchemaRegistry* v8_schema_registry) { |
| 804 module_system->RegisterNativeHandler( | 803 module_system->RegisterNativeHandler( |
| 805 "chrome", | 804 "chrome", |
| 806 std::unique_ptr<NativeHandler>(new ChromeNativeHandler(context))); | 805 std::unique_ptr<NativeHandler>(new ChromeNativeHandler(context))); |
| 807 module_system->RegisterNativeHandler( | 806 module_system->RegisterNativeHandler( |
| 808 "logging", | 807 "logging", |
| 809 std::unique_ptr<NativeHandler>(new LoggingNativeHandler(context))); | 808 std::unique_ptr<NativeHandler>(new LoggingNativeHandler(context))); |
| 810 module_system->RegisterNativeHandler("schema_registry", | 809 module_system->RegisterNativeHandler("schema_registry", |
| 811 v8_schema_registry->AsNativeHandler()); | 810 v8_schema_registry->AsNativeHandler()); |
| 812 module_system->RegisterNativeHandler( | 811 module_system->RegisterNativeHandler( |
| 813 "test_features", | 812 "test_features", |
| (...skipping 11 matching lines...) Expand all Loading... |
| 825 std::unique_ptr<NativeHandler>(new V8ContextNativeHandler(context))); | 824 std::unique_ptr<NativeHandler>(new V8ContextNativeHandler(context))); |
| 826 module_system->RegisterNativeHandler( | 825 module_system->RegisterNativeHandler( |
| 827 "event_natives", | 826 "event_natives", |
| 828 std::unique_ptr<NativeHandler>(new EventBindings(context))); | 827 std::unique_ptr<NativeHandler>(new EventBindings(context))); |
| 829 module_system->RegisterNativeHandler( | 828 module_system->RegisterNativeHandler( |
| 830 "messaging_natives", base::MakeUnique<MessagingBindings>(context)); | 829 "messaging_natives", base::MakeUnique<MessagingBindings>(context)); |
| 831 module_system->RegisterNativeHandler( | 830 module_system->RegisterNativeHandler( |
| 832 "apiDefinitions", std::unique_ptr<NativeHandler>( | 831 "apiDefinitions", std::unique_ptr<NativeHandler>( |
| 833 new ApiDefinitionsNatives(dispatcher, context))); | 832 new ApiDefinitionsNatives(dispatcher, context))); |
| 834 module_system->RegisterNativeHandler( | 833 module_system->RegisterNativeHandler( |
| 835 "sendRequest", std::unique_ptr<NativeHandler>( | 834 "sendRequest", |
| 836 new SendRequestNatives(request_sender, context))); | 835 base::MakeUnique<SendRequestNatives>( |
| 836 // Note: |bindings_system| can be null in unit tests. |
| 837 bindings_system ? bindings_system->GetRequestSender() : nullptr, |
| 838 context)); |
| 837 module_system->RegisterNativeHandler( | 839 module_system->RegisterNativeHandler( |
| 838 "setIcon", std::unique_ptr<NativeHandler>(new SetIconNatives(context))); | 840 "setIcon", std::unique_ptr<NativeHandler>(new SetIconNatives(context))); |
| 839 module_system->RegisterNativeHandler( | 841 module_system->RegisterNativeHandler( |
| 840 "activityLogger", std::unique_ptr<NativeHandler>( | 842 "activityLogger", std::unique_ptr<NativeHandler>( |
| 841 new APIActivityLogger(context, dispatcher))); | 843 new APIActivityLogger(context, dispatcher))); |
| 842 module_system->RegisterNativeHandler( | 844 module_system->RegisterNativeHandler( |
| 843 "renderFrameObserverNatives", | 845 "renderFrameObserverNatives", |
| 844 std::unique_ptr<NativeHandler>(new RenderFrameObserverNatives(context))); | 846 std::unique_ptr<NativeHandler>(new RenderFrameObserverNatives(context))); |
| 845 | 847 |
| 846 // Natives used by multiple APIs. | 848 // Natives used by multiple APIs. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 865 "guest_view_internal", std::unique_ptr<NativeHandler>( | 867 "guest_view_internal", std::unique_ptr<NativeHandler>( |
| 866 new GuestViewInternalCustomBindings(context))); | 868 new GuestViewInternalCustomBindings(context))); |
| 867 module_system->RegisterNativeHandler( | 869 module_system->RegisterNativeHandler( |
| 868 "id_generator", | 870 "id_generator", |
| 869 std::unique_ptr<NativeHandler>(new IdGeneratorCustomBindings(context))); | 871 std::unique_ptr<NativeHandler>(new IdGeneratorCustomBindings(context))); |
| 870 module_system->RegisterNativeHandler( | 872 module_system->RegisterNativeHandler( |
| 871 "runtime", | 873 "runtime", |
| 872 std::unique_ptr<NativeHandler>(new RuntimeCustomBindings(context))); | 874 std::unique_ptr<NativeHandler>(new RuntimeCustomBindings(context))); |
| 873 module_system->RegisterNativeHandler( | 875 module_system->RegisterNativeHandler( |
| 874 "display_source", | 876 "display_source", |
| 875 std::unique_ptr<NativeHandler>(new DisplaySourceCustomBindings(context))); | 877 base::MakeUnique<DisplaySourceCustomBindings>(context, bindings_system)); |
| 876 } | 878 } |
| 877 | 879 |
| 878 bool Dispatcher::OnControlMessageReceived(const IPC::Message& message) { | 880 bool Dispatcher::OnControlMessageReceived(const IPC::Message& message) { |
| 879 bool handled = true; | 881 bool handled = true; |
| 880 IPC_BEGIN_MESSAGE_MAP(Dispatcher, message) | 882 IPC_BEGIN_MESSAGE_MAP(Dispatcher, message) |
| 881 IPC_MESSAGE_HANDLER(ExtensionMsg_ActivateExtension, OnActivateExtension) | 883 IPC_MESSAGE_HANDLER(ExtensionMsg_ActivateExtension, OnActivateExtension) |
| 882 IPC_MESSAGE_HANDLER(ExtensionMsg_CancelSuspend, OnCancelSuspend) | 884 IPC_MESSAGE_HANDLER(ExtensionMsg_CancelSuspend, OnCancelSuspend) |
| 883 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnDeliverMessage) | 885 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnDeliverMessage) |
| 884 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnConnect, OnDispatchOnConnect) | 886 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnConnect, OnDispatchOnConnect) |
| 885 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnDisconnect, OnDispatchOnDisconnect) | 887 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnDisconnect, OnDispatchOnDisconnect) |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1328 void Dispatcher::UpdateBindingsForContext(ScriptContext* context) { | 1330 void Dispatcher::UpdateBindingsForContext(ScriptContext* context) { |
| 1329 bindings_system_->UpdateBindingsForContext(context); | 1331 bindings_system_->UpdateBindingsForContext(context); |
| 1330 Feature::Context context_type = context->context_type(); | 1332 Feature::Context context_type = context->context_type(); |
| 1331 if (context_type == Feature::WEB_PAGE_CONTEXT || | 1333 if (context_type == Feature::WEB_PAGE_CONTEXT || |
| 1332 context_type == Feature::BLESSED_WEB_PAGE_CONTEXT) { | 1334 context_type == Feature::BLESSED_WEB_PAGE_CONTEXT) { |
| 1333 UpdateContentCapabilities(context); | 1335 UpdateContentCapabilities(context); |
| 1334 } | 1336 } |
| 1335 } | 1337 } |
| 1336 | 1338 |
| 1337 // NOTE: please use the naming convention "foo_natives" for these. | 1339 // NOTE: please use the naming convention "foo_natives" for these. |
| 1338 void Dispatcher::RegisterNativeHandlers(ModuleSystem* module_system, | 1340 void Dispatcher::RegisterNativeHandlers( |
| 1339 ScriptContext* context, | 1341 ModuleSystem* module_system, |
| 1340 RequestSender* request_sender, | 1342 ScriptContext* context, |
| 1341 V8SchemaRegistry* v8_schema_registry) { | 1343 ExtensionBindingsSystem* bindings_system, |
| 1342 RegisterNativeHandlers(module_system, context, this, request_sender, | 1344 V8SchemaRegistry* v8_schema_registry) { |
| 1345 RegisterNativeHandlers(module_system, context, this, bindings_system, |
| 1343 v8_schema_registry); | 1346 v8_schema_registry); |
| 1344 const Extension* extension = context->extension(); | 1347 const Extension* extension = context->extension(); |
| 1345 int manifest_version = extension ? extension->manifest_version() : 1; | 1348 int manifest_version = extension ? extension->manifest_version() : 1; |
| 1346 bool is_component_extension = | 1349 bool is_component_extension = |
| 1347 extension && Manifest::IsComponentLocation(extension->location()); | 1350 extension && Manifest::IsComponentLocation(extension->location()); |
| 1348 bool send_request_disabled = | 1351 bool send_request_disabled = |
| 1349 (extension && Manifest::IsUnpackedLocation(extension->location()) && | 1352 (extension && Manifest::IsUnpackedLocation(extension->location()) && |
| 1350 BackgroundInfo::HasLazyBackgroundPage(extension)); | 1353 BackgroundInfo::HasLazyBackgroundPage(extension)); |
| 1351 module_system->RegisterNativeHandler( | 1354 module_system->RegisterNativeHandler( |
| 1352 "process", | 1355 "process", |
| 1353 std::unique_ptr<NativeHandler>(new ProcessInfoNativeHandler( | 1356 std::unique_ptr<NativeHandler>(new ProcessInfoNativeHandler( |
| 1354 context, context->GetExtensionID(), | 1357 context, context->GetExtensionID(), |
| 1355 context->GetContextTypeDescription(), | 1358 context->GetContextTypeDescription(), |
| 1356 ExtensionsRendererClient::Get()->IsIncognitoProcess(), | 1359 ExtensionsRendererClient::Get()->IsIncognitoProcess(), |
| 1357 is_component_extension, manifest_version, send_request_disabled))); | 1360 is_component_extension, manifest_version, send_request_disabled))); |
| 1358 | 1361 |
| 1359 delegate_->RegisterNativeHandlers(this, module_system, context); | 1362 delegate_->RegisterNativeHandlers(this, module_system, bindings_system, |
| 1363 context); |
| 1360 } | 1364 } |
| 1361 | 1365 |
| 1362 void Dispatcher::UpdateContentCapabilities(ScriptContext* context) { | 1366 void Dispatcher::UpdateContentCapabilities(ScriptContext* context) { |
| 1363 APIPermissionSet permissions; | 1367 APIPermissionSet permissions; |
| 1364 for (const auto& extension : | 1368 for (const auto& extension : |
| 1365 *RendererExtensionRegistry::Get()->GetMainThreadExtensionSet()) { | 1369 *RendererExtensionRegistry::Get()->GetMainThreadExtensionSet()) { |
| 1366 blink::WebLocalFrame* web_frame = context->web_frame(); | 1370 blink::WebLocalFrame* web_frame = context->web_frame(); |
| 1367 GURL url = context->url(); | 1371 GURL url = context->url(); |
| 1368 // We allow about:blank pages to take on the privileges of their parents if | 1372 // We allow about:blank pages to take on the privileges of their parents if |
| 1369 // they aren't sandboxed. | 1373 // they aren't sandboxed. |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1443 // The "guestViewDeny" module must always be loaded last. It registers | 1447 // The "guestViewDeny" module must always be loaded last. It registers |
| 1444 // error-providing custom elements for the GuestView types that are not | 1448 // error-providing custom elements for the GuestView types that are not |
| 1445 // available, and thus all of those types must have been checked and loaded | 1449 // available, and thus all of those types must have been checked and loaded |
| 1446 // (or not loaded) beforehand. | 1450 // (or not loaded) beforehand. |
| 1447 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { | 1451 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { |
| 1448 module_system->Require("guestViewDeny"); | 1452 module_system->Require("guestViewDeny"); |
| 1449 } | 1453 } |
| 1450 } | 1454 } |
| 1451 | 1455 |
| 1452 } // namespace extensions | 1456 } // namespace extensions |
| OLD | NEW |