Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: Source/modules/serviceworkers/ServiceWorkerClients.cpp

Issue 850413002: [ServiceWorker] Implement ServiceWorkerClients.openWindow(). (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@sw_client_info_cb
Patch Set: rebase Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 return ScriptPromise(); 84 return ScriptPromise();
83 85
84 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState); 86 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState);
85 ScriptPromise promise = resolver->promise(); 87 ScriptPromise promise = resolver->promise();
86 88
87 WebServiceWorkerClientsClaimCallbacks* callbacks = new CallbackPromiseAdapte r<void, ServiceWorkerError>(resolver); 89 WebServiceWorkerClientsClaimCallbacks* callbacks = new CallbackPromiseAdapte r<void, ServiceWorkerError>(resolver);
88 ServiceWorkerGlobalScopeClient::from(executionContext)->claim(callbacks); 90 ServiceWorkerGlobalScopeClient::from(executionContext)->claim(callbacks);
89 return promise; 91 return promise;
90 } 92 }
91 93
94 ScriptPromise ServiceWorkerClients::openWindow(ScriptState* scriptState, const S tring& url)
95 {
96 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState);
97 ScriptPromise promise = resolver->promise();
98 ExecutionContext* context = scriptState->executionContext();
99
100 KURL parsedUrl = KURL(toWorkerGlobalScope(context)->location()->url(), url);
101 if (!parsedUrl.isValid()) {
102 resolver->reject(DOMException::create(SyntaxError, "'" + url + "' is not a valid URL."));
103 return promise;
104 }
105
106 if (!context->securityOrigin()->canRequest(parsedUrl)) {
107 resolver->reject(DOMException::create(SecurityError, "'" + parsedUrl.eli dedString() + "' is not same-origin with the Worker."));
108 return promise;
109 }
110
111 if (!context->isWindowInteractionAllowed()) {
112 resolver->reject(DOMException::create(InvalidAccessError, "Not allowed t o open a window."));
113 return promise;
114 }
115 context->consumeWindowInteraction();
116
117 ServiceWorkerGlobalScopeClient::from(context)->openWindow(parsedUrl, new Cal lbackPromiseAdapter<ServiceWorkerWindowClient, ServiceWorkerError>(resolver));
118 return promise;
119 }
120
92 } // namespace blink 121 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/serviceworkers/ServiceWorkerClients.h ('k') | Source/modules/serviceworkers/ServiceWorkerGlobalScopeClient.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698