| 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" |
| 11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/json/json_file_value_serializer.h" | 12 #include "base/json/json_file_value_serializer.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 15 #include "base/path_service.h" | 15 #include "base/path_service.h" |
| 16 #include "base/scoped_temp_dir.h" | 16 #include "base/scoped_temp_dir.h" |
| 17 #include "base/stringprintf.h" | 17 #include "base/stringprintf.h" |
| 18 #include "base/threading/thread_restrictions.h" | 18 #include "base/threading/thread_restrictions.h" |
| 19 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
| 20 #include "chrome/common/chrome_constants.h" | 20 #include "chrome/common/chrome_constants.h" |
| 21 #include "chrome/common/chrome_paths.h" | 21 #include "chrome/common/chrome_paths.h" |
| 22 #include "chrome/common/extensions/extension.h" | 22 #include "chrome/common/extensions/extension.h" |
| 23 #include "chrome/common/extensions/extension_action.h" | |
| 24 #include "chrome/common/extensions/extension_l10n_util.h" | 23 #include "chrome/common/extensions/extension_l10n_util.h" |
| 25 #include "chrome/common/extensions/extension_manifest_constants.h" | 24 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 26 #include "chrome/common/extensions/extension_messages.h" | 25 #include "chrome/common/extensions/extension_messages.h" |
| 27 #include "chrome/common/extensions/extension_resource.h" | 26 #include "chrome/common/extensions/extension_resource.h" |
| 28 #include "chrome/common/extensions/message_bundle.h" | 27 #include "chrome/common/extensions/message_bundle.h" |
| 29 #include "grit/generated_resources.h" | 28 #include "grit/generated_resources.h" |
| 30 #include "net/base/escape.h" | 29 #include "net/base/escape.h" |
| 31 #include "net/base/file_stream.h" | 30 #include "net/base/file_stream.h" |
| 32 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
| 33 | 32 |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 if (!file_util::PathExists(plugin.path)) { | 313 if (!file_util::PathExists(plugin.path)) { |
| 315 *error = | 314 *error = |
| 316 l10n_util::GetStringFUTF8( | 315 l10n_util::GetStringFUTF8( |
| 317 IDS_EXTENSION_LOAD_PLUGIN_PATH_FAILED, | 316 IDS_EXTENSION_LOAD_PLUGIN_PATH_FAILED, |
| 318 plugin.path.LossyDisplayName()); | 317 plugin.path.LossyDisplayName()); |
| 319 return false; | 318 return false; |
| 320 } | 319 } |
| 321 } | 320 } |
| 322 | 321 |
| 323 // Validate icon location and icon file size for page actions. | 322 // Validate icon location and icon file size for page actions. |
| 324 ExtensionAction* page_action = extension->page_action(); | 323 Extension::ActionInfo* page_action = extension->page_action(); |
| 325 if (page_action) { | 324 if (page_action) { |
| 326 std::vector<std::string> icon_paths(*page_action->icon_paths()); | 325 const FilePath path = extension->GetResource( |
| 327 if (!page_action->default_icon_path().empty()) | 326 page_action->default_icon_path).GetFilePath(); |
| 328 icon_paths.push_back(page_action->default_icon_path()); | 327 if (!ValidateFilePath(path)) { |
| 329 for (std::vector<std::string>::iterator iter = icon_paths.begin(); | 328 *error = |
| 330 iter != icon_paths.end(); ++iter) { | 329 l10n_util::GetStringFUTF8( |
| 331 const FilePath path = extension->GetResource(*iter).GetFilePath(); | 330 IDS_EXTENSION_LOAD_ICON_FOR_PAGE_ACTION_FAILED, |
| 332 if (!ValidateFilePath(path)) { | 331 UTF8ToUTF16(page_action->default_icon_path)); |
| 333 *error = | 332 return false; |
| 334 l10n_util::GetStringFUTF8( | |
| 335 IDS_EXTENSION_LOAD_ICON_FOR_PAGE_ACTION_FAILED, | |
| 336 UTF8ToUTF16(*iter)); | |
| 337 return false; | |
| 338 } | |
| 339 } | 333 } |
| 340 } | 334 } |
| 341 | 335 |
| 342 // Validate icon location and icon file size for browser actions. | 336 // Validate icon location and icon file size for browser actions. |
| 343 // Note: browser actions don't use the icon_paths(). | 337 // Note: browser actions don't use the icon_paths(). |
| 344 ExtensionAction* browser_action = extension->browser_action(); | 338 Extension::ActionInfo* browser_action = extension->browser_action(); |
| 345 if (browser_action) { | 339 if (browser_action) { |
| 346 std::string path = browser_action->default_icon_path(); | 340 std::string path = browser_action->default_icon_path; |
| 347 if (!path.empty()) { | 341 if (!path.empty()) { |
| 348 const FilePath file_path = extension->GetResource(path).GetFilePath(); | 342 const FilePath file_path = extension->GetResource(path).GetFilePath(); |
| 349 if (!ValidateFilePath(file_path)) { | 343 if (!ValidateFilePath(file_path)) { |
| 350 *error = | 344 *error = |
| 351 l10n_util::GetStringFUTF8( | 345 l10n_util::GetStringFUTF8( |
| 352 IDS_EXTENSION_LOAD_ICON_FOR_BROWSER_ACTION_FAILED, | 346 IDS_EXTENSION_LOAD_ICON_FOR_BROWSER_ACTION_FAILED, |
| 353 UTF8ToUTF16(path)); | 347 UTF8ToUTF16(path)); |
| 354 return false; | 348 return false; |
| 355 } | 349 } |
| 356 } | 350 } |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 786 return temp_path; | 780 return temp_path; |
| 787 | 781 |
| 788 return FilePath(); | 782 return FilePath(); |
| 789 } | 783 } |
| 790 | 784 |
| 791 void DeleteFile(const FilePath& path, bool recursive) { | 785 void DeleteFile(const FilePath& path, bool recursive) { |
| 792 file_util::Delete(path, recursive); | 786 file_util::Delete(path, recursive); |
| 793 } | 787 } |
| 794 | 788 |
| 795 } // namespace extension_file_util | 789 } // namespace extension_file_util |
| OLD | NEW |