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

Side by Side Diff: third_party/WebKit/Source/web/SuspendableScriptExecutor.cpp

Issue 2628053003: Remove extension group from DOMWrapperWorld. (Closed)
Patch Set: Fix GCCallbackTest Created 3 years, 11 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 // 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 "web/SuspendableScriptExecutor.h" 5 #include "web/SuspendableScriptExecutor.h"
6 6
7 #include "bindings/core/v8/ScriptController.h" 7 #include "bindings/core/v8/ScriptController.h"
8 #include "bindings/core/v8/ScriptSourceCode.h" 8 #include "bindings/core/v8/ScriptSourceCode.h"
9 #include "bindings/core/v8/V8PersistentValueVector.h" 9 #include "bindings/core/v8/V8PersistentValueVector.h"
10 #include "bindings/core/v8/WindowProxy.h" 10 #include "bindings/core/v8/WindowProxy.h"
11 #include "core/dom/Document.h" 11 #include "core/dom/Document.h"
12 #include "core/dom/DocumentUserGestureToken.h" 12 #include "core/dom/DocumentUserGestureToken.h"
13 #include "core/frame/LocalFrame.h" 13 #include "core/frame/LocalFrame.h"
14 #include "platform/UserGestureIndicator.h" 14 #include "platform/UserGestureIndicator.h"
15 #include "public/platform/WebVector.h" 15 #include "public/platform/WebVector.h"
16 #include "public/web/WebScriptExecutionCallback.h" 16 #include "public/web/WebScriptExecutionCallback.h"
17 #include "wtf/PtrUtil.h" 17 #include "wtf/PtrUtil.h"
18 #include "wtf/Vector.h" 18 #include "wtf/Vector.h"
19 #include <memory> 19 #include <memory>
20 20
21 namespace blink { 21 namespace blink {
22 22
23 namespace { 23 namespace {
24 24
25 class WebScriptExecutor : public SuspendableScriptExecutor::Executor { 25 class WebScriptExecutor : public SuspendableScriptExecutor::Executor {
26 public: 26 public:
27 WebScriptExecutor(const HeapVector<ScriptSourceCode>& sources, 27 WebScriptExecutor(const HeapVector<ScriptSourceCode>& sources,
28 int worldID, 28 int worldID,
29 int extensionGroup,
30 bool userGesture); 29 bool userGesture);
31 30
32 Vector<v8::Local<v8::Value>> execute(LocalFrame*) override; 31 Vector<v8::Local<v8::Value>> execute(LocalFrame*) override;
33 32
34 DEFINE_INLINE_VIRTUAL_TRACE() { 33 DEFINE_INLINE_VIRTUAL_TRACE() {
35 visitor->trace(m_sources); 34 visitor->trace(m_sources);
36 SuspendableScriptExecutor::Executor::trace(visitor); 35 SuspendableScriptExecutor::Executor::trace(visitor);
37 } 36 }
38 37
39 private: 38 private:
40 HeapVector<ScriptSourceCode> m_sources; 39 HeapVector<ScriptSourceCode> m_sources;
41 int m_worldID; 40 int m_worldID;
42 int m_extensionGroup;
43 bool m_userGesture; 41 bool m_userGesture;
44 }; 42 };
45 43
46 WebScriptExecutor::WebScriptExecutor( 44 WebScriptExecutor::WebScriptExecutor(
47 const HeapVector<ScriptSourceCode>& sources, 45 const HeapVector<ScriptSourceCode>& sources,
48 int worldID, 46 int worldID,
49 int extensionGroup,
50 bool userGesture) 47 bool userGesture)
51 : m_sources(sources), 48 : m_sources(sources),
52 m_worldID(worldID), 49 m_worldID(worldID),
53 m_extensionGroup(extensionGroup),
54 m_userGesture(userGesture) {} 50 m_userGesture(userGesture) {}
55 51
56 Vector<v8::Local<v8::Value>> WebScriptExecutor::execute(LocalFrame* frame) { 52 Vector<v8::Local<v8::Value>> WebScriptExecutor::execute(LocalFrame* frame) {
57 std::unique_ptr<UserGestureIndicator> indicator; 53 std::unique_ptr<UserGestureIndicator> indicator;
58 if (m_userGesture) { 54 if (m_userGesture) {
59 indicator = WTF::wrapUnique( 55 indicator = WTF::wrapUnique(
60 new UserGestureIndicator(DocumentUserGestureToken::create( 56 new UserGestureIndicator(DocumentUserGestureToken::create(
61 frame->document(), UserGestureToken::NewGesture))); 57 frame->document(), UserGestureToken::NewGesture)));
62 } 58 }
63 59
64 Vector<v8::Local<v8::Value>> results; 60 Vector<v8::Local<v8::Value>> results;
65 if (m_worldID) { 61 if (m_worldID) {
66 frame->script().executeScriptInIsolatedWorld(m_worldID, m_sources, 62 frame->script().executeScriptInIsolatedWorld(m_worldID, m_sources,
67 m_extensionGroup, &results); 63 &results);
68 } else { 64 } else {
69 v8::Local<v8::Value> scriptValue = 65 v8::Local<v8::Value> scriptValue =
70 frame->script().executeScriptInMainWorldAndReturnValue( 66 frame->script().executeScriptInMainWorldAndReturnValue(
71 m_sources.front()); 67 m_sources.front());
72 results.push_back(scriptValue); 68 results.push_back(scriptValue);
73 } 69 }
74 70
75 return results; 71 return results;
76 } 72 }
77 73
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 } 125 }
130 return results; 126 return results;
131 } 127 }
132 128
133 } // namespace 129 } // namespace
134 130
135 void SuspendableScriptExecutor::createAndRun( 131 void SuspendableScriptExecutor::createAndRun(
136 LocalFrame* frame, 132 LocalFrame* frame,
137 int worldID, 133 int worldID,
138 const HeapVector<ScriptSourceCode>& sources, 134 const HeapVector<ScriptSourceCode>& sources,
139 int extensionGroup,
140 bool userGesture, 135 bool userGesture,
141 WebScriptExecutionCallback* callback) { 136 WebScriptExecutionCallback* callback) {
142 // TODO(devlin): Passing in a v8::Isolate* directly would be better than 137 // TODO(devlin): Passing in a v8::Isolate* directly would be better than
143 // toIsolate() here. 138 // toIsolate() here.
144 ScriptState* scriptState = ScriptState::forWorld( 139 ScriptState* scriptState = ScriptState::forWorld(
145 frame, 140 frame, *DOMWrapperWorld::fromWorldId(toIsolate(frame), worldID));
146 *DOMWrapperWorld::fromWorldId(toIsolate(frame), worldID, extensionGroup));
147 SuspendableScriptExecutor* executor = new SuspendableScriptExecutor( 141 SuspendableScriptExecutor* executor = new SuspendableScriptExecutor(
148 frame, scriptState, callback, 142 frame, scriptState, callback,
149 new WebScriptExecutor(sources, worldID, extensionGroup, userGesture)); 143 new WebScriptExecutor(sources, worldID, userGesture));
150 executor->run(); 144 executor->run();
151 } 145 }
152 146
153 void SuspendableScriptExecutor::createAndRun( 147 void SuspendableScriptExecutor::createAndRun(
154 LocalFrame* frame, 148 LocalFrame* frame,
155 v8::Isolate* isolate, 149 v8::Isolate* isolate,
156 v8::Local<v8::Context> context, 150 v8::Local<v8::Context> context,
157 v8::Local<v8::Function> function, 151 v8::Local<v8::Function> function,
158 v8::Local<v8::Value> receiver, 152 v8::Local<v8::Value> receiver,
159 int argc, 153 int argc,
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 m_keepAlive.clear(); 225 m_keepAlive.clear();
232 stop(); 226 stop();
233 } 227 }
234 228
235 DEFINE_TRACE(SuspendableScriptExecutor) { 229 DEFINE_TRACE(SuspendableScriptExecutor) {
236 visitor->trace(m_executor); 230 visitor->trace(m_executor);
237 SuspendableTimer::trace(visitor); 231 SuspendableTimer::trace(visitor);
238 } 232 }
239 233
240 } // namespace blink 234 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/SuspendableScriptExecutor.h ('k') | third_party/WebKit/Source/web/WebLocalFrameImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698