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

Side by Side Diff: chrome/browser/ui/webui/nacl_ui.cc

Issue 19079002: Enable pnacl by default (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Jan's code review fixes Created 7 years, 5 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/nacl_ui.h" 5 #include "chrome/browser/ui/webui/nacl_ui.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 results->SetString("key", key); 210 results->SetString("key", key);
211 results->SetString("value", value); 211 results->SetString("value", value);
212 list->Append(results); 212 list->Append(results);
213 } 213 }
214 214
215 // Generate an empty data-pair which acts as a line break. 215 // Generate an empty data-pair which acts as a line break.
216 void AddLineBreak(ListValue* list) { 216 void AddLineBreak(ListValue* list) {
217 AddPair(list, ASCIIToUTF16(""), ASCIIToUTF16("")); 217 AddPair(list, ASCIIToUTF16(""), ASCIIToUTF16(""));
218 } 218 }
219 219
220 // Check whether a commandline switch is turned on or off.
221 void ListFlagStatus(ListValue* list, const std::string& flag_label,
222 const std::string& flag_name) {
223 if (CommandLine::ForCurrentProcess()->HasSwitch(flag_name))
224 AddPair(list, ASCIIToUTF16(flag_label), ASCIIToUTF16("On"));
225 else
226 AddPair(list, ASCIIToUTF16(flag_label), ASCIIToUTF16("Off"));
227 }
228
229 void NaClDomHandler::HandleRequestNaClInfo(const ListValue* args) { 220 void NaClDomHandler::HandleRequestNaClInfo(const ListValue* args) {
230 page_has_requested_data_ = true; 221 page_has_requested_data_ = true;
231 // Force re-validation of pnacl's path in the next call to 222 // Force re-validation of pnacl's path in the next call to
232 // MaybeRespondToPage(), in case PNaCl went from not-installed 223 // MaybeRespondToPage(), in case PNaCl went from not-installed
233 // to installed since the request. 224 // to installed since the request.
234 pnacl_path_validated_ = false; 225 pnacl_path_validated_ = false;
235 MaybeRespondToPage(); 226 MaybeRespondToPage();
236 } 227 }
237 228
238 void NaClDomHandler::OnGotPlugins( 229 void NaClDomHandler::OnGotPlugins(
239 const std::vector<content::WebPluginInfo>& plugins) { 230 const std::vector<content::WebPluginInfo>& plugins) {
240 has_plugin_info_ = true; 231 has_plugin_info_ = true;
241 MaybeRespondToPage(); 232 MaybeRespondToPage();
242 } 233 }
243 234
244 void NaClDomHandler::PopulatePageInformation(DictionaryValue* naclInfo) { 235 void NaClDomHandler::PopulatePageInformation(DictionaryValue* naclInfo) {
James Hawkins 2013/07/24 18:27:22 This method is now 122 lines long (which is too lo
sehr 2013/07/24 22:30:52 I am reverting the UI refactoring for now, and hav
245 DCHECK(pnacl_path_validated_); 236 DCHECK(pnacl_path_validated_);
246 // Store Key-Value pairs of about-information. 237 // Store Key-Value pairs of about-information.
247 scoped_ptr<ListValue> list(new ListValue()); 238 scoped_ptr<ListValue> list(new ListValue());
248 239
249 // Obtain the Chrome version info. 240 // Obtain the Chrome version info.
250 chrome::VersionInfo version_info; 241 chrome::VersionInfo version_info;
251 AddPair(list.get(), 242 AddPair(list.get(),
252 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME), 243 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME),
253 ASCIIToUTF16(version_info.Version() + " (" + 244 ASCIIToUTF16(version_info.Version() + " (" +
254 chrome::VersionInfo::GetVersionStringModifier() + ")")); 245 chrome::VersionInfo::GetVersionStringModifier() + ")"));
(...skipping 25 matching lines...) Expand all
280 ASCIIToUTF16(os_label)); 271 ASCIIToUTF16(os_label));
281 272
282 AddLineBreak(list.get()); 273 AddLineBreak(list.get());
283 274
284 // Obtain the version of the NaCl plugin. 275 // Obtain the version of the NaCl plugin.
285 std::vector<content::WebPluginInfo> info_array; 276 std::vector<content::WebPluginInfo> info_array;
286 PluginService::GetInstance()->GetPluginInfoArray( 277 PluginService::GetInstance()->GetPluginInfoArray(
287 GURL(), "application/x-nacl", false, &info_array, NULL); 278 GURL(), "application/x-nacl", false, &info_array, NULL);
288 string16 nacl_version; 279 string16 nacl_version;
289 string16 nacl_key = ASCIIToUTF16("NaCl plugin"); 280 string16 nacl_key = ASCIIToUTF16("NaCl plugin");
281 bool plugin_enabled = true;
James Hawkins 2013/07/24 18:27:22 This var being set in so many places is not very r
sehr 2013/07/24 22:30:52 The refactoring CL will address this issue.
290 if (info_array.empty()) { 282 if (info_array.empty()) {
291 AddPair(list.get(), nacl_key, ASCIIToUTF16("Disabled")); 283 AddPair(list.get(), nacl_key, ASCIIToUTF16("Disabled"));
284 plugin_enabled = false;
292 } else { 285 } else {
293 PluginPrefs* plugin_prefs = 286 PluginPrefs* plugin_prefs =
294 PluginPrefs::GetForProfile(Profile::FromWebUI(web_ui())).get(); 287 PluginPrefs::GetForProfile(Profile::FromWebUI(web_ui())).get();
295 288
296 // Only the 0th plugin is used. 289 // Only the 0th plugin is used.
297 nacl_version = info_array[0].version + ASCIIToUTF16(" ") + 290 nacl_version = info_array[0].version + ASCIIToUTF16(" ") +
298 info_array[0].path.LossyDisplayName(); 291 info_array[0].path.LossyDisplayName();
299 if (!plugin_prefs->IsPluginEnabled(info_array[0])) { 292 if (!plugin_prefs->IsPluginEnabled(info_array[0])) {
293 plugin_enabled = false;
300 nacl_version += ASCIIToUTF16(" (Disabled in profile prefs)"); 294 nacl_version += ASCIIToUTF16(" (Disabled in profile prefs)");
301 AddPair(list.get(), nacl_key, nacl_version);
302 } 295 }
303 296
304 AddPair(list.get(), nacl_key, nacl_version); 297 AddPair(list.get(), nacl_key, nacl_version);
305 298
306 // Mark the rest as not used. 299 // Mark the rest as not used.
307 for (size_t i = 1; i < info_array.size(); ++i) { 300 for (size_t i = 1; i < info_array.size(); ++i) {
308 nacl_version = info_array[i].version + ASCIIToUTF16(" ") + 301 nacl_version = info_array[i].version + ASCIIToUTF16(" ") +
309 info_array[i].path.LossyDisplayName(); 302 info_array[i].path.LossyDisplayName();
310 nacl_version += ASCIIToUTF16(" (not used)"); 303 nacl_version += ASCIIToUTF16(" (not used)");
311 if (!plugin_prefs->IsPluginEnabled(info_array[i])) 304 if (!plugin_prefs->IsPluginEnabled(info_array[i])) {
312 nacl_version += ASCIIToUTF16(" (Disabled in profile prefs)"); 305 nacl_version += ASCIIToUTF16(" (Disabled in profile prefs)");
306 }
313 AddPair(list.get(), nacl_key, nacl_version); 307 AddPair(list.get(), nacl_key, nacl_version);
314 } 308 }
315 } 309 }
316 310
317 // Check that commandline flags are enabled. 311 AddLineBreak(list.get());
318 ListFlagStatus(list.get(), "Flag '--enable-nacl'", switches::kEnableNaCl);
319 312
320 AddLineBreak(list.get()); 313 // Display whether PNaCl is enabled.
314 string16 pnacl_enabled_string = ASCIIToUTF16("Enabled");
315 if (!plugin_enabled) {
316 pnacl_enabled_string = ASCIIToUTF16("Disabled in profile prefs");
317 } else if (CommandLine::ForCurrentProcess()->HasSwitch(
318 switches::kDisablePnacl)) {
319 pnacl_enabled_string = ASCIIToUTF16("Disabled by flag '--disable-pnacl'");
320 }
321 AddPair(list.get(),
322 ASCIIToUTF16("Portable Native Client (PNaCl)"),
323 pnacl_enabled_string);
321 324
322 // Obtain the version of the PNaCl translator. 325 // Obtain the version of the PNaCl translator.
323 base::FilePath pnacl_path; 326 base::FilePath pnacl_path;
324 bool got_path = PathService::Get(chrome::DIR_PNACL_COMPONENT, &pnacl_path); 327 bool got_path = PathService::Get(chrome::DIR_PNACL_COMPONENT, &pnacl_path);
325 if (!got_path || pnacl_path.empty() || !pnacl_path_exists_) { 328 if (!got_path || pnacl_path.empty() || !pnacl_path_exists_) {
326 AddPair(list.get(), 329 AddPair(list.get(),
327 ASCIIToUTF16("PNaCl translator"), 330 ASCIIToUTF16("PNaCl translator"),
328 ASCIIToUTF16("Not installed")); 331 ASCIIToUTF16("Not installed"));
329 } else { 332 } else {
330 AddPair(list.get(), 333 AddPair(list.get(),
331 ASCIIToUTF16("PNaCl translator path"), 334 ASCIIToUTF16("PNaCl translator path"),
332 pnacl_path.LossyDisplayName()); 335 pnacl_path.LossyDisplayName());
333 // Version string is part of the directory name: 336 // Version string is part of the directory name:
334 // pnacl/<version>/_platform_specific/<arch>/[files] 337 // pnacl/<version>/_platform_specific/<arch>/[files]
335 // Keep in sync with pnacl_component_installer.cc. 338 // Keep in sync with pnacl_component_installer.cc.
336 AddPair(list.get(), 339 AddPair(list.get(),
337 ASCIIToUTF16("PNaCl translator version"), 340 ASCIIToUTF16("PNaCl translator version"),
338 pnacl_path.DirName().DirName().BaseName().LossyDisplayName()); 341 pnacl_path.DirName().DirName().BaseName().LossyDisplayName());
339 } 342 }
340 343
341 ListFlagStatus(list.get(), "Flag '--enable-pnacl'", switches::kEnablePnacl); 344 AddLineBreak(list.get());
345
346 // Display whether NaCl is enabled.
347
348 string16 nacl_enabled_string = ASCIIToUTF16("Disabled");
349 if (plugin_enabled &&
350 CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableNaCl)) {
351 nacl_enabled_string = ASCIIToUTF16("Enabled by flag '--enable-nacl'");
352 }
353 AddPair(list.get(),
354 ASCIIToUTF16("Native Client (non-portable, outside web store)"),
355 nacl_enabled_string);
356
342 // naclInfo will take ownership of list, and clean it up on destruction. 357 // naclInfo will take ownership of list, and clean it up on destruction.
343 naclInfo->Set("naclInfo", list.release()); 358 naclInfo->Set("naclInfo", list.release());
344 } 359 }
345 360
346 void NaClDomHandler::DidValidatePnaclPath(bool is_valid) { 361 void NaClDomHandler::DidValidatePnaclPath(bool is_valid) {
347 pnacl_path_validated_ = true; 362 pnacl_path_validated_ = true;
348 pnacl_path_exists_ = is_valid; 363 pnacl_path_exists_ = is_valid;
349 MaybeRespondToPage(); 364 MaybeRespondToPage();
350 } 365 }
351 366
(...skipping 24 matching lines...) Expand all
376 391
377 NaClUI::NaClUI(content::WebUI* web_ui) : WebUIController(web_ui) { 392 NaClUI::NaClUI(content::WebUI* web_ui) : WebUIController(web_ui) {
378 content::RecordAction(UserMetricsAction("ViewAboutNaCl")); 393 content::RecordAction(UserMetricsAction("ViewAboutNaCl"));
379 394
380 web_ui->AddMessageHandler(new NaClDomHandler()); 395 web_ui->AddMessageHandler(new NaClDomHandler());
381 396
382 // Set up the about:nacl source. 397 // Set up the about:nacl source.
383 Profile* profile = Profile::FromWebUI(web_ui); 398 Profile* profile = Profile::FromWebUI(web_ui);
384 content::WebUIDataSource::Add(profile, CreateNaClUIHTMLSource()); 399 content::WebUIDataSource::Add(profile, CreateNaClUIHTMLSource());
385 } 400 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698