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

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

Issue 869513004: SuspendableScriptExecutor executes code once (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 10 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
« no previous file with comments | « Source/web/SuspendableScriptExecutor.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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 RefPtrWillBeRawPtr<SuspendableScriptExecutor> executor = adoptRefWillBeNoop( new SuspendableScriptExecutor(frame, worldID, sources, extensionGroup, userGestu re, callback));
21 executor->ref(); 21 executor->ref();
22 executor->run(); 22 executor->run();
23 } 23 }
24 24
25 void SuspendableScriptExecutor::resume()
26 {
27 executeAndDestroySelf();
28 }
29
30 void SuspendableScriptExecutor::contextDestroyed() 25 void SuspendableScriptExecutor::contextDestroyed()
31 { 26 {
32 // this method can only be called if the script was not called in run() 27 // this method can only be called if the script was not called in run()
33 // and context remained suspend (method resume has never called) 28 // and context remained suspend (method resume has never called)
34 ActiveDOMObject::contextDestroyed(); 29 SuspendableTimer::contextDestroyed();
35 m_callback->completed(Vector<v8::Local<v8::Value>>()); 30 m_callback->completed(Vector<v8::Local<v8::Value>>());
36 deref(); 31 deref();
37 } 32 }
38 33
39 SuspendableScriptExecutor::SuspendableScriptExecutor(LocalFrame* frame, int worl dID, const WillBeHeapVector<ScriptSourceCode>& sources, int extensionGroup, bool userGesture, WebScriptExecutionCallback* callback) 34 SuspendableScriptExecutor::SuspendableScriptExecutor(LocalFrame* frame, int worl dID, const WillBeHeapVector<ScriptSourceCode>& sources, int extensionGroup, bool userGesture, WebScriptExecutionCallback* callback)
40 : ActiveDOMObject(frame->document()) 35 : SuspendableTimer(frame->document())
41 , m_frame(frame) 36 , m_frame(frame)
42 , m_worldID(worldID) 37 , m_worldID(worldID)
43 , m_sources(sources) 38 , m_sources(sources)
44 , m_extensionGroup(extensionGroup) 39 , m_extensionGroup(extensionGroup)
45 , m_userGesture(userGesture) 40 , m_userGesture(userGesture)
46 , m_callback(callback) 41 , m_callback(callback)
47 { 42 {
48 } 43 }
49 44
50 SuspendableScriptExecutor::~SuspendableScriptExecutor() 45 SuspendableScriptExecutor::~SuspendableScriptExecutor()
51 { 46 {
52 } 47 }
53 48
49 void SuspendableScriptExecutor::fired()
50 {
51 executeAndDestroySelf();
52 }
53
54 void SuspendableScriptExecutor::run() 54 void SuspendableScriptExecutor::run()
55 { 55 {
56 suspendIfNeeded();
57 ExecutionContext* context = executionContext(); 56 ExecutionContext* context = executionContext();
58 ASSERT(context); 57 ASSERT(context);
59 if (context && !context->activeDOMObjectsAreSuspended()) 58 if (!context->activeDOMObjectsAreSuspended()) {
59 suspendIfNeeded();
pfeldman 2015/02/05 13:49:42 Why do you make this call?
kozy 2015/02/05 14:58:26 We can remove it. Removed.
60 executeAndDestroySelf(); 60 executeAndDestroySelf();
61 } else {
62 startOneShot(0, FROM_HERE);
63 suspendIfNeeded();
64 }
61 } 65 }
62 66
63 void SuspendableScriptExecutor::executeAndDestroySelf() 67 void SuspendableScriptExecutor::executeAndDestroySelf()
64 { 68 {
65 // after calling the destructor of object - object will be unsubscribed from 69 // after calling the destructor of object - object will be unsubscribed from
66 // resumed and contextDestroyed LifecycleObserver methods 70 // resumed and contextDestroyed LifecycleObserver methods
67 OwnPtr<UserGestureIndicator> indicator; 71 OwnPtr<UserGestureIndicator> indicator;
68 if (m_userGesture) 72 if (m_userGesture)
69 indicator = adoptPtr(new UserGestureIndicator(DefinitelyProcessingNewUse rGesture)); 73 indicator = adoptPtr(new UserGestureIndicator(DefinitelyProcessingNewUse rGesture));
70 74
71 v8::HandleScope scope(v8::Isolate::GetCurrent()); 75 v8::HandleScope scope(v8::Isolate::GetCurrent());
72 Vector<v8::Local<v8::Value>> results; 76 Vector<v8::Local<v8::Value>> results;
73 if (m_worldID) { 77 if (m_worldID) {
74 m_frame->script().executeScriptInIsolatedWorld(m_worldID, m_sources, m_e xtensionGroup, &results); 78 m_frame->script().executeScriptInIsolatedWorld(m_worldID, m_sources, m_e xtensionGroup, &results);
75 } else { 79 } else {
76 v8::Local<v8::Value> scriptValue = m_frame->script().executeScriptInMain WorldAndReturnValue(m_sources.first()); 80 v8::Local<v8::Value> scriptValue = m_frame->script().executeScriptInMain WorldAndReturnValue(m_sources.first());
77 results.append(scriptValue); 81 results.append(scriptValue);
78 } 82 }
79 m_callback->completed(results); 83 m_callback->completed(results);
80 deref(); 84 deref();
81 } 85 }
82 86
83 void SuspendableScriptExecutor::trace(Visitor* visitor) 87 void SuspendableScriptExecutor::trace(Visitor* visitor)
84 { 88 {
85 #if ENABLE(OILPAN) 89 #if ENABLE(OILPAN)
86 visitor->trace(m_frame); 90 visitor->trace(m_frame);
87 visitor->trace(m_sources); 91 visitor->trace(m_sources);
88 #endif 92 #endif
89 ActiveDOMObject::trace(visitor); 93 SuspendableTimer::trace(visitor);
90 } 94 }
91 95
92 } // namespace blink 96 } // namespace blink
OLDNEW
« no previous file with comments | « Source/web/SuspendableScriptExecutor.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698