| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2011 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/chromeos/webui/login/login_container_ui.h" |
| 6 |
| 7 #include "base/ref_counted_memory.h" |
| 8 #include "base/singleton.h" |
| 9 #include "base/string_piece.h" |
| 10 #include "base/values.h" |
| 11 #include "chrome/browser/chromeos/webui/login/login_ui_helpers.h" |
| 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/browser/ui/browser_window.h" |
| 15 #include "chrome/common/url_constants.h" |
| 16 #include "content/browser/browser_thread.h" |
| 17 #include "content/browser/tab_contents/tab_contents.h" |
| 18 #include "views/screen.h" |
| 19 |
| 20 namespace { |
| 21 const char* kLoginURL = "chrome://login"; |
| 22 } |
| 23 namespace chromeos { |
| 24 |
| 25 // LoginContainerUIHTMLSource -------------------------------------------------- |
| 26 |
| 27 LoginContainerUIHTMLSource::LoginContainerUIHTMLSource( |
| 28 MessageLoop* message_loop) |
| 29 : DataSource(chrome::kChromeUILoginContainerHost, message_loop), |
| 30 html_operations_(new HTMLOperationsInterface()) { |
| 31 } |
| 32 |
| 33 void LoginContainerUIHTMLSource::StartDataRequest(const std::string& path, |
| 34 bool is_off_the_record, |
| 35 int request_id) { |
| 36 DictionaryValue localized_strings; |
| 37 SetFontAndTextDirection(&localized_strings); |
| 38 |
| 39 base::StringPiece login_html = html_operations_->GetLoginContainerHTML(); |
| 40 std::string full_html = html_operations_->GetFullHTML(login_html, |
| 41 &localized_strings); |
| 42 scoped_refptr<RefCountedBytes> html_bytes( |
| 43 html_operations_->CreateHTMLBytes(full_html)); |
| 44 SendResponse(request_id, (html_bytes.get())); |
| 45 } |
| 46 |
| 47 // LoginContainerUIHandler ----------------------------------------------------- |
| 48 |
| 49 LoginContainerUIHandler::LoginContainerUIHandler() |
| 50 : browser_operations_(new BrowserOperationsInterface), |
| 51 profile_operations_(new ProfileOperationsInterface) { |
| 52 } |
| 53 |
| 54 LoginContainerUIHandler::~LoginContainerUIHandler() { |
| 55 } |
| 56 |
| 57 WebUIMessageHandler* LoginContainerUIHandler::Attach(WebUI* web_ui) { |
| 58 return WebUIMessageHandler::Attach(web_ui); |
| 59 } |
| 60 |
| 61 void LoginContainerUIHandler::RegisterMessages() { |
| 62 web_ui_->RegisterMessageCallback( |
| 63 "OpenLoginScreen", |
| 64 NewCallback(this, |
| 65 &LoginContainerUIHandler::HandleOpenLoginScreen)); |
| 66 } |
| 67 |
| 68 void LoginContainerUIHandler::HandleOpenLoginScreen(const ListValue* args) { |
| 69 Profile* profile = profile_operations_->GetDefaultProfileByPath(); |
| 70 Browser* current_browser = browser_operations_->GetLoginBrowser(profile); |
| 71 Browser* login_screen = browser_operations_->CreateBrowser(profile); |
| 72 login_screen->AddSelectedTabWithURL(GURL(kLoginURL), PageTransition::LINK); |
| 73 login_screen->window()->Show(); |
| 74 current_browser->CloseWindow(); |
| 75 } |
| 76 |
| 77 // LoginContainerUI ------------------------------------------------------------ |
| 78 |
| 79 LoginContainerUI::LoginContainerUI(TabContents* contents) |
| 80 : WebUI(contents) { |
| 81 LoginContainerUIHandler* handler = new LoginContainerUIHandler(); |
| 82 AddMessageHandler(handler->Attach(this)); |
| 83 LoginContainerUIHTMLSource* html_source = |
| 84 new LoginContainerUIHTMLSource(MessageLoop::current()); |
| 85 |
| 86 contents->profile()->GetChromeURLDataManager()->AddDataSource(html_source); |
| 87 } |
| 88 |
| 89 } // namespace chromeos |
| OLD | NEW |