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

Side by Side Diff: chrome/common/extensions/extension_file_util.cc

Issue 229813002: Move extensions manifest IconsHandler to //extensions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review comments (icons-handler) Created 6 years, 8 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/common/extensions/extension_file_util.h" 5 #include "chrome/common/extensions/extension_file_util.h"
6 6
7 #include <map> 7 #include <map>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/files/file_enumerator.h" 11 #include "base/files/file_enumerator.h"
12 #include "base/files/scoped_temp_dir.h" 12 #include "base/files/scoped_temp_dir.h"
13 #include "base/json/json_file_value_serializer.h" 13 #include "base/json/json_file_value_serializer.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/metrics/histogram.h" 15 #include "base/metrics/histogram.h"
16 #include "base/path_service.h" 16 #include "base/path_service.h"
17 #include "base/strings/stringprintf.h" 17 #include "base/strings/stringprintf.h"
18 #include "base/strings/utf_string_conversions.h"
19 #include "base/threading/thread_restrictions.h" 18 #include "base/threading/thread_restrictions.h"
20 #include "chrome/common/chrome_paths.h" 19 #include "chrome/common/chrome_paths.h"
21 #include "chrome/common/extensions/api/extension_action/action_info.h" 20 #include "chrome/common/extensions/api/extension_action/action_info.h"
22 #include "chrome/common/extensions/manifest_handlers/icons_handler.h"
23 #include "chrome/common/extensions/manifest_handlers/theme_handler.h" 21 #include "chrome/common/extensions/manifest_handlers/theme_handler.h"
24 #include "extensions/common/constants.h" 22 #include "extensions/common/constants.h"
25 #include "extensions/common/extension.h" 23 #include "extensions/common/extension.h"
26 #include "extensions/common/extension_icon_set.h" 24 #include "extensions/common/extension_icon_set.h"
27 #include "extensions/common/extension_l10n_util.h" 25 #include "extensions/common/extension_l10n_util.h"
28 #include "extensions/common/extension_messages.h" 26 #include "extensions/common/extension_messages.h"
29 #include "extensions/common/extension_resource.h" 27 #include "extensions/common/extension_resource.h"
30 #include "extensions/common/install_warning.h" 28 #include "extensions/common/install_warning.h"
31 #include "extensions/common/manifest.h" 29 #include "extensions/common/manifest.h"
32 #include "extensions/common/manifest_constants.h" 30 #include "extensions/common/manifest_constants.h"
33 #include "extensions/common/manifest_handler.h" 31 #include "extensions/common/manifest_handler.h"
32 #include "extensions/common/manifest_handlers/icons_handler.h"
34 #include "grit/generated_resources.h" 33 #include "grit/generated_resources.h"
35 #include "net/base/file_stream.h" 34 #include "net/base/file_stream.h"
36 #include "ui/base/l10n/l10n_util.h" 35 #include "ui/base/l10n/l10n_util.h"
37 36
38 using extensions::Extension; 37 using extensions::Extension;
39 using extensions::ExtensionResource; 38 using extensions::ExtensionResource;
40 using extensions::Manifest; 39 using extensions::Manifest;
41 40
42 namespace errors = extensions::manifest_errors; 41 namespace errors = extensions::manifest_errors;
43 42
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 if (!Extension::ParsePEMKeyBytes(key_contents, &key_bytes)) { 215 if (!Extension::ParsePEMKeyBytes(key_contents, &key_bytes)) {
217 // If we can't parse the key, assume it's ok too. 216 // If we can't parse the key, assume it's ok too.
218 continue; 217 continue;
219 } 218 }
220 219
221 result.push_back(current); 220 result.push_back(current);
222 } 221 }
223 return result; 222 return result;
224 } 223 }
225 224
226 bool ValidateFilePath(const base::FilePath& path) {
227 int64 size = 0;
228 if (!base::PathExists(path) ||
229 !base::GetFileSize(path, &size) ||
230 size == 0) {
231 return false;
232 }
233
234 return true;
235 }
236
237 bool ValidateExtensionIconSet(const ExtensionIconSet& icon_set,
238 const Extension* extension,
239 int error_message_id,
240 std::string* error) {
241 for (ExtensionIconSet::IconMap::const_iterator iter = icon_set.map().begin();
242 iter != icon_set.map().end();
243 ++iter) {
244 const base::FilePath path =
245 extension->GetResource(iter->second).GetFilePath();
246 if (!ValidateFilePath(path)) {
247 *error = l10n_util::GetStringFUTF8(error_message_id,
248 base::UTF8ToUTF16(iter->second));
249 return false;
250 }
251 }
252 return true;
253 }
254
255 bool ValidateExtension(const Extension* extension, 225 bool ValidateExtension(const Extension* extension,
256 std::string* error, 226 std::string* error,
257 std::vector<extensions::InstallWarning>* warnings) { 227 std::vector<extensions::InstallWarning>* warnings) {
258 // Ask registered manifest handlers to validate their paths. 228 // Ask registered manifest handlers to validate their paths.
259 if (!extensions::ManifestHandler::ValidateExtension( 229 if (!extensions::ManifestHandler::ValidateExtension(
260 extension, error, warnings)) 230 extension, error, warnings))
261 return false; 231 return false;
262 232
263 // Check children of extension root to see if any of them start with _ and is 233 // Check children of extension root to see if any of them start with _ and is
264 // not on the reserved list. We only warn, and do not block the loading of the 234 // not on the reserved list. We only warn, and do not block the loading of the
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 return base::FilePath(); 358 return base::FilePath();
389 } 359 }
390 return temp_path; 360 return temp_path;
391 } 361 }
392 362
393 void DeleteFile(const base::FilePath& path, bool recursive) { 363 void DeleteFile(const base::FilePath& path, bool recursive) {
394 base::DeleteFile(path, recursive); 364 base::DeleteFile(path, recursive);
395 } 365 }
396 366
397 } // namespace extension_file_util 367 } // namespace extension_file_util
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension_file_util.h ('k') | chrome/common/extensions/manifest_handlers/icons_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698