| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "base/base64.h" | 10 #include "base/base64.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 | 87 |
| 88 bool IsBaseCrxKey(const std::string& key) { | 88 bool IsBaseCrxKey(const std::string& key) { |
| 89 for (size_t i = 0; i < arraysize(kBaseCrxKeys); ++i) { | 89 for (size_t i = 0; i < arraysize(kBaseCrxKeys); ++i) { |
| 90 if (key == kBaseCrxKeys[i]) | 90 if (key == kBaseCrxKeys[i]) |
| 91 return true; | 91 return true; |
| 92 } | 92 } |
| 93 | 93 |
| 94 return false; | 94 return false; |
| 95 } | 95 } |
| 96 | 96 |
| 97 // Names of API modules that do not require a permission. |
| 98 const char kBrowserActionModuleName[] = "browserAction"; |
| 99 const char kBrowserActionsModuleName[] = "browserActions"; |
| 100 const char kDevToolsModuleName[] = "devtools"; |
| 101 const char kExtensionModuleName[] = "extension"; |
| 102 const char kI18NModuleName[] = "i18n"; |
| 103 const char kPageActionModuleName[] = "pageAction"; |
| 104 const char kPageActionsModuleName[] = "pageActions"; |
| 105 const char kTestModuleName[] = "test"; |
| 106 |
| 107 const char* kNonPermissionModuleNames[] = { |
| 108 kBrowserActionModuleName, |
| 109 kBrowserActionsModuleName, |
| 110 kDevToolsModuleName, |
| 111 kExtensionModuleName, |
| 112 kI18NModuleName, |
| 113 kPageActionModuleName, |
| 114 kPageActionsModuleName, |
| 115 kTestModuleName |
| 116 }; |
| 117 const size_t kNumNonPermissionModuleNames = |
| 118 arraysize(kNonPermissionModuleNames); |
| 119 |
| 97 } // namespace | 120 } // namespace |
| 98 | 121 |
| 99 const FilePath::CharType Extension::kManifestFilename[] = | 122 const FilePath::CharType Extension::kManifestFilename[] = |
| 100 FILE_PATH_LITERAL("manifest.json"); | 123 FILE_PATH_LITERAL("manifest.json"); |
| 101 const FilePath::CharType Extension::kLocaleFolder[] = | 124 const FilePath::CharType Extension::kLocaleFolder[] = |
| 102 FILE_PATH_LITERAL("_locales"); | 125 FILE_PATH_LITERAL("_locales"); |
| 103 const FilePath::CharType Extension::kMessagesFilename[] = | 126 const FilePath::CharType Extension::kMessagesFilename[] = |
| 104 FILE_PATH_LITERAL("messages.json"); | 127 FILE_PATH_LITERAL("messages.json"); |
| 105 | 128 |
| 106 #if defined(OS_WIN) | 129 #if defined(OS_WIN) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 117 EXTENSION_ICON_LARGE, | 140 EXTENSION_ICON_LARGE, |
| 118 EXTENSION_ICON_MEDIUM, | 141 EXTENSION_ICON_MEDIUM, |
| 119 EXTENSION_ICON_SMALL, | 142 EXTENSION_ICON_SMALL, |
| 120 EXTENSION_ICON_SMALLISH, | 143 EXTENSION_ICON_SMALLISH, |
| 121 EXTENSION_ICON_BITTY | 144 EXTENSION_ICON_BITTY |
| 122 }; | 145 }; |
| 123 | 146 |
| 124 const int Extension::kPageActionIconMaxSize = 19; | 147 const int Extension::kPageActionIconMaxSize = 19; |
| 125 const int Extension::kBrowserActionIconMaxSize = 19; | 148 const int Extension::kBrowserActionIconMaxSize = 19; |
| 126 | 149 |
| 150 // Explicit permissions -- permission declaration required. |
| 127 const char* Extension::kBackgroundPermission = "background"; | 151 const char* Extension::kBackgroundPermission = "background"; |
| 128 const char* Extension::kContextMenusPermission = "contextMenus"; | 152 const char* Extension::kContextMenusPermission = "contextMenus"; |
| 129 const char* Extension::kBookmarkPermission = "bookmarks"; | 153 const char* Extension::kBookmarkPermission = "bookmarks"; |
| 130 const char* Extension::kCookiePermission = "cookies"; | 154 const char* Extension::kCookiePermission = "cookies"; |
| 131 const char* Extension::kExperimentalPermission = "experimental"; | 155 const char* Extension::kExperimentalPermission = "experimental"; |
| 132 const char* Extension::kGeolocationPermission = "geolocation"; | 156 const char* Extension::kGeolocationPermission = "geolocation"; |
| 133 const char* Extension::kHistoryPermission = "history"; | 157 const char* Extension::kHistoryPermission = "history"; |
| 134 const char* Extension::kIdlePermission = "idle"; | 158 const char* Extension::kIdlePermission = "idle"; |
| 135 const char* Extension::kNotificationPermission = "notifications"; | 159 const char* Extension::kNotificationPermission = "notifications"; |
| 136 const char* Extension::kProxyPermission = "proxy"; | 160 const char* Extension::kProxyPermission = "proxy"; |
| (...skipping 1580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1717 // Only allow access to chrome://favicon to regular extensions. Component | 1741 // Only allow access to chrome://favicon to regular extensions. Component |
| 1718 // extensions can have access to all of chrome://*. | 1742 // extensions can have access to all of chrome://*. |
| 1719 return (pattern.host() == chrome::kChromeUIFavIconHost || | 1743 return (pattern.host() == chrome::kChromeUIFavIconHost || |
| 1720 location() == Extension::COMPONENT); | 1744 location() == Extension::COMPONENT); |
| 1721 } | 1745 } |
| 1722 | 1746 |
| 1723 // Otherwise, the valid schemes were handled by URLPattern. | 1747 // Otherwise, the valid schemes were handled by URLPattern. |
| 1724 return true; | 1748 return true; |
| 1725 } | 1749 } |
| 1726 | 1750 |
| 1751 // static. |
| 1752 bool Extension::HasApiPermission( |
| 1753 const std::vector<std::string>& api_permissions, |
| 1754 const std::string& permission) { |
| 1755 std::string permission_name = permission; |
| 1756 |
| 1757 // windows and tabs are the same permission. |
| 1758 if (permission_name == "windows") |
| 1759 permission_name = Extension::kTabPermission; |
| 1760 |
| 1761 if (std::find(api_permissions.begin(), api_permissions.end(), |
| 1762 permission_name) != api_permissions.end()) |
| 1763 return true; |
| 1764 |
| 1765 for (size_t i = 0; i < kNumNonPermissionModuleNames; ++i) { |
| 1766 if (permission_name == kNonPermissionModuleNames[i]) { |
| 1767 return true; |
| 1768 } |
| 1769 } |
| 1770 |
| 1771 return false; |
| 1772 } |
| 1773 |
| 1727 bool Extension::HasHostPermission(const GURL& url) const { | 1774 bool Extension::HasHostPermission(const GURL& url) const { |
| 1728 for (URLPatternList::const_iterator host = host_permissions_.begin(); | 1775 for (URLPatternList::const_iterator host = host_permissions_.begin(); |
| 1729 host != host_permissions_.end(); ++host) { | 1776 host != host_permissions_.end(); ++host) { |
| 1730 if (host->MatchesUrl(url)) | 1777 if (host->MatchesUrl(url)) |
| 1731 return true; | 1778 return true; |
| 1732 } | 1779 } |
| 1733 return false; | 1780 return false; |
| 1734 } | 1781 } |
| 1735 | 1782 |
| 1736 const ExtensionExtent Extension::GetEffectiveHostPermissions() const { | 1783 const ExtensionExtent Extension::GetEffectiveHostPermissions() const { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1804 : extension_id(id), | 1851 : extension_id(id), |
| 1805 extension_path(path), | 1852 extension_path(path), |
| 1806 extension_location(location) { | 1853 extension_location(location) { |
| 1807 if (manifest) | 1854 if (manifest) |
| 1808 extension_manifest.reset( | 1855 extension_manifest.reset( |
| 1809 static_cast<DictionaryValue*>(manifest->DeepCopy())); | 1856 static_cast<DictionaryValue*>(manifest->DeepCopy())); |
| 1810 } | 1857 } |
| 1811 | 1858 |
| 1812 ExtensionInfo::~ExtensionInfo() { | 1859 ExtensionInfo::~ExtensionInfo() { |
| 1813 } | 1860 } |
| OLD | NEW |