| 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" | |
| 18 #include "chrome/browser/ui/browser_navigator.h" | 17 #include "chrome/browser/ui/browser_navigator.h" |
| 19 #include "chrome/browser/ui/browser_navigator_params.h" | 18 #include "chrome/browser/ui/browser_navigator_params.h" |
| 20 #include "chrome/browser/ui/signin_view_controller_delegate.h" | 19 #include "chrome/browser/ui/signin_view_controller_delegate.h" |
| 21 #include "chrome/browser/ui/user_manager.h" | 20 #include "chrome/browser/ui/user_manager.h" |
| 21 #include "chrome/browser/ui/webui/signin/signin_utils.h" |
| 22 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 23 #include "components/metrics/metrics_pref_names.h" | 23 #include "components/metrics/metrics_pref_names.h" |
| 24 #include "components/prefs/pref_service.h" | 24 #include "components/prefs/pref_service.h" |
| 25 #include "components/signin/core/common/signin_pref_names.h" | 25 #include "components/signin/core/common/signin_pref_names.h" |
| 26 #include "content/public/browser/storage_partition.h" | 26 #include "content/public/browser/storage_partition.h" |
| 27 #include "content/public/browser/user_metrics.h" | 27 #include "content/public/browser/user_metrics.h" |
| 28 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
| 29 #include "content/public/browser/web_ui.h" | 29 #include "content/public/browser/web_ui.h" |
| 30 #include "google_apis/gaia/gaia_urls.h" | 30 #include "google_apis/gaia/gaia_urls.h" |
| 31 #include "net/base/url_util.h" | 31 #include "net/base/url_util.h" |
| 32 | 32 |
| 33 namespace { | |
| 34 | |
| 35 Browser* GetDesktopBrowser(content::WebUI* web_ui) { | |
| 36 Browser* browser = chrome::FindBrowserWithWebContents( | |
| 37 web_ui->GetWebContents()); | |
| 38 if (!browser) | |
| 39 browser = chrome::FindLastActiveWithProfile(Profile::FromWebUI(web_ui)); | |
| 40 return browser; | |
| 41 } | |
| 42 | |
| 43 } // namespace | |
| 44 | |
| 45 InlineLoginHandler::InlineLoginHandler() : weak_ptr_factory_(this) {} | 33 InlineLoginHandler::InlineLoginHandler() : weak_ptr_factory_(this) {} |
| 46 | 34 |
| 47 InlineLoginHandler::~InlineLoginHandler() {} | 35 InlineLoginHandler::~InlineLoginHandler() {} |
| 48 | 36 |
| 49 void InlineLoginHandler::RegisterMessages() { | 37 void InlineLoginHandler::RegisterMessages() { |
| 50 web_ui()->RegisterMessageCallback("initialize", | 38 web_ui()->RegisterMessageCallback("initialize", |
| 51 base::Bind(&InlineLoginHandler::HandleInitializeMessage, | 39 base::Bind(&InlineLoginHandler::HandleInitializeMessage, |
| 52 base::Unretained(this))); | 40 base::Unretained(this))); |
| 53 web_ui()->RegisterMessageCallback("completeLogin", | 41 web_ui()->RegisterMessageCallback("completeLogin", |
| 54 base::Bind(&InlineLoginHandler::HandleCompleteLoginMessage, | 42 base::Bind(&InlineLoginHandler::HandleCompleteLoginMessage, |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 net::AppendOrReplaceQueryParameter( | 259 net::AppendOrReplaceQueryParameter( |
| 272 main_frame_url, signin::kSignInPromoQueryKeyConstrained, "0"), | 260 main_frame_url, signin::kSignInPromoQueryKeyConstrained, "0"), |
| 273 ui::PAGE_TRANSITION_AUTO_TOPLEVEL); | 261 ui::PAGE_TRANSITION_AUTO_TOPLEVEL); |
| 274 chrome::Navigate(¶ms); | 262 chrome::Navigate(¶ms); |
| 275 | 263 |
| 276 web_ui()->CallJavascriptFunctionUnsafe("inline.login.closeDialog"); | 264 web_ui()->CallJavascriptFunctionUnsafe("inline.login.closeDialog"); |
| 277 } | 265 } |
| 278 | 266 |
| 279 void InlineLoginHandler::HandleNavigationButtonClicked( | 267 void InlineLoginHandler::HandleNavigationButtonClicked( |
| 280 const base::ListValue* args) { | 268 const base::ListValue* args) { |
| 281 Browser* browser = GetDesktopBrowser(web_ui()); | 269 Browser* browser = signin::GetDesktopBrowser(web_ui()); |
| 282 DCHECK(browser); | 270 DCHECK(browser); |
| 283 | 271 |
| 284 browser->signin_view_controller()->delegate()->PerformNavigation(); | 272 browser->signin_view_controller()->delegate()->PerformNavigation(); |
| 285 } | 273 } |
| 286 | 274 |
| 287 void InlineLoginHandler::HandleDialogClose(const base::ListValue* args) { | 275 void InlineLoginHandler::HandleDialogClose(const base::ListValue* args) { |
| 288 Browser* browser = GetDesktopBrowser(web_ui()); | 276 Browser* browser = signin::GetDesktopBrowser(web_ui()); |
| 289 // If the dialog was opened in the User Manager browser will be null here. | 277 // If the dialog was opened in the User Manager browser will be null here. |
| 290 if (browser) | 278 if (browser) |
| 291 browser->CloseModalSigninWindow(); | 279 browser->CloseModalSigninWindow(); |
| 292 | 280 |
| 293 // Does nothing if user manager is not showing. | 281 // Does nothing if user manager is not showing. |
| 294 UserManager::HideReauthDialog(); | 282 UserManager::HideReauthDialog(); |
| 295 } | 283 } |
| OLD | NEW |