OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/common/permissions/permissions_data.h" | 5 #include "extensions/common/permissions/permissions_data.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "content/public/common/url_constants.h" | 8 #include "content/public/common/url_constants.h" |
9 #include "extensions/common/constants.h" | 9 #include "extensions/common/constants.h" |
10 #include "extensions/common/error_utils.h" | 10 #include "extensions/common/error_utils.h" |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 } | 154 } |
155 | 155 |
156 std::vector<base::string16> | 156 std::vector<base::string16> |
157 PermissionsData::GetPermissionMessageDetailsStrings() const { | 157 PermissionsData::GetPermissionMessageDetailsStrings() const { |
158 if (ShouldSkipPermissionWarnings(extension_id_)) | 158 if (ShouldSkipPermissionWarnings(extension_id_)) |
159 return std::vector<base::string16>(); | 159 return std::vector<base::string16>(); |
160 return PermissionMessageProvider::Get()->GetWarningMessagesDetails( | 160 return PermissionMessageProvider::Get()->GetWarningMessagesDetails( |
161 active_permissions(), manifest_type_); | 161 active_permissions(), manifest_type_); |
162 } | 162 } |
163 | 163 |
164 bool PermissionsData::CanExecuteScriptOnPage(const Extension* extension, | 164 bool PermissionsData::CanAccessPage(const Extension* extension, |
165 const GURL& document_url, | 165 const GURL& document_url, |
166 const GURL& top_frame_url, | 166 const GURL& top_frame_url, |
167 int tab_id, | 167 int tab_id, |
168 const UserScript* script, | 168 int process_id, |
169 int process_id, | 169 std::string* error) const { |
170 std::string* error) const { | 170 return CanRunOnPage(extension, |
171 if (g_policy_delegate && | 171 document_url, |
172 !g_policy_delegate->CanExecuteScriptOnPage(extension, | 172 top_frame_url, |
173 document_url, | 173 tab_id, |
174 top_frame_url, | 174 process_id, |
175 tab_id, | 175 active_permissions()->explicit_hosts(), |
176 script, | 176 error); |
177 process_id, | 177 } |
178 error)) { | |
179 return false; | |
180 } | |
181 | 178 |
182 bool can_execute_everywhere = CanExecuteScriptEverywhere(extension); | 179 bool PermissionsData::CanRunContentScriptOnPage(const Extension* extension, |
183 if (!can_execute_everywhere && | 180 const GURL& document_url, |
184 !ExtensionsClient::Get()->IsScriptableURL(document_url, error)) { | 181 const GURL& top_frame_url, |
185 return false; | 182 int tab_id, |
186 } | 183 int process_id, |
187 | 184 std::string* error) const { |
188 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 185 return CanRunOnPage(extension, |
189 switches::kExtensionsOnChromeURLs)) { | 186 document_url, |
190 if (document_url.SchemeIs(content::kChromeUIScheme) && | 187 top_frame_url, |
191 !can_execute_everywhere) { | 188 tab_id, |
192 if (error) | 189 process_id, |
193 *error = manifest_errors::kCannotAccessChromeUrl; | 190 active_permissions()->scriptable_hosts(), |
194 return false; | 191 error); |
195 } | |
196 } | |
197 | |
198 if (top_frame_url.SchemeIs(kExtensionScheme) && | |
199 top_frame_url.GetOrigin() != | |
200 Extension::GetBaseURLFromExtensionId(extension->id()).GetOrigin() && | |
201 !can_execute_everywhere) { | |
202 if (error) | |
203 *error = manifest_errors::kCannotAccessExtensionUrl; | |
204 return false; | |
205 } | |
206 | |
207 if (HasTabSpecificPermissionToExecuteScript(tab_id, top_frame_url)) | |
208 return true; | |
209 | |
210 bool can_access = false; | |
211 | |
212 if (script) { | |
213 // If a script is specified, use its matches. | |
214 can_access = script->MatchesURL(document_url); | |
215 } else { | |
216 // Otherwise, see if this extension has permission to execute script | |
217 // programmatically on pages. | |
218 can_access = active_permissions()->HasExplicitAccessToOrigin(document_url); | |
219 } | |
220 | |
221 if (!can_access && error) { | |
222 *error = ErrorUtils::FormatErrorMessage(manifest_errors::kCannotAccessPage, | |
223 document_url.spec()); | |
224 } | |
225 | |
226 return can_access; | |
227 } | 192 } |
228 | 193 |
229 bool PermissionsData::CanCaptureVisiblePage(int tab_id, | 194 bool PermissionsData::CanCaptureVisiblePage(int tab_id, |
230 std::string* error) const { | 195 std::string* error) const { |
231 const URLPattern all_urls(URLPattern::SCHEME_ALL, | 196 const URLPattern all_urls(URLPattern::SCHEME_ALL, |
232 URLPattern::kAllUrlsPattern); | 197 URLPattern::kAllUrlsPattern); |
233 | 198 |
234 if (active_permissions()->explicit_hosts().ContainsPattern(all_urls)) | 199 if (active_permissions()->explicit_hosts().ContainsPattern(all_urls)) |
235 return true; | 200 return true; |
236 | 201 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 scoped_refptr<const PermissionSet> tab_permissions = | 263 scoped_refptr<const PermissionSet> tab_permissions = |
299 GetTabSpecificPermissions(tab_id); | 264 GetTabSpecificPermissions(tab_id); |
300 if (tab_permissions.get() && | 265 if (tab_permissions.get() && |
301 tab_permissions->explicit_hosts().MatchesSecurityOrigin(url)) { | 266 tab_permissions->explicit_hosts().MatchesSecurityOrigin(url)) { |
302 return true; | 267 return true; |
303 } | 268 } |
304 } | 269 } |
305 return false; | 270 return false; |
306 } | 271 } |
307 | 272 |
| 273 bool PermissionsData::CanRunOnPage(const Extension* extension, |
| 274 const GURL& document_url, |
| 275 const GURL& top_frame_url, |
| 276 int tab_id, |
| 277 int process_id, |
| 278 const URLPatternSet& permitted_url_patterns, |
| 279 std::string* error) const { |
| 280 if (g_policy_delegate && |
| 281 !g_policy_delegate->CanExecuteScriptOnPage( |
| 282 extension, document_url, top_frame_url, tab_id, process_id, error)) { |
| 283 return false; |
| 284 } |
| 285 |
| 286 bool can_execute_everywhere = CanExecuteScriptEverywhere(extension); |
| 287 if (!can_execute_everywhere && |
| 288 !ExtensionsClient::Get()->IsScriptableURL(document_url, error)) { |
| 289 return false; |
| 290 } |
| 291 |
| 292 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 293 switches::kExtensionsOnChromeURLs)) { |
| 294 if (document_url.SchemeIs(content::kChromeUIScheme) && |
| 295 !can_execute_everywhere) { |
| 296 if (error) |
| 297 *error = manifest_errors::kCannotAccessChromeUrl; |
| 298 return false; |
| 299 } |
| 300 } |
| 301 |
| 302 if (top_frame_url.SchemeIs(kExtensionScheme) && |
| 303 top_frame_url.GetOrigin() != |
| 304 Extension::GetBaseURLFromExtensionId(extension->id()).GetOrigin() && |
| 305 !can_execute_everywhere) { |
| 306 if (error) |
| 307 *error = manifest_errors::kCannotAccessExtensionUrl; |
| 308 return false; |
| 309 } |
| 310 |
| 311 if (HasTabSpecificPermissionToExecuteScript(tab_id, top_frame_url)) |
| 312 return true; |
| 313 |
| 314 bool can_access = permitted_url_patterns.MatchesURL(document_url); |
| 315 |
| 316 if (!can_access && error) { |
| 317 *error = ErrorUtils::FormatErrorMessage(manifest_errors::kCannotAccessPage, |
| 318 document_url.spec()); |
| 319 } |
| 320 |
| 321 return can_access; |
| 322 } |
| 323 |
308 } // namespace extensions | 324 } // namespace extensions |
OLD | NEW |