OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "extensions/browser/info_map.h" | 5 #include "extensions/browser/info_map.h" |
6 | 6 |
7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
8 #include "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
9 #include "extensions/browser/content_verifier.h" | 9 #include "extensions/browser/content_verifier.h" |
10 #include "extensions/common/constants.h" | 10 #include "extensions/common/constants.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 if (!process_map_.Remove(extension_id, process_id, site_instance_id)) { | 122 if (!process_map_.Remove(extension_id, process_id, site_instance_id)) { |
123 NOTREACHED() << "Unknown extension process registration for: " | 123 NOTREACHED() << "Unknown extension process registration for: " |
124 << extension_id << "," << process_id << "."; | 124 << extension_id << "," << process_id << "."; |
125 } | 125 } |
126 } | 126 } |
127 | 127 |
128 void InfoMap::UnregisterAllExtensionsInProcess(int process_id) { | 128 void InfoMap::UnregisterAllExtensionsInProcess(int process_id) { |
129 process_map_.RemoveAllFromProcess(process_id); | 129 process_map_.RemoveAllFromProcess(process_id); |
130 } | 130 } |
131 | 131 |
132 void InfoMap::GetExtensionsWithAPIPermissionForSecurityOrigin( | 132 bool InfoMap::SecurityOriginHasAPIPermission( |
133 const GURL& origin, | 133 const GURL& origin, |
134 int process_id, | 134 int process_id, |
135 APIPermission::ID permission, | 135 APIPermission::ID permission) const { |
136 ExtensionSet* extensions) const { | 136 CheckOnValidThread(); |
137 DCHECK(extensions); | |
138 | |
139 if (origin.SchemeIs(kExtensionScheme)) { | 137 if (origin.SchemeIs(kExtensionScheme)) { |
140 const std::string& id = origin.host(); | 138 const std::string& id = origin.host(); |
141 const Extension* extension = extensions_.GetByID(id); | 139 const Extension* extension = extensions_.GetByID(id); |
142 if (extension && | 140 return extension && |
| 141 extension->permissions_data()->HasAPIPermission(permission) && |
| 142 process_map_.Contains(id, process_id); |
| 143 } |
| 144 for (const auto& extension : extensions_) { |
| 145 if (extension->web_extent().MatchesSecurityOrigin(origin) && |
143 extension->permissions_data()->HasAPIPermission(permission) && | 146 extension->permissions_data()->HasAPIPermission(permission) && |
144 process_map_.Contains(id, process_id)) { | 147 process_map_.Contains(extension->id(), process_id)) { |
145 extensions->Insert(extension); | 148 return true; |
146 } | |
147 return; | |
148 } | |
149 | |
150 ExtensionSet::const_iterator i = extensions_.begin(); | |
151 for (; i != extensions_.end(); ++i) { | |
152 if ((*i)->web_extent().MatchesSecurityOrigin(origin) && | |
153 process_map_.Contains((*i)->id(), process_id) && | |
154 (*i)->permissions_data()->HasAPIPermission(permission)) { | |
155 extensions->Insert(*i); | |
156 } | 149 } |
157 } | 150 } |
158 } | 151 return false; |
159 | |
160 bool InfoMap::SecurityOriginHasAPIPermission(const GURL& origin, | |
161 int process_id, | |
162 APIPermission::ID permission) | |
163 const { | |
164 ExtensionSet extensions; | |
165 GetExtensionsWithAPIPermissionForSecurityOrigin( | |
166 origin, process_id, permission, &extensions); | |
167 return !extensions.is_empty(); | |
168 } | 152 } |
169 | 153 |
170 // This function is security sensitive. Bugs could cause problems that break | 154 // This function is security sensitive. Bugs could cause problems that break |
171 // restrictions on local file access or NaCl's validation caching. If you modify | 155 // restrictions on local file access or NaCl's validation caching. If you modify |
172 // this function, please get a security review from a NaCl person. | 156 // this function, please get a security review from a NaCl person. |
173 bool InfoMap::MapUrlToLocalFilePath(const GURL& file_url, | 157 bool InfoMap::MapUrlToLocalFilePath(const GURL& file_url, |
174 bool use_blocking_api, | 158 bool use_blocking_api, |
175 base::FilePath* file_path) { | 159 base::FilePath* file_path) { |
176 // Check that the URL is recognized by the extension system. | 160 // Check that the URL is recognized by the extension system. |
177 const Extension* extension = extensions_.GetExtensionOrAppByURL(file_url); | 161 const Extension* extension = extensions_.GetExtensionOrAppByURL(file_url); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 } | 237 } |
254 | 238 |
255 InfoMap::~InfoMap() { | 239 InfoMap::~InfoMap() { |
256 if (quota_service_) { | 240 if (quota_service_) { |
257 BrowserThread::DeleteSoon( | 241 BrowserThread::DeleteSoon( |
258 BrowserThread::IO, FROM_HERE, quota_service_.release()); | 242 BrowserThread::IO, FROM_HERE, quota_service_.release()); |
259 } | 243 } |
260 } | 244 } |
261 | 245 |
262 } // namespace extensions | 246 } // namespace extensions |
OLD | NEW |