Chromium Code Reviews| 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 "extensions/browser/api/web_request/web_request_permissions.h" | 5 #include "extensions/browser/api/web_request/web_request_permissions.h" |
| 6 | 6 |
| 7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "chromeos/login/login_state.h" | |
| 9 #include "content/public/browser/resource_request_info.h" | 10 #include "content/public/browser/resource_request_info.h" |
| 10 #include "extensions/browser/extension_navigation_ui_data.h" | 11 #include "extensions/browser/extension_navigation_ui_data.h" |
| 11 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h" | 12 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h" |
| 12 #include "extensions/browser/info_map.h" | 13 #include "extensions/browser/info_map.h" |
| 13 #include "extensions/common/constants.h" | 14 #include "extensions/common/constants.h" |
| 14 #include "extensions/common/extension.h" | 15 #include "extensions/common/extension.h" |
| 15 #include "extensions/common/extension_urls.h" | 16 #include "extensions/common/extension_urls.h" |
| 16 #include "extensions/common/permissions/permissions_data.h" | 17 #include "extensions/common/permissions/permissions_data.h" |
| 17 #include "net/url_request/url_request.h" | 18 #include "net/url_request/url_request.h" |
| 18 #include "url/gurl.h" | 19 #include "url/gurl.h" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 extension_info_map->process_map().Contains(extensions::kWebStoreAppId, | 102 extension_info_map->process_map().Contains(extensions::kWebStoreAppId, |
| 102 process_id)) { | 103 process_id)) { |
| 103 return true; | 104 return true; |
| 104 } | 105 } |
| 105 } | 106 } |
| 106 | 107 |
| 107 const GURL& url = request->url(); | 108 const GURL& url = request->url(); |
| 108 return IsSensitiveURL(url) || !HasWebRequestScheme(url); | 109 return IsSensitiveURL(url) || !HasWebRequestScheme(url); |
| 109 } | 110 } |
| 110 | 111 |
| 112 namespace { | |
| 113 | |
| 114 bool g_allow_all_extension_locations_in_public_session = false; | |
|
Devlin
2016/11/15 15:12:02
This should go in the existing anonymous namespace
Ivan Šandrk
2016/11/15 16:07:40
Done.
| |
| 115 | |
| 116 } // namespace | |
| 117 | |
| 118 // static | |
| 119 void WebRequestPermissions:: | |
| 120 AllowAllExtensionLocationsInPublicSessionForTesting(bool value) { | |
| 121 g_allow_all_extension_locations_in_public_session = value; | |
| 122 } | |
| 123 | |
| 111 // static | 124 // static |
| 112 PermissionsData::AccessType WebRequestPermissions::CanExtensionAccessURL( | 125 PermissionsData::AccessType WebRequestPermissions::CanExtensionAccessURL( |
| 113 const extensions::InfoMap* extension_info_map, | 126 const extensions::InfoMap* extension_info_map, |
| 114 const std::string& extension_id, | 127 const std::string& extension_id, |
| 115 const GURL& url, | 128 const GURL& url, |
| 116 int tab_id, | 129 int tab_id, |
| 117 bool crosses_incognito, | 130 bool crosses_incognito, |
| 118 HostPermissionsCheck host_permissions_check) { | 131 HostPermissionsCheck host_permissions_check) { |
| 119 // extension_info_map can be NULL in testing. | 132 // extension_info_map can be NULL in testing. |
| 120 if (!extension_info_map) | 133 if (!extension_info_map) |
| 121 return PermissionsData::ACCESS_ALLOWED; | 134 return PermissionsData::ACCESS_ALLOWED; |
| 122 | 135 |
| 123 const extensions::Extension* extension = | 136 const extensions::Extension* extension = |
| 124 extension_info_map->extensions().GetByID(extension_id); | 137 extension_info_map->extensions().GetByID(extension_id); |
| 125 if (!extension) | 138 if (!extension) |
| 126 return PermissionsData::ACCESS_DENIED; | 139 return PermissionsData::ACCESS_DENIED; |
| 127 | 140 |
| 141 // When we are in a Public Session, allow all URLs for webRequests initiated | |
| 142 // by a regular extension. | |
| 143 #if defined(OS_CHROMEOS) | |
| 144 if (chromeos::LoginState::IsInitialized() && | |
| 145 chromeos::LoginState::Get()->IsPublicSessionUser() && | |
| 146 extension->is_extension()) { | |
| 147 // Make sure that the extension is truly installed by policy (the assumption | |
| 148 // in Public Session is that all extensions are installed by policy). | |
| 149 CHECK(g_allow_all_extension_locations_in_public_session || | |
| 150 extensions::Manifest::IsPolicyLocation(extension->location())); | |
| 151 return PermissionsData::ACCESS_ALLOWED; | |
| 152 } | |
| 153 #endif | |
| 154 | |
| 128 // Check if this event crosses incognito boundaries when it shouldn't. | 155 // Check if this event crosses incognito boundaries when it shouldn't. |
| 129 if (crosses_incognito && !extension_info_map->CanCrossIncognito(extension)) | 156 if (crosses_incognito && !extension_info_map->CanCrossIncognito(extension)) |
| 130 return PermissionsData::ACCESS_DENIED; | 157 return PermissionsData::ACCESS_DENIED; |
| 131 | 158 |
| 132 PermissionsData::AccessType access = PermissionsData::ACCESS_DENIED; | 159 PermissionsData::AccessType access = PermissionsData::ACCESS_DENIED; |
| 133 switch (host_permissions_check) { | 160 switch (host_permissions_check) { |
| 134 case DO_NOT_CHECK_HOST: | 161 case DO_NOT_CHECK_HOST: |
| 135 access = PermissionsData::ACCESS_ALLOWED; | 162 access = PermissionsData::ACCESS_ALLOWED; |
| 136 break; | 163 break; |
| 137 case REQUIRE_HOST_PERMISSION: | 164 case REQUIRE_HOST_PERMISSION: |
| 138 // about: URLs are not covered in host permissions, but are allowed | 165 // about: URLs are not covered in host permissions, but are allowed |
| 139 // anyway. | 166 // anyway. |
| 140 if (url.SchemeIs(url::kAboutScheme) || | 167 if (url.SchemeIs(url::kAboutScheme) || |
| 141 url::IsSameOriginWith(url, extension->url())) { | 168 url::IsSameOriginWith(url, extension->url())) { |
| 142 access = PermissionsData::ACCESS_ALLOWED; | 169 access = PermissionsData::ACCESS_ALLOWED; |
| 143 break; | 170 break; |
| 144 } | 171 } |
| 145 access = extension->permissions_data()->GetPageAccess(extension, url, | 172 access = extension->permissions_data()->GetPageAccess(extension, url, |
| 146 tab_id, nullptr); | 173 tab_id, nullptr); |
| 147 break; | 174 break; |
| 148 case REQUIRE_ALL_URLS: | 175 case REQUIRE_ALL_URLS: |
| 149 if (extension->permissions_data()->HasEffectiveAccessToAllHosts()) | 176 if (extension->permissions_data()->HasEffectiveAccessToAllHosts()) |
| 150 access = PermissionsData::ACCESS_ALLOWED; | 177 access = PermissionsData::ACCESS_ALLOWED; |
| 151 // else ACCESS_DENIED | 178 // else ACCESS_DENIED |
| 152 break; | 179 break; |
| 153 } | 180 } |
| 154 | 181 |
| 155 return access; | 182 return access; |
| 156 } | 183 } |
| OLD | NEW |