| OLD | NEW |
| 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_info_map.h" | 5 #include "chrome/browser/extensions/extension_info_map.h" |
| 6 | 6 |
| 7 #include "chrome/common/extensions/extension.h" | 7 #include "chrome/common/extensions/extension.h" |
| 8 #include "chrome/common/extensions/extension_set.h" | 8 #include "chrome/common/extensions/extension_set.h" |
| 9 #include "chrome/common/url_constants.h" | 9 #include "chrome/common/url_constants.h" |
| 10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 | 120 |
| 121 void ExtensionInfoMap::UnregisterAllExtensionsInProcess(int process_id) { | 121 void ExtensionInfoMap::UnregisterAllExtensionsInProcess(int process_id) { |
| 122 process_map_.RemoveAllFromProcess(process_id); | 122 process_map_.RemoveAllFromProcess(process_id); |
| 123 } | 123 } |
| 124 | 124 |
| 125 bool ExtensionInfoMap::SecurityOriginHasAPIPermission( | 125 bool ExtensionInfoMap::SecurityOriginHasAPIPermission( |
| 126 const GURL& origin, int process_id, | 126 const GURL& origin, int process_id, |
| 127 extensions::APIPermission::ID permission) const { | 127 extensions::APIPermission::ID permission) const { |
| 128 if (origin.SchemeIs(chrome::kExtensionScheme)) { | 128 if (origin.SchemeIs(chrome::kExtensionScheme)) { |
| 129 const std::string& id = origin.host(); | 129 const std::string& id = origin.host(); |
| 130 return extensions_.GetByID(id)->HasAPIPermission(permission) && | 130 const Extension* extension = extensions_.GetByID(id); |
| 131 CHECK(extension != NULL); |
| 132 return extension->HasAPIPermission(permission) && |
| 131 process_map_.Contains(id, process_id); | 133 process_map_.Contains(id, process_id); |
| 132 } | 134 } |
| 133 | 135 |
| 134 ExtensionSet::const_iterator i = extensions_.begin(); | 136 ExtensionSet::const_iterator i = extensions_.begin(); |
| 135 for (; i != extensions_.end(); ++i) { | 137 for (; i != extensions_.end(); ++i) { |
| 136 if ((*i)->web_extent().MatchesSecurityOrigin(origin) && | 138 if ((*i)->web_extent().MatchesSecurityOrigin(origin) && |
| 137 process_map_.Contains((*i)->id(), process_id) && | 139 process_map_.Contains((*i)->id(), process_id) && |
| 138 (*i)->HasAPIPermission(permission)) { | 140 (*i)->HasAPIPermission(permission)) { |
| 139 return true; | 141 return true; |
| 140 } | 142 } |
| 141 } | 143 } |
| 142 return false; | 144 return false; |
| 143 } | 145 } |
| 144 | 146 |
| 145 ExtensionsQuotaService* ExtensionInfoMap::GetQuotaService() { | 147 ExtensionsQuotaService* ExtensionInfoMap::GetQuotaService() { |
| 146 CheckOnValidThread(); | 148 CheckOnValidThread(); |
| 147 if (!quota_service_.get()) | 149 if (!quota_service_.get()) |
| 148 quota_service_.reset(new ExtensionsQuotaService()); | 150 quota_service_.reset(new ExtensionsQuotaService()); |
| 149 return quota_service_.get(); | 151 return quota_service_.get(); |
| 150 } | 152 } |
| 151 | 153 |
| 152 ExtensionInfoMap::~ExtensionInfoMap() { | 154 ExtensionInfoMap::~ExtensionInfoMap() { |
| 153 if (quota_service_.get()) { | 155 if (quota_service_.get()) { |
| 154 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, | 156 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, |
| 155 quota_service_.release()); | 157 quota_service_.release()); |
| 156 } | 158 } |
| 157 } | 159 } |
| OLD | NEW |