OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/autofill/core/browser/payments/payments_client.h" | 5 #include "components/autofill/core/browser/payments/payments_client.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/json/json_reader.h" | 11 #include "base/json/json_reader.h" |
12 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
18 #include "base/values.h" | 18 #include "base/values.h" |
19 #include "build/build_config.h" | 19 #include "build/build_config.h" |
20 #include "components/autofill/core/browser/autofill_data_model.h" | 20 #include "components/autofill/core/browser/autofill_data_model.h" |
21 #include "components/autofill/core/browser/autofill_type.h" | 21 #include "components/autofill/core/browser/autofill_type.h" |
22 #include "components/autofill/core/browser/credit_card.h" | 22 #include "components/autofill/core/browser/credit_card.h" |
23 #include "components/autofill/core/browser/payments/payments_request.h" | 23 #include "components/autofill/core/browser/payments/payments_request.h" |
24 #include "components/autofill/core/common/autofill_switches.h" | 24 #include "components/autofill/core/browser/payments/payments_service_url.h" |
25 #include "components/data_use_measurement/core/data_use_user_data.h" | 25 #include "components/data_use_measurement/core/data_use_user_data.h" |
26 #include "google_apis/gaia/identity_provider.h" | 26 #include "google_apis/gaia/identity_provider.h" |
27 #include "net/base/escape.h" | 27 #include "net/base/escape.h" |
28 #include "net/base/load_flags.h" | 28 #include "net/base/load_flags.h" |
29 #include "net/http/http_status_code.h" | 29 #include "net/http/http_status_code.h" |
30 #include "net/url_request/url_fetcher.h" | 30 #include "net/url_request/url_fetcher.h" |
31 #include "net/url_request/url_request_context_getter.h" | 31 #include "net/url_request/url_request_context_getter.h" |
32 | 32 |
33 namespace autofill { | 33 namespace autofill { |
34 namespace payments { | 34 namespace payments { |
35 | 35 |
36 namespace { | 36 namespace { |
37 | 37 |
38 const char kPaymentsRequestHost[] = "https://wallet.google.com"; | |
39 const char kPaymentsRequestHostSandbox[] = "https://sandbox.google.com"; | |
40 | |
41 const char kUnmaskCardRequestPath[] = | 38 const char kUnmaskCardRequestPath[] = |
42 "payments/apis-secure/creditcardservice/getrealpan?s7e_suffix=chromewallet"; | 39 "payments/apis-secure/creditcardservice/getrealpan?s7e_suffix=chromewallet"; |
43 const char kUnmaskCardRequestFormat[] = | 40 const char kUnmaskCardRequestFormat[] = |
44 "requestContentType=application/json; charset=utf-8&request=%s" | 41 "requestContentType=application/json; charset=utf-8&request=%s" |
45 "&s7e_13_cvc=%s"; | 42 "&s7e_13_cvc=%s"; |
46 | 43 |
47 const char kGetUploadDetailsRequestPath[] = | 44 const char kGetUploadDetailsRequestPath[] = |
48 "payments/apis/chromepaymentsservice/getdetailsforsavecard"; | 45 "payments/apis/chromepaymentsservice/getdetailsforsavecard"; |
49 | 46 |
50 const char kUploadCardRequestPath[] = | 47 const char kUploadCardRequestPath[] = |
51 "payments/apis-secure/chromepaymentsservice/savecard" | 48 "payments/apis-secure/chromepaymentsservice/savecard" |
52 "?s7e_suffix=chromewallet"; | 49 "?s7e_suffix=chromewallet"; |
53 const char kUploadCardRequestFormat[] = | 50 const char kUploadCardRequestFormat[] = |
54 "requestContentType=application/json; charset=utf-8&request=%s" | 51 "requestContentType=application/json; charset=utf-8&request=%s" |
55 "&s7e_1_pan=%s&s7e_13_cvc=%s"; | 52 "&s7e_1_pan=%s&s7e_13_cvc=%s"; |
56 | 53 |
57 const char kTokenServiceConsumerId[] = "wallet_client"; | 54 const char kTokenServiceConsumerId[] = "wallet_client"; |
58 const char kPaymentsOAuth2Scope[] = | 55 const char kPaymentsOAuth2Scope[] = |
59 "https://www.googleapis.com/auth/wallet.chrome"; | 56 "https://www.googleapis.com/auth/wallet.chrome"; |
60 | 57 |
61 // This is mostly copied from wallet_service_url.cc, which is currently in | |
62 // content/, hence inaccessible from here. | |
63 bool IsPaymentsProductionEnabled() { | |
64 // If the command line flag exists, it takes precedence. | |
65 const base::CommandLine* command_line = | |
66 base::CommandLine::ForCurrentProcess(); | |
67 std::string sandbox_enabled( | |
68 command_line->GetSwitchValueASCII(switches::kWalletServiceUseSandbox)); | |
69 if (!sandbox_enabled.empty()) | |
70 return sandbox_enabled != "1"; | |
71 | |
72 #if defined(ENABLE_PROD_WALLET_SERVICE) | |
73 return true; | |
74 #else | |
75 return false; | |
76 #endif | |
77 } | |
78 | |
79 GURL GetRequestUrl(const std::string& path) { | 58 GURL GetRequestUrl(const std::string& path) { |
80 if (base::CommandLine::ForCurrentProcess()->HasSwitch("sync-url")) { | 59 if (base::CommandLine::ForCurrentProcess()->HasSwitch("sync-url")) { |
81 if (IsPaymentsProductionEnabled()) { | 60 if (IsPaymentsProductionEnabled()) { |
82 LOG(ERROR) << "You are using production Payments but you specified a " | 61 LOG(ERROR) << "You are using production Payments but you specified a " |
83 "--sync-url. You likely want to disable the sync sandbox " | 62 "--sync-url. You likely want to disable the sync sandbox " |
84 "or switch to sandbox Payments. Both are controlled in " | 63 "or switch to sandbox Payments. Both are controlled in " |
85 "about:flags."; | 64 "about:flags."; |
86 } | 65 } |
87 } else if (!IsPaymentsProductionEnabled()) { | 66 } else if (!IsPaymentsProductionEnabled()) { |
88 LOG(ERROR) << "You are using sandbox Payments but you didn't specify a " | 67 LOG(ERROR) << "You are using sandbox Payments but you didn't specify a " |
89 "--sync-url. You likely want to enable the sync sandbox " | 68 "--sync-url. You likely want to enable the sync sandbox " |
90 "or switch to production Payments. Both are controlled in " | 69 "or switch to production Payments. Both are controlled in " |
91 "about:flags."; | 70 "about:flags."; |
92 } | 71 } |
93 | 72 |
94 GURL base(IsPaymentsProductionEnabled() ? kPaymentsRequestHost | 73 return GetBaseSecureUrl().Resolve(path); |
95 : kPaymentsRequestHostSandbox); | |
96 return base.Resolve(path); | |
97 } | 74 } |
98 | 75 |
99 std::unique_ptr<base::DictionaryValue> BuildRiskDictionary( | 76 std::unique_ptr<base::DictionaryValue> BuildRiskDictionary( |
100 const std::string& encoded_risk_data) { | 77 const std::string& encoded_risk_data) { |
101 std::unique_ptr<base::DictionaryValue> risk_data(new base::DictionaryValue()); | 78 std::unique_ptr<base::DictionaryValue> risk_data(new base::DictionaryValue()); |
102 #if defined(OS_IOS) | 79 #if defined(OS_IOS) |
103 // Browser fingerprinting is not available on iOS. Instead, we generate | 80 // Browser fingerprinting is not available on iOS. Instead, we generate |
104 // RiskAdvisoryData. | 81 // RiskAdvisoryData. |
105 risk_data->SetString("message_type", "RISK_ADVISORY_DATA"); | 82 risk_data->SetString("message_type", "RISK_ADVISORY_DATA"); |
106 risk_data->SetString("encoding_type", "BASE_64_URL"); | 83 risk_data->SetString("encoding_type", "BASE_64_URL"); |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 | 525 |
549 void PaymentsClient::SetOAuth2TokenAndStartRequest() { | 526 void PaymentsClient::SetOAuth2TokenAndStartRequest() { |
550 url_fetcher_->AddExtraRequestHeader(net::HttpRequestHeaders::kAuthorization + | 527 url_fetcher_->AddExtraRequestHeader(net::HttpRequestHeaders::kAuthorization + |
551 std::string(": Bearer ") + access_token_); | 528 std::string(": Bearer ") + access_token_); |
552 | 529 |
553 url_fetcher_->Start(); | 530 url_fetcher_->Start(); |
554 } | 531 } |
555 | 532 |
556 } // namespace payments | 533 } // namespace payments |
557 } // namespace autofill | 534 } // namespace autofill |
OLD | NEW |