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 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 // We have to delay the cleaning until the new URL has finished loading because | 469 // We have to delay the cleaning until the new URL has finished loading because |
470 // we're not allowed to remove the last-loaded URL from the history. Objects | 470 // we're not allowed to remove the last-loaded URL from the history. Objects |
471 // of this type automatically self-destruct once they're finished their work. | 471 // of this type automatically self-destruct once they're finished their work. |
472 class CurrentHistoryCleaner : public content::WebContentsObserver { | 472 class CurrentHistoryCleaner : public content::WebContentsObserver { |
473 public: | 473 public: |
474 explicit CurrentHistoryCleaner(content::WebContents* contents); | 474 explicit CurrentHistoryCleaner(content::WebContents* contents); |
475 virtual ~CurrentHistoryCleaner(); | 475 virtual ~CurrentHistoryCleaner(); |
476 | 476 |
477 // content::WebContentsObserver: | 477 // content::WebContentsObserver: |
478 virtual void WebContentsDestroyed(content::WebContents* contents) OVERRIDE; | 478 virtual void WebContentsDestroyed(content::WebContents* contents) OVERRIDE; |
479 virtual void DidStopLoading( | 479 virtual void DidCommitProvisionalLoadForFrame( |
| 480 int64 frame_id, |
| 481 bool is_main_frame, |
| 482 const GURL& url, |
| 483 content::PageTransition transition_type, |
480 content::RenderViewHost* render_view_host) OVERRIDE; | 484 content::RenderViewHost* render_view_host) OVERRIDE; |
481 | 485 |
482 private: | 486 private: |
483 scoped_ptr<content::WebContents> contents_; | 487 scoped_ptr<content::WebContents> contents_; |
484 int history_index_to_remove_; | 488 int history_index_to_remove_; |
485 | 489 |
486 DISALLOW_COPY_AND_ASSIGN(CurrentHistoryCleaner); | 490 DISALLOW_COPY_AND_ASSIGN(CurrentHistoryCleaner); |
487 }; | 491 }; |
488 | 492 |
489 CurrentHistoryCleaner::CurrentHistoryCleaner(content::WebContents* contents) | 493 CurrentHistoryCleaner::CurrentHistoryCleaner(content::WebContents* contents) |
490 : WebContentsObserver(contents) { | 494 : WebContentsObserver(contents) { |
491 history_index_to_remove_ = | 495 history_index_to_remove_ = |
492 web_contents()->GetController().GetLastCommittedEntryIndex(); | 496 web_contents()->GetController().GetLastCommittedEntryIndex(); |
493 } | 497 } |
494 | 498 |
495 CurrentHistoryCleaner::~CurrentHistoryCleaner() { | 499 CurrentHistoryCleaner::~CurrentHistoryCleaner() { |
496 } | 500 } |
497 | 501 |
498 void CurrentHistoryCleaner::DidStopLoading( | 502 void CurrentHistoryCleaner::DidCommitProvisionalLoadForFrame( |
| 503 int64 frame_id, |
| 504 bool is_main_frame, |
| 505 const GURL& url, |
| 506 content::PageTransition transition_type, |
499 content::RenderViewHost* render_view_host) { | 507 content::RenderViewHost* render_view_host) { |
| 508 // Return early if this is not top-level navigation. |
| 509 if (!is_main_frame) |
| 510 return; |
| 511 |
500 content::NavigationController* nc = &web_contents()->GetController(); | 512 content::NavigationController* nc = &web_contents()->GetController(); |
| 513 |
501 // Have to wait until something else gets added to history before removal. | 514 // Have to wait until something else gets added to history before removal. |
502 if (history_index_to_remove_ < nc->GetLastCommittedEntryIndex()) { | 515 if (history_index_to_remove_ < nc->GetLastCommittedEntryIndex()) { |
503 nc->RemoveEntryAtIndex(history_index_to_remove_); | 516 content::NavigationEntry* entry = |
504 delete this; // Success. | 517 nc->GetEntryAtIndex(history_index_to_remove_); |
| 518 if (SyncPromoUI::IsContinueUrlForWebBasedSigninFlow(entry->GetURL()) && |
| 519 nc->RemoveEntryAtIndex(history_index_to_remove_)) { |
| 520 delete this; // Success. |
| 521 } |
505 } | 522 } |
506 } | 523 } |
507 | 524 |
508 void CurrentHistoryCleaner::WebContentsDestroyed( | 525 void CurrentHistoryCleaner::WebContentsDestroyed( |
509 content::WebContents* contents) { | 526 content::WebContents* contents) { |
510 delete this; // Failure. | 527 delete this; // Failure. |
511 } | 528 } |
512 | 529 |
513 void CloseTab(content::WebContents* tab) { | 530 void CloseTab(content::WebContents* tab) { |
514 Browser* browser = chrome::FindBrowserWithWebContents(tab); | 531 Browser* browser = chrome::FindBrowserWithWebContents(tab); |
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
899 helper->email_ = email; | 916 helper->email_ = email; |
900 | 917 |
901 if (continue_url.is_valid()) | 918 if (continue_url.is_valid()) |
902 helper->continue_url_ = continue_url; | 919 helper->continue_url_ = continue_url; |
903 } | 920 } |
904 | 921 |
905 // static | 922 // static |
906 void OneClickSigninHelper::RemoveSigninRedirectURLHistoryItem( | 923 void OneClickSigninHelper::RemoveSigninRedirectURLHistoryItem( |
907 content::WebContents* web_contents) { | 924 content::WebContents* web_contents) { |
908 // Only actually remove the item if it's the blank.html continue url. | 925 // Only actually remove the item if it's the blank.html continue url. |
909 if (SyncPromoUI::IsContinueUrlForWebBasedSigninFlow(web_contents->GetURL())) | 926 if (SyncPromoUI::IsContinueUrlForWebBasedSigninFlow( |
| 927 web_contents->GetLastCommittedURL())) { |
910 new CurrentHistoryCleaner(web_contents); // will self-destruct when done | 928 new CurrentHistoryCleaner(web_contents); // will self-destruct when done |
| 929 } |
911 } | 930 } |
912 | 931 |
913 void OneClickSigninHelper::ShowSigninErrorBubble(Browser* browser, | 932 void OneClickSigninHelper::ShowSigninErrorBubble(Browser* browser, |
914 const std::string& error) { | 933 const std::string& error) { |
915 DCHECK(!error.empty()); | 934 DCHECK(!error.empty()); |
916 | 935 |
917 browser->window()->ShowOneClickSigninBubble( | 936 browser->window()->ShowOneClickSigninBubble( |
918 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE, | 937 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE, |
919 string16(), /* no SAML email */ | 938 string16(), /* no SAML email */ |
920 UTF8ToUTF16(error), | 939 UTF8ToUTF16(error), |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1034 if (manager && manager->IsSigninProcess(process_id)) | 1053 if (manager && manager->IsSigninProcess(process_id)) |
1035 manager->ClearSigninProcess(); | 1054 manager->ClearSigninProcess(); |
1036 } | 1055 } |
1037 } | 1056 } |
1038 | 1057 |
1039 void OneClickSigninHelper::DidStopLoading( | 1058 void OneClickSigninHelper::DidStopLoading( |
1040 content::RenderViewHost* render_view_host) { | 1059 content::RenderViewHost* render_view_host) { |
1041 // If the user left the sign in process, clear all members. | 1060 // If the user left the sign in process, clear all members. |
1042 // TODO(rogerta): might need to allow some youtube URLs. | 1061 // TODO(rogerta): might need to allow some youtube URLs. |
1043 content::WebContents* contents = web_contents(); | 1062 content::WebContents* contents = web_contents(); |
1044 const GURL url = contents->GetURL(); | 1063 const GURL url = contents->GetLastCommittedURL(); |
1045 Profile* profile = | 1064 Profile* profile = |
1046 Profile::FromBrowserContext(contents->GetBrowserContext()); | 1065 Profile::FromBrowserContext(contents->GetBrowserContext()); |
1047 VLOG(1) << "OneClickSigninHelper::DidStopLoading: url=" << url.spec(); | 1066 VLOG(1) << "OneClickSigninHelper::DidStopLoading: url=" << url.spec(); |
1048 | 1067 |
1049 // If an error has already occured during the sign in flow, make sure to | 1068 // If an error has already occured during the sign in flow, make sure to |
1050 // display it to the user and abort the process. Do this only for | 1069 // display it to the user and abort the process. Do this only for |
1051 // explicit sign ins. | 1070 // explicit sign ins. |
1052 // TODO(rogerta): Could we move this code back up to ShowInfoBarUIThread()? | 1071 // TODO(rogerta): Could we move this code back up to ShowInfoBarUIThread()? |
1053 if (!error_message_.empty() && auto_accept_ == AUTO_ACCEPT_EXPLICIT) { | 1072 if (!error_message_.empty() && auto_accept_ == AUTO_ACCEPT_EXPLICIT) { |
1054 VLOG(1) << "OneClickSigninHelper::DidStopLoading: error=" << error_message_; | 1073 VLOG(1) << "OneClickSigninHelper::DidStopLoading: error=" << error_message_; |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1318 content::Referrer(), | 1337 content::Referrer(), |
1319 content::PAGE_TRANSITION_AUTO_TOPLEVEL, | 1338 content::PAGE_TRANSITION_AUTO_TOPLEVEL, |
1320 std::string()); | 1339 std::string()); |
1321 } | 1340 } |
1322 } | 1341 } |
1323 | 1342 |
1324 // Clear the redirect URL. | 1343 // Clear the redirect URL. |
1325 redirect_url_ = GURL(); | 1344 redirect_url_ = GURL(); |
1326 sync_service->RemoveObserver(this); | 1345 sync_service->RemoveObserver(this); |
1327 } | 1346 } |
OLD | NEW |