| 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/ExceptionState.h" | 9 #include "bindings/core/v8/ExceptionState.h" |
| 10 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 9 #include "bindings/core/v8/SerializedScriptValue.h" | 11 #include "bindings/core/v8/SerializedScriptValue.h" |
| 12 #include "core/page/WindowFocusAllowedIndicator.h" |
| 13 #include "modules/serviceworkers/ServiceWorkerError.h" |
| 10 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" | 14 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" |
| 11 #include "public/platform/WebString.h" | 15 #include "public/platform/WebString.h" |
| 12 #include "wtf/RefPtr.h" | 16 #include "wtf/RefPtr.h" |
| 13 | 17 |
| 14 namespace blink { | 18 namespace blink { |
| 15 | 19 |
| 16 ServiceWorkerClient* ServiceWorkerClient::create(unsigned id) | 20 ServiceWorkerClient* ServiceWorkerClient::create(unsigned id) |
| 17 { | 21 { |
| 18 return new ServiceWorkerClient(id); | 22 return new ServiceWorkerClient(id); |
| 19 } | 23 } |
| 20 | 24 |
| 21 ServiceWorkerClient::ServiceWorkerClient(unsigned id) | 25 ServiceWorkerClient::ServiceWorkerClient(unsigned id) |
| 22 : m_id(id) | 26 : m_id(id) |
| 23 { | 27 { |
| 24 } | 28 } |
| 25 | 29 |
| 26 void ServiceWorkerClient::postMessage(ExecutionContext* context, PassRefPtr<Seri
alizedScriptValue> message, const MessagePortArray* ports, ExceptionState& excep
tionState) | 30 void ServiceWorkerClient::postMessage(ExecutionContext* context, PassRefPtr<Seri
alizedScriptValue> message, const MessagePortArray* ports, ExceptionState& excep
tionState) |
| 27 { | 31 { |
| 28 // Disentangle the port in preparation for sending it to the remote context. | 32 // Disentangle the port in preparation for sending it to the remote context. |
| 29 OwnPtr<MessagePortChannelArray> channels = MessagePort::disentanglePorts(por
ts, exceptionState); | 33 OwnPtr<MessagePortChannelArray> channels = MessagePort::disentanglePorts(por
ts, exceptionState); |
| 30 if (exceptionState.hadException()) | 34 if (exceptionState.hadException()) |
| 31 return; | 35 return; |
| 32 | 36 |
| 33 WebString messageString = message->toWireString(); | 37 WebString messageString = message->toWireString(); |
| 34 OwnPtr<WebMessagePortChannelArray> webChannels = MessagePort::toWebMessagePo
rtChannelArray(channels.release()); | 38 OwnPtr<WebMessagePortChannelArray> webChannels = MessagePort::toWebMessagePo
rtChannelArray(channels.release()); |
| 35 ServiceWorkerGlobalScopeClient::from(context)->postMessageToClient(m_id, mes
sageString, webChannels.release()); | 39 ServiceWorkerGlobalScopeClient::from(context)->postMessageToClient(m_id, mes
sageString, webChannels.release()); |
| 36 } | 40 } |
| 37 | 41 |
| 42 ScriptPromise ServiceWorkerClient::focus(ScriptState* scriptState) |
| 43 { |
| 44 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); |
| 45 ScriptPromise promise = resolver->promise(); |
| 46 |
| 47 if (!scriptState->executionContext()->isWindowFocusAllowed()) { |
| 48 resolver->resolve(false); |
| 49 return promise; |
| 50 } |
| 51 scriptState->executionContext()->consumeWindowFocusToken(); |
| 52 |
| 53 ServiceWorkerGlobalScopeClient::from(scriptState->executionContext())->focus
(m_id, new CallbackPromiseAdapter<bool, ServiceWorkerError>(resolver)); |
| 54 return promise; |
| 55 } |
| 56 |
| 38 } // namespace blink | 57 } // namespace blink |
| OLD | NEW |