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/ServiceWorkerClients.h" | 6 #include "modules/serviceworkers/ServiceWorkerClients.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/DOMException.h" | 10 #include "core/dom/DOMException.h" |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 } | 108 } |
109 | 109 |
110 ScriptPromise ServiceWorkerClients::openWindow(ScriptState* scriptState, const S
tring& url) | 110 ScriptPromise ServiceWorkerClients::openWindow(ScriptState* scriptState, const S
tring& url) |
111 { | 111 { |
112 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); | 112 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); |
113 ScriptPromise promise = resolver->promise(); | 113 ScriptPromise promise = resolver->promise(); |
114 ExecutionContext* context = scriptState->executionContext(); | 114 ExecutionContext* context = scriptState->executionContext(); |
115 | 115 |
116 KURL parsedUrl = KURL(toWorkerGlobalScope(context)->location()->url(), url); | 116 KURL parsedUrl = KURL(toWorkerGlobalScope(context)->location()->url(), url); |
117 if (!parsedUrl.isValid()) { | 117 if (!parsedUrl.isValid()) { |
118 resolver->reject(DOMException::create(SyntaxError, "'" + url + "' is not
a valid URL.")); | 118 resolver->reject(V8ThrowException::createTypeError(scriptState->isolate(
), "'" + url + "' is not a valid URL.")); |
119 return promise; | 119 return promise; |
120 } | 120 } |
121 | 121 |
122 if (!context->securityOrigin()->canDisplay(parsedUrl)) { | 122 if (!context->securityOrigin()->canDisplay(parsedUrl)) { |
123 resolver->reject(DOMException::create(SecurityError, "'" + parsedUrl.eli
dedString() + "' cannot be opened.")); | 123 resolver->reject(DOMException::create(SecurityError, "'" + parsedUrl.eli
dedString() + "' cannot be opened.")); |
124 return promise; | 124 return promise; |
125 } | 125 } |
126 | 126 |
127 if (!context->isWindowInteractionAllowed()) { | 127 if (!context->isWindowInteractionAllowed()) { |
128 resolver->reject(DOMException::create(InvalidAccessError, "Not allowed t
o open a window.")); | 128 resolver->reject(DOMException::create(InvalidAccessError, "Not allowed t
o open a window.")); |
129 return promise; | 129 return promise; |
130 } | 130 } |
131 context->consumeWindowInteraction(); | 131 context->consumeWindowInteraction(); |
132 | 132 |
133 ServiceWorkerGlobalScopeClient::from(context)->openWindow(parsedUrl, new Cal
lbackPromiseAdapter<ServiceWorkerWindowClient, ServiceWorkerError>(resolver)); | 133 ServiceWorkerGlobalScopeClient::from(context)->openWindow(parsedUrl, new Cal
lbackPromiseAdapter<ServiceWorkerWindowClient, ServiceWorkerError>(resolver)); |
134 return promise; | 134 return promise; |
135 } | 135 } |
136 | 136 |
137 } // namespace blink | 137 } // namespace blink |
OLD | NEW |