Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/PaymentInstruments.h" | 5 #include "modules/payments/PaymentInstruments.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "bindings/core/v8/ExceptionState.h" | 9 #include "bindings/core/v8/ExceptionState.h" |
| 10 #include "bindings/core/v8/ScriptPromise.h" | 10 #include "bindings/core/v8/ScriptPromise.h" |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 34 "There is no stored instrument")); | 34 "There is no stored instrument")); |
| 35 return true; | 35 return true; |
| 36 case payments::mojom::blink::PaymentHandlerStatus::NO_ACTIVE_WORKER: | 36 case payments::mojom::blink::PaymentHandlerStatus::NO_ACTIVE_WORKER: |
| 37 resolver->Reject( | 37 resolver->Reject( |
| 38 DOMException::Create(kInvalidStateError, "No active service worker")); | 38 DOMException::Create(kInvalidStateError, "No active service worker")); |
| 39 return true; | 39 return true; |
| 40 case payments::mojom::blink::PaymentHandlerStatus::STORAGE_OPERATION_FAILED: | 40 case payments::mojom::blink::PaymentHandlerStatus::STORAGE_OPERATION_FAILED: |
| 41 resolver->Reject(DOMException::Create(kInvalidStateError, | 41 resolver->Reject(DOMException::Create(kInvalidStateError, |
| 42 "Storage operation is failed")); | 42 "Storage operation is failed")); |
| 43 return true; | 43 return true; |
| 44 case payments::mojom::blink::PaymentHandlerStatus:: | |
| 45 FETCH_INSTRUMENT_ICON_FAILED: | |
| 46 resolver->Reject(DOMException::Create( | |
| 47 kNotFoundError, "Fetch or decode instrument icon failed")); | |
| 48 return true; | |
| 44 } | 49 } |
| 45 NOTREACHED(); | 50 NOTREACHED(); |
| 46 return false; | 51 return false; |
| 47 } | 52 } |
| 48 | 53 |
| 49 } // namespace | 54 } // namespace |
| 50 | 55 |
| 51 PaymentInstruments::PaymentInstruments( | 56 PaymentInstruments::PaymentInstruments( |
| 52 const payments::mojom::blink::PaymentManagerPtr& manager) | 57 const payments::mojom::blink::PaymentManagerPtr& manager) |
| 53 : manager_(manager) {} | 58 : manager_(manager) {} |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 script_state, | 137 script_state, |
| 133 DOMException::Create(kInvalidStateError, kPaymentManagerUnavailable)); | 138 DOMException::Create(kInvalidStateError, kPaymentManagerUnavailable)); |
| 134 } | 139 } |
| 135 | 140 |
| 136 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); | 141 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); |
| 137 ScriptPromise promise = resolver->Promise(); | 142 ScriptPromise promise = resolver->Promise(); |
| 138 | 143 |
| 139 payments::mojom::blink::PaymentInstrumentPtr instrument = | 144 payments::mojom::blink::PaymentInstrumentPtr instrument = |
| 140 payments::mojom::blink::PaymentInstrument::New(); | 145 payments::mojom::blink::PaymentInstrument::New(); |
| 141 instrument->name = details.hasName() ? details.name() : WTF::g_empty_string; | 146 instrument->name = details.hasName() ? details.name() : WTF::g_empty_string; |
| 147 if (details.hasIcons()) { | |
| 148 for (const ImageObject image_object : details.icons()) { | |
| 149 instrument->icons.push_back(payments::mojom::blink::ImageObject::New()); | |
| 150 if (image_object.hasSrc()) | |
|
zino
2017/06/09 20:29:48
Do we need this check?
Because it is a required fi
zino
2017/06/09 20:29:48
The url can be relative, so, we should parse the u
gogerald1
2017/06/09 22:25:03
Done.
gogerald1
2017/06/09 22:25:03
Done.
| |
| 151 instrument->icons.back()->src = image_object.src(); | |
| 152 } | |
| 153 } | |
| 154 | |
| 142 if (details.hasEnabledMethods()) { | 155 if (details.hasEnabledMethods()) { |
| 143 instrument->enabled_methods = details.enabledMethods(); | 156 instrument->enabled_methods = details.enabledMethods(); |
| 144 } | 157 } |
| 145 | 158 |
| 146 if (details.hasCapabilities()) { | 159 if (details.hasCapabilities()) { |
| 147 v8::Local<v8::String> value; | 160 v8::Local<v8::String> value; |
| 148 if (!v8::JSON::Stringify(script_state->GetContext(), | 161 if (!v8::JSON::Stringify(script_state->GetContext(), |
| 149 details.capabilities().V8Value().As<v8::Object>()) | 162 details.capabilities().V8Value().As<v8::Object>()) |
| 150 .ToLocal(&value)) { | 163 .ToLocal(&value)) { |
| 151 exception_state.ThrowTypeError( | 164 exception_state.ThrowTypeError( |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 193 | 206 |
| 194 void PaymentInstruments::onGetPaymentInstrument( | 207 void PaymentInstruments::onGetPaymentInstrument( |
| 195 ScriptPromiseResolver* resolver, | 208 ScriptPromiseResolver* resolver, |
| 196 payments::mojom::blink::PaymentInstrumentPtr stored_instrument, | 209 payments::mojom::blink::PaymentInstrumentPtr stored_instrument, |
| 197 payments::mojom::blink::PaymentHandlerStatus status) { | 210 payments::mojom::blink::PaymentHandlerStatus status) { |
| 198 DCHECK(resolver); | 211 DCHECK(resolver); |
| 199 if (rejectError(resolver, status)) | 212 if (rejectError(resolver, status)) |
| 200 return; | 213 return; |
| 201 PaymentInstrument instrument; | 214 PaymentInstrument instrument; |
| 202 instrument.setName(stored_instrument->name); | 215 instrument.setName(stored_instrument->name); |
| 216 | |
| 217 HeapVector<ImageObject> icons; | |
| 218 for (const auto& icon : stored_instrument->icons) { | |
| 219 ImageObject image_object; | |
| 220 image_object.setSrc(icon->src); | |
| 221 icons.emplace_back(image_object); | |
| 222 } | |
| 223 instrument.setIcons(icons); | |
| 224 | |
| 203 Vector<String> enabled_methods; | 225 Vector<String> enabled_methods; |
| 204 for (const auto& method : stored_instrument->enabled_methods) { | 226 for (const auto& method : stored_instrument->enabled_methods) { |
| 205 enabled_methods.push_back(method); | 227 enabled_methods.push_back(method); |
| 206 } | 228 } |
| 207 | 229 |
| 208 instrument.setEnabledMethods(enabled_methods); | 230 instrument.setEnabledMethods(enabled_methods); |
| 209 if (!stored_instrument->stringified_capabilities.IsEmpty()) { | 231 if (!stored_instrument->stringified_capabilities.IsEmpty()) { |
| 210 ScriptState::Scope scope(resolver->GetScriptState()); | 232 ScriptState::Scope scope(resolver->GetScriptState()); |
| 211 ExceptionState exception_state(resolver->GetScriptState()->GetIsolate(), | 233 ExceptionState exception_state(resolver->GetScriptState()->GetIsolate(), |
| 212 ExceptionState::kGetterContext, | 234 ExceptionState::kGetterContext, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 254 void PaymentInstruments::onClearPaymentInstruments( | 276 void PaymentInstruments::onClearPaymentInstruments( |
| 255 ScriptPromiseResolver* resolver, | 277 ScriptPromiseResolver* resolver, |
| 256 payments::mojom::blink::PaymentHandlerStatus status) { | 278 payments::mojom::blink::PaymentHandlerStatus status) { |
| 257 DCHECK(resolver); | 279 DCHECK(resolver); |
| 258 if (rejectError(resolver, status)) | 280 if (rejectError(resolver, status)) |
| 259 return; | 281 return; |
| 260 resolver->Resolve(); | 282 resolver->Resolve(); |
| 261 } | 283 } |
| 262 | 284 |
| 263 } // namespace blink | 285 } // namespace blink |
| OLD | NEW |