| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "modules/serviceworkers/ServiceWorkerClient.h" | 6 #include "modules/serviceworkers/ServiceWorkerClient.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/CallbackPromiseAdapter.h" | 8 #include "bindings/core/v8/CallbackPromiseAdapter.h" |
| 9 #include "bindings/core/v8/ExceptionState.h" | 9 #include "bindings/core/v8/ExceptionState.h" |
| 10 #include "bindings/core/v8/SerializedScriptValue.h" | 10 #include "bindings/core/v8/SerializedScriptValue.h" |
| 11 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" | 11 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" |
| 12 #include "public/platform/WebString.h" | 12 #include "public/platform/WebString.h" |
| 13 #include "wtf/RefPtr.h" | 13 #include "wtf/RefPtr.h" |
| 14 | 14 |
| 15 namespace blink { | 15 namespace blink { |
| 16 | 16 |
| 17 ServiceWorkerClient* ServiceWorkerClient::create(const WebServiceWorkerClientInf
o& info) | 17 ServiceWorkerClient* ServiceWorkerClient::create(const WebServiceWorkerClientInf
o& info) |
| 18 { | 18 { |
| 19 return new ServiceWorkerClient(info); | 19 return new ServiceWorkerClient(info); |
| 20 } | 20 } |
| 21 | 21 |
| 22 ServiceWorkerClient::ServiceWorkerClient(const WebServiceWorkerClientInfo& info) | 22 ServiceWorkerClient::ServiceWorkerClient(const WebServiceWorkerClientInfo& info) |
| 23 : m_id(info.clientID) | 23 : m_id(info.clientID) |
| 24 , m_uuid(info.uuid) |
| 24 , m_url(info.url.string()) | 25 , m_url(info.url.string()) |
| 25 { | 26 { |
| 26 } | 27 } |
| 27 | 28 |
| 28 ServiceWorkerClient::~ServiceWorkerClient() | 29 ServiceWorkerClient::~ServiceWorkerClient() |
| 29 { | 30 { |
| 30 } | 31 } |
| 31 | 32 |
| 32 void ServiceWorkerClient::postMessage(ExecutionContext* context, PassRefPtr<Seri
alizedScriptValue> message, const MessagePortArray* ports, ExceptionState& excep
tionState) | 33 void ServiceWorkerClient::postMessage(ExecutionContext* context, PassRefPtr<Seri
alizedScriptValue> message, const MessagePortArray* ports, ExceptionState& excep
tionState) |
| 33 { | 34 { |
| 34 // Disentangle the port in preparation for sending it to the remote context. | 35 // Disentangle the port in preparation for sending it to the remote context. |
| 35 OwnPtr<MessagePortChannelArray> channels = MessagePort::disentanglePorts(por
ts, exceptionState); | 36 OwnPtr<MessagePortChannelArray> channels = MessagePort::disentanglePorts(por
ts, exceptionState); |
| 36 if (exceptionState.hadException()) | 37 if (exceptionState.hadException()) |
| 37 return; | 38 return; |
| 38 | 39 |
| 39 WebString messageString = message->toWireString(); | 40 WebString messageString = message->toWireString(); |
| 40 OwnPtr<WebMessagePortChannelArray> webChannels = MessagePort::toWebMessagePo
rtChannelArray(channels.release()); | 41 OwnPtr<WebMessagePortChannelArray> webChannels = MessagePort::toWebMessagePo
rtChannelArray(channels.release()); |
| 41 ServiceWorkerGlobalScopeClient::from(context)->postMessageToClient(m_id, mes
sageString, webChannels.release()); | 42 if (!m_uuid.isEmpty()) { |
| 43 ServiceWorkerGlobalScopeClient::from(context)->postMessageToClient(m_uui
d, messageString, webChannels.release()); |
| 44 } else { |
| 45 // FIXME: Deprecate this when we switch to uuid. |
| 46 ServiceWorkerGlobalScopeClient::from(context)->postMessageToClient(m_id,
messageString, webChannels.release()); |
| 47 } |
| 42 } | 48 } |
| 43 | 49 |
| 44 } // namespace blink | 50 } // namespace blink |
| OLD | NEW |