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/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/api/extension_action/action_info.h" |
23 #include "chrome/common/extensions/api/extension_action/browser_action_handler.h " | 23 #include "chrome/common/extensions/api/extension_action/browser_action_handler.h " |
24 #include "chrome/common/extensions/api/i18n/default_locale_handler.h" | 24 #include "chrome/common/extensions/api/i18n/default_locale_handler.h" |
25 #include "chrome/common/extensions/api/themes/theme_handler.h" | 25 #include "chrome/common/extensions/api/themes/theme_handler.h" |
26 #include "chrome/common/extensions/background_info.h" | |
26 #include "chrome/common/extensions/extension.h" | 27 #include "chrome/common/extensions/extension.h" |
27 #include "chrome/common/extensions/extension_l10n_util.h" | 28 #include "chrome/common/extensions/extension_l10n_util.h" |
28 #include "chrome/common/extensions/extension_manifest_constants.h" | 29 #include "chrome/common/extensions/extension_manifest_constants.h" |
29 #include "chrome/common/extensions/extension_messages.h" | 30 #include "chrome/common/extensions/extension_messages.h" |
30 #include "chrome/common/extensions/extension_resource.h" | 31 #include "chrome/common/extensions/extension_resource.h" |
31 #include "chrome/common/extensions/manifest.h" | 32 #include "chrome/common/extensions/manifest.h" |
32 #include "chrome/common/extensions/manifest_url_handler.h" | 33 #include "chrome/common/extensions/manifest_url_handler.h" |
33 #include "chrome/common/extensions/message_bundle.h" | 34 #include "chrome/common/extensions/message_bundle.h" |
34 #include "extensions/common/install_warning.h" | 35 #include "extensions/common/install_warning.h" |
35 #include "grit/generated_resources.h" | 36 #include "grit/generated_resources.h" |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
349 } | 350 } |
350 | 351 |
351 action = extensions::ActionInfo::GetBrowserActionInfo(extension); | 352 action = extensions::ActionInfo::GetBrowserActionInfo(extension); |
352 if (action && !action->default_icon.empty() && | 353 if (action && !action->default_icon.empty() && |
353 !ValidateExtensionIconSet(action->default_icon, extension, | 354 !ValidateExtensionIconSet(action->default_icon, extension, |
354 IDS_EXTENSION_LOAD_ICON_FOR_BROWSER_ACTION_FAILED, error)) { | 355 IDS_EXTENSION_LOAD_ICON_FOR_BROWSER_ACTION_FAILED, error)) { |
355 return false; | 356 return false; |
356 } | 357 } |
357 | 358 |
358 // Validate that background scripts exist. | 359 // Validate that background scripts exist. |
359 for (size_t i = 0; i < extension->background_scripts().size(); ++i) { | 360 const std::vector<std::string>& background_scripts = |
361 extensions::BackgroundInfo::GetBackgroundScripts(extension); | |
362 for (size_t i = 0; i < background_scripts.size(); ++i) { | |
360 if (!file_util::PathExists( | 363 if (!file_util::PathExists( |
361 extension->GetResource( | 364 extension->GetResource(background_scripts[i]).GetFilePath())) { |
362 extension->background_scripts()[i]).GetFilePath())) { | |
363 *error = l10n_util::GetStringFUTF8( | 365 *error = l10n_util::GetStringFUTF8( |
364 IDS_EXTENSION_LOAD_BACKGROUND_SCRIPT_FAILED, | 366 IDS_EXTENSION_LOAD_BACKGROUND_SCRIPT_FAILED, |
365 UTF8ToUTF16(extension->background_scripts()[i])); | 367 UTF8ToUTF16(background_scripts[i])); |
366 return false; | 368 return false; |
367 } | 369 } |
368 } | 370 } |
369 | 371 |
370 // Validate background page location, except for hosted apps, which should use | 372 // Validate background page location, except for hosted apps, which should use |
371 // an external URL. Background page for hosted apps are verified when the | 373 // an external URL. Background page for hosted apps are verified when the |
372 // extension is created (in Extension::InitFromValue) | 374 // extension is created (in Extension::InitFromValue) |
373 if (extension->has_background_page() && | 375 if (extensions::BackgroundInfo::HasBackgroundPage(extension) && |
374 !extension->is_hosted_app() && | 376 !extension->is_hosted_app() && |
375 extension->background_scripts().empty()) { | 377 extensions::BackgroundInfo::GetBackgroundScripts(extension).empty()) { |
Matt Perry
2013/02/15 20:15:02
already have background_scripts
Yoyo Zhou
2013/02/16 00:54:04
Not sure I understand this comment.
Matt Perry
2013/02/16 01:16:52
you cache the scripts in |background_scripts| abov
| |
376 base::FilePath page_path = ExtensionURLToRelativeFilePath( | 378 base::FilePath page_path = ExtensionURLToRelativeFilePath( |
377 extension->GetBackgroundURL()); | 379 extensions::BackgroundInfo::GetBackgroundURL(extension)); |
378 const base::FilePath path = extension->GetResource(page_path).GetFilePath(); | 380 const base::FilePath path = extension->GetResource(page_path).GetFilePath(); |
379 if (path.empty() || !file_util::PathExists(path)) { | 381 if (path.empty() || !file_util::PathExists(path)) { |
380 *error = | 382 *error = |
381 l10n_util::GetStringFUTF8( | 383 l10n_util::GetStringFUTF8( |
382 IDS_EXTENSION_LOAD_BACKGROUND_PAGE_FAILED, | 384 IDS_EXTENSION_LOAD_BACKGROUND_PAGE_FAILED, |
383 page_path.LossyDisplayName()); | 385 page_path.LossyDisplayName()); |
384 return false; | 386 return false; |
385 } | 387 } |
386 } | 388 } |
387 | 389 |
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
772 return base::FilePath(); | 774 return base::FilePath(); |
773 } | 775 } |
774 return temp_path; | 776 return temp_path; |
775 } | 777 } |
776 | 778 |
777 void DeleteFile(const base::FilePath& path, bool recursive) { | 779 void DeleteFile(const base::FilePath& path, bool recursive) { |
778 file_util::Delete(path, recursive); | 780 file_util::Delete(path, recursive); |
779 } | 781 } |
780 | 782 |
781 } // namespace extension_file_util | 783 } // namespace extension_file_util |
OLD | NEW |