| 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/ServiceWorkerWindowClient.h" | 5 #include "modules/serviceworkers/ServiceWorkerWindowClient.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 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/DOMException.h" | 10 #include "core/dom/DOMException.h" |
| 11 #include "core/dom/ExceptionCode.h" | 11 #include "core/dom/ExceptionCode.h" |
| 12 #include "core/dom/ExecutionContext.h" | |
| 13 #include "core/page/PageVisibilityState.h" | 12 #include "core/page/PageVisibilityState.h" |
| 14 #include "core/workers/WorkerGlobalScope.h" | 13 #include "core/workers/WorkerGlobalScope.h" |
| 15 #include "core/workers/WorkerLocation.h" | 14 #include "core/workers/WorkerLocation.h" |
| 16 #include "modules/serviceworkers/ServiceWorkerError.h" | 15 #include "modules/serviceworkers/ServiceWorkerError.h" |
| 17 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" | 16 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" |
| 18 #include "modules/serviceworkers/ServiceWorkerWindowClientCallback.h" | 17 #include "modules/serviceworkers/ServiceWorkerWindowClientCallback.h" |
| 19 #include "platform/wtf/RefPtr.h" | 18 #include "platform/wtf/RefPtr.h" |
| 20 #include "public/platform/WebString.h" | 19 #include "public/platform/WebString.h" |
| 21 | 20 |
| 22 namespace blink { | 21 namespace blink { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 42 | 41 |
| 43 String ServiceWorkerWindowClient::visibilityState() const { | 42 String ServiceWorkerWindowClient::visibilityState() const { |
| 44 return PageVisibilityStateString( | 43 return PageVisibilityStateString( |
| 45 static_cast<PageVisibilityState>(page_visibility_state_)); | 44 static_cast<PageVisibilityState>(page_visibility_state_)); |
| 46 } | 45 } |
| 47 | 46 |
| 48 ScriptPromise ServiceWorkerWindowClient::focus(ScriptState* script_state) { | 47 ScriptPromise ServiceWorkerWindowClient::focus(ScriptState* script_state) { |
| 49 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); | 48 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); |
| 50 ScriptPromise promise = resolver->Promise(); | 49 ScriptPromise promise = resolver->Promise(); |
| 51 | 50 |
| 52 if (!ExecutionContext::From(script_state)->IsWindowInteractionAllowed()) { | 51 if (!script_state->GetExecutionContext()->IsWindowInteractionAllowed()) { |
| 53 resolver->Reject(DOMException::Create(kInvalidAccessError, | 52 resolver->Reject(DOMException::Create(kInvalidAccessError, |
| 54 "Not allowed to focus a window.")); | 53 "Not allowed to focus a window.")); |
| 55 return promise; | 54 return promise; |
| 56 } | 55 } |
| 57 ExecutionContext::From(script_state)->ConsumeWindowInteraction(); | 56 script_state->GetExecutionContext()->ConsumeWindowInteraction(); |
| 58 | 57 |
| 59 ServiceWorkerGlobalScopeClient::From(ExecutionContext::From(script_state)) | 58 ServiceWorkerGlobalScopeClient::From(script_state->GetExecutionContext()) |
| 60 ->Focus(Uuid(), | 59 ->Focus(Uuid(), |
| 61 WTF::MakeUnique<CallbackPromiseAdapter<ServiceWorkerWindowClient, | 60 WTF::MakeUnique<CallbackPromiseAdapter<ServiceWorkerWindowClient, |
| 62 ServiceWorkerError>>( | 61 ServiceWorkerError>>( |
| 63 resolver)); | 62 resolver)); |
| 64 return promise; | 63 return promise; |
| 65 } | 64 } |
| 66 | 65 |
| 67 ScriptPromise ServiceWorkerWindowClient::navigate(ScriptState* script_state, | 66 ScriptPromise ServiceWorkerWindowClient::navigate(ScriptState* script_state, |
| 68 const String& url) { | 67 const String& url) { |
| 69 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); | 68 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); |
| 70 ScriptPromise promise = resolver->Promise(); | 69 ScriptPromise promise = resolver->Promise(); |
| 71 ExecutionContext* context = ExecutionContext::From(script_state); | 70 ExecutionContext* context = script_state->GetExecutionContext(); |
| 72 | 71 |
| 73 KURL parsed_url = KURL(ToWorkerGlobalScope(context)->location()->Url(), url); | 72 KURL parsed_url = KURL(ToWorkerGlobalScope(context)->location()->Url(), url); |
| 74 if (!parsed_url.IsValid() || parsed_url.ProtocolIsAbout()) { | 73 if (!parsed_url.IsValid() || parsed_url.ProtocolIsAbout()) { |
| 75 resolver->Reject(V8ThrowException::CreateTypeError( | 74 resolver->Reject(V8ThrowException::CreateTypeError( |
| 76 script_state->GetIsolate(), "'" + url + "' is not a valid URL.")); | 75 script_state->GetIsolate(), "'" + url + "' is not a valid URL.")); |
| 77 return promise; | 76 return promise; |
| 78 } | 77 } |
| 79 if (!context->GetSecurityOrigin()->CanDisplay(parsed_url)) { | 78 if (!context->GetSecurityOrigin()->CanDisplay(parsed_url)) { |
| 80 resolver->Reject(V8ThrowException::CreateTypeError( | 79 resolver->Reject(V8ThrowException::CreateTypeError( |
| 81 script_state->GetIsolate(), | 80 script_state->GetIsolate(), |
| 82 "'" + parsed_url.ElidedString() + "' cannot navigate.")); | 81 "'" + parsed_url.ElidedString() + "' cannot navigate.")); |
| 83 return promise; | 82 return promise; |
| 84 } | 83 } |
| 85 | 84 |
| 86 ServiceWorkerGlobalScopeClient::From(context)->Navigate( | 85 ServiceWorkerGlobalScopeClient::From(context)->Navigate( |
| 87 Uuid(), parsed_url, WTF::MakeUnique<NavigateClientCallback>(resolver)); | 86 Uuid(), parsed_url, WTF::MakeUnique<NavigateClientCallback>(resolver)); |
| 88 return promise; | 87 return promise; |
| 89 } | 88 } |
| 90 | 89 |
| 91 DEFINE_TRACE(ServiceWorkerWindowClient) { | 90 DEFINE_TRACE(ServiceWorkerWindowClient) { |
| 92 ServiceWorkerClient::Trace(visitor); | 91 ServiceWorkerClient::Trace(visitor); |
| 93 } | 92 } |
| 94 | 93 |
| 95 } // namespace blink | 94 } // namespace blink |
| OLD | NEW |