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/tabs/tab_strip_model.h" | 16 #include "chrome/browser/tabs/tab_strip_model.h" |
17 #include "chrome/browser/ui/browser_list.h" | 17 #include "chrome/browser/ui/browser_list.h" |
18 #include "chrome/common/chrome_notification_types.h" | 18 #include "chrome/common/chrome_notification_types.h" |
19 #include "chrome/common/net/gaia/gaia_auth_fetcher.h" | 19 #include "chrome/common/net/gaia/gaia_auth_fetcher.h" |
20 #include "chrome/common/net/gaia/gaia_constants.h" | 20 #include "chrome/common/net/gaia/gaia_constants.h" |
21 #include "chrome/common/net/gaia/gaia_urls.h" | 21 #include "chrome/common/net/gaia/gaia_urls.h" |
22 #include "chrome/common/net/gaia/google_service_auth_error.h" | 22 #include "chrome/common/net/gaia/google_service_auth_error.h" |
23 #include "chrome/common/net/gaia/oauth_request_signer.h" | 23 #include "chrome/common/net/gaia/oauth_request_signer.h" |
| 24 #include "chrome/common/net/url_util.h" |
24 #include "content/public/browser/notification_details.h" | 25 #include "content/public/browser/notification_details.h" |
25 #include "content/public/browser/notification_source.h" | 26 #include "content/public/browser/notification_source.h" |
26 #include "content/public/common/url_fetcher.h" | 27 #include "content/public/common/url_fetcher.h" |
27 #include "grit/chromium_strings.h" | 28 #include "grit/chromium_strings.h" |
28 #include "net/base/load_flags.h" | 29 #include "net/base/load_flags.h" |
29 #include "net/http/http_status_code.h" | 30 #include "net/http/http_status_code.h" |
30 #include "net/url_request/url_request_context_getter.h" | 31 #include "net/url_request/url_request_context_getter.h" |
31 #include "net/url_request/url_request_status.h" | 32 #include "net/url_request/url_request_status.h" |
32 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
33 | 34 |
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 OnOAuthGetAccessTokenFetched(data, status, response_code); | 679 OnOAuthGetAccessTokenFetched(data, status, response_code); |
679 } else if (url.spec() == gaia_urls->oauth_wrap_bridge_url()) { | 680 } else if (url.spec() == gaia_urls->oauth_wrap_bridge_url()) { |
680 OnOAuthWrapBridgeFetched(data, status, response_code); | 681 OnOAuthWrapBridgeFetched(data, status, response_code); |
681 } else if (url.spec() == gaia_urls->oauth_user_info_url()) { | 682 } else if (url.spec() == gaia_urls->oauth_user_info_url()) { |
682 OnUserInfoFetched(data, status, response_code); | 683 OnUserInfoFetched(data, status, response_code); |
683 } else if (StartsWithASCII(url.spec(), | 684 } else if (StartsWithASCII(url.spec(), |
684 gaia_urls->oauth_revoke_token_url(), | 685 gaia_urls->oauth_revoke_token_url(), |
685 true)) { | 686 true)) { |
686 OnOAuthRevokeTokenFetched(data, status, response_code); | 687 OnOAuthRevokeTokenFetched(data, status, response_code); |
687 } else { | 688 } else { |
688 NOTREACHED(); | 689 // Invalid cookies cause Gaia to redirect to ServiceLogin. Check if |
| 690 // this is the case and report failure properly. |
| 691 std::string url_no_query = url.GetOrigin().spec() + url.path().substr(1); |
| 692 std::string continue_url; |
| 693 if (url_no_query == gaia_urls->service_login_url() && |
| 694 chrome_common_net::GetValueForKeyInQuery(url, "continue", |
| 695 &continue_url)) { |
| 696 LOG(ERROR) << "GaiaOAuthFetcher redirected to service login" |
| 697 << " , url=" << url.spec(); |
| 698 |
| 699 if (StartsWithASCII(continue_url, |
| 700 gaia_urls->get_oauth_token_url(), |
| 701 true)) { |
| 702 consumer_->OnGetOAuthTokenFailure(GoogleServiceAuthError( |
| 703 GoogleServiceAuthError::SERVICE_UNAVAILABLE)); |
| 704 } else if (continue_url == gaia_urls->oauth1_login_url()) { |
| 705 consumer_->OnOAuthLoginFailure(GoogleServiceAuthError( |
| 706 GoogleServiceAuthError::SERVICE_UNAVAILABLE)); |
| 707 } else if (continue_url == gaia_urls->oauth_get_access_token_url()) { |
| 708 consumer_->OnOAuthGetAccessTokenFailure(GoogleServiceAuthError( |
| 709 GoogleServiceAuthError::SERVICE_UNAVAILABLE)); |
| 710 } else if (continue_url == gaia_urls->oauth_wrap_bridge_url()) { |
| 711 consumer_->OnOAuthWrapBridgeFailure(service_scope_, |
| 712 GoogleServiceAuthError( |
| 713 GoogleServiceAuthError::SERVICE_UNAVAILABLE)); |
| 714 } else if (continue_url == gaia_urls->oauth_user_info_url()) { |
| 715 consumer_->OnUserInfoFailure(GoogleServiceAuthError( |
| 716 GoogleServiceAuthError::SERVICE_UNAVAILABLE)); |
| 717 } else if (StartsWithASCII(continue_url, |
| 718 gaia_urls->oauth_revoke_token_url(), |
| 719 true)) { |
| 720 consumer_->OnOAuthRevokeTokenFailure(GoogleServiceAuthError( |
| 721 GoogleServiceAuthError::SERVICE_UNAVAILABLE)); |
| 722 } else { |
| 723 NOTREACHED(); |
| 724 } |
| 725 } else { |
| 726 NOTREACHED() << "GaiaOAuthFetcher unknown url=" << url.spec(); |
| 727 } |
689 } | 728 } |
690 } | 729 } |
691 | 730 |
692 bool GaiaOAuthFetcher::ShouldAutoFetch(AutoFetchLimit fetch_step) { | 731 bool GaiaOAuthFetcher::ShouldAutoFetch(AutoFetchLimit fetch_step) { |
693 return fetch_step <= auto_fetch_limit_; | 732 return fetch_step <= auto_fetch_limit_; |
694 } | 733 } |
OLD | NEW |