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

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

Issue 2893823004: [Payments] Implement openWindow for service worker based payment handler (Closed)
Patch Set: address comments Created 3 years, 7 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 "modules/serviceworkers/ServiceWorkerClients.h" 5 #include "modules/serviceworkers/ServiceWorkerClients.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 #include "bindings/core/v8/CallbackPromiseAdapter.h" 9 #include "bindings/core/v8/CallbackPromiseAdapter.h"
10 #include "bindings/core/v8/ScriptPromiseResolver.h" 10 #include "bindings/core/v8/ScriptPromiseResolver.h"
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 auto callbacks = 153 auto callbacks =
154 WTF::MakeUnique<CallbackPromiseAdapter<void, ServiceWorkerError>>( 154 WTF::MakeUnique<CallbackPromiseAdapter<void, ServiceWorkerError>>(
155 resolver); 155 resolver);
156 ServiceWorkerGlobalScopeClient::From(execution_context) 156 ServiceWorkerGlobalScopeClient::From(execution_context)
157 ->Claim(std::move(callbacks)); 157 ->Claim(std::move(callbacks));
158 return promise; 158 return promise;
159 } 159 }
160 160
161 ScriptPromise ServiceWorkerClients::openWindow(ScriptState* script_state, 161 ScriptPromise ServiceWorkerClients::openWindow(ScriptState* script_state,
162 const String& url) { 162 const String& url) {
163 return openWindow(script_state, String(), url);
164 }
165
166 ScriptPromise ServiceWorkerClients::openWindow(ScriptState* script_state,
167 const String& redirect_url,
168 const String& url) {
163 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); 169 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state);
164 ScriptPromise promise = resolver->Promise(); 170 ScriptPromise promise = resolver->Promise();
165 ExecutionContext* context = ExecutionContext::From(script_state); 171 ExecutionContext* context = ExecutionContext::From(script_state);
166 172
167 KURL parsed_url = KURL(ToWorkerGlobalScope(context)->location()->Url(), url); 173 KURL parsed_url = KURL(ToWorkerGlobalScope(context)->location()->Url(), url);
168 if (!parsed_url.IsValid()) { 174 if (!parsed_url.IsValid()) {
169 resolver->Reject(V8ThrowException::CreateTypeError( 175 resolver->Reject(V8ThrowException::CreateTypeError(
170 script_state->GetIsolate(), "'" + url + "' is not a valid URL.")); 176 script_state->GetIsolate(), "'" + url + "' is not a valid URL."));
171 return promise; 177 return promise;
172 } 178 }
173 179
174 if (!context->GetSecurityOrigin()->CanDisplay(parsed_url)) { 180 if (!context->GetSecurityOrigin()->CanDisplay(parsed_url)) {
175 resolver->Reject(V8ThrowException::CreateTypeError( 181 resolver->Reject(V8ThrowException::CreateTypeError(
176 script_state->GetIsolate(), 182 script_state->GetIsolate(),
177 "'" + parsed_url.ElidedString() + "' cannot be opened.")); 183 "'" + parsed_url.ElidedString() + "' cannot be opened."));
178 return promise; 184 return promise;
179 } 185 }
180 186
181 if (!context->IsWindowInteractionAllowed()) { 187 if (!context->IsWindowInteractionAllowed()) {
182 resolver->Reject(DOMException::Create(kInvalidAccessError, 188 resolver->Reject(DOMException::Create(kInvalidAccessError,
183 "Not allowed to open a window.")); 189 "Not allowed to open a window."));
184 return promise; 190 return promise;
185 } 191 }
186 context->ConsumeWindowInteraction(); 192 context->ConsumeWindowInteraction();
187 193
188 ServiceWorkerGlobalScopeClient::From(context)->OpenWindow( 194 ServiceWorkerGlobalScopeClient::From(context)->OpenWindow(
189 parsed_url, WTF::MakeUnique<NavigateClientCallback>(resolver)); 195 KURL(kParsedURLString, redirect_url), parsed_url,
196 WTF::MakeUnique<NavigateClientCallback>(resolver));
190 return promise; 197 return promise;
191 } 198 }
192 199
193 } // namespace blink 200 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698