| 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" |
| 41 #include "public/platform/WebSecurityOrigin.h" |
| 40 #include "public/platform/WebString.h" | 42 #include "public/platform/WebString.h" |
| 41 #include "public/platform/modules/serviceworker/WebServiceWorkerState.h" | 43 #include "public/platform/modules/serviceworker/WebServiceWorkerState.h" |
| 42 | 44 |
| 43 namespace blink { | 45 namespace blink { |
| 44 | 46 |
| 45 const AtomicString& ServiceWorker::interfaceName() const | 47 const AtomicString& ServiceWorker::interfaceName() const |
| 46 { | 48 { |
| 47 return EventTargetNames::ServiceWorker; | 49 return EventTargetNames::ServiceWorker; |
| 48 } | 50 } |
| 49 | 51 |
| 50 void ServiceWorker::postMessage(ExecutionContext* context, PassRefPtr<Serialized
ScriptValue> message, const MessagePortArray* ports, ExceptionState& exceptionSt
ate) | 52 void ServiceWorker::postMessage(ExecutionContext* context, PassRefPtr<Serialized
ScriptValue> message, const MessagePortArray* ports, ExceptionState& exceptionSt
ate) |
| 51 { | 53 { |
| 54 ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::from(ge
tExecutionContext()); |
| 55 if (!client || !client->provider()) { |
| 56 exceptionState.throwDOMException(InvalidStateError, "Failed to post a me
ssage: No associated provider is available."); |
| 57 return; |
| 58 } |
| 59 |
| 52 // Disentangle the port in preparation for sending it to the remote context. | 60 // Disentangle the port in preparation for sending it to the remote context. |
| 53 OwnPtr<MessagePortChannelArray> channels = MessagePort::disentanglePorts(con
text, ports, exceptionState); | 61 OwnPtr<MessagePortChannelArray> channels = MessagePort::disentanglePorts(con
text, ports, exceptionState); |
| 54 if (exceptionState.hadException()) | 62 if (exceptionState.hadException()) |
| 55 return; | 63 return; |
| 56 if (m_handle->serviceWorker()->state() == WebServiceWorkerStateRedundant) { | 64 if (m_handle->serviceWorker()->state() == WebServiceWorkerStateRedundant) { |
| 57 exceptionState.throwDOMException(InvalidStateError, "ServiceWorker is in
redundant state."); | 65 exceptionState.throwDOMException(InvalidStateError, "ServiceWorker is in
redundant state."); |
| 58 return; | 66 return; |
| 59 } | 67 } |
| 60 | 68 |
| 61 if (message->containsTransferableArrayBuffer()) | 69 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")); | 70 context->addConsoleMessage(ConsoleMessage::create(JSMessageSource, Warni
ngMessageLevel, "ServiceWorker cannot send an ArrayBuffer as a transferable obje
ct yet. See http://crbug.com/511119")); |
| 63 | 71 |
| 64 WebString messageString = message->toWireString(); | 72 WebString messageString = message->toWireString(); |
| 65 OwnPtr<WebMessagePortChannelArray> webChannels = MessagePort::toWebMessagePo
rtChannelArray(channels.release()); | 73 OwnPtr<WebMessagePortChannelArray> webChannels = MessagePort::toWebMessagePo
rtChannelArray(channels.release()); |
| 66 m_handle->serviceWorker()->postMessage(messageString, webChannels.leakPtr())
; | 74 m_handle->serviceWorker()->postMessage(client->provider(), messageString, We
bSecurityOrigin(getExecutionContext()->getSecurityOrigin()), webChannels.leakPtr
()); |
| 67 } | 75 } |
| 68 | 76 |
| 69 void ServiceWorker::internalsTerminate() | 77 void ServiceWorker::internalsTerminate() |
| 70 { | 78 { |
| 71 m_handle->serviceWorker()->terminate(); | 79 m_handle->serviceWorker()->terminate(); |
| 72 } | 80 } |
| 73 | 81 |
| 74 void ServiceWorker::dispatchStateChangeEvent() | 82 void ServiceWorker::dispatchStateChangeEvent() |
| 75 { | 83 { |
| 76 this->dispatchEvent(Event::create(EventTypeNames::statechange)); | 84 this->dispatchEvent(Event::create(EventTypeNames::statechange)); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 { | 154 { |
| 147 ASSERT(m_handle); | 155 ASSERT(m_handle); |
| 148 m_handle->serviceWorker()->setProxy(this); | 156 m_handle->serviceWorker()->setProxy(this); |
| 149 } | 157 } |
| 150 | 158 |
| 151 ServiceWorker::~ServiceWorker() | 159 ServiceWorker::~ServiceWorker() |
| 152 { | 160 { |
| 153 } | 161 } |
| 154 | 162 |
| 155 } // namespace blink | 163 } // namespace blink |
| OLD | NEW |