Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/payments/PaymentRequestEvent.h" | 5 #include "modules/payments/PaymentRequestEvent.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ScriptPromiseResolver.h" | |
| 8 #include "core/dom/DOMException.h" | |
| 9 #include "core/workers/WorkerGlobalScope.h" | |
| 10 #include "core/workers/WorkerLocation.h" | |
| 7 #include "modules/serviceworkers/RespondWithObserver.h" | 11 #include "modules/serviceworkers/RespondWithObserver.h" |
| 12 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" | |
| 13 #include "modules/serviceworkers/ServiceWorkerWindowClientCallback.h" | |
| 14 #include "platform/wtf/PtrUtil.h" | |
| 8 #include "platform/wtf/text/AtomicString.h" | 15 #include "platform/wtf/text/AtomicString.h" |
| 9 | 16 |
| 10 namespace blink { | 17 namespace blink { |
| 11 | 18 |
| 12 PaymentRequestEvent* PaymentRequestEvent::Create( | 19 PaymentRequestEvent* PaymentRequestEvent::Create( |
| 13 const AtomicString& type, | 20 const AtomicString& type, |
| 14 const PaymentAppRequest& app_request, | 21 const PaymentAppRequest& app_request, |
| 15 RespondWithObserver* respond_with_observer, | 22 RespondWithObserver* respond_with_observer, |
| 16 WaitUntilObserver* wait_until_observer) { | 23 WaitUntilObserver* wait_until_observer) { |
| 17 return new PaymentRequestEvent(type, app_request, respond_with_observer, | 24 return new PaymentRequestEvent(type, app_request, respond_with_observer, |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 46 | 53 |
| 47 const HeapVector<PaymentDetailsModifier>& PaymentRequestEvent::modifiers() | 54 const HeapVector<PaymentDetailsModifier>& PaymentRequestEvent::modifiers() |
| 48 const { | 55 const { |
| 49 return modifiers_; | 56 return modifiers_; |
| 50 } | 57 } |
| 51 | 58 |
| 52 const String& PaymentRequestEvent::instrumentKey() const { | 59 const String& PaymentRequestEvent::instrumentKey() const { |
| 53 return instrument_key_; | 60 return instrument_key_; |
| 54 } | 61 } |
| 55 | 62 |
| 63 ScriptPromise PaymentRequestEvent::openWindow(ScriptState* script_state, | |
|
Marijn Kruisselbrink
2017/06/02 18:19:02
The logic in this method doesn't seem to match wha
gogerald1
2017/06/02 19:33:59
Add a TODO for checking payment request state.
Ca
Marijn Kruisselbrink
2017/06/02 20:49:38
CanAccess is not exactly the same as checking for
gogerald1
2017/06/02 21:46:03
CanDisplay
From the comments "For example, web sit
Marijn Kruisselbrink
2017/06/02 22:18:05
Well, it depends... Clients.openWindow doesn't hav
gogerald1
2017/06/05 13:49:46
Done.
gogerald1
2017/06/05 13:49:46
Filed two bugs against the spec and added two todo
Marijn Kruisselbrink
2017/06/05 21:23:03
Yes, if the desired behavior is that during a paym
| |
| 64 const String& url) { | |
| 65 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); | |
| 66 ScriptPromise promise = resolver->Promise(); | |
| 67 ExecutionContext* context = ExecutionContext::From(script_state); | |
| 68 | |
| 69 KURL parsed_url_to_open = | |
|
Marijn Kruisselbrink
2017/06/02 18:19:02
Isn't this just context->CompleteURL(url) ?
gogerald1
2017/06/02 19:34:00
The url could be relative url
gogerald1
2017/06/02 20:09:05
Done.
| |
| 70 KURL(ToWorkerGlobalScope(context)->location()->Url(), url); | |
| 71 if (!parsed_url_to_open.IsValid()) { | |
| 72 resolver->Reject(V8ThrowException::CreateTypeError( | |
| 73 script_state->GetIsolate(), "'" + url + "' is not a valid URL.")); | |
| 74 return promise; | |
| 75 } | |
| 76 | |
| 77 if (!context->GetSecurityOrigin()->CanDisplay(parsed_url_to_open)) { | |
| 78 resolver->Reject(V8ThrowException::CreateTypeError( | |
| 79 script_state->GetIsolate(), | |
| 80 "'" + parsed_url_to_open.ElidedString() + "' cannot be opened.")); | |
| 81 return promise; | |
| 82 } | |
| 83 | |
| 84 if (!context->GetSecurityOrigin()->CanAccess( | |
| 85 SecurityOrigin::Create(parsed_url_to_open).Get())) { | |
| 86 resolver->Reject(DOMException::Create( | |
| 87 kSecurityError, | |
| 88 "'" + parsed_url_to_open.ElidedString() + "' is not allowed.")); | |
| 89 return promise; | |
| 90 } | |
| 91 | |
| 92 if (!context->IsWindowInteractionAllowed()) { | |
| 93 resolver->Reject(DOMException::Create(kInvalidAccessError, | |
| 94 "Not allowed to open a window.")); | |
| 95 return promise; | |
| 96 } | |
| 97 context->ConsumeWindowInteraction(); | |
| 98 | |
| 99 ServiceWorkerGlobalScopeClient::From(context)->OpenWindowForPaymentHandler( | |
| 100 parsed_url_to_open, WTF::MakeUnique<NavigateClientCallback>(resolver)); | |
| 101 return promise; | |
| 102 } | |
| 103 | |
| 56 void PaymentRequestEvent::respondWith(ScriptState* script_state, | 104 void PaymentRequestEvent::respondWith(ScriptState* script_state, |
| 57 ScriptPromise script_promise, | 105 ScriptPromise script_promise, |
| 58 ExceptionState& exception_state) { | 106 ExceptionState& exception_state) { |
| 59 stopImmediatePropagation(); | 107 stopImmediatePropagation(); |
| 60 if (observer_) { | 108 if (observer_) { |
| 61 observer_->RespondWith(script_state, script_promise, exception_state); | 109 observer_->RespondWith(script_state, script_promise, exception_state); |
| 62 } | 110 } |
| 63 } | 111 } |
| 64 | 112 |
| 65 DEFINE_TRACE(PaymentRequestEvent) { | 113 DEFINE_TRACE(PaymentRequestEvent) { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 78 top_level_origin_(app_request.topLevelOrigin()), | 126 top_level_origin_(app_request.topLevelOrigin()), |
| 79 payment_request_origin_(app_request.paymentRequestOrigin()), | 127 payment_request_origin_(app_request.paymentRequestOrigin()), |
| 80 payment_request_id_(app_request.paymentRequestId()), | 128 payment_request_id_(app_request.paymentRequestId()), |
| 81 method_data_(std::move(app_request.methodData())), | 129 method_data_(std::move(app_request.methodData())), |
| 82 total_(app_request.total()), | 130 total_(app_request.total()), |
| 83 modifiers_(app_request.modifiers()), | 131 modifiers_(app_request.modifiers()), |
| 84 instrument_key_(app_request.instrumentKey()), | 132 instrument_key_(app_request.instrumentKey()), |
| 85 observer_(respond_with_observer) {} | 133 observer_(respond_with_observer) {} |
| 86 | 134 |
| 87 } // namespace blink | 135 } // namespace blink |
| OLD | NEW |