Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(129)

Side by Side Diff: chrome/common/extensions/extension.cc

Issue 4687005: Track permissions granted to extensions in prefs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 1111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1122 std::inserter(new_only, new_only.end())); 1122 std::inserter(new_only, new_only.end()));
1123 1123
1124 // If there are any new permission messages, then it's an increase. 1124 // If there are any new permission messages, then it's an increase.
1125 if (!new_only.empty()) 1125 if (!new_only.empty())
1126 return true; 1126 return true;
1127 1127
1128 return false; 1128 return false;
1129 } 1129 }
1130 1130
1131 // static 1131 // static
1132 // TODO(jstritar): This can be combined with the other IsPrivilegeIncrease
1133 // so that extensions can remove and re-add permissions during upgrades.
Aaron Boodman 2010/11/12 00:05:24 I don't understand this comment. Can you combine t
jstritar 2010/11/19 21:38:36 Okay, I combined both IsPrivilegeIncreases and upd
1134 bool Extension::IsPrivilegeIncrease(const std::set<std::string>* granted_apis,
1135 const std::set<std::string>* granted_hosts,
1136 const Extension* extension) {
1137 // TODO(erikkay) This will trip when you add a new distinct hostname,
1138 // but we should unique based on RCD as well. crbug.com/57042
1139 std::set<std::string> new_hosts;
1140 std::set<std::string> new_hosts_only;
1141
1142 extension->GetEffectiveHostPermissions().GetAsStringSet(&new_hosts);
1143 std::set_difference(new_hosts.begin(), new_hosts.end(),
1144 granted_hosts->begin(), granted_hosts->end(),
1145 std::inserter(new_hosts_only, new_hosts_only.end()));
1146
1147 if (!new_hosts_only.empty())
1148 return true;
1149
1150 std::set<std::string> new_apis = extension->api_permissions();
1151 std::set<std::string> new_apis_only;
1152 std::set_difference(new_apis.begin(), new_apis.end(),
1153 granted_apis->begin(), granted_apis->end(),
1154 std::inserter(new_apis_only, new_apis_only.end()));
1155
1156 if (!new_apis_only.empty())
1157 return true;
1158
1159 return false;
1160 }
1161
1162 // static
1132 void Extension::DecodeIcon(const Extension* extension, 1163 void Extension::DecodeIcon(const Extension* extension,
1133 Icons icon_size, 1164 Icons icon_size,
1134 scoped_ptr<SkBitmap>* result) { 1165 scoped_ptr<SkBitmap>* result) {
1135 FilePath icon_path = extension->GetIconResource( 1166 FilePath icon_path = extension->GetIconResource(
1136 icon_size, ExtensionIconSet::MATCH_EXACTLY).GetFilePath(); 1167 icon_size, ExtensionIconSet::MATCH_EXACTLY).GetFilePath();
1137 DecodeIconFromPath(icon_path, icon_size, result); 1168 DecodeIconFromPath(icon_path, icon_size, result);
1138 } 1169 }
1139 1170
1140 // static 1171 // static
1141 void Extension::DecodeIconFromPath(const FilePath& icon_path, 1172 void Extension::DecodeIconFromPath(const FilePath& icon_path,
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after
1699 continue; 1730 continue;
1700 } 1731 }
1701 } else { 1732 } else {
1702 // Hosted apps only get access to a subset of the valid permissions. 1733 // Hosted apps only get access to a subset of the valid permissions.
1703 if (IsHostedAppPermission(permission_str)) { 1734 if (IsHostedAppPermission(permission_str)) {
1704 api_permissions_.insert(permission_str); 1735 api_permissions_.insert(permission_str);
1705 continue; 1736 continue;
1706 } 1737 }
1707 } 1738 }
1708 1739
1709 // Otherwise, it's a host pattern permission. 1740 // Check if it's a host pattern permission.
1710 URLPattern pattern = URLPattern(CanExecuteScriptEverywhere() ? 1741 URLPattern pattern = URLPattern(CanExecuteScriptEverywhere() ?
1711 URLPattern::SCHEME_ALL : 1742 URLPattern::SCHEME_ALL :
1712 (UserScript::kValidUserScriptSchemes | 1743 (UserScript::kValidUserScriptSchemes |
1713 URLPattern::SCHEME_CHROMEUI) & ~URLPattern::SCHEME_FILE); 1744 URLPattern::SCHEME_CHROMEUI) & ~URLPattern::SCHEME_FILE);
1714 1745
1715 if (URLPattern::PARSE_SUCCESS != pattern.Parse(permission_str)) { 1746 if (URLPattern::PARSE_SUCCESS == pattern.Parse(permission_str)) {
1716 *error = ExtensionErrorUtils::FormatErrorMessage( 1747 if (!CanSpecifyHostPermission(pattern)) {
1717 errors::kInvalidPermission, base::IntToString(i)); 1748 *error = ExtensionErrorUtils::FormatErrorMessage(
1718 return false; 1749 errors::kInvalidPermissionScheme, base::IntToString(i));
1750 return false;
1751 }
1752
1753 // The path component is not used for host permissions, so we force it
1754 // to match all paths.
1755 pattern.set_path("/*");
1756
1757 host_permissions_.push_back(pattern);
1719 } 1758 }
1720 1759
1721 if (!CanSpecifyHostPermission(pattern)) { 1760 // If it's not a host permission, then it's probably an unknown API
1722 *error = ExtensionErrorUtils::FormatErrorMessage( 1761 // permission. Do not throw an error so extensions can retain
1723 errors::kInvalidPermissionScheme, base::IntToString(i)); 1762 // backwards compatability.
Aaron Boodman 2010/11/12 00:05:24 This is a good place to add a link to the bug, so
jstritar 2010/11/19 21:38:36 Done.
1724 return false;
1725 }
1726
1727 // The path component is not used for host permissions, so we force it to
1728 // match all paths.
1729 pattern.set_path("/*");
1730
1731 host_permissions_.push_back(pattern);
1732 } 1763 }
1733 } 1764 }
1734 1765
1735 if (source.HasKey(keys::kDefaultLocale)) { 1766 if (source.HasKey(keys::kDefaultLocale)) {
1736 if (!source.GetString(keys::kDefaultLocale, 1767 if (!source.GetString(keys::kDefaultLocale,
1737 &default_locale_) || 1768 &default_locale_) ||
1738 default_locale_.empty()) { 1769 default_locale_.empty()) {
1739 *error = errors::kInvalidDefaultLocale; 1770 *error = errors::kInvalidDefaultLocale;
1740 return false; 1771 return false;
1741 } 1772 }
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
2210 UninstalledExtensionInfo::UninstalledExtensionInfo( 2241 UninstalledExtensionInfo::UninstalledExtensionInfo(
2211 const Extension& extension) 2242 const Extension& extension)
2212 : extension_id(extension.id()), 2243 : extension_id(extension.id()),
2213 extension_api_permissions(extension.api_permissions()), 2244 extension_api_permissions(extension.api_permissions()),
2214 is_theme(extension.is_theme()), 2245 is_theme(extension.is_theme()),
2215 is_app(extension.is_app()), 2246 is_app(extension.is_app()),
2216 converted_from_user_script(extension.converted_from_user_script()), 2247 converted_from_user_script(extension.converted_from_user_script()),
2217 update_url(extension.update_url()) {} 2248 update_url(extension.update_url()) {}
2218 2249
2219 UninstalledExtensionInfo::~UninstalledExtensionInfo() {} 2250 UninstalledExtensionInfo::~UninstalledExtensionInfo() {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698