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

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: Update with code review feedback. 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(
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
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;
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); 295 AddPair(list.get(), nacl_key, nacl_version);
302 } 296 }
303 297
304 AddPair(list.get(), nacl_key, nacl_version); 298 AddPair(list.get(), nacl_key, nacl_version);
305 299
306 // Mark the rest as not used. 300 // Mark the rest as not used.
307 for (size_t i = 1; i < info_array.size(); ++i) { 301 for (size_t i = 1; i < info_array.size(); ++i) {
308 nacl_version = info_array[i].version + ASCIIToUTF16(" ") + 302 nacl_version = info_array[i].version + ASCIIToUTF16(" ") +
309 info_array[i].path.LossyDisplayName(); 303 info_array[i].path.LossyDisplayName();
310 nacl_version += ASCIIToUTF16(" (not used)"); 304 nacl_version += ASCIIToUTF16(" (not used)");
311 if (!plugin_prefs->IsPluginEnabled(info_array[i])) 305 if (!plugin_prefs->IsPluginEnabled(info_array[i])) {
306 plugin_enabled = false;
Mark Seaborn 2013/07/22 23:28:10 I don't understand this. If there are multiple pl
sehr 2013/07/23 22:03:26 There weren't multiple plugins handling the mime t
312 nacl_version += ASCIIToUTF16(" (Disabled in profile prefs)"); 307 nacl_version += ASCIIToUTF16(" (Disabled in profile prefs)");
308 }
313 AddPair(list.get(), nacl_key, nacl_version); 309 AddPair(list.get(), nacl_key, nacl_version);
314 } 310 }
315 } 311 }
316 312
317 // Check that commandline flags are enabled. 313 // Display whether NaCl is enabled.
318 ListFlagStatus(list.get(), "Flag '--enable-nacl'", switches::kEnableNaCl); 314 string16 nacl_enabled_string = ASCIIToUTF16("Disabled");
315 if (plugin_enabled &&
316 CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableNaCl)) {
317 nacl_enabled_string = ASCIIToUTF16("Enabled by flag '--enable-nacl'");
318 }
319 AddPair(list.get(), ASCIIToUTF16("Native Client"), nacl_enabled_string);
319 320
320 AddLineBreak(list.get()); 321 AddLineBreak(list.get());
321 322
323 // Display whether PNaCl is enabled.
324 string16 pnacl_enabled_string = ASCIIToUTF16("Enabled");
325 if (!plugin_enabled) {
326 pnacl_enabled_string = ASCIIToUTF16("Disabled in profile prefs");
327 }
328 else if (CommandLine::ForCurrentProcess()->HasSwitch(
Mark Seaborn 2013/07/22 23:28:10 Should go on previous line as "} else if"
sehr 2013/07/23 22:03:26 Done.
329 switches::kDisablePnacl)) {
Mark Seaborn 2013/07/22 23:28:10 Fix indentation here. // good if (SomeFunc(
sehr 2013/07/23 22:03:26 Done.
330 pnacl_enabled_string = ASCIIToUTF16("Disabled by flag '--disable-pnacl'");
331 }
332 AddPair(list.get(),
333 ASCIIToUTF16("Portable Native Client"),
334 pnacl_enabled_string);
335
322 // Obtain the version of the PNaCl translator. 336 // Obtain the version of the PNaCl translator.
323 base::FilePath pnacl_path; 337 base::FilePath pnacl_path;
324 bool got_path = PathService::Get(chrome::DIR_PNACL_COMPONENT, &pnacl_path); 338 bool got_path = PathService::Get(chrome::DIR_PNACL_COMPONENT, &pnacl_path);
325 if (!got_path || pnacl_path.empty() || !pnacl_path_exists_) { 339 if (!got_path || pnacl_path.empty() || !pnacl_path_exists_) {
326 AddPair(list.get(), 340 AddPair(list.get(),
327 ASCIIToUTF16("PNaCl translator"), 341 ASCIIToUTF16("PNaCl translator"),
328 ASCIIToUTF16("Not installed")); 342 ASCIIToUTF16("Not installed"));
329 } else { 343 } else {
330 AddPair(list.get(), 344 AddPair(list.get(),
331 ASCIIToUTF16("PNaCl translator path"), 345 ASCIIToUTF16("PNaCl translator path"),
332 pnacl_path.LossyDisplayName()); 346 pnacl_path.LossyDisplayName());
333 // Version string is part of the directory name: 347 // Version string is part of the directory name:
334 // pnacl/<version>/_platform_specific/<arch>/[files] 348 // pnacl/<version>/_platform_specific/<arch>/[files]
335 // Keep in sync with pnacl_component_installer.cc. 349 // Keep in sync with pnacl_component_installer.cc.
336 AddPair(list.get(), 350 AddPair(list.get(),
337 ASCIIToUTF16("PNaCl translator version"), 351 ASCIIToUTF16("PNaCl translator version"),
338 pnacl_path.DirName().DirName().BaseName().LossyDisplayName()); 352 pnacl_path.DirName().DirName().BaseName().LossyDisplayName());
339 } 353 }
340 354
341 ListFlagStatus(list.get(), "Flag '--enable-pnacl'", switches::kEnablePnacl);
342 // naclInfo will take ownership of list, and clean it up on destruction. 355 // naclInfo will take ownership of list, and clean it up on destruction.
343 naclInfo->Set("naclInfo", list.release()); 356 naclInfo->Set("naclInfo", list.release());
344 } 357 }
345 358
346 void NaClDomHandler::DidValidatePnaclPath(bool is_valid) { 359 void NaClDomHandler::DidValidatePnaclPath(bool is_valid) {
347 pnacl_path_validated_ = true; 360 pnacl_path_validated_ = true;
348 pnacl_path_exists_ = is_valid; 361 pnacl_path_exists_ = is_valid;
349 MaybeRespondToPage(); 362 MaybeRespondToPage();
350 } 363 }
351 364
(...skipping 24 matching lines...) Expand all
376 389
377 NaClUI::NaClUI(content::WebUI* web_ui) : WebUIController(web_ui) { 390 NaClUI::NaClUI(content::WebUI* web_ui) : WebUIController(web_ui) {
378 content::RecordAction(UserMetricsAction("ViewAboutNaCl")); 391 content::RecordAction(UserMetricsAction("ViewAboutNaCl"));
379 392
380 web_ui->AddMessageHandler(new NaClDomHandler()); 393 web_ui->AddMessageHandler(new NaClDomHandler());
381 394
382 // Set up the about:nacl source. 395 // Set up the about:nacl source.
383 Profile* profile = Profile::FromWebUI(web_ui); 396 Profile* profile = Profile::FromWebUI(web_ui);
384 content::WebUIDataSource::Add(profile, CreateNaClUIHTMLSource()); 397 content::WebUIDataSource::Add(profile, CreateNaClUIHTMLSource());
385 } 398 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698