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/PaymentAppServiceWorkerRegistration.h" | 5 #include "modules/payments/PaymentAppServiceWorkerRegistration.h" |
6 | 6 |
7 #include "bindings/core/v8/ExceptionState.h" | |
7 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
9 #include "core/dom/ExecutionContext.h" | |
8 #include "modules/payments/PaymentManager.h" | 10 #include "modules/payments/PaymentManager.h" |
9 #include "modules/serviceworkers/ServiceWorkerRegistration.h" | 11 #include "modules/serviceworkers/ServiceWorkerRegistration.h" |
10 #include "platform/bindings/ScriptState.h" | 12 #include "platform/bindings/ScriptState.h" |
13 #include "platform/weborigin/KURL.h" | |
14 #include "platform/weborigin/SecurityOrigin.h" | |
11 | 15 |
12 namespace blink { | 16 namespace blink { |
13 | 17 |
14 PaymentAppServiceWorkerRegistration::~PaymentAppServiceWorkerRegistration() {} | 18 PaymentAppServiceWorkerRegistration::~PaymentAppServiceWorkerRegistration() {} |
15 | 19 |
16 // static | 20 // static |
17 PaymentAppServiceWorkerRegistration& PaymentAppServiceWorkerRegistration::From( | 21 PaymentAppServiceWorkerRegistration& PaymentAppServiceWorkerRegistration::From( |
18 ServiceWorkerRegistration& registration) { | 22 ServiceWorkerRegistration& registration) { |
19 PaymentAppServiceWorkerRegistration* supplement = | 23 PaymentAppServiceWorkerRegistration* supplement = |
20 static_cast<PaymentAppServiceWorkerRegistration*>( | 24 static_cast<PaymentAppServiceWorkerRegistration*>( |
21 Supplement<ServiceWorkerRegistration>::From(registration, | 25 Supplement<ServiceWorkerRegistration>::From(registration, |
22 SupplementName())); | 26 SupplementName())); |
23 | 27 |
24 if (!supplement) { | 28 if (!supplement) { |
25 supplement = new PaymentAppServiceWorkerRegistration(®istration); | 29 supplement = new PaymentAppServiceWorkerRegistration(®istration); |
26 ProvideTo(registration, SupplementName(), supplement); | 30 ProvideTo(registration, SupplementName(), supplement); |
27 } | 31 } |
28 | 32 |
29 return *supplement; | 33 return *supplement; |
30 } | 34 } |
31 | 35 |
32 // static | 36 // static |
33 PaymentManager* PaymentAppServiceWorkerRegistration::paymentManager( | 37 PaymentManager* PaymentAppServiceWorkerRegistration::paymentManager( |
34 ScriptState* script_state, | 38 ScriptState* script_state, |
35 ServiceWorkerRegistration& registration) { | 39 ServiceWorkerRegistration& registration, |
40 ExceptionState& exception_state) { | |
36 return PaymentAppServiceWorkerRegistration::From(registration) | 41 return PaymentAppServiceWorkerRegistration::From(registration) |
37 .paymentManager(script_state); | 42 .paymentManager(script_state, exception_state); |
38 } | 43 } |
39 | 44 |
40 PaymentManager* PaymentAppServiceWorkerRegistration::paymentManager( | 45 PaymentManager* PaymentAppServiceWorkerRegistration::paymentManager( |
41 ScriptState* script_state) { | 46 ScriptState* script_state, |
47 ExceptionState& exception_state) { | |
48 ExecutionContext* context = ExecutionContext::From(script_state); | |
49 KURL origin = KURL(KURL(), context->GetSecurityOrigin()->ToString()); | |
50 if (!origin.ProtocolIsInHTTPFamily()) { | |
please use gerrit instead
2017/05/15 14:46:47
Also check context->IsSecureContext().
zino
2017/05/15 18:38:12
I don't think this check is needed.
because the Se
| |
51 exception_state.ThrowSecurityError( | |
52 "The PaymentManger attirbute is only allowed in https://* context."); | |
please use gerrit instead
2017/05/15 14:46:47
PaymentManger can be used only in HTTPS scheme.
zino
2017/05/15 18:38:12
Done.
| |
53 return nullptr; | |
54 } | |
55 | |
42 if (!payment_manager_) { | 56 if (!payment_manager_) { |
43 payment_manager_ = PaymentManager::Create(registration_); | 57 payment_manager_ = PaymentManager::Create(registration_); |
44 } | 58 } |
45 return payment_manager_.Get(); | 59 return payment_manager_.Get(); |
46 } | 60 } |
47 | 61 |
48 DEFINE_TRACE(PaymentAppServiceWorkerRegistration) { | 62 DEFINE_TRACE(PaymentAppServiceWorkerRegistration) { |
49 visitor->Trace(registration_); | 63 visitor->Trace(registration_); |
50 visitor->Trace(payment_manager_); | 64 visitor->Trace(payment_manager_); |
51 Supplement<ServiceWorkerRegistration>::Trace(visitor); | 65 Supplement<ServiceWorkerRegistration>::Trace(visitor); |
52 } | 66 } |
53 | 67 |
54 PaymentAppServiceWorkerRegistration::PaymentAppServiceWorkerRegistration( | 68 PaymentAppServiceWorkerRegistration::PaymentAppServiceWorkerRegistration( |
55 ServiceWorkerRegistration* registration) | 69 ServiceWorkerRegistration* registration) |
56 : registration_(registration) {} | 70 : registration_(registration) {} |
57 | 71 |
58 // static | 72 // static |
59 const char* PaymentAppServiceWorkerRegistration::SupplementName() { | 73 const char* PaymentAppServiceWorkerRegistration::SupplementName() { |
60 return "PaymentAppServiceWorkerRegistration"; | 74 return "PaymentAppServiceWorkerRegistration"; |
61 } | 75 } |
62 | 76 |
63 } // namespace blink | 77 } // namespace blink |
OLD | NEW |