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

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

Issue 2808051: Refactored extension privilege enumeration and implemented URLPattern compari... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 4 months 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
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | chrome/common/extensions/extension_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 844 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 // Otherwise, if the new extension has a plugin, it's a privilege increase. 855 // Otherwise, if the new extension has a plugin, it's a privilege increase.
856 if (new_extension->plugins().size() > 0) 856 if (new_extension->plugins().size() > 0)
857 return true; 857 return true;
858 858
859 // If we are increasing the set of hosts we have access to, it's a privilege 859 // If we are increasing the set of hosts we have access to, it's a privilege
860 // increase. 860 // increase.
861 if (!old_extension->HasAccessToAllHosts()) { 861 if (!old_extension->HasAccessToAllHosts()) {
862 if (new_extension->HasAccessToAllHosts()) 862 if (new_extension->HasAccessToAllHosts())
863 return true; 863 return true;
864 864
865 std::set<std::string> old_hosts = 865 ExtensionExtent::PatternList old_hosts =
866 old_extension->GetEffectiveHostPermissions(); 866 old_extension->GetEffectiveHostPermissions().patterns();
867 std::set<std::string> new_hosts = 867 ExtensionExtent::PatternList new_hosts =
868 new_extension->GetEffectiveHostPermissions(); 868 new_extension->GetEffectiveHostPermissions().patterns();
869 869
870 std::set<std::string> difference; 870 std::set<URLPattern, URLPattern::EffectiveHostCompareFunctor> diff;
871 std::set_difference(new_hosts.begin(), new_hosts.end(), 871 std::set_difference(new_hosts.begin(), new_hosts.end(),
872 old_hosts.begin(), old_hosts.end(), 872 old_hosts.begin(), old_hosts.end(),
873 std::insert_iterator<std::set<std::string> >( 873 std::insert_iterator<std::set<URLPattern,
874 difference, difference.end())); 874 URLPattern::EffectiveHostCompareFunctor> >(diff, diff.end()),
875 if (difference.size() > 0) 875 URLPattern::EffectiveHostCompare);
876 if (diff.size() > 0)
876 return true; 877 return true;
877 } 878 }
878 879
879 if (!old_extension->HasEffectiveBrowsingHistoryPermission() && 880 if (!old_extension->HasEffectiveBrowsingHistoryPermission() &&
880 new_extension->HasEffectiveBrowsingHistoryPermission()) { 881 new_extension->HasEffectiveBrowsingHistoryPermission()) {
881 return true; 882 return true;
882 } 883 }
883 884
884 const SimplePermissions& simple_permissions = GetSimplePermissions(); 885 const SimplePermissions& simple_permissions = GetSimplePermissions();
885 for (SimplePermissions::const_iterator iter = simple_permissions.begin(); 886 for (SimplePermissions::const_iterator iter = simple_permissions.begin();
(...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after
1686 1687
1687 bool Extension::HasHostPermission(const GURL& url) const { 1688 bool Extension::HasHostPermission(const GURL& url) const {
1688 for (URLPatternList::const_iterator host = host_permissions_.begin(); 1689 for (URLPatternList::const_iterator host = host_permissions_.begin();
1689 host != host_permissions_.end(); ++host) { 1690 host != host_permissions_.end(); ++host) {
1690 if (host->MatchesUrl(url)) 1691 if (host->MatchesUrl(url))
1691 return true; 1692 return true;
1692 } 1693 }
1693 return false; 1694 return false;
1694 } 1695 }
1695 1696
1696 const std::set<std::string> Extension::GetEffectiveHostPermissions() const { 1697 const ExtensionExtent Extension::GetEffectiveHostPermissions() const {
1697 std::set<std::string> effective_hosts; 1698 ExtensionExtent effective_hosts;
1698 1699
1699 for (URLPatternList::const_iterator host = host_permissions_.begin(); 1700 for (URLPatternList::const_iterator host = host_permissions_.begin();
1700 host != host_permissions_.end(); ++host) 1701 host != host_permissions_.end(); ++host)
1701 effective_hosts.insert(host->host()); 1702 effective_hosts.AddPattern(*host);
1702 1703
1703 for (UserScriptList::const_iterator content_script = content_scripts_.begin(); 1704 for (UserScriptList::const_iterator content_script = content_scripts_.begin();
1704 content_script != content_scripts_.end(); ++content_script) { 1705 content_script != content_scripts_.end(); ++content_script) {
1705 UserScript::PatternList::const_iterator pattern = 1706 UserScript::PatternList::const_iterator pattern =
1706 content_script->url_patterns().begin(); 1707 content_script->url_patterns().begin();
1707 for (; pattern != content_script->url_patterns().end(); ++pattern) 1708 for (; pattern != content_script->url_patterns().end(); ++pattern)
1708 effective_hosts.insert(pattern->host()); 1709 effective_hosts.AddPattern(*pattern);
1709 } 1710 }
1710 1711
1711 return effective_hosts; 1712 return effective_hosts;
1712 } 1713 }
1713 1714
1714 bool Extension::HasAccessToAllHosts() const { 1715 bool Extension::HasAccessToAllHosts() const {
1715 for (URLPatternList::const_iterator host = host_permissions_.begin(); 1716 for (URLPatternList::const_iterator host = host_permissions_.begin();
1716 host != host_permissions_.end(); ++host) { 1717 host != host_permissions_.end(); ++host) {
1717 if (host->match_subdomains() && host->host().empty()) 1718 if (host->match_subdomains() && host->host().empty())
1718 return true; 1719 return true;
(...skipping 26 matching lines...) Expand all
1745 } else { 1746 } else {
1746 return false; 1747 return false;
1747 } 1748 }
1748 } else { 1749 } else {
1749 return true; 1750 return true;
1750 } 1751 }
1751 } 1752 }
1752 } 1753 }
1753 return false; 1754 return false;
1754 } 1755 }
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | chrome/common/extensions/extension_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698