gogerald | 6d16ea5 | 2017-04-13 20:43:28 | [diff] [blame] | 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 | |
Rouslan Solomakhin | de01253 | 2017-09-20 15:18:34 | [diff] [blame] | 5 | #ifndef COMPONENTS_PAYMENTS_CONTENT_PAYMENT_METHOD_MANIFEST_TABLE_H_ |
| 6 | #define COMPONENTS_PAYMENTS_CONTENT_PAYMENT_METHOD_MANIFEST_TABLE_H_ |
gogerald | 6d16ea5 | 2017-04-13 20:43:28 | [diff] [blame] | 7 | |
Rouslan Solomakhin | ebf9f16 | 2020-08-27 15:28:13 | [diff] [blame] | 8 | #include <memory> |
gogerald | 6d16ea5 | 2017-04-13 20:43:28 | [diff] [blame] | 9 | #include <string> |
| 10 | #include <vector> |
| 11 | |
Rouslan Solomakhin | ebf9f16 | 2020-08-27 15:28:13 | [diff] [blame] | 12 | #include "base/strings/string16.h" |
gogerald | 6d16ea5 | 2017-04-13 20:43:28 | [diff] [blame] | 13 | #include "components/webdata/common/web_database_table.h" |
| 14 | |
Rouslan Solomakhin | de01253 | 2017-09-20 15:18:34 | [diff] [blame] | 15 | class WebDatabase; |
| 16 | |
gogerald | 6d16ea5 | 2017-04-13 20:43:28 | [diff] [blame] | 17 | namespace payments { |
| 18 | |
Rouslan Solomakhin | ebf9f16 | 2020-08-27 15:28:13 | [diff] [blame] | 19 | struct SecurePaymentConfirmationInstrument; |
| 20 | |
| 21 | // This class manages Web Payment tables in SQLite database. It expects the |
| 22 | // following schema. |
gogerald | 6d16ea5 | 2017-04-13 20:43:28 | [diff] [blame] | 23 | // |
Rouslan Solomakhin | ebf9f16 | 2020-08-27 15:28:13 | [diff] [blame] | 24 | // payment_method_manifest This table stores WebAppManifestSection.id of the |
gogerald | 6d16ea5 | 2017-04-13 20:43:28 | [diff] [blame] | 25 | // supported web app in this payment method manifest. |
| 26 | // Note that a payment method manifest might contain |
| 27 | // multiple supported web apps ids. |
gogerald | 69a1f75 | 2017-04-27 21:18:07 | [diff] [blame] | 28 | // |
Rouslan Solomakhin | ebf9f16 | 2020-08-27 15:28:13 | [diff] [blame] | 29 | // expire_date The expire date in seconds from 1601-01-01 00:00:00 |
gogerald | 69a1f75 | 2017-04-27 21:18:07 | [diff] [blame] | 30 | // UTC. |
Rouslan Solomakhin | ebf9f16 | 2020-08-27 15:28:13 | [diff] [blame] | 31 | // method_name The method name. |
| 32 | // web_app_id The supported web app id. |
gogerald | 6d16ea5 | 2017-04-13 20:43:28 | [diff] [blame] | 33 | // (WebAppManifestSection.id). |
| 34 | // |
Rouslan Solomakhin | ebf9f16 | 2020-08-27 15:28:13 | [diff] [blame] | 35 | // secure_payment_confirmation_instrument |
| 36 | // This table stores instrument information for secure |
| 37 | // payment confirmation method. |
| 38 | // |
| 39 | // credential_id The WebAuthn credential identifier blob. Primary key. |
| 40 | // relying_party_id The relying party identifier string. |
| 41 | // label The instrument human-readable label string. |
| 42 | // icon The serialized SkBitmap blob. |
gogerald | 6d16ea5 | 2017-04-13 20:43:28 | [diff] [blame] | 43 | class PaymentMethodManifestTable : public WebDatabaseTable { |
| 44 | public: |
| 45 | PaymentMethodManifestTable(); |
| 46 | ~PaymentMethodManifestTable() override; |
| 47 | |
Rouslan Solomakhin | ebf9f16 | 2020-08-27 15:28:13 | [diff] [blame] | 48 | PaymentMethodManifestTable(const PaymentMethodManifestTable& other) = delete; |
| 49 | PaymentMethodManifestTable& operator=( |
| 50 | const PaymentMethodManifestTable& other) = delete; |
| 51 | |
| 52 | // Retrieves the PaymentMethodManifestTable* owned by `db`. |
gogerald | 6d16ea5 | 2017-04-13 20:43:28 | [diff] [blame] | 53 | static PaymentMethodManifestTable* FromWebDatabase(WebDatabase* db); |
| 54 | |
| 55 | // WebDatabaseTable: |
| 56 | WebDatabaseTable::TypeKey GetTypeKey() const override; |
| 57 | bool CreateTablesIfNecessary() override; |
| 58 | bool IsSyncable() override; |
| 59 | bool MigrateToVersion(int version, bool* update_compatible_version) override; |
| 60 | |
gogerald | 69a1f75 | 2017-04-27 21:18:07 | [diff] [blame] | 61 | // Remove expired data. |
| 62 | void RemoveExpiredData(); |
| 63 | |
Rouslan Solomakhin | ebf9f16 | 2020-08-27 15:28:13 | [diff] [blame] | 64 | // Adds `payment_method`'s manifest. `web_app_ids` contains supported web apps |
gogerald | 6d16ea5 | 2017-04-13 20:43:28 | [diff] [blame] | 65 | // ids. |
| 66 | bool AddManifest(const std::string& payment_method, |
| 67 | const std::vector<std::string>& web_app_ids); |
| 68 | |
Rouslan Solomakhin | ebf9f16 | 2020-08-27 15:28:13 | [diff] [blame] | 69 | // Gets manifest for `payment_method`. Return empty vector if no manifest |
gogerald | 6d16ea5 | 2017-04-13 20:43:28 | [diff] [blame] | 70 | // exists for this method. |
| 71 | std::vector<std::string> GetManifest(const std::string& payment_method); |
| 72 | |
Rouslan Solomakhin | ebf9f16 | 2020-08-27 15:28:13 | [diff] [blame] | 73 | // Adds a secure payment confirmation `instrument`. All existing data for the |
| 74 | // instrument's (relying_party_id, credential_id) tuple is erased before the |
| 75 | // new data is added. |
| 76 | // |
| 77 | // Each field in the `instrument` should be non-empty and `relying_party_id` |
| 78 | // field should be a valid domain string. See: |
| 79 | // https://url.spec.whatwg.org/#valid-domain-string |
| 80 | // |
| 81 | // Returns false for invalid data, e.g., credential reuse between relying |
| 82 | // parties, or on failure. |
| 83 | bool AddSecurePaymentConfirmationInstrument( |
| 84 | const SecurePaymentConfirmationInstrument& instrument); |
| 85 | |
| 86 | // Gets the list of secure payment confirmation instruments for the given list |
| 87 | // of `credential_ids`. |
| 88 | // |
| 89 | // Returns an empty vector when no data is found or when a read error occurs. |
| 90 | // Does not return invalid instruments. |
| 91 | // |
| 92 | // Please use `std::move()` for `credential_ids` parameter to avoid extra |
| 93 | // copies. |
| 94 | std::vector<std::unique_ptr<SecurePaymentConfirmationInstrument>> |
| 95 | GetSecurePaymentConfirmationInstruments( |
| 96 | std::vector<std::vector<uint8_t>> credential_ids); |
gogerald | 6d16ea5 | 2017-04-13 20:43:28 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | } // namespace payments |
| 100 | |
Rouslan Solomakhin | de01253 | 2017-09-20 15:18:34 | [diff] [blame] | 101 | #endif // COMPONENTS_PAYMENTS_CONTENT_PAYMENT_METHOD_MANIFEST_TABLE_H_ |