| 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/ScriptPromiseResolver.h" | 10 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 11 #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" | 12 #include "modules/serviceworkers/ServiceWorkerError.h" |
| 14 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" | 13 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" |
| 15 #include "public/platform/WebString.h" | 14 #include "public/platform/WebString.h" |
| 16 #include "wtf/RefPtr.h" | 15 #include "wtf/RefPtr.h" |
| 17 | 16 |
| 18 namespace blink { | 17 namespace blink { |
| 19 | 18 |
| 20 ServiceWorkerClient* ServiceWorkerClient::create(unsigned id) | 19 ServiceWorkerClient* ServiceWorkerClient::create(unsigned id) |
| 21 { | 20 { |
| 22 return new ServiceWorkerClient(id); | 21 return new ServiceWorkerClient(id); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 37 WebString messageString = message->toWireString(); | 36 WebString messageString = message->toWireString(); |
| 38 OwnPtr<WebMessagePortChannelArray> webChannels = MessagePort::toWebMessagePo
rtChannelArray(channels.release()); | 37 OwnPtr<WebMessagePortChannelArray> webChannels = MessagePort::toWebMessagePo
rtChannelArray(channels.release()); |
| 39 ServiceWorkerGlobalScopeClient::from(context)->postMessageToClient(m_id, mes
sageString, webChannels.release()); | 38 ServiceWorkerGlobalScopeClient::from(context)->postMessageToClient(m_id, mes
sageString, webChannels.release()); |
| 40 } | 39 } |
| 41 | 40 |
| 42 ScriptPromise ServiceWorkerClient::focus(ScriptState* scriptState) | 41 ScriptPromise ServiceWorkerClient::focus(ScriptState* scriptState) |
| 43 { | 42 { |
| 44 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); | 43 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); |
| 45 ScriptPromise promise = resolver->promise(); | 44 ScriptPromise promise = resolver->promise(); |
| 46 | 45 |
| 47 if (!scriptState->executionContext()->isWindowFocusAllowed()) { | 46 // FIXME: there should be a check for whether the caller is allowed to focus |
| 48 resolver->resolve(false); | 47 // the client. The promise should succeed with |false| if the call is not |
| 49 return promise; | 48 // allowed. https://crbug.com/437149 |
| 50 } | |
| 51 scriptState->executionContext()->consumeWindowFocus(); | |
| 52 | 49 |
| 53 ServiceWorkerGlobalScopeClient::from(scriptState->executionContext())->focus
(m_id, new CallbackPromiseAdapter<bool, ServiceWorkerError>(resolver)); | 50 ServiceWorkerGlobalScopeClient::from(scriptState->executionContext())->focus
(m_id, new CallbackPromiseAdapter<bool, ServiceWorkerError>(resolver)); |
| 54 return promise; | 51 return promise; |
| 55 } | 52 } |
| 56 | 53 |
| 57 } // namespace blink | 54 } // namespace blink |
| OLD | NEW |