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