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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 #include "chrome/browser/ui/chrome_pages.h" | 46 #include "chrome/browser/ui/chrome_pages.h" |
47 #include "chrome/browser/ui/sync/one_click_signin_histogram.h" | 47 #include "chrome/browser/ui/sync/one_click_signin_histogram.h" |
48 #include "chrome/browser/ui/sync/one_click_signin_sync_starter.h" | 48 #include "chrome/browser/ui/sync/one_click_signin_sync_starter.h" |
49 #include "chrome/browser/ui/sync/signin_histogram.h" | 49 #include "chrome/browser/ui/sync/signin_histogram.h" |
50 #include "chrome/browser/ui/tab_modal_confirm_dialog.h" | 50 #include "chrome/browser/ui/tab_modal_confirm_dialog.h" |
51 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" | 51 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" |
52 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 52 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
53 #include "chrome/common/chrome_switches.h" | 53 #include "chrome/common/chrome_switches.h" |
54 #include "chrome/common/chrome_version_info.h" | 54 #include "chrome/common/chrome_version_info.h" |
55 #include "chrome/common/net/url_util.h" | 55 #include "chrome/common/net/url_util.h" |
56 #include "chrome/common/one_click_signin_messages.h" | |
57 #include "chrome/common/pref_names.h" | 56 #include "chrome/common/pref_names.h" |
58 #include "chrome/common/url_constants.h" | 57 #include "chrome/common/url_constants.h" |
59 #include "content/public/browser/browser_thread.h" | 58 #include "content/public/browser/browser_thread.h" |
60 #include "content/public/browser/navigation_entry.h" | 59 #include "content/public/browser/navigation_entry.h" |
61 #include "content/public/browser/page_navigator.h" | 60 #include "content/public/browser/page_navigator.h" |
62 #include "content/public/browser/render_process_host.h" | 61 #include "content/public/browser/render_process_host.h" |
63 #include "content/public/browser/web_contents.h" | 62 #include "content/public/browser/web_contents.h" |
64 #include "content/public/browser/web_contents_view.h" | 63 #include "content/public/browser/web_contents_view.h" |
65 #include "content/public/common/frame_navigate_params.h" | 64 #include "content/public/common/frame_navigate_params.h" |
66 #include "content/public/common/page_transition_types.h" | 65 #include "content/public/common/page_transition_types.h" |
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
544 } // namespace | 543 } // namespace |
545 | 544 |
546 | 545 |
547 // OneClickSigninHelper ------------------------------------------------------- | 546 // OneClickSigninHelper ------------------------------------------------------- |
548 | 547 |
549 DEFINE_WEB_CONTENTS_USER_DATA_KEY(OneClickSigninHelper); | 548 DEFINE_WEB_CONTENTS_USER_DATA_KEY(OneClickSigninHelper); |
550 | 549 |
551 // static | 550 // static |
552 const int OneClickSigninHelper::kMaxNavigationsSince = 10; | 551 const int OneClickSigninHelper::kMaxNavigationsSince = 10; |
553 | 552 |
554 OneClickSigninHelper::OneClickSigninHelper(content::WebContents* web_contents) | 553 OneClickSigninHelper::OneClickSigninHelper(content::WebContents* web_contents, |
554 PasswordManager* password_manager) | |
555 : content::WebContentsObserver(web_contents), | 555 : content::WebContentsObserver(web_contents), |
556 showing_signin_(false), | 556 showing_signin_(false), |
557 auto_accept_(AUTO_ACCEPT_NONE), | 557 auto_accept_(AUTO_ACCEPT_NONE), |
558 source_(SyncPromoUI::SOURCE_UNKNOWN), | 558 source_(SyncPromoUI::SOURCE_UNKNOWN), |
559 switched_to_advanced_(false), | 559 switched_to_advanced_(false), |
560 original_source_(SyncPromoUI::SOURCE_UNKNOWN), | 560 original_source_(SyncPromoUI::SOURCE_UNKNOWN), |
561 untrusted_navigations_since_signin_visit_(0), | 561 untrusted_navigations_since_signin_visit_(0), |
562 untrusted_confirmation_required_(false), | 562 untrusted_confirmation_required_(false), |
563 do_not_clear_pending_email_(false) { | 563 do_not_clear_pending_email_(false), |
564 password_callback_(base::Bind(&OneClickSigninHelper::PasswordSubmitted, | |
565 base::Unretained(this))) { | |
Ilya Sherman
2013/07/27 01:09:48
Why is base::Unretained() safe here?
Garrett Casto
2013/08/03 00:38:42
Yes, for the same reason as the PrerenderTabHelper
| |
566 if (password_manager) | |
567 password_manager->AddSubmissionCallback(password_callback_); | |
564 } | 568 } |
565 | 569 |
566 OneClickSigninHelper::~OneClickSigninHelper() { | 570 OneClickSigninHelper::~OneClickSigninHelper() { |
567 content::WebContents* contents = web_contents(); | 571 content::WebContents* contents = web_contents(); |
568 if (contents) { | 572 if (contents) { |
569 Profile* profile = | 573 Profile* profile = |
570 Profile::FromBrowserContext(contents->GetBrowserContext()); | 574 Profile::FromBrowserContext(contents->GetBrowserContext()); |
571 ProfileSyncService* sync_service = | 575 ProfileSyncService* sync_service = |
572 ProfileSyncServiceFactory::GetForProfile(profile); | 576 ProfileSyncServiceFactory::GetForProfile(profile); |
573 if (sync_service && sync_service->HasObserver(this)) | 577 if (sync_service && sync_service->HasObserver(this)) |
574 sync_service->RemoveObserver(this); | 578 sync_service->RemoveObserver(this); |
575 } | 579 } |
576 } | 580 } |
577 | 581 |
578 // static | 582 // static |
583 void OneClickSigninHelper::CreateForWebContentsWithPasswordManager( | |
584 content::WebContents* contents, | |
585 PasswordManager* password_manager) { | |
586 if (!FromWebContents(contents)) { | |
587 contents->SetUserData(UserDataKey(), | |
588 new OneClickSigninHelper(contents, password_manager)); | |
589 } | |
590 } | |
591 | |
592 // static | |
579 bool OneClickSigninHelper::CanOffer(content::WebContents* web_contents, | 593 bool OneClickSigninHelper::CanOffer(content::WebContents* web_contents, |
580 CanOfferFor can_offer_for, | 594 CanOfferFor can_offer_for, |
581 const std::string& email, | 595 const std::string& email, |
582 std::string* error_message) { | 596 std::string* error_message) { |
583 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 597 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
584 VLOG(1) << "OneClickSigninHelper::CanOffer"; | 598 VLOG(1) << "OneClickSigninHelper::CanOffer"; |
585 | 599 |
586 if (error_message) | 600 if (error_message) |
587 error_message->clear(); | 601 error_message->clear(); |
588 | 602 |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
978 if (!do_not_clear_pending_email_) { | 992 if (!do_not_clear_pending_email_) { |
979 Profile* profile = | 993 Profile* profile = |
980 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 994 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
981 content::BrowserThread::PostTask( | 995 content::BrowserThread::PostTask( |
982 content::BrowserThread::IO, FROM_HERE, | 996 content::BrowserThread::IO, FROM_HERE, |
983 base::Bind(&ClearPendingEmailOnIOThread, | 997 base::Bind(&ClearPendingEmailOnIOThread, |
984 base::Unretained(profile->GetResourceContext()))); | 998 base::Unretained(profile->GetResourceContext()))); |
985 } | 999 } |
986 } | 1000 } |
987 | 1001 |
988 bool OneClickSigninHelper::OnMessageReceived(const IPC::Message& message) { | 1002 void OneClickSigninHelper::PasswordSubmitted( |
989 bool handled = true; | 1003 const content::PasswordForm& form) { |
990 IPC_BEGIN_MESSAGE_MAP(OneClickSigninHelper, message) | |
991 IPC_MESSAGE_HANDLER(OneClickSigninHostMsg_FormSubmitted, OnFormSubmitted) | |
992 IPC_MESSAGE_UNHANDLED(handled = false) | |
993 IPC_END_MESSAGE_MAP() | |
994 | |
995 return handled; | |
996 } | |
997 | |
998 bool OneClickSigninHelper::OnFormSubmitted(const content::PasswordForm& form) { | |
999 // |password_| used to be set in DidNavigateAnyFrame, this is too late because | 1004 // |password_| used to be set in DidNavigateAnyFrame, this is too late because |
1000 // it is not executed until the end of redirect chains and password may | 1005 // it is not executed until the end of redirect chains and password may |
1001 // get lost if one of the redirects requires context swap. | 1006 // get lost if one of the redirects requires context swap. |
Ilya Sherman
2013/07/27 01:09:48
nit: Is this comment still relevant? If so, shoul
Garrett Casto
2013/08/03 00:38:42
I kept the gist of this in password manager code.
| |
1002 | 1007 |
1003 // We only need to scrape the password for Gaia logins. | 1008 // We only need to scrape the password for Gaia logins. |
1004 if (form.origin.is_valid() && | 1009 if (gaia::IsGaiaSignonRealm(GURL(form.signon_realm))) { |
1005 gaia::IsGaiaSignonRealm(GURL(form.signon_realm))) { | |
1006 VLOG(1) << "OneClickSigninHelper::DidNavigateAnyFrame: got password"; | 1010 VLOG(1) << "OneClickSigninHelper::DidNavigateAnyFrame: got password"; |
1007 password_ = UTF16ToUTF8(form.password_value); | 1011 password_ = UTF16ToUTF8(form.password_value); |
1008 } | 1012 } |
1009 | |
1010 return true; | |
1011 } | 1013 } |
1012 | 1014 |
1013 void OneClickSigninHelper::SetDoNotClearPendingEmailForTesting() { | 1015 void OneClickSigninHelper::SetDoNotClearPendingEmailForTesting() { |
1014 do_not_clear_pending_email_ = true; | 1016 do_not_clear_pending_email_ = true; |
1015 } | 1017 } |
1016 | 1018 |
1017 void OneClickSigninHelper::NavigateToPendingEntry( | 1019 void OneClickSigninHelper::NavigateToPendingEntry( |
1018 const GURL& url, | 1020 const GURL& url, |
1019 content::NavigationController::ReloadType reload_type) { | 1021 content::NavigationController::ReloadType reload_type) { |
1020 VLOG(1) << "OneClickSigninHelper::NavigateToPendingEntry: url=" << url.spec(); | 1022 VLOG(1) << "OneClickSigninHelper::NavigateToPendingEntry: url=" << url.spec(); |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1337 content::Referrer(), | 1339 content::Referrer(), |
1338 content::PAGE_TRANSITION_AUTO_TOPLEVEL, | 1340 content::PAGE_TRANSITION_AUTO_TOPLEVEL, |
1339 std::string()); | 1341 std::string()); |
1340 } | 1342 } |
1341 } | 1343 } |
1342 | 1344 |
1343 // Clear the redirect URL. | 1345 // Clear the redirect URL. |
1344 redirect_url_ = GURL(); | 1346 redirect_url_ = GURL(); |
1345 sync_service->RemoveObserver(this); | 1347 sync_service->RemoveObserver(this); |
1346 } | 1348 } |
OLD | NEW |