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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 #include "components/signin/core/common/profile_management_switches.h" | 72 #include "components/signin/core/common/profile_management_switches.h" |
73 #include "components/sync_driver/sync_prefs.h" | 73 #include "components/sync_driver/sync_prefs.h" |
74 #include "content/public/browser/browser_thread.h" | 74 #include "content/public/browser/browser_thread.h" |
75 #include "content/public/browser/navigation_entry.h" | 75 #include "content/public/browser/navigation_entry.h" |
76 #include "content/public/browser/page_navigator.h" | 76 #include "content/public/browser/page_navigator.h" |
77 #include "content/public/browser/render_frame_host.h" | 77 #include "content/public/browser/render_frame_host.h" |
78 #include "content/public/browser/render_process_host.h" | 78 #include "content/public/browser/render_process_host.h" |
79 #include "content/public/browser/web_contents.h" | 79 #include "content/public/browser/web_contents.h" |
80 #include "content/public/browser/web_contents_delegate.h" | 80 #include "content/public/browser/web_contents_delegate.h" |
81 #include "content/public/common/frame_navigate_params.h" | 81 #include "content/public/common/frame_navigate_params.h" |
82 #include "content/public/common/page_transition_types.h" | |
83 #include "google_apis/gaia/gaia_auth_util.h" | 82 #include "google_apis/gaia/gaia_auth_util.h" |
84 #include "google_apis/gaia/gaia_urls.h" | 83 #include "google_apis/gaia/gaia_urls.h" |
85 #include "grit/components_strings.h" | 84 #include "grit/components_strings.h" |
86 #include "ipc/ipc_message_macros.h" | 85 #include "ipc/ipc_message_macros.h" |
87 #include "net/base/url_util.h" | 86 #include "net/base/url_util.h" |
88 #include "net/cookies/cookie_monster.h" | 87 #include "net/cookies/cookie_monster.h" |
89 #include "net/url_request/url_request.h" | 88 #include "net/url_request/url_request.h" |
90 #include "ui/base/l10n/l10n_util.h" | 89 #include "ui/base/l10n/l10n_util.h" |
| 90 #include "ui/base/page_transition_types.h" |
91 #include "url/gurl.h" | 91 #include "url/gurl.h" |
92 | 92 |
93 | 93 |
94 namespace { | 94 namespace { |
95 | 95 |
96 // ConfirmEmailDialogDelegate ------------------------------------------------- | 96 // ConfirmEmailDialogDelegate ------------------------------------------------- |
97 | 97 |
98 class ConfirmEmailDialogDelegate : public TabModalConfirmDialogDelegate { | 98 class ConfirmEmailDialogDelegate : public TabModalConfirmDialogDelegate { |
99 public: | 99 public: |
100 enum Action { | 100 enum Action { |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 void ConfirmEmailDialogDelegate::OnClosed() { | 202 void ConfirmEmailDialogDelegate::OnClosed() { |
203 base::ResetAndReturn(&callback_).Run(CLOSE); | 203 base::ResetAndReturn(&callback_).Run(CLOSE); |
204 } | 204 } |
205 | 205 |
206 void ConfirmEmailDialogDelegate::OnLinkClicked( | 206 void ConfirmEmailDialogDelegate::OnLinkClicked( |
207 WindowOpenDisposition disposition) { | 207 WindowOpenDisposition disposition) { |
208 content::OpenURLParams params( | 208 content::OpenURLParams params( |
209 GURL(chrome::kChromeSyncMergeTroubleshootingURL), | 209 GURL(chrome::kChromeSyncMergeTroubleshootingURL), |
210 content::Referrer(), | 210 content::Referrer(), |
211 NEW_POPUP, | 211 NEW_POPUP, |
212 content::PAGE_TRANSITION_AUTO_TOPLEVEL, | 212 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
213 false); | 213 false); |
214 // It is guaranteed that |web_contents_| is valid here because when it's | 214 // It is guaranteed that |web_contents_| is valid here because when it's |
215 // deleted, the dialog is immediately closed and no further action can be | 215 // deleted, the dialog is immediately closed and no further action can be |
216 // performed. | 216 // performed. |
217 web_contents_->OpenURL(params); | 217 web_contents_->OpenURL(params); |
218 } | 218 } |
219 | 219 |
220 | 220 |
221 // Helpers -------------------------------------------------------------------- | 221 // Helpers -------------------------------------------------------------------- |
222 | 222 |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 class CurrentHistoryCleaner : public content::WebContentsObserver { | 436 class CurrentHistoryCleaner : public content::WebContentsObserver { |
437 public: | 437 public: |
438 explicit CurrentHistoryCleaner(content::WebContents* contents); | 438 explicit CurrentHistoryCleaner(content::WebContents* contents); |
439 virtual ~CurrentHistoryCleaner(); | 439 virtual ~CurrentHistoryCleaner(); |
440 | 440 |
441 // content::WebContentsObserver: | 441 // content::WebContentsObserver: |
442 virtual void WebContentsDestroyed() OVERRIDE; | 442 virtual void WebContentsDestroyed() OVERRIDE; |
443 virtual void DidCommitProvisionalLoadForFrame( | 443 virtual void DidCommitProvisionalLoadForFrame( |
444 content::RenderFrameHost* render_frame_host, | 444 content::RenderFrameHost* render_frame_host, |
445 const GURL& url, | 445 const GURL& url, |
446 content::PageTransition transition_type) OVERRIDE; | 446 ui::PageTransition transition_type) OVERRIDE; |
447 | 447 |
448 private: | 448 private: |
449 scoped_ptr<content::WebContents> contents_; | 449 scoped_ptr<content::WebContents> contents_; |
450 int history_index_to_remove_; | 450 int history_index_to_remove_; |
451 | 451 |
452 DISALLOW_COPY_AND_ASSIGN(CurrentHistoryCleaner); | 452 DISALLOW_COPY_AND_ASSIGN(CurrentHistoryCleaner); |
453 }; | 453 }; |
454 | 454 |
455 CurrentHistoryCleaner::CurrentHistoryCleaner(content::WebContents* contents) | 455 CurrentHistoryCleaner::CurrentHistoryCleaner(content::WebContents* contents) |
456 : WebContentsObserver(contents) { | 456 : WebContentsObserver(contents) { |
457 history_index_to_remove_ = | 457 history_index_to_remove_ = |
458 web_contents()->GetController().GetLastCommittedEntryIndex(); | 458 web_contents()->GetController().GetLastCommittedEntryIndex(); |
459 } | 459 } |
460 | 460 |
461 CurrentHistoryCleaner::~CurrentHistoryCleaner() { | 461 CurrentHistoryCleaner::~CurrentHistoryCleaner() { |
462 } | 462 } |
463 | 463 |
464 void CurrentHistoryCleaner::DidCommitProvisionalLoadForFrame( | 464 void CurrentHistoryCleaner::DidCommitProvisionalLoadForFrame( |
465 content::RenderFrameHost* render_frame_host, | 465 content::RenderFrameHost* render_frame_host, |
466 const GURL& url, | 466 const GURL& url, |
467 content::PageTransition transition_type) { | 467 ui::PageTransition transition_type) { |
468 // Return early if this is not top-level navigation. | 468 // Return early if this is not top-level navigation. |
469 if (render_frame_host->GetParent()) | 469 if (render_frame_host->GetParent()) |
470 return; | 470 return; |
471 | 471 |
472 content::NavigationController* nc = &web_contents()->GetController(); | 472 content::NavigationController* nc = &web_contents()->GetController(); |
473 HistoryService* hs = HistoryServiceFactory::GetForProfile( | 473 HistoryService* hs = HistoryServiceFactory::GetForProfile( |
474 Profile::FromBrowserContext(web_contents()->GetBrowserContext()), | 474 Profile::FromBrowserContext(web_contents()->GetBrowserContext()), |
475 Profile::IMPLICIT_ACCESS); | 475 Profile::IMPLICIT_ACCESS); |
476 | 476 |
477 // Have to wait until something else gets added to history before removal. | 477 // Have to wait until something else gets added to history before removal. |
(...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1197 if (contents->GetController().GetPendingEntry()) | 1197 if (contents->GetController().GetPendingEntry()) |
1198 return; | 1198 return; |
1199 | 1199 |
1200 VLOG(1) << "RedirectToNtpOrAppsPage"; | 1200 VLOG(1) << "RedirectToNtpOrAppsPage"; |
1201 // Redirect to NTP/Apps page and display a confirmation bubble | 1201 // Redirect to NTP/Apps page and display a confirmation bubble |
1202 GURL url(source == signin::SOURCE_APPS_PAGE_LINK ? | 1202 GURL url(source == signin::SOURCE_APPS_PAGE_LINK ? |
1203 chrome::kChromeUIAppsURL : chrome::kChromeUINewTabURL); | 1203 chrome::kChromeUIAppsURL : chrome::kChromeUINewTabURL); |
1204 content::OpenURLParams params(url, | 1204 content::OpenURLParams params(url, |
1205 content::Referrer(), | 1205 content::Referrer(), |
1206 CURRENT_TAB, | 1206 CURRENT_TAB, |
1207 content::PAGE_TRANSITION_AUTO_TOPLEVEL, | 1207 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
1208 false); | 1208 false); |
1209 contents->OpenURL(params); | 1209 contents->OpenURL(params); |
1210 } | 1210 } |
1211 | 1211 |
1212 // static | 1212 // static |
1213 void OneClickSigninHelper::RedirectToNtpOrAppsPageIfNecessary( | 1213 void OneClickSigninHelper::RedirectToNtpOrAppsPageIfNecessary( |
1214 content::WebContents* contents, signin::Source source) { | 1214 content::WebContents* contents, signin::Source source) { |
1215 if (source != signin::SOURCE_SETTINGS && | 1215 if (source != signin::SOURCE_SETTINGS && |
1216 source != signin::SOURCE_WEBSTORE_INSTALL) { | 1216 source != signin::SOURCE_WEBSTORE_INSTALL) { |
1217 RedirectToNtpOrAppsPage(contents, source); | 1217 RedirectToNtpOrAppsPage(contents, source); |
1218 } | 1218 } |
1219 } | 1219 } |
1220 | 1220 |
1221 void OneClickSigninHelper::RedirectToSignin() { | 1221 void OneClickSigninHelper::RedirectToSignin() { |
1222 VLOG(1) << "OneClickSigninHelper::RedirectToSignin"; | 1222 VLOG(1) << "OneClickSigninHelper::RedirectToSignin"; |
1223 | 1223 |
1224 // Extract the existing sounce=X value. Default to "2" if missing. | 1224 // Extract the existing sounce=X value. Default to "2" if missing. |
1225 signin::Source source = signin::GetSourceForPromoURL(continue_url_); | 1225 signin::Source source = signin::GetSourceForPromoURL(continue_url_); |
1226 if (source == signin::SOURCE_UNKNOWN) | 1226 if (source == signin::SOURCE_UNKNOWN) |
1227 source = signin::SOURCE_MENU; | 1227 source = signin::SOURCE_MENU; |
1228 GURL page = signin::GetPromoURL(source, false); | 1228 GURL page = signin::GetPromoURL(source, false); |
1229 | 1229 |
1230 content::WebContents* contents = web_contents(); | 1230 content::WebContents* contents = web_contents(); |
1231 contents->GetController().LoadURL(page, | 1231 contents->GetController().LoadURL(page, |
1232 content::Referrer(), | 1232 content::Referrer(), |
1233 content::PAGE_TRANSITION_AUTO_TOPLEVEL, | 1233 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
1234 std::string()); | 1234 std::string()); |
1235 } | 1235 } |
1236 | 1236 |
1237 void OneClickSigninHelper::CleanTransientState() { | 1237 void OneClickSigninHelper::CleanTransientState() { |
1238 VLOG(1) << "OneClickSigninHelper::CleanTransientState"; | 1238 VLOG(1) << "OneClickSigninHelper::CleanTransientState"; |
1239 showing_signin_ = false; | 1239 showing_signin_ = false; |
1240 email_.clear(); | 1240 email_.clear(); |
1241 password_.clear(); | 1241 password_.clear(); |
1242 auto_accept_ = AUTO_ACCEPT_NONE; | 1242 auto_accept_ = AUTO_ACCEPT_NONE; |
1243 source_ = signin::SOURCE_UNKNOWN; | 1243 source_ = signin::SOURCE_UNKNOWN; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1307 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 1307 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
1308 SigninClient* signin_client = | 1308 SigninClient* signin_client = |
1309 profile ? ChromeSigninClientFactory::GetForProfile(profile) : NULL; | 1309 profile ? ChromeSigninClientFactory::GetForProfile(profile) : NULL; |
1310 int process_id = web_contents()->GetRenderProcessHost()->GetID(); | 1310 int process_id = web_contents()->GetRenderProcessHost()->GetID(); |
1311 if (signin_client && signin_client->IsSigninProcess(process_id)) | 1311 if (signin_client && signin_client->IsSigninProcess(process_id)) |
1312 signin_client->ClearSigninProcess(); | 1312 signin_client->ClearSigninProcess(); |
1313 | 1313 |
1314 // If the navigation to a non-sign-in URL hasn't been triggered by the web | 1314 // If the navigation to a non-sign-in URL hasn't been triggered by the web |
1315 // contents, the sign in flow has been aborted and the state must be | 1315 // contents, the sign in flow has been aborted and the state must be |
1316 // cleaned (crbug.com/269421). | 1316 // cleaned (crbug.com/269421). |
1317 if (!content::PageTransitionIsWebTriggerable(params.transition) && | 1317 if (!ui::PageTransitionIsWebTriggerable(params.transition) && |
1318 auto_accept_ != AUTO_ACCEPT_NONE) { | 1318 auto_accept_ != AUTO_ACCEPT_NONE) { |
1319 CleanTransientState(); | 1319 CleanTransientState(); |
1320 } | 1320 } |
1321 } | 1321 } |
1322 } | 1322 } |
1323 | 1323 |
1324 void OneClickSigninHelper::DidStopLoading( | 1324 void OneClickSigninHelper::DidStopLoading( |
1325 content::RenderViewHost* render_view_host) { | 1325 content::RenderViewHost* render_view_host) { |
1326 // If the user left the sign in process, clear all members. | 1326 // If the user left the sign in process, clear all members. |
1327 // TODO(rogerta): might need to allow some youtube URLs. | 1327 // TODO(rogerta): might need to allow some youtube URLs. |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1597 // If the web contents is showing a blank page and not about to be closed, | 1597 // If the web contents is showing a blank page and not about to be closed, |
1598 // redirect to the NTP or apps page. | 1598 // redirect to the NTP or apps page. |
1599 if (signin::IsContinueUrlForWebBasedSigninFlow(current_url) && | 1599 if (signin::IsContinueUrlForWebBasedSigninFlow(current_url) && |
1600 !signin::IsAutoCloseEnabledInURL(original_continue_url_)) { | 1600 !signin::IsAutoCloseEnabledInURL(original_continue_url_)) { |
1601 RedirectToNtpOrAppsPage( | 1601 RedirectToNtpOrAppsPage( |
1602 web_contents(), | 1602 web_contents(), |
1603 signin::GetSourceForPromoURL(original_continue_url_)); | 1603 signin::GetSourceForPromoURL(original_continue_url_)); |
1604 } | 1604 } |
1605 } | 1605 } |
1606 } | 1606 } |
OLD | NEW |