| 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.h" | 5 #include "chrome/common/extensions/extension.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "base/utf_string_conversions.h" | 21 #include "base/utf_string_conversions.h" |
| 22 #include "base/values.h" | 22 #include "base/values.h" |
| 23 #include "base/version.h" | 23 #include "base/version.h" |
| 24 #include "chrome/common/chrome_constants.h" | 24 #include "chrome/common/chrome_constants.h" |
| 25 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
| 26 #include "chrome/common/chrome_version_info.h" | 26 #include "chrome/common/chrome_version_info.h" |
| 27 // TODO(rdevlin.cronin): Remove this once PageAction, BrowserAction, and | 27 // TODO(rdevlin.cronin): Remove this once PageAction, BrowserAction, and |
| 28 // SystemIndicator have been moved out of Extension. | 28 // SystemIndicator have been moved out of Extension. |
| 29 #include "chrome/common/extensions/api/extension_action/action_info.h" | 29 #include "chrome/common/extensions/api/extension_action/action_info.h" |
| 30 #include "chrome/common/extensions/api/extension_action/page_action_handler.h" | 30 #include "chrome/common/extensions/api/extension_action/page_action_handler.h" |
| 31 #include "chrome/common/extensions/api/icons/icons_handler.h" |
| 31 #include "chrome/common/extensions/api/themes/theme_handler.h" | 32 #include "chrome/common/extensions/api/themes/theme_handler.h" |
| 32 #include "chrome/common/extensions/csp_handler.h" | 33 #include "chrome/common/extensions/csp_handler.h" |
| 33 #include "chrome/common/extensions/csp_validator.h" | 34 #include "chrome/common/extensions/csp_validator.h" |
| 34 #include "chrome/common/extensions/extension_manifest_constants.h" | 35 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 35 #include "chrome/common/extensions/extension_resource.h" | |
| 36 #include "chrome/common/extensions/feature_switch.h" | 36 #include "chrome/common/extensions/feature_switch.h" |
| 37 #include "chrome/common/extensions/features/base_feature_provider.h" | 37 #include "chrome/common/extensions/features/base_feature_provider.h" |
| 38 #include "chrome/common/extensions/features/feature.h" | 38 #include "chrome/common/extensions/features/feature.h" |
| 39 #include "chrome/common/extensions/manifest.h" | 39 #include "chrome/common/extensions/manifest.h" |
| 40 #include "chrome/common/extensions/manifest_handler.h" | 40 #include "chrome/common/extensions/manifest_handler.h" |
| 41 #include "chrome/common/extensions/manifest_handler_helpers.h" | 41 #include "chrome/common/extensions/manifest_handler_helpers.h" |
| 42 #include "chrome/common/extensions/manifest_url_handler.h" | 42 #include "chrome/common/extensions/manifest_url_handler.h" |
| 43 #include "chrome/common/extensions/permissions/api_permission_set.h" | 43 #include "chrome/common/extensions/permissions/api_permission_set.h" |
| 44 #include "chrome/common/extensions/permissions/permission_set.h" | 44 #include "chrome/common/extensions/permissions/permission_set.h" |
| 45 #include "chrome/common/extensions/permissions/permissions_info.h" | 45 #include "chrome/common/extensions/permissions/permissions_info.h" |
| 46 #include "chrome/common/extensions/user_script.h" | 46 #include "chrome/common/extensions/user_script.h" |
| 47 #include "chrome/common/url_constants.h" | 47 #include "chrome/common/url_constants.h" |
| 48 #include "crypto/sha2.h" | 48 #include "crypto/sha2.h" |
| 49 #include "extensions/common/constants.h" | 49 #include "extensions/common/constants.h" |
| 50 #include "extensions/common/error_utils.h" | 50 #include "extensions/common/error_utils.h" |
| 51 #include "extensions/common/url_pattern_set.h" | 51 #include "extensions/common/url_pattern_set.h" |
| 52 #include "googleurl/src/url_util.h" | 52 #include "googleurl/src/url_util.h" |
| 53 #include "grit/chromium_strings.h" | 53 #include "grit/chromium_strings.h" |
| 54 #include "grit/theme_resources.h" | 54 #include "grit/theme_resources.h" |
| 55 #include "third_party/skia/include/core/SkBitmap.h" | 55 #include "third_party/skia/include/core/SkBitmap.h" |
| 56 #include "ui/base/l10n/l10n_util.h" | 56 #include "ui/base/l10n/l10n_util.h" |
| 57 #include "ui/base/resource/resource_bundle.h" | |
| 58 #include "webkit/glue/image_decoder.h" | |
| 59 | 57 |
| 60 #if defined(OS_WIN) | 58 #if defined(OS_WIN) |
| 61 #include "base/win/metro.h" | 59 #include "base/win/metro.h" |
| 62 #include "grit/generated_resources.h" | 60 #include "grit/generated_resources.h" |
| 63 #endif | 61 #endif |
| 64 | 62 |
| 65 namespace keys = extension_manifest_keys; | 63 namespace keys = extension_manifest_keys; |
| 66 namespace values = extension_manifest_values; | 64 namespace values = extension_manifest_values; |
| 67 namespace errors = extension_manifest_errors; | 65 namespace errors = extension_manifest_errors; |
| 68 namespace info_keys = extension_info_keys; | 66 namespace info_keys = extension_info_keys; |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 #if defined(OS_WIN) | 206 #if defined(OS_WIN) |
| 209 const char Extension::kExtensionRegistryPath[] = | 207 const char Extension::kExtensionRegistryPath[] = |
| 210 "Software\\Google\\Chrome\\Extensions"; | 208 "Software\\Google\\Chrome\\Extensions"; |
| 211 #endif | 209 #endif |
| 212 | 210 |
| 213 // first 16 bytes of SHA256 hashed public key. | 211 // first 16 bytes of SHA256 hashed public key. |
| 214 const size_t Extension::kIdSize = 16; | 212 const size_t Extension::kIdSize = 16; |
| 215 | 213 |
| 216 const char Extension::kMimeType[] = "application/x-chrome-extension"; | 214 const char Extension::kMimeType[] = "application/x-chrome-extension"; |
| 217 | 215 |
| 218 const int Extension::kPageActionIconMaxSize = 19; | |
| 219 const int Extension::kBrowserActionIconMaxSize = 19; | |
| 220 | |
| 221 const int Extension::kValidWebExtentSchemes = | 216 const int Extension::kValidWebExtentSchemes = |
| 222 URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS; | 217 URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS; |
| 223 | 218 |
| 224 const int Extension::kValidHostPermissionSchemes = | 219 const int Extension::kValidHostPermissionSchemes = |
| 225 UserScript::kValidUserScriptSchemes | URLPattern::SCHEME_CHROMEUI; | 220 UserScript::kValidUserScriptSchemes | URLPattern::SCHEME_CHROMEUI; |
| 226 | 221 |
| 227 Extension::Requirements::Requirements() | 222 Extension::Requirements::Requirements() |
| 228 : webgl(false), | 223 : webgl(false), |
| 229 css3d(false), | 224 css3d(false), |
| 230 npapi(false) { | 225 npapi(false) { |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 output->append(" "); | 475 output->append(" "); |
| 481 output->append(is_public ? kPublic : kPrivate); | 476 output->append(is_public ? kPublic : kPrivate); |
| 482 output->append(" "); | 477 output->append(" "); |
| 483 output->append(kKeyInfoEndMarker); | 478 output->append(kKeyInfoEndMarker); |
| 484 output->append("\n"); | 479 output->append("\n"); |
| 485 | 480 |
| 486 return true; | 481 return true; |
| 487 } | 482 } |
| 488 | 483 |
| 489 // static | 484 // static |
| 490 void Extension::DecodeIcon(const Extension* extension, | |
| 491 int preferred_icon_size, | |
| 492 ExtensionIconSet::MatchType match_type, | |
| 493 scoped_ptr<SkBitmap>* result) { | |
| 494 std::string path = extension->icons().Get(preferred_icon_size, match_type); | |
| 495 int size = extension->icons().GetIconSizeFromPath(path); | |
| 496 ExtensionResource icon_resource = extension->GetResource(path); | |
| 497 DecodeIconFromPath(icon_resource.GetFilePath(), size, result); | |
| 498 } | |
| 499 | |
| 500 // static | |
| 501 void Extension::DecodeIcon(const Extension* extension, | |
| 502 int icon_size, | |
| 503 scoped_ptr<SkBitmap>* result) { | |
| 504 DecodeIcon(extension, icon_size, ExtensionIconSet::MATCH_EXACTLY, result); | |
| 505 } | |
| 506 | |
| 507 // static | |
| 508 void Extension::DecodeIconFromPath(const base::FilePath& icon_path, | |
| 509 int icon_size, | |
| 510 scoped_ptr<SkBitmap>* result) { | |
| 511 if (icon_path.empty()) | |
| 512 return; | |
| 513 | |
| 514 std::string file_contents; | |
| 515 if (!file_util::ReadFileToString(icon_path, &file_contents)) { | |
| 516 DLOG(ERROR) << "Could not read icon file: " << icon_path.LossyDisplayName(); | |
| 517 return; | |
| 518 } | |
| 519 | |
| 520 // Decode the image using WebKit's image decoder. | |
| 521 const unsigned char* data = | |
| 522 reinterpret_cast<const unsigned char*>(file_contents.data()); | |
| 523 webkit_glue::ImageDecoder decoder; | |
| 524 scoped_ptr<SkBitmap> decoded(new SkBitmap()); | |
| 525 *decoded = decoder.Decode(data, file_contents.length()); | |
| 526 if (decoded->empty()) { | |
| 527 DLOG(ERROR) << "Could not decode icon file: " | |
| 528 << icon_path.LossyDisplayName(); | |
| 529 return; | |
| 530 } | |
| 531 | |
| 532 if (decoded->width() != icon_size || decoded->height() != icon_size) { | |
| 533 DLOG(ERROR) << "Icon file has unexpected size: " | |
| 534 << base::IntToString(decoded->width()) << "x" | |
| 535 << base::IntToString(decoded->height()); | |
| 536 return; | |
| 537 } | |
| 538 | |
| 539 result->swap(decoded); | |
| 540 } | |
| 541 | |
| 542 // static | |
| 543 const gfx::ImageSkia& Extension::GetDefaultIcon(bool is_app) { | |
| 544 int id = is_app ? IDR_APP_DEFAULT_ICON : IDR_EXTENSION_DEFAULT_ICON; | |
| 545 return *ResourceBundle::GetSharedInstance().GetImageSkiaNamed(id); | |
| 546 } | |
| 547 | |
| 548 // static | |
| 549 GURL Extension::GetBaseURLFromExtensionId(const std::string& extension_id) { | 485 GURL Extension::GetBaseURLFromExtensionId(const std::string& extension_id) { |
| 550 return GURL(std::string(extensions::kExtensionScheme) + | 486 return GURL(std::string(extensions::kExtensionScheme) + |
| 551 content::kStandardSchemeSeparator + extension_id + "/"); | 487 content::kStandardSchemeSeparator + extension_id + "/"); |
| 552 } | 488 } |
| 553 | 489 |
| 554 // static | 490 // static |
| 555 void Extension::SetScriptingWhitelist( | 491 void Extension::SetScriptingWhitelist( |
| 556 const Extension::ScriptingWhitelist& whitelist) { | 492 const Extension::ScriptingWhitelist& whitelist) { |
| 557 ScriptingWhitelist* current_whitelist = | 493 ScriptingWhitelist* current_whitelist = |
| 558 ExtensionConfig::GetInstance()->whitelist(); | 494 ExtensionConfig::GetInstance()->whitelist(); |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 // no sense for component extensions. | 723 // no sense for component extensions. |
| 788 return location() != Manifest::COMPONENT; | 724 return location() != Manifest::COMPONENT; |
| 789 } | 725 } |
| 790 | 726 |
| 791 std::set<base::FilePath> Extension::GetBrowserImages() const { | 727 std::set<base::FilePath> Extension::GetBrowserImages() const { |
| 792 std::set<base::FilePath> image_paths; | 728 std::set<base::FilePath> image_paths; |
| 793 // TODO(viettrungluu): These |FilePath::FromWStringHack(UTF8ToWide())| | 729 // TODO(viettrungluu): These |FilePath::FromWStringHack(UTF8ToWide())| |
| 794 // indicate that we're doing something wrong. | 730 // indicate that we're doing something wrong. |
| 795 | 731 |
| 796 // Extension icons. | 732 // Extension icons. |
| 797 for (ExtensionIconSet::IconMap::const_iterator iter = icons().map().begin(); | 733 for (ExtensionIconSet::IconMap::const_iterator iter = |
| 798 iter != icons().map().end(); ++iter) { | 734 IconsInfo::GetIcons(this).map().begin(); |
| 735 iter != IconsInfo::GetIcons(this).map().end(); ++iter) { |
| 799 image_paths.insert( | 736 image_paths.insert( |
| 800 base::FilePath::FromWStringHack(UTF8ToWide(iter->second))); | 737 base::FilePath::FromWStringHack(UTF8ToWide(iter->second))); |
| 801 } | 738 } |
| 802 | 739 |
| 803 // Theme images. | 740 // Theme images. |
| 804 DictionaryValue* theme_images = ThemeInfo::GetThemeImages(this); | 741 DictionaryValue* theme_images = ThemeInfo::GetThemeImages(this); |
| 805 if (theme_images) { | 742 if (theme_images) { |
| 806 for (DictionaryValue::Iterator it(*theme_images); !it.IsAtEnd(); | 743 for (DictionaryValue::Iterator it(*theme_images); !it.IsAtEnd(); |
| 807 it.Advance()) { | 744 it.Advance()) { |
| 808 std::string val; | 745 std::string val; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 829 iter != browser_action->default_icon.map().end(); | 766 iter != browser_action->default_icon.map().end(); |
| 830 ++iter) { | 767 ++iter) { |
| 831 image_paths.insert( | 768 image_paths.insert( |
| 832 base::FilePath::FromWStringHack(UTF8ToWide(iter->second))); | 769 base::FilePath::FromWStringHack(UTF8ToWide(iter->second))); |
| 833 } | 770 } |
| 834 } | 771 } |
| 835 | 772 |
| 836 return image_paths; | 773 return image_paths; |
| 837 } | 774 } |
| 838 | 775 |
| 839 ExtensionResource Extension::GetIconResource( | |
| 840 int size, ExtensionIconSet::MatchType match_type) const { | |
| 841 std::string path = icons().Get(size, match_type); | |
| 842 return path.empty() ? ExtensionResource() : GetResource(path); | |
| 843 } | |
| 844 | |
| 845 GURL Extension::GetIconURL(int size, | |
| 846 ExtensionIconSet::MatchType match_type) const { | |
| 847 std::string path = icons().Get(size, match_type); | |
| 848 return path.empty() ? GURL() : GetResourceURL(path); | |
| 849 } | |
| 850 | |
| 851 GURL Extension::GetFullLaunchURL() const { | 776 GURL Extension::GetFullLaunchURL() const { |
| 852 return launch_local_path().empty() ? GURL(launch_web_url()) : | 777 return launch_local_path().empty() ? GURL(launch_web_url()) : |
| 853 url().Resolve(launch_local_path()); | 778 url().Resolve(launch_local_path()); |
| 854 } | 779 } |
| 855 | 780 |
| 856 bool Extension::CanExecuteScriptOnPage(const GURL& document_url, | 781 bool Extension::CanExecuteScriptOnPage(const GURL& document_url, |
| 857 const GURL& top_frame_url, | 782 const GURL& top_frame_url, |
| 858 int tab_id, | 783 int tab_id, |
| 859 const UserScript* script, | 784 const UserScript* script, |
| 860 std::string* error) const { | 785 std::string* error) const { |
| (...skipping 928 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1789 // Override launch url to new tab. | 1714 // Override launch url to new tab. |
| 1790 launch_web_url_ = chrome::kChromeUINewTabURL; | 1715 launch_web_url_ = chrome::kChromeUINewTabURL; |
| 1791 extent_.ClearPatterns(); | 1716 extent_.ClearPatterns(); |
| 1792 } | 1717 } |
| 1793 | 1718 |
| 1794 return true; | 1719 return true; |
| 1795 } | 1720 } |
| 1796 | 1721 |
| 1797 bool Extension::LoadSharedFeatures(string16* error) { | 1722 bool Extension::LoadSharedFeatures(string16* error) { |
| 1798 if (!LoadDescription(error) || | 1723 if (!LoadDescription(error) || |
| 1799 !LoadIcons(error) || | |
| 1800 !ManifestHandler::ParseExtension(this, error) || | 1724 !ManifestHandler::ParseExtension(this, error) || |
| 1801 !LoadPlugins(error) || | 1725 !LoadPlugins(error) || |
| 1802 !LoadNaClModules(error) || | 1726 !LoadNaClModules(error) || |
| 1803 !LoadSandboxedPages(error) || | 1727 !LoadSandboxedPages(error) || |
| 1804 !LoadRequirements(error) || | 1728 !LoadRequirements(error) || |
| 1805 !LoadOfflineEnabled(error) || | 1729 !LoadOfflineEnabled(error) || |
| 1806 // LoadBackgroundScripts() must be called before LoadBackgroundPage(). | 1730 // LoadBackgroundScripts() must be called before LoadBackgroundPage(). |
| 1807 !LoadBackgroundScripts(error) || | 1731 !LoadBackgroundScripts(error) || |
| 1808 !LoadBackgroundPage(error) || | 1732 !LoadBackgroundPage(error) || |
| 1809 !LoadBackgroundPersistent(error) || | 1733 !LoadBackgroundPersistent(error) || |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1841 switches::kAllowLegacyExtensionManifests)) { | 1765 switches::kAllowLegacyExtensionManifests)) { |
| 1842 *error = ErrorUtils::FormatErrorMessageUTF16( | 1766 *error = ErrorUtils::FormatErrorMessageUTF16( |
| 1843 errors::kInvalidManifestVersionOld, | 1767 errors::kInvalidManifestVersionOld, |
| 1844 base::IntToString(kModernManifestVersion)); | 1768 base::IntToString(kModernManifestVersion)); |
| 1845 return false; | 1769 return false; |
| 1846 } | 1770 } |
| 1847 | 1771 |
| 1848 return true; | 1772 return true; |
| 1849 } | 1773 } |
| 1850 | 1774 |
| 1851 bool Extension::LoadIcons(string16* error) { | |
| 1852 if (!manifest_->HasKey(keys::kIcons)) | |
| 1853 return true; | |
| 1854 DictionaryValue* icons_value = NULL; | |
| 1855 if (!manifest_->GetDictionary(keys::kIcons, &icons_value)) { | |
| 1856 *error = ASCIIToUTF16(errors::kInvalidIcons); | |
| 1857 return false; | |
| 1858 } | |
| 1859 | |
| 1860 return manifest_handler_helpers::LoadIconsFromDictionary( | |
| 1861 icons_value, | |
| 1862 extension_misc::kExtensionIconSizes, | |
| 1863 extension_misc::kNumExtensionIconSizes, | |
| 1864 &icons_, | |
| 1865 error); | |
| 1866 } | |
| 1867 | |
| 1868 bool Extension::LoadPlugins(string16* error) { | 1775 bool Extension::LoadPlugins(string16* error) { |
| 1869 if (!manifest_->HasKey(keys::kPlugins)) | 1776 if (!manifest_->HasKey(keys::kPlugins)) |
| 1870 return true; | 1777 return true; |
| 1871 | 1778 |
| 1872 ListValue* list_value = NULL; | 1779 ListValue* list_value = NULL; |
| 1873 if (!manifest_->GetList(keys::kPlugins, &list_value)) { | 1780 if (!manifest_->GetList(keys::kPlugins, &list_value)) { |
| 1874 *error = ASCIIToUTF16(errors::kInvalidPlugins); | 1781 *error = ASCIIToUTF16(errors::kInvalidPlugins); |
| 1875 return false; | 1782 return false; |
| 1876 } | 1783 } |
| 1877 | 1784 |
| (...skipping 854 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2732 | 2639 |
| 2733 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 2640 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
| 2734 const Extension* extension, | 2641 const Extension* extension, |
| 2735 const PermissionSet* permissions, | 2642 const PermissionSet* permissions, |
| 2736 Reason reason) | 2643 Reason reason) |
| 2737 : reason(reason), | 2644 : reason(reason), |
| 2738 extension(extension), | 2645 extension(extension), |
| 2739 permissions(permissions) {} | 2646 permissions(permissions) {} |
| 2740 | 2647 |
| 2741 } // namespace extensions | 2648 } // namespace extensions |
| OLD | NEW |