Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/WorkerOrWorkletScriptController.cpp

Issue 1880933002: Begin to enable extension APIs in Extension Service Worker. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments from falken@ and haraken@ Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009, 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2009, 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" 31 #include "bindings/core/v8/WorkerOrWorkletScriptController.h"
32 32
33 #include "bindings/core/v8/ScriptCallStack.h" 33 #include "bindings/core/v8/ScriptCallStack.h"
34 #include "bindings/core/v8/ScriptController.h"
34 #include "bindings/core/v8/ScriptSourceCode.h" 35 #include "bindings/core/v8/ScriptSourceCode.h"
35 #include "bindings/core/v8/ScriptValue.h" 36 #include "bindings/core/v8/ScriptValue.h"
36 #include "bindings/core/v8/V8DedicatedWorkerGlobalScope.h" 37 #include "bindings/core/v8/V8DedicatedWorkerGlobalScope.h"
37 #include "bindings/core/v8/V8ErrorHandler.h" 38 #include "bindings/core/v8/V8ErrorHandler.h"
38 #include "bindings/core/v8/V8Initializer.h" 39 #include "bindings/core/v8/V8Initializer.h"
39 #include "bindings/core/v8/V8ObjectConstructor.h" 40 #include "bindings/core/v8/V8ObjectConstructor.h"
40 #include "bindings/core/v8/V8ScriptRunner.h" 41 #include "bindings/core/v8/V8ScriptRunner.h"
41 #include "bindings/core/v8/V8SharedWorkerGlobalScope.h" 42 #include "bindings/core/v8/V8SharedWorkerGlobalScope.h"
42 #include "bindings/core/v8/V8WorkerGlobalScope.h" 43 #include "bindings/core/v8/V8WorkerGlobalScope.h"
43 #include "bindings/core/v8/WrapperTypeInfo.h" 44 #include "bindings/core/v8/WrapperTypeInfo.h"
44 #include "core/events/ErrorEvent.h" 45 #include "core/events/ErrorEvent.h"
45 #include "core/frame/DOMTimer.h" 46 #include "core/frame/DOMTimer.h"
46 #include "core/inspector/MainThreadDebugger.h" 47 #include "core/inspector/MainThreadDebugger.h"
47 #include "core/inspector/WorkerThreadDebugger.h" 48 #include "core/inspector/WorkerThreadDebugger.h"
48 #include "core/workers/MainThreadWorkletGlobalScope.h" 49 #include "core/workers/MainThreadWorkletGlobalScope.h"
49 #include "core/workers/WorkerOrWorkletGlobalScope.h" 50 #include "core/workers/WorkerOrWorkletGlobalScope.h"
50 #include "core/workers/WorkerThread.h" 51 #include "core/workers/WorkerThread.h"
51 #include "platform/heap/ThreadState.h" 52 #include "platform/heap/ThreadState.h"
52 #include "public/platform/Platform.h" 53 #include "public/platform/Platform.h"
54 #include "wtf/Threading.h"
53 #include <v8.h> 55 #include <v8.h>
54 56
55 namespace blink { 57 namespace blink {
56 58
57 class WorkerOrWorkletScriptController::ExecutionState final { 59 class WorkerOrWorkletScriptController::ExecutionState final {
58 STACK_ALLOCATED(); 60 STACK_ALLOCATED();
59 public: 61 public:
60 explicit ExecutionState(WorkerOrWorkletScriptController* controller) 62 explicit ExecutionState(WorkerOrWorkletScriptController* controller)
61 : hadException(false) 63 : hadException(false)
62 , lineNumber(0) 64 , lineNumber(0)
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 // and its fields will be traced when scanning the stack. 101 // and its fields will be traced when scanning the stack.
100 Member<WorkerOrWorkletScriptController> m_controller; 102 Member<WorkerOrWorkletScriptController> m_controller;
101 ExecutionState* m_outerState; 103 ExecutionState* m_outerState;
102 }; 104 };
103 105
104 WorkerOrWorkletScriptController* WorkerOrWorkletScriptController::create(WorkerO rWorkletGlobalScope* globalScope, v8::Isolate* isolate) 106 WorkerOrWorkletScriptController* WorkerOrWorkletScriptController::create(WorkerO rWorkletGlobalScope* globalScope, v8::Isolate* isolate)
105 { 107 {
106 return new WorkerOrWorkletScriptController(globalScope, isolate); 108 return new WorkerOrWorkletScriptController(globalScope, isolate);
107 } 109 }
108 110
111 V8Extensions& WorkerOrWorkletScriptController::registeredExtensions()
112 {
113 // Accessed from worker threads.
114 DEFINE_THREAD_SAFE_STATIC_LOCAL(V8Extensions, extensions, new V8Extensions);
115 return extensions;
116 }
117
118 void WorkerOrWorkletScriptController::registerExtensionIfNeeded(v8::Extension* e xtension)
119 {
120 const V8Extensions& extensions = registeredExtensions();
121 for (size_t i = 0; i < extensions.size(); ++i) {
122 if (extensions[i] == extension)
123 return;
124 }
125 v8::RegisterExtension(extension);
yhirano 2016/04/22 02:28:11 Naive question, is this function thread-safe?
lazyboy 2016/04/22 03:25:25 Good question, It seems this would eventually call
126 registeredExtensions().append(extension);
127 }
128
109 WorkerOrWorkletScriptController::WorkerOrWorkletScriptController(WorkerOrWorklet GlobalScope* globalScope, v8::Isolate* isolate) 129 WorkerOrWorkletScriptController::WorkerOrWorkletScriptController(WorkerOrWorklet GlobalScope* globalScope, v8::Isolate* isolate)
110 : m_globalScope(globalScope) 130 : m_globalScope(globalScope)
111 , m_isolate(isolate) 131 , m_isolate(isolate)
112 , m_executionForbidden(false) 132 , m_executionForbidden(false)
113 , m_executionScheduledToTerminate(false) 133 , m_executionScheduledToTerminate(false)
114 , m_rejectedPromises(RejectedPromises::create()) 134 , m_rejectedPromises(RejectedPromises::create())
115 , m_executionState(0) 135 , m_executionState(0)
116 { 136 {
117 ASSERT(isolate); 137 ASSERT(isolate);
118 m_world = DOMWrapperWorld::create(isolate, WorkerWorldId); 138 m_world = DOMWrapperWorld::create(isolate, WorkerWorldId);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 // Create a new v8::Context with the worker/worklet as the global object 178 // Create a new v8::Context with the worker/worklet as the global object
159 // (aka the inner global). 179 // (aka the inner global).
160 ScriptWrappable* scriptWrappable = m_globalScope->getScriptWrappable(); 180 ScriptWrappable* scriptWrappable = m_globalScope->getScriptWrappable();
161 const WrapperTypeInfo* wrapperTypeInfo = scriptWrappable->wrapperTypeInfo(); 181 const WrapperTypeInfo* wrapperTypeInfo = scriptWrappable->wrapperTypeInfo();
162 v8::Local<v8::FunctionTemplate> globalInterfaceTemplate = wrapperTypeInfo->d omTemplate(m_isolate, *m_world); 182 v8::Local<v8::FunctionTemplate> globalInterfaceTemplate = wrapperTypeInfo->d omTemplate(m_isolate, *m_world);
163 if (globalInterfaceTemplate.IsEmpty()) 183 if (globalInterfaceTemplate.IsEmpty())
164 return false; 184 return false;
165 v8::Local<v8::ObjectTemplate> globalTemplate = globalInterfaceTemplate->Inst anceTemplate(); 185 v8::Local<v8::ObjectTemplate> globalTemplate = globalInterfaceTemplate->Inst anceTemplate();
166 v8::Local<v8::Context> context; 186 v8::Local<v8::Context> context;
167 { 187 {
188 // Initialize V8 extensions before creating the context.
189 Vector<const char*> extensionNames;
190 if (m_globalScope->isServiceWorkerGlobalScope()) {
haraken 2016/04/21 07:50:44 Slightly better: CHECK(m_globalScope->isService
lazyboy 2016/04/22 00:17:39 Since the latest patch uses ScriptController::regi
191 const V8Extensions& extensions = registeredExtensions();
192 extensionNames.reserveInitialCapacity(extensions.size());
193 for (const auto* extension : extensions)
194 extensionNames.append(extension->name());
195 }
196 v8::ExtensionConfiguration extensionConfiguration(extensionNames.size(), extensionNames.data());
197
168 V8PerIsolateData::UseCounterDisabledScope useCounterDisabled(V8PerIsolat eData::from(m_isolate)); 198 V8PerIsolateData::UseCounterDisabledScope useCounterDisabled(V8PerIsolat eData::from(m_isolate));
169 context = v8::Context::New(m_isolate, nullptr, globalTemplate); 199 context = v8::Context::New(m_isolate, &extensionConfiguration, globalTem plate);
170 } 200 }
171 if (context.IsEmpty()) 201 if (context.IsEmpty())
172 return false; 202 return false;
173 203
174 m_scriptState = ScriptState::create(context, m_world); 204 m_scriptState = ScriptState::create(context, m_world);
175 205
176 ScriptState::Scope scope(m_scriptState.get()); 206 ScriptState::Scope scope(m_scriptState.get());
177 207
178 // Name new context for debugging. For main thread worklet global scopes 208 // Name new context for debugging. For main thread worklet global scopes
179 // this is done once the context is initialized. 209 // this is done once the context is initialized.
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 m_executionState->m_errorEventFromImportedScript = errorEvent; 349 m_executionState->m_errorEventFromImportedScript = errorEvent;
320 exceptionState.rethrowV8Exception(V8ThrowException::createGeneralError(m_iso late, errorMessage)); 350 exceptionState.rethrowV8Exception(V8ThrowException::createGeneralError(m_iso late, errorMessage));
321 } 351 }
322 352
323 DEFINE_TRACE(WorkerOrWorkletScriptController) 353 DEFINE_TRACE(WorkerOrWorkletScriptController)
324 { 354 {
325 visitor->trace(m_globalScope); 355 visitor->trace(m_globalScope);
326 } 356 }
327 357
328 } // namespace blink 358 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698