OLD | NEW |
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/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_path.h" | 10 #include "base/file_path.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "chrome/common/extensions/message_bundle.h" | 28 #include "chrome/common/extensions/message_bundle.h" |
29 #include "grit/generated_resources.h" | 29 #include "grit/generated_resources.h" |
30 #include "net/base/escape.h" | 30 #include "net/base/escape.h" |
31 #include "net/base/file_stream.h" | 31 #include "net/base/file_stream.h" |
32 #include "ui/base/l10n/l10n_util.h" | 32 #include "ui/base/l10n/l10n_util.h" |
33 | 33 |
34 using extensions::Extension; | 34 using extensions::Extension; |
35 | 35 |
36 namespace errors = extension_manifest_errors; | 36 namespace errors = extension_manifest_errors; |
37 | 37 |
| 38 namespace { |
| 39 |
| 40 bool ValidateExtensionIconSet(const ExtensionIconSet* icon_set, |
| 41 const Extension* extension, |
| 42 int error_message_id, |
| 43 std::string* error) { |
| 44 for (ExtensionIconSet::IconMap::const_iterator iter = icon_set->map().begin(); |
| 45 iter != icon_set->map().end(); |
| 46 ++iter) { |
| 47 const FilePath path = extension->GetResource(iter->second).GetFilePath(); |
| 48 if (!extension_file_util::ValidateFilePath(path)) { |
| 49 *error = l10n_util::GetStringFUTF8(error_message_id, |
| 50 UTF8ToUTF16(iter->second)); |
| 51 return false; |
| 52 } |
| 53 } |
| 54 return true; |
| 55 } |
| 56 |
| 57 } // namespace |
| 58 |
38 namespace extension_file_util { | 59 namespace extension_file_util { |
39 | 60 |
40 // Validates locale info. Doesn't check if messages.json files are valid. | 61 // Validates locale info. Doesn't check if messages.json files are valid. |
41 static bool ValidateLocaleInfo(const Extension& extension, | 62 static bool ValidateLocaleInfo(const Extension& extension, |
42 std::string* error); | 63 std::string* error); |
43 | 64 |
44 // Returns false and sets the error if script file can't be loaded, | 65 // Returns false and sets the error if script file can't be loaded, |
45 // or if it's not UTF-8 encoded. | 66 // or if it's not UTF-8 encoded. |
46 static bool IsScriptValid(const FilePath& path, const FilePath& relative_path, | 67 static bool IsScriptValid(const FilePath& path, const FilePath& relative_path, |
47 int message_id, std::string* error); | 68 int message_id, std::string* error); |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 const Extension::PluginInfo& plugin = extension->plugins()[i]; | 334 const Extension::PluginInfo& plugin = extension->plugins()[i]; |
314 if (!file_util::PathExists(plugin.path)) { | 335 if (!file_util::PathExists(plugin.path)) { |
315 *error = | 336 *error = |
316 l10n_util::GetStringFUTF8( | 337 l10n_util::GetStringFUTF8( |
317 IDS_EXTENSION_LOAD_PLUGIN_PATH_FAILED, | 338 IDS_EXTENSION_LOAD_PLUGIN_PATH_FAILED, |
318 plugin.path.LossyDisplayName()); | 339 plugin.path.LossyDisplayName()); |
319 return false; | 340 return false; |
320 } | 341 } |
321 } | 342 } |
322 | 343 |
323 // Validate icon location and icon file size for page actions. | 344 const ExtensionAction* action = extension->page_action(); |
324 ExtensionAction* page_action = extension->page_action(); | 345 if (action && action->default_icon() && |
325 if (page_action) { | 346 !ValidateExtensionIconSet(action->default_icon(), extension, |
326 std::string path = page_action->default_icon_path(); | 347 IDS_EXTENSION_LOAD_ICON_FOR_PAGE_ACTION_FAILED, error)) { |
327 if (!path.empty()) { | 348 return false; |
328 const FilePath file_path = extension->GetResource(path).GetFilePath(); | |
329 if (!ValidateFilePath(file_path)) { | |
330 *error = | |
331 l10n_util::GetStringFUTF8( | |
332 IDS_EXTENSION_LOAD_ICON_FOR_PAGE_ACTION_FAILED, | |
333 UTF8ToUTF16(path)); | |
334 return false; | |
335 } | |
336 } | |
337 } | 349 } |
338 | 350 |
339 // Validate icon location and icon file size for browser actions. | 351 action = extension->browser_action(); |
340 ExtensionAction* browser_action = extension->browser_action(); | 352 if (action && action->default_icon() && |
341 if (browser_action) { | 353 !ValidateExtensionIconSet(action->default_icon(), extension, |
342 std::string path = browser_action->default_icon_path(); | 354 IDS_EXTENSION_LOAD_ICON_FOR_BROWSER_ACTION_FAILED, error)) { |
343 if (!path.empty()) { | 355 return false; |
344 const FilePath file_path = extension->GetResource(path).GetFilePath(); | |
345 if (!ValidateFilePath(file_path)) { | |
346 *error = | |
347 l10n_util::GetStringFUTF8( | |
348 IDS_EXTENSION_LOAD_ICON_FOR_BROWSER_ACTION_FAILED, | |
349 UTF8ToUTF16(path)); | |
350 return false; | |
351 } | |
352 } | |
353 } | 356 } |
354 | 357 |
355 // Validate that background scripts exist. | 358 // Validate that background scripts exist. |
356 for (size_t i = 0; i < extension->background_scripts().size(); ++i) { | 359 for (size_t i = 0; i < extension->background_scripts().size(); ++i) { |
357 if (!file_util::PathExists( | 360 if (!file_util::PathExists( |
358 extension->GetResource( | 361 extension->GetResource( |
359 extension->background_scripts()[i]).GetFilePath())) { | 362 extension->background_scripts()[i]).GetFilePath())) { |
360 *error = l10n_util::GetStringFUTF8( | 363 *error = l10n_util::GetStringFUTF8( |
361 IDS_EXTENSION_LOAD_BACKGROUND_SCRIPT_FAILED, | 364 IDS_EXTENSION_LOAD_BACKGROUND_SCRIPT_FAILED, |
362 UTF8ToUTF16(extension->background_scripts()[i])); | 365 UTF8ToUTF16(extension->background_scripts()[i])); |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
782 return temp_path; | 785 return temp_path; |
783 | 786 |
784 return FilePath(); | 787 return FilePath(); |
785 } | 788 } |
786 | 789 |
787 void DeleteFile(const FilePath& path, bool recursive) { | 790 void DeleteFile(const FilePath& path, bool recursive) { |
788 file_util::Delete(path, recursive); | 791 file_util::Delete(path, recursive); |
789 } | 792 } |
790 | 793 |
791 } // namespace extension_file_util | 794 } // namespace extension_file_util |
OLD | NEW |