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

Side by Side Diff: chrome/browser/extensions/extension_special_storage_policy.cc

Issue 10709006: Show apps protecting local data in chrome://settings/cookies. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: argh Created 8 years, 5 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
OLDNEW
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/browser/extensions/extension_special_storage_policy.h" 5 #include "chrome/browser/extensions/extension_special_storage_policy.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/stl_util.h"
9 #include "chrome/browser/content_settings/cookie_settings.h" 10 #include "chrome/browser/content_settings/cookie_settings.h"
10 #include "chrome/common/content_settings.h" 11 #include "chrome/common/content_settings.h"
11 #include "chrome/common/content_settings_types.h" 12 #include "chrome/common/content_settings_types.h"
12 #include "chrome/common/extensions/extension.h" 13 #include "chrome/common/extensions/extension.h"
13 #include "chrome/common/url_constants.h" 14 #include "chrome/common/url_constants.h"
14 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
15 16
16 using content::BrowserThread; 17 using content::BrowserThread;
17 using extensions::APIPermission; 18 using extensions::APIPermission;
18 19
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 const std::string& extension_id) { 60 const std::string& extension_id) {
60 base::AutoLock locker(lock_); 61 base::AutoLock locker(lock_);
61 return file_handler_extensions_.ContainsExtension(extension_id); 62 return file_handler_extensions_.ContainsExtension(extension_id);
62 } 63 }
63 64
64 bool ExtensionSpecialStoragePolicy::NeedsProtection( 65 bool ExtensionSpecialStoragePolicy::NeedsProtection(
65 const extensions::Extension* extension) { 66 const extensions::Extension* extension) {
66 return extension->is_hosted_app() && !extension->from_bookmark(); 67 return extension->is_hosted_app() && !extension->from_bookmark();
67 } 68 }
68 69
70 const ExtensionSet* ExtensionSpecialStoragePolicy::ExtensionsProtectingOrigin(
71 const GURL& origin) {
72 base::AutoLock locker(lock_);
73 return protected_apps_.ExtensionsContaining(origin);
74 }
75
69 void ExtensionSpecialStoragePolicy::GrantRightsForExtension( 76 void ExtensionSpecialStoragePolicy::GrantRightsForExtension(
70 const extensions::Extension* extension) { 77 const extensions::Extension* extension) {
71 DCHECK(extension); 78 DCHECK(extension);
72 if (!extension->is_hosted_app() && 79 if (!NeedsProtection(extension) &&
73 !extension->HasAPIPermission( 80 !extension->HasAPIPermission(
74 APIPermission::kUnlimitedStorage) && 81 APIPermission::kUnlimitedStorage) &&
75 !extension->HasAPIPermission( 82 !extension->HasAPIPermission(
76 APIPermission::kFileBrowserHandler)) { 83 APIPermission::kFileBrowserHandler)) {
77 return; 84 return;
78 } 85 }
79 { 86 {
80 base::AutoLock locker(lock_); 87 base::AutoLock locker(lock_);
81 if (NeedsProtection(extension)) 88 if (NeedsProtection(extension))
82 protected_apps_.Add(extension); 89 protected_apps_.Add(extension);
83 if (extension->HasAPIPermission(APIPermission::kUnlimitedStorage)) 90 if (extension->HasAPIPermission(APIPermission::kUnlimitedStorage))
84 unlimited_extensions_.Add(extension); 91 unlimited_extensions_.Add(extension);
85 if (extension->HasAPIPermission( 92 if (extension->HasAPIPermission(
86 APIPermission::kFileBrowserHandler)) { 93 APIPermission::kFileBrowserHandler)) {
87 file_handler_extensions_.Add(extension); 94 file_handler_extensions_.Add(extension);
88 } 95 }
89 } 96 }
90 NotifyChanged(); 97 NotifyChanged();
91 } 98 }
92 99
93 void ExtensionSpecialStoragePolicy::RevokeRightsForExtension( 100 void ExtensionSpecialStoragePolicy::RevokeRightsForExtension(
94 const extensions::Extension* extension) { 101 const extensions::Extension* extension) {
95 DCHECK(extension); 102 DCHECK(extension);
96 if (!extension->is_hosted_app() && 103 if (!NeedsProtection(extension) &&
97 !extension->HasAPIPermission( 104 !extension->HasAPIPermission(
98 APIPermission::kUnlimitedStorage) && 105 APIPermission::kUnlimitedStorage) &&
99 !extension->HasAPIPermission( 106 !extension->HasAPIPermission(
100 APIPermission::kFileBrowserHandler)) { 107 APIPermission::kFileBrowserHandler)) {
101 return; 108 return;
102 } 109 }
103 { 110 {
104 base::AutoLock locker(lock_); 111 base::AutoLock locker(lock_);
105 if (extension->is_hosted_app() && !extension->from_bookmark()) 112 if (NeedsProtection(extension))
106 protected_apps_.Remove(extension); 113 protected_apps_.Remove(extension);
107 if (extension->HasAPIPermission(APIPermission::kUnlimitedStorage)) 114 if (extension->HasAPIPermission(APIPermission::kUnlimitedStorage))
108 unlimited_extensions_.Remove(extension); 115 unlimited_extensions_.Remove(extension);
109 if (extension->HasAPIPermission( 116 if (extension->HasAPIPermission(APIPermission::kFileBrowserHandler))
110 APIPermission::kFileBrowserHandler)) {
111 file_handler_extensions_.Remove(extension); 117 file_handler_extensions_.Remove(extension);
112 }
113 } 118 }
114 NotifyChanged(); 119 NotifyChanged();
115 } 120 }
116 121
117 void ExtensionSpecialStoragePolicy::RevokeRightsForAllExtensions() { 122 void ExtensionSpecialStoragePolicy::RevokeRightsForAllExtensions() {
118 { 123 {
119 base::AutoLock locker(lock_); 124 base::AutoLock locker(lock_);
120 protected_apps_.Clear(); 125 protected_apps_.Clear();
121 unlimited_extensions_.Clear(); 126 unlimited_extensions_.Clear();
122 file_handler_extensions_.Clear(); 127 file_handler_extensions_.Clear();
123 } 128 }
124 NotifyChanged(); 129 NotifyChanged();
125 } 130 }
126 131
127 void ExtensionSpecialStoragePolicy::NotifyChanged() { 132 void ExtensionSpecialStoragePolicy::NotifyChanged() {
128 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { 133 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
129 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 134 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
130 base::Bind(&ExtensionSpecialStoragePolicy::NotifyChanged, this)); 135 base::Bind(&ExtensionSpecialStoragePolicy::NotifyChanged, this));
131 return; 136 return;
132 } 137 }
133 SpecialStoragePolicy::NotifyObservers(); 138 SpecialStoragePolicy::NotifyObservers();
134 } 139 }
135 140
136 //----------------------------------------------------------------------------- 141 //-----------------------------------------------------------------------------
137 // SpecialCollection helper class 142 // SpecialCollection helper class
138 //----------------------------------------------------------------------------- 143 //-----------------------------------------------------------------------------
139 144
140 ExtensionSpecialStoragePolicy::SpecialCollection::SpecialCollection() {} 145 ExtensionSpecialStoragePolicy::SpecialCollection::SpecialCollection() {}
141 146
142 ExtensionSpecialStoragePolicy::SpecialCollection::~SpecialCollection() {} 147 ExtensionSpecialStoragePolicy::SpecialCollection::~SpecialCollection() {
148 STLDeleteValues(&cached_results_);
149 }
143 150
144 bool ExtensionSpecialStoragePolicy::SpecialCollection::Contains( 151 bool ExtensionSpecialStoragePolicy::SpecialCollection::Contains(
145 const GURL& origin) { 152 const GURL& origin) {
153 return !ExtensionsContaining(origin)->is_empty();
154 }
155
156 const ExtensionSet*
157 ExtensionSpecialStoragePolicy::SpecialCollection::ExtensionsContaining(
158 const GURL& origin) {
146 CachedResults::const_iterator found = cached_results_.find(origin); 159 CachedResults::const_iterator found = cached_results_.find(origin);
147 if (found != cached_results_.end()) 160 if (found != cached_results_.end())
148 return found->second; 161 return found->second;
149 162
150 for (Extensions::const_iterator iter = extensions_.begin(); 163 ExtensionSet* result = new ExtensionSet();
164 for (ExtensionSet::const_iterator iter = extensions_.begin();
151 iter != extensions_.end(); ++iter) { 165 iter != extensions_.end(); ++iter) {
152 if (iter->second->OverlapsWithOrigin(origin)) { 166 if ((*iter)->OverlapsWithOrigin(origin))
153 cached_results_[origin] = true; 167 result->Insert(*iter);
154 return true;
155 }
156 } 168 }
157 cached_results_[origin] = false; 169 cached_results_[origin] = result;
158 return false; 170 return result;
159 } 171 }
160 172
161 bool ExtensionSpecialStoragePolicy::SpecialCollection::ContainsExtension( 173 bool ExtensionSpecialStoragePolicy::SpecialCollection::ContainsExtension(
162 const std::string& extension_id) { 174 const std::string& extension_id) {
163 return extensions_.find(extension_id) != extensions_.end(); 175 return extensions_.Contains(extension_id);
164 } 176 }
165 177
166 void ExtensionSpecialStoragePolicy::SpecialCollection::Add( 178 void ExtensionSpecialStoragePolicy::SpecialCollection::Add(
167 const extensions::Extension* extension) { 179 const extensions::Extension* extension) {
168 cached_results_.clear(); 180 ClearCache();
169 extensions_[extension->id()] = extension; 181 extensions_.Insert(extension);
170 } 182 }
171 183
172 void ExtensionSpecialStoragePolicy::SpecialCollection::Remove( 184 void ExtensionSpecialStoragePolicy::SpecialCollection::Remove(
173 const extensions::Extension* extension) { 185 const extensions::Extension* extension) {
174 cached_results_.clear(); 186 ClearCache();
175 extensions_.erase(extension->id()); 187 extensions_.Remove(extension->id());
176 } 188 }
177 189
178 void ExtensionSpecialStoragePolicy::SpecialCollection::Clear() { 190 void ExtensionSpecialStoragePolicy::SpecialCollection::Clear() {
191 ClearCache();
192 extensions_.Clear();
193 }
194
195 void ExtensionSpecialStoragePolicy::SpecialCollection::ClearCache() {
196 STLDeleteValues(&cached_results_);
179 cached_results_.clear(); 197 cached_results_.clear();
180 extensions_.clear();
181 } 198 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698