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 "config.h" | 5 #include "config.h" |
6 #include "web/SuspendableScriptExecutor.h" | 6 #include "web/SuspendableScriptExecutor.h" |
7 | 7 |
8 #include "bindings/core/v8/ScriptController.h" | 8 #include "bindings/core/v8/ScriptController.h" |
9 #include "bindings/core/v8/ScriptSourceCode.h" | 9 #include "bindings/core/v8/ScriptSourceCode.h" |
10 #include "core/dom/Document.h" | 10 #include "core/dom/Document.h" |
11 #include "core/frame/LocalFrame.h" | 11 #include "core/frame/LocalFrame.h" |
12 #include "platform/UserGestureIndicator.h" | 12 #include "platform/UserGestureIndicator.h" |
13 #include "public/platform/WebVector.h" | 13 #include "public/platform/WebVector.h" |
14 #include "public/web/WebScriptExecutionCallback.h" | 14 #include "public/web/WebScriptExecutionCallback.h" |
15 | 15 |
16 namespace blink { | 16 namespace blink { |
17 | 17 |
18 void SuspendableScriptExecutor::createAndRun(LocalFrame* frame, int worldID, con
st WillBeHeapVector<ScriptSourceCode>& sources, int extensionGroup, bool userGes
ture, WebScriptExecutionCallback* callback) | 18 void SuspendableScriptExecutor::createAndRun(LocalFrame* frame, int worldID, con
st WillBeHeapVector<ScriptSourceCode>& sources, int extensionGroup, bool userGes
ture, WebScriptExecutionCallback* callback) |
19 { | 19 { |
20 RefPtrWillBeRawPtr<SuspendableScriptExecutor> executor = adoptRefWillBeNoop(
new SuspendableScriptExecutor(frame, worldID, sources, extensionGroup, userGestu
re, callback)); | 20 SuspendableScriptExecutor* executor = new SuspendableScriptExecutor(frame, w
orldID, sources, extensionGroup, userGesture, callback); |
21 executor->ref(); | 21 executor->m_keepAlive = executor; |
22 executor->run(); | 22 executor->run(); |
23 } | 23 } |
24 | 24 |
25 void SuspendableScriptExecutor::contextDestroyed() | 25 void SuspendableScriptExecutor::contextDestroyed() |
26 { | 26 { |
27 SuspendableTimer::contextDestroyed(); | 27 SuspendableTimer::contextDestroyed(); |
28 m_callback->completed(Vector<v8::Local<v8::Value>>()); | 28 m_callback->completed(Vector<v8::Local<v8::Value>>()); |
29 dispose(); | 29 dispose(); |
30 } | 30 } |
31 | 31 |
32 SuspendableScriptExecutor::SuspendableScriptExecutor(LocalFrame* frame, int worl
dID, const WillBeHeapVector<ScriptSourceCode>& sources, int extensionGroup, bool
userGesture, WebScriptExecutionCallback* callback) | 32 SuspendableScriptExecutor::SuspendableScriptExecutor(LocalFrame* frame, int worl
dID, const WillBeHeapVector<ScriptSourceCode>& sources, int extensionGroup, bool
userGesture, WebScriptExecutionCallback* callback) |
33 : SuspendableTimer(frame->document()) | 33 : SuspendableTimer(frame->document()) |
34 , m_frame(frame) | 34 , m_frame(frame) |
| 35 , m_sources(sources) |
| 36 , m_callback(callback) |
35 , m_worldID(worldID) | 37 , m_worldID(worldID) |
36 , m_sources(sources) | |
37 , m_extensionGroup(extensionGroup) | 38 , m_extensionGroup(extensionGroup) |
38 , m_userGesture(userGesture) | 39 , m_userGesture(userGesture) |
39 , m_callback(callback) | |
40 #if ENABLE(ASSERT) | 40 #if ENABLE(ASSERT) |
41 , m_disposed(false) | 41 , m_disposed(false) |
42 #endif | 42 #endif |
43 { | 43 { |
44 } | 44 } |
45 | 45 |
46 SuspendableScriptExecutor::~SuspendableScriptExecutor() | 46 SuspendableScriptExecutor::~SuspendableScriptExecutor() |
47 { | 47 { |
48 #if ENABLE(ASSERT) | |
49 ASSERT(m_disposed); | 48 ASSERT(m_disposed); |
50 #endif | |
51 } | 49 } |
52 | 50 |
53 void SuspendableScriptExecutor::fired() | 51 void SuspendableScriptExecutor::fired() |
54 { | 52 { |
55 executeAndDestroySelf(); | 53 executeAndDestroySelf(); |
56 } | 54 } |
57 | 55 |
58 void SuspendableScriptExecutor::run() | 56 void SuspendableScriptExecutor::run() |
59 { | 57 { |
60 ExecutionContext* context = executionContext(); | 58 ExecutionContext* context = executionContext(); |
61 ASSERT(context); | 59 ASSERT(context); |
62 if (!context->activeDOMObjectsAreSuspended()) { | 60 if (!context->activeDOMObjectsAreSuspended()) { |
63 suspendIfNeeded(); | 61 suspendIfNeeded(); |
64 executeAndDestroySelf(); | 62 executeAndDestroySelf(); |
65 return; | 63 return; |
66 } | 64 } |
67 startOneShot(0, FROM_HERE); | 65 startOneShot(0, FROM_HERE); |
68 suspendIfNeeded(); | 66 suspendIfNeeded(); |
69 } | 67 } |
70 | 68 |
71 void SuspendableScriptExecutor::executeAndDestroySelf() | 69 void SuspendableScriptExecutor::executeAndDestroySelf() |
72 { | 70 { |
73 // Ensure that this object is not deleted even if the context is destroyed. | |
74 RefPtrWillBeRawPtr<SuspendableScriptExecutor> protect(this); | |
75 | |
76 // after calling the destructor of object - object will be unsubscribed from | 71 // after calling the destructor of object - object will be unsubscribed from |
77 // resumed and contextDestroyed LifecycleObserver methods | 72 // resumed and contextDestroyed LifecycleObserver methods |
78 OwnPtr<UserGestureIndicator> indicator; | 73 OwnPtr<UserGestureIndicator> indicator; |
79 if (m_userGesture) | 74 if (m_userGesture) |
80 indicator = adoptPtr(new UserGestureIndicator(DefinitelyProcessingNewUse
rGesture)); | 75 indicator = adoptPtr(new UserGestureIndicator(DefinitelyProcessingNewUse
rGesture)); |
81 | 76 |
82 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 77 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
83 Vector<v8::Local<v8::Value>> results; | 78 Vector<v8::Local<v8::Value>> results; |
84 if (m_worldID) { | 79 if (m_worldID) { |
85 m_frame->script().executeScriptInIsolatedWorld(m_worldID, m_sources, m_e
xtensionGroup, &results); | 80 m_frame->script().executeScriptInIsolatedWorld(m_worldID, m_sources, m_e
xtensionGroup, &results); |
(...skipping 10 matching lines...) Expand all Loading... |
96 m_callback->completed(results); | 91 m_callback->completed(results); |
97 dispose(); | 92 dispose(); |
98 } | 93 } |
99 | 94 |
100 void SuspendableScriptExecutor::dispose() | 95 void SuspendableScriptExecutor::dispose() |
101 { | 96 { |
102 #if ENABLE(ASSERT) | 97 #if ENABLE(ASSERT) |
103 m_disposed = true; | 98 m_disposed = true; |
104 #endif | 99 #endif |
105 | 100 |
106 #if ENABLE(OILPAN) | |
107 // Remove object as a ContextLifecycleObserver. | 101 // Remove object as a ContextLifecycleObserver. |
108 ActiveDOMObject::clearContext(); | 102 ActiveDOMObject::clearContext(); |
109 #endif | 103 m_keepAlive.clear(); |
110 deref(); | 104 stop(); |
111 } | 105 } |
112 | 106 |
113 DEFINE_TRACE(SuspendableScriptExecutor) | 107 DEFINE_TRACE(SuspendableScriptExecutor) |
114 { | 108 { |
115 #if ENABLE(OILPAN) | |
116 visitor->trace(m_frame); | 109 visitor->trace(m_frame); |
117 visitor->trace(m_sources); | 110 visitor->trace(m_sources); |
118 #endif | |
119 SuspendableTimer::trace(visitor); | 111 SuspendableTimer::trace(visitor); |
120 } | 112 } |
121 | 113 |
122 } // namespace blink | 114 } // namespace blink |
OLD | NEW |