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

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

Issue 474683003: Not for review - Rebase of crrev.com/62833003 Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: . Created 6 years, 2 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/UIWorkerGlobalScope.h ('k') | Source/core/workers/UIWorkerGlobalScope.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/workers/UIWorkerGlobalScope.cpp
diff --git a/Source/core/workers/UIWorkerGlobalScope.cpp b/Source/core/workers/UIWorkerGlobalScope.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..31dfda17f2cd8526b819c32b6d97fa914901f347
--- /dev/null
+++ b/Source/core/workers/UIWorkerGlobalScope.cpp
@@ -0,0 +1,187 @@
+/*
+ * Copyright (C) 2009 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "core/workers/UIWorkerGlobalScope.h"
+
+#include "bindings/core/v8/ExceptionState.h"
+#include "bindings/core/v8/SerializedScriptValue.h"
+#include "core/frame/LocalDOMWindow.h"
+#include "core/workers/UIWorkerThread.h"
+#include "core/workers/WorkerClients.h"
+#include "core/workers/WorkerObjectProxy.h"
+#include "core/workers/WorkerThreadStartupData.h"
+#include "platform/TraceEvent.h"
+#include "public/platform/WebTeleportCallback.h"
+#include "public/platform/WebTeleporter.h"
+
+namespace blink {
+
+namespace {
+
+class WebTeleportCallbackWrapper : public WebTeleportCallback {
+public:
+ WebTeleportCallbackWrapper(
+ TeleportCallback* callback,
+ PassRefPtrWillBeRawPtr<TeleportContext> context,
+ Vector<OwnPtr<WebTeleportCallback> >* callbacks,
+ WebTeleporter* teleporter)
+ : m_callback(callback)
+ , m_context(context)
+ , m_callbacks(callbacks)
+ , m_teleporter(teleporter)
+ {
+ if (m_context)
+ m_values = m_context->getWebTeleportValues();
+ }
+
+ virtual void Run(const WebVector<WebTeleportValue>& values) override
+ {
+ TRACE_EVENT0("teleport", "WebTeleportCallback::Run");
+ m_context->setWebTeleportValues(values);
+ m_callback->handleEvent(m_context.get());
+ ASSERT(m_callbacks->contains(this));
+ m_teleporter->teleportMessage(WebVector<WebTeleportValue>(), 0);
+ m_callbacks->remove(m_callbacks->find(this));
+ }
+
+ WebTeleportValues* values() { return m_values.get(); }
+
+private:
+ TeleportCallback* m_callback;
+ RefPtr<TeleportContext> m_context;
+ OwnPtr<WebTeleportValues> m_values;
+ // FIXME: perhaps it would be better to pass a pointer to a
+ // WorkerCallbackRegistry or something and invoke onCallbackComplete on the
+ // registry when Run happens? This is expedient for now, but feel free to
+ // hate on this in review :)
+ Vector<OwnPtr<WebTeleportCallback> >* m_callbacks;
+ WebTeleporter* m_teleporter;
+};
+
+} // namespace
+
+PassRefPtrWillBeRawPtr<UIWorkerGlobalScope> UIWorkerGlobalScope::create(UIWorkerThread* thread, PassOwnPtrWillBeRawPtr<WorkerThreadStartupData> startupData, double timeOrigin)
+{
+ RefPtrWillBeRawPtr<UIWorkerGlobalScope> context = adoptRefWillBeNoop(new UIWorkerGlobalScope(startupData->m_scriptURL, startupData->m_userAgent, thread, timeOrigin, NULL/*TODO?*/, startupData->m_workerClients.release()));
+ context->applyContentSecurityPolicyFromString(startupData->m_contentSecurityPolicy, startupData->m_contentSecurityPolicyType);
+ return context.release();
+}
+
+UIWorkerGlobalScope::UIWorkerGlobalScope(const KURL& url, const String& userAgent, UIWorkerThread* thread, double timeOrigin, const SecurityOrigin* starterOrigin, PassOwnPtrWillBeRawPtr<WorkerClients> workerClients)
+ : WorkerGlobalScope(url, userAgent, thread, timeOrigin, starterOrigin, workerClients)
+{
+ TRACE_EVENT0("teleport,uiworker", "UIWorkerGlobalScope::UIWorkerGlobalScope");
+}
+
+UIWorkerGlobalScope::~UIWorkerGlobalScope()
+{
+}
+
+const AtomicString& UIWorkerGlobalScope::interfaceName() const
+{
+ return EventTargetNames::UIWorkerGlobalScope;
+}
+
+void UIWorkerGlobalScope::postMessage(ExecutionContext*, PassRefPtr<SerializedScriptValue> message, const MessagePortArray* ports, ExceptionState& exceptionState)
+{
+ // Disentangle the port in preparation for sending it to the remote context.
+ OwnPtr<MessagePortChannelArray> channels = MessagePort::disentanglePorts(ports, exceptionState);
+ if (exceptionState.hadException())
+ return;
+ thread()->workerObjectProxy().postMessageToWorkerObject(message, channels.release());
+}
+
+void UIWorkerGlobalScope::importScripts(const Vector<String>& urls, ExceptionState& exceptionState)
+{
+ Base::importScripts(urls, exceptionState);
+ thread()->workerObjectProxy().reportPendingActivity(hasPendingActivity());
+}
+
+
+UIWorkerThread* UIWorkerGlobalScope::thread() const
+{
+ return static_cast<UIWorkerThread*>(Base::thread());
+}
+
+class UseCounterTask : public ExecutionContextTask {
+public:
+ static PassOwnPtr<UseCounterTask> createCount(UseCounter::Feature feature) { return adoptPtr(new UseCounterTask(feature, false)); }
+ static PassOwnPtr<UseCounterTask> createDeprecation(UseCounter::Feature feature) { return adoptPtr(new UseCounterTask(feature, true)); }
+
+private:
+ UseCounterTask(UseCounter::Feature feature, bool isDeprecation)
+ : m_feature(feature)
+ , m_isDeprecation(isDeprecation)
+ {
+ }
+
+ virtual void performTask(ExecutionContext* context) override
+ {
+ ASSERT(context->isDocument());
+ if (m_isDeprecation)
+ UseCounter::countDeprecation(context, m_feature);
+ else
+ UseCounter::count(context, m_feature);
+ }
+
+ UseCounter::Feature m_feature;
+ bool m_isDeprecation;
+};
+
+void UIWorkerGlobalScope::countFeature(UseCounter::Feature feature) const
+{
+ thread()->workerObjectProxy().postTaskToMainExecutionContext(UseCounterTask::createCount(feature));
+}
+
+void UIWorkerGlobalScope::countDeprecation(UseCounter::Feature feature) const
+{
+ thread()->workerObjectProxy().postTaskToMainExecutionContext(UseCounterTask::createDeprecation(feature));
+}
+
+void UIWorkerGlobalScope::teleportMessage(PassRefPtrWillBeRawPtr<TeleportContext> context, TeleportCallback* callback, ExceptionState& exceptionState)
+{
+ TRACE_EVENT0("teleport", "UIWorkerGlobalScope::teleportMessage");
+ //OwnPtr<WebTeleportCallbackWrapper> webCallback(adoptPtr(new WebTeleportCallbackWrapper(callback, context, &m_callbacks, thread()->teleporter())));
+ OwnPtr<WebTeleportCallbackWrapper> webCallback(adoptPtr(new WebTeleportCallbackWrapper(callback, context, &m_callbacks, thread()->teleporter())));
+ if (webCallback->values()) {
+ thread()->teleporter()->teleportMessage(*webCallback->values(), webCallback.get());
+ m_callbacks.append(webCallback.release());
+ } else {
+ exceptionState.throwTypeError("Teleport failed.");
+ }
+}
+
+void UIWorkerGlobalScope::trace(Visitor* visitor)
+{
+ WorkerGlobalScope::trace(visitor);
+}
+
+} // namespace blink
« no previous file with comments | « Source/core/workers/UIWorkerGlobalScope.h ('k') | Source/core/workers/UIWorkerGlobalScope.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698