Index: chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentManifestParser.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentManifestParser.java b/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentManifestParser.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6f3cd1feaf55e55b801e49300792868c39b586e1 |
--- /dev/null |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentManifestParser.java |
@@ -0,0 +1,81 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+package org.chromium.chrome.browser.payments; |
+ |
+import org.chromium.base.annotations.CalledByNative; |
+import org.chromium.base.annotations.JNINamespace; |
+import org.chromium.payments.mojom.PaymentManifestSection; |
+ |
+/** Parses payment manifests in a utility process. */ |
+@JNINamespace("payments") |
+public class PaymentManifestParser { |
+ /** Interface for the callback to invoke when finished parsing. */ |
+ public interface ManifestParseCallback { |
+ /** |
+ * Called on successful parse of a payment method manifest. |
+ * |
+ * @param manifest The successfully parsed payment method manifest. |
+ */ |
+ @CalledByNative("ManifestParseCallback") |
+ void onManifestParseSuccess(PaymentManifestSection[] manifest); |
+ |
+ /** Called on failed parse of a payment method manifest. */ |
+ @CalledByNative("ManifestParseCallback") |
+ void onManifestParseFailure(); |
+ } |
+ |
+ /** Owned native host of the utility process that parses manifest contents. */ |
+ private long mNativePaymentManifestParserAndroid; |
+ |
+ /** Starts the utility process. */ |
+ public void startUtilityProcess() { |
+ assert mNativePaymentManifestParserAndroid == 0; |
+ mNativePaymentManifestParserAndroid = nativeCreatePaymentManifestParserAndroid(); |
+ nativeStartUtilityProcess(mNativePaymentManifestParserAndroid); |
+ } |
+ |
+ /** Stops the utility process. */ |
+ public void stopUtilityProcess() { |
+ assert mNativePaymentManifestParserAndroid != 0; |
+ nativeStopUtilityProcess(mNativePaymentManifestParserAndroid); |
+ mNativePaymentManifestParserAndroid = 0; |
+ } |
+ |
+ /** |
+ * Parses the manifest file asynchronously. |
+ * |
+ * @param content The content to parse. |
+ * @param callback The callback to invoke when finished parsing. |
+ */ |
+ public void parse(String content, ManifestParseCallback callback) { |
+ nativeParsePaymentManifest(mNativePaymentManifestParserAndroid, content, callback); |
+ } |
+ |
+ @CalledByNative |
+ private static PaymentManifestSection[] createManifest(int size) { |
+ return new PaymentManifestSection[size]; |
+ } |
+ |
+ @CalledByNative |
+ private static void addSectionToManifest(PaymentManifestSection[] manifest, int sectionIndex, |
+ String packageName, long version, int fingerprintsSize) { |
+ manifest[sectionIndex] = new PaymentManifestSection(); |
+ manifest[sectionIndex].packageName = packageName; |
+ manifest[sectionIndex].version = version; |
+ manifest[sectionIndex].sha256CertFingerprints = new String[fingerprintsSize]; |
+ } |
+ |
+ @CalledByNative |
+ private static void addFingerprintToSection(PaymentManifestSection[] manifest, int sectionIndex, |
+ int fingerprintIndex, String fingerprint) { |
+ manifest[sectionIndex].sha256CertFingerprints[fingerprintIndex] = fingerprint; |
+ } |
+ |
+ private static native long nativeCreatePaymentManifestParserAndroid(); |
+ private static native void nativeStartUtilityProcess(long nativePaymentManifestParserAndroid); |
+ private static native void nativeParsePaymentManifest(long nativePaymentManifestParserAndroid, |
+ String content, ManifestParseCallback callback); |
+ private static native void nativeStopUtilityProcess(long nativePaymentManifestParserAndroid); |
+} |