| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/json/json_value_serializer.h" | 11 #include "base/json/json_value_serializer.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 15 #include "base/scoped_temp_dir.h" | 15 #include "base/scoped_temp_dir.h" |
| 16 #include "base/stringprintf.h" | 16 #include "base/stringprintf.h" |
| 17 #include "base/threading/thread_restrictions.h" | 17 #include "base/threading/thread_restrictions.h" |
| 18 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
| 19 #include "chrome/common/chrome_paths.h" | 19 #include "chrome/common/chrome_paths.h" |
| 20 #include "chrome/common/extensions/extension.h" | 20 #include "chrome/common/extensions/extension.h" |
| 21 #include "chrome/common/extensions/extension_action.h" | 21 #include "chrome/common/extensions/extension_action.h" |
| 22 #include "chrome/common/extensions/extension_constants.h" | 22 #include "chrome/common/extensions/extension_constants.h" |
| 23 #include "chrome/common/extensions/extension_l10n_util.h" | 23 #include "chrome/common/extensions/extension_l10n_util.h" |
| 24 #include "chrome/common/extensions/extension_message_bundle.h" | 24 #include "chrome/common/extensions/extension_message_bundle.h" |
| 25 #include "chrome/common/extensions/extension_messages.h" | 25 #include "chrome/common/extensions/extension_messages.h" |
| 26 #include "chrome/common/extensions/extension_resource.h" | 26 #include "chrome/common/extensions/extension_resource.h" |
| 27 #include "chrome/common/extensions/extension_sidebar_defaults.h" | |
| 28 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
| 29 #include "net/base/escape.h" | 28 #include "net/base/escape.h" |
| 30 #include "net/base/file_stream.h" | 29 #include "net/base/file_stream.h" |
| 31 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
| 32 | 31 |
| 33 namespace errors = extension_manifest_errors; | 32 namespace errors = extension_manifest_errors; |
| 34 | 33 |
| 35 namespace extension_file_util { | 34 namespace extension_file_util { |
| 36 | 35 |
| 37 // Validates locale info. Doesn't check if messages.json files are valid. | 36 // Validates locale info. Doesn't check if messages.json files are valid. |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 const FilePath path = extension->GetResource(options_path).GetFilePath(); | 312 const FilePath path = extension->GetResource(options_path).GetFilePath(); |
| 314 if (path.empty() || !file_util::PathExists(path)) { | 313 if (path.empty() || !file_util::PathExists(path)) { |
| 315 *error = | 314 *error = |
| 316 l10n_util::GetStringFUTF8( | 315 l10n_util::GetStringFUTF8( |
| 317 IDS_EXTENSION_LOAD_OPTIONS_PAGE_FAILED, | 316 IDS_EXTENSION_LOAD_OPTIONS_PAGE_FAILED, |
| 318 options_path.LossyDisplayName()); | 317 options_path.LossyDisplayName()); |
| 319 return false; | 318 return false; |
| 320 } | 319 } |
| 321 } | 320 } |
| 322 | 321 |
| 323 // Validate sidebar default page location. | |
| 324 ExtensionSidebarDefaults* sidebar_defaults = extension->sidebar_defaults(); | |
| 325 if (sidebar_defaults && sidebar_defaults->default_page().is_valid()) { | |
| 326 FilePath page_path = ExtensionURLToRelativeFilePath( | |
| 327 sidebar_defaults->default_page()); | |
| 328 const FilePath path = extension->GetResource(page_path).GetFilePath(); | |
| 329 if (path.empty() || !file_util::PathExists(path)) { | |
| 330 *error = | |
| 331 l10n_util::GetStringFUTF8( | |
| 332 IDS_EXTENSION_LOAD_SIDEBAR_PAGE_FAILED, | |
| 333 page_path.LossyDisplayName()); | |
| 334 return false; | |
| 335 } | |
| 336 } | |
| 337 | |
| 338 // Validate locale info. | 322 // Validate locale info. |
| 339 if (!ValidateLocaleInfo(*extension, error)) | 323 if (!ValidateLocaleInfo(*extension, error)) |
| 340 return false; | 324 return false; |
| 341 | 325 |
| 342 // Check children of extension root to see if any of them start with _ and is | 326 // Check children of extension root to see if any of them start with _ and is |
| 343 // not on the reserved list. | 327 // not on the reserved list. |
| 344 if (!CheckForIllegalFilenames(extension->path(), error)) { | 328 if (!CheckForIllegalFilenames(extension->path(), error)) { |
| 345 return false; | 329 return false; |
| 346 } | 330 } |
| 347 | 331 |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 681 return temp_path; | 665 return temp_path; |
| 682 | 666 |
| 683 return FilePath(); | 667 return FilePath(); |
| 684 } | 668 } |
| 685 | 669 |
| 686 void DeleteFile(const FilePath& path, bool recursive) { | 670 void DeleteFile(const FilePath& path, bool recursive) { |
| 687 file_util::Delete(path, recursive); | 671 file_util::Delete(path, recursive); |
| 688 } | 672 } |
| 689 | 673 |
| 690 } // namespace extension_file_util | 674 } // namespace extension_file_util |
| OLD | NEW |