 Chromium Code Reviews
 Chromium Code Reviews Issue 1197163003:
  Oilpan: make SuspendableScriptExecutor safe.  (Closed) 
  Base URL: svn://svn.chromium.org/blink/trunk
    
  
    Issue 1197163003:
  Oilpan: make SuspendableScriptExecutor safe.  (Closed) 
  Base URL: svn://svn.chromium.org/blink/trunk| 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 RefPtrWillBeRawPtr<SuspendableScriptExecutor> executor = adoptRefWillBeNoop( new SuspendableScriptExecutor(frame, worldID, sources, extensionGroup, userGestu re, callback)); | 
| 21 #if !ENABLE(OILPAN) | |
| 
haraken
2015/06/23 08:12:01
In Oilpan, who keeps the SuspendableScriptExecutor
 
sof
2015/06/23 09:17:31
Done.
 | |
| 21 executor->ref(); | 22 executor->ref(); | 
| 23 #endif | |
| 22 executor->run(); | 24 executor->run(); | 
| 23 } | 25 } | 
| 24 | 26 | 
| 25 void SuspendableScriptExecutor::contextDestroyed() | 27 void SuspendableScriptExecutor::contextDestroyed() | 
| 26 { | 28 { | 
| 27 // this method can only be called if the script was not called in run() | 29 // this method can only be called if the script was not called in run() | 
| 28 // and context remained suspend (method resume has never called) | 30 // and context remained suspend (method resume has never called) | 
| 29 SuspendableTimer::contextDestroyed(); | 31 SuspendableTimer::contextDestroyed(); | 
| 30 m_callback->completed(Vector<v8::Local<v8::Value>>()); | 32 m_callback->completed(Vector<v8::Local<v8::Value>>()); | 
| 31 deref(); | 33 dispose(); | 
| 32 } | 34 } | 
| 33 | 35 | 
| 34 SuspendableScriptExecutor::SuspendableScriptExecutor(LocalFrame* frame, int worl dID, const WillBeHeapVector<ScriptSourceCode>& sources, int extensionGroup, bool userGesture, WebScriptExecutionCallback* callback) | 36 SuspendableScriptExecutor::SuspendableScriptExecutor(LocalFrame* frame, int worl dID, const WillBeHeapVector<ScriptSourceCode>& sources, int extensionGroup, bool userGesture, WebScriptExecutionCallback* callback) | 
| 35 : SuspendableTimer(frame->document()) | 37 : SuspendableTimer(frame->document()) | 
| 36 , m_frame(frame) | 38 , m_frame(frame) | 
| 37 , m_worldID(worldID) | 39 , m_worldID(worldID) | 
| 38 , m_sources(sources) | 40 , m_sources(sources) | 
| 39 , m_extensionGroup(extensionGroup) | 41 , m_extensionGroup(extensionGroup) | 
| 40 , m_userGesture(userGesture) | 42 , m_userGesture(userGesture) | 
| 41 , m_callback(callback) | 43 , m_callback(callback) | 
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 | 76 | 
| 75 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 77 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 
| 76 Vector<v8::Local<v8::Value>> results; | 78 Vector<v8::Local<v8::Value>> results; | 
| 77 if (m_worldID) { | 79 if (m_worldID) { | 
| 78 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); | 
| 79 } else { | 81 } else { | 
| 80 v8::Local<v8::Value> scriptValue = m_frame->script().executeScriptInMain WorldAndReturnValue(m_sources.first()); | 82 v8::Local<v8::Value> scriptValue = m_frame->script().executeScriptInMain WorldAndReturnValue(m_sources.first()); | 
| 81 results.append(scriptValue); | 83 results.append(scriptValue); | 
| 82 } | 84 } | 
| 83 m_callback->completed(results); | 85 m_callback->completed(results); | 
| 86 dispose(); | |
| 87 } | |
| 88 | |
| 89 void SuspendableScriptExecutor::dispose() | |
| 90 { | |
| 91 #if ENABLE(OILPAN) | |
| 92 // Remove object as a ContextLifecycleObserver. | |
| 93 ActiveDOMObject::clearContext(); | |
| 94 #else | |
| 84 deref(); | 95 deref(); | 
| 96 #endif | |
| 85 } | 97 } | 
| 86 | 98 | 
| 87 DEFINE_TRACE(SuspendableScriptExecutor) | 99 DEFINE_TRACE(SuspendableScriptExecutor) | 
| 88 { | 100 { | 
| 89 #if ENABLE(OILPAN) | 101 #if ENABLE(OILPAN) | 
| 90 visitor->trace(m_frame); | 102 visitor->trace(m_frame); | 
| 91 visitor->trace(m_sources); | 103 visitor->trace(m_sources); | 
| 92 #endif | 104 #endif | 
| 93 SuspendableTimer::trace(visitor); | 105 SuspendableTimer::trace(visitor); | 
| 94 } | 106 } | 
| 95 | 107 | 
| 96 } // namespace blink | 108 } // namespace blink | 
| OLD | NEW |