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 (ExtensionsClient::Get()->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 (ExtensionsClient::Get()->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 (ExtensionsClient::Get()->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 792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1310 blink::WebCustomElement::addEmbedderCustomElementName("webview"); | 1361 blink::WebCustomElement::addEmbedderCustomElementName("webview"); |
1311 blink::WebCustomElement::addEmbedderCustomElementName("webviewbrowserplugin"); | 1362 blink::WebCustomElement::addEmbedderCustomElementName("webviewbrowserplugin"); |
1312 } | 1363 } |
1313 | 1364 |
1314 void Dispatcher::UpdateBindings(const std::string& extension_id) { | 1365 void Dispatcher::UpdateBindings(const std::string& extension_id) { |
1315 script_context_set().ForEach(extension_id, | 1366 script_context_set().ForEach(extension_id, |
1316 base::Bind(&Dispatcher::UpdateBindingsForContext, | 1367 base::Bind(&Dispatcher::UpdateBindingsForContext, |
1317 base::Unretained(this))); | 1368 base::Unretained(this))); |
1318 } | 1369 } |
1319 | 1370 |
| 1371 // Note: this function runs on multiple threads: main renderer thread and |
| 1372 // service worker threads. |
1320 void Dispatcher::UpdateBindingsForContext(ScriptContext* context) { | 1373 void Dispatcher::UpdateBindingsForContext(ScriptContext* context) { |
1321 v8::HandleScope handle_scope(context->isolate()); | 1374 v8::HandleScope handle_scope(context->isolate()); |
1322 v8::Context::Scope context_scope(context->v8_context()); | 1375 v8::Context::Scope context_scope(context->v8_context()); |
1323 | 1376 |
1324 // TODO(kalman): Make the bindings registration have zero overhead then run | 1377 // TODO(kalman): Make the bindings registration have zero overhead then run |
1325 // the same code regardless of context type. | 1378 // the same code regardless of context type. |
1326 switch (context->context_type()) { | 1379 switch (context->context_type()) { |
1327 case Feature::UNSPECIFIED_CONTEXT: | 1380 case Feature::UNSPECIFIED_CONTEXT: |
1328 case Feature::WEB_PAGE_CONTEXT: | 1381 case Feature::WEB_PAGE_CONTEXT: |
1329 case Feature::BLESSED_WEB_PAGE_CONTEXT: | 1382 case Feature::BLESSED_WEB_PAGE_CONTEXT: |
1330 // Hard-code registration of any APIs that are exposed to webpage-like | 1383 // 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. | 1384 // contexts, because it's too expensive to run the full bindings code. |
1332 // All of the same permission checks will still apply. | 1385 // All of the same permission checks will still apply. |
1333 if (context->GetAvailability("app").is_available()) | 1386 if (context->GetAvailability("app").is_available()) |
1334 RegisterBinding("app", context); | 1387 RegisterBinding("app", context); |
1335 if (context->GetAvailability("webstore").is_available()) | 1388 if (context->GetAvailability("webstore").is_available()) |
1336 RegisterBinding("webstore", context); | 1389 RegisterBinding("webstore", context); |
1337 if (context->GetAvailability("dashboardPrivate").is_available()) | 1390 if (context->GetAvailability("dashboardPrivate").is_available()) |
1338 RegisterBinding("dashboardPrivate", context); | 1391 RegisterBinding("dashboardPrivate", context); |
1339 if (IsRuntimeAvailableToContext(context)) | 1392 if (IsRuntimeAvailableToContext(context)) |
1340 RegisterBinding("runtime", context); | 1393 RegisterBinding("runtime", context); |
1341 UpdateContentCapabilities(context); | 1394 UpdateContentCapabilities(context); |
1342 break; | 1395 break; |
1343 | 1396 |
| 1397 case Feature::SERVICE_WORKER_CONTEXT: |
| 1398 DCHECK(ExtensionsClient::Get() |
| 1399 ->ExtensionAPIEnabledInExtensionServiceWorkers()); |
| 1400 // Intentional fallthrough. |
1344 case Feature::BLESSED_EXTENSION_CONTEXT: | 1401 case Feature::BLESSED_EXTENSION_CONTEXT: |
1345 case Feature::UNBLESSED_EXTENSION_CONTEXT: | 1402 case Feature::UNBLESSED_EXTENSION_CONTEXT: |
1346 case Feature::CONTENT_SCRIPT_CONTEXT: | 1403 case Feature::CONTENT_SCRIPT_CONTEXT: |
1347 case Feature::WEBUI_CONTEXT: { | 1404 case Feature::WEBUI_CONTEXT: { |
1348 // Extension context; iterate through all the APIs and bind the available | 1405 // Extension context; iterate through all the APIs and bind the available |
1349 // ones. | 1406 // ones. |
1350 const FeatureProvider* api_feature_provider = | 1407 const FeatureProvider* api_feature_provider = |
1351 FeatureProvider::GetAPIFeatures(); | 1408 FeatureProvider::GetAPIFeatures(); |
1352 for (const auto& map_entry : api_feature_provider->GetAllFeatures()) { | 1409 for (const auto& map_entry : api_feature_provider->GetAllFeatures()) { |
1353 // Internal APIs are included via require(api_name) from internal code | 1410 // Internal APIs are included via require(api_name) from internal code |
1354 // rather than chrome[api_name]. | 1411 // rather than chrome[api_name]. |
1355 if (map_entry.second->IsInternal()) | 1412 if (map_entry.second->IsInternal()) |
1356 continue; | 1413 continue; |
1357 | 1414 |
1358 // If this API has a parent feature (and isn't marked 'noparent'), | 1415 // 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. | 1416 // then this must be a function or event, so we should not register. |
1360 if (api_feature_provider->GetParent(map_entry.second.get()) != nullptr) | 1417 if (api_feature_provider->GetParent(map_entry.second.get()) != nullptr) |
1361 continue; | 1418 continue; |
1362 | 1419 |
1363 // Skip chrome.test if this isn't a test. | 1420 // Skip chrome.test if this isn't a test. |
1364 if (map_entry.first == "test" && | 1421 if (map_entry.first == "test" && |
1365 !base::CommandLine::ForCurrentProcess()->HasSwitch( | 1422 !base::CommandLine::ForCurrentProcess()->HasSwitch( |
1366 ::switches::kTestType)) { | 1423 ::switches::kTestType)) { |
1367 continue; | 1424 continue; |
1368 } | 1425 } |
1369 | 1426 |
1370 if (context->IsAnyFeatureAvailableToContext(*map_entry.second.get())) | 1427 if (context->IsAnyFeatureAvailableToContext(*map_entry.second.get())) { |
| 1428 // TODO(lazyboy): RegisterBinding() uses |source_map_|, any thread |
| 1429 // safety issue? |
1371 RegisterBinding(map_entry.first, context); | 1430 RegisterBinding(map_entry.first, context); |
| 1431 } |
1372 } | 1432 } |
1373 break; | 1433 break; |
1374 } | 1434 } |
1375 case Feature::SERVICE_WORKER_CONTEXT: | |
1376 // Handled in DidInitializeServiceWorkerContextOnWorkerThread(). | |
1377 NOTREACHED(); | |
1378 break; | |
1379 } | 1435 } |
1380 } | 1436 } |
1381 | 1437 |
1382 void Dispatcher::RegisterBinding(const std::string& api_name, | 1438 void Dispatcher::RegisterBinding(const std::string& api_name, |
1383 ScriptContext* context) { | 1439 ScriptContext* context) { |
1384 std::string bind_name; | 1440 std::string bind_name; |
1385 v8::Local<v8::Object> bind_object = | 1441 v8::Local<v8::Object> bind_object = |
1386 GetOrCreateBindObjectIfAvailable(api_name, &bind_name, context); | 1442 GetOrCreateBindObjectIfAvailable(api_name, &bind_name, context); |
1387 | 1443 |
1388 // Empty if the bind object failed to be created, probably because the | 1444 // Empty if the bind object failed to be created, probably because the |
(...skipping 27 matching lines...) Expand all Loading... |
1416 context, api_name, "binding"))); | 1472 context, api_name, "binding"))); |
1417 module_system->SetNativeLazyField( | 1473 module_system->SetNativeLazyField( |
1418 bind_object, bind_name, api_name, "binding"); | 1474 bind_object, bind_name, api_name, "binding"); |
1419 } else { | 1475 } else { |
1420 module_system->SetLazyField(bind_object, bind_name, api_name, "binding"); | 1476 module_system->SetLazyField(bind_object, bind_name, api_name, "binding"); |
1421 } | 1477 } |
1422 } | 1478 } |
1423 | 1479 |
1424 // NOTE: please use the naming convention "foo_natives" for these. | 1480 // NOTE: please use the naming convention "foo_natives" for these. |
1425 void Dispatcher::RegisterNativeHandlers(ModuleSystem* module_system, | 1481 void Dispatcher::RegisterNativeHandlers(ModuleSystem* module_system, |
1426 ScriptContext* context) { | 1482 ScriptContext* context, |
1427 RegisterNativeHandlers(module_system, | 1483 RequestSender* request_sender, |
1428 context, | 1484 V8SchemaRegistry* v8_schema_registry) { |
1429 this, | 1485 RegisterNativeHandlers(module_system, context, this, request_sender, |
1430 request_sender_.get(), | 1486 v8_schema_registry); |
1431 v8_schema_registry_.get()); | |
1432 const Extension* extension = context->extension(); | 1487 const Extension* extension = context->extension(); |
1433 int manifest_version = extension ? extension->manifest_version() : 1; | 1488 int manifest_version = extension ? extension->manifest_version() : 1; |
1434 bool is_component_extension = | 1489 bool is_component_extension = |
1435 extension && Manifest::IsComponentLocation(extension->location()); | 1490 extension && Manifest::IsComponentLocation(extension->location()); |
1436 bool send_request_disabled = | 1491 bool send_request_disabled = |
1437 (extension && Manifest::IsUnpackedLocation(extension->location()) && | 1492 (extension && Manifest::IsUnpackedLocation(extension->location()) && |
1438 BackgroundInfo::HasLazyBackgroundPage(extension)); | 1493 BackgroundInfo::HasLazyBackgroundPage(extension)); |
1439 module_system->RegisterNativeHandler( | 1494 module_system->RegisterNativeHandler( |
1440 "process", | 1495 "process", |
1441 scoped_ptr<NativeHandler>(new ProcessInfoNativeHandler( | 1496 scoped_ptr<NativeHandler>(new ProcessInfoNativeHandler( |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1492 iter != active_extension_ids_.end(); | 1547 iter != active_extension_ids_.end(); |
1493 ++iter) { | 1548 ++iter) { |
1494 const Extension* extension = | 1549 const Extension* extension = |
1495 RendererExtensionRegistry::Get()->GetByID(*iter); | 1550 RendererExtensionRegistry::Get()->GetByID(*iter); |
1496 if (extension && extension->is_platform_app()) | 1551 if (extension && extension->is_platform_app()) |
1497 return true; | 1552 return true; |
1498 } | 1553 } |
1499 return false; | 1554 return false; |
1500 } | 1555 } |
1501 | 1556 |
| 1557 // static. |
1502 v8::Local<v8::Object> Dispatcher::GetOrCreateObject( | 1558 v8::Local<v8::Object> Dispatcher::GetOrCreateObject( |
1503 const v8::Local<v8::Object>& object, | 1559 const v8::Local<v8::Object>& object, |
1504 const std::string& field, | 1560 const std::string& field, |
1505 v8::Isolate* isolate) { | 1561 v8::Isolate* isolate) { |
1506 v8::Local<v8::String> key = v8::String::NewFromUtf8(isolate, field.c_str()); | 1562 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 | 1563 // 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 | 1564 // API, so it is safe to delete. This is checked before GetOrCreateObject is |
1509 // called. | 1565 // called. |
1510 if (object->HasRealNamedCallbackProperty(key)) { | 1566 if (object->HasRealNamedCallbackProperty(key)) { |
1511 object->Delete(key); | 1567 object->Delete(key); |
1512 } else if (object->HasRealNamedProperty(key)) { | 1568 } else if (object->HasRealNamedProperty(key)) { |
1513 v8::Local<v8::Value> value = object->Get(key); | 1569 v8::Local<v8::Value> value = object->Get(key); |
1514 CHECK(value->IsObject()); | 1570 CHECK(value->IsObject()); |
1515 return v8::Local<v8::Object>::Cast(value); | 1571 return v8::Local<v8::Object>::Cast(value); |
1516 } | 1572 } |
1517 | 1573 |
1518 v8::Local<v8::Object> new_object = v8::Object::New(isolate); | 1574 v8::Local<v8::Object> new_object = v8::Object::New(isolate); |
1519 object->Set(key, new_object); | 1575 object->Set(key, new_object); |
1520 return new_object; | 1576 return new_object; |
1521 } | 1577 } |
1522 | 1578 |
| 1579 // static. |
1523 v8::Local<v8::Object> Dispatcher::GetOrCreateBindObjectIfAvailable( | 1580 v8::Local<v8::Object> Dispatcher::GetOrCreateBindObjectIfAvailable( |
1524 const std::string& api_name, | 1581 const std::string& api_name, |
1525 std::string* bind_name, | 1582 std::string* bind_name, |
1526 ScriptContext* context) { | 1583 ScriptContext* context) { |
1527 std::vector<std::string> split = base::SplitString( | 1584 std::vector<std::string> split = base::SplitString( |
1528 api_name, ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 1585 api_name, ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
1529 | 1586 |
1530 v8::Local<v8::Object> bind_object; | 1587 v8::Local<v8::Object> bind_object; |
1531 | 1588 |
1532 // Check if this API has an ancestor. If the API's ancestor is available and | 1589 // 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 | 1680 // The "guestViewDeny" module must always be loaded last. It registers |
1624 // error-providing custom elements for the GuestView types that are not | 1681 // 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 | 1682 // available, and thus all of those types must have been checked and loaded |
1626 // (or not loaded) beforehand. | 1683 // (or not loaded) beforehand. |
1627 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { | 1684 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { |
1628 module_system->Require("guestViewDeny"); | 1685 module_system->Require("guestViewDeny"); |
1629 } | 1686 } |
1630 } | 1687 } |
1631 | 1688 |
1632 } // namespace extensions | 1689 } // namespace extensions |
OLD | NEW |