| 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 "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 | 58 |
| 59 return false; | 59 return false; |
| 60 } | 60 } |
| 61 | 61 |
| 62 // Checks whether the host |pattern| is allowed for the given |extension|, | 62 // Checks whether the host |pattern| is allowed for the given |extension|, |
| 63 // given API permissions |permissions|. | 63 // given API permissions |permissions|. |
| 64 bool CanSpecifyHostPermission(const Extension* extension, | 64 bool CanSpecifyHostPermission(const Extension* extension, |
| 65 const URLPattern& pattern, | 65 const URLPattern& pattern, |
| 66 const APIPermissionSet& permissions) { | 66 const APIPermissionSet& permissions) { |
| 67 if (!pattern.match_all_urls() && | 67 if (!pattern.match_all_urls() && |
| 68 pattern.MatchesScheme(chrome::kChromeUIScheme)) { | 68 pattern.MatchesScheme(content::kChromeUIScheme)) { |
| 69 URLPatternSet chrome_scheme_hosts = ExtensionsClient::Get()-> | 69 URLPatternSet chrome_scheme_hosts = ExtensionsClient::Get()-> |
| 70 GetPermittedChromeSchemeHosts(extension, permissions); | 70 GetPermittedChromeSchemeHosts(extension, permissions); |
| 71 if (chrome_scheme_hosts.ContainsPattern(pattern)) | 71 if (chrome_scheme_hosts.ContainsPattern(pattern)) |
| 72 return true; | 72 return true; |
| 73 | 73 |
| 74 // Component extensions can have access to all of chrome://*. | 74 // Component extensions can have access to all of chrome://*. |
| 75 if (PermissionsData::CanExecuteScriptEverywhere(extension)) | 75 if (PermissionsData::CanExecuteScriptEverywhere(extension)) |
| 76 return true; | 76 return true; |
| 77 | 77 |
| 78 if (CommandLine::ForCurrentProcess()->HasSwitch( | 78 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 // to match all paths. | 183 // to match all paths. |
| 184 pattern.SetPath("/*"); | 184 pattern.SetPath("/*"); |
| 185 int valid_schemes = pattern.valid_schemes(); | 185 int valid_schemes = pattern.valid_schemes(); |
| 186 if (pattern.MatchesScheme(content::kFileScheme) && | 186 if (pattern.MatchesScheme(content::kFileScheme) && |
| 187 !PermissionsData::CanExecuteScriptEverywhere(extension)) { | 187 !PermissionsData::CanExecuteScriptEverywhere(extension)) { |
| 188 extension->set_wants_file_access(true); | 188 extension->set_wants_file_access(true); |
| 189 if (!(extension->creation_flags() & Extension::ALLOW_FILE_ACCESS)) | 189 if (!(extension->creation_flags() & Extension::ALLOW_FILE_ACCESS)) |
| 190 valid_schemes &= ~URLPattern::SCHEME_FILE; | 190 valid_schemes &= ~URLPattern::SCHEME_FILE; |
| 191 } | 191 } |
| 192 | 192 |
| 193 if (pattern.scheme() != chrome::kChromeUIScheme && | 193 if (pattern.scheme() != content::kChromeUIScheme && |
| 194 !PermissionsData::CanExecuteScriptEverywhere(extension)) { | 194 !PermissionsData::CanExecuteScriptEverywhere(extension)) { |
| 195 // Keep chrome:// in allowed schemes only if it's explicitly requested | 195 // Keep chrome:// in allowed schemes only if it's explicitly requested |
| 196 // or CanExecuteScriptEverywhere is true. If the | 196 // or CanExecuteScriptEverywhere is true. If the |
| 197 // extensions_on_chrome_urls flag is not set, CanSpecifyHostPermission | 197 // extensions_on_chrome_urls flag is not set, CanSpecifyHostPermission |
| 198 // will fail, so don't check the flag here. | 198 // will fail, so don't check the flag here. |
| 199 valid_schemes &= ~URLPattern::SCHEME_CHROMEUI; | 199 valid_schemes &= ~URLPattern::SCHEME_CHROMEUI; |
| 200 } | 200 } |
| 201 pattern.SetValidSchemes(valid_schemes); | 201 pattern.SetValidSchemes(valid_schemes); |
| 202 | 202 |
| 203 if (!CanSpecifyHostPermission(extension, pattern, *api_permissions)) { | 203 if (!CanSpecifyHostPermission(extension, pattern, *api_permissions)) { |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 extension, document_url, top_frame_url, tab_id, | 469 extension, document_url, top_frame_url, tab_id, |
| 470 script, process_id, error)) | 470 script, process_id, error)) |
| 471 return false; | 471 return false; |
| 472 | 472 |
| 473 if (!can_execute_everywhere && | 473 if (!can_execute_everywhere && |
| 474 !ExtensionsClient::Get()->IsScriptableURL(document_url, error)) { | 474 !ExtensionsClient::Get()->IsScriptableURL(document_url, error)) { |
| 475 return false; | 475 return false; |
| 476 } | 476 } |
| 477 | 477 |
| 478 if (!command_line->HasSwitch(switches::kExtensionsOnChromeURLs)) { | 478 if (!command_line->HasSwitch(switches::kExtensionsOnChromeURLs)) { |
| 479 if (document_url.SchemeIs(chrome::kChromeUIScheme) && | 479 if (document_url.SchemeIs(content::kChromeUIScheme) && |
| 480 !can_execute_everywhere) { | 480 !can_execute_everywhere) { |
| 481 if (error) | 481 if (error) |
| 482 *error = errors::kCannotAccessChromeUrl; | 482 *error = errors::kCannotAccessChromeUrl; |
| 483 return false; | 483 return false; |
| 484 } | 484 } |
| 485 } | 485 } |
| 486 | 486 |
| 487 if (top_frame_url.SchemeIs(extensions::kExtensionScheme) && | 487 if (top_frame_url.SchemeIs(extensions::kExtensionScheme) && |
| 488 top_frame_url.GetOrigin() != | 488 top_frame_url.GetOrigin() != |
| 489 Extension::GetBaseURLFromExtensionId(extension->id()).GetOrigin() && | 489 Extension::GetBaseURLFromExtensionId(extension->id()).GetOrigin() && |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 initial_optional_permissions_->api_permissions, | 608 initial_optional_permissions_->api_permissions, |
| 609 initial_optional_permissions_->manifest_permissions, | 609 initial_optional_permissions_->manifest_permissions, |
| 610 initial_optional_permissions_->host_permissions, | 610 initial_optional_permissions_->host_permissions, |
| 611 URLPatternSet()); | 611 URLPatternSet()); |
| 612 | 612 |
| 613 initial_required_permissions_.reset(); | 613 initial_required_permissions_.reset(); |
| 614 initial_optional_permissions_.reset(); | 614 initial_optional_permissions_.reset(); |
| 615 } | 615 } |
| 616 | 616 |
| 617 } // namespace extensions | 617 } // namespace extensions |
| OLD | NEW |