| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "modules/serviceworkers/ServiceWorker.h" | 31 #include "modules/serviceworkers/ServiceWorker.h" |
| 32 | 32 |
| 33 #include "bindings/core/v8/ExceptionState.h" | 33 #include "bindings/core/v8/ExceptionState.h" |
| 34 #include "core/dom/ExceptionCode.h" | 34 #include "core/dom/ExceptionCode.h" |
| 35 #include "core/dom/MessagePort.h" | 35 #include "core/dom/MessagePort.h" |
| 36 #include "core/events/Event.h" | 36 #include "core/events/Event.h" |
| 37 #include "core/inspector/ConsoleMessage.h" | 37 #include "core/inspector/ConsoleMessage.h" |
| 38 #include "modules/EventTargetModules.h" | 38 #include "modules/EventTargetModules.h" |
| 39 #include "modules/serviceworkers/ServiceWorkerContainerClient.h" |
| 39 #include "public/platform/WebMessagePortChannel.h" | 40 #include "public/platform/WebMessagePortChannel.h" |
| 40 #include "public/platform/WebString.h" | 41 #include "public/platform/WebString.h" |
| 41 #include "public/platform/modules/serviceworker/WebServiceWorkerState.h" | 42 #include "public/platform/modules/serviceworker/WebServiceWorkerState.h" |
| 42 | 43 |
| 43 namespace blink { | 44 namespace blink { |
| 44 | 45 |
| 45 const AtomicString& ServiceWorker::interfaceName() const | 46 const AtomicString& ServiceWorker::interfaceName() const |
| 46 { | 47 { |
| 47 return EventTargetNames::ServiceWorker; | 48 return EventTargetNames::ServiceWorker; |
| 48 } | 49 } |
| 49 | 50 |
| 50 void ServiceWorker::postMessage(ExecutionContext* context, PassRefPtr<Serialized
ScriptValue> message, const MessagePortArray* ports, ExceptionState& exceptionSt
ate) | 51 void ServiceWorker::postMessage(ExecutionContext* context, PassRefPtr<Serialized
ScriptValue> message, const MessagePortArray* ports, ExceptionState& exceptionSt
ate) |
| 51 { | 52 { |
| 53 ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::from(ex
ecutionContext()); |
| 54 if (!client || !client->provider()) { |
| 55 exceptionState.throwDOMException(InvalidStateError, "Failed to post a me
ssage: No associated provider is available."); |
| 56 return; |
| 57 } |
| 58 |
| 52 // Disentangle the port in preparation for sending it to the remote context. | 59 // Disentangle the port in preparation for sending it to the remote context. |
| 53 OwnPtr<MessagePortChannelArray> channels = MessagePort::disentanglePorts(con
text, ports, exceptionState); | 60 OwnPtr<MessagePortChannelArray> channels = MessagePort::disentanglePorts(con
text, ports, exceptionState); |
| 54 if (exceptionState.hadException()) | 61 if (exceptionState.hadException()) |
| 55 return; | 62 return; |
| 56 if (m_handle->serviceWorker()->state() == WebServiceWorkerStateRedundant) { | 63 if (m_handle->serviceWorker()->state() == WebServiceWorkerStateRedundant) { |
| 57 exceptionState.throwDOMException(InvalidStateError, "ServiceWorker is in
redundant state."); | 64 exceptionState.throwDOMException(InvalidStateError, "ServiceWorker is in
redundant state."); |
| 58 return; | 65 return; |
| 59 } | 66 } |
| 60 | 67 |
| 61 if (message->containsTransferableArrayBuffer()) | 68 if (message->containsTransferableArrayBuffer()) |
| 62 context->addConsoleMessage(ConsoleMessage::create(JSMessageSource, Warni
ngMessageLevel, "ServiceWorker cannot send an ArrayBuffer as a transferable obje
ct yet. See http://crbug.com/511119")); | 69 context->addConsoleMessage(ConsoleMessage::create(JSMessageSource, Warni
ngMessageLevel, "ServiceWorker cannot send an ArrayBuffer as a transferable obje
ct yet. See http://crbug.com/511119")); |
| 63 | 70 |
| 64 WebString messageString = message->toWireString(); | 71 WebString messageString = message->toWireString(); |
| 65 OwnPtr<WebMessagePortChannelArray> webChannels = MessagePort::toWebMessagePo
rtChannelArray(channels.release()); | 72 OwnPtr<WebMessagePortChannelArray> webChannels = MessagePort::toWebMessagePo
rtChannelArray(channels.release()); |
| 66 m_handle->serviceWorker()->postMessage(messageString, webChannels.leakPtr())
; | 73 m_handle->serviceWorker()->postMessage(client->provider(), messageString, we
bChannels.leakPtr()); |
| 67 } | 74 } |
| 68 | 75 |
| 69 void ServiceWorker::internalsTerminate() | 76 void ServiceWorker::internalsTerminate() |
| 70 { | 77 { |
| 71 m_handle->serviceWorker()->terminate(); | 78 m_handle->serviceWorker()->terminate(); |
| 72 } | 79 } |
| 73 | 80 |
| 74 void ServiceWorker::dispatchStateChangeEvent() | 81 void ServiceWorker::dispatchStateChangeEvent() |
| 75 { | 82 { |
| 76 this->dispatchEvent(Event::create(EventTypeNames::statechange)); | 83 this->dispatchEvent(Event::create(EventTypeNames::statechange)); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 { | 143 { |
| 137 ASSERT(m_handle); | 144 ASSERT(m_handle); |
| 138 m_handle->serviceWorker()->setProxy(this); | 145 m_handle->serviceWorker()->setProxy(this); |
| 139 } | 146 } |
| 140 | 147 |
| 141 ServiceWorker::~ServiceWorker() | 148 ServiceWorker::~ServiceWorker() |
| 142 { | 149 { |
| 143 } | 150 } |
| 144 | 151 |
| 145 } // namespace blink | 152 } // namespace blink |
| OLD | NEW |