| 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 12 matching lines...) Expand all Loading... |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "modules/serviceworkers/ServiceWorker.h" | 31 #include "modules/serviceworkers/ServiceWorker.h" |
| 32 | 32 |
| 33 #include <memory> |
| 33 #include "bindings/core/v8/ExceptionState.h" | 34 #include "bindings/core/v8/ExceptionState.h" |
| 35 #include "bindings/core/v8/ScriptState.h" |
| 34 #include "core/dom/ExceptionCode.h" | 36 #include "core/dom/ExceptionCode.h" |
| 35 #include "core/dom/MessagePort.h" | 37 #include "core/dom/MessagePort.h" |
| 36 #include "core/events/Event.h" | 38 #include "core/events/Event.h" |
| 37 #include "modules/EventTargetModules.h" | 39 #include "modules/EventTargetModules.h" |
| 38 #include "modules/serviceworkers/ServiceWorkerContainerClient.h" | 40 #include "modules/serviceworkers/ServiceWorkerContainerClient.h" |
| 39 #include "public/platform/WebMessagePortChannel.h" | 41 #include "public/platform/WebMessagePortChannel.h" |
| 40 #include "public/platform/WebSecurityOrigin.h" | 42 #include "public/platform/WebSecurityOrigin.h" |
| 41 #include "public/platform/WebString.h" | 43 #include "public/platform/WebString.h" |
| 42 #include "public/platform/modules/serviceworker/WebServiceWorkerState.h" | 44 #include "public/platform/modules/serviceworker/WebServiceWorkerState.h" |
| 43 #include <memory> | |
| 44 | 45 |
| 45 namespace blink { | 46 namespace blink { |
| 46 | 47 |
| 47 const AtomicString& ServiceWorker::interfaceName() const { | 48 const AtomicString& ServiceWorker::interfaceName() const { |
| 48 return EventTargetNames::ServiceWorker; | 49 return EventTargetNames::ServiceWorker; |
| 49 } | 50 } |
| 50 | 51 |
| 51 void ServiceWorker::postMessage(ExecutionContext* context, | 52 void ServiceWorker::postMessage(ScriptState* scriptState, |
| 52 PassRefPtr<SerializedScriptValue> message, | 53 PassRefPtr<SerializedScriptValue> message, |
| 53 const MessagePortArray& ports, | 54 const MessagePortArray& ports, |
| 54 ExceptionState& exceptionState) { | 55 ExceptionState& exceptionState) { |
| 55 ServiceWorkerContainerClient* client = | 56 ServiceWorkerContainerClient* client = |
| 56 ServiceWorkerContainerClient::from(getExecutionContext()); | 57 ServiceWorkerContainerClient::from(getExecutionContext()); |
| 57 if (!client || !client->provider()) { | 58 if (!client || !client->provider()) { |
| 58 exceptionState.throwDOMException( | 59 exceptionState.throwDOMException( |
| 59 InvalidStateError, | 60 InvalidStateError, |
| 60 "Failed to post a message: No associated provider is available."); | 61 "Failed to post a message: No associated provider is available."); |
| 61 return; | 62 return; |
| 62 } | 63 } |
| 63 | 64 |
| 64 // Disentangle the port in preparation for sending it to the remote context. | 65 // Disentangle the port in preparation for sending it to the remote context. |
| 65 std::unique_ptr<MessagePortChannelArray> channels = | 66 std::unique_ptr<MessagePortChannelArray> channels = |
| 66 MessagePort::disentanglePorts(context, ports, exceptionState); | 67 MessagePort::disentanglePorts(scriptState->getExecutionContext(), ports, |
| 68 exceptionState); |
| 67 if (exceptionState.hadException()) | 69 if (exceptionState.hadException()) |
| 68 return; | 70 return; |
| 69 if (m_handle->serviceWorker()->state() == WebServiceWorkerStateRedundant) { | 71 if (m_handle->serviceWorker()->state() == WebServiceWorkerStateRedundant) { |
| 70 exceptionState.throwDOMException(InvalidStateError, | 72 exceptionState.throwDOMException(InvalidStateError, |
| 71 "ServiceWorker is in redundant state."); | 73 "ServiceWorker is in redundant state."); |
| 72 return; | 74 return; |
| 73 } | 75 } |
| 74 | 76 |
| 75 WebString messageString = message->toWireString(); | 77 WebString messageString = message->toWireString(); |
| 76 std::unique_ptr<WebMessagePortChannelArray> webChannels = | 78 std::unique_ptr<WebMessagePortChannelArray> webChannels = |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 m_handle->serviceWorker()->setProxy(this); | 158 m_handle->serviceWorker()->setProxy(this); |
| 157 } | 159 } |
| 158 | 160 |
| 159 ServiceWorker::~ServiceWorker() {} | 161 ServiceWorker::~ServiceWorker() {} |
| 160 | 162 |
| 161 DEFINE_TRACE(ServiceWorker) { | 163 DEFINE_TRACE(ServiceWorker) { |
| 162 AbstractWorker::trace(visitor); | 164 AbstractWorker::trace(visitor); |
| 163 } | 165 } |
| 164 | 166 |
| 165 } // namespace blink | 167 } // namespace blink |
| OLD | NEW |