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

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() 25 void SuspendableScriptExecutor::resume()
26 { 26 {
27 executeAndDestroySelf(); 27 if (!m_isStarted)
pfeldman 2015/02/04 12:45:20 This implies that the code containing alert will a
kozy 2015/02/04 13:12:33 Fixed.
28 executeAndDestroySelf();
28 } 29 }
29 30
30 void SuspendableScriptExecutor::contextDestroyed() 31 void SuspendableScriptExecutor::contextDestroyed()
31 { 32 {
32 // this method can only be called if the script was not called in run() 33 // this method can only be called if the script was not called in run()
33 // and context remained suspend (method resume has never called) 34 // and context remained suspend (method resume has never called)
34 ActiveDOMObject::contextDestroyed(); 35 ActiveDOMObject::contextDestroyed();
35 m_callback->completed(Vector<v8::Local<v8::Value>>()); 36 if (!m_isStarted) {
36 deref(); 37 m_callback->completed(Vector<v8::Local<v8::Value>>());
38 deref();
39 }
37 } 40 }
38 41
39 SuspendableScriptExecutor::SuspendableScriptExecutor(LocalFrame* frame, int worl dID, const WillBeHeapVector<ScriptSourceCode>& sources, int extensionGroup, bool userGesture, WebScriptExecutionCallback* callback) 42 SuspendableScriptExecutor::SuspendableScriptExecutor(LocalFrame* frame, int worl dID, const WillBeHeapVector<ScriptSourceCode>& sources, int extensionGroup, bool userGesture, WebScriptExecutionCallback* callback)
40 : ActiveDOMObject(frame->document()) 43 : ActiveDOMObject(frame->document())
41 , m_frame(frame) 44 , m_frame(frame)
42 , m_worldID(worldID) 45 , m_worldID(worldID)
43 , m_sources(sources) 46 , m_sources(sources)
44 , m_extensionGroup(extensionGroup) 47 , m_extensionGroup(extensionGroup)
45 , m_userGesture(userGesture) 48 , m_userGesture(userGesture)
49 , m_isStarted(false)
46 , m_callback(callback) 50 , m_callback(callback)
47 { 51 {
48 } 52 }
49 53
50 SuspendableScriptExecutor::~SuspendableScriptExecutor() 54 SuspendableScriptExecutor::~SuspendableScriptExecutor()
51 { 55 {
52 } 56 }
53 57
54 void SuspendableScriptExecutor::run() 58 void SuspendableScriptExecutor::run()
55 { 59 {
56 suspendIfNeeded(); 60 suspendIfNeeded();
57 ExecutionContext* context = executionContext(); 61 ExecutionContext* context = executionContext();
58 ASSERT(context); 62 ASSERT(context);
59 if (context && !context->activeDOMObjectsAreSuspended()) 63 if (!m_isStarted && context && !context->activeDOMObjectsAreSuspended())
60 executeAndDestroySelf(); 64 executeAndDestroySelf();
61 } 65 }
62 66
63 void SuspendableScriptExecutor::executeAndDestroySelf() 67 void SuspendableScriptExecutor::executeAndDestroySelf()
64 { 68 {
69 m_isStarted = true;
65 // after calling the destructor of object - object will be unsubscribed from 70 // after calling the destructor of object - object will be unsubscribed from
66 // resumed and contextDestroyed LifecycleObserver methods 71 // resumed and contextDestroyed LifecycleObserver methods
67 OwnPtr<UserGestureIndicator> indicator; 72 OwnPtr<UserGestureIndicator> indicator;
68 if (m_userGesture) 73 if (m_userGesture)
69 indicator = adoptPtr(new UserGestureIndicator(DefinitelyProcessingNewUse rGesture)); 74 indicator = adoptPtr(new UserGestureIndicator(DefinitelyProcessingNewUse rGesture));
70 75
71 v8::HandleScope scope(v8::Isolate::GetCurrent()); 76 v8::HandleScope scope(v8::Isolate::GetCurrent());
72 Vector<v8::Local<v8::Value>> results; 77 Vector<v8::Local<v8::Value>> results;
73 if (m_worldID) { 78 if (m_worldID) {
74 m_frame->script().executeScriptInIsolatedWorld(m_worldID, m_sources, m_e xtensionGroup, &results); 79 m_frame->script().executeScriptInIsolatedWorld(m_worldID, m_sources, m_e xtensionGroup, &results);
75 } else { 80 } else {
76 v8::Local<v8::Value> scriptValue = m_frame->script().executeScriptInMain WorldAndReturnValue(m_sources.first()); 81 v8::Local<v8::Value> scriptValue = m_frame->script().executeScriptInMain WorldAndReturnValue(m_sources.first());
77 results.append(scriptValue); 82 results.append(scriptValue);
78 } 83 }
79 m_callback->completed(results); 84 m_callback->completed(results);
80 deref(); 85 deref();
81 } 86 }
82 87
83 void SuspendableScriptExecutor::trace(Visitor* visitor) 88 void SuspendableScriptExecutor::trace(Visitor* visitor)
84 { 89 {
85 #if ENABLE(OILPAN) 90 #if ENABLE(OILPAN)
86 visitor->trace(m_frame); 91 visitor->trace(m_frame);
87 visitor->trace(m_sources); 92 visitor->trace(m_sources);
88 #endif 93 #endif
89 ActiveDOMObject::trace(visitor); 94 ActiveDOMObject::trace(visitor);
90 } 95 }
91 96
92 } // namespace blink 97 } // 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