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

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

Issue 21004005: Made small refactoring of OobeUI. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 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>
ygorshenin1 2013/07/30 15:06:34 nit: delete <string> inclusion.
dzhioev (left Google) 2013/07/30 16:18:55 Done.
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/enrollment/enrollment_screen_actor.h" 16 #include "chrome/browser/chromeos/login/enrollment/enrollment_screen_actor.h"
17 #include "chrome/browser/chromeos/login/login_display_host_impl.h" 17 #include "chrome/browser/chromeos/login/login_display_host_impl.h"
(...skipping 29 matching lines...) Expand all
47 #include "content/public/browser/web_ui.h" 47 #include "content/public/browser/web_ui.h"
48 #include "content/public/browser/web_ui_data_source.h" 48 #include "content/public/browser/web_ui_data_source.h"
49 #include "grit/browser_resources.h" 49 #include "grit/browser_resources.h"
50 #include "ui/base/resource/resource_bundle.h" 50 #include "ui/base/resource/resource_bundle.h"
51 #include "ui/webui/web_ui_util.h" 51 #include "ui/webui/web_ui_util.h"
52 52
53 namespace chromeos { 53 namespace chromeos {
54 54
55 namespace { 55 namespace {
56 56
57 // Path for a stripped down login page that does not have OOBE elements. 57 const char kOobeDisplay[] = "oobe";
58 const char kLoginPath[] = "login#login"; 58 const char kLoginDisplay[] = "login";
59 const char kLockDisplay[] = "lock";
60 const char kUserAddingDisplay[] = "user-adding";
61
62 const char* kKnownDisplayTypes[] = {
63 kOobeDisplay,
64 kLoginDisplay,
65 kLockDisplay,
66 kUserAddingDisplay
67 };
59 68
60 const char kStringsJSPath[] = "strings.js"; 69 const char kStringsJSPath[] = "strings.js";
61 const char kLoginJSPath[] = "login.js"; 70 const char kLoginJSPath[] = "login.js";
62 const char kOobeJSPath[] = "oobe.js"; 71 const char kOobeJSPath[] = "oobe.js";
63 const char kKeyboardUtilsJSPath[] = "keyboard_utils.js"; 72 const char kKeyboardUtilsJSPath[] = "keyboard_utils.js";
64 const char kDemoUserLoginJSPath[] = "demo_user_login.js"; 73 const char kDemoUserLoginJSPath[] = "demo_user_login.js";
65 74
66 // Paths for deferred resource loading. 75 // Paths for deferred resource loading.
67 const char kEnrollmentHTMLPath[] = "enrollment.html"; 76 const char kEnrollmentHTMLPath[] = "enrollment.html";
68 const char kEnrollmentCSSPath[] = "enrollment.css"; 77 const char kEnrollmentCSSPath[] = "enrollment.css";
(...skipping 10 matching lines...) Expand all
79 new base::RefCountedBytes(); 88 new base::RefCountedBytes();
80 callback.Run(empty_bytes.get()); 89 callback.Run(empty_bytes.get());
81 return true; 90 return true;
82 } 91 }
83 92
84 return false; 93 return false;
85 } 94 }
86 95
87 // Creates a WebUIDataSource for chrome://oobe 96 // Creates a WebUIDataSource for chrome://oobe
88 content::WebUIDataSource* CreateOobeUIDataSource( 97 content::WebUIDataSource* CreateOobeUIDataSource(
89 const base::DictionaryValue& localized_strings) { 98 const base::DictionaryValue& localized_strings,
99 const std::string& display_type) {
90 content::WebUIDataSource* source = 100 content::WebUIDataSource* source =
91 content::WebUIDataSource::Create(chrome::kChromeUIOobeHost); 101 content::WebUIDataSource::Create(chrome::kChromeUIOobeHost);
92 source->SetUseJsonJSFormatV2(); 102 source->SetUseJsonJSFormatV2();
93 source->AddLocalizedStrings(localized_strings); 103 source->AddLocalizedStrings(localized_strings);
94 source->SetJsonPath(kStringsJSPath); 104 source->SetJsonPath(kStringsJSPath);
95 105
96 if (chromeos::KioskModeSettings::Get()->IsKioskModeEnabled()) { 106 if (chromeos::KioskModeSettings::Get()->IsKioskModeEnabled()) {
97 source->SetDefaultResource(IDR_DEMO_USER_LOGIN_HTML); 107 source->SetDefaultResource(IDR_DEMO_USER_LOGIN_HTML);
98 source->AddResourcePath(kDemoUserLoginJSPath, 108 source->AddResourcePath(kDemoUserLoginJSPath, IDR_DEMO_USER_LOGIN_JS);
99 IDR_DEMO_USER_LOGIN_JS);
100 return source; 109 return source;
101 } 110 }
102 111 if (display_type == kOobeDisplay) {
103 source->SetDefaultResource(IDR_OOBE_HTML); 112 source->SetDefaultResource(IDR_OOBE_HTML);
104 source->AddResourcePath(kOobeJSPath, 113 source->AddResourcePath(kOobeJSPath, IDR_OOBE_JS);
105 IDR_OOBE_JS); 114 } else {
106 source->AddResourcePath(kLoginPath, 115 source->SetDefaultResource(IDR_LOGIN_HTML);
107 IDR_LOGIN_HTML); 116 source->AddResourcePath(kLoginJSPath, IDR_LOGIN_JS);
108 source->AddResourcePath(kLoginJSPath, 117 }
109 IDR_LOGIN_JS); 118 source->AddResourcePath(kKeyboardUtilsJSPath, IDR_KEYBOARD_UTILS_JS);
110 source->AddResourcePath(kKeyboardUtilsJSPath,
111 IDR_KEYBOARD_UTILS_JS);
112 source->OverrideContentSecurityPolicyFrameSrc( 119 source->OverrideContentSecurityPolicyFrameSrc(
113 "frame-src chrome://terms/ " 120 "frame-src chrome://terms/ "
114 "chrome-extension://mfffpogegjflfpflabcdkioaeobkgjik/;"); 121 "chrome-extension://mfffpogegjflfpflabcdkioaeobkgjik/;");
115 122
116 // Serve deferred resources. 123 // Serve deferred resources.
117 source->AddResourcePath(kEnrollmentHTMLPath, 124 source->AddResourcePath(kEnrollmentHTMLPath, IDR_OOBE_ENROLLMENT_HTML);
118 IDR_OOBE_ENROLLMENT_HTML); 125 source->AddResourcePath(kEnrollmentCSSPath, IDR_OOBE_ENROLLMENT_CSS);
119 source->AddResourcePath(kEnrollmentCSSPath, 126 source->AddResourcePath(kEnrollmentJSPath, IDR_OOBE_ENROLLMENT_JS);
120 IDR_OOBE_ENROLLMENT_CSS);
121 source->AddResourcePath(kEnrollmentJSPath,
122 IDR_OOBE_ENROLLMENT_JS);
123 127
124 return source; 128 return source;
125 } 129 }
126 130
131 std::string GetDisplayType(const GURL& url) {
132 std::string path = url.path().size() ? url.path().substr(1) : "";
133 if (std::find(kKnownDisplayTypes,
134 kKnownDisplayTypes + arraysize(kKnownDisplayTypes),
135 path) == kKnownDisplayTypes + arraysize(kKnownDisplayTypes)) {
136 LOG(ERROR) << "Unknown display type '" + path + "'. Setting default.";
ygorshenin1 2013/07/30 15:06:34 nit: if possible don't intermix IO operators with
dzhioev (left Google) 2013/07/30 16:18:55 Done.
137 return kLoginDisplay;
138 }
139 return path;
140 }
141
127 } // namespace 142 } // namespace
128 143
129 // static 144 // static
130 const char OobeUI::kScreenOobeNetwork[] = "connect"; 145 const char OobeUI::kScreenOobeNetwork[] = "connect";
131 const char OobeUI::kScreenOobeEula[] = "eula"; 146 const char OobeUI::kScreenOobeEula[] = "eula";
132 const char OobeUI::kScreenOobeUpdate[] = "update"; 147 const char OobeUI::kScreenOobeUpdate[] = "update";
133 const char OobeUI::kScreenOobeEnrollment[] = "oauth-enrollment"; 148 const char OobeUI::kScreenOobeEnrollment[] = "oauth-enrollment";
134 const char OobeUI::kScreenGaiaSignin[] = "gaia-signin"; 149 const char OobeUI::kScreenGaiaSignin[] = "gaia-signin";
135 const char OobeUI::kScreenAccountPicker[] = "account-picker"; 150 const char OobeUI::kScreenAccountPicker[] = "account-picker";
136 const char OobeUI::kScreenKioskAutolaunch[] = "autolaunch"; 151 const char OobeUI::kScreenKioskAutolaunch[] = "autolaunch";
137 const char OobeUI::kScreenKioskEnable[] = "kiosk-enable"; 152 const char OobeUI::kScreenKioskEnable[] = "kiosk-enable";
138 const char OobeUI::kScreenErrorMessage[] = "error-message"; 153 const char OobeUI::kScreenErrorMessage[] = "error-message";
139 const char OobeUI::kScreenUserImagePicker[] = "user-image"; 154 const char OobeUI::kScreenUserImagePicker[] = "user-image";
140 const char OobeUI::kScreenTpmError[] = "tpm-error-message"; 155 const char OobeUI::kScreenTpmError[] = "tpm-error-message";
141 const char OobeUI::kScreenPasswordChanged[] = "password-changed"; 156 const char OobeUI::kScreenPasswordChanged[] = "password-changed";
142 const char OobeUI::kScreenManagedUserCreationFlow[] 157 const char OobeUI::kScreenManagedUserCreationFlow[]
143 = "managed-user-creation"; 158 = "managed-user-creation";
144 const char OobeUI::kScreenTermsOfService[] = "terms-of-service"; 159 const char OobeUI::kScreenTermsOfService[] = "terms-of-service";
145 const char OobeUI::kScreenWrongHWID[] = "wrong-hwid"; 160 const char OobeUI::kScreenWrongHWID[] = "wrong-hwid";
146 161
147 OobeUI::OobeUI(content::WebUI* web_ui) 162 OobeUI::OobeUI(content::WebUI* web_ui, const GURL& url)
148 : WebUIController(web_ui), 163 : WebUIController(web_ui),
164 core_handler_(NULL),
149 update_screen_handler_(NULL), 165 update_screen_handler_(NULL),
150 network_screen_actor_(NULL), 166 network_screen_actor_(NULL),
151 eula_screen_actor_(NULL), 167 eula_screen_actor_(NULL),
152 reset_screen_actor_(NULL), 168 reset_screen_actor_(NULL),
153 autolaunch_screen_actor_(NULL), 169 autolaunch_screen_actor_(NULL),
154 kiosk_enable_screen_actor_(NULL), 170 kiosk_enable_screen_actor_(NULL),
155 wrong_hwid_screen_actor_(NULL), 171 wrong_hwid_screen_actor_(NULL),
156 locally_managed_user_creation_screen_actor_(NULL), 172 locally_managed_user_creation_screen_actor_(NULL),
157 error_screen_handler_(NULL), 173 error_screen_handler_(NULL),
158 signin_screen_handler_(NULL), 174 signin_screen_handler_(NULL),
159 terms_of_service_screen_actor_(NULL), 175 terms_of_service_screen_actor_(NULL),
160 user_image_screen_actor_(NULL), 176 user_image_screen_actor_(NULL),
161 kiosk_app_menu_handler_(NULL), 177 kiosk_app_menu_handler_(NULL),
162 current_screen_(SCREEN_UNKNOWN), 178 current_screen_(SCREEN_UNKNOWN),
163 ready_(false) { 179 ready_(false) {
180 display_type_ = GetDisplayType(url);
164 InitializeScreenMaps(); 181 InitializeScreenMaps();
165 182
166 network_state_informer_ = new NetworkStateInformer(); 183 network_state_informer_ = new NetworkStateInformer();
167 network_state_informer_->Init(); 184 network_state_informer_->Init();
168 185
169 core_handler_ = new CoreOobeHandler(this); 186 core_handler_ = new CoreOobeHandler(this);
170 AddScreenHandler(core_handler_); 187 AddScreenHandler(core_handler_);
171 core_handler_->SetDelegate(this); 188 core_handler_->SetDelegate(this);
172 189
173 AddScreenHandler(new NetworkDropdownHandler); 190 AddScreenHandler(new NetworkDropdownHandler);
174 191
175 update_screen_handler_ = new UpdateScreenHandler(); 192 update_screen_handler_ = new UpdateScreenHandler();
176 AddScreenHandler(update_screen_handler_); 193 AddScreenHandler(update_screen_handler_);
177 194
178 NetworkScreenHandler* network_screen_handler = new NetworkScreenHandler(); 195 if (display_type_ == kOobeDisplay) {
179 network_screen_actor_ = network_screen_handler; 196 NetworkScreenHandler* network_screen_handler = new NetworkScreenHandler();
180 AddScreenHandler(network_screen_handler); 197 network_screen_actor_ = network_screen_handler;
198 AddScreenHandler(network_screen_handler);
199 }
181 200
182 EulaScreenHandler* eula_screen_handler = new EulaScreenHandler(); 201 EulaScreenHandler* eula_screen_handler = new EulaScreenHandler();
183 eula_screen_actor_ = eula_screen_handler; 202 eula_screen_actor_ = eula_screen_handler;
184 AddScreenHandler(eula_screen_handler); 203 AddScreenHandler(eula_screen_handler);
185 204
186 ResetScreenHandler* reset_screen_handler = new ResetScreenHandler(); 205 ResetScreenHandler* reset_screen_handler = new ResetScreenHandler();
187 reset_screen_actor_ = reset_screen_handler; 206 reset_screen_actor_ = reset_screen_handler;
188 AddScreenHandler(reset_screen_handler); 207 AddScreenHandler(reset_screen_handler);
189 208
190 KioskAutolaunchScreenHandler* autolaunch_screen_handler = 209 KioskAutolaunchScreenHandler* autolaunch_screen_handler =
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 ThemeSource* theme = new ThemeSource(profile); 262 ThemeSource* theme = new ThemeSource(profile);
244 content::URLDataSource::Add(profile, theme); 263 content::URLDataSource::Add(profile, theme);
245 264
246 // Set up the chrome://terms/ data source, for EULA content. 265 // Set up the chrome://terms/ data source, for EULA content.
247 AboutUIHTMLSource* about_source = 266 AboutUIHTMLSource* about_source =
248 new AboutUIHTMLSource(chrome::kChromeUITermsHost, profile); 267 new AboutUIHTMLSource(chrome::kChromeUITermsHost, profile);
249 content::URLDataSource::Add(profile, about_source); 268 content::URLDataSource::Add(profile, about_source);
250 269
251 // Set up the chrome://oobe/ source. 270 // Set up the chrome://oobe/ source.
252 content::WebUIDataSource::Add(profile, 271 content::WebUIDataSource::Add(profile,
253 CreateOobeUIDataSource(localized_strings)); 272 CreateOobeUIDataSource(localized_strings,
273 display_type_));
254 274
255 // Set up the chrome://userimage/ source. 275 // Set up the chrome://userimage/ source.
256 options::UserImageSource* user_image_source = 276 options::UserImageSource* user_image_source =
257 new options::UserImageSource(); 277 new options::UserImageSource();
258 content::URLDataSource::Add(profile, user_image_source); 278 content::URLDataSource::Add(profile, user_image_source);
259 } 279 }
260 280
261 OobeUI::~OobeUI() { 281 OobeUI::~OobeUI() {
262 core_handler_->SetDelegate(NULL); 282 core_handler_->SetDelegate(NULL);
263 } 283 }
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 void OobeUI::OnCurrentScreenChanged(const std::string& screen) { 446 void OobeUI::OnCurrentScreenChanged(const std::string& screen) {
427 if (screen_ids_.count(screen)) { 447 if (screen_ids_.count(screen)) {
428 current_screen_ = screen_ids_[screen]; 448 current_screen_ = screen_ids_[screen];
429 } else { 449 } else {
430 NOTREACHED() << "Screen should be registered in InitializeScreenMaps()"; 450 NOTREACHED() << "Screen should be registered in InitializeScreenMaps()";
431 current_screen_ = SCREEN_UNKNOWN; 451 current_screen_ = SCREEN_UNKNOWN;
432 } 452 }
433 } 453 }
434 454
435 } // namespace chromeos 455 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698