Chromium Code Reviews| 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); |
| } |