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/ui/sync/one_click_signin_helper.h" | 5 #include "chrome/browser/ui/sync/one_click_signin_helper.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 56 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
57 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 57 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
58 #include "chrome/common/chrome_version_info.h" | 58 #include "chrome/common/chrome_version_info.h" |
59 #include "chrome/common/net/url_util.h" | 59 #include "chrome/common/net/url_util.h" |
60 #include "chrome/common/pref_names.h" | 60 #include "chrome/common/pref_names.h" |
61 #include "chrome/common/url_constants.h" | 61 #include "chrome/common/url_constants.h" |
62 #include "chrome/grit/chromium_strings.h" | 62 #include "chrome/grit/chromium_strings.h" |
63 #include "chrome/grit/generated_resources.h" | 63 #include "chrome/grit/generated_resources.h" |
64 #include "components/autofill/core/common/password_form.h" | 64 #include "components/autofill/core/common/password_form.h" |
65 #include "components/google/core/browser/google_util.h" | 65 #include "components/google/core/browser/google_util.h" |
| 66 #include "components/password_manager/content/browser/content_password_manager_d
river.h" |
66 #include "components/password_manager/core/browser/password_manager.h" | 67 #include "components/password_manager/core/browser/password_manager.h" |
67 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 68 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
68 #include "components/signin/core/browser/signin_client.h" | 69 #include "components/signin/core/browser/signin_client.h" |
69 #include "components/signin/core/browser/signin_error_controller.h" | 70 #include "components/signin/core/browser/signin_error_controller.h" |
70 #include "components/signin/core/browser/signin_manager.h" | 71 #include "components/signin/core/browser/signin_manager.h" |
71 #include "components/signin/core/browser/signin_manager_cookie_helper.h" | 72 #include "components/signin/core/browser/signin_manager_cookie_helper.h" |
72 #include "components/signin/core/common/profile_management_switches.h" | 73 #include "components/signin/core/common/profile_management_switches.h" |
73 #include "components/sync_driver/sync_prefs.h" | 74 #include "components/sync_driver/sync_prefs.h" |
74 #include "content/public/browser/browser_thread.h" | 75 #include "content/public/browser/browser_thread.h" |
75 #include "content/public/browser/navigation_entry.h" | 76 #include "content/public/browser/navigation_entry.h" |
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 } | 666 } |
666 | 667 |
667 | 668 |
668 // OneClickSigninHelper ------------------------------------------------------- | 669 // OneClickSigninHelper ------------------------------------------------------- |
669 | 670 |
670 DEFINE_WEB_CONTENTS_USER_DATA_KEY(OneClickSigninHelper); | 671 DEFINE_WEB_CONTENTS_USER_DATA_KEY(OneClickSigninHelper); |
671 | 672 |
672 // static | 673 // static |
673 const int OneClickSigninHelper::kMaxNavigationsSince = 10; | 674 const int OneClickSigninHelper::kMaxNavigationsSince = 10; |
674 | 675 |
675 OneClickSigninHelper::OneClickSigninHelper( | 676 OneClickSigninHelper::OneClickSigninHelper(content::WebContents* web_contents) |
676 content::WebContents* web_contents, | |
677 password_manager::PasswordManager* password_manager) | |
678 : content::WebContentsObserver(web_contents), | 677 : content::WebContentsObserver(web_contents), |
679 showing_signin_(false), | 678 showing_signin_(false), |
680 auto_accept_(AUTO_ACCEPT_NONE), | 679 auto_accept_(AUTO_ACCEPT_NONE), |
681 source_(signin::SOURCE_UNKNOWN), | 680 source_(signin::SOURCE_UNKNOWN), |
682 switched_to_advanced_(false), | 681 switched_to_advanced_(false), |
683 untrusted_navigations_since_signin_visit_(0), | 682 untrusted_navigations_since_signin_visit_(0), |
684 untrusted_confirmation_required_(false), | 683 untrusted_confirmation_required_(false), |
685 do_not_clear_pending_email_(false), | 684 do_not_clear_pending_email_(false), |
686 do_not_start_sync_for_testing_(false), | 685 do_not_start_sync_for_testing_(false), |
687 weak_pointer_factory_(this) { | 686 weak_pointer_factory_(this) { |
688 // May be NULL during testing. | 687 if (web_contents->GetMainFrame()) |
689 if (password_manager) { | 688 RenderFrameCreated(web_contents->GetMainFrame()); |
690 password_manager->AddSubmissionCallback( | |
691 base::Bind(&OneClickSigninHelper::PasswordSubmitted, | |
692 weak_pointer_factory_.GetWeakPtr())); | |
693 } | |
694 } | 689 } |
695 | 690 |
696 OneClickSigninHelper::~OneClickSigninHelper() {} | 691 OneClickSigninHelper::~OneClickSigninHelper() {} |
697 | 692 |
698 // static | 693 // static |
699 void OneClickSigninHelper::LogHistogramValue( | 694 void OneClickSigninHelper::LogHistogramValue( |
700 signin::Source source, int action) { | 695 signin::Source source, int action) { |
701 switch (source) { | 696 switch (source) { |
702 case signin::SOURCE_START_PAGE: | 697 case signin::SOURCE_START_PAGE: |
703 UMA_HISTOGRAM_ENUMERATION("Signin.StartPageActions", action, | 698 UMA_HISTOGRAM_ENUMERATION("Signin.StartPageActions", action, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
752 COMPILE_ASSERT(signin::SOURCE_UNKNOWN == 12, | 747 COMPILE_ASSERT(signin::SOURCE_UNKNOWN == 12, |
753 kSourceEnumHasChangedButNotThisSwitchStatement); | 748 kSourceEnumHasChangedButNotThisSwitchStatement); |
754 UMA_HISTOGRAM_ENUMERATION("Signin.UnknownActions", action, | 749 UMA_HISTOGRAM_ENUMERATION("Signin.UnknownActions", action, |
755 one_click_signin::HISTOGRAM_MAX); | 750 one_click_signin::HISTOGRAM_MAX); |
756 } | 751 } |
757 UMA_HISTOGRAM_ENUMERATION("Signin.AllAccessPointActions", action, | 752 UMA_HISTOGRAM_ENUMERATION("Signin.AllAccessPointActions", action, |
758 one_click_signin::HISTOGRAM_MAX); | 753 one_click_signin::HISTOGRAM_MAX); |
759 } | 754 } |
760 | 755 |
761 // static | 756 // static |
762 void OneClickSigninHelper::CreateForWebContentsWithPasswordManager( | |
763 content::WebContents* contents, | |
764 password_manager::PasswordManager* password_manager) { | |
765 if (!FromWebContents(contents)) { | |
766 contents->SetUserData(UserDataKey(), | |
767 new OneClickSigninHelper(contents, password_manager)); | |
768 } | |
769 } | |
770 | |
771 // static | |
772 bool OneClickSigninHelper::CanOffer(content::WebContents* web_contents, | 757 bool OneClickSigninHelper::CanOffer(content::WebContents* web_contents, |
773 CanOfferFor can_offer_for, | 758 CanOfferFor can_offer_for, |
774 const std::string& email, | 759 const std::string& email, |
775 std::string* error_message) { | 760 std::string* error_message) { |
776 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 761 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
777 VLOG(1) << "OneClickSigninHelper::CanOffer"; | 762 VLOG(1) << "OneClickSigninHelper::CanOffer"; |
778 | 763 |
779 if (error_message) | 764 if (error_message) |
780 error_message->clear(); | 765 error_message->clear(); |
781 | 766 |
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1255 } | 1240 } |
1256 | 1241 |
1257 void OneClickSigninHelper::SetDoNotClearPendingEmailForTesting() { | 1242 void OneClickSigninHelper::SetDoNotClearPendingEmailForTesting() { |
1258 do_not_clear_pending_email_ = true; | 1243 do_not_clear_pending_email_ = true; |
1259 } | 1244 } |
1260 | 1245 |
1261 void OneClickSigninHelper::set_do_not_start_sync_for_testing() { | 1246 void OneClickSigninHelper::set_do_not_start_sync_for_testing() { |
1262 do_not_start_sync_for_testing_ = true; | 1247 do_not_start_sync_for_testing_ = true; |
1263 } | 1248 } |
1264 | 1249 |
| 1250 void OneClickSigninHelper::RenderFrameCreated( |
| 1251 content::RenderFrameHost* render_frame_host) { |
| 1252 ContentPasswordManagerDriver* driver = |
| 1253 ContentPasswordManagerDriver::GetForRenderFrameHost(render_frame_host); |
| 1254 // May be NULL in testing. |
| 1255 if (!driver) |
| 1256 return; |
| 1257 driver->GetPasswordManager()->AddSubmissionCallback(base::Bind( |
| 1258 &PrerenderTabHelper::PasswordSubmitted, weak_factory_.GetWeakPtr())); |
| 1259 } |
| 1260 |
1265 void OneClickSigninHelper::DidStartNavigationToPendingEntry( | 1261 void OneClickSigninHelper::DidStartNavigationToPendingEntry( |
1266 const GURL& url, | 1262 const GURL& url, |
1267 content::NavigationController::ReloadType reload_type) { | 1263 content::NavigationController::ReloadType reload_type) { |
1268 VLOG(1) << "OneClickSigninHelper::DidStartNavigationToPendingEntry: url=" << | 1264 VLOG(1) << "OneClickSigninHelper::DidStartNavigationToPendingEntry: url=" << |
1269 url.spec(); | 1265 url.spec(); |
1270 // If the tab navigates to a new page, and this page is not a valid Gaia | 1266 // If the tab navigates to a new page, and this page is not a valid Gaia |
1271 // sign in redirect or reponse, or the expected continue URL, make sure to | 1267 // sign in redirect or reponse, or the expected continue URL, make sure to |
1272 // clear the internal state. This is needed to detect navigations in the | 1268 // clear the internal state. This is needed to detect navigations in the |
1273 // middle of the sign in process that may redirect back to the sign in | 1269 // middle of the sign in process that may redirect back to the sign in |
1274 // process (see crbug.com/181163 for details). | 1270 // process (see crbug.com/181163 for details). |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1581 // If the web contents is showing a blank page and not about to be closed, | 1577 // If the web contents is showing a blank page and not about to be closed, |
1582 // redirect to the NTP or apps page. | 1578 // redirect to the NTP or apps page. |
1583 if (signin::IsContinueUrlForWebBasedSigninFlow(current_url) && | 1579 if (signin::IsContinueUrlForWebBasedSigninFlow(current_url) && |
1584 !signin::IsAutoCloseEnabledInURL(original_continue_url_)) { | 1580 !signin::IsAutoCloseEnabledInURL(original_continue_url_)) { |
1585 RedirectToNtpOrAppsPage( | 1581 RedirectToNtpOrAppsPage( |
1586 web_contents(), | 1582 web_contents(), |
1587 signin::GetSourceForPromoURL(original_continue_url_)); | 1583 signin::GetSourceForPromoURL(original_continue_url_)); |
1588 } | 1584 } |
1589 } | 1585 } |
1590 } | 1586 } |
OLD | NEW |