Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_path.h" | 11 #include "base/files/file_path.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/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/api/extension_action/action_info.h" | |
| 23 #include "chrome/common/extensions/api/icons/icons_handler.h" | |
| 22 #include "chrome/common/extensions/extension.h" | 24 #include "chrome/common/extensions/extension.h" |
| 23 #include "chrome/common/extensions/extension_icon_set.h" | 25 #include "chrome/common/extensions/extension_icon_set.h" |
| 24 #include "chrome/common/extensions/extension_l10n_util.h" | 26 #include "chrome/common/extensions/extension_l10n_util.h" |
| 25 #include "chrome/common/extensions/extension_manifest_constants.h" | 27 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 26 #include "chrome/common/extensions/extension_messages.h" | 28 #include "chrome/common/extensions/extension_messages.h" |
| 27 #include "chrome/common/extensions/manifest.h" | 29 #include "chrome/common/extensions/manifest.h" |
| 28 #include "chrome/common/extensions/manifest_handler.h" | 30 #include "chrome/common/extensions/manifest_handler.h" |
| 31 #include "chrome/common/extensions/manifest_handlers/theme_handler.h" | |
| 29 #include "chrome/common/extensions/message_bundle.h" | 32 #include "chrome/common/extensions/message_bundle.h" |
| 30 #include "extensions/common/constants.h" | 33 #include "extensions/common/constants.h" |
| 31 #include "extensions/common/extension_resource.h" | 34 #include "extensions/common/extension_resource.h" |
| 32 #include "extensions/common/install_warning.h" | 35 #include "extensions/common/install_warning.h" |
| 33 #include "grit/generated_resources.h" | 36 #include "grit/generated_resources.h" |
| 34 #include "net/base/escape.h" | 37 #include "net/base/escape.h" |
| 35 #include "net/base/file_stream.h" | 38 #include "net/base/file_stream.h" |
| 36 #include "ui/base/l10n/l10n_util.h" | 39 #include "ui/base/l10n/l10n_util.h" |
| 37 | 40 |
| 38 using extensions::Extension; | 41 using extensions::Extension; |
| 39 using extensions::ExtensionResource; | 42 using extensions::ExtensionResource; |
| 40 using extensions::Manifest; | 43 using extensions::Manifest; |
| 41 | 44 |
| 42 namespace errors = extension_manifest_errors; | 45 namespace errors = extension_manifest_errors; |
| 43 | 46 |
| 44 namespace { | 47 namespace { |
| 45 | 48 |
| 46 const base::FilePath::CharType kTempDirectoryName[] = FILE_PATH_LITERAL("Temp"); | 49 const base::FilePath::CharType kTempDirectoryName[] = FILE_PATH_LITERAL("Temp"); |
| 47 | 50 |
| 51 // Add the image paths contained in the |icon_set| to |image_paths|. | |
| 52 void AddPathsFromIconSet(const ExtensionIconSet& icon_set, | |
| 53 std::set<base::FilePath>* image_paths) { | |
| 54 // TODO(viettrungluu): These |FilePath::FromWStringHack(UTF8ToWide())| | |
| 55 // indicate that we're doing something wrong. | |
| 56 for (ExtensionIconSet::IconMap::const_iterator iter = icon_set.map().begin(); | |
| 57 iter != icon_set.map().end(); ++iter) { | |
| 58 image_paths->insert( | |
| 59 base::FilePath::FromWStringHack(UTF8ToWide(iter->second))); | |
|
Yoyo Zhou
2013/04/10 21:44:58
Seems like we should be using FromUTF8Unsafe inste
Devlin
2013/04/12 02:17:06
Done (will change if viettrungluu would prefer som
viettrungluu
2013/04/12 22:33:15
Yes, I agree (assuming that we know for sure that
| |
| 60 } | |
| 61 } | |
| 62 | |
| 48 } // namespace | 63 } // namespace |
| 49 | 64 |
| 50 namespace extension_file_util { | 65 namespace extension_file_util { |
| 51 | 66 |
| 52 base::FilePath InstallExtension(const base::FilePath& unpacked_source_dir, | 67 base::FilePath InstallExtension(const base::FilePath& unpacked_source_dir, |
| 53 const std::string& id, | 68 const std::string& id, |
| 54 const std::string& version, | 69 const std::string& version, |
| 55 const base::FilePath& extensions_dir) { | 70 const base::FilePath& extensions_dir) { |
| 56 base::FilePath extension_dir = extensions_dir.AppendASCII(id); | 71 base::FilePath extension_dir = extensions_dir.AppendASCII(id); |
| 57 base::FilePath version_dir; | 72 base::FilePath version_dir; |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 272 extensions::InstallWarning::FORMAT_TEXT, | 287 extensions::InstallWarning::FORMAT_TEXT, |
| 273 l10n_util::GetStringFUTF8( | 288 l10n_util::GetStringFUTF8( |
| 274 IDS_EXTENSION_CONTAINS_PRIVATE_KEY, | 289 IDS_EXTENSION_CONTAINS_PRIVATE_KEY, |
| 275 private_keys[i].LossyDisplayName()))); | 290 private_keys[i].LossyDisplayName()))); |
| 276 } | 291 } |
| 277 // Only warn; don't block loading the extension. | 292 // Only warn; don't block loading the extension. |
| 278 } | 293 } |
| 279 return true; | 294 return true; |
| 280 } | 295 } |
| 281 | 296 |
| 297 std::set<base::FilePath> GetExtensionBrowserImages(const Extension* extension) { | |
| 298 std::set<base::FilePath> image_paths; | |
| 299 | |
| 300 AddPathsFromIconSet(extensions::IconsInfo::GetIcons(extension), &image_paths); | |
| 301 | |
| 302 // Theme images | |
| 303 const base::DictionaryValue* theme_images = | |
| 304 extensions::ThemeInfo::GetImages(extension); | |
| 305 if (theme_images) { | |
| 306 for (base::DictionaryValue::Iterator it(*theme_images); !it.IsAtEnd(); | |
| 307 it.Advance()) { | |
| 308 base::FilePath::StringType path; | |
| 309 if (it.value().GetAsString(&path)) | |
| 310 image_paths.insert(base::FilePath(path)); | |
| 311 } | |
| 312 } | |
| 313 | |
| 314 const extensions::ActionInfo* page_action = | |
| 315 extensions::ActionInfo::GetPageActionInfo(extension); | |
| 316 if (page_action && !page_action->default_icon.empty()) | |
| 317 AddPathsFromIconSet(page_action->default_icon, &image_paths); | |
| 318 | |
| 319 const extensions::ActionInfo* browser_action = | |
| 320 extensions::ActionInfo::GetBrowserActionInfo(extension); | |
| 321 if (browser_action && !browser_action->default_icon.empty()) | |
| 322 AddPathsFromIconSet(browser_action->default_icon, &image_paths); | |
| 323 | |
| 324 return image_paths; | |
| 325 } | |
| 326 | |
| 282 void GarbageCollectExtensions( | 327 void GarbageCollectExtensions( |
| 283 const base::FilePath& install_directory, | 328 const base::FilePath& install_directory, |
| 284 const std::multimap<std::string, base::FilePath>& extension_paths) { | 329 const std::multimap<std::string, base::FilePath>& extension_paths) { |
| 285 // Nothing to clean up if it doesn't exist. | 330 // Nothing to clean up if it doesn't exist. |
| 286 if (!file_util::DirectoryExists(install_directory)) | 331 if (!file_util::DirectoryExists(install_directory)) |
| 287 return; | 332 return; |
| 288 | 333 |
| 289 DVLOG(1) << "Garbage collecting extensions..."; | 334 DVLOG(1) << "Garbage collecting extensions..."; |
| 290 file_util::FileEnumerator enumerator(install_directory, | 335 file_util::FileEnumerator enumerator(install_directory, |
| 291 false, // Not recursive. | 336 false, // Not recursive. |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 530 return base::FilePath(); | 575 return base::FilePath(); |
| 531 } | 576 } |
| 532 return temp_path; | 577 return temp_path; |
| 533 } | 578 } |
| 534 | 579 |
| 535 void DeleteFile(const base::FilePath& path, bool recursive) { | 580 void DeleteFile(const base::FilePath& path, bool recursive) { |
| 536 file_util::Delete(path, recursive); | 581 file_util::Delete(path, recursive); |
| 537 } | 582 } |
| 538 | 583 |
| 539 } // namespace extension_file_util | 584 } // namespace extension_file_util |
| OLD | NEW |