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 24 matching lines...) Expand all Loading... |
35 #include "content/public/renderer/render_thread.h" | 35 #include "content/public/renderer/render_thread.h" |
36 #include "extensions/common/api/messaging/message.h" | 36 #include "extensions/common/api/messaging/message.h" |
37 #include "extensions/common/constants.h" | 37 #include "extensions/common/constants.h" |
38 #include "extensions/common/extension_api.h" | 38 #include "extensions/common/extension_api.h" |
39 #include "extensions/common/extension_messages.h" | 39 #include "extensions/common/extension_messages.h" |
40 #include "extensions/common/extension_urls.h" | 40 #include "extensions/common/extension_urls.h" |
41 #include "extensions/common/feature_switch.h" | 41 #include "extensions/common/feature_switch.h" |
42 #include "extensions/common/features/behavior_feature.h" | 42 #include "extensions/common/features/behavior_feature.h" |
43 #include "extensions/common/features/feature.h" | 43 #include "extensions/common/features/feature.h" |
44 #include "extensions/common/features/feature_provider.h" | 44 #include "extensions/common/features/feature_provider.h" |
| 45 #include "extensions/common/features/feature_util.h" |
45 #include "extensions/common/manifest.h" | 46 #include "extensions/common/manifest.h" |
46 #include "extensions/common/manifest_constants.h" | 47 #include "extensions/common/manifest_constants.h" |
47 #include "extensions/common/manifest_handlers/background_info.h" | 48 #include "extensions/common/manifest_handlers/background_info.h" |
48 #include "extensions/common/manifest_handlers/content_capabilities_handler.h" | 49 #include "extensions/common/manifest_handlers/content_capabilities_handler.h" |
49 #include "extensions/common/manifest_handlers/externally_connectable.h" | 50 #include "extensions/common/manifest_handlers/externally_connectable.h" |
50 #include "extensions/common/manifest_handlers/options_page_info.h" | 51 #include "extensions/common/manifest_handlers/options_page_info.h" |
51 #include "extensions/common/message_bundle.h" | 52 #include "extensions/common/message_bundle.h" |
52 #include "extensions/common/permissions/permission_set.h" | 53 #include "extensions/common/permissions/permission_set.h" |
53 #include "extensions/common/permissions/permissions_data.h" | 54 #include "extensions/common/permissions/permissions_data.h" |
54 #include "extensions/common/switches.h" | 55 #include "extensions/common/switches.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 #include "extensions/renderer/set_icon_natives.h" | 90 #include "extensions/renderer/set_icon_natives.h" |
90 #include "extensions/renderer/static_v8_external_one_byte_string_resource.h" | 91 #include "extensions/renderer/static_v8_external_one_byte_string_resource.h" |
91 #include "extensions/renderer/test_features_native_handler.h" | 92 #include "extensions/renderer/test_features_native_handler.h" |
92 #include "extensions/renderer/test_native_handler.h" | 93 #include "extensions/renderer/test_native_handler.h" |
93 #include "extensions/renderer/user_gestures_native_handler.h" | 94 #include "extensions/renderer/user_gestures_native_handler.h" |
94 #include "extensions/renderer/utils_native_handler.h" | 95 #include "extensions/renderer/utils_native_handler.h" |
95 #include "extensions/renderer/v8_context_native_handler.h" | 96 #include "extensions/renderer/v8_context_native_handler.h" |
96 #include "extensions/renderer/v8_helpers.h" | 97 #include "extensions/renderer/v8_helpers.h" |
97 #include "extensions/renderer/wake_event_page.h" | 98 #include "extensions/renderer/wake_event_page.h" |
98 #include "extensions/renderer/worker_script_context_set.h" | 99 #include "extensions/renderer/worker_script_context_set.h" |
| 100 #include "extensions/renderer/worker_thread_dispatcher.h" |
99 #include "grit/extensions_renderer_resources.h" | 101 #include "grit/extensions_renderer_resources.h" |
100 #include "mojo/public/js/constants.h" | 102 #include "mojo/public/js/constants.h" |
101 #include "third_party/WebKit/public/platform/WebString.h" | 103 #include "third_party/WebKit/public/platform/WebString.h" |
102 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 104 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
103 #include "third_party/WebKit/public/web/WebCustomElement.h" | 105 #include "third_party/WebKit/public/web/WebCustomElement.h" |
104 #include "third_party/WebKit/public/web/WebDataSource.h" | 106 #include "third_party/WebKit/public/web/WebDataSource.h" |
105 #include "third_party/WebKit/public/web/WebDocument.h" | 107 #include "third_party/WebKit/public/web/WebDocument.h" |
106 #include "third_party/WebKit/public/web/WebFrame.h" | 108 #include "third_party/WebKit/public/web/WebFrame.h" |
107 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 109 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
108 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" | 110 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
109 #include "third_party/WebKit/public/web/WebScopedUserGesture.h" | 111 #include "third_party/WebKit/public/web/WebScopedUserGesture.h" |
| 112 #include "third_party/WebKit/public/web/WebScriptController.h" |
110 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" | 113 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" |
111 #include "third_party/WebKit/public/web/WebView.h" | 114 #include "third_party/WebKit/public/web/WebView.h" |
112 #include "ui/base/layout.h" | 115 #include "ui/base/layout.h" |
113 #include "ui/base/resource/resource_bundle.h" | 116 #include "ui/base/resource/resource_bundle.h" |
114 #include "v8/include/v8.h" | 117 #include "v8/include/v8.h" |
115 | 118 |
116 using base::UserMetricsAction; | 119 using base::UserMetricsAction; |
117 using blink::WebDataSource; | 120 using blink::WebDataSource; |
118 using blink::WebDocument; | 121 using blink::WebDocument; |
119 using blink::WebScopedUserGesture; | 122 using blink::WebScopedUserGesture; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 } | 226 } |
224 | 227 |
225 script_context_set_.reset(new ScriptContextSet(&active_extension_ids_)); | 228 script_context_set_.reset(new ScriptContextSet(&active_extension_ids_)); |
226 user_script_set_manager_.reset(new UserScriptSetManager()); | 229 user_script_set_manager_.reset(new UserScriptSetManager()); |
227 script_injection_manager_.reset( | 230 script_injection_manager_.reset( |
228 new ScriptInjectionManager(user_script_set_manager_.get())); | 231 new ScriptInjectionManager(user_script_set_manager_.get())); |
229 user_script_set_manager_observer_.Add(user_script_set_manager_.get()); | 232 user_script_set_manager_observer_.Add(user_script_set_manager_.get()); |
230 request_sender_.reset(new RequestSender(this)); | 233 request_sender_.reset(new RequestSender(this)); |
231 PopulateSourceMap(); | 234 PopulateSourceMap(); |
232 WakeEventPage::Get()->Init(RenderThread::Get()); | 235 WakeEventPage::Get()->Init(RenderThread::Get()); |
| 236 // Ideally this should be done after checking |
| 237 // ExtensionAPIEnabledInExtensionServiceWorkers(), but the Dispatcher is |
| 238 // created so early that sending an IPC from browser/ process to synchronize |
| 239 // this enabled-ness is too late. |
| 240 WorkerThreadDispatcher::Get()->Init(RenderThread::Get()); |
233 | 241 |
234 RenderThread::Get()->RegisterExtension(SafeBuiltins::CreateV8Extension()); | 242 RenderThread::Get()->RegisterExtension(SafeBuiltins::CreateV8Extension()); |
235 | 243 |
236 // WebSecurityPolicy whitelists. They should be registered for both | 244 // WebSecurityPolicy whitelists. They should be registered for both |
237 // chrome-extension: and chrome-extension-resource. | 245 // chrome-extension: and chrome-extension-resource. |
238 using RegisterFunction = void (*)(const WebString&); | 246 using RegisterFunction = void (*)(const WebString&); |
239 RegisterFunction register_functions[] = { | 247 RegisterFunction register_functions[] = { |
240 // Treat as secure because communication with them is entirely in the | 248 // Treat as secure because communication with them is entirely in the |
241 // browser, so there is no danger of manipulation or eavesdropping on | 249 // browser, so there is no danger of manipulation or eavesdropping on |
242 // communication with them by third parties. | 250 // communication with them by third parties. |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 { | 329 { |
322 std::unique_ptr<ModuleSystem> module_system( | 330 std::unique_ptr<ModuleSystem> module_system( |
323 new ModuleSystem(context, &source_map_)); | 331 new ModuleSystem(context, &source_map_)); |
324 context->set_module_system(std::move(module_system)); | 332 context->set_module_system(std::move(module_system)); |
325 } | 333 } |
326 ModuleSystem* module_system = context->module_system(); | 334 ModuleSystem* module_system = context->module_system(); |
327 | 335 |
328 // Enable natives in startup. | 336 // Enable natives in startup. |
329 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system); | 337 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system); |
330 | 338 |
331 RegisterNativeHandlers(module_system, context); | 339 RegisterNativeHandlers(module_system, context, request_sender_.get(), |
| 340 v8_schema_registry_.get()); |
332 | 341 |
333 // chrome.Event is part of the public API (although undocumented). Make it | 342 // chrome.Event is part of the public API (although undocumented). Make it |
334 // lazily evalulate to Event from event_bindings.js. For extensions only | 343 // lazily evalulate to Event from event_bindings.js. For extensions only |
335 // though, not all webpages! | 344 // though, not all webpages! |
336 if (context->extension()) { | 345 if (context->extension()) { |
337 v8::Local<v8::Object> chrome = AsObjectOrEmpty(GetOrCreateChrome(context)); | 346 v8::Local<v8::Object> chrome = AsObjectOrEmpty(GetOrCreateChrome(context)); |
338 if (!chrome.IsEmpty()) | 347 if (!chrome.IsEmpty()) |
339 module_system->SetLazyField(chrome, "Event", kEventBindings, "Event"); | 348 module_system->SetLazyField(chrome, "Event", kEventBindings, "Event"); |
340 } | 349 } |
341 | 350 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 break; | 388 break; |
380 case Feature::SERVICE_WORKER_CONTEXT: | 389 case Feature::SERVICE_WORKER_CONTEXT: |
381 // Handled in DidInitializeServiceWorkerContextOnWorkerThread(). | 390 // Handled in DidInitializeServiceWorkerContextOnWorkerThread(). |
382 NOTREACHED(); | 391 NOTREACHED(); |
383 break; | 392 break; |
384 } | 393 } |
385 | 394 |
386 VLOG(1) << "Num tracked contexts: " << script_context_set_->size(); | 395 VLOG(1) << "Num tracked contexts: " << script_context_set_->size(); |
387 } | 396 } |
388 | 397 |
389 // static | |
390 void Dispatcher::DidInitializeServiceWorkerContextOnWorkerThread( | 398 void Dispatcher::DidInitializeServiceWorkerContextOnWorkerThread( |
391 v8::Local<v8::Context> v8_context, | 399 v8::Local<v8::Context> v8_context, |
| 400 int embedded_worker_id, |
392 const GURL& url) { | 401 const GURL& url) { |
393 const base::TimeTicks start_time = base::TimeTicks::Now(); | 402 const base::TimeTicks start_time = base::TimeTicks::Now(); |
394 | 403 |
395 if (!url.SchemeIs(kExtensionScheme) && | 404 if (!url.SchemeIs(kExtensionScheme) && |
396 !url.SchemeIs(kExtensionResourceScheme)) { | 405 !url.SchemeIs(kExtensionResourceScheme)) { |
397 // Early-out if this isn't a chrome-extension:// or resource scheme, | 406 // Early-out if this isn't a chrome-extension:// or resource scheme, |
398 // because looking up the extension registry is unnecessary if it's not. | 407 // because looking up the extension registry is unnecessary if it's not. |
399 // Checking this will also skip over hosted apps, which is the desired | 408 // Checking this will also skip over hosted apps, which is the desired |
400 // behavior - hosted app service workers are not our concern. | 409 // behavior - hosted app service workers are not our concern. |
401 return; | 410 return; |
(...skipping 24 matching lines...) Expand all Loading... |
426 // saying that an extension is ready, and documenting that extension APIs | 435 // saying that an extension is ready, and documenting that extension APIs |
427 // won't work before that event has fired? | 436 // won't work before that event has fired? |
428 return; | 437 return; |
429 } | 438 } |
430 | 439 |
431 ScriptContext* context = new ScriptContext( | 440 ScriptContext* context = new ScriptContext( |
432 v8_context, nullptr, extension, Feature::SERVICE_WORKER_CONTEXT, | 441 v8_context, nullptr, extension, Feature::SERVICE_WORKER_CONTEXT, |
433 extension, Feature::SERVICE_WORKER_CONTEXT); | 442 extension, Feature::SERVICE_WORKER_CONTEXT); |
434 context->set_url(url); | 443 context->set_url(url); |
435 | 444 |
| 445 if (ExtensionsClient::Get()->ExtensionAPIEnabledInExtensionServiceWorkers()) { |
| 446 WorkerThreadDispatcher::Get()->AddWorkerData(embedded_worker_id); |
| 447 { |
| 448 // TODO(lazyboy): Make sure accessing |source_map_| in worker thread is |
| 449 // safe. |
| 450 std::unique_ptr<ModuleSystem> module_system( |
| 451 new ModuleSystem(context, &source_map_)); |
| 452 context->set_module_system(std::move(module_system)); |
| 453 } |
| 454 |
| 455 ModuleSystem* module_system = context->module_system(); |
| 456 // Enable natives in startup. |
| 457 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system); |
| 458 RegisterNativeHandlers( |
| 459 module_system, context, |
| 460 WorkerThreadDispatcher::Get()->GetRequestSender(), |
| 461 WorkerThreadDispatcher::Get()->GetV8SchemaRegistry()); |
| 462 // chrome.Event is part of the public API (although undocumented). Make it |
| 463 // lazily evalulate to Event from event_bindings.js. |
| 464 v8::Local<v8::Object> chrome = AsObjectOrEmpty(GetOrCreateChrome(context)); |
| 465 if (!chrome.IsEmpty()) |
| 466 module_system->SetLazyField(chrome, "Event", kEventBindings, "Event"); |
| 467 |
| 468 UpdateBindingsForContext(context); |
| 469 // TODO(lazyboy): Get rid of RequireGuestViewModules() as this doesn't seem |
| 470 // necessary for Extension SW. |
| 471 RequireGuestViewModules(context); |
| 472 delegate_->RequireAdditionalModules(context, |
| 473 false /* is_within_platform_app */); |
| 474 } |
| 475 |
436 g_worker_script_context_set.Get().Insert(base::WrapUnique(context)); | 476 g_worker_script_context_set.Get().Insert(base::WrapUnique(context)); |
437 | 477 |
438 v8::Isolate* isolate = context->isolate(); | 478 v8::Isolate* isolate = context->isolate(); |
439 | 479 |
440 // Fetch the source code for service_worker_bindings.js. | 480 // Fetch the source code for service_worker_bindings.js. |
441 base::StringPiece script_resource = | 481 base::StringPiece script_resource = |
442 ResourceBundle::GetSharedInstance().GetRawDataResource( | 482 ResourceBundle::GetSharedInstance().GetRawDataResource( |
443 IDR_SERVICE_WORKER_BINDINGS_JS); | 483 IDR_SERVICE_WORKER_BINDINGS_JS); |
444 v8::Local<v8::String> script = v8::String::NewExternal( | 484 v8::Local<v8::String> script = v8::String::NewExternal( |
445 isolate, new StaticV8ExternalOneByteStringResource(script_resource)); | 485 isolate, new StaticV8ExternalOneByteStringResource(script_resource)); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 // In fact |request_sender_| should really be owned by ScriptContext. | 530 // In fact |request_sender_| should really be owned by ScriptContext. |
491 request_sender_->InvalidateSource(context); | 531 request_sender_->InvalidateSource(context); |
492 | 532 |
493 script_context_set_->Remove(context); | 533 script_context_set_->Remove(context); |
494 VLOG(1) << "Num tracked contexts: " << script_context_set_->size(); | 534 VLOG(1) << "Num tracked contexts: " << script_context_set_->size(); |
495 } | 535 } |
496 | 536 |
497 // static | 537 // static |
498 void Dispatcher::WillDestroyServiceWorkerContextOnWorkerThread( | 538 void Dispatcher::WillDestroyServiceWorkerContextOnWorkerThread( |
499 v8::Local<v8::Context> v8_context, | 539 v8::Local<v8::Context> v8_context, |
| 540 int embedded_worker_id, |
500 const GURL& url) { | 541 const GURL& url) { |
501 if (url.SchemeIs(kExtensionScheme) || | 542 if (url.SchemeIs(kExtensionScheme) || |
502 url.SchemeIs(kExtensionResourceScheme)) { | 543 url.SchemeIs(kExtensionResourceScheme)) { |
503 // See comment in DidInitializeServiceWorkerContextOnWorkerThread. | 544 // See comment in DidInitializeServiceWorkerContextOnWorkerThread. |
504 g_worker_script_context_set.Get().Remove(v8_context, url); | 545 g_worker_script_context_set.Get().Remove(v8_context, url); |
505 } | 546 } |
| 547 if (ExtensionsClient::Get()->ExtensionAPIEnabledInExtensionServiceWorkers()) |
| 548 WorkerThreadDispatcher::Get()->RemoveWorkerData(embedded_worker_id); |
506 } | 549 } |
507 | 550 |
508 void Dispatcher::DidCreateDocumentElement(blink::WebLocalFrame* frame) { | 551 void Dispatcher::DidCreateDocumentElement(blink::WebLocalFrame* frame) { |
509 // Note: use GetEffectiveDocumentURL not just frame->document()->url() | 552 // Note: use GetEffectiveDocumentURL not just frame->document()->url() |
510 // so that this also injects the stylesheet on about:blank frames that | 553 // so that this also injects the stylesheet on about:blank frames that |
511 // are hosted in the extension process. | 554 // are hosted in the extension process. |
512 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL( | 555 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL( |
513 frame, frame->document().url(), true /* match_about_blank */); | 556 frame, frame->document().url(), true /* match_about_blank */); |
514 | 557 |
515 const Extension* extension = | 558 const Extension* extension = |
(...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1301 blink::WebCustomElement::addEmbedderCustomElementName("webview"); | 1344 blink::WebCustomElement::addEmbedderCustomElementName("webview"); |
1302 blink::WebCustomElement::addEmbedderCustomElementName("webviewbrowserplugin"); | 1345 blink::WebCustomElement::addEmbedderCustomElementName("webviewbrowserplugin"); |
1303 } | 1346 } |
1304 | 1347 |
1305 void Dispatcher::UpdateBindings(const std::string& extension_id) { | 1348 void Dispatcher::UpdateBindings(const std::string& extension_id) { |
1306 script_context_set().ForEach(extension_id, | 1349 script_context_set().ForEach(extension_id, |
1307 base::Bind(&Dispatcher::UpdateBindingsForContext, | 1350 base::Bind(&Dispatcher::UpdateBindingsForContext, |
1308 base::Unretained(this))); | 1351 base::Unretained(this))); |
1309 } | 1352 } |
1310 | 1353 |
| 1354 // Note: this function runs on multiple threads: main renderer thread and |
| 1355 // service worker threads. |
1311 void Dispatcher::UpdateBindingsForContext(ScriptContext* context) { | 1356 void Dispatcher::UpdateBindingsForContext(ScriptContext* context) { |
1312 v8::HandleScope handle_scope(context->isolate()); | 1357 v8::HandleScope handle_scope(context->isolate()); |
1313 v8::Context::Scope context_scope(context->v8_context()); | 1358 v8::Context::Scope context_scope(context->v8_context()); |
1314 | 1359 |
1315 // TODO(kalman): Make the bindings registration have zero overhead then run | 1360 // TODO(kalman): Make the bindings registration have zero overhead then run |
1316 // the same code regardless of context type. | 1361 // the same code regardless of context type. |
1317 switch (context->context_type()) { | 1362 switch (context->context_type()) { |
1318 case Feature::UNSPECIFIED_CONTEXT: | 1363 case Feature::UNSPECIFIED_CONTEXT: |
1319 case Feature::WEB_PAGE_CONTEXT: | 1364 case Feature::WEB_PAGE_CONTEXT: |
1320 case Feature::BLESSED_WEB_PAGE_CONTEXT: | 1365 case Feature::BLESSED_WEB_PAGE_CONTEXT: |
1321 // Hard-code registration of any APIs that are exposed to webpage-like | 1366 // Hard-code registration of any APIs that are exposed to webpage-like |
1322 // contexts, because it's too expensive to run the full bindings code. | 1367 // contexts, because it's too expensive to run the full bindings code. |
1323 // All of the same permission checks will still apply. | 1368 // All of the same permission checks will still apply. |
1324 if (context->GetAvailability("app").is_available()) | 1369 if (context->GetAvailability("app").is_available()) |
1325 RegisterBinding("app", context); | 1370 RegisterBinding("app", context); |
1326 if (context->GetAvailability("webstore").is_available()) | 1371 if (context->GetAvailability("webstore").is_available()) |
1327 RegisterBinding("webstore", context); | 1372 RegisterBinding("webstore", context); |
1328 if (context->GetAvailability("dashboardPrivate").is_available()) | 1373 if (context->GetAvailability("dashboardPrivate").is_available()) |
1329 RegisterBinding("dashboardPrivate", context); | 1374 RegisterBinding("dashboardPrivate", context); |
1330 if (IsRuntimeAvailableToContext(context)) | 1375 if (IsRuntimeAvailableToContext(context)) |
1331 RegisterBinding("runtime", context); | 1376 RegisterBinding("runtime", context); |
1332 UpdateContentCapabilities(context); | 1377 UpdateContentCapabilities(context); |
1333 break; | 1378 break; |
1334 | 1379 |
| 1380 case Feature::SERVICE_WORKER_CONTEXT: |
| 1381 DCHECK(ExtensionsClient::Get() |
| 1382 ->ExtensionAPIEnabledInExtensionServiceWorkers()); |
| 1383 // Intentional fallthrough. |
1335 case Feature::BLESSED_EXTENSION_CONTEXT: | 1384 case Feature::BLESSED_EXTENSION_CONTEXT: |
1336 case Feature::UNBLESSED_EXTENSION_CONTEXT: | 1385 case Feature::UNBLESSED_EXTENSION_CONTEXT: |
1337 case Feature::CONTENT_SCRIPT_CONTEXT: | 1386 case Feature::CONTENT_SCRIPT_CONTEXT: |
1338 case Feature::WEBUI_CONTEXT: { | 1387 case Feature::WEBUI_CONTEXT: { |
1339 // Extension context; iterate through all the APIs and bind the available | 1388 // Extension context; iterate through all the APIs and bind the available |
1340 // ones. | 1389 // ones. |
1341 const FeatureProvider* api_feature_provider = | 1390 const FeatureProvider* api_feature_provider = |
1342 FeatureProvider::GetAPIFeatures(); | 1391 FeatureProvider::GetAPIFeatures(); |
1343 for (const auto& map_entry : api_feature_provider->GetAllFeatures()) { | 1392 for (const auto& map_entry : api_feature_provider->GetAllFeatures()) { |
1344 // Internal APIs are included via require(api_name) from internal code | 1393 // Internal APIs are included via require(api_name) from internal code |
1345 // rather than chrome[api_name]. | 1394 // rather than chrome[api_name]. |
1346 if (map_entry.second->IsInternal()) | 1395 if (map_entry.second->IsInternal()) |
1347 continue; | 1396 continue; |
1348 | 1397 |
1349 // If this API has a parent feature (and isn't marked 'noparent'), | 1398 // If this API has a parent feature (and isn't marked 'noparent'), |
1350 // then this must be a function or event, so we should not register. | 1399 // then this must be a function or event, so we should not register. |
1351 if (api_feature_provider->GetParent(map_entry.second.get()) != nullptr) | 1400 if (api_feature_provider->GetParent(map_entry.second.get()) != nullptr) |
1352 continue; | 1401 continue; |
1353 | 1402 |
1354 // Skip chrome.test if this isn't a test. | 1403 // Skip chrome.test if this isn't a test. |
1355 if (map_entry.first == "test" && | 1404 if (map_entry.first == "test" && |
1356 !base::CommandLine::ForCurrentProcess()->HasSwitch( | 1405 !base::CommandLine::ForCurrentProcess()->HasSwitch( |
1357 ::switches::kTestType)) { | 1406 ::switches::kTestType)) { |
1358 continue; | 1407 continue; |
1359 } | 1408 } |
1360 | 1409 |
1361 if (context->IsAnyFeatureAvailableToContext(*map_entry.second.get())) | 1410 if (context->IsAnyFeatureAvailableToContext(*map_entry.second.get())) { |
| 1411 // TODO(lazyboy): RegisterBinding() uses |source_map_|, any thread |
| 1412 // safety issue? |
1362 RegisterBinding(map_entry.first, context); | 1413 RegisterBinding(map_entry.first, context); |
| 1414 } |
1363 } | 1415 } |
1364 break; | 1416 break; |
1365 } | 1417 } |
1366 case Feature::SERVICE_WORKER_CONTEXT: | |
1367 // Handled in DidInitializeServiceWorkerContextOnWorkerThread(). | |
1368 NOTREACHED(); | |
1369 break; | |
1370 } | 1418 } |
1371 } | 1419 } |
1372 | 1420 |
1373 void Dispatcher::RegisterBinding(const std::string& api_name, | 1421 void Dispatcher::RegisterBinding(const std::string& api_name, |
1374 ScriptContext* context) { | 1422 ScriptContext* context) { |
1375 std::string bind_name; | 1423 std::string bind_name; |
1376 v8::Local<v8::Object> bind_object = | 1424 v8::Local<v8::Object> bind_object = |
1377 GetOrCreateBindObjectIfAvailable(api_name, &bind_name, context); | 1425 GetOrCreateBindObjectIfAvailable(api_name, &bind_name, context); |
1378 | 1426 |
1379 // Empty if the bind object failed to be created, probably because the | 1427 // Empty if the bind object failed to be created, probably because the |
(...skipping 27 matching lines...) Expand all Loading... |
1407 new BindingGeneratingNativeHandler(context, api_name, "binding"))); | 1455 new BindingGeneratingNativeHandler(context, api_name, "binding"))); |
1408 module_system->SetNativeLazyField( | 1456 module_system->SetNativeLazyField( |
1409 bind_object, bind_name, api_name, "binding"); | 1457 bind_object, bind_name, api_name, "binding"); |
1410 } else { | 1458 } else { |
1411 module_system->SetLazyField(bind_object, bind_name, api_name, "binding"); | 1459 module_system->SetLazyField(bind_object, bind_name, api_name, "binding"); |
1412 } | 1460 } |
1413 } | 1461 } |
1414 | 1462 |
1415 // NOTE: please use the naming convention "foo_natives" for these. | 1463 // NOTE: please use the naming convention "foo_natives" for these. |
1416 void Dispatcher::RegisterNativeHandlers(ModuleSystem* module_system, | 1464 void Dispatcher::RegisterNativeHandlers(ModuleSystem* module_system, |
1417 ScriptContext* context) { | 1465 ScriptContext* context, |
1418 RegisterNativeHandlers(module_system, | 1466 RequestSender* request_sender, |
1419 context, | 1467 V8SchemaRegistry* v8_schema_registry) { |
1420 this, | 1468 RegisterNativeHandlers(module_system, context, this, request_sender, |
1421 request_sender_.get(), | 1469 v8_schema_registry); |
1422 v8_schema_registry_.get()); | |
1423 const Extension* extension = context->extension(); | 1470 const Extension* extension = context->extension(); |
1424 int manifest_version = extension ? extension->manifest_version() : 1; | 1471 int manifest_version = extension ? extension->manifest_version() : 1; |
1425 bool is_component_extension = | 1472 bool is_component_extension = |
1426 extension && Manifest::IsComponentLocation(extension->location()); | 1473 extension && Manifest::IsComponentLocation(extension->location()); |
1427 bool send_request_disabled = | 1474 bool send_request_disabled = |
1428 (extension && Manifest::IsUnpackedLocation(extension->location()) && | 1475 (extension && Manifest::IsUnpackedLocation(extension->location()) && |
1429 BackgroundInfo::HasLazyBackgroundPage(extension)); | 1476 BackgroundInfo::HasLazyBackgroundPage(extension)); |
1430 module_system->RegisterNativeHandler( | 1477 module_system->RegisterNativeHandler( |
1431 "process", | 1478 "process", |
1432 std::unique_ptr<NativeHandler>(new ProcessInfoNativeHandler( | 1479 std::unique_ptr<NativeHandler>(new ProcessInfoNativeHandler( |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1480 iter != active_extension_ids_.end(); | 1527 iter != active_extension_ids_.end(); |
1481 ++iter) { | 1528 ++iter) { |
1482 const Extension* extension = | 1529 const Extension* extension = |
1483 RendererExtensionRegistry::Get()->GetByID(*iter); | 1530 RendererExtensionRegistry::Get()->GetByID(*iter); |
1484 if (extension && extension->is_platform_app()) | 1531 if (extension && extension->is_platform_app()) |
1485 return true; | 1532 return true; |
1486 } | 1533 } |
1487 return false; | 1534 return false; |
1488 } | 1535 } |
1489 | 1536 |
| 1537 // static. |
1490 v8::Local<v8::Object> Dispatcher::GetOrCreateObject( | 1538 v8::Local<v8::Object> Dispatcher::GetOrCreateObject( |
1491 const v8::Local<v8::Object>& object, | 1539 const v8::Local<v8::Object>& object, |
1492 const std::string& field, | 1540 const std::string& field, |
1493 v8::Isolate* isolate) { | 1541 v8::Isolate* isolate) { |
1494 v8::Local<v8::String> key = v8::String::NewFromUtf8(isolate, field.c_str()); | 1542 v8::Local<v8::String> key = v8::String::NewFromUtf8(isolate, field.c_str()); |
1495 // If the object has a callback property, it is assumed it is an unavailable | 1543 // If the object has a callback property, it is assumed it is an unavailable |
1496 // API, so it is safe to delete. This is checked before GetOrCreateObject is | 1544 // API, so it is safe to delete. This is checked before GetOrCreateObject is |
1497 // called. | 1545 // called. |
1498 if (object->HasRealNamedCallbackProperty(key)) { | 1546 if (object->HasRealNamedCallbackProperty(key)) { |
1499 object->Delete(key); | 1547 object->Delete(key); |
1500 } else if (object->HasRealNamedProperty(key)) { | 1548 } else if (object->HasRealNamedProperty(key)) { |
1501 v8::Local<v8::Value> value = object->Get(key); | 1549 v8::Local<v8::Value> value = object->Get(key); |
1502 CHECK(value->IsObject()); | 1550 CHECK(value->IsObject()); |
1503 return v8::Local<v8::Object>::Cast(value); | 1551 return v8::Local<v8::Object>::Cast(value); |
1504 } | 1552 } |
1505 | 1553 |
1506 v8::Local<v8::Object> new_object = v8::Object::New(isolate); | 1554 v8::Local<v8::Object> new_object = v8::Object::New(isolate); |
1507 object->Set(key, new_object); | 1555 object->Set(key, new_object); |
1508 return new_object; | 1556 return new_object; |
1509 } | 1557 } |
1510 | 1558 |
| 1559 // static. |
1511 v8::Local<v8::Object> Dispatcher::GetOrCreateBindObjectIfAvailable( | 1560 v8::Local<v8::Object> Dispatcher::GetOrCreateBindObjectIfAvailable( |
1512 const std::string& api_name, | 1561 const std::string& api_name, |
1513 std::string* bind_name, | 1562 std::string* bind_name, |
1514 ScriptContext* context) { | 1563 ScriptContext* context) { |
1515 std::vector<std::string> split = base::SplitString( | 1564 std::vector<std::string> split = base::SplitString( |
1516 api_name, ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 1565 api_name, ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
1517 | 1566 |
1518 v8::Local<v8::Object> bind_object; | 1567 v8::Local<v8::Object> bind_object; |
1519 | 1568 |
1520 // Check if this API has an ancestor. If the API's ancestor is available and | 1569 // Check if this API has an ancestor. If the API's ancestor is available and |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1600 // The "guestViewDeny" module must always be loaded last. It registers | 1649 // The "guestViewDeny" module must always be loaded last. It registers |
1601 // error-providing custom elements for the GuestView types that are not | 1650 // error-providing custom elements for the GuestView types that are not |
1602 // available, and thus all of those types must have been checked and loaded | 1651 // available, and thus all of those types must have been checked and loaded |
1603 // (or not loaded) beforehand. | 1652 // (or not loaded) beforehand. |
1604 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { | 1653 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { |
1605 module_system->Require("guestViewDeny"); | 1654 module_system->Require("guestViewDeny"); |
1606 } | 1655 } |
1607 } | 1656 } |
1608 | 1657 |
1609 } // namespace extensions | 1658 } // namespace extensions |
OLD | NEW |