Added SuspendableScriptExecutor::createAndRun to replace ctor+run

R=vsevik@chromium.org,aandrey@chromium.org,pfeldman@chromium.org

Review URL: https://codereview.chromium.org/649183010

git-svn-id: svn://svn.chromium.org/blink/trunk@184344 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent fc85a511
...@@ -14,6 +14,26 @@ ...@@ -14,6 +14,26 @@
namespace blink { namespace blink {
void SuspendableScriptExecutor::createAndRun(LocalFrame* frame, int worldID, const Vector<ScriptSourceCode>& sources, int extensionGroup, bool userGesture, WebScriptExecutionCallback* callback)
{
SuspendableScriptExecutor* executor = new SuspendableScriptExecutor(frame, worldID, sources, extensionGroup, userGesture, callback);
executor->run();
}
void SuspendableScriptExecutor::resume()
{
executeAndDestroySelf();
}
void SuspendableScriptExecutor::contextDestroyed()
{
// this method can only be called if the script was not called in run()
// and context remained suspend (method resume has never called)
ActiveDOMObject::contextDestroyed();
m_callback->completed(Vector<v8::Local<v8::Value> >());
delete this;
}
SuspendableScriptExecutor::SuspendableScriptExecutor(LocalFrame* frame, int worldID, const Vector<ScriptSourceCode>& sources, int extensionGroup, bool userGesture, WebScriptExecutionCallback* callback) SuspendableScriptExecutor::SuspendableScriptExecutor(LocalFrame* frame, int worldID, const Vector<ScriptSourceCode>& sources, int extensionGroup, bool userGesture, WebScriptExecutionCallback* callback)
: ActiveDOMObject(frame->document()) : ActiveDOMObject(frame->document())
, m_frame(frame) , m_frame(frame)
...@@ -38,20 +58,6 @@ void SuspendableScriptExecutor::run() ...@@ -38,20 +58,6 @@ void SuspendableScriptExecutor::run()
executeAndDestroySelf(); executeAndDestroySelf();
} }
void SuspendableScriptExecutor::resume()
{
executeAndDestroySelf();
}
void SuspendableScriptExecutor::contextDestroyed()
{
// this method can only be called if the script was not called in run()
// and context remained suspend (method resume has never called)
ActiveDOMObject::contextDestroyed();
m_callback->completed(Vector<v8::Local<v8::Value> >());
delete this;
}
void SuspendableScriptExecutor::executeAndDestroySelf() void SuspendableScriptExecutor::executeAndDestroySelf()
{ {
// after calling the destructor of object - object will be unsubscribed from // after calling the destructor of object - object will be unsubscribed from
......
...@@ -17,17 +17,16 @@ class WebScriptExecutionCallback; ...@@ -17,17 +17,16 @@ class WebScriptExecutionCallback;
class SuspendableScriptExecutor final : public ActiveDOMObject { class SuspendableScriptExecutor final : public ActiveDOMObject {
public: public:
SuspendableScriptExecutor(LocalFrame*, int worldID, const Vector<ScriptSourceCode>& sources, int extensionGroup, bool userGesture, WebScriptExecutionCallback*); static void createAndRun(LocalFrame*, int worldID, const Vector<ScriptSourceCode>& sources, int extensionGroup, bool userGesture, WebScriptExecutionCallback*);
virtual ~SuspendableScriptExecutor();
// this method must be called only once
void run();
virtual void resume() override; virtual void resume() override;
virtual void contextDestroyed() override; virtual void contextDestroyed() override;
private: private:
SuspendableScriptExecutor(LocalFrame*, int worldID, const Vector<ScriptSourceCode>& sources, int extensionGroup, bool userGesture, WebScriptExecutionCallback*);
virtual ~SuspendableScriptExecutor();
void run();
void executeAndDestroySelf(); void executeAndDestroySelf();
LocalFrame* m_frame; LocalFrame* m_frame;
......
...@@ -789,9 +789,7 @@ void WebLocalFrameImpl::requestExecuteScriptAndReturnValue(const WebScriptSource ...@@ -789,9 +789,7 @@ void WebLocalFrameImpl::requestExecuteScriptAndReturnValue(const WebScriptSource
{ {
ASSERT(frame()); ASSERT(frame());
Vector<ScriptSourceCode> sources = createSourcesVector(&source, 1); SuspendableScriptExecutor::createAndRun(frame(), 0, createSourcesVector(&source, 1), 0, userGesture, callback);
SuspendableScriptExecutor* executor = new SuspendableScriptExecutor(frame(), 0, sources, 0, userGesture, callback);
executor->run();
} }
void WebLocalFrameImpl::executeScriptInIsolatedWorld(int worldID, const WebScriptSource* sourcesIn, unsigned numSources, int extensionGroup, WebVector<v8::Local<v8::Value> >* results) void WebLocalFrameImpl::executeScriptInIsolatedWorld(int worldID, const WebScriptSource* sourcesIn, unsigned numSources, int extensionGroup, WebVector<v8::Local<v8::Value> >* results)
...@@ -821,9 +819,7 @@ void WebLocalFrameImpl::requestExecuteScriptInIsolatedWorld(int worldID, const W ...@@ -821,9 +819,7 @@ void WebLocalFrameImpl::requestExecuteScriptInIsolatedWorld(int worldID, const W
RELEASE_ASSERT(worldID > 0); RELEASE_ASSERT(worldID > 0);
RELEASE_ASSERT(worldID < EmbedderWorldIdLimit); RELEASE_ASSERT(worldID < EmbedderWorldIdLimit);
Vector<ScriptSourceCode> sources = createSourcesVector(sourcesIn, numSources); SuspendableScriptExecutor::createAndRun(frame(), worldID, createSourcesVector(sourcesIn, numSources), extensionGroup, userGesture, callback);
SuspendableScriptExecutor* executor = new SuspendableScriptExecutor(frame(), worldID, sources, extensionGroup, userGesture, callback);
executor->run();
} }
v8::Handle<v8::Value> WebLocalFrameImpl::callFunctionEvenIfScriptDisabled(v8::Handle<v8::Function> function, v8::Handle<v8::Value> receiver, int argc, v8::Handle<v8::Value> argv[]) v8::Handle<v8::Value> WebLocalFrameImpl::callFunctionEvenIfScriptDisabled(v8::Handle<v8::Function> function, v8::Handle<v8::Value> receiver, int argc, v8::Handle<v8::Value> argv[])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment