OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "modules/worklet/WorkletGlobalScope.h" | |
6 | |
7 #include "bindings/core/v8/SourceLocation.h" | |
8 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" | |
9 #include "core/frame/FrameConsole.h" | |
10 #include "core/inspector/InspectorInstrumentation.h" | |
11 #include "core/inspector/MainThreadDebugger.h" | |
12 | |
13 namespace blink { | |
14 | |
15 WorkletGlobalScope::WorkletGlobalScope(LocalFrame* frame, const KURL& url, const
String& userAgent, PassRefPtr<SecurityOrigin> securityOrigin, v8::Isolate* isol
ate) | |
16 : MainThreadWorkletGlobalScope(frame) | |
17 , m_url(url) | |
18 , m_userAgent(userAgent) | |
19 , m_scriptController(WorkerOrWorkletScriptController::create(this, isolate)) | |
20 { | |
21 setSecurityOrigin(securityOrigin); | |
22 } | |
23 | |
24 WorkletGlobalScope::~WorkletGlobalScope() | |
25 { | |
26 } | |
27 | |
28 void WorkletGlobalScope::dispose() | |
29 { | |
30 stopActiveDOMObjects(); | |
31 | |
32 ASSERT(m_scriptController); | |
33 m_scriptController->willScheduleExecutionTermination(); | |
34 m_scriptController->dispose(); | |
35 m_scriptController.clear(); | |
36 } | |
37 | |
38 v8::Local<v8::Object> WorkletGlobalScope::wrap(v8::Isolate*, v8::Local<v8::Objec
t> creationContext) | |
39 { | |
40 // WorkletGlobalScope must never be wrapped with wrap method. The global | |
41 // object of ECMAScript environment is used as the wrapper. | |
42 RELEASE_NOTREACHED(); | |
43 return v8::Local<v8::Object>(); | |
44 } | |
45 | |
46 v8::Local<v8::Object> WorkletGlobalScope::associateWithWrapper(v8::Isolate*, con
st WrapperTypeInfo*, v8::Local<v8::Object> wrapper) | |
47 { | |
48 RELEASE_NOTREACHED(); // Same as wrap method. | |
49 return v8::Local<v8::Object>(); | |
50 } | |
51 | |
52 void WorkletGlobalScope::disableEval(const String& errorMessage) | |
53 { | |
54 m_scriptController->disableEval(errorMessage); | |
55 } | |
56 | |
57 bool WorkletGlobalScope::isSecureContext(String& errorMessage, const SecureConte
xtCheck privilegeContextCheck) const | |
58 { | |
59 // Until there are APIs that are available in worklets and that | |
60 // require a privileged context test that checks ancestors, just do | |
61 // a simple check here. | |
62 if (getSecurityOrigin()->isPotentiallyTrustworthy()) | |
63 return true; | |
64 errorMessage = getSecurityOrigin()->isPotentiallyTrustworthyErrorMessage(); | |
65 return false; | |
66 } | |
67 | |
68 void WorkletGlobalScope::reportBlockedScriptExecutionToInspector(const String& d
irectiveText) | |
69 { | |
70 InspectorInstrumentation::scriptExecutionBlockedByCSP(this, directiveText); | |
71 } | |
72 | |
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) | |
79 { | |
80 ConsoleMessage* consoleMessage = ConsoleMessage::create(JSMessageSource, Err
orMessageLevel, errorMessage, std::move(location)); | |
81 addConsoleMessage(consoleMessage); | |
82 } | |
83 | |
84 KURL WorkletGlobalScope::virtualCompleteURL(const String& url) const | |
85 { | |
86 // Always return a null URL when passed a null string. | |
87 // TODO(ikilpatrick): Should we change the KURL constructor to have this | |
88 // behavior? | |
89 if (url.isNull()) | |
90 return KURL(); | |
91 // Always use UTF-8 in Worklets. | |
92 return KURL(m_url, url); | |
93 } | |
94 | |
95 DEFINE_TRACE(WorkletGlobalScope) | |
96 { | |
97 visitor->trace(m_scriptController); | |
98 ExecutionContext::trace(visitor); | |
99 SecurityContext::trace(visitor); | |
100 MainThreadWorkletGlobalScope::trace(visitor); | |
101 } | |
102 | |
103 } // namespace blink | |
OLD | NEW |