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

Side by Side Diff: chrome/browser/extensions/api/declarative/rules_registry_storage_delegate.cc

Issue 10831008: Refactor and fix declarative webRequest API permissions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed license headers Created 8 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
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/api/declarative/rules_registry_storage_deleg ate.h" 5 #include "chrome/browser/extensions/api/declarative/rules_registry_storage_deleg ate.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "chrome/browser/extensions/extension_info_map.h"
9 #include "chrome/browser/extensions/extension_service.h"
8 #include "chrome/browser/extensions/extension_system.h" 10 #include "chrome/browser/extensions/extension_system.h"
9 #include "chrome/browser/extensions/state_store.h" 11 #include "chrome/browser/extensions/state_store.h"
12 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/common/chrome_notification_types.h" 13 #include "chrome/common/chrome_notification_types.h"
11 #include "chrome/common/extensions/extension.h" 14 #include "chrome/common/extensions/extension.h"
12 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
13 #include "content/public/browser/notification_details.h" 16 #include "content/public/browser/notification_details.h"
14 #include "content/public/browser/notification_source.h" 17 #include "content/public/browser/notification_source.h"
15 18
16 namespace extensions { 19 namespace extensions {
17 20
18 namespace { 21 namespace {
19 22
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 Inner(Profile* profile, 60 Inner(Profile* profile,
58 RulesRegistryWithCache* rules_registry, 61 RulesRegistryWithCache* rules_registry,
59 const std::string& storage_key); 62 const std::string& storage_key);
60 63
61 private: 64 private:
62 friend class base::RefCountedThreadSafe<Inner>; 65 friend class base::RefCountedThreadSafe<Inner>;
63 friend class RulesRegistryStorageDelegate; 66 friend class RulesRegistryStorageDelegate;
64 67
65 ~Inner(); 68 ~Inner();
66 69
70 // Initialization of the storage delegate if it is used in the context of
71 // an incognito profile.
72 void InitForOTRProfile();
73
67 // NotificationObserver 74 // NotificationObserver
68 virtual void Observe( 75 virtual void Observe(
69 int type, 76 int type,
70 const content::NotificationSource& source, 77 const content::NotificationSource& source,
71 const content::NotificationDetails& details) OVERRIDE; 78 const content::NotificationDetails& details) OVERRIDE;
72 79
73 // Read/write a list of rules serialized to Values. 80 // Read/write a list of rules serialized to Values.
74 void ReadFromStorage(const std::string& extension_id); 81 void ReadFromStorage(const std::string& extension_id);
75 void ReadFromStorageCallback(const std::string& extension_id, 82 void ReadFromStorageCallback(const std::string& extension_id,
76 scoped_ptr<base::Value> value); 83 scoped_ptr<base::Value> value);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 RulesRegistryStorageDelegate::Inner::Inner( 164 RulesRegistryStorageDelegate::Inner::Inner(
158 Profile* profile, 165 Profile* profile,
159 RulesRegistryWithCache* rules_registry, 166 RulesRegistryWithCache* rules_registry,
160 const std::string& storage_key) 167 const std::string& storage_key)
161 : registrar_(new content::NotificationRegistrar()), 168 : registrar_(new content::NotificationRegistrar()),
162 profile_(profile), 169 profile_(profile),
163 storage_key_(storage_key), 170 storage_key_(storage_key),
164 rules_registry_thread_(rules_registry->GetOwnerThread()), 171 rules_registry_thread_(rules_registry->GetOwnerThread()),
165 rules_registry_(rules_registry), 172 rules_registry_(rules_registry),
166 ready_(false) { 173 ready_(false) {
167 registrar_->Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, 174 if (!profile_->IsOffTheRecord()) {
168 content::Source<Profile>(profile)); 175 registrar_->Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
169 registrar_->Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, 176 content::Source<Profile>(profile));
170 content::Source<Profile>(profile)); 177 registrar_->Add(this, chrome::NOTIFICATION_EXTENSIONS_READY,
178 content::Source<Profile>(profile));
179 } else {
180 registrar_->Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
181 content::Source<Profile>(profile->GetOriginalProfile()));
182 InitForOTRProfile();
183 }
171 } 184 }
172 185
173 RulesRegistryStorageDelegate::Inner::~Inner() { 186 RulesRegistryStorageDelegate::Inner::~Inner() {
174 DCHECK(!registrar_.get()); 187 DCHECK(!registrar_.get());
175 } 188 }
176 189
190 void RulesRegistryStorageDelegate::Inner::InitForOTRProfile() {
191 ExtensionService* extension_service =
192 extensions::ExtensionSystem::Get(profile_)->extension_service();
193 const ExtensionSet* extensions = extension_service->extensions();
194 for (ExtensionSet::const_iterator i = extensions->begin();
195 i != extensions->end(); ++i) {
196 if ((*i)->HasAPIPermission(APIPermission::kDeclarativeWebRequest) &&
197 extension_service->IsIncognitoEnabled((*i)->id()))
198 ReadFromStorage((*i)->id());
199 }
200 ready_ = true;
201 }
202
177 void RulesRegistryStorageDelegate::Inner::Observe( 203 void RulesRegistryStorageDelegate::Inner::Observe(
178 int type, 204 int type,
179 const content::NotificationSource& source, 205 const content::NotificationSource& source,
180 const content::NotificationDetails& details) { 206 const content::NotificationDetails& details) {
181 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 207 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
182 if (type == chrome::NOTIFICATION_EXTENSION_LOADED) { 208 if (type == chrome::NOTIFICATION_EXTENSION_LOADED) {
183 const extensions::Extension* extension = 209 const extensions::Extension* extension =
184 content::Details<const extensions::Extension>(details).ptr(); 210 content::Details<const extensions::Extension>(details).ptr();
185 // TODO(mpcomplete): This API check should generalize to any use of 211 // TODO(mpcomplete): This API check should generalize to any use of
186 // declarative rules, not just webRequest. 212 // declarative rules, not just webRequest.
187 if (extension->HasAPIPermission( 213 if (extension->HasAPIPermission(
188 APIPermission::kDeclarativeWebRequest)) { 214 APIPermission::kDeclarativeWebRequest)) {
189 ReadFromStorage(extension->id()); 215 ExtensionInfoMap* extension_info_map =
216 ExtensionSystem::Get(profile_)->info_map();
217 if (profile_->IsOffTheRecord() &&
218 !extension_info_map->IsIncognitoEnabled(extension->id())) {
219 // Ignore this extension.
220 } else {
221 ReadFromStorage(extension->id());
222 }
190 } 223 }
191 } else if (type == chrome::NOTIFICATION_EXTENSIONS_READY) { 224 } else if (type == chrome::NOTIFICATION_EXTENSIONS_READY) {
192 CheckIfReady(); 225 CheckIfReady();
193 } 226 }
194 } 227 }
195 228
196 void RulesRegistryStorageDelegate::Inner::ReadFromStorage( 229 void RulesRegistryStorageDelegate::Inner::ReadFromStorage(
197 const std::string& extension_id) { 230 const std::string& extension_id) {
198 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 231 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
199 extensions::StateStore* store = ExtensionSystem::Get(profile_)->state_store(); 232 extensions::StateStore* store = ExtensionSystem::Get(profile_)->state_store();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 void RulesRegistryStorageDelegate::Inner::NotifyReadyOnRegistryThread() { 279 void RulesRegistryStorageDelegate::Inner::NotifyReadyOnRegistryThread() {
247 DCHECK(content::BrowserThread::CurrentlyOn(rules_registry_thread_)); 280 DCHECK(content::BrowserThread::CurrentlyOn(rules_registry_thread_));
248 if (ready_) 281 if (ready_)
249 return; // we've already notified our readiness 282 return; // we've already notified our readiness
250 283
251 ready_ = true; 284 ready_ = true;
252 rules_registry_->OnReady(); 285 rules_registry_->OnReady();
253 } 286 }
254 287
255 } // namespace extensions 288 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698