Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Side by Side Diff: chrome/browser/ui/webui/chromeos/login/oobe_ui.cc

Issue 11881055: Simplify WebUI data sources. Currently WebUI data sources implement a URLDataSourceDelegate interfa… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix issue in about_ui exposed by cros tests Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/ref_counted_memory.h" 12 #include "base/memory/ref_counted_memory.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "chrome/browser/browser_about_handler.h" 14 #include "chrome/browser/browser_about_handler.h"
15 #include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_settings.h" 15 #include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_settings.h"
16 #include "chrome/browser/chromeos/login/base_login_display_host.h" 16 #include "chrome/browser/chromeos/login/base_login_display_host.h"
17 #include "chrome/browser/chromeos/login/enrollment/enterprise_enrollment_screen_ actor.h" 17 #include "chrome/browser/chromeos/login/enrollment/enterprise_enrollment_screen_ actor.h"
18 #include "chrome/browser/chromeos/login/screen_locker.h" 18 #include "chrome/browser/chromeos/login/screen_locker.h"
19 #include "chrome/browser/chromeos/login/user_manager.h" 19 #include "chrome/browser/chromeos/login/user_manager.h"
20 #include "chrome/browser/chromeos/login/wizard_controller.h" 20 #include "chrome/browser/chromeos/login/wizard_controller.h"
21 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/ui/webui/about_ui.h" 22 #include "chrome/browser/ui/webui/about_ui.h"
23 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
24 #include "chrome/browser/ui/webui/chromeos/login/base_screen_handler.h" 23 #include "chrome/browser/ui/webui/chromeos/login/base_screen_handler.h"
25 #include "chrome/browser/ui/webui/chromeos/login/enterprise_oauth_enrollment_scr een_handler.h" 24 #include "chrome/browser/ui/webui/chromeos/login/enterprise_oauth_enrollment_scr een_handler.h"
26 #include "chrome/browser/ui/webui/chromeos/login/error_screen_handler.h" 25 #include "chrome/browser/ui/webui/chromeos/login/error_screen_handler.h"
27 #include "chrome/browser/ui/webui/chromeos/login/eula_screen_handler.h" 26 #include "chrome/browser/ui/webui/chromeos/login/eula_screen_handler.h"
28 #include "chrome/browser/ui/webui/chromeos/login/network_dropdown_handler.h" 27 #include "chrome/browser/ui/webui/chromeos/login/network_dropdown_handler.h"
29 #include "chrome/browser/ui/webui/chromeos/login/network_screen_handler.h" 28 #include "chrome/browser/ui/webui/chromeos/login/network_screen_handler.h"
30 #include "chrome/browser/ui/webui/chromeos/login/network_state_informer.h" 29 #include "chrome/browser/ui/webui/chromeos/login/network_state_informer.h"
31 #include "chrome/browser/ui/webui/chromeos/login/reset_screen_handler.h" 30 #include "chrome/browser/ui/webui/chromeos/login/reset_screen_handler.h"
32 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" 31 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
33 #include "chrome/browser/ui/webui/chromeos/login/update_screen_handler.h" 32 #include "chrome/browser/ui/webui/chromeos/login/update_screen_handler.h"
34 #include "chrome/browser/ui/webui/chromeos/login/user_image_screen_handler.h" 33 #include "chrome/browser/ui/webui/chromeos/login/user_image_screen_handler.h"
35 #include "chrome/browser/ui/webui/options/chromeos/user_image_source.h" 34 #include "chrome/browser/ui/webui/options/chromeos/user_image_source.h"
36 #include "chrome/browser/ui/webui/theme_source.h" 35 #include "chrome/browser/ui/webui/theme_source.h"
36 #include "chrome/browser/ui/webui/web_ui_util.h"
37 #include "chrome/common/chrome_switches.h" 37 #include "chrome/common/chrome_switches.h"
38 #include "chrome/common/jstemplate_builder.h" 38 #include "chrome/common/jstemplate_builder.h"
39 #include "chrome/common/url_constants.h" 39 #include "chrome/common/url_constants.h"
40 #include "content/public/browser/url_data_source_delegate.h" 40 #include "content/public/browser/url_data_source.h"
41 #include "content/public/browser/web_contents.h" 41 #include "content/public/browser/web_contents.h"
42 #include "content/public/browser/web_ui.h" 42 #include "content/public/browser/web_ui.h"
43 #include "grit/browser_resources.h" 43 #include "grit/browser_resources.h"
44 #include "ui/base/resource/resource_bundle.h" 44 #include "ui/base/resource/resource_bundle.h"
45 45
46 using content::WebContents; 46 using content::WebContents;
47 47
48 namespace { 48 namespace {
49 49
50 // Path for a stripped down login page that does not have OOBE elements. 50 // Path for a stripped down login page that does not have OOBE elements.
51 const char kLoginPath[] = "login"; 51 const char kLoginPath[] = "login";
52 52
53 // Path for the enterprise enrollment gaia page hosting. 53 // Path for the enterprise enrollment gaia page hosting.
54 const char kEnterpriseEnrollmentGaiaLoginPath[] = "gaialogin"; 54 const char kEnterpriseEnrollmentGaiaLoginPath[] = "gaialogin";
55 55
56 } // namespace 56 } // namespace
57 57
58 namespace chromeos { 58 namespace chromeos {
59 59
60 class OobeUIHTMLSource : public content::URLDataSourceDelegate { 60 class OobeUIHTMLSource : public content::URLDataSource {
61 public: 61 public:
62 explicit OobeUIHTMLSource(DictionaryValue* localized_strings); 62 explicit OobeUIHTMLSource(DictionaryValue* localized_strings);
63 63
64 // content::URLDataSourceDelegate implementation. 64 // content::URLDataSource implementation.
65 virtual std::string GetSource() OVERRIDE; 65 virtual std::string GetSource() OVERRIDE;
66 virtual void StartDataRequest(const std::string& path, 66 virtual void StartDataRequest(
67 bool is_incognito, 67 const std::string& path,
68 int request_id); 68 bool is_incognito,
69 const content::URLDataSource::GotDataCallback& callback);
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 : localized_strings_(localized_strings) { 86 : localized_strings_(localized_strings) {
86 } 87 }
87 88
88 std::string OobeUIHTMLSource::GetSource() { 89 std::string OobeUIHTMLSource::GetSource() {
89 return chrome::kChromeUIOobeHost; 90 return chrome::kChromeUIOobeHost;
90 } 91 }
91 92
92 void OobeUIHTMLSource::StartDataRequest(const std::string& path, 93 void OobeUIHTMLSource::StartDataRequest(
93 bool is_incognito, 94 const std::string& path,
94 int request_id) { 95 bool is_incognito,
96 const content::URLDataSource::GotDataCallback& callback) {
95 if (UserManager::Get()->IsUserLoggedIn() && 97 if (UserManager::Get()->IsUserLoggedIn() &&
96 !UserManager::Get()->IsLoggedInAsStub() && 98 !UserManager::Get()->IsLoggedInAsStub() &&
97 !ScreenLocker::default_screen_locker()) { 99 !ScreenLocker::default_screen_locker()) {
98 scoped_refptr<base::RefCountedBytes> empty_bytes = 100 scoped_refptr<base::RefCountedBytes> empty_bytes =
99 new base::RefCountedBytes(); 101 new base::RefCountedBytes();
100 url_data_source()->SendResponse(request_id, empty_bytes); 102 callback.Run(empty_bytes);
101 return; 103 return;
102 } 104 }
103 105
104 std::string response; 106 std::string response;
105 if (chromeos::KioskModeSettings::Get()->IsKioskModeEnabled()) 107 if (chromeos::KioskModeSettings::Get()->IsKioskModeEnabled())
106 response = GetDataResource(IDR_DEMO_USER_LOGIN_HTML); 108 response = GetDataResource(IDR_DEMO_USER_LOGIN_HTML);
107 else if (path.empty()) 109 else if (path.empty())
108 response = GetDataResource(IDR_OOBE_HTML); 110 response = GetDataResource(IDR_OOBE_HTML);
109 else if (path == kLoginPath) 111 else if (path == kLoginPath)
110 response = GetDataResource(IDR_LOGIN_HTML); 112 response = GetDataResource(IDR_LOGIN_HTML);
111 else if (path == kEnterpriseEnrollmentGaiaLoginPath) 113 else if (path == kEnterpriseEnrollmentGaiaLoginPath)
112 response = GetDataResource(IDR_GAIA_LOGIN_HTML); 114 response = GetDataResource(IDR_GAIA_LOGIN_HTML);
113 115
114 url_data_source()->SendResponse( 116 callback.Run(base::RefCountedString::TakeString(&response));
115 request_id, base::RefCountedString::TakeString(&response));
116 } 117 }
117 118
118 std::string OobeUIHTMLSource::GetDataResource(int resource_id) const { 119 std::string OobeUIHTMLSource::GetDataResource(int resource_id) const {
119 const base::StringPiece html( 120 const base::StringPiece html(
120 ResourceBundle::GetSharedInstance().GetRawDataResource( 121 ResourceBundle::GetSharedInstance().GetRawDataResource(
121 resource_id)); 122 resource_id));
122 return jstemplate_builder::GetI18nTemplateHtml(html, 123 return jstemplate_builder::GetI18nTemplateHtml(html,
123 localized_strings_.get()); 124 localized_strings_.get());
124 } 125 }
125 126
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 // WebUI implementation of the LoginDisplayHost opens HTML page directly, 265 // WebUI implementation of the LoginDisplayHost opens HTML page directly,
265 // without opening OOBE page. 266 // without opening OOBE page.
266 NOTREACHED(); 267 NOTREACHED();
267 return NULL; 268 return NULL;
268 } 269 }
269 270
270 void OobeUI::GetLocalizedStrings(base::DictionaryValue* localized_strings) { 271 void OobeUI::GetLocalizedStrings(base::DictionaryValue* localized_strings) {
271 // Note, handlers_[0] is a GenericHandler used by the WebUI. 272 // Note, handlers_[0] is a GenericHandler used by the WebUI.
272 for (size_t i = 0; i < handlers_.size(); ++i) 273 for (size_t i = 0; i < handlers_.size(); ++i)
273 handlers_[i]->GetLocalizedStrings(localized_strings); 274 handlers_[i]->GetLocalizedStrings(localized_strings);
274 URLDataSource::SetFontAndTextDirection(localized_strings); 275 web_ui_util::SetFontAndTextDirection(localized_strings);
275 276
276 #if defined(GOOGLE_CHROME_BUILD) 277 #if defined(GOOGLE_CHROME_BUILD)
277 localized_strings->SetString("buildType", "chrome"); 278 localized_strings->SetString("buildType", "chrome");
278 #else 279 #else
279 localized_strings->SetString("buildType", "chromium"); 280 localized_strings->SetString("buildType", "chromium");
280 #endif 281 #endif
281 282
282 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableNewOobe)) 283 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableNewOobe))
283 localized_strings->SetString("oobeType", "new"); 284 localized_strings->SetString("oobeType", "new");
284 else 285 else
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 void OobeUI::OnCurrentScreenChanged(const std::string& screen) { 366 void OobeUI::OnCurrentScreenChanged(const std::string& screen) {
366 if (screen_ids_.count(screen)) { 367 if (screen_ids_.count(screen)) {
367 current_screen_ = screen_ids_[screen]; 368 current_screen_ = screen_ids_[screen];
368 } else { 369 } else {
369 NOTREACHED() << "Screen should be registered in InitializeScreenMaps()"; 370 NOTREACHED() << "Screen should be registered in InitializeScreenMaps()";
370 current_screen_ = SCREEN_UNKNOWN; 371 current_screen_ = SCREEN_UNKNOWN;
371 } 372 }
372 } 373 }
373 374
374 } // namespace chromeos 375 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698