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

Unified Diff: chrome/browser/extensions/api/api_resource_manager.h

Issue 10919201: Make sure that a given app/extension requests only its own resources. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Improve tests; fix merge conflicts. Created 8 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/api_resource_manager.h
diff --git a/chrome/browser/extensions/api/api_resource_manager.h b/chrome/browser/extensions/api/api_resource_manager.h
index ded4dd50d10ac2d8bb6721464fe6b5466f90d34f..212d1e923dbfd2c095cc126becd2a97661ecc2b5 100644
--- a/chrome/browser/extensions/api/api_resource_manager.h
+++ b/chrome/browser/extensions/api/api_resource_manager.h
@@ -51,24 +51,32 @@ class ApiResourceManager : public ProfileKeyedService,
return 0;
}
- void Remove(int api_resource_id) {
+ void Remove(const std::string& extension_id, int api_resource_id) {
DCHECK(BrowserThread::CurrentlyOn(thread_id_));
- api_resource_map_->erase(api_resource_id);
+ if (GetOwnedResource(extension_id, api_resource_id) != NULL) {
+ api_resource_map_->erase(api_resource_id);
+ }
}
- T* Get(int api_resource_id) {
+ T* Get(const std::string& extension_id, int api_resource_id) {
DCHECK(BrowserThread::CurrentlyOn(thread_id_));
- linked_ptr<T> ptr = (*api_resource_map_)[api_resource_id];
- return ptr.get();
+ return GetOwnedResource(extension_id, api_resource_id);
}
private:
- // TODO(miket): consider partitioning the ID space by extension ID to make it
- // harder for extensions to peek into each others' resources.
int GenerateId() {
return next_id_++;
}
+ T* GetOwnedResource(const std::string& extension_id,
+ int api_resource_id) {
+ linked_ptr<T> ptr = (*api_resource_map_)[api_resource_id];
+ T* resource = ptr.get();
+ if (resource && extension_id == resource->owner_extension_id())
+ return resource;
+ return NULL;
+ }
+
int next_id_;
BrowserThread::ID thread_id_;

Powered by Google App Engine
This is Rietveld 408576698