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

Unified Diff: Source/core/workers/InProcessWorkerBase.cpp

Issue 1075603003: workers: Move core worker functionality into InProcessWorkerBase. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: . Created 5 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/workers/InProcessWorkerBase.h ('k') | Source/core/workers/Worker.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/workers/InProcessWorkerBase.cpp
diff --git a/Source/core/workers/InProcessWorkerBase.cpp b/Source/core/workers/InProcessWorkerBase.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..ffa1ae6f5a43ff58ddcbb6ff49be15a3f6a55a68
--- /dev/null
+++ b/Source/core/workers/InProcessWorkerBase.cpp
@@ -0,0 +1,102 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+#include "core/workers/InProcessWorkerBase.h"
+
+#include "bindings/core/v8/ExceptionState.h"
+#include "core/events/MessageEvent.h"
+#include "core/fetch/ResourceFetcher.h"
+#include "core/frame/LocalDOMWindow.h"
+#include "core/inspector/InspectorInstrumentation.h"
+#include "core/workers/WorkerGlobalScopeProxy.h"
+#include "core/workers/WorkerScriptLoader.h"
+#include "core/workers/WorkerThread.h"
+#include "wtf/MainThread.h"
+
+namespace blink {
+
+InProcessWorkerBase::InProcessWorkerBase(ExecutionContext* context)
+ : AbstractWorker(context)
+ , m_contextProxy(nullptr)
+{
+}
+
+InProcessWorkerBase::~InProcessWorkerBase()
+{
+ ASSERT(isMainThread());
+ if (!m_contextProxy)
+ return;
+ m_contextProxy->workerObjectDestroyed();
+}
+
+void InProcessWorkerBase::postMessage(ExecutionContext*, PassRefPtr<SerializedScriptValue> message, const MessagePortArray* ports, ExceptionState& exceptionState)
+{
+ ASSERT(m_contextProxy);
+ // Disentangle the port in preparation for sending it to the remote context.
+ OwnPtr<MessagePortChannelArray> channels = MessagePort::disentanglePorts(ports, exceptionState);
+ if (exceptionState.hadException())
+ return;
+ m_contextProxy->postMessageToWorkerGlobalScope(message, channels.release());
+}
+
+bool InProcessWorkerBase::initialize(ExecutionContext* context, const String& url, ExceptionState& exceptionState)
+{
+ suspendIfNeeded();
+
+ KURL scriptURL = resolveURL(url, exceptionState);
+ if (scriptURL.isEmpty())
+ return false;
+
+ m_scriptLoader = WorkerScriptLoader::create();
+ m_scriptLoader->loadAsynchronously(*context, scriptURL, DenyCrossOriginRequests, this);
+
+ m_contextProxy = createWorkerGlobalScopeProxy(context);
+
+ return true;
+}
+
+void InProcessWorkerBase::terminate()
+{
+ if (m_contextProxy)
+ m_contextProxy->terminateWorkerGlobalScope();
+}
+
+void InProcessWorkerBase::stop()
+{
+ terminate();
+}
+
+bool InProcessWorkerBase::hasPendingActivity() const
+{
+ // The worker context does not exist while loading, so we must ensure that the worker object is not collected, nor are its event listeners.
+ return (m_contextProxy && m_contextProxy->hasPendingActivity()) || m_scriptLoader;
+}
+
+void InProcessWorkerBase::didReceiveResponse(unsigned long identifier, const ResourceResponse&)
+{
+ InspectorInstrumentation::didReceiveScriptResponse(executionContext(), identifier);
+}
+
+void InProcessWorkerBase::notifyFinished()
+{
+ if (m_scriptLoader->failed()) {
+ dispatchEvent(Event::createCancelable(EventTypeNames::error));
+ } else {
+ ASSERT(m_contextProxy);
+ WorkerThreadStartMode startMode = DontPauseWorkerGlobalScopeOnStart;
+ if (InspectorInstrumentation::shouldPauseDedicatedWorkerOnStart(executionContext()))
+ startMode = PauseWorkerGlobalScopeOnStart;
+ m_contextProxy->startWorkerGlobalScope(m_scriptLoader->url(), executionContext()->userAgent(m_scriptLoader->url()), m_scriptLoader->script(), startMode);
+ InspectorInstrumentation::scriptImported(executionContext(), m_scriptLoader->identifier(), m_scriptLoader->script());
+ }
+ m_scriptLoader = nullptr;
+}
+
+DEFINE_TRACE(InProcessWorkerBase)
+{
+ AbstractWorker::trace(visitor);
+}
+
+} // namespace blink
« no previous file with comments | « Source/core/workers/InProcessWorkerBase.h ('k') | Source/core/workers/Worker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698