OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "modules/worklet/WorkletGlobalScope.h" | 5 #include "core/workers/WorkletGlobalScope.h" |
6 | 6 |
7 #include "bindings/core/v8/SourceLocation.h" | 7 #include "bindings/core/v8/SourceLocation.h" |
8 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" | 8 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" |
9 #include "core/frame/FrameConsole.h" | |
10 #include "core/inspector/InspectorInstrumentation.h" | 9 #include "core/inspector/InspectorInstrumentation.h" |
11 #include "core/inspector/MainThreadDebugger.h" | 10 #include "core/inspector/MainThreadDebugger.h" |
12 | 11 |
13 namespace blink { | 12 namespace blink { |
14 | 13 |
15 WorkletGlobalScope::WorkletGlobalScope(LocalFrame* frame, const KURL& url, const
String& userAgent, PassRefPtr<SecurityOrigin> securityOrigin, v8::Isolate* isol
ate) | 14 WorkletGlobalScope::WorkletGlobalScope(const KURL& url, const String& userAgent,
PassRefPtr<SecurityOrigin> securityOrigin, v8::Isolate* isolate) |
16 : MainThreadWorkletGlobalScope(frame) | 15 : m_url(url) |
17 , m_url(url) | |
18 , m_userAgent(userAgent) | 16 , m_userAgent(userAgent) |
19 , m_scriptController(WorkerOrWorkletScriptController::create(this, isolate)) | 17 , m_scriptController(WorkerOrWorkletScriptController::create(this, isolate)) |
20 { | 18 { |
21 setSecurityOrigin(securityOrigin); | 19 setSecurityOrigin(securityOrigin); |
22 } | 20 } |
23 | 21 |
24 WorkletGlobalScope::~WorkletGlobalScope() | 22 WorkletGlobalScope::~WorkletGlobalScope() |
25 { | 23 { |
26 } | 24 } |
27 | 25 |
28 void WorkletGlobalScope::dispose() | 26 void WorkletGlobalScope::dispose() |
29 { | 27 { |
30 stopActiveDOMObjects(); | 28 stopActiveDOMObjects(); |
31 | 29 |
32 ASSERT(m_scriptController); | 30 DCHECK(m_scriptController); |
33 m_scriptController->willScheduleExecutionTermination(); | 31 m_scriptController->willScheduleExecutionTermination(); |
34 m_scriptController->dispose(); | 32 m_scriptController->dispose(); |
35 m_scriptController.clear(); | 33 m_scriptController.clear(); |
36 } | 34 } |
37 | 35 |
38 v8::Local<v8::Object> WorkletGlobalScope::wrap(v8::Isolate*, v8::Local<v8::Objec
t> creationContext) | 36 v8::Local<v8::Object> WorkletGlobalScope::wrap(v8::Isolate*, v8::Local<v8::Objec
t> creationContext) |
39 { | 37 { |
40 // WorkletGlobalScope must never be wrapped with wrap method. The global | 38 // WorkletGlobalScope must never be wrapped with wrap method. The global |
41 // object of ECMAScript environment is used as the wrapper. | 39 // object of ECMAScript environment is used as the wrapper. |
42 RELEASE_NOTREACHED(); | 40 RELEASE_NOTREACHED(); |
(...skipping 20 matching lines...) Expand all Loading... |
63 return true; | 61 return true; |
64 errorMessage = getSecurityOrigin()->isPotentiallyTrustworthyErrorMessage(); | 62 errorMessage = getSecurityOrigin()->isPotentiallyTrustworthyErrorMessage(); |
65 return false; | 63 return false; |
66 } | 64 } |
67 | 65 |
68 void WorkletGlobalScope::reportBlockedScriptExecutionToInspector(const String& d
irectiveText) | 66 void WorkletGlobalScope::reportBlockedScriptExecutionToInspector(const String& d
irectiveText) |
69 { | 67 { |
70 InspectorInstrumentation::scriptExecutionBlockedByCSP(this, directiveText); | 68 InspectorInstrumentation::scriptExecutionBlockedByCSP(this, directiveText); |
71 } | 69 } |
72 | 70 |
73 void WorkletGlobalScope::addConsoleMessage(ConsoleMessage* consoleMessage) | |
74 { | |
75 frame()->console().addMessage(consoleMessage); | |
76 } | |
77 | |
78 void WorkletGlobalScope::logExceptionToConsole(const String& errorMessage, PassO
wnPtr<SourceLocation> location) | 71 void WorkletGlobalScope::logExceptionToConsole(const String& errorMessage, PassO
wnPtr<SourceLocation> location) |
79 { | 72 { |
80 ConsoleMessage* consoleMessage = ConsoleMessage::create(JSMessageSource, Err
orMessageLevel, errorMessage, std::move(location)); | 73 ConsoleMessage* consoleMessage = ConsoleMessage::create(JSMessageSource, Err
orMessageLevel, errorMessage, std::move(location)); |
81 addConsoleMessage(consoleMessage); | 74 addConsoleMessage(consoleMessage); |
82 } | 75 } |
83 | 76 |
84 KURL WorkletGlobalScope::virtualCompleteURL(const String& url) const | 77 KURL WorkletGlobalScope::virtualCompleteURL(const String& url) const |
85 { | 78 { |
86 // Always return a null URL when passed a null string. | 79 // Always return a null URL when passed a null string. |
87 // TODO(ikilpatrick): Should we change the KURL constructor to have this | 80 // TODO(ikilpatrick): Should we change the KURL constructor to have this |
88 // behavior? | 81 // behavior? |
89 if (url.isNull()) | 82 if (url.isNull()) |
90 return KURL(); | 83 return KURL(); |
91 // Always use UTF-8 in Worklets. | 84 // Always use UTF-8 in Worklets. |
92 return KURL(m_url, url); | 85 return KURL(m_url, url); |
93 } | 86 } |
94 | 87 |
95 DEFINE_TRACE(WorkletGlobalScope) | 88 DEFINE_TRACE(WorkletGlobalScope) |
96 { | 89 { |
97 visitor->trace(m_scriptController); | 90 visitor->trace(m_scriptController); |
98 ExecutionContext::trace(visitor); | 91 ExecutionContext::trace(visitor); |
99 SecurityContext::trace(visitor); | 92 SecurityContext::trace(visitor); |
100 MainThreadWorkletGlobalScope::trace(visitor); | 93 WorkerOrWorkletGlobalScope::trace(visitor); |
101 } | 94 } |
102 | 95 |
103 } // namespace blink | 96 } // namespace blink |
OLD | NEW |