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 "bindings/core/v8/CallbackPromiseAdapter.h" | 7 #include "bindings/core/v8/CallbackPromiseAdapter.h" |
8 #include "bindings/core/v8/ScriptPromiseResolver.h" | 8 #include "bindings/core/v8/ScriptPromiseResolver.h" |
9 #include "core/dom/DOMException.h" | 9 #include "core/dom/DOMException.h" |
10 #include "core/dom/ExceptionCode.h" | 10 #include "core/dom/ExceptionCode.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 ScriptPromise promise = resolver->promise(); | 49 ScriptPromise promise = resolver->promise(); |
50 | 50 |
51 if (!scriptState->getExecutionContext()->isWindowInteractionAllowed()) { | 51 if (!scriptState->getExecutionContext()->isWindowInteractionAllowed()) { |
52 resolver->reject(DOMException::create(InvalidAccessError, | 52 resolver->reject(DOMException::create(InvalidAccessError, |
53 "Not allowed to focus a window.")); | 53 "Not allowed to focus a window.")); |
54 return promise; | 54 return promise; |
55 } | 55 } |
56 scriptState->getExecutionContext()->consumeWindowInteraction(); | 56 scriptState->getExecutionContext()->consumeWindowInteraction(); |
57 | 57 |
58 ServiceWorkerGlobalScopeClient::from(scriptState->getExecutionContext()) | 58 ServiceWorkerGlobalScopeClient::from(scriptState->getExecutionContext()) |
59 ->focus(uuid(), new CallbackPromiseAdapter<ServiceWorkerWindowClient, | 59 ->focus(uuid(), |
60 ServiceWorkerError>(resolver)); | 60 WTF::makeUnique<CallbackPromiseAdapter<ServiceWorkerWindowClient, |
| 61 ServiceWorkerError>>( |
| 62 resolver)); |
61 return promise; | 63 return promise; |
62 } | 64 } |
63 | 65 |
64 ScriptPromise ServiceWorkerWindowClient::navigate(ScriptState* scriptState, | 66 ScriptPromise ServiceWorkerWindowClient::navigate(ScriptState* scriptState, |
65 const String& url) { | 67 const String& url) { |
66 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 68 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
67 ScriptPromise promise = resolver->promise(); | 69 ScriptPromise promise = resolver->promise(); |
68 ExecutionContext* context = scriptState->getExecutionContext(); | 70 ExecutionContext* context = scriptState->getExecutionContext(); |
69 | 71 |
70 KURL parsedUrl = KURL(toWorkerGlobalScope(context)->location()->url(), url); | 72 KURL parsedUrl = KURL(toWorkerGlobalScope(context)->location()->url(), url); |
71 if (!parsedUrl.isValid() || parsedUrl.protocolIsAbout()) { | 73 if (!parsedUrl.isValid() || parsedUrl.protocolIsAbout()) { |
72 resolver->reject(V8ThrowException::createTypeError( | 74 resolver->reject(V8ThrowException::createTypeError( |
73 scriptState->isolate(), "'" + url + "' is not a valid URL.")); | 75 scriptState->isolate(), "'" + url + "' is not a valid URL.")); |
74 return promise; | 76 return promise; |
75 } | 77 } |
76 if (!context->getSecurityOrigin()->canDisplay(parsedUrl)) { | 78 if (!context->getSecurityOrigin()->canDisplay(parsedUrl)) { |
77 resolver->reject(V8ThrowException::createTypeError( | 79 resolver->reject(V8ThrowException::createTypeError( |
78 scriptState->isolate(), | 80 scriptState->isolate(), |
79 "'" + parsedUrl.elidedString() + "' cannot navigate.")); | 81 "'" + parsedUrl.elidedString() + "' cannot navigate.")); |
80 return promise; | 82 return promise; |
81 } | 83 } |
82 | 84 |
83 ServiceWorkerGlobalScopeClient::from(context)->navigate( | 85 ServiceWorkerGlobalScopeClient::from(context)->navigate( |
84 uuid(), parsedUrl, new NavigateClientCallback(resolver)); | 86 uuid(), parsedUrl, WTF::makeUnique<NavigateClientCallback>(resolver)); |
85 return promise; | 87 return promise; |
86 } | 88 } |
87 | 89 |
88 DEFINE_TRACE(ServiceWorkerWindowClient) { | 90 DEFINE_TRACE(ServiceWorkerWindowClient) { |
89 ServiceWorkerClient::trace(visitor); | 91 ServiceWorkerClient::trace(visitor); |
90 } | 92 } |
91 | 93 |
92 } // namespace blink | 94 } // namespace blink |
OLD | NEW |