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/ExceptionCode.h" | 10 #include "core/dom/ExceptionCode.h" |
11 #include "core/workers/WorkerGlobalScope.h" | |
12 #include "core/workers/WorkerLocation.h" | |
11 #include "modules/serviceworkers/ServiceWorkerError.h" | 13 #include "modules/serviceworkers/ServiceWorkerError.h" |
12 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" | 14 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" |
13 #include "modules/serviceworkers/ServiceWorkerWindowClient.h" | 15 #include "modules/serviceworkers/ServiceWorkerWindowClient.h" |
14 #include "public/platform/WebServiceWorkerClientsInfo.h" | 16 #include "public/platform/WebServiceWorkerClientsInfo.h" |
15 #include "wtf/RefPtr.h" | 17 #include "wtf/RefPtr.h" |
16 #include "wtf/Vector.h" | 18 #include "wtf/Vector.h" |
17 | 19 |
18 namespace blink { | 20 namespace blink { |
19 | 21 |
20 namespace { | 22 namespace { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 if (options.type() != "window") { | 68 if (options.type() != "window") { |
67 // FIXME: Currently we only support WindowClients. | 69 // FIXME: Currently we only support WindowClients. |
68 resolver->reject(DOMException::create(NotSupportedError, "type parameter of getAll is not supported.")); | 70 resolver->reject(DOMException::create(NotSupportedError, "type parameter of getAll is not supported.")); |
69 return promise; | 71 return promise; |
70 } | 72 } |
71 | 73 |
72 ServiceWorkerGlobalScopeClient::from(scriptState->executionContext())->getCl ients(new CallbackPromiseAdapter<ClientArray, ServiceWorkerError>(resolver)); | 74 ServiceWorkerGlobalScopeClient::from(scriptState->executionContext())->getCl ients(new CallbackPromiseAdapter<ClientArray, ServiceWorkerError>(resolver)); |
73 return promise; | 75 return promise; |
74 } | 76 } |
75 | 77 |
78 ScriptPromise ServiceWorkerClients::openWindow(ScriptState* scriptState, const S tring& url) | |
79 { | |
80 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState); | |
81 ScriptPromise promise = resolver->promise(); | |
82 ExecutionContext* context = scriptState->executionContext(); | |
83 | |
84 KURL parsedUrl = KURL(toWorkerGlobalScope(context)->location()->url(), url); | |
85 if (!parsedUrl.isValid()) { | |
86 resolver->reject(DOMException::create(SyntaxError, "'" + url + "' is not a valid URL.")); | |
87 return promise; | |
88 } | |
89 | |
90 if (!context->securityOrigin()->canRequest(parsedUrl)) { | |
91 resolver->reject(DOMException::create(SecurityError, "'" + parsedUrl.str ing() + "' is cross origin. It cannot be opened.")); | |
Mike West
2015/01/28 13:43:58
Nit: `parsedUrl.elidedString()`
Nit2: How about 'i
mlamouri (slow - plz ping)
2015/02/02 16:09:26
Done. Done.
| |
92 return promise; | |
93 } | |
94 | |
95 if (!context->isWindowInteractionAllowed()) { | |
Mike West
2015/01/28 13:43:58
Where is this defined?
mlamouri (slow - plz ping)
2015/02/02 16:09:26
https://codereview.chromium.org/866983004
| |
96 resolver->reject(DOMException::create(InvalidAccessError, "Not allowed t o open a window.")); | |
97 return promise; | |
98 } | |
99 context->consumeWindowInteraction(); | |
Mike West
2015/01/28 13:43:58
Ditto.
mlamouri (slow - plz ping)
2015/02/02 16:09:26
https://codereview.chromium.org/866983004
| |
100 | |
101 ServiceWorkerGlobalScopeClient::from(context)->openWindow(parsedUrl, new Cal lbackPromiseAdapter<ServiceWorkerWindowClient, ServiceWorkerError>(resolver)); | |
102 return promise; | |
103 } | |
104 | |
76 } // namespace blink | 105 } // namespace blink |
OLD | NEW |