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/ui/webui/chromeos/login/login_ui.h" | |
6 | |
7 #include "base/memory/ref_counted_memory.h" | |
8 #include "base/values.h" | |
9 #include "chrome/browser/profiles/profile.h" | |
10 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | |
11 #include "chrome/browser/ui/webui/chromeos/login/login_ui_helpers.h" | |
12 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" | |
13 #include "chrome/browser/ui/webui/options/chromeos/user_image_source.h" | |
14 #include "chrome/browser/ui/webui/theme_source.h" | |
15 #include "chrome/common/url_constants.h" | |
16 #include "content/browser/tab_contents/tab_contents.h" | |
17 | |
18 namespace chromeos { | |
19 | |
20 // Boilerplate class that is used to associate the LoginUI code with the URL | |
21 // "chrome://login" | |
22 class LoginUIHTMLSource : public ChromeURLDataManager::DataSource { | |
23 public: | |
24 explicit LoginUIHTMLSource(base::DictionaryValue* localized_strings); | |
25 virtual ~LoginUIHTMLSource(); | |
26 | |
27 virtual void StartDataRequest(const std::string& path, | |
28 bool is_incognito, | |
29 int request_id); | |
30 virtual std::string GetMimeType(const std::string&) const; | |
31 | |
32 private: | |
33 scoped_ptr<HTMLOperationsInterface> html_operations_; | |
34 scoped_ptr<DictionaryValue> localized_strings_; | |
35 | |
36 DISALLOW_COPY_AND_ASSIGN(LoginUIHTMLSource); | |
37 }; | |
38 | |
39 // LoginUIHTMLSource, public: -------------------------------------------------- | |
40 | |
41 LoginUIHTMLSource::LoginUIHTMLSource(base::DictionaryValue* localized_strings) | |
42 : DataSource(chrome::kChromeUILoginHost, MessageLoop::current()), | |
43 html_operations_(new HTMLOperationsInterface()), | |
44 localized_strings_(localized_strings) { | |
45 } | |
46 | |
47 LoginUIHTMLSource::~LoginUIHTMLSource() { | |
48 } | |
49 | |
50 void LoginUIHTMLSource::StartDataRequest(const std::string& path, | |
51 bool is_incognito, | |
52 int request_id) { | |
53 SetFontAndTextDirection(localized_strings_.get()); | |
54 | |
55 base::StringPiece login_html = html_operations_->GetLoginHTML(); | |
56 std::string full_html = html_operations_->GetFullHTML( | |
57 login_html, localized_strings_.get()); | |
58 | |
59 SendResponse(request_id, base::RefCountedString::TakeString(&full_html)); | |
60 } | |
61 | |
62 std::string LoginUIHTMLSource::GetMimeType(const std::string&) const { | |
63 return "text/html"; | |
64 } | |
65 | |
66 // LoginUI, public: ------------------------------------------------------------ | |
67 | |
68 LoginUI::LoginUI(TabContents* contents) | |
69 : ChromeWebUI(contents) { | |
70 scoped_ptr<base::DictionaryValue> localized_strings( | |
71 new base::DictionaryValue); | |
72 | |
73 BaseScreenHandler* signin_screen_handler = new SigninScreenHandler; | |
74 AddMessageHandler(signin_screen_handler->Attach(this)); | |
75 signin_screen_handler->GetLocalizedStrings(localized_strings.get()); | |
76 | |
77 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); | |
78 LoginUIHTMLSource* html_source = | |
79 new LoginUIHTMLSource(localized_strings.release()); | |
80 profile->GetChromeURLDataManager()->AddDataSource(html_source); | |
81 | |
82 // Load the theme URLs. | |
83 ThemeSource* theme = new ThemeSource(profile); | |
84 profile->GetChromeURLDataManager()->AddDataSource(theme); | |
85 | |
86 // Load the user-image URLs | |
87 // Set up the chrome://userimage/ source. | |
88 chromeos::UserImageSource* user_image_source = | |
89 new chromeos::UserImageSource(); | |
90 profile->GetChromeURLDataManager()->AddDataSource(user_image_source); | |
91 } | |
92 | |
93 } // namespace chromeos | |
OLD | NEW |