Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/url_request_util.h" | 5 #include "chrome/browser/extensions/url_request_util.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 15 #include "base/task_runner_util.h" | 15 #include "base/task_runner_util.h" |
| 16 #include "chrome/common/chrome_paths.h" | 16 #include "chrome/common/chrome_paths.h" |
| 17 #include "chrome/common/extensions/manifest_url_handler.h" | 17 #include "chrome/common/extensions/manifest_url_handler.h" |
| 18 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 19 #include "content/public/browser/resource_request_info.h" | 19 #include "content/public/browser/resource_request_info.h" |
| 20 #include "extensions/browser/component_extension_resource_manager.h" | 20 #include "extensions/browser/component_extension_resource_manager.h" |
| 21 #include "extensions/browser/extension_protocols.h" | 21 #include "extensions/browser/extension_protocols.h" |
| 22 #include "extensions/browser/extensions_browser_client.h" | 22 #include "extensions/browser/extensions_browser_client.h" |
| 23 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h" | 23 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h" |
| 24 #include "extensions/browser/info_map.h" | 24 #include "extensions/browser/info_map.h" |
| 25 #include "extensions/browser/url_request_util.h" | |
| 25 #include "extensions/common/file_util.h" | 26 #include "extensions/common/file_util.h" |
| 26 #include "extensions/common/manifest_handlers/icons_handler.h" | 27 #include "extensions/common/manifest_handlers/icons_handler.h" |
| 27 #include "extensions/common/manifest_handlers/web_accessible_resources_info.h" | 28 #include "extensions/common/manifest_handlers/web_accessible_resources_info.h" |
| 28 #include "extensions/common/manifest_handlers/webview_info.h" | 29 #include "extensions/common/manifest_handlers/webview_info.h" |
| 29 #include "net/base/mime_util.h" | 30 #include "net/base/mime_util.h" |
| 30 #include "net/base/net_errors.h" | 31 #include "net/base/net_errors.h" |
| 31 #include "net/http/http_request_headers.h" | 32 #include "net/http/http_request_headers.h" |
| 32 #include "net/http/http_response_headers.h" | 33 #include "net/http/http_response_headers.h" |
| 33 #include "net/http/http_response_info.h" | 34 #include "net/http/http_response_info.h" |
| 34 #include "net/url_request/url_request.h" | 35 #include "net/url_request/url_request.h" |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 net::HttpResponseInfo response_info_; | 127 net::HttpResponseInfo response_info_; |
| 127 | 128 |
| 128 mutable base::WeakPtrFactory<URLRequestResourceBundleJob> weak_factory_; | 129 mutable base::WeakPtrFactory<URLRequestResourceBundleJob> weak_factory_; |
| 129 }; | 130 }; |
| 130 | 131 |
| 131 } // namespace | 132 } // namespace |
| 132 | 133 |
| 133 namespace extensions { | 134 namespace extensions { |
| 134 namespace url_request_util { | 135 namespace url_request_util { |
| 135 | 136 |
| 136 bool AllowCrossRendererResourceLoad(net::URLRequest* request, | 137 bool ChromeAllowCrossRendererResourceLoad(net::URLRequest* request, |
| 137 bool is_incognito, | 138 bool is_incognito, |
| 138 const Extension* extension, | 139 const Extension* extension, |
| 139 InfoMap* extension_info_map) { | 140 InfoMap* extension_info_map) { |
| 140 const content::ResourceRequestInfo* info = | 141 const content::ResourceRequestInfo* info = |
| 141 content::ResourceRequestInfo::ForRequest(request); | 142 content::ResourceRequestInfo::ForRequest(request); |
| 142 | 143 |
| 143 bool is_guest = false; | 144 std::string partition_id; |
| 145 bool is_guest = WebViewRendererState::GetInstance()->GetPartitionID( | |
| 146 info->GetChildID(), &partition_id); | |
| 144 | 147 |
| 145 // Extensions with webview: allow loading certain resources by guest renderers | 148 if (AllowCrossRendererResourceLoad( |
| 146 // with privileged partition IDs as specified in the manifest file. | 149 request, is_incognito, extension, extension_info_map)) { |
| 147 WebViewRendererState* web_view_renderer_state = | |
| 148 WebViewRendererState::GetInstance(); | |
| 149 std::string partition_id; | |
| 150 is_guest = web_view_renderer_state->GetPartitionID(info->GetChildID(), | |
| 151 &partition_id); | |
| 152 std::string resource_path = request->url().path(); | |
| 153 if (is_guest && WebviewInfo::IsResourceWebviewAccessible( | |
| 154 extension, partition_id, resource_path)) { | |
| 155 return true; | 150 return true; |
| 156 } | 151 } |
| 157 | 152 |
| 158 // If the request is for navigations outside of webviews, then it should be | 153 // If the request is for navigations outside of webviews, then it should be |
| 159 // allowed. The navigation logic in CrossSiteResourceHandler will properly | 154 // allowed. The navigation logic in CrossSiteResourceHandler will properly |
| 160 // transfer the navigation to a privileged process before it commits. | 155 // transfer the navigation to a privileged process before it commits. |
| 161 if (content::IsResourceTypeFrame(info->GetResourceType()) && !is_guest) | 156 if (content::IsResourceTypeFrame(info->GetResourceType()) && !is_guest) |
|
Fady Samuel
2014/09/15 19:54:43
It seems to me that if we move this part into Allo
lfg
2014/09/15 20:13:20
Done.
| |
| 162 return true; | 157 return true; |
| 163 | 158 |
| 164 if (!content::PageTransitionIsWebTriggerable(info->GetPageTransition())) | 159 if (!content::PageTransitionIsWebTriggerable(info->GetPageTransition())) |
| 165 return false; | 160 return false; |
| 166 | 161 |
| 167 // The following checks require that we have an actual extension object. If we | 162 // The following checks require that we have an actual extension object. If we |
| 168 // don't have it, allow the request handling to continue with the rest of the | 163 // don't have it, allow the request handling to continue with the rest of the |
| 169 // checks. | 164 // checks. |
| 170 if (!extension) | 165 if (!extension) |
| 171 return true; | 166 return true; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 232 network_delegate, | 227 network_delegate, |
| 233 relative_path, | 228 relative_path, |
| 234 resource_id, | 229 resource_id, |
| 235 content_security_policy, | 230 content_security_policy, |
| 236 send_cors_header); | 231 send_cors_header); |
| 237 } | 232 } |
| 238 } | 233 } |
| 239 return NULL; | 234 return NULL; |
| 240 } | 235 } |
| 241 | 236 |
| 242 bool IsWebViewRequest(net::URLRequest* request) { | |
| 243 const content::ResourceRequestInfo* info = | |
| 244 content::ResourceRequestInfo::ForRequest(request); | |
| 245 // |info| can be NULL sometimes: http://crbug.com/370070. | |
| 246 if (!info) | |
| 247 return false; | |
| 248 return WebViewRendererState::GetInstance()->IsGuest(info->GetChildID()); | |
| 249 } | |
| 250 | |
| 251 } // namespace url_request_util | 237 } // namespace url_request_util |
| 252 } // namespace extensions | 238 } // namespace extensions |
| OLD | NEW |