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

Unified Diff: third_party/WebKit/Source/modules/payments/PaymentAppManager.cpp

Issue 2506093002: PaymentApp: Implement PaymentAppManager.getManifest(). (Closed)
Patch Set: PaymentApp: Implement PaymentAppManager.getManifest(). Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/modules/payments/PaymentAppManager.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/modules/payments/PaymentAppManager.cpp
diff --git a/third_party/WebKit/Source/modules/payments/PaymentAppManager.cpp b/third_party/WebKit/Source/modules/payments/PaymentAppManager.cpp
index d75482de914574dc476b13b81807800c0f38bfd8..55cb50b243b700954c1968125248c838c1095a7c 100644
--- a/third_party/WebKit/Source/modules/payments/PaymentAppManager.cpp
+++ b/third_party/WebKit/Source/modules/payments/PaymentAppManager.cpp
@@ -48,6 +48,37 @@ struct TypeConverter<PaymentAppManifestPtr, blink::PaymentAppManifest> {
}
};
+template <>
+struct TypeConverter<blink::PaymentAppManifest, PaymentAppManifestPtr> {
+ static blink::PaymentAppManifest Convert(const PaymentAppManifestPtr& input) {
+ blink::PaymentAppManifest output;
+ output.setLabel(input->label);
+ output.setIcon(input->icon);
+ blink::HeapVector<blink::PaymentAppOption> options;
+ for (const auto& option : input->options) {
+ options.append(mojo::ConvertTo<blink::PaymentAppOption>(option));
+ }
+ output.setOptions(options);
+ return output;
+ }
+};
+
+template <>
+struct TypeConverter<blink::PaymentAppOption, PaymentAppOptionPtr> {
+ static blink::PaymentAppOption Convert(const PaymentAppOptionPtr& input) {
+ blink::PaymentAppOption output;
+ output.setLabel(input->label);
+ output.setIcon(input->icon);
+ output.setId(input->id);
+ Vector<WTF::String> enabledMethods;
+ for (const auto& method : input->enabled_methods) {
+ enabledMethods.append(method);
+ }
+ output.setEnabledMethods(enabledMethods);
+ return output;
+ }
+};
+
} // namespace mojo
namespace blink {
@@ -58,9 +89,8 @@ PaymentAppManager* PaymentAppManager::create(
return new PaymentAppManager(scriptState, registration);
}
-ScriptPromise PaymentAppManager::getManifest(ScriptState* scriptState) {
- NOTIMPLEMENTED();
- return ScriptPromise();
+void PaymentAppManager::contextDestroyed() {
+ m_manager.reset();
}
ScriptPromise PaymentAppManager::setManifest(
@@ -85,6 +115,41 @@ ScriptPromise PaymentAppManager::setManifest(
return promise;
}
+ScriptPromise PaymentAppManager::getManifest(ScriptState* scriptState) {
+ if (!m_manager) {
+ return ScriptPromise::rejectWithDOMException(
+ scriptState, DOMException::create(InvalidStateError,
+ "Payment app manager unavailable."));
+ }
+
+ ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
+ ScriptPromise promise = resolver->promise();
+
+ m_manager->GetManifest(m_registration->scope(),
+ convertToBaseCallback(WTF::bind(
+ &PaymentAppManager::onGetManifest,
+ wrapPersistent(this), wrapPersistent(resolver))));
+
+ return promise;
+}
+
+DEFINE_TRACE(PaymentAppManager) {
+ visitor->trace(m_registration);
+ ContextLifecycleObserver::trace(visitor);
+}
+
+PaymentAppManager::PaymentAppManager(ScriptState* scriptState,
+ ServiceWorkerRegistration* registration)
+ : ContextLifecycleObserver(scriptState->getExecutionContext()),
+ m_registration(registration) {
+ DCHECK(registration);
+ Platform::current()->interfaceProvider()->getInterface(
+ mojo::GetProxy(&m_manager));
+
+ m_manager.set_connection_error_handler(convertToBaseCallback(WTF::bind(
+ &PaymentAppManager::onServiceConnectionError, wrapWeakPersistent(this))));
+}
+
void PaymentAppManager::onSetManifest(
ScriptPromiseResolver* resolver,
payments::mojom::blink::PaymentAppManifestError error) {
@@ -101,28 +166,36 @@ void PaymentAppManager::onSetManifest(
resolver->reject(
DOMException::create(InvalidStateError, "No active service worker."));
break;
- case payments::mojom::blink::PaymentAppManifestError::STORE_MANIFEST_FAILED:
+ case payments::mojom::blink::PaymentAppManifestError::
+ MANIFEST_STORAGE_OPERATION_FAILED:
resolver->reject(DOMException::create(
InvalidStateError, "Storing manifest data is failed."));
break;
}
}
-DEFINE_TRACE(PaymentAppManager) {
- visitor->trace(m_registration);
- ContextLifecycleObserver::trace(visitor);
-}
-
-PaymentAppManager::PaymentAppManager(ScriptState* scriptState,
- ServiceWorkerRegistration* registration)
- : ContextLifecycleObserver(scriptState->getExecutionContext()),
- m_registration(registration) {
- DCHECK(registration);
- Platform::current()->interfaceProvider()->getInterface(
- mojo::GetProxy(&m_manager));
-
- m_manager.set_connection_error_handler(convertToBaseCallback(WTF::bind(
- &PaymentAppManager::onServiceConnectionError, wrapWeakPersistent(this))));
+void PaymentAppManager::onGetManifest(
+ ScriptPromiseResolver* resolver,
+ payments::mojom::blink::PaymentAppManifestPtr manifest,
+ payments::mojom::blink::PaymentAppManifestError error) {
+ DCHECK(resolver);
+ switch (error) {
+ case payments::mojom::blink::PaymentAppManifestError::NONE:
+ resolver->resolve(
+ mojo::ConvertTo<PaymentAppManifest>(std::move(manifest)));
+ break;
+ case payments::mojom::blink::PaymentAppManifestError::NOT_IMPLEMENTED:
+ resolver->reject(
+ DOMException::create(NotSupportedError, "Not implemented yet."));
+ break;
+ case payments::mojom::blink::PaymentAppManifestError::NO_ACTIVE_WORKER:
+ case payments::mojom::blink::PaymentAppManifestError::
+ MANIFEST_STORAGE_OPERATION_FAILED:
+ resolver->reject(DOMException::create(
+ AbortError,
+ "No payment app manifest associated with the service worker."));
+ break;
+ }
}
void PaymentAppManager::onServiceConnectionError() {
@@ -133,8 +206,4 @@ void PaymentAppManager::onServiceConnectionError() {
m_manager.reset();
}
-void PaymentAppManager::contextDestroyed() {
- m_manager.reset();
-}
-
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/modules/payments/PaymentAppManager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698