| 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/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/ScriptPromiseResolver.h" | 9 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 10 #include "core/dom/ExceptionCode.h" | 10 #include "core/dom/ExceptionCode.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 ServiceWorkerWindowClient* ServiceWorkerWindowClient::create(const WebServiceWor
kerClientInfo& info) | 30 ServiceWorkerWindowClient* ServiceWorkerWindowClient::create(const WebServiceWor
kerClientInfo& info) |
| 31 { | 31 { |
| 32 return new ServiceWorkerWindowClient(info); | 32 return new ServiceWorkerWindowClient(info); |
| 33 } | 33 } |
| 34 | 34 |
| 35 ServiceWorkerWindowClient::ServiceWorkerWindowClient(const WebServiceWorkerClien
tInfo& info) | 35 ServiceWorkerWindowClient::ServiceWorkerWindowClient(const WebServiceWorkerClien
tInfo& info) |
| 36 : ServiceWorkerClient(info) | 36 : ServiceWorkerClient(info) |
| 37 , m_pageVisibilityState(info.pageVisibilityState) | 37 , m_pageVisibilityState(info.pageVisibilityState) |
| 38 , m_isFocused(info.isFocused) | 38 , m_isFocused(info.isFocused) |
| 39 , m_frameType(info.frameType) | |
| 40 { | 39 { |
| 41 } | 40 } |
| 42 | 41 |
| 43 ServiceWorkerWindowClient::~ServiceWorkerWindowClient() | 42 ServiceWorkerWindowClient::~ServiceWorkerWindowClient() |
| 44 { | 43 { |
| 45 } | 44 } |
| 46 | 45 |
| 47 String ServiceWorkerWindowClient::visibilityState() const | 46 String ServiceWorkerWindowClient::visibilityState() const |
| 48 { | 47 { |
| 49 return pageVisibilityStateString(static_cast<PageVisibilityState>(m_pageVisi
bilityState)); | 48 return pageVisibilityStateString(static_cast<PageVisibilityState>(m_pageVisi
bilityState)); |
| 50 } | 49 } |
| 51 | 50 |
| 52 String ServiceWorkerWindowClient::frameType() const | |
| 53 { | |
| 54 switch (m_frameType) { | |
| 55 case WebURLRequest::FrameTypeAuxiliary: | |
| 56 return "auxiliary"; | |
| 57 case WebURLRequest::FrameTypeNested: | |
| 58 return "nested"; | |
| 59 case WebURLRequest::FrameTypeNone: | |
| 60 return "none"; | |
| 61 case WebURLRequest::FrameTypeTopLevel: | |
| 62 return "top-level"; | |
| 63 } | |
| 64 | |
| 65 ASSERT_NOT_REACHED(); | |
| 66 return String(); | |
| 67 } | |
| 68 | |
| 69 ScriptPromise ServiceWorkerWindowClient::focus(ScriptState* scriptState) | 51 ScriptPromise ServiceWorkerWindowClient::focus(ScriptState* scriptState) |
| 70 { | 52 { |
| 71 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); | 53 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); |
| 72 ScriptPromise promise = resolver->promise(); | 54 ScriptPromise promise = resolver->promise(); |
| 73 | 55 |
| 74 if (!scriptState->executionContext()->isWindowInteractionAllowed()) { | 56 if (!scriptState->executionContext()->isWindowInteractionAllowed()) { |
| 75 resolver->reject(DOMException::create(InvalidAccessError, "Not allowed t
o focus a window.")); | 57 resolver->reject(DOMException::create(InvalidAccessError, "Not allowed t
o focus a window.")); |
| 76 return promise; | 58 return promise; |
| 77 } | 59 } |
| 78 scriptState->executionContext()->consumeWindowInteraction(); | 60 scriptState->executionContext()->consumeWindowInteraction(); |
| 79 | 61 |
| 80 ServiceWorkerGlobalScopeClient::from(scriptState->executionContext())->focus
(uuid(), new CallbackPromiseAdapter<ServiceWorkerWindowClient, ServiceWorkerErro
r>(resolver)); | 62 ServiceWorkerGlobalScopeClient::from(scriptState->executionContext())->focus
(uuid(), new CallbackPromiseAdapter<ServiceWorkerWindowClient, ServiceWorkerErro
r>(resolver)); |
| 81 return promise; | 63 return promise; |
| 82 } | 64 } |
| 83 | 65 |
| 84 DEFINE_TRACE(ServiceWorkerWindowClient) | 66 DEFINE_TRACE(ServiceWorkerWindowClient) |
| 85 { | 67 { |
| 86 ServiceWorkerClient::trace(visitor); | 68 ServiceWorkerClient::trace(visitor); |
| 87 } | 69 } |
| 88 | 70 |
| 89 } // namespace blink | 71 } // namespace blink |
| OLD | NEW |