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/chromeos/login/oobe_ui.h" | 5 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "ash/ash_switches.h" | 9 #include "ash/ash_switches.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 #include "chrome/browser/ui/webui/chromeos/login/reset_screen_handler.h" | 31 #include "chrome/browser/ui/webui/chromeos/login/reset_screen_handler.h" |
32 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" | 32 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" |
33 #include "chrome/browser/ui/webui/chromeos/login/update_screen_handler.h" | 33 #include "chrome/browser/ui/webui/chromeos/login/update_screen_handler.h" |
34 #include "chrome/browser/ui/webui/chromeos/login/user_image_screen_handler.h" | 34 #include "chrome/browser/ui/webui/chromeos/login/user_image_screen_handler.h" |
35 #include "chrome/browser/ui/webui/options/chromeos/user_image_source.h" | 35 #include "chrome/browser/ui/webui/options/chromeos/user_image_source.h" |
36 #include "chrome/browser/ui/webui/options/chromeos/wallpaper_source.h" | 36 #include "chrome/browser/ui/webui/options/chromeos/wallpaper_source.h" |
37 #include "chrome/browser/ui/webui/theme_source.h" | 37 #include "chrome/browser/ui/webui/theme_source.h" |
38 #include "chrome/common/chrome_switches.h" | 38 #include "chrome/common/chrome_switches.h" |
39 #include "chrome/common/jstemplate_builder.h" | 39 #include "chrome/common/jstemplate_builder.h" |
40 #include "chrome/common/url_constants.h" | 40 #include "chrome/common/url_constants.h" |
| 41 #include "content/public/browser/url_data_source_delegate.h" |
41 #include "content/public/browser/web_contents.h" | 42 #include "content/public/browser/web_contents.h" |
42 #include "content/public/browser/web_ui.h" | 43 #include "content/public/browser/web_ui.h" |
43 #include "grit/browser_resources.h" | 44 #include "grit/browser_resources.h" |
44 #include "ui/base/resource/resource_bundle.h" | 45 #include "ui/base/resource/resource_bundle.h" |
45 | 46 |
46 using content::WebContents; | 47 using content::WebContents; |
47 | 48 |
48 namespace { | 49 namespace { |
49 | 50 |
50 // Path for a stripped down login page that does not have OOBE elements. | 51 // Path for a stripped down login page that does not have OOBE elements. |
51 const char kLoginPath[] = "login"; | 52 const char kLoginPath[] = "login"; |
52 | 53 |
53 // Path for the enterprise enrollment gaia page hosting. | 54 // Path for the enterprise enrollment gaia page hosting. |
54 const char kEnterpriseEnrollmentGaiaLoginPath[] = "gaialogin"; | 55 const char kEnterpriseEnrollmentGaiaLoginPath[] = "gaialogin"; |
55 | 56 |
56 } // namespace | 57 } // namespace |
57 | 58 |
58 namespace chromeos { | 59 namespace chromeos { |
59 | 60 |
60 class OobeUIHTMLSource : public ChromeURLDataManager::DataSource { | 61 class OobeUIHTMLSource : public content::URLDataSourceDelegate { |
61 public: | 62 public: |
62 explicit OobeUIHTMLSource(DictionaryValue* localized_strings); | 63 explicit OobeUIHTMLSource(DictionaryValue* localized_strings); |
63 | 64 |
64 // Called when the network layer has requested a resource underneath | 65 // content::URLDataSourceDelegate implementation. |
65 // the path we registered. | 66 virtual std::string GetSource() OVERRIDE; |
66 virtual void StartDataRequest(const std::string& path, | 67 virtual void StartDataRequest(const std::string& path, |
67 bool is_incognito, | 68 bool is_incognito, |
68 int request_id); | 69 int request_id); |
69 virtual std::string GetMimeType(const std::string&) const { | 70 virtual std::string GetMimeType(const std::string&) const { |
70 return "text/html"; | 71 return "text/html"; |
71 } | 72 } |
72 | 73 |
73 private: | 74 private: |
74 virtual ~OobeUIHTMLSource() {} | 75 virtual ~OobeUIHTMLSource() {} |
75 | 76 |
76 std::string GetDataResource(int resource_id) const; | 77 std::string GetDataResource(int resource_id) const; |
77 | 78 |
78 scoped_ptr<DictionaryValue> localized_strings_; | 79 scoped_ptr<DictionaryValue> localized_strings_; |
79 DISALLOW_COPY_AND_ASSIGN(OobeUIHTMLSource); | 80 DISALLOW_COPY_AND_ASSIGN(OobeUIHTMLSource); |
80 }; | 81 }; |
81 | 82 |
82 // OobeUIHTMLSource ------------------------------------------------------- | 83 // OobeUIHTMLSource ------------------------------------------------------- |
83 | 84 |
84 OobeUIHTMLSource::OobeUIHTMLSource(DictionaryValue* localized_strings) | 85 OobeUIHTMLSource::OobeUIHTMLSource(DictionaryValue* localized_strings) |
85 : DataSource(chrome::kChromeUIOobeHost, MessageLoop::current()), | 86 : localized_strings_(localized_strings) { |
86 localized_strings_(localized_strings) { | 87 } |
| 88 |
| 89 std::string OobeUIHTMLSource::GetSource() { |
| 90 return chrome::kChromeUIOobeHost; |
87 } | 91 } |
88 | 92 |
89 void OobeUIHTMLSource::StartDataRequest(const std::string& path, | 93 void OobeUIHTMLSource::StartDataRequest(const std::string& path, |
90 bool is_incognito, | 94 bool is_incognito, |
91 int request_id) { | 95 int request_id) { |
92 if (UserManager::Get()->IsUserLoggedIn() && | 96 if (UserManager::Get()->IsUserLoggedIn() && |
93 !UserManager::Get()->IsLoggedInAsStub() && | 97 !UserManager::Get()->IsLoggedInAsStub() && |
94 !ScreenLocker::default_screen_locker()) { | 98 !ScreenLocker::default_screen_locker()) { |
95 scoped_refptr<base::RefCountedBytes> empty_bytes = | 99 scoped_refptr<base::RefCountedBytes> empty_bytes = |
96 new base::RefCountedBytes(); | 100 new base::RefCountedBytes(); |
97 SendResponse(request_id, empty_bytes); | 101 url_data_source()->SendResponse(request_id, empty_bytes); |
98 return; | 102 return; |
99 } | 103 } |
100 | 104 |
101 std::string response; | 105 std::string response; |
102 if (chromeos::KioskModeSettings::Get()->IsKioskModeEnabled()) | 106 if (chromeos::KioskModeSettings::Get()->IsKioskModeEnabled()) |
103 response = GetDataResource(IDR_DEMO_USER_LOGIN_HTML); | 107 response = GetDataResource(IDR_DEMO_USER_LOGIN_HTML); |
104 else if (path.empty()) | 108 else if (path.empty()) |
105 response = GetDataResource(IDR_OOBE_HTML); | 109 response = GetDataResource(IDR_OOBE_HTML); |
106 else if (path == kLoginPath) | 110 else if (path == kLoginPath) |
107 response = GetDataResource(IDR_LOGIN_HTML); | 111 response = GetDataResource(IDR_LOGIN_HTML); |
108 else if (path == kEnterpriseEnrollmentGaiaLoginPath) | 112 else if (path == kEnterpriseEnrollmentGaiaLoginPath) |
109 response = GetDataResource(IDR_GAIA_LOGIN_HTML); | 113 response = GetDataResource(IDR_GAIA_LOGIN_HTML); |
110 | 114 |
111 SendResponse(request_id, base::RefCountedString::TakeString(&response)); | 115 url_data_source()->SendResponse( |
| 116 request_id, base::RefCountedString::TakeString(&response)); |
112 } | 117 } |
113 | 118 |
114 std::string OobeUIHTMLSource::GetDataResource(int resource_id) const { | 119 std::string OobeUIHTMLSource::GetDataResource(int resource_id) const { |
115 const base::StringPiece html( | 120 const base::StringPiece html( |
116 ResourceBundle::GetSharedInstance().GetRawDataResource( | 121 ResourceBundle::GetSharedInstance().GetRawDataResource( |
117 resource_id)); | 122 resource_id)); |
118 return jstemplate_builder::GetI18nTemplateHtml(html, | 123 return jstemplate_builder::GetI18nTemplateHtml(html, |
119 localized_strings_.get()); | 124 localized_strings_.get()); |
120 } | 125 } |
121 | 126 |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 // WebUI implementation of the LoginDisplayHost opens HTML page directly, | 265 // WebUI implementation of the LoginDisplayHost opens HTML page directly, |
261 // without opening OOBE page. | 266 // without opening OOBE page. |
262 NOTREACHED(); | 267 NOTREACHED(); |
263 return NULL; | 268 return NULL; |
264 } | 269 } |
265 | 270 |
266 void OobeUI::GetLocalizedStrings(base::DictionaryValue* localized_strings) { | 271 void OobeUI::GetLocalizedStrings(base::DictionaryValue* localized_strings) { |
267 // Note, handlers_[0] is a GenericHandler used by the WebUI. | 272 // Note, handlers_[0] is a GenericHandler used by the WebUI. |
268 for (size_t i = 0; i < handlers_.size(); ++i) | 273 for (size_t i = 0; i < handlers_.size(); ++i) |
269 handlers_[i]->GetLocalizedStrings(localized_strings); | 274 handlers_[i]->GetLocalizedStrings(localized_strings); |
270 ChromeURLDataManager::DataSource::SetFontAndTextDirection(localized_strings); | 275 URLDataSource::SetFontAndTextDirection(localized_strings); |
271 | 276 |
272 #if defined(GOOGLE_CHROME_BUILD) | 277 #if defined(GOOGLE_CHROME_BUILD) |
273 localized_strings->SetString("buildType", "chrome"); | 278 localized_strings->SetString("buildType", "chrome"); |
274 #else | 279 #else |
275 localized_strings->SetString("buildType", "chromium"); | 280 localized_strings->SetString("buildType", "chromium"); |
276 #endif | 281 #endif |
277 | 282 |
278 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableNewOobe)) | 283 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableNewOobe)) |
279 localized_strings->SetString("oobeType", "new"); | 284 localized_strings->SetString("oobeType", "new"); |
280 else | 285 else |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 void OobeUI::OnCurrentScreenChanged(const std::string& screen) { | 366 void OobeUI::OnCurrentScreenChanged(const std::string& screen) { |
362 if (screen_ids_.count(screen)) { | 367 if (screen_ids_.count(screen)) { |
363 current_screen_ = screen_ids_[screen]; | 368 current_screen_ = screen_ids_[screen]; |
364 } else { | 369 } else { |
365 NOTREACHED() << "Screen should be registered in InitializeScreenMaps()"; | 370 NOTREACHED() << "Screen should be registered in InitializeScreenMaps()"; |
366 current_screen_ = SCREEN_UNKNOWN; | 371 current_screen_ = SCREEN_UNKNOWN; |
367 } | 372 } |
368 } | 373 } |
369 | 374 |
370 } // namespace chromeos | 375 } // namespace chromeos |
OLD | NEW |