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

Unified Diff: third_party/WebKit/Source/modules/serviceworkers/ServiceWorker.cpp

Issue 1701843002: ServiceWorker: Implement 'source' and 'origin' attributes of ExtendableMessageEvent (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move_focus_into_utils
Patch Set: fix oilpan build Created 4 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/serviceworkers/ServiceWorker.cpp
diff --git a/third_party/WebKit/Source/modules/serviceworkers/ServiceWorker.cpp b/third_party/WebKit/Source/modules/serviceworkers/ServiceWorker.cpp
index 16d287892bc8d21b2b1d550f3473cf21fe7da29f..b09694d9654913cabdaf3e270d3d6f34b384ffd3 100644
--- a/third_party/WebKit/Source/modules/serviceworkers/ServiceWorker.cpp
+++ b/third_party/WebKit/Source/modules/serviceworkers/ServiceWorker.cpp
@@ -36,6 +36,7 @@
#include "core/events/Event.h"
#include "core/inspector/ConsoleMessage.h"
#include "modules/EventTargetModules.h"
+#include "modules/serviceworkers/ServiceWorkerContainerClient.h"
#include "public/platform/WebMessagePortChannel.h"
#include "public/platform/WebString.h"
#include "public/platform/modules/serviceworker/WebServiceWorkerState.h"
@@ -49,6 +50,11 @@ const AtomicString& ServiceWorker::interfaceName() const
void ServiceWorker::postMessage(ExecutionContext* context, PassRefPtr<SerializedScriptValue> message, const MessagePortArray* ports, ExceptionState& exceptionState)
{
+ if (!m_provider) {
+ exceptionState.throwDOMException(InvalidStateError, "Failed to post a message: No associated provider is available.");
+ return;
+ }
falken 2016/03/02 09:02:48 Instead of keeping track of m_provider, would it b
nhiroki 2016/03/02 09:57:12 Good point. Changed!
+
// Disentangle the port in preparation for sending it to the remote context.
OwnPtr<MessagePortChannelArray> channels = MessagePort::disentanglePorts(context, ports, exceptionState);
if (exceptionState.hadException())
@@ -63,7 +69,7 @@ void ServiceWorker::postMessage(ExecutionContext* context, PassRefPtr<Serialized
WebString messageString = message->toWireString();
OwnPtr<WebMessagePortChannelArray> webChannels = MessagePort::toWebMessagePortChannelArray(channels.release());
- m_handle->serviceWorker()->postMessage(messageString, webChannels.leakPtr());
+ m_handle->serviceWorker()->postMessage(m_provider, messageString, webChannels.leakPtr());
}
void ServiceWorker::internalsTerminate()
@@ -116,6 +122,11 @@ bool ServiceWorker::hasPendingActivity() const
return m_handle->serviceWorker()->state() != WebServiceWorkerStateRedundant;
}
+void ServiceWorker::contextDestroyed()
+{
+ m_provider = nullptr;
+}
+
ServiceWorker* ServiceWorker::getOrCreate(ExecutionContext* executionContext, PassOwnPtr<WebServiceWorker::Handle> handle)
{
if (!handle)
@@ -133,8 +144,12 @@ ServiceWorker* ServiceWorker::getOrCreate(ExecutionContext* executionContext, Pa
ServiceWorker::ServiceWorker(ExecutionContext* executionContext, PassOwnPtr<WebServiceWorker::Handle> handle)
: AbstractWorker(executionContext)
, m_handle(handle)
+ , m_provider(nullptr)
{
ASSERT(m_handle);
+
+ if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::from(executionContext))
+ m_provider = client->provider();
m_handle->serviceWorker()->setProxy(this);
}

Powered by Google App Engine
This is Rietveld 408576698