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

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

Issue 22415017: Read pnacl version from common .json file instead of using dirname. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleanup 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/file_util.h" 13 #include "base/file_util.h"
14 #include "base/json/json_file_value_serializer.h"
14 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
15 #include "base/path_service.h" 16 #include "base/path_service.h"
16 #include "base/strings/string16.h" 17 #include "base/strings/string16.h"
17 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
18 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
19 #include "base/values.h" 20 #include "base/values.h"
20 #include "chrome/browser/plugins/plugin_prefs.h" 21 #include "chrome/browser/plugins/plugin_prefs.h"
21 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/common/chrome_paths.h" 23 #include "chrome/common/chrome_paths.h"
23 #include "chrome/common/chrome_switches.h" 24 #include "chrome/common/chrome_switches.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 // WebUIMessageHandler implementation. 78 // WebUIMessageHandler implementation.
78 virtual void RegisterMessages() OVERRIDE; 79 virtual void RegisterMessages() OVERRIDE;
79 80
80 // Callback for the "requestNaClInfo" message. 81 // Callback for the "requestNaClInfo" message.
81 void HandleRequestNaClInfo(const ListValue* args); 82 void HandleRequestNaClInfo(const ListValue* args);
82 83
83 // Callback for the NaCl plugin information. 84 // Callback for the NaCl plugin information.
84 void OnGotPlugins(const std::vector<content::WebPluginInfo>& plugins); 85 void OnGotPlugins(const std::vector<content::WebPluginInfo>& plugins);
85 86
86 // A helper callback that receives the result of checking if PNaCl path 87 // A helper callback that receives the result of checking if PNaCl path
87 // exists. |is_valid| is true if the PNaCl path that was returned by 88 // exists and checking the PNaCl |version|. |is_valid| is true if the PNaCl
88 // PathService is valid, and false otherwise. 89 // path that was returned by PathService is valid, and false otherwise.
89 void DidValidatePnaclPath(bool* is_valid); 90 void DidCheckPathAndVersion(bool* is_valid, std::string* version);
Dan Beam 2013/08/09 01:12:29 ^ can this be private?
jvoung (off chromium) 2013/08/09 03:31:53 Yep, some of the other callbacks can be too. Done.
90 91
91 private: 92 private:
92 // Called when enough information is gathered to return data back to the page. 93 // Called when enough information is gathered to return data back to the page.
93 void MaybeRespondToPage(); 94 void MaybeRespondToPage();
94 95
95 // Helper for MaybeRespondToPage -- called after enough information 96 // Helper for MaybeRespondToPage -- called after enough information
96 // is gathered. 97 // is gathered.
97 void PopulatePageInformation(DictionaryValue* naclInfo); 98 void PopulatePageInformation(DictionaryValue* naclInfo);
98 99
99 // Factory for the creating refs in callbacks. 100 // Factory for the creating refs in callbacks.
100 base::WeakPtrFactory<NaClDomHandler> weak_ptr_factory_; 101 base::WeakPtrFactory<NaClDomHandler> weak_ptr_factory_;
101 102
102 // Returns whether the specified plugin is enabled. 103 // Returns whether the specified plugin is enabled.
103 bool isPluginEnabled(size_t plugin_index); 104 bool isPluginEnabled(size_t plugin_index);
104 105
105 // Adds information regarding the operating system and chrome version to list. 106 // Adds information regarding the operating system and chrome version to list.
106 void AddOperatingSystemInfo(ListValue* list); 107 void AddOperatingSystemInfo(ListValue* list);
107 108
108 // Adds the list of plugins for NaCl to list. 109 // Adds the list of plugins for NaCl to list.
109 void AddPluginList(ListValue* list); 110 void AddPluginList(ListValue* list);
110 111
111 // Adds the information relevant to PNaCl (e.g., enablement, paths) to list. 112 // Adds the information relevant to PNaCl (e.g., enablement, paths, version)
113 // to the list.
112 void AddPnaclInfo(ListValue* list); 114 void AddPnaclInfo(ListValue* list);
113 115
114 // Adds the information relevant to NaCl to list. 116 // Adds the information relevant to NaCl to list.
115 void AddNaClInfo(ListValue* list); 117 void AddNaClInfo(ListValue* list);
116 118
117 // Whether the page has requested data. 119 // Whether the page has requested data.
118 bool page_has_requested_data_; 120 bool page_has_requested_data_;
119 121
120 // Whether the plugin information is ready. 122 // Whether the plugin information is ready.
121 bool has_plugin_info_; 123 bool has_plugin_info_;
122 124
123 // Whether PNaCl path was validated. PathService can return a path 125 // Whether PNaCl path was validated. PathService can return a path
124 // that does not exists, so it needs to be validated. 126 // that does not exists, so it needs to be validated.
125 bool pnacl_path_validated_; 127 bool pnacl_path_validated_;
126 bool pnacl_path_exists_; 128 bool pnacl_path_exists_;
129 std::string pnacl_version_string_;
127 130
128 DISALLOW_COPY_AND_ASSIGN(NaClDomHandler); 131 DISALLOW_COPY_AND_ASSIGN(NaClDomHandler);
129 }; 132 };
130 133
131 NaClDomHandler::NaClDomHandler() 134 NaClDomHandler::NaClDomHandler()
132 : weak_ptr_factory_(this), 135 : weak_ptr_factory_(this),
133 page_has_requested_data_(false), 136 page_has_requested_data_(false),
134 has_plugin_info_(false), 137 has_plugin_info_(false),
135 pnacl_path_validated_(false), 138 pnacl_path_validated_(false),
136 pnacl_path_exists_(false) { 139 pnacl_path_exists_(false) {
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 base::FilePath pnacl_path; 261 base::FilePath pnacl_path;
259 bool got_path = PathService::Get(chrome::DIR_PNACL_COMPONENT, &pnacl_path); 262 bool got_path = PathService::Get(chrome::DIR_PNACL_COMPONENT, &pnacl_path);
260 if (!got_path || pnacl_path.empty() || !pnacl_path_exists_) { 263 if (!got_path || pnacl_path.empty() || !pnacl_path_exists_) {
261 AddPair(list, 264 AddPair(list,
262 ASCIIToUTF16("PNaCl translator"), 265 ASCIIToUTF16("PNaCl translator"),
263 ASCIIToUTF16("Not installed")); 266 ASCIIToUTF16("Not installed"));
264 } else { 267 } else {
265 AddPair(list, 268 AddPair(list,
266 ASCIIToUTF16("PNaCl translator path"), 269 ASCIIToUTF16("PNaCl translator path"),
267 pnacl_path.LossyDisplayName()); 270 pnacl_path.LossyDisplayName());
268 // Version string is part of the directory name:
269 // pnacl/<version>/_platform_specific/<arch>/[files]
270 // Keep in sync with pnacl_component_installer.cc.
271 AddPair(list, 271 AddPair(list,
272 ASCIIToUTF16("PNaCl translator version"), 272 ASCIIToUTF16("PNaCl translator version"),
273 pnacl_path.DirName().DirName().BaseName().LossyDisplayName()); 273 ASCIIToUTF16(pnacl_version_string_));
274 } 274 }
275 AddLineBreak(list); 275 AddLineBreak(list);
276 } 276 }
277 277
278 void NaClDomHandler::AddNaClInfo(ListValue* list) { 278 void NaClDomHandler::AddNaClInfo(ListValue* list) {
279 string16 nacl_enabled_string = ASCIIToUTF16("Disabled"); 279 string16 nacl_enabled_string = ASCIIToUTF16("Disabled");
280 if (isPluginEnabled(0) && 280 if (isPluginEnabled(0) &&
281 CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableNaCl)) { 281 CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableNaCl)) {
282 nacl_enabled_string = ASCIIToUTF16("Enabled by flag '--enable-nacl'"); 282 nacl_enabled_string = ASCIIToUTF16("Enabled by flag '--enable-nacl'");
283 } 283 }
(...skipping 27 matching lines...) Expand all
311 // Display the list of plugins serving NaCl. 311 // Display the list of plugins serving NaCl.
312 AddPluginList(list.get()); 312 AddPluginList(list.get());
313 // Display information relevant to PNaCl. 313 // Display information relevant to PNaCl.
314 AddPnaclInfo(list.get()); 314 AddPnaclInfo(list.get());
315 // Display information relevant to NaCl (non-portable. 315 // Display information relevant to NaCl (non-portable.
316 AddNaClInfo(list.get()); 316 AddNaClInfo(list.get());
317 // naclInfo will take ownership of list, and clean it up on destruction. 317 // naclInfo will take ownership of list, and clean it up on destruction.
318 naclInfo->Set("naclInfo", list.release()); 318 naclInfo->Set("naclInfo", list.release());
319 } 319 }
320 320
321 void NaClDomHandler::DidValidatePnaclPath(bool* is_valid) { 321 void NaClDomHandler::DidCheckPathAndVersion(bool* is_valid,
322 std::string* version) {
322 pnacl_path_validated_ = true; 323 pnacl_path_validated_ = true;
323 pnacl_path_exists_ = *is_valid; 324 pnacl_path_exists_ = *is_valid;
325 pnacl_version_string_ = *version;
324 MaybeRespondToPage(); 326 MaybeRespondToPage();
325 } 327 }
326 328
327 void ValidatePnaclPath(bool* is_valid) { 329 void CheckVersion(const base::FilePath& pnacl_path, std::string* version) {
330 base::FilePath pnacl_json_path = pnacl_path.Append(FILE_PATH_LITERAL(
331 "pnacl_public_pnacl_json"));
332 JSONFileValueSerializer serializer(pnacl_json_path);
333 std::string error;
334 scoped_ptr<base::Value> root(serializer.Deserialize(NULL, &error));
335 if (!root.get() || !root->IsType(base::Value::TYPE_DICTIONARY))
336 return;
Dan Beam 2013/08/09 01:12:29 nit: \n
jvoung (off chromium) 2013/08/09 03:31:53 Done.
337 if (!static_cast<base::DictionaryValue*>(root.get())->GetStringASCII(
338 "pnacl-version", version))
Dan Beam 2013/08/09 01:12:29 nit: curlies
339 return;
Dan Beam 2013/08/09 01:12:29 nit: why are you returning at the end?
jvoung (off chromium) 2013/08/09 03:31:53 Oops, I used to have DLOG warnings for these. Now
340 }
341
342 void CheckPathAndVersion(bool* is_valid, std::string* version) {
328 base::FilePath pnacl_path; 343 base::FilePath pnacl_path;
329 bool got_path = PathService::Get(chrome::DIR_PNACL_COMPONENT, &pnacl_path); 344 bool got_path = PathService::Get(chrome::DIR_PNACL_COMPONENT, &pnacl_path);
330 *is_valid = got_path && !pnacl_path.empty() && base::PathExists(pnacl_path); 345 *is_valid = got_path && !pnacl_path.empty() && base::PathExists(pnacl_path);
346 if (*is_valid)
347 CheckVersion(pnacl_path, version);
331 } 348 }
332 349
333 void NaClDomHandler::MaybeRespondToPage() { 350 void NaClDomHandler::MaybeRespondToPage() {
334 // Don't reply until everything is ready. The page will show a 'loading' 351 // Don't reply until everything is ready. The page will show a 'loading'
335 // message until then. 352 // message until then.
336 if (!page_has_requested_data_ || !has_plugin_info_) 353 if (!page_has_requested_data_ || !has_plugin_info_)
337 return; 354 return;
338 355
339 if (!pnacl_path_validated_) { 356 if (!pnacl_path_validated_) {
340 bool* is_valid = new bool; 357 bool* is_valid = new bool;
358 std::string* version_string = new std::string;
341 BrowserThread::PostBlockingPoolTaskAndReply( 359 BrowserThread::PostBlockingPoolTaskAndReply(
342 FROM_HERE, 360 FROM_HERE,
343 base::Bind(&ValidatePnaclPath, is_valid), 361 base::Bind(&CheckPathAndVersion,
344 base::Bind(&NaClDomHandler::DidValidatePnaclPath, 362 is_valid,
363 version_string),
Dan Beam 2013/08/09 01:12:29 nit: looks like this fits in 1 line
jvoung (off chromium) 2013/08/09 03:31:53 Done.
364 base::Bind(&NaClDomHandler::DidCheckPathAndVersion,
345 weak_ptr_factory_.GetWeakPtr(), 365 weak_ptr_factory_.GetWeakPtr(),
346 base::Owned(is_valid))); 366 base::Owned(is_valid),
367 base::Owned(version_string)));
347 return; 368 return;
348 } 369 }
349 370
350 DictionaryValue naclInfo; 371 DictionaryValue naclInfo;
351 PopulatePageInformation(&naclInfo); 372 PopulatePageInformation(&naclInfo);
352 web_ui()->CallJavascriptFunction("nacl.returnNaClInfo", naclInfo); 373 web_ui()->CallJavascriptFunction("nacl.returnNaClInfo", naclInfo);
353 } 374 }
354 375
355 } // namespace 376 } // namespace
356 377
357 /////////////////////////////////////////////////////////////////////////////// 378 ///////////////////////////////////////////////////////////////////////////////
358 // 379 //
359 // NaClUI 380 // NaClUI
360 // 381 //
361 /////////////////////////////////////////////////////////////////////////////// 382 ///////////////////////////////////////////////////////////////////////////////
362 383
363 NaClUI::NaClUI(content::WebUI* web_ui) : WebUIController(web_ui) { 384 NaClUI::NaClUI(content::WebUI* web_ui) : WebUIController(web_ui) {
364 content::RecordAction(UserMetricsAction("ViewAboutNaCl")); 385 content::RecordAction(UserMetricsAction("ViewAboutNaCl"));
365 386
366 web_ui->AddMessageHandler(new NaClDomHandler()); 387 web_ui->AddMessageHandler(new NaClDomHandler());
367 388
368 // Set up the about:nacl source. 389 // Set up the about:nacl source.
369 Profile* profile = Profile::FromWebUI(web_ui); 390 Profile* profile = Profile::FromWebUI(web_ui);
370 content::WebUIDataSource::Add(profile, CreateNaClUIHTMLSource()); 391 content::WebUIDataSource::Add(profile, CreateNaClUIHTMLSource());
371 } 392 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698