OLD | NEW |
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 "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
10 #include "core/frame/LocalFrame.h" | 10 #include "core/frame/LocalFrame.h" |
11 #include "platform/UserGestureIndicator.h" | 11 #include "platform/UserGestureIndicator.h" |
12 #include "public/platform/WebVector.h" | 12 #include "public/platform/WebVector.h" |
13 #include "public/web/WebScriptExecutionCallback.h" | 13 #include "public/web/WebScriptExecutionCallback.h" |
14 #include "wtf/PtrUtil.h" | |
15 #include <memory> | |
16 | 14 |
17 namespace blink { | 15 namespace blink { |
18 | 16 |
19 void SuspendableScriptExecutor::createAndRun(LocalFrame* frame, int worldID, con
st HeapVector<ScriptSourceCode>& sources, int extensionGroup, bool userGesture,
WebScriptExecutionCallback* callback) | 17 void SuspendableScriptExecutor::createAndRun(LocalFrame* frame, int worldID, con
st HeapVector<ScriptSourceCode>& sources, int extensionGroup, bool userGesture,
WebScriptExecutionCallback* callback) |
20 { | 18 { |
21 SuspendableScriptExecutor* executor = new SuspendableScriptExecutor(frame, w
orldID, sources, extensionGroup, userGesture, callback); | 19 SuspendableScriptExecutor* executor = new SuspendableScriptExecutor(frame, w
orldID, sources, extensionGroup, userGesture, callback); |
22 executor->run(); | 20 executor->run(); |
23 } | 21 } |
24 | 22 |
25 void SuspendableScriptExecutor::contextDestroyed() | 23 void SuspendableScriptExecutor::contextDestroyed() |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 return; | 58 return; |
61 } | 59 } |
62 startOneShot(0, BLINK_FROM_HERE); | 60 startOneShot(0, BLINK_FROM_HERE); |
63 suspendIfNeeded(); | 61 suspendIfNeeded(); |
64 } | 62 } |
65 | 63 |
66 void SuspendableScriptExecutor::executeAndDestroySelf() | 64 void SuspendableScriptExecutor::executeAndDestroySelf() |
67 { | 65 { |
68 // after calling the destructor of object - object will be unsubscribed from | 66 // after calling the destructor of object - object will be unsubscribed from |
69 // resumed and contextDestroyed LifecycleObserver methods | 67 // resumed and contextDestroyed LifecycleObserver methods |
70 std::unique_ptr<UserGestureIndicator> indicator; | 68 OwnPtr<UserGestureIndicator> indicator; |
71 if (m_userGesture) | 69 if (m_userGesture) |
72 indicator = wrapUnique(new UserGestureIndicator(DefinitelyProcessingNewU
serGesture)); | 70 indicator = adoptPtr(new UserGestureIndicator(DefinitelyProcessingNewUse
rGesture)); |
73 | 71 |
74 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 72 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
75 Vector<v8::Local<v8::Value>> results; | 73 Vector<v8::Local<v8::Value>> results; |
76 if (m_worldID) { | 74 if (m_worldID) { |
77 m_frame->script().executeScriptInIsolatedWorld(m_worldID, m_sources, m_e
xtensionGroup, &results); | 75 m_frame->script().executeScriptInIsolatedWorld(m_worldID, m_sources, m_e
xtensionGroup, &results); |
78 } else { | 76 } else { |
79 v8::Local<v8::Value> scriptValue = m_frame->script().executeScriptInMain
WorldAndReturnValue(m_sources.first()); | 77 v8::Local<v8::Value> scriptValue = m_frame->script().executeScriptInMain
WorldAndReturnValue(m_sources.first()); |
80 results.append(scriptValue); | 78 results.append(scriptValue); |
81 } | 79 } |
82 | 80 |
(...skipping 15 matching lines...) Expand all Loading... |
98 } | 96 } |
99 | 97 |
100 DEFINE_TRACE(SuspendableScriptExecutor) | 98 DEFINE_TRACE(SuspendableScriptExecutor) |
101 { | 99 { |
102 visitor->trace(m_frame); | 100 visitor->trace(m_frame); |
103 visitor->trace(m_sources); | 101 visitor->trace(m_sources); |
104 SuspendableTimer::trace(visitor); | 102 SuspendableTimer::trace(visitor); |
105 } | 103 } |
106 | 104 |
107 } // namespace blink | 105 } // namespace blink |
OLD | NEW |