| 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 HostPermissionsCheck host_permissions_check) { | 119 HostPermissionsCheck host_permissions_check) { |
| 119 // extension_info_map can be NULL in testing. | 120 // extension_info_map can be NULL in testing. |
| 120 if (!extension_info_map) | 121 if (!extension_info_map) |
| 121 return PermissionsData::ACCESS_ALLOWED; | 122 return PermissionsData::ACCESS_ALLOWED; |
| 122 | 123 |
| 123 const extensions::Extension* extension = | 124 const extensions::Extension* extension = |
| 124 extension_info_map->extensions().GetByID(extension_id); | 125 extension_info_map->extensions().GetByID(extension_id); |
| 125 if (!extension) | 126 if (!extension) |
| 126 return PermissionsData::ACCESS_DENIED; | 127 return PermissionsData::ACCESS_DENIED; |
| 127 | 128 |
| 129 // When we are in a Public Session, allow all URL's for webRequests initiated |
| 130 // by a regular extension. |
| 131 #if defined(OS_CHROMEOS) |
| 132 if (chromeos::LoginState::IsInitialized() && |
| 133 chromeos::LoginState::Get()->IsPublicSessionUser() && |
| 134 extension->is_extension()) { |
| 135 // Make sure that the extension is truly installed by policy (the assumption |
| 136 // in Public Session is that all extensions are installed by policy). |
| 137 // CHECK(extensions::Manifest::IsPolicyLocation(extension->location())); |
| 138 return PermissionsData::ACCESS_ALLOWED; |
| 139 } |
| 140 #endif |
| 141 |
| 128 // Check if this event crosses incognito boundaries when it shouldn't. | 142 // Check if this event crosses incognito boundaries when it shouldn't. |
| 129 if (crosses_incognito && !extension_info_map->CanCrossIncognito(extension)) | 143 if (crosses_incognito && !extension_info_map->CanCrossIncognito(extension)) |
| 130 return PermissionsData::ACCESS_DENIED; | 144 return PermissionsData::ACCESS_DENIED; |
| 131 | 145 |
| 132 PermissionsData::AccessType access = PermissionsData::ACCESS_DENIED; | 146 PermissionsData::AccessType access = PermissionsData::ACCESS_DENIED; |
| 133 switch (host_permissions_check) { | 147 switch (host_permissions_check) { |
| 134 case DO_NOT_CHECK_HOST: | 148 case DO_NOT_CHECK_HOST: |
| 135 access = PermissionsData::ACCESS_ALLOWED; | 149 access = PermissionsData::ACCESS_ALLOWED; |
| 136 break; | 150 break; |
| 137 case REQUIRE_HOST_PERMISSION: | 151 case REQUIRE_HOST_PERMISSION: |
| 138 // about: URLs are not covered in host permissions, but are allowed | 152 // about: URLs are not covered in host permissions, but are allowed |
| 139 // anyway. | 153 // anyway. |
| 140 if (url.SchemeIs(url::kAboutScheme) || | 154 if (url.SchemeIs(url::kAboutScheme) || |
| 141 url::IsSameOriginWith(url, extension->url())) { | 155 url::IsSameOriginWith(url, extension->url())) { |
| 142 access = PermissionsData::ACCESS_ALLOWED; | 156 access = PermissionsData::ACCESS_ALLOWED; |
| 143 break; | 157 break; |
| 144 } | 158 } |
| 145 access = extension->permissions_data()->GetPageAccess(extension, url, | 159 access = extension->permissions_data()->GetPageAccess(extension, url, |
| 146 tab_id, nullptr); | 160 tab_id, nullptr); |
| 147 break; | 161 break; |
| 148 case REQUIRE_ALL_URLS: | 162 case REQUIRE_ALL_URLS: |
| 149 if (extension->permissions_data()->HasEffectiveAccessToAllHosts()) | 163 if (extension->permissions_data()->HasEffectiveAccessToAllHosts()) |
| 150 access = PermissionsData::ACCESS_ALLOWED; | 164 access = PermissionsData::ACCESS_ALLOWED; |
| 151 // else ACCESS_DENIED | 165 // else ACCESS_DENIED |
| 152 break; | 166 break; |
| 153 } | 167 } |
| 154 | 168 |
| 155 return access; | 169 return access; |
| 156 } | 170 } |
| OLD | NEW |