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