OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/content/browser/wallet/wallet_service_url.h" | 5 #include "components/autofill/content/browser/wallet/wallet_service_url.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
11 #include "base/metrics/field_trial.h" | 11 #include "base/metrics/field_trial.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
14 #include "components/autofill/core/common/autofill_switches.h" | 14 #include "components/autofill/core/common/autofill_switches.h" |
15 #include "content/public/common/url_constants.h" | |
15 #include "google_apis/gaia/gaia_urls.h" | 16 #include "google_apis/gaia/gaia_urls.h" |
16 #include "net/base/url_util.h" | 17 #include "net/base/url_util.h" |
17 #include "url/gurl.h" | 18 #include "url/gurl.h" |
18 | 19 |
19 namespace autofill { | 20 namespace autofill { |
20 namespace { | 21 namespace { |
21 | 22 |
22 const char kProdWalletServiceUrl[] = "https://wallet.google.com/"; | 23 const char kProdWalletServiceUrl[] = "https://wallet.google.com/"; |
23 | 24 |
24 // TODO(ahutter): Remove this once production is ready. | 25 // TODO(ahutter): Remove this once production is ready. |
25 const char kSandboxWalletServiceUrl[] = | 26 const char kSandboxWalletServiceUrl[] = |
26 "https://wallet-web.sandbox.google.com/"; | 27 "https://wallet-web.sandbox.google.com/"; |
27 | 28 |
28 // TODO(ahutter): Remove this once production is ready. | 29 // TODO(ahutter): Remove this once production is ready. |
29 const char kSandboxWalletSecureServiceUrl[] = | 30 const char kSandboxWalletSecureServiceUrl[] = |
30 "https://wallet-web.sandbox.google.com/"; | 31 "https://wallet-web.sandbox.google.com/"; |
31 | 32 |
33 // Set to true during some tests. | |
34 bool g_use_testing_sign_in_continue_url = false; | |
35 | |
32 bool IsWalletProductionEnabled() { | 36 bool IsWalletProductionEnabled() { |
33 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 37 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
34 std::string sandbox_enabled( | 38 std::string sandbox_enabled( |
35 command_line->GetSwitchValueASCII(switches::kWalletServiceUseSandbox)); | 39 command_line->GetSwitchValueASCII(switches::kWalletServiceUseSandbox)); |
36 if (!sandbox_enabled.empty()) | 40 if (!sandbox_enabled.empty()) |
37 return sandbox_enabled != "1"; | 41 return sandbox_enabled != "1"; |
38 return true; | 42 return true; |
39 } | 43 } |
40 | 44 |
41 GURL GetWalletHostUrl() { | 45 GURL GetWalletHostUrl() { |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 GetSignInContinueUrl().spec()); | 147 GetSignInContinueUrl().spec()); |
144 return url; | 148 return url; |
145 } | 149 } |
146 | 150 |
147 // The continue url portion of the sign-in URL. This URL is used as a milestone | 151 // The continue url portion of the sign-in URL. This URL is used as a milestone |
148 // to determine that the sign-in process is finished. It has to be a Google | 152 // to determine that the sign-in process is finished. It has to be a Google |
149 // domain, use https://, and do almost nothing, but otherwise it's not too | 153 // domain, use https://, and do almost nothing, but otherwise it's not too |
150 // important what the URL actually is: it's not important that this URL has the | 154 // important what the URL actually is: it's not important that this URL has the |
151 // ability to generate a gdToken. | 155 // ability to generate a gdToken. |
152 GURL GetSignInContinueUrl() { | 156 GURL GetSignInContinueUrl() { |
157 if (g_use_testing_sign_in_continue_url) | |
158 return GURL(content::kAboutBlankURL); | |
159 | |
153 return GetPassiveAuthUrl(0); | 160 return GetPassiveAuthUrl(0); |
154 } | 161 } |
155 | 162 |
163 void SetUseTestingSignInContinueUrl() { | |
164 g_use_testing_sign_in_continue_url = true; | |
165 } | |
166 | |
156 bool IsSignInContinueUrl(const GURL& url, size_t* user_index) { | 167 bool IsSignInContinueUrl(const GURL& url, size_t* user_index) { |
157 GURL final_url = wallet::GetSignInContinueUrl(); | 168 GURL final_url = GetSignInContinueUrl(); |
158 if (!url.SchemeIsSecure() || | 169 if (url.scheme() != final_url.scheme() || |
159 url.host() != final_url.host() || | 170 url.host() != final_url.host() || |
160 url.path() != final_url.path()) { | 171 url.path() != final_url.path()) { |
161 return false; | 172 return false; |
162 } | 173 } |
163 | 174 |
164 *user_index = 0; | 175 *user_index = 0; |
165 std::string query_str = url.query(); | 176 std::string query_str = url.query(); |
166 url_parse::Component query(0, query_str.length()); | 177 url_parse::Component query(0, query_str.length()); |
167 url_parse::Component key, value; | 178 url_parse::Component key, value; |
168 const char kUserIndexKey[] = "authuser"; | 179 const char kUserIndexKey[] = "authuser"; |
169 while (url_parse::ExtractQueryKeyValue(query_str.c_str(), &query, &key, | 180 while (url_parse::ExtractQueryKeyValue(query_str.c_str(), &query, &key, |
170 &value)) { | 181 &value)) { |
171 if (key.is_nonempty() && | 182 if (key.is_nonempty() && |
172 query_str.substr(key.begin, key.len) == kUserIndexKey) { | 183 query_str.substr(key.begin, key.len) == kUserIndexKey) { |
173 base::StringToSizeT(query_str.substr(value.begin, value.len), user_index); | 184 base::StringToSizeT(query_str.substr(value.begin, value.len), user_index); |
174 break; | 185 break; |
175 } | 186 } |
176 } | 187 } |
177 | 188 |
178 return true; | 189 return true; |
179 } | 190 } |
180 | 191 |
181 bool IsSignInRelatedUrl(const GURL& url) { | 192 bool IsSignInRelatedUrl(const GURL& url) { |
182 return url.GetOrigin() == GetSignInUrl().GetOrigin(); | 193 size_t unused; |
194 return url.GetOrigin() == GetSignInUrl().GetOrigin() || | |
195 IsSignInContinueUrl(url, &unused); | |
groby-ooo-7-16
2014/01/03 00:10:22
I assume we added this additional test because of
Evan Stade
2014/01/03 00:14:57
Not sure where you're getting the youtube idea fro
| |
183 } | 196 } |
184 | 197 |
185 bool IsUsingProd() { | 198 bool IsUsingProd() { |
186 return GetWalletHostUrl() == GURL(kProdWalletServiceUrl); | 199 return GetWalletHostUrl() == GURL(kProdWalletServiceUrl); |
187 } | 200 } |
188 | 201 |
189 } // namespace wallet | 202 } // namespace wallet |
190 } // namespace autofill | 203 } // namespace autofill |
OLD | NEW |