OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.components.payments; |
| 6 |
| 7 import org.chromium.base.annotations.CalledByNative; |
| 8 import org.chromium.base.annotations.JNINamespace; |
| 9 import org.chromium.payments.mojom.PaymentManifestSection; |
| 10 |
| 11 /** Parses payment manifests in a utility process. */ |
| 12 @JNINamespace("payments") |
| 13 public class PaymentManifestParser { |
| 14 /** Interface for the callback to invoke when finished parsing. */ |
| 15 public interface ManifestParseCallback { |
| 16 /** |
| 17 * Called on successful parse of a payment method manifest. |
| 18 * |
| 19 * @param manifest The successfully parsed payment method manifest. |
| 20 */ |
| 21 @CalledByNative("ManifestParseCallback") |
| 22 void onManifestParseSuccess(PaymentManifestSection[] manifest); |
| 23 |
| 24 /** Called on failed parse of a payment method manifest. */ |
| 25 @CalledByNative("ManifestParseCallback") |
| 26 void onManifestParseFailure(); |
| 27 } |
| 28 |
| 29 /** Owned native host of the utility process that parses manifest contents.
*/ |
| 30 private long mNativePaymentManifestParserAndroid; |
| 31 |
| 32 /** Starts the utility process. */ |
| 33 public void startUtilityProcess() { |
| 34 assert mNativePaymentManifestParserAndroid == 0; |
| 35 mNativePaymentManifestParserAndroid = nativeCreatePaymentManifestParserA
ndroid(); |
| 36 nativeStartUtilityProcess(mNativePaymentManifestParserAndroid); |
| 37 } |
| 38 |
| 39 /** Stops the utility process. */ |
| 40 public void stopUtilityProcess() { |
| 41 assert mNativePaymentManifestParserAndroid != 0; |
| 42 nativeStopUtilityProcess(mNativePaymentManifestParserAndroid); |
| 43 mNativePaymentManifestParserAndroid = 0; |
| 44 } |
| 45 |
| 46 /** @return Whether the utility process is running. */ |
| 47 public boolean isUtilityProcessRunning() { |
| 48 return mNativePaymentManifestParserAndroid != 0; |
| 49 } |
| 50 |
| 51 /** |
| 52 * Parses the manifest file asynchronously. |
| 53 * |
| 54 * @param content The content to parse. |
| 55 * @param callback The callback to invoke when finished parsing. |
| 56 */ |
| 57 public void parse(String content, ManifestParseCallback callback) { |
| 58 nativeParsePaymentManifest(mNativePaymentManifestParserAndroid, content,
callback); |
| 59 } |
| 60 |
| 61 @CalledByNative |
| 62 private static PaymentManifestSection[] createManifest(int numberOfsections)
{ |
| 63 return new PaymentManifestSection[numberOfsections]; |
| 64 } |
| 65 |
| 66 @CalledByNative |
| 67 private static void addSectionToManifest(PaymentManifestSection[] manifest,
int sectionIndex, |
| 68 String packageName, long version, int numberOfFingerprints) { |
| 69 manifest[sectionIndex] = new PaymentManifestSection(); |
| 70 manifest[sectionIndex].packageName = packageName; |
| 71 manifest[sectionIndex].version = version; |
| 72 manifest[sectionIndex].sha256CertFingerprints = new byte[numberOfFingerp
rints][]; |
| 73 } |
| 74 |
| 75 @CalledByNative |
| 76 private static void addFingerprintToSection(PaymentManifestSection[] manifes
t, int sectionIndex, |
| 77 int fingerprintIndex, byte[] fingerprint) { |
| 78 manifest[sectionIndex].sha256CertFingerprints[fingerprintIndex] = finger
print; |
| 79 } |
| 80 |
| 81 private static native long nativeCreatePaymentManifestParserAndroid(); |
| 82 private static native void nativeStartUtilityProcess(long nativePaymentManif
estParserAndroid); |
| 83 private static native void nativeParsePaymentManifest(long nativePaymentMani
festParserAndroid, |
| 84 String content, ManifestParseCallback callback); |
| 85 private static native void nativeStopUtilityProcess(long nativePaymentManife
stParserAndroid); |
| 86 } |
OLD | NEW |