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/string_util.h" |
13 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 15 #include "base/strings/utf_string_conversions.h" |
14 #include "components/autofill/core/common/autofill_switches.h" | 16 #include "components/autofill/core/common/autofill_switches.h" |
| 17 #include "content/public/common/url_constants.h" |
15 #include "google_apis/gaia/gaia_urls.h" | 18 #include "google_apis/gaia/gaia_urls.h" |
16 #include "net/base/url_util.h" | 19 #include "net/base/url_util.h" |
17 #include "url/gurl.h" | 20 #include "url/gurl.h" |
18 | 21 |
19 namespace autofill { | 22 namespace autofill { |
20 namespace { | 23 namespace { |
21 | 24 |
22 const char kProdWalletServiceUrl[] = "https://wallet.google.com/"; | 25 const char kProdWalletServiceUrl[] = "https://wallet.google.com/"; |
23 | 26 |
24 // TODO(ahutter): Remove this once production is ready. | 27 // TODO(ahutter): Remove this once production is ready. |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 // The continue url portion of the sign-in URL. This URL is used as a milestone | 150 // 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 | 151 // 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 | 152 // 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 | 153 // important what the URL actually is: it's not important that this URL has the |
151 // ability to generate a gdToken. | 154 // ability to generate a gdToken. |
152 GURL GetSignInContinueUrl() { | 155 GURL GetSignInContinueUrl() { |
153 return GetPassiveAuthUrl(0); | 156 return GetPassiveAuthUrl(0); |
154 } | 157 } |
155 | 158 |
156 bool IsSignInContinueUrl(const GURL& url, size_t* user_index) { | 159 bool IsSignInContinueUrl(const GURL& url, size_t* user_index) { |
157 GURL final_url = wallet::GetSignInContinueUrl(); | 160 GURL final_url = GetSignInContinueUrl(); |
158 if (!url.SchemeIsSecure() || | 161 if (url.scheme() != final_url.scheme() || |
159 url.host() != final_url.host() || | 162 url.host() != final_url.host() || |
160 url.path() != final_url.path()) { | 163 url.path() != final_url.path()) { |
161 return false; | 164 return false; |
162 } | 165 } |
163 | 166 |
164 *user_index = 0; | 167 *user_index = 0; |
165 std::string query_str = url.query(); | 168 std::string query_str = url.query(); |
166 url_parse::Component query(0, query_str.length()); | 169 url_parse::Component query(0, query_str.length()); |
167 url_parse::Component key, value; | 170 url_parse::Component key, value; |
168 const char kUserIndexKey[] = "authuser"; | 171 const char kUserIndexKey[] = "authuser"; |
169 while (url_parse::ExtractQueryKeyValue(query_str.c_str(), &query, &key, | 172 while (url_parse::ExtractQueryKeyValue(query_str.c_str(), &query, &key, |
170 &value)) { | 173 &value)) { |
171 if (key.is_nonempty() && | 174 if (key.is_nonempty() && |
172 query_str.substr(key.begin, key.len) == kUserIndexKey) { | 175 query_str.substr(key.begin, key.len) == kUserIndexKey) { |
173 base::StringToSizeT(query_str.substr(value.begin, value.len), user_index); | 176 base::StringToSizeT(query_str.substr(value.begin, value.len), user_index); |
174 break; | 177 break; |
175 } | 178 } |
176 } | 179 } |
177 | 180 |
178 return true; | 181 return true; |
179 } | 182 } |
180 | 183 |
181 bool IsSignInRelatedUrl(const GURL& url) { | 184 bool IsSignInRelatedUrl(const GURL& url) { |
182 return url.GetOrigin() == GetSignInUrl().GetOrigin(); | 185 size_t unused; |
| 186 return url.GetOrigin() == GetSignInUrl().GetOrigin() || |
| 187 StartsWith(base::UTF8ToUTF16(url.GetOrigin().host()), |
| 188 base::ASCIIToUTF16("accounts."), |
| 189 false) || |
| 190 IsSignInContinueUrl(url, &unused); |
183 } | 191 } |
184 | 192 |
185 bool IsUsingProd() { | 193 bool IsUsingProd() { |
186 return GetWalletHostUrl() == GURL(kProdWalletServiceUrl); | 194 return GetWalletHostUrl() == GURL(kProdWalletServiceUrl); |
187 } | 195 } |
188 | 196 |
189 } // namespace wallet | 197 } // namespace wallet |
190 } // namespace autofill | 198 } // namespace autofill |
OLD | NEW |