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 <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 23 matching lines...) Expand all Loading... |
34 #include "content/public/renderer/render_thread.h" | 34 #include "content/public/renderer/render_thread.h" |
35 #include "extensions/common/api/messaging/message.h" | 35 #include "extensions/common/api/messaging/message.h" |
36 #include "extensions/common/constants.h" | 36 #include "extensions/common/constants.h" |
37 #include "extensions/common/extension_api.h" | 37 #include "extensions/common/extension_api.h" |
38 #include "extensions/common/extension_messages.h" | 38 #include "extensions/common/extension_messages.h" |
39 #include "extensions/common/extension_urls.h" | 39 #include "extensions/common/extension_urls.h" |
40 #include "extensions/common/feature_switch.h" | 40 #include "extensions/common/feature_switch.h" |
41 #include "extensions/common/features/behavior_feature.h" | 41 #include "extensions/common/features/behavior_feature.h" |
42 #include "extensions/common/features/feature.h" | 42 #include "extensions/common/features/feature.h" |
43 #include "extensions/common/features/feature_provider.h" | 43 #include "extensions/common/features/feature_provider.h" |
| 44 #include "extensions/common/features/feature_util.h" |
44 #include "extensions/common/manifest.h" | 45 #include "extensions/common/manifest.h" |
45 #include "extensions/common/manifest_constants.h" | 46 #include "extensions/common/manifest_constants.h" |
46 #include "extensions/common/manifest_handlers/background_info.h" | 47 #include "extensions/common/manifest_handlers/background_info.h" |
47 #include "extensions/common/manifest_handlers/content_capabilities_handler.h" | 48 #include "extensions/common/manifest_handlers/content_capabilities_handler.h" |
48 #include "extensions/common/manifest_handlers/externally_connectable.h" | 49 #include "extensions/common/manifest_handlers/externally_connectable.h" |
49 #include "extensions/common/manifest_handlers/options_page_info.h" | 50 #include "extensions/common/manifest_handlers/options_page_info.h" |
50 #include "extensions/common/message_bundle.h" | 51 #include "extensions/common/message_bundle.h" |
51 #include "extensions/common/permissions/permission_set.h" | 52 #include "extensions/common/permissions/permission_set.h" |
52 #include "extensions/common/permissions/permissions_data.h" | 53 #include "extensions/common/permissions/permissions_data.h" |
53 #include "extensions/common/switches.h" | 54 #include "extensions/common/switches.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 #include "extensions/renderer/set_icon_natives.h" | 92 #include "extensions/renderer/set_icon_natives.h" |
92 #include "extensions/renderer/static_v8_external_one_byte_string_resource.h" | 93 #include "extensions/renderer/static_v8_external_one_byte_string_resource.h" |
93 #include "extensions/renderer/test_features_native_handler.h" | 94 #include "extensions/renderer/test_features_native_handler.h" |
94 #include "extensions/renderer/test_native_handler.h" | 95 #include "extensions/renderer/test_native_handler.h" |
95 #include "extensions/renderer/user_gestures_native_handler.h" | 96 #include "extensions/renderer/user_gestures_native_handler.h" |
96 #include "extensions/renderer/utils_native_handler.h" | 97 #include "extensions/renderer/utils_native_handler.h" |
97 #include "extensions/renderer/v8_context_native_handler.h" | 98 #include "extensions/renderer/v8_context_native_handler.h" |
98 #include "extensions/renderer/v8_helpers.h" | 99 #include "extensions/renderer/v8_helpers.h" |
99 #include "extensions/renderer/wake_event_page.h" | 100 #include "extensions/renderer/wake_event_page.h" |
100 #include "extensions/renderer/worker_script_context_set.h" | 101 #include "extensions/renderer/worker_script_context_set.h" |
| 102 #include "extensions/renderer/worker_thread_dispatcher.h" |
101 #include "grit/extensions_renderer_resources.h" | 103 #include "grit/extensions_renderer_resources.h" |
102 #include "mojo/public/js/constants.h" | 104 #include "mojo/public/js/constants.h" |
103 #include "third_party/WebKit/public/platform/WebString.h" | 105 #include "third_party/WebKit/public/platform/WebString.h" |
104 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 106 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
105 #include "third_party/WebKit/public/web/WebCustomElement.h" | 107 #include "third_party/WebKit/public/web/WebCustomElement.h" |
106 #include "third_party/WebKit/public/web/WebDataSource.h" | 108 #include "third_party/WebKit/public/web/WebDataSource.h" |
107 #include "third_party/WebKit/public/web/WebDocument.h" | 109 #include "third_party/WebKit/public/web/WebDocument.h" |
108 #include "third_party/WebKit/public/web/WebFrame.h" | 110 #include "third_party/WebKit/public/web/WebFrame.h" |
109 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 111 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
110 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" | 112 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
111 #include "third_party/WebKit/public/web/WebScopedUserGesture.h" | 113 #include "third_party/WebKit/public/web/WebScopedUserGesture.h" |
| 114 #include "third_party/WebKit/public/web/WebScriptController.h" |
112 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" | 115 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" |
113 #include "third_party/WebKit/public/web/WebView.h" | 116 #include "third_party/WebKit/public/web/WebView.h" |
114 #include "ui/base/layout.h" | 117 #include "ui/base/layout.h" |
115 #include "ui/base/resource/resource_bundle.h" | 118 #include "ui/base/resource/resource_bundle.h" |
116 #include "v8/include/v8.h" | 119 #include "v8/include/v8.h" |
117 | 120 |
118 using base::UserMetricsAction; | 121 using base::UserMetricsAction; |
119 using blink::WebDataSource; | 122 using blink::WebDataSource; |
120 using blink::WebDocument; | 123 using blink::WebDocument; |
121 using blink::WebScopedUserGesture; | 124 using blink::WebScopedUserGesture; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 } | 228 } |
226 | 229 |
227 script_context_set_.reset(new ScriptContextSet(&active_extension_ids_)); | 230 script_context_set_.reset(new ScriptContextSet(&active_extension_ids_)); |
228 user_script_set_manager_.reset(new UserScriptSetManager()); | 231 user_script_set_manager_.reset(new UserScriptSetManager()); |
229 script_injection_manager_.reset( | 232 script_injection_manager_.reset( |
230 new ScriptInjectionManager(user_script_set_manager_.get())); | 233 new ScriptInjectionManager(user_script_set_manager_.get())); |
231 user_script_set_manager_observer_.Add(user_script_set_manager_.get()); | 234 user_script_set_manager_observer_.Add(user_script_set_manager_.get()); |
232 request_sender_.reset(new RequestSender(this)); | 235 request_sender_.reset(new RequestSender(this)); |
233 PopulateSourceMap(); | 236 PopulateSourceMap(); |
234 WakeEventPage::Get()->Init(RenderThread::Get()); | 237 WakeEventPage::Get()->Init(RenderThread::Get()); |
| 238 // Ideally this should be done after checking |
| 239 // ExtensionAPIEnabledInExtensionServiceWorkers(), but the Dispatcher is |
| 240 // created so early that sending an IPC from browser/ process to synchronize |
| 241 // this enabled-ness is too late. |
| 242 WorkerThreadDispatcher::Get()->Init(RenderThread::Get()); |
235 | 243 |
236 RenderThread::Get()->RegisterExtension(SafeBuiltins::CreateV8Extension()); | 244 RenderThread::Get()->RegisterExtension(SafeBuiltins::CreateV8Extension()); |
237 | 245 |
238 // WebSecurityPolicy whitelists. They should be registered for both | 246 // WebSecurityPolicy whitelists. They should be registered for both |
239 // chrome-extension: and chrome-extension-resource. | 247 // chrome-extension: and chrome-extension-resource. |
240 using RegisterFunction = void (*)(const WebString&); | 248 using RegisterFunction = void (*)(const WebString&); |
241 RegisterFunction register_functions[] = { | 249 RegisterFunction register_functions[] = { |
242 // Treat as secure because communication with them is entirely in the | 250 // Treat as secure because communication with them is entirely in the |
243 // browser, so there is no danger of manipulation or eavesdropping on | 251 // browser, so there is no danger of manipulation or eavesdropping on |
244 // communication with them by third parties. | 252 // communication with them by third parties. |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 { | 331 { |
324 scoped_ptr<ModuleSystem> module_system( | 332 scoped_ptr<ModuleSystem> module_system( |
325 new ModuleSystem(context, &source_map_)); | 333 new ModuleSystem(context, &source_map_)); |
326 context->set_module_system(std::move(module_system)); | 334 context->set_module_system(std::move(module_system)); |
327 } | 335 } |
328 ModuleSystem* module_system = context->module_system(); | 336 ModuleSystem* module_system = context->module_system(); |
329 | 337 |
330 // Enable natives in startup. | 338 // Enable natives in startup. |
331 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system); | 339 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system); |
332 | 340 |
333 RegisterNativeHandlers(module_system, context); | 341 RegisterNativeHandlers(module_system, context, request_sender_.get(), |
| 342 v8_schema_registry_.get()); |
334 | 343 |
335 // chrome.Event is part of the public API (although undocumented). Make it | 344 // chrome.Event is part of the public API (although undocumented). Make it |
336 // lazily evalulate to Event from event_bindings.js. For extensions only | 345 // lazily evalulate to Event from event_bindings.js. For extensions only |
337 // though, not all webpages! | 346 // though, not all webpages! |
338 if (context->extension()) { | 347 if (context->extension()) { |
339 v8::Local<v8::Object> chrome = AsObjectOrEmpty(GetOrCreateChrome(context)); | 348 v8::Local<v8::Object> chrome = AsObjectOrEmpty(GetOrCreateChrome(context)); |
340 if (!chrome.IsEmpty()) | 349 if (!chrome.IsEmpty()) |
341 module_system->SetLazyField(chrome, "Event", kEventBindings, "Event"); | 350 module_system->SetLazyField(chrome, "Event", kEventBindings, "Event"); |
342 } | 351 } |
343 | 352 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 case Feature::SERVICE_WORKER_CONTEXT: | 391 case Feature::SERVICE_WORKER_CONTEXT: |
383 // Handled in DidInitializeServiceWorkerContextOnWorkerThread(). | 392 // Handled in DidInitializeServiceWorkerContextOnWorkerThread(). |
384 NOTREACHED(); | 393 NOTREACHED(); |
385 break; | 394 break; |
386 } | 395 } |
387 | 396 |
388 VLOG(1) << "Num tracked contexts: " << script_context_set_->size(); | 397 VLOG(1) << "Num tracked contexts: " << script_context_set_->size(); |
389 } | 398 } |
390 | 399 |
391 // static | 400 // static |
| 401 void Dispatcher::InstallV8ExtensionForServiceWorkers() { |
| 402 if (feature_util::ExtensionAPIEnabledInExtensionServiceWorkers()) { |
| 403 blink::WebScriptController::registerExtensionForServiceWorkerScript( |
| 404 SafeBuiltins::CreateV8Extension()); |
| 405 } |
| 406 } |
| 407 |
392 void Dispatcher::DidInitializeServiceWorkerContextOnWorkerThread( | 408 void Dispatcher::DidInitializeServiceWorkerContextOnWorkerThread( |
393 v8::Local<v8::Context> v8_context, | 409 v8::Local<v8::Context> v8_context, |
| 410 int embedded_worker_id, |
394 const GURL& url) { | 411 const GURL& url) { |
395 const base::TimeTicks start_time = base::TimeTicks::Now(); | 412 const base::TimeTicks start_time = base::TimeTicks::Now(); |
396 | 413 |
397 if (!url.SchemeIs(kExtensionScheme) && | 414 if (!url.SchemeIs(kExtensionScheme) && |
398 !url.SchemeIs(kExtensionResourceScheme)) { | 415 !url.SchemeIs(kExtensionResourceScheme)) { |
399 // Early-out if this isn't a chrome-extension:// or resource scheme, | 416 // Early-out if this isn't a chrome-extension:// or resource scheme, |
400 // because looking up the extension registry is unnecessary if it's not. | 417 // because looking up the extension registry is unnecessary if it's not. |
401 // Checking this will also skip over hosted apps, which is the desired | 418 // Checking this will also skip over hosted apps, which is the desired |
402 // behavior - hosted app service workers are not our concern. | 419 // behavior - hosted app service workers are not our concern. |
403 return; | 420 return; |
(...skipping 24 matching lines...) Expand all Loading... |
428 // saying that an extension is ready, and documenting that extension APIs | 445 // saying that an extension is ready, and documenting that extension APIs |
429 // won't work before that event has fired? | 446 // won't work before that event has fired? |
430 return; | 447 return; |
431 } | 448 } |
432 | 449 |
433 ScriptContext* context = new ScriptContext( | 450 ScriptContext* context = new ScriptContext( |
434 v8_context, nullptr, extension, Feature::SERVICE_WORKER_CONTEXT, | 451 v8_context, nullptr, extension, Feature::SERVICE_WORKER_CONTEXT, |
435 extension, Feature::SERVICE_WORKER_CONTEXT); | 452 extension, Feature::SERVICE_WORKER_CONTEXT); |
436 context->set_url(url); | 453 context->set_url(url); |
437 | 454 |
| 455 if (feature_util::ExtensionAPIEnabledInExtensionServiceWorkers()) { |
| 456 WorkerThreadDispatcher::Get()->AddWorkerData(embedded_worker_id); |
| 457 { |
| 458 // TODO(lazyboy): Make sure accessing |source_map_| in worker thread is |
| 459 // safe. |
| 460 std::unique_ptr<ModuleSystem> module_system( |
| 461 new ModuleSystem(context, &source_map_)); |
| 462 context->set_module_system(std::move(module_system)); |
| 463 } |
| 464 |
| 465 ModuleSystem* module_system = context->module_system(); |
| 466 // Enable natives in startup. |
| 467 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system); |
| 468 RegisterNativeHandlers( |
| 469 module_system, context, |
| 470 WorkerThreadDispatcher::Get()->GetRequestSender(), |
| 471 WorkerThreadDispatcher::Get()->GetV8SchemaRegistry()); |
| 472 // chrome.Event is part of the public API (although undocumented). Make it |
| 473 // lazily evalulate to Event from event_bindings.js. |
| 474 v8::Local<v8::Object> chrome = AsObjectOrEmpty(GetOrCreateChrome(context)); |
| 475 if (!chrome.IsEmpty()) |
| 476 module_system->SetLazyField(chrome, "Event", kEventBindings, "Event"); |
| 477 |
| 478 UpdateBindingsForContext(context); |
| 479 // TODO(lazyboy): Get rid of RequireGuestViewModules() as this doesn't seem |
| 480 // necessary for Extension SW. |
| 481 RequireGuestViewModules(context); |
| 482 delegate_->RequireAdditionalModules(context, |
| 483 false /* is_within_platform_app */); |
| 484 } |
| 485 |
438 g_worker_script_context_set.Get().Insert(make_scoped_ptr(context)); | 486 g_worker_script_context_set.Get().Insert(make_scoped_ptr(context)); |
439 | 487 |
440 v8::Isolate* isolate = context->isolate(); | 488 v8::Isolate* isolate = context->isolate(); |
441 | 489 |
442 // Fetch the source code for service_worker_bindings.js. | 490 // Fetch the source code for service_worker_bindings.js. |
443 base::StringPiece script_resource = | 491 base::StringPiece script_resource = |
444 ResourceBundle::GetSharedInstance().GetRawDataResource( | 492 ResourceBundle::GetSharedInstance().GetRawDataResource( |
445 IDR_SERVICE_WORKER_BINDINGS_JS); | 493 IDR_SERVICE_WORKER_BINDINGS_JS); |
446 v8::Local<v8::String> script = v8::String::NewExternal( | 494 v8::Local<v8::String> script = v8::String::NewExternal( |
447 isolate, new StaticV8ExternalOneByteStringResource(script_resource)); | 495 isolate, new StaticV8ExternalOneByteStringResource(script_resource)); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 // In fact |request_sender_| should really be owned by ScriptContext. | 540 // In fact |request_sender_| should really be owned by ScriptContext. |
493 request_sender_->InvalidateSource(context); | 541 request_sender_->InvalidateSource(context); |
494 | 542 |
495 script_context_set_->Remove(context); | 543 script_context_set_->Remove(context); |
496 VLOG(1) << "Num tracked contexts: " << script_context_set_->size(); | 544 VLOG(1) << "Num tracked contexts: " << script_context_set_->size(); |
497 } | 545 } |
498 | 546 |
499 // static | 547 // static |
500 void Dispatcher::WillDestroyServiceWorkerContextOnWorkerThread( | 548 void Dispatcher::WillDestroyServiceWorkerContextOnWorkerThread( |
501 v8::Local<v8::Context> v8_context, | 549 v8::Local<v8::Context> v8_context, |
| 550 int embedded_worker_id, |
502 const GURL& url) { | 551 const GURL& url) { |
503 if (url.SchemeIs(kExtensionScheme) || | 552 if (url.SchemeIs(kExtensionScheme) || |
504 url.SchemeIs(kExtensionResourceScheme)) { | 553 url.SchemeIs(kExtensionResourceScheme)) { |
505 // See comment in DidInitializeServiceWorkerContextOnWorkerThread. | 554 // See comment in DidInitializeServiceWorkerContextOnWorkerThread. |
506 g_worker_script_context_set.Get().Remove(v8_context, url); | 555 g_worker_script_context_set.Get().Remove(v8_context, url); |
507 } | 556 } |
| 557 if (feature_util::ExtensionAPIEnabledInExtensionServiceWorkers()) |
| 558 WorkerThreadDispatcher::Get()->RemoveWorkerData(embedded_worker_id); |
508 } | 559 } |
509 | 560 |
510 void Dispatcher::DidCreateDocumentElement(blink::WebLocalFrame* frame) { | 561 void Dispatcher::DidCreateDocumentElement(blink::WebLocalFrame* frame) { |
511 // Note: use GetEffectiveDocumentURL not just frame->document()->url() | 562 // Note: use GetEffectiveDocumentURL not just frame->document()->url() |
512 // so that this also injects the stylesheet on about:blank frames that | 563 // so that this also injects the stylesheet on about:blank frames that |
513 // are hosted in the extension process. | 564 // are hosted in the extension process. |
514 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL( | 565 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL( |
515 frame, frame->document().url(), true /* match_about_blank */); | 566 frame, frame->document().url(), true /* match_about_blank */); |
516 | 567 |
517 const Extension* extension = | 568 const Extension* extension = |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
910 bool handled = true; | 961 bool handled = true; |
911 IPC_BEGIN_MESSAGE_MAP(Dispatcher, message) | 962 IPC_BEGIN_MESSAGE_MAP(Dispatcher, message) |
912 IPC_MESSAGE_HANDLER(ExtensionMsg_ActivateExtension, OnActivateExtension) | 963 IPC_MESSAGE_HANDLER(ExtensionMsg_ActivateExtension, OnActivateExtension) |
913 IPC_MESSAGE_HANDLER(ExtensionMsg_CancelSuspend, OnCancelSuspend) | 964 IPC_MESSAGE_HANDLER(ExtensionMsg_CancelSuspend, OnCancelSuspend) |
914 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnDeliverMessage) | 965 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnDeliverMessage) |
915 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnConnect, OnDispatchOnConnect) | 966 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnConnect, OnDispatchOnConnect) |
916 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnDisconnect, OnDispatchOnDisconnect) | 967 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnDisconnect, OnDispatchOnDisconnect) |
917 IPC_MESSAGE_HANDLER(ExtensionMsg_Loaded, OnLoaded) | 968 IPC_MESSAGE_HANDLER(ExtensionMsg_Loaded, OnLoaded) |
918 IPC_MESSAGE_HANDLER(ExtensionMsg_MessageInvoke, OnMessageInvoke) | 969 IPC_MESSAGE_HANDLER(ExtensionMsg_MessageInvoke, OnMessageInvoke) |
919 IPC_MESSAGE_HANDLER(ExtensionMsg_SetChannel, OnSetChannel) | 970 IPC_MESSAGE_HANDLER(ExtensionMsg_SetChannel, OnSetChannel) |
| 971 IPC_MESSAGE_HANDLER( |
| 972 ExtensionMsg_SetExtensionAPIEnabledInExtensionServiceWorkers, |
| 973 OnSetExtensionAPIEnabledInExtensionServiceWorkers) |
920 IPC_MESSAGE_HANDLER(ExtensionMsg_SetScriptingWhitelist, | 974 IPC_MESSAGE_HANDLER(ExtensionMsg_SetScriptingWhitelist, |
921 OnSetScriptingWhitelist) | 975 OnSetScriptingWhitelist) |
922 IPC_MESSAGE_HANDLER(ExtensionMsg_SetSystemFont, OnSetSystemFont) | 976 IPC_MESSAGE_HANDLER(ExtensionMsg_SetSystemFont, OnSetSystemFont) |
923 IPC_MESSAGE_HANDLER(ExtensionMsg_SetWebViewPartitionID, | 977 IPC_MESSAGE_HANDLER(ExtensionMsg_SetWebViewPartitionID, |
924 OnSetWebViewPartitionID) | 978 OnSetWebViewPartitionID) |
925 IPC_MESSAGE_HANDLER(ExtensionMsg_ShouldSuspend, OnShouldSuspend) | 979 IPC_MESSAGE_HANDLER(ExtensionMsg_ShouldSuspend, OnShouldSuspend) |
926 IPC_MESSAGE_HANDLER(ExtensionMsg_Suspend, OnSuspend) | 980 IPC_MESSAGE_HANDLER(ExtensionMsg_Suspend, OnSuspend) |
927 IPC_MESSAGE_HANDLER(ExtensionMsg_TransferBlobs, OnTransferBlobs) | 981 IPC_MESSAGE_HANDLER(ExtensionMsg_TransferBlobs, OnTransferBlobs) |
928 IPC_MESSAGE_HANDLER(ExtensionMsg_Unloaded, OnUnloaded) | 982 IPC_MESSAGE_HANDLER(ExtensionMsg_Unloaded, OnUnloaded) |
929 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdatePermissions, OnUpdatePermissions) | 983 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdatePermissions, OnUpdatePermissions) |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1084 const base::ListValue& args, | 1138 const base::ListValue& args, |
1085 bool user_gesture) { | 1139 bool user_gesture) { |
1086 InvokeModuleSystemMethod( | 1140 InvokeModuleSystemMethod( |
1087 NULL, extension_id, module_name, function_name, args, user_gesture); | 1141 NULL, extension_id, module_name, function_name, args, user_gesture); |
1088 } | 1142 } |
1089 | 1143 |
1090 void Dispatcher::OnSetChannel(int channel) { | 1144 void Dispatcher::OnSetChannel(int channel) { |
1091 delegate_->SetChannel(channel); | 1145 delegate_->SetChannel(channel); |
1092 } | 1146 } |
1093 | 1147 |
| 1148 void Dispatcher::OnSetExtensionAPIEnabledInExtensionServiceWorkers( |
| 1149 bool enabled) { |
| 1150 feature_util::SetExtensionAPIEnabledInExtensionServiceWorkers(enabled); |
| 1151 } |
| 1152 |
1094 void Dispatcher::OnSetScriptingWhitelist( | 1153 void Dispatcher::OnSetScriptingWhitelist( |
1095 const ExtensionsClient::ScriptingWhitelist& extension_ids) { | 1154 const ExtensionsClient::ScriptingWhitelist& extension_ids) { |
1096 ExtensionsClient::Get()->SetScriptingWhitelist(extension_ids); | 1155 ExtensionsClient::Get()->SetScriptingWhitelist(extension_ids); |
1097 } | 1156 } |
1098 | 1157 |
1099 void Dispatcher::OnSetSystemFont(const std::string& font_family, | 1158 void Dispatcher::OnSetSystemFont(const std::string& font_family, |
1100 const std::string& font_size) { | 1159 const std::string& font_size) { |
1101 system_font_family_ = font_family; | 1160 system_font_family_ = font_family; |
1102 system_font_size_ = font_size; | 1161 system_font_size_ = font_size; |
1103 } | 1162 } |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1310 blink::WebCustomElement::addEmbedderCustomElementName("webview"); | 1369 blink::WebCustomElement::addEmbedderCustomElementName("webview"); |
1311 blink::WebCustomElement::addEmbedderCustomElementName("webviewbrowserplugin"); | 1370 blink::WebCustomElement::addEmbedderCustomElementName("webviewbrowserplugin"); |
1312 } | 1371 } |
1313 | 1372 |
1314 void Dispatcher::UpdateBindings(const std::string& extension_id) { | 1373 void Dispatcher::UpdateBindings(const std::string& extension_id) { |
1315 script_context_set().ForEach(extension_id, | 1374 script_context_set().ForEach(extension_id, |
1316 base::Bind(&Dispatcher::UpdateBindingsForContext, | 1375 base::Bind(&Dispatcher::UpdateBindingsForContext, |
1317 base::Unretained(this))); | 1376 base::Unretained(this))); |
1318 } | 1377 } |
1319 | 1378 |
| 1379 // Note: this function runs on multiple threads: main renderer thread and |
| 1380 // service worker threads. |
1320 void Dispatcher::UpdateBindingsForContext(ScriptContext* context) { | 1381 void Dispatcher::UpdateBindingsForContext(ScriptContext* context) { |
1321 v8::HandleScope handle_scope(context->isolate()); | 1382 v8::HandleScope handle_scope(context->isolate()); |
1322 v8::Context::Scope context_scope(context->v8_context()); | 1383 v8::Context::Scope context_scope(context->v8_context()); |
1323 | 1384 |
1324 // TODO(kalman): Make the bindings registration have zero overhead then run | 1385 // TODO(kalman): Make the bindings registration have zero overhead then run |
1325 // the same code regardless of context type. | 1386 // the same code regardless of context type. |
1326 switch (context->context_type()) { | 1387 switch (context->context_type()) { |
1327 case Feature::UNSPECIFIED_CONTEXT: | 1388 case Feature::UNSPECIFIED_CONTEXT: |
1328 case Feature::WEB_PAGE_CONTEXT: | 1389 case Feature::WEB_PAGE_CONTEXT: |
1329 case Feature::BLESSED_WEB_PAGE_CONTEXT: | 1390 case Feature::BLESSED_WEB_PAGE_CONTEXT: |
1330 // Hard-code registration of any APIs that are exposed to webpage-like | 1391 // Hard-code registration of any APIs that are exposed to webpage-like |
1331 // contexts, because it's too expensive to run the full bindings code. | 1392 // contexts, because it's too expensive to run the full bindings code. |
1332 // All of the same permission checks will still apply. | 1393 // All of the same permission checks will still apply. |
1333 if (context->GetAvailability("app").is_available()) | 1394 if (context->GetAvailability("app").is_available()) |
1334 RegisterBinding("app", context); | 1395 RegisterBinding("app", context); |
1335 if (context->GetAvailability("webstore").is_available()) | 1396 if (context->GetAvailability("webstore").is_available()) |
1336 RegisterBinding("webstore", context); | 1397 RegisterBinding("webstore", context); |
1337 if (context->GetAvailability("dashboardPrivate").is_available()) | 1398 if (context->GetAvailability("dashboardPrivate").is_available()) |
1338 RegisterBinding("dashboardPrivate", context); | 1399 RegisterBinding("dashboardPrivate", context); |
1339 if (IsRuntimeAvailableToContext(context)) | 1400 if (IsRuntimeAvailableToContext(context)) |
1340 RegisterBinding("runtime", context); | 1401 RegisterBinding("runtime", context); |
1341 UpdateContentCapabilities(context); | 1402 UpdateContentCapabilities(context); |
1342 break; | 1403 break; |
1343 | 1404 |
| 1405 case Feature::SERVICE_WORKER_CONTEXT: |
| 1406 DCHECK(feature_util::ExtensionAPIEnabledInExtensionServiceWorkers()); |
| 1407 // Intentional fallthrough. |
1344 case Feature::BLESSED_EXTENSION_CONTEXT: | 1408 case Feature::BLESSED_EXTENSION_CONTEXT: |
1345 case Feature::UNBLESSED_EXTENSION_CONTEXT: | 1409 case Feature::UNBLESSED_EXTENSION_CONTEXT: |
1346 case Feature::CONTENT_SCRIPT_CONTEXT: | 1410 case Feature::CONTENT_SCRIPT_CONTEXT: |
1347 case Feature::WEBUI_CONTEXT: { | 1411 case Feature::WEBUI_CONTEXT: { |
1348 // Extension context; iterate through all the APIs and bind the available | 1412 // Extension context; iterate through all the APIs and bind the available |
1349 // ones. | 1413 // ones. |
1350 const FeatureProvider* api_feature_provider = | 1414 const FeatureProvider* api_feature_provider = |
1351 FeatureProvider::GetAPIFeatures(); | 1415 FeatureProvider::GetAPIFeatures(); |
1352 for (const auto& map_entry : api_feature_provider->GetAllFeatures()) { | 1416 for (const auto& map_entry : api_feature_provider->GetAllFeatures()) { |
1353 // Internal APIs are included via require(api_name) from internal code | 1417 // Internal APIs are included via require(api_name) from internal code |
1354 // rather than chrome[api_name]. | 1418 // rather than chrome[api_name]. |
1355 if (map_entry.second->IsInternal()) | 1419 if (map_entry.second->IsInternal()) |
1356 continue; | 1420 continue; |
1357 | 1421 |
1358 // If this API has a parent feature (and isn't marked 'noparent'), | 1422 // If this API has a parent feature (and isn't marked 'noparent'), |
1359 // then this must be a function or event, so we should not register. | 1423 // then this must be a function or event, so we should not register. |
1360 if (api_feature_provider->GetParent(map_entry.second.get()) != nullptr) | 1424 if (api_feature_provider->GetParent(map_entry.second.get()) != nullptr) |
1361 continue; | 1425 continue; |
1362 | 1426 |
1363 // Skip chrome.test if this isn't a test. | 1427 // Skip chrome.test if this isn't a test. |
1364 if (map_entry.first == "test" && | 1428 if (map_entry.first == "test" && |
1365 !base::CommandLine::ForCurrentProcess()->HasSwitch( | 1429 !base::CommandLine::ForCurrentProcess()->HasSwitch( |
1366 ::switches::kTestType)) { | 1430 ::switches::kTestType)) { |
1367 continue; | 1431 continue; |
1368 } | 1432 } |
1369 | 1433 |
1370 if (context->IsAnyFeatureAvailableToContext(*map_entry.second.get())) | 1434 if (context->IsAnyFeatureAvailableToContext(*map_entry.second.get())) { |
| 1435 // TODO(lazyboy): RegisterBinding() uses |source_map_|, any thread |
| 1436 // safety issue? |
1371 RegisterBinding(map_entry.first, context); | 1437 RegisterBinding(map_entry.first, context); |
| 1438 } |
1372 } | 1439 } |
1373 break; | 1440 break; |
1374 } | 1441 } |
1375 case Feature::SERVICE_WORKER_CONTEXT: | |
1376 // Handled in DidInitializeServiceWorkerContextOnWorkerThread(). | |
1377 NOTREACHED(); | |
1378 break; | |
1379 } | 1442 } |
1380 } | 1443 } |
1381 | 1444 |
1382 void Dispatcher::RegisterBinding(const std::string& api_name, | 1445 void Dispatcher::RegisterBinding(const std::string& api_name, |
1383 ScriptContext* context) { | 1446 ScriptContext* context) { |
1384 std::string bind_name; | 1447 std::string bind_name; |
1385 v8::Local<v8::Object> bind_object = | 1448 v8::Local<v8::Object> bind_object = |
1386 GetOrCreateBindObjectIfAvailable(api_name, &bind_name, context); | 1449 GetOrCreateBindObjectIfAvailable(api_name, &bind_name, context); |
1387 | 1450 |
1388 // Empty if the bind object failed to be created, probably because the | 1451 // Empty if the bind object failed to be created, probably because the |
(...skipping 27 matching lines...) Expand all Loading... |
1416 context, api_name, "binding"))); | 1479 context, api_name, "binding"))); |
1417 module_system->SetNativeLazyField( | 1480 module_system->SetNativeLazyField( |
1418 bind_object, bind_name, api_name, "binding"); | 1481 bind_object, bind_name, api_name, "binding"); |
1419 } else { | 1482 } else { |
1420 module_system->SetLazyField(bind_object, bind_name, api_name, "binding"); | 1483 module_system->SetLazyField(bind_object, bind_name, api_name, "binding"); |
1421 } | 1484 } |
1422 } | 1485 } |
1423 | 1486 |
1424 // NOTE: please use the naming convention "foo_natives" for these. | 1487 // NOTE: please use the naming convention "foo_natives" for these. |
1425 void Dispatcher::RegisterNativeHandlers(ModuleSystem* module_system, | 1488 void Dispatcher::RegisterNativeHandlers(ModuleSystem* module_system, |
1426 ScriptContext* context) { | 1489 ScriptContext* context, |
1427 RegisterNativeHandlers(module_system, | 1490 RequestSender* request_sender, |
1428 context, | 1491 V8SchemaRegistry* v8_schema_registry) { |
1429 this, | 1492 RegisterNativeHandlers(module_system, context, this, request_sender, |
1430 request_sender_.get(), | 1493 v8_schema_registry); |
1431 v8_schema_registry_.get()); | |
1432 const Extension* extension = context->extension(); | 1494 const Extension* extension = context->extension(); |
1433 int manifest_version = extension ? extension->manifest_version() : 1; | 1495 int manifest_version = extension ? extension->manifest_version() : 1; |
1434 bool is_component_extension = | 1496 bool is_component_extension = |
1435 extension && Manifest::IsComponentLocation(extension->location()); | 1497 extension && Manifest::IsComponentLocation(extension->location()); |
1436 bool send_request_disabled = | 1498 bool send_request_disabled = |
1437 (extension && Manifest::IsUnpackedLocation(extension->location()) && | 1499 (extension && Manifest::IsUnpackedLocation(extension->location()) && |
1438 BackgroundInfo::HasLazyBackgroundPage(extension)); | 1500 BackgroundInfo::HasLazyBackgroundPage(extension)); |
1439 module_system->RegisterNativeHandler( | 1501 module_system->RegisterNativeHandler( |
1440 "process", | 1502 "process", |
1441 scoped_ptr<NativeHandler>(new ProcessInfoNativeHandler( | 1503 scoped_ptr<NativeHandler>(new ProcessInfoNativeHandler( |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1492 iter != active_extension_ids_.end(); | 1554 iter != active_extension_ids_.end(); |
1493 ++iter) { | 1555 ++iter) { |
1494 const Extension* extension = | 1556 const Extension* extension = |
1495 RendererExtensionRegistry::Get()->GetByID(*iter); | 1557 RendererExtensionRegistry::Get()->GetByID(*iter); |
1496 if (extension && extension->is_platform_app()) | 1558 if (extension && extension->is_platform_app()) |
1497 return true; | 1559 return true; |
1498 } | 1560 } |
1499 return false; | 1561 return false; |
1500 } | 1562 } |
1501 | 1563 |
| 1564 // static. |
1502 v8::Local<v8::Object> Dispatcher::GetOrCreateObject( | 1565 v8::Local<v8::Object> Dispatcher::GetOrCreateObject( |
1503 const v8::Local<v8::Object>& object, | 1566 const v8::Local<v8::Object>& object, |
1504 const std::string& field, | 1567 const std::string& field, |
1505 v8::Isolate* isolate) { | 1568 v8::Isolate* isolate) { |
1506 v8::Local<v8::String> key = v8::String::NewFromUtf8(isolate, field.c_str()); | 1569 v8::Local<v8::String> key = v8::String::NewFromUtf8(isolate, field.c_str()); |
1507 // If the object has a callback property, it is assumed it is an unavailable | 1570 // If the object has a callback property, it is assumed it is an unavailable |
1508 // API, so it is safe to delete. This is checked before GetOrCreateObject is | 1571 // API, so it is safe to delete. This is checked before GetOrCreateObject is |
1509 // called. | 1572 // called. |
1510 if (object->HasRealNamedCallbackProperty(key)) { | 1573 if (object->HasRealNamedCallbackProperty(key)) { |
1511 object->Delete(key); | 1574 object->Delete(key); |
1512 } else if (object->HasRealNamedProperty(key)) { | 1575 } else if (object->HasRealNamedProperty(key)) { |
1513 v8::Local<v8::Value> value = object->Get(key); | 1576 v8::Local<v8::Value> value = object->Get(key); |
1514 CHECK(value->IsObject()); | 1577 CHECK(value->IsObject()); |
1515 return v8::Local<v8::Object>::Cast(value); | 1578 return v8::Local<v8::Object>::Cast(value); |
1516 } | 1579 } |
1517 | 1580 |
1518 v8::Local<v8::Object> new_object = v8::Object::New(isolate); | 1581 v8::Local<v8::Object> new_object = v8::Object::New(isolate); |
1519 object->Set(key, new_object); | 1582 object->Set(key, new_object); |
1520 return new_object; | 1583 return new_object; |
1521 } | 1584 } |
1522 | 1585 |
| 1586 // static. |
1523 v8::Local<v8::Object> Dispatcher::GetOrCreateBindObjectIfAvailable( | 1587 v8::Local<v8::Object> Dispatcher::GetOrCreateBindObjectIfAvailable( |
1524 const std::string& api_name, | 1588 const std::string& api_name, |
1525 std::string* bind_name, | 1589 std::string* bind_name, |
1526 ScriptContext* context) { | 1590 ScriptContext* context) { |
1527 std::vector<std::string> split = base::SplitString( | 1591 std::vector<std::string> split = base::SplitString( |
1528 api_name, ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 1592 api_name, ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
1529 | 1593 |
1530 v8::Local<v8::Object> bind_object; | 1594 v8::Local<v8::Object> bind_object; |
1531 | 1595 |
1532 // Check if this API has an ancestor. If the API's ancestor is available and | 1596 // Check if this API has an ancestor. If the API's ancestor is available and |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1623 // The "guestViewDeny" module must always be loaded last. It registers | 1687 // The "guestViewDeny" module must always be loaded last. It registers |
1624 // error-providing custom elements for the GuestView types that are not | 1688 // error-providing custom elements for the GuestView types that are not |
1625 // available, and thus all of those types must have been checked and loaded | 1689 // available, and thus all of those types must have been checked and loaded |
1626 // (or not loaded) beforehand. | 1690 // (or not loaded) beforehand. |
1627 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { | 1691 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { |
1628 module_system->Require("guestViewDeny"); | 1692 module_system->Require("guestViewDeny"); |
1629 } | 1693 } |
1630 } | 1694 } |
1631 | 1695 |
1632 } // namespace extensions | 1696 } // namespace extensions |
OLD | NEW |