| 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/api/web_request/web_request_permissions.h" | 5 #include "chrome/browser/extensions/api/web_request/web_request_permissions.h" |
| 6 | 6 |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
| 9 #include "chrome/browser/extensions/extension_info_map.h" | 9 #include "chrome/browser/extensions/extension_info_map.h" |
| 10 #include "chrome/common/extensions/extension.h" | 10 #include "chrome/common/extensions/extension.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 const GURL& url = request->url(); | 90 const GURL& url = request->url(); |
| 91 return IsSensitiveURL(url) || !HasWebRequestScheme(url); | 91 return IsSensitiveURL(url) || !HasWebRequestScheme(url); |
| 92 } | 92 } |
| 93 | 93 |
| 94 // static | 94 // static |
| 95 bool WebRequestPermissions::CanExtensionAccessURL( | 95 bool WebRequestPermissions::CanExtensionAccessURL( |
| 96 const ExtensionInfoMap* extension_info_map, | 96 const ExtensionInfoMap* extension_info_map, |
| 97 const std::string& extension_id, | 97 const std::string& extension_id, |
| 98 const GURL& url, | 98 const GURL& url, |
| 99 bool crosses_incognito, | 99 bool crosses_incognito, |
| 100 bool enforce_host_permissions) { | 100 HostPermissionsCheck host_permissions_check) { |
| 101 // extension_info_map can be NULL in testing. | 101 // extension_info_map can be NULL in testing. |
| 102 if (!extension_info_map) | 102 if (!extension_info_map) |
| 103 return true; | 103 return true; |
| 104 | 104 |
| 105 const extensions::Extension* extension = | 105 const extensions::Extension* extension = |
| 106 extension_info_map->extensions().GetByID(extension_id); | 106 extension_info_map->extensions().GetByID(extension_id); |
| 107 if (!extension) | 107 if (!extension) |
| 108 return false; | 108 return false; |
| 109 | 109 |
| 110 // Check if this event crosses incognito boundaries when it shouldn't. | 110 // Check if this event crosses incognito boundaries when it shouldn't. |
| 111 if (crosses_incognito && !extension_info_map->CanCrossIncognito(extension)) | 111 if (crosses_incognito && !extension_info_map->CanCrossIncognito(extension)) |
| 112 return false; | 112 return false; |
| 113 | 113 |
| 114 if (enforce_host_permissions) { | 114 switch (host_permissions_check) { |
| 115 // about: URLs are not covered in host permissions, but are allowed anyway. | 115 case DO_NOT_CHECK_HOST: |
| 116 bool host_permissions_ok = (url.SchemeIs(chrome::kAboutScheme) || | 116 break; |
| 117 extension->HasHostPermission(url) || | 117 case REQUIRE_HOST_PERMISSION: |
| 118 url.GetOrigin() == extension->url()); | 118 // about: URLs are not covered in host permissions, but are allowed |
| 119 if (!host_permissions_ok) | 119 // anyway. |
| 120 return false; | 120 if (!((url.SchemeIs(chrome::kAboutScheme) || |
| 121 extension->HasHostPermission(url) || |
| 122 url.GetOrigin() == extension->url()))) |
| 123 return false; |
| 124 break; |
| 125 case REQUIRE_ALL_URLS: |
| 126 if (!extension->HasEffectiveAccessToAllHosts()) |
| 127 return false; |
| 128 break; |
| 121 } | 129 } |
| 122 | 130 |
| 123 return true; | 131 return true; |
| 124 } | 132 } |
| OLD | NEW |