| 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/webui/signin/login_ui_service.h" | 5 #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
| 6 | 6 |
| 7 #include "chrome/browser/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
| 8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
| 9 #include "chrome/browser/ui/browser_list.h" | 9 #include "chrome/browser/ui/browser_list.h" |
| 10 #include "chrome/browser/ui/browser_window.h" | 10 #include "chrome/browser/ui/browser_window.h" |
| 11 #include "chrome/common/url_constants.h" | 11 #include "chrome/common/url_constants.h" |
| 12 #include "content/public/browser/render_view_host.h" | |
| 13 #include "content/public/browser/render_view_host_delegate.h" | |
| 14 #include "content/public/browser/web_contents.h" | |
| 15 #include "content/public/browser/web_ui.h" | |
| 16 | 12 |
| 17 LoginUIService::LoginUIService(Profile* profile) | 13 LoginUIService::LoginUIService(Profile* profile) |
| 18 : ui_(NULL), | 14 : ui_(NULL), |
| 19 profile_(profile) { | 15 profile_(profile) { |
| 20 } | 16 } |
| 21 | 17 |
| 22 LoginUIService::~LoginUIService() {} | 18 LoginUIService::~LoginUIService() {} |
| 23 | 19 |
| 24 void LoginUIService::SetLoginUI(content::WebUI* ui) { | 20 void LoginUIService::SetLoginUI(LoginUI* ui) { |
| 25 DCHECK(!current_login_ui() || current_login_ui() == ui); | 21 DCHECK(!current_login_ui() || current_login_ui() == ui); |
| 26 ui_ = ui; | 22 ui_ = ui; |
| 27 } | 23 } |
| 28 | 24 |
| 29 void LoginUIService::LoginUIClosed(content::WebUI* ui) { | 25 void LoginUIService::LoginUIClosed(LoginUI* ui) { |
| 30 if (current_login_ui() == ui) | 26 if (current_login_ui() == ui) |
| 31 ui_ = NULL; | 27 ui_ = NULL; |
| 32 } | 28 } |
| 33 | 29 |
| 34 void LoginUIService::FocusLoginUI() { | 30 void LoginUIService::ShowLoginUI() { |
| 35 if (!ui_) { | 31 if (ui_) { |
| 36 NOTREACHED() << "FocusLoginUI() called with no active login UI"; | 32 // We already have active login UI - make it visible. |
| 33 ui_->FocusUI(); |
| 37 return; | 34 return; |
| 38 } | 35 } |
| 39 ui_->GetWebContents()->GetRenderViewHost()->GetDelegate()->Activate(); | |
| 40 } | |
| 41 | |
| 42 void LoginUIService::ShowLoginUI(bool force_login) { | |
| 43 if (ui_) { | |
| 44 // We already have active login UI - make it visible. | |
| 45 FocusLoginUI(); | |
| 46 return; | |
| 47 } | |
| 48 | |
| 49 std::string page(force_login ? | |
| 50 chrome::kSyncSetupForceLoginSubPage : chrome::kSyncSetupSubPage); | |
| 51 | 36 |
| 52 // Need to navigate to the settings page and display the UI. | 37 // Need to navigate to the settings page and display the UI. |
| 53 if (profile_) { | 38 if (profile_) { |
| 54 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); | 39 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); |
| 55 if (!browser) { | 40 if (!browser) { |
| 56 browser = Browser::Create(profile_); | 41 browser = Browser::Create(profile_); |
| 57 browser->ShowOptionsTab(page); | 42 browser->ShowOptionsTab(chrome::kSyncSetupSubPage); |
| 58 browser->window()->Show(); | 43 browser->window()->Show(); |
| 59 } else { | 44 } else { |
| 60 browser->ShowOptionsTab(page); | 45 browser->ShowOptionsTab(chrome::kSyncSetupSubPage); |
| 61 } | 46 } |
| 62 } | 47 } |
| 63 } | 48 } |
| OLD | NEW |