| 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 "modules/serviceworkers/ServiceWorkerClient.h" | 5 #include "modules/serviceworkers/ServiceWorkerClient.h" |
| 6 #include "modules/serviceworkers/ServiceWorkerWindowClient.h" | 6 #include "modules/serviceworkers/ServiceWorkerWindowClient.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 "core/inspector/ConsoleMessage.h" | 11 #include "core/inspector/ConsoleMessage.h" |
| 12 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" | 12 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" |
| 13 #include "public/platform/WebString.h" | 13 #include "public/platform/WebString.h" |
| 14 #include "wtf/RefPtr.h" | 14 #include "wtf/RefPtr.h" |
| 15 #include <memory> | |
| 16 | 15 |
| 17 namespace blink { | 16 namespace blink { |
| 18 | 17 |
| 19 ServiceWorkerClient* ServiceWorkerClient::take(ScriptPromiseResolver*, std::uniq
ue_ptr<WebServiceWorkerClientInfo> webClient) | 18 ServiceWorkerClient* ServiceWorkerClient::take(ScriptPromiseResolver*, PassOwnPt
r<WebServiceWorkerClientInfo> webClient) |
| 20 { | 19 { |
| 21 if (!webClient) | 20 if (!webClient) |
| 22 return nullptr; | 21 return nullptr; |
| 23 | 22 |
| 24 switch (webClient->clientType) { | 23 switch (webClient->clientType) { |
| 25 case WebServiceWorkerClientTypeWindow: | 24 case WebServiceWorkerClientTypeWindow: |
| 26 return ServiceWorkerWindowClient::create(*webClient); | 25 return ServiceWorkerWindowClient::create(*webClient); |
| 27 case WebServiceWorkerClientTypeWorker: | 26 case WebServiceWorkerClientTypeWorker: |
| 28 case WebServiceWorkerClientTypeSharedWorker: | 27 case WebServiceWorkerClientTypeSharedWorker: |
| 29 return ServiceWorkerClient::create(*webClient); | 28 return ServiceWorkerClient::create(*webClient); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 return "top-level"; | 63 return "top-level"; |
| 65 } | 64 } |
| 66 | 65 |
| 67 ASSERT_NOT_REACHED(); | 66 ASSERT_NOT_REACHED(); |
| 68 return String(); | 67 return String(); |
| 69 } | 68 } |
| 70 | 69 |
| 71 void ServiceWorkerClient::postMessage(ExecutionContext* context, PassRefPtr<Seri
alizedScriptValue> message, const MessagePortArray& ports, ExceptionState& excep
tionState) | 70 void ServiceWorkerClient::postMessage(ExecutionContext* context, PassRefPtr<Seri
alizedScriptValue> message, const MessagePortArray& ports, ExceptionState& excep
tionState) |
| 72 { | 71 { |
| 73 // Disentangle the port in preparation for sending it to the remote context. | 72 // Disentangle the port in preparation for sending it to the remote context. |
| 74 std::unique_ptr<MessagePortChannelArray> channels = MessagePort::disentangle
Ports(context, ports, exceptionState); | 73 OwnPtr<MessagePortChannelArray> channels = MessagePort::disentanglePorts(con
text, ports, exceptionState); |
| 75 if (exceptionState.hadException()) | 74 if (exceptionState.hadException()) |
| 76 return; | 75 return; |
| 77 | 76 |
| 78 if (message->containsTransferableArrayBuffer()) | 77 if (message->containsTransferableArrayBuffer()) |
| 79 context->addConsoleMessage(ConsoleMessage::create(JSMessageSource, Warni
ngMessageLevel, "ServiceWorkerClient cannot send an ArrayBuffer as a transferabl
e object yet. See http://crbug.com/511119")); | 78 context->addConsoleMessage(ConsoleMessage::create(JSMessageSource, Warni
ngMessageLevel, "ServiceWorkerClient cannot send an ArrayBuffer as a transferabl
e object yet. See http://crbug.com/511119")); |
| 80 | 79 |
| 81 WebString messageString = message->toWireString(); | 80 WebString messageString = message->toWireString(); |
| 82 std::unique_ptr<WebMessagePortChannelArray> webChannels = MessagePort::toWeb
MessagePortChannelArray(std::move(channels)); | 81 OwnPtr<WebMessagePortChannelArray> webChannels = MessagePort::toWebMessagePo
rtChannelArray(std::move(channels)); |
| 83 ServiceWorkerGlobalScopeClient::from(context)->postMessageToClient(m_uuid, m
essageString, std::move(webChannels)); | 82 ServiceWorkerGlobalScopeClient::from(context)->postMessageToClient(m_uuid, m
essageString, std::move(webChannels)); |
| 84 } | 83 } |
| 85 | 84 |
| 86 } // namespace blink | 85 } // namespace blink |
| OLD | NEW |