 Chromium Code Reviews
 Chromium Code Reviews Issue 352523003:
  Have the Debugger extension api check that it has access to the tab  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 352523003:
  Have the Debugger extension api check that it has access to the tab  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| 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" | 
| 11 #include "extensions/common/extensions_client.h" | 11 #include "extensions/common/extensions_client.h" | 
| 12 #include "extensions/common/manifest.h" | 12 #include "extensions/common/manifest.h" | 
| 13 #include "extensions/common/manifest_constants.h" | 13 #include "extensions/common/manifest_constants.h" | 
| 14 #include "extensions/common/manifest_handlers/permissions_parser.h" | 14 #include "extensions/common/manifest_handlers/permissions_parser.h" | 
| 15 #include "extensions/common/permissions/permission_message_provider.h" | 15 #include "extensions/common/permissions/permission_message_provider.h" | 
| 16 #include "extensions/common/switches.h" | 16 #include "extensions/common/switches.h" | 
| 17 #include "extensions/common/url_pattern_set.h" | 17 #include "extensions/common/url_pattern_set.h" | 
| 18 #include "extensions/common/user_script.h" | 18 #include "extensions/common/user_script.h" | 
| 19 #include "url/gurl.h" | 19 #include "url/gurl.h" | 
| 20 #include "url/url_constants.h" | |
| 20 | 21 | 
| 21 namespace extensions { | 22 namespace extensions { | 
| 22 | 23 | 
| 23 namespace { | 24 namespace { | 
| 24 | 25 | 
| 25 PermissionsData::PolicyDelegate* g_policy_delegate = NULL; | 26 PermissionsData::PolicyDelegate* g_policy_delegate = NULL; | 
| 26 | 27 | 
| 27 // Returns true if this extension id is from a trusted provider. | 28 // Returns true if this extension id is from a trusted provider. | 
| 28 bool ShouldSkipPermissionWarnings(const std::string& extension_id) { | 29 bool ShouldSkipPermissionWarnings(const std::string& extension_id) { | 
| 29 // See http://b/4946060 for more details. | 30 // See http://b/4946060 for more details. | 
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 if (extension->location() == Manifest::COMPONENT) | 64 if (extension->location() == Manifest::COMPONENT) | 
| 64 return true; | 65 return true; | 
| 65 | 66 | 
| 66 const ExtensionsClient::ScriptingWhitelist& whitelist = | 67 const ExtensionsClient::ScriptingWhitelist& whitelist = | 
| 67 ExtensionsClient::Get()->GetScriptingWhitelist(); | 68 ExtensionsClient::Get()->GetScriptingWhitelist(); | 
| 68 | 69 | 
| 69 return std::find(whitelist.begin(), whitelist.end(), extension->id()) != | 70 return std::find(whitelist.begin(), whitelist.end(), extension->id()) != | 
| 70 whitelist.end(); | 71 whitelist.end(); | 
| 71 } | 72 } | 
| 72 | 73 | 
| 74 // static | |
| 75 bool PermissionsData::IsRestrictedUrl(const GURL& document_url, | |
| 76 const GURL& top_frame_url, | |
| 77 const Extension* extension, | |
| 78 std::string* error) { | |
| 79 if (CanExecuteScriptEverywhere(extension)) | |
| 80 return false; | |
| 81 | |
| 82 // Check if the scheme is valid for extensions. If not, return. | |
| 83 // For some reason, about urls are valid but not listed in the valid schemes. | |
| 84 // Hmm.... | |
| 
meacer
2014/06/26 17:32:08
Is this because of the somewhat recent change that
 
Devlin
2014/06/26 17:37:13
Mostly, this is going off the PermissionsData test
 
not at google - send to devlin
2014/06/26 18:11:28
If this is just so that tabCapture can work, can't
 
meacer
2014/06/26 19:24:39
I meant this bug, not specific to tab capture: htt
 | |
| 85 if (!URLPattern::IsValidSchemeForExtensions(document_url.scheme()) && | |
| 86 !document_url.SchemeIs(url::kAboutScheme)) { | |
| 87 if (error) { | |
| 88 *error = ErrorUtils::FormatErrorMessage( | |
| 89 manifest_errors::kCannotAccessPage, | |
| 90 document_url.spec()); | |
| 91 } | |
| 92 return true; | |
| 93 } | |
| 94 | |
| 95 if (!ExtensionsClient::Get()->IsScriptableURL(document_url, error)) | |
| 96 return true; | |
| 97 | |
| 98 bool allow_on_chrome_urls = base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 99 switches::kExtensionsOnChromeURLs); | |
| 100 if (document_url.SchemeIs(content::kChromeUIScheme) && | |
| 101 !allow_on_chrome_urls) { | |
| 102 if (error) | |
| 103 *error = manifest_errors::kCannotAccessChromeUrl; | |
| 104 return true; | |
| 105 } | |
| 106 | |
| 107 if (top_frame_url.SchemeIs(kExtensionScheme) && | |
| 108 top_frame_url.host() != extension->id() && | |
| 109 !allow_on_chrome_urls) { | |
| 110 if (error) | |
| 111 *error = manifest_errors::kCannotAccessExtensionUrl; | |
| 112 return true; | |
| 113 } | |
| 114 | |
| 115 return false; | |
| 116 } | |
| 117 | |
| 73 void PermissionsData::SetActivePermissions( | 118 void PermissionsData::SetActivePermissions( | 
| 74 const PermissionSet* permissions) const { | 119 const PermissionSet* permissions) const { | 
| 75 base::AutoLock auto_lock(runtime_lock_); | 120 base::AutoLock auto_lock(runtime_lock_); | 
| 76 active_permissions_unsafe_ = permissions; | 121 active_permissions_unsafe_ = permissions; | 
| 77 } | 122 } | 
| 78 | 123 | 
| 79 void PermissionsData::UpdateTabSpecificPermissions( | 124 void PermissionsData::UpdateTabSpecificPermissions( | 
| 80 int tab_id, | 125 int tab_id, | 
| 81 scoped_refptr<const PermissionSet> permissions) const { | 126 scoped_refptr<const PermissionSet> permissions) const { | 
| 82 base::AutoLock auto_lock(runtime_lock_); | 127 base::AutoLock auto_lock(runtime_lock_); | 
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 276 int tab_id, | 321 int tab_id, | 
| 277 int process_id, | 322 int process_id, | 
| 278 const URLPatternSet& permitted_url_patterns, | 323 const URLPatternSet& permitted_url_patterns, | 
| 279 std::string* error) const { | 324 std::string* error) const { | 
| 280 if (g_policy_delegate && | 325 if (g_policy_delegate && | 
| 281 !g_policy_delegate->CanExecuteScriptOnPage( | 326 !g_policy_delegate->CanExecuteScriptOnPage( | 
| 282 extension, document_url, top_frame_url, tab_id, process_id, error)) { | 327 extension, document_url, top_frame_url, tab_id, process_id, error)) { | 
| 283 return false; | 328 return false; | 
| 284 } | 329 } | 
| 285 | 330 | 
| 286 bool can_execute_everywhere = CanExecuteScriptEverywhere(extension); | 331 if (IsRestrictedUrl(document_url, top_frame_url, extension, error)) | 
| 287 if (!can_execute_everywhere && | |
| 288 !ExtensionsClient::Get()->IsScriptableURL(document_url, error)) { | |
| 289 return false; | 332 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 | 333 | 
| 311 if (HasTabSpecificPermissionToExecuteScript(tab_id, top_frame_url)) | 334 if (HasTabSpecificPermissionToExecuteScript(tab_id, top_frame_url)) | 
| 312 return true; | 335 return true; | 
| 313 | 336 | 
| 314 bool can_access = permitted_url_patterns.MatchesURL(document_url); | 337 bool can_access = permitted_url_patterns.MatchesURL(document_url); | 
| 315 | 338 | 
| 316 if (!can_access && error) { | 339 if (!can_access && error) { | 
| 317 *error = ErrorUtils::FormatErrorMessage(manifest_errors::kCannotAccessPage, | 340 *error = ErrorUtils::FormatErrorMessage(manifest_errors::kCannotAccessPage, | 
| 318 document_url.spec()); | 341 document_url.spec()); | 
| 319 } | 342 } | 
| 320 | 343 | 
| 321 return can_access; | 344 return can_access; | 
| 322 } | 345 } | 
| 323 | 346 | 
| 324 } // namespace extensions | 347 } // namespace extensions | 
| OLD | NEW |