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" |
22 #include "chrome/common/extensions/extension.h" | 23 #include "chrome/common/extensions/extension.h" |
23 #include "chrome/common/extensions/extension_icon_set.h" | 24 #include "chrome/common/extensions/extension_icon_set.h" |
24 #include "chrome/common/extensions/extension_l10n_util.h" | 25 #include "chrome/common/extensions/extension_l10n_util.h" |
25 #include "chrome/common/extensions/extension_manifest_constants.h" | 26 #include "chrome/common/extensions/extension_manifest_constants.h" |
26 #include "chrome/common/extensions/extension_messages.h" | 27 #include "chrome/common/extensions/extension_messages.h" |
27 #include "chrome/common/extensions/manifest.h" | 28 #include "chrome/common/extensions/manifest.h" |
28 #include "chrome/common/extensions/manifest_handler.h" | 29 #include "chrome/common/extensions/manifest_handler.h" |
| 30 #include "chrome/common/extensions/manifest_handlers/icons_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::FromUTF8Unsafe()| indicate that we're |
| 55 // 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(base::FilePath::FromUTF8Unsafe(iter->second)); |
| 59 } |
| 60 } |
| 61 |
48 } // namespace | 62 } // namespace |
49 | 63 |
50 namespace extension_file_util { | 64 namespace extension_file_util { |
51 | 65 |
52 base::FilePath InstallExtension(const base::FilePath& unpacked_source_dir, | 66 base::FilePath InstallExtension(const base::FilePath& unpacked_source_dir, |
53 const std::string& id, | 67 const std::string& id, |
54 const std::string& version, | 68 const std::string& version, |
55 const base::FilePath& extensions_dir) { | 69 const base::FilePath& extensions_dir) { |
56 base::FilePath extension_dir = extensions_dir.AppendASCII(id); | 70 base::FilePath extension_dir = extensions_dir.AppendASCII(id); |
57 base::FilePath version_dir; | 71 base::FilePath version_dir; |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 extensions::InstallWarning::FORMAT_TEXT, | 286 extensions::InstallWarning::FORMAT_TEXT, |
273 l10n_util::GetStringFUTF8( | 287 l10n_util::GetStringFUTF8( |
274 IDS_EXTENSION_CONTAINS_PRIVATE_KEY, | 288 IDS_EXTENSION_CONTAINS_PRIVATE_KEY, |
275 private_keys[i].LossyDisplayName()))); | 289 private_keys[i].LossyDisplayName()))); |
276 } | 290 } |
277 // Only warn; don't block loading the extension. | 291 // Only warn; don't block loading the extension. |
278 } | 292 } |
279 return true; | 293 return true; |
280 } | 294 } |
281 | 295 |
| 296 std::set<base::FilePath> GetBrowserImagePaths(const Extension* extension) { |
| 297 std::set<base::FilePath> image_paths; |
| 298 |
| 299 AddPathsFromIconSet(extensions::IconsInfo::GetIcons(extension), &image_paths); |
| 300 |
| 301 // Theme images |
| 302 const base::DictionaryValue* theme_images = |
| 303 extensions::ThemeInfo::GetImages(extension); |
| 304 if (theme_images) { |
| 305 for (base::DictionaryValue::Iterator it(*theme_images); !it.IsAtEnd(); |
| 306 it.Advance()) { |
| 307 base::FilePath::StringType path; |
| 308 if (it.value().GetAsString(&path)) |
| 309 image_paths.insert(base::FilePath(path)); |
| 310 } |
| 311 } |
| 312 |
| 313 const extensions::ActionInfo* page_action = |
| 314 extensions::ActionInfo::GetPageActionInfo(extension); |
| 315 if (page_action && !page_action->default_icon.empty()) |
| 316 AddPathsFromIconSet(page_action->default_icon, &image_paths); |
| 317 |
| 318 const extensions::ActionInfo* browser_action = |
| 319 extensions::ActionInfo::GetBrowserActionInfo(extension); |
| 320 if (browser_action && !browser_action->default_icon.empty()) |
| 321 AddPathsFromIconSet(browser_action->default_icon, &image_paths); |
| 322 |
| 323 return image_paths; |
| 324 } |
| 325 |
282 void GarbageCollectExtensions( | 326 void GarbageCollectExtensions( |
283 const base::FilePath& install_directory, | 327 const base::FilePath& install_directory, |
284 const std::multimap<std::string, base::FilePath>& extension_paths) { | 328 const std::multimap<std::string, base::FilePath>& extension_paths) { |
285 // Nothing to clean up if it doesn't exist. | 329 // Nothing to clean up if it doesn't exist. |
286 if (!file_util::DirectoryExists(install_directory)) | 330 if (!file_util::DirectoryExists(install_directory)) |
287 return; | 331 return; |
288 | 332 |
289 DVLOG(1) << "Garbage collecting extensions..."; | 333 DVLOG(1) << "Garbage collecting extensions..."; |
290 file_util::FileEnumerator enumerator(install_directory, | 334 file_util::FileEnumerator enumerator(install_directory, |
291 false, // Not recursive. | 335 false, // Not recursive. |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 return base::FilePath(); | 574 return base::FilePath(); |
531 } | 575 } |
532 return temp_path; | 576 return temp_path; |
533 } | 577 } |
534 | 578 |
535 void DeleteFile(const base::FilePath& path, bool recursive) { | 579 void DeleteFile(const base::FilePath& path, bool recursive) { |
536 file_util::Delete(path, recursive); | 580 file_util::Delete(path, recursive); |
537 } | 581 } |
538 | 582 |
539 } // namespace extension_file_util | 583 } // namespace extension_file_util |
OLD | NEW |