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