| 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> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/callback_forward.h" | 13 #include "base/callback_forward.h" |
| 14 #include "base/callback_helpers.h" | 14 #include "base/callback_helpers.h" |
| 15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
| 16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/metrics/field_trial.h" | 17 #include "base/metrics/field_trial.h" |
| 18 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
| 19 #include "base/prefs/pref_service.h" | 19 #include "base/prefs/pref_service.h" |
| 20 #include "base/strings/string_split.h" | 20 #include "base/strings/string_split.h" |
| 21 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
| 22 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
| 23 #include "base/supports_user_data.h" | 23 #include "base/supports_user_data.h" |
| 24 #include "base/values.h" | 24 #include "base/values.h" |
| 25 #include "chrome/browser/browser_process.h" | 25 #include "chrome/browser/browser_process.h" |
| 26 #include "chrome/browser/chrome_notification_types.h" | 26 #include "chrome/browser/chrome_notification_types.h" |
| 27 #include "chrome/browser/defaults.h" | 27 #include "chrome/browser/defaults.h" |
| 28 #include "chrome/browser/google/google_util.h" | 28 #include "chrome/browser/google/google_util.h" |
| 29 #include "chrome/browser/password_manager/password_manager.h" |
| 29 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 30 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 30 #include "chrome/browser/profiles/profile.h" | 31 #include "chrome/browser/profiles/profile.h" |
| 31 #include "chrome/browser/profiles/profile_info_cache.h" | 32 #include "chrome/browser/profiles/profile_info_cache.h" |
| 32 #include "chrome/browser/profiles/profile_io_data.h" | 33 #include "chrome/browser/profiles/profile_io_data.h" |
| 33 #include "chrome/browser/profiles/profile_manager.h" | 34 #include "chrome/browser/profiles/profile_manager.h" |
| 34 #include "chrome/browser/search/search.h" | 35 #include "chrome/browser/search/search.h" |
| 35 #include "chrome/browser/signin/chrome_signin_manager_delegate.h" | 36 #include "chrome/browser/signin/chrome_signin_manager_delegate.h" |
| 36 #include "chrome/browser/signin/signin_global_error.h" | 37 #include "chrome/browser/signin/signin_global_error.h" |
| 37 #include "chrome/browser/signin/signin_manager.h" | 38 #include "chrome/browser/signin/signin_manager.h" |
| 38 #include "chrome/browser/signin/signin_manager_delegate.h" | 39 #include "chrome/browser/signin/signin_manager_delegate.h" |
| 39 #include "chrome/browser/signin/signin_manager_factory.h" | 40 #include "chrome/browser/signin/signin_manager_factory.h" |
| 40 #include "chrome/browser/signin/signin_names_io_thread.h" | 41 #include "chrome/browser/signin/signin_names_io_thread.h" |
| 41 #include "chrome/browser/sync/profile_sync_service.h" | 42 #include "chrome/browser/sync/profile_sync_service.h" |
| 42 #include "chrome/browser/sync/profile_sync_service_factory.h" | 43 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 43 #include "chrome/browser/sync/sync_prefs.h" | 44 #include "chrome/browser/sync/sync_prefs.h" |
| 44 #include "chrome/browser/tab_contents/tab_util.h" | 45 #include "chrome/browser/tab_contents/tab_util.h" |
| 45 #include "chrome/browser/ui/browser_finder.h" | 46 #include "chrome/browser/ui/browser_finder.h" |
| 46 #include "chrome/browser/ui/browser_window.h" | 47 #include "chrome/browser/ui/browser_window.h" |
| 47 #include "chrome/browser/ui/chrome_pages.h" | 48 #include "chrome/browser/ui/chrome_pages.h" |
| 48 #include "chrome/browser/ui/sync/one_click_signin_histogram.h" | 49 #include "chrome/browser/ui/sync/one_click_signin_histogram.h" |
| 49 #include "chrome/browser/ui/sync/one_click_signin_sync_starter.h" | 50 #include "chrome/browser/ui/sync/one_click_signin_sync_starter.h" |
| 50 #include "chrome/browser/ui/sync/signin_histogram.h" | 51 #include "chrome/browser/ui/sync/signin_histogram.h" |
| 51 #include "chrome/browser/ui/tab_modal_confirm_dialog.h" | 52 #include "chrome/browser/ui/tab_modal_confirm_dialog.h" |
| 52 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" | 53 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" |
| 53 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 54 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 54 #include "chrome/common/chrome_switches.h" | 55 #include "chrome/common/chrome_switches.h" |
| 55 #include "chrome/common/chrome_version_info.h" | 56 #include "chrome/common/chrome_version_info.h" |
| 56 #include "chrome/common/net/url_util.h" | 57 #include "chrome/common/net/url_util.h" |
| 57 #include "chrome/common/one_click_signin_messages.h" | |
| 58 #include "chrome/common/pref_names.h" | 58 #include "chrome/common/pref_names.h" |
| 59 #include "chrome/common/url_constants.h" | 59 #include "chrome/common/url_constants.h" |
| 60 #include "content/public/browser/browser_thread.h" | 60 #include "content/public/browser/browser_thread.h" |
| 61 #include "content/public/browser/navigation_entry.h" | 61 #include "content/public/browser/navigation_entry.h" |
| 62 #include "content/public/browser/page_navigator.h" | 62 #include "content/public/browser/page_navigator.h" |
| 63 #include "content/public/browser/render_process_host.h" | 63 #include "content/public/browser/render_process_host.h" |
| 64 #include "content/public/browser/web_contents.h" | 64 #include "content/public/browser/web_contents.h" |
| 65 #include "content/public/browser/web_contents_view.h" | 65 #include "content/public/browser/web_contents_view.h" |
| 66 #include "content/public/common/frame_navigate_params.h" | 66 #include "content/public/common/frame_navigate_params.h" |
| 67 #include "content/public/common/page_transition_types.h" | 67 #include "content/public/common/page_transition_types.h" |
| (...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 } // namespace | 553 } // namespace |
| 554 | 554 |
| 555 | 555 |
| 556 // OneClickSigninHelper ------------------------------------------------------- | 556 // OneClickSigninHelper ------------------------------------------------------- |
| 557 | 557 |
| 558 DEFINE_WEB_CONTENTS_USER_DATA_KEY(OneClickSigninHelper); | 558 DEFINE_WEB_CONTENTS_USER_DATA_KEY(OneClickSigninHelper); |
| 559 | 559 |
| 560 // static | 560 // static |
| 561 const int OneClickSigninHelper::kMaxNavigationsSince = 10; | 561 const int OneClickSigninHelper::kMaxNavigationsSince = 10; |
| 562 | 562 |
| 563 OneClickSigninHelper::OneClickSigninHelper(content::WebContents* web_contents) | 563 OneClickSigninHelper::OneClickSigninHelper(content::WebContents* web_contents, |
| 564 PasswordManager* password_manager) |
| 564 : content::WebContentsObserver(web_contents), | 565 : content::WebContentsObserver(web_contents), |
| 565 showing_signin_(false), | 566 showing_signin_(false), |
| 566 auto_accept_(AUTO_ACCEPT_NONE), | 567 auto_accept_(AUTO_ACCEPT_NONE), |
| 567 source_(signin::SOURCE_UNKNOWN), | 568 source_(signin::SOURCE_UNKNOWN), |
| 568 switched_to_advanced_(false), | 569 switched_to_advanced_(false), |
| 569 untrusted_navigations_since_signin_visit_(0), | 570 untrusted_navigations_since_signin_visit_(0), |
| 570 untrusted_confirmation_required_(false), | 571 untrusted_confirmation_required_(false), |
| 571 do_not_clear_pending_email_(false), | 572 do_not_clear_pending_email_(false), |
| 572 weak_pointer_factory_(this) { | 573 weak_pointer_factory_(this) { |
| 574 // May be NULL during testing. |
| 575 if (password_manager) { |
| 576 password_manager->AddSubmissionCallback( |
| 577 base::Bind(&OneClickSigninHelper::PasswordSubmitted, |
| 578 weak_pointer_factory_.GetWeakPtr())); |
| 579 } |
| 573 } | 580 } |
| 574 | 581 |
| 575 OneClickSigninHelper::~OneClickSigninHelper() { | 582 OneClickSigninHelper::~OneClickSigninHelper() { |
| 576 content::WebContents* contents = web_contents(); | 583 content::WebContents* contents = web_contents(); |
| 577 if (contents) { | 584 if (contents) { |
| 578 Profile* profile = | 585 Profile* profile = |
| 579 Profile::FromBrowserContext(contents->GetBrowserContext()); | 586 Profile::FromBrowserContext(contents->GetBrowserContext()); |
| 580 ProfileSyncService* sync_service = | 587 ProfileSyncService* sync_service = |
| 581 ProfileSyncServiceFactory::GetForProfile(profile); | 588 ProfileSyncServiceFactory::GetForProfile(profile); |
| 582 if (sync_service && sync_service->HasObserver(this)) | 589 if (sync_service && sync_service->HasObserver(this)) |
| 583 sync_service->RemoveObserver(this); | 590 sync_service->RemoveObserver(this); |
| 584 } | 591 } |
| 585 } | 592 } |
| 586 | 593 |
| 587 // static | 594 // static |
| 595 void OneClickSigninHelper::CreateForWebContentsWithPasswordManager( |
| 596 content::WebContents* contents, |
| 597 PasswordManager* password_manager) { |
| 598 if (!FromWebContents(contents)) { |
| 599 contents->SetUserData(UserDataKey(), |
| 600 new OneClickSigninHelper(contents, password_manager)); |
| 601 } |
| 602 } |
| 603 |
| 604 // static |
| 588 bool OneClickSigninHelper::CanOffer(content::WebContents* web_contents, | 605 bool OneClickSigninHelper::CanOffer(content::WebContents* web_contents, |
| 589 CanOfferFor can_offer_for, | 606 CanOfferFor can_offer_for, |
| 590 const std::string& email, | 607 const std::string& email, |
| 591 std::string* error_message) { | 608 std::string* error_message) { |
| 592 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 609 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 593 VLOG(1) << "OneClickSigninHelper::CanOffer"; | 610 VLOG(1) << "OneClickSigninHelper::CanOffer"; |
| 594 | 611 |
| 595 if (error_message) | 612 if (error_message) |
| 596 error_message->clear(); | 613 error_message->clear(); |
| 597 | 614 |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 992 if (!do_not_clear_pending_email_) { | 1009 if (!do_not_clear_pending_email_) { |
| 993 Profile* profile = | 1010 Profile* profile = |
| 994 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 1011 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 995 content::BrowserThread::PostTask( | 1012 content::BrowserThread::PostTask( |
| 996 content::BrowserThread::IO, FROM_HERE, | 1013 content::BrowserThread::IO, FROM_HERE, |
| 997 base::Bind(&ClearPendingEmailOnIOThread, | 1014 base::Bind(&ClearPendingEmailOnIOThread, |
| 998 base::Unretained(profile->GetResourceContext()))); | 1015 base::Unretained(profile->GetResourceContext()))); |
| 999 } | 1016 } |
| 1000 } | 1017 } |
| 1001 | 1018 |
| 1002 bool OneClickSigninHelper::OnMessageReceived(const IPC::Message& message) { | 1019 void OneClickSigninHelper::PasswordSubmitted( |
| 1003 bool handled = true; | 1020 const content::PasswordForm& form) { |
| 1004 IPC_BEGIN_MESSAGE_MAP(OneClickSigninHelper, message) | |
| 1005 IPC_MESSAGE_HANDLER(OneClickSigninHostMsg_FormSubmitted, OnFormSubmitted) | |
| 1006 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 1007 IPC_END_MESSAGE_MAP() | |
| 1008 | |
| 1009 return handled; | |
| 1010 } | |
| 1011 | |
| 1012 bool OneClickSigninHelper::OnFormSubmitted(const content::PasswordForm& form) { | |
| 1013 // |password_| used to be set in DidNavigateAnyFrame, this is too late because | |
| 1014 // it is not executed until the end of redirect chains and password may | |
| 1015 // get lost if one of the redirects requires context swap. | |
| 1016 | |
| 1017 // We only need to scrape the password for Gaia logins. | 1021 // We only need to scrape the password for Gaia logins. |
| 1018 if (form.origin.is_valid() && | 1022 if (gaia::IsGaiaSignonRealm(GURL(form.signon_realm))) { |
| 1019 gaia::IsGaiaSignonRealm(GURL(form.signon_realm))) { | |
| 1020 VLOG(1) << "OneClickSigninHelper::DidNavigateAnyFrame: got password"; | 1023 VLOG(1) << "OneClickSigninHelper::DidNavigateAnyFrame: got password"; |
| 1021 password_ = UTF16ToUTF8(form.password_value); | 1024 password_ = UTF16ToUTF8(form.password_value); |
| 1022 } | 1025 } |
| 1023 | |
| 1024 return true; | |
| 1025 } | 1026 } |
| 1026 | 1027 |
| 1027 void OneClickSigninHelper::SetDoNotClearPendingEmailForTesting() { | 1028 void OneClickSigninHelper::SetDoNotClearPendingEmailForTesting() { |
| 1028 do_not_clear_pending_email_ = true; | 1029 do_not_clear_pending_email_ = true; |
| 1029 } | 1030 } |
| 1030 | 1031 |
| 1031 void OneClickSigninHelper::NavigateToPendingEntry( | 1032 void OneClickSigninHelper::NavigateToPendingEntry( |
| 1032 const GURL& url, | 1033 const GURL& url, |
| 1033 content::NavigationController::ReloadType reload_type) { | 1034 content::NavigationController::ReloadType reload_type) { |
| 1034 VLOG(1) << "OneClickSigninHelper::NavigateToPendingEntry: url=" << url.spec(); | 1035 VLOG(1) << "OneClickSigninHelper::NavigateToPendingEntry: url=" << url.spec(); |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1389 // If the web contents is showing a blank page and not about to be closed, | 1390 // If the web contents is showing a blank page and not about to be closed, |
| 1390 // redirect to the NTP or apps page. | 1391 // redirect to the NTP or apps page. |
| 1391 if (signin::IsContinueUrlForWebBasedSigninFlow(current_url) && | 1392 if (signin::IsContinueUrlForWebBasedSigninFlow(current_url) && |
| 1392 !signin::IsAutoCloseEnabledInURL(original_continue_url_)) { | 1393 !signin::IsAutoCloseEnabledInURL(original_continue_url_)) { |
| 1393 RedirectToNtpOrAppsPage( | 1394 RedirectToNtpOrAppsPage( |
| 1394 web_contents(), | 1395 web_contents(), |
| 1395 signin::GetSourceForPromoURL(original_continue_url_)); | 1396 signin::GetSourceForPromoURL(original_continue_url_)); |
| 1396 } | 1397 } |
| 1397 } | 1398 } |
| 1398 } | 1399 } |
| OLD | NEW |