Index: extensions/renderer/dispatcher.cc |
diff --git a/extensions/renderer/dispatcher.cc b/extensions/renderer/dispatcher.cc |
index a31eda7eea84987adc2f49c007c735cd924f7ef7..bb3dc92f71c29ac83b2631d728095264e564d4cb 100644 |
--- a/extensions/renderer/dispatcher.cc |
+++ b/extensions/renderer/dispatcher.cc |
@@ -98,6 +98,7 @@ |
#include "extensions/renderer/v8_helpers.h" |
#include "extensions/renderer/wake_event_page.h" |
#include "extensions/renderer/worker_script_context_set.h" |
+#include "extensions/renderer/worker_thread_dispatcher.h" |
#include "grit/extensions_renderer_resources.h" |
#include "mojo/public/js/constants.h" |
#include "third_party/WebKit/public/platform/WebString.h" |
@@ -109,6 +110,7 @@ |
#include "third_party/WebKit/public/web/WebLocalFrame.h" |
#include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
#include "third_party/WebKit/public/web/WebScopedUserGesture.h" |
+#include "third_party/WebKit/public/web/WebScriptController.h" |
#include "third_party/WebKit/public/web/WebSecurityPolicy.h" |
#include "third_party/WebKit/public/web/WebView.h" |
#include "ui/base/layout.h" |
@@ -232,6 +234,7 @@ Dispatcher::Dispatcher(DispatcherDelegate* delegate) |
request_sender_.reset(new RequestSender(this)); |
PopulateSourceMap(); |
WakeEventPage::Get()->Init(RenderThread::Get()); |
+ WorkerThreadDispatcher::Get()->Init(RenderThread::Get()); |
RenderThread::Get()->RegisterExtension(SafeBuiltins::CreateV8Extension()); |
@@ -330,7 +333,8 @@ void Dispatcher::DidCreateScriptContext( |
// Enable natives in startup. |
ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system); |
- RegisterNativeHandlers(module_system, context); |
+ RegisterNativeHandlers(module_system, context, request_sender_.get(), |
+ v8_schema_registry_.get()); |
// chrome.Event is part of the public API (although undocumented). Make it |
// lazily evalulate to Event from event_bindings.js. For extensions only |
@@ -389,8 +393,14 @@ void Dispatcher::DidCreateScriptContext( |
} |
// static |
+void Dispatcher::InstallV8ExtensionForServiceWorkers() { |
+ blink::WebScriptController::registerExtensionForServiceWorkerScript( |
+ SafeBuiltins::CreateV8Extension()); |
+} |
+ |
void Dispatcher::DidInitializeServiceWorkerContextOnWorkerThread( |
v8::Local<v8::Context> v8_context, |
+ int embedded_worker_id, |
const GURL& url) { |
const base::TimeTicks start_time = base::TimeTicks::Now(); |
@@ -435,6 +445,37 @@ void Dispatcher::DidInitializeServiceWorkerContextOnWorkerThread( |
extension, Feature::SERVICE_WORKER_CONTEXT); |
context->set_url(url); |
+ // TODO(lazyboy): |
Devlin
2016/04/13 19:46:32
?
lazyboy
2016/04/14 02:07:53
Removed.
|
+ WorkerThreadDispatcher::Get()->AddWorkerData(embedded_worker_id); |
+ { |
+ // TODO(lazyboy): Make sure accessing |source_map_| in worker thread is |
+ // safe. |
+ scoped_ptr<ModuleSystem> module_system( |
Devlin
2016/04/13 19:46:31
unique_ptr
lazyboy
2016/04/14 02:07:53
Done.
|
+ new ModuleSystem(context, &source_map_)); |
+ context->set_module_system(std::move(module_system)); |
+ } |
+ |
+ ModuleSystem* module_system = context->module_system(); |
+ // Enable natives in startup. |
+ ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system); |
+ RegisterNativeHandlers(module_system, context, |
+ WorkerThreadDispatcher::Get()->GetRequestSender(), |
+ WorkerThreadDispatcher::Get()->GetV8SchemaRegistry()); |
+ // chrome.Event is part of the public API (although undocumented). Make it |
+ // lazily evalulate to Event from event_bindings.js. For extensions only |
+ // though, not all webpages! |
+ 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.
|
+ v8::Local<v8::Object> chrome = AsObjectOrEmpty(GetOrCreateChrome(context)); |
+ if (!chrome.IsEmpty()) |
+ module_system->SetLazyField(chrome, "Event", kEventBindings, "Event"); |
+ } |
+ UpdateBindingsForContext(context); |
+ // TODO(lazyboy): Get rid of RequireGuestViewModules() as this doesn't seem |
+ // necessary for Extension SW. |
+ RequireGuestViewModules(context); |
+ delegate_->RequireAdditionalModules(context, |
+ false /* is_within_platform_app */); |
+ |
g_worker_script_context_set.Get().Insert(make_scoped_ptr(context)); |
v8::Isolate* isolate = context->isolate(); |
@@ -499,12 +540,14 @@ void Dispatcher::WillReleaseScriptContext( |
// static |
void Dispatcher::WillDestroyServiceWorkerContextOnWorkerThread( |
v8::Local<v8::Context> v8_context, |
+ int embedded_worker_id, |
const GURL& url) { |
if (url.SchemeIs(kExtensionScheme) || |
url.SchemeIs(kExtensionResourceScheme)) { |
// See comment in DidInitializeServiceWorkerContextOnWorkerThread. |
g_worker_script_context_set.Get().Remove(v8_context, url); |
} |
+ WorkerThreadDispatcher::Get()->RemoveWorkerData(embedded_worker_id); |
} |
void Dispatcher::DidCreateDocumentElement(blink::WebLocalFrame* frame) { |
@@ -1344,6 +1387,7 @@ void Dispatcher::UpdateBindingsForContext(ScriptContext* context) { |
case Feature::BLESSED_EXTENSION_CONTEXT: |
case Feature::UNBLESSED_EXTENSION_CONTEXT: |
case Feature::CONTENT_SCRIPT_CONTEXT: |
+ case Feature::SERVICE_WORKER_CONTEXT: |
case Feature::WEBUI_CONTEXT: { |
// Extension context; iterate through all the APIs and bind the available |
// ones. |
@@ -1367,15 +1411,14 @@ void Dispatcher::UpdateBindingsForContext(ScriptContext* context) { |
continue; |
} |
- if (context->IsAnyFeatureAvailableToContext(*map_entry.second.get())) |
+ if (context->IsAnyFeatureAvailableToContext(*map_entry.second.get())) { |
+ // TODO(lazyboy): RegisterBinding() uses |source_map_|, any thread |
+ // safety issue? |
RegisterBinding(map_entry.first, context); |
+ } |
} |
break; |
} |
- case Feature::SERVICE_WORKER_CONTEXT: |
- // Handled in DidInitializeServiceWorkerContextOnWorkerThread(). |
- NOTREACHED(); |
- break; |
} |
} |
@@ -1423,12 +1466,11 @@ void Dispatcher::RegisterBinding(const std::string& api_name, |
// NOTE: please use the naming convention "foo_natives" for these. |
void Dispatcher::RegisterNativeHandlers(ModuleSystem* module_system, |
- ScriptContext* context) { |
- RegisterNativeHandlers(module_system, |
- context, |
- this, |
- request_sender_.get(), |
- v8_schema_registry_.get()); |
+ ScriptContext* context, |
+ RequestSender* request_sender, |
+ V8SchemaRegistry* v8_schema_registry) { |
+ RegisterNativeHandlers(module_system, context, this, request_sender, |
+ v8_schema_registry); |
const Extension* extension = context->extension(); |
int manifest_version = extension ? extension->manifest_version() : 1; |
bool is_component_extension = |
@@ -1499,6 +1541,7 @@ bool Dispatcher::IsWithinPlatformApp() { |
return false; |
} |
+// static. |
v8::Local<v8::Object> Dispatcher::GetOrCreateObject( |
const v8::Local<v8::Object>& object, |
const std::string& field, |
@@ -1520,6 +1563,7 @@ v8::Local<v8::Object> Dispatcher::GetOrCreateObject( |
return new_object; |
} |
+// static. |
v8::Local<v8::Object> Dispatcher::GetOrCreateBindObjectIfAvailable( |
const std::string& api_name, |
std::string* bind_name, |