| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/webui/signin/inline_login_handler.h" | 5 #include "chrome/browser/ui/webui/signin/inline_login_handler.h" |
| 6 | 6 |
| 7 #include <limits.h> | 7 #include <limits.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/extensions/signin/gaia_auth_extension_loader.h" | 14 #include "chrome/browser/extensions/signin/gaia_auth_extension_loader.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/signin/signin_promo.h" | 16 #include "chrome/browser/signin/signin_promo.h" |
| 17 #include "chrome/browser/ui/browser_finder.h" |
| 17 #include "chrome/browser/ui/browser_navigator.h" | 18 #include "chrome/browser/ui/browser_navigator.h" |
| 18 #include "chrome/browser/ui/browser_navigator_params.h" | 19 #include "chrome/browser/ui/browser_navigator_params.h" |
| 20 #include "chrome/browser/ui/signin_view_controller_delegate.h" |
| 19 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
| 20 #include "components/metrics/metrics_pref_names.h" | 22 #include "components/metrics/metrics_pref_names.h" |
| 21 #include "components/prefs/pref_service.h" | 23 #include "components/prefs/pref_service.h" |
| 22 #include "components/signin/core/common/signin_pref_names.h" | 24 #include "components/signin/core/common/signin_pref_names.h" |
| 23 #include "content/public/browser/storage_partition.h" | 25 #include "content/public/browser/storage_partition.h" |
| 24 #include "content/public/browser/user_metrics.h" | 26 #include "content/public/browser/user_metrics.h" |
| 25 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
| 26 #include "content/public/browser/web_ui.h" | 28 #include "content/public/browser/web_ui.h" |
| 27 #include "google_apis/gaia/gaia_urls.h" | 29 #include "google_apis/gaia/gaia_urls.h" |
| 28 #include "net/base/url_util.h" | 30 #include "net/base/url_util.h" |
| 29 | 31 |
| 32 namespace { |
| 33 |
| 34 Browser* GetDesktopBrowser(content::WebUI* web_ui) { |
| 35 Browser* browser = chrome::FindBrowserWithWebContents( |
| 36 web_ui->GetWebContents()); |
| 37 if (!browser) |
| 38 browser = chrome::FindLastActiveWithProfile(Profile::FromWebUI(web_ui)); |
| 39 DCHECK(browser); |
| 40 return browser; |
| 41 } |
| 42 |
| 43 } // namespace |
| 44 |
| 30 InlineLoginHandler::InlineLoginHandler() : weak_ptr_factory_(this) {} | 45 InlineLoginHandler::InlineLoginHandler() : weak_ptr_factory_(this) {} |
| 31 | 46 |
| 32 InlineLoginHandler::~InlineLoginHandler() {} | 47 InlineLoginHandler::~InlineLoginHandler() {} |
| 33 | 48 |
| 34 void InlineLoginHandler::RegisterMessages() { | 49 void InlineLoginHandler::RegisterMessages() { |
| 35 web_ui()->RegisterMessageCallback("initialize", | 50 web_ui()->RegisterMessageCallback("initialize", |
| 36 base::Bind(&InlineLoginHandler::HandleInitializeMessage, | 51 base::Bind(&InlineLoginHandler::HandleInitializeMessage, |
| 37 base::Unretained(this))); | 52 base::Unretained(this))); |
| 38 web_ui()->RegisterMessageCallback("completeLogin", | 53 web_ui()->RegisterMessageCallback("completeLogin", |
| 39 base::Bind(&InlineLoginHandler::HandleCompleteLoginMessage, | 54 base::Bind(&InlineLoginHandler::HandleCompleteLoginMessage, |
| 40 base::Unretained(this))); | 55 base::Unretained(this))); |
| 41 web_ui()->RegisterMessageCallback( | 56 web_ui()->RegisterMessageCallback( |
| 42 "switchToFullTab", | 57 "switchToFullTab", |
| 43 base::Bind(&InlineLoginHandler::HandleSwitchToFullTabMessage, | 58 base::Bind(&InlineLoginHandler::HandleSwitchToFullTabMessage, |
| 44 base::Unretained(this))); | 59 base::Unretained(this))); |
| 60 web_ui()->RegisterMessageCallback("navigationButtonClicked", |
| 61 base::Bind(&InlineLoginHandler::HandleNavigationButtonClicked, |
| 62 base::Unretained(this))); |
| 45 } | 63 } |
| 46 | 64 |
| 47 void InlineLoginHandler::HandleInitializeMessage(const base::ListValue* args) { | 65 void InlineLoginHandler::HandleInitializeMessage(const base::ListValue* args) { |
| 48 content::WebContents* contents = web_ui()->GetWebContents(); | 66 content::WebContents* contents = web_ui()->GetWebContents(); |
| 49 content::StoragePartition* partition = | 67 content::StoragePartition* partition = |
| 50 content::BrowserContext::GetStoragePartitionForSite( | 68 content::BrowserContext::GetStoragePartitionForSite( |
| 51 contents->GetBrowserContext(), signin::GetSigninPartitionURL()); | 69 contents->GetBrowserContext(), signin::GetSigninPartitionURL()); |
| 52 if (partition) { | 70 if (partition) { |
| 53 partition->ClearData( | 71 partition->ClearData( |
| 54 content::StoragePartition::REMOVE_DATA_MASK_ALL, | 72 content::StoragePartition::REMOVE_DATA_MASK_ALL, |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 | 246 |
| 229 chrome::NavigateParams params( | 247 chrome::NavigateParams params( |
| 230 profile, | 248 profile, |
| 231 net::AppendOrReplaceQueryParameter( | 249 net::AppendOrReplaceQueryParameter( |
| 232 main_frame_url, signin::kSignInPromoQueryKeyConstrained, "0"), | 250 main_frame_url, signin::kSignInPromoQueryKeyConstrained, "0"), |
| 233 ui::PAGE_TRANSITION_AUTO_TOPLEVEL); | 251 ui::PAGE_TRANSITION_AUTO_TOPLEVEL); |
| 234 chrome::Navigate(¶ms); | 252 chrome::Navigate(¶ms); |
| 235 | 253 |
| 236 web_ui()->CallJavascriptFunction("inline.login.closeDialog"); | 254 web_ui()->CallJavascriptFunction("inline.login.closeDialog"); |
| 237 } | 255 } |
| 256 |
| 257 void InlineLoginHandler::HandleNavigationButtonClicked( |
| 258 const base::ListValue* args) { |
| 259 Browser* browser = GetDesktopBrowser(web_ui()); |
| 260 DCHECK(browser); |
| 261 |
| 262 browser->signin_view_controller()->delegate()->PerformNavigation(); |
| 263 } |
| OLD | NEW |