OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/net/gaia/gaia_oauth_fetcher.h" | 5 #include "chrome/browser/net/gaia/gaia_oauth_fetcher.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/json/json_reader.h" | 11 #include "base/json/json_reader.h" |
12 #include "base/string_split.h" | 12 #include "base/string_split.h" |
13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
14 #include "chrome/browser/net/gaia/gaia_oauth_consumer.h" | 14 #include "chrome/browser/net/gaia/gaia_oauth_consumer.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/ui/browser_list.h" | 16 #include "chrome/browser/ui/browser.h" |
| 17 #include "chrome/browser/ui/browser_finder.h" |
17 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 18 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
18 #include "chrome/common/chrome_notification_types.h" | 19 #include "chrome/common/chrome_notification_types.h" |
19 #include "chrome/common/net/gaia/gaia_auth_fetcher.h" | 20 #include "chrome/common/net/gaia/gaia_auth_fetcher.h" |
20 #include "chrome/common/net/gaia/gaia_constants.h" | 21 #include "chrome/common/net/gaia/gaia_constants.h" |
21 #include "chrome/common/net/gaia/gaia_urls.h" | 22 #include "chrome/common/net/gaia/gaia_urls.h" |
22 #include "chrome/common/net/gaia/google_service_auth_error.h" | 23 #include "chrome/common/net/gaia/google_service_auth_error.h" |
23 #include "chrome/common/net/gaia/oauth_request_signer.h" | 24 #include "chrome/common/net/gaia/oauth_request_signer.h" |
24 #include "chrome/common/net/url_util.h" | 25 #include "chrome/common/net/url_util.h" |
25 #include "content/public/browser/notification_details.h" | 26 #include "content/public/browser/notification_details.h" |
26 #include "content/public/browser/notification_source.h" | 27 #include "content/public/browser/notification_source.h" |
| 28 #include "content/public/common/referrer.h" |
27 #include "content/public/common/url_fetcher.h" | 29 #include "content/public/common/url_fetcher.h" |
28 #include "grit/chromium_strings.h" | 30 #include "grit/chromium_strings.h" |
29 #include "net/base/load_flags.h" | 31 #include "net/base/load_flags.h" |
30 #include "net/http/http_status_code.h" | 32 #include "net/http/http_status_code.h" |
31 #include "net/url_request/url_request_context_getter.h" | 33 #include "net/url_request/url_request_context_getter.h" |
32 #include "net/url_request/url_request_status.h" | 34 #include "net/url_request/url_request_status.h" |
33 #include "ui/base/l10n/l10n_util.h" | 35 #include "ui/base/l10n/l10n_util.h" |
34 | 36 |
35 static const char kOAuthTokenCookie[] = "oauth_token"; | 37 static const char kOAuthTokenCookie[] = "oauth_token"; |
36 | 38 |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 void GaiaOAuthFetcher::StartGetOAuthToken() { | 306 void GaiaOAuthFetcher::StartGetOAuthToken() { |
305 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; | 307 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; |
306 DCHECK(!popup_); | 308 DCHECK(!popup_); |
307 | 309 |
308 request_type_ = OAUTH1_LOGIN; | 310 request_type_ = OAUTH1_LOGIN; |
309 fetch_pending_ = true; | 311 fetch_pending_ = true; |
310 registrar_.Add(this, | 312 registrar_.Add(this, |
311 chrome::NOTIFICATION_COOKIE_CHANGED, | 313 chrome::NOTIFICATION_COOKIE_CHANGED, |
312 content::Source<Profile>(profile_)); | 314 content::Source<Profile>(profile_)); |
313 | 315 |
314 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); | 316 Browser* browser = browser::FindLastActiveWithProfile(profile_); |
315 DCHECK(browser); | 317 DCHECK(browser); |
316 | 318 |
317 OpenGetOAuthTokenURL(browser, | 319 OpenGetOAuthTokenURL(browser, |
318 MakeGetOAuthTokenUrl(GaiaUrls::GetInstance()->oauth1_login_scope(), | 320 MakeGetOAuthTokenUrl(GaiaUrls::GetInstance()->oauth1_login_scope(), |
319 l10n_util::GetStringUTF8(IDS_PRODUCT_NAME)), | 321 l10n_util::GetStringUTF8(IDS_PRODUCT_NAME)), |
320 content::Referrer(GURL("chrome://settings/personal"), | 322 content::Referrer(GURL("chrome://settings/personal"), |
321 WebKit::WebReferrerPolicyDefault), | 323 WebKit::WebReferrerPolicyDefault), |
322 NEW_POPUP, | 324 NEW_POPUP, |
323 content::PAGE_TRANSITION_AUTO_BOOKMARK); | 325 content::PAGE_TRANSITION_AUTO_BOOKMARK); |
324 popup_ = BrowserList::GetLastActiveWithProfile(profile_); | 326 popup_ = browser::FindLastActiveWithProfile(profile_); |
325 DCHECK(popup_ && popup_ != browser); | 327 DCHECK(popup_ && popup_ != browser); |
326 registrar_.Add(this, | 328 registrar_.Add(this, |
327 chrome::NOTIFICATION_BROWSER_CLOSING, | 329 chrome::NOTIFICATION_BROWSER_CLOSING, |
328 content::Source<Browser>(popup_)); | 330 content::Source<Browser>(popup_)); |
329 } | 331 } |
330 | 332 |
331 void GaiaOAuthFetcher::StartOAuthLogin( | 333 void GaiaOAuthFetcher::StartOAuthLogin( |
332 const char* source, | 334 const char* source, |
333 const char* service, | 335 const char* service, |
334 const std::string& oauth1_access_token, | 336 const std::string& oauth1_access_token, |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 break; | 708 break; |
707 case OAUTH2_REVOKE_TOKEN: | 709 case OAUTH2_REVOKE_TOKEN: |
708 OnOAuthRevokeTokenFetched(data, status, response_code); | 710 OnOAuthRevokeTokenFetched(data, status, response_code); |
709 break; | 711 break; |
710 } | 712 } |
711 } | 713 } |
712 | 714 |
713 bool GaiaOAuthFetcher::ShouldAutoFetch(RequestType fetch_step) { | 715 bool GaiaOAuthFetcher::ShouldAutoFetch(RequestType fetch_step) { |
714 return fetch_step <= auto_fetch_limit_; | 716 return fetch_step <= auto_fetch_limit_; |
715 } | 717 } |
OLD | NEW |