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 "extensions/browser/url_request_util.h" | 5 #include "extensions/browser/url_request_util.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "content/public/browser/resource_request_info.h" | 9 #include "content/public/browser/resource_request_info.h" |
| 10 #include "content/public/common/browser_side_navigation_policy.h" | |
| 10 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h" | 11 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h" |
| 11 #include "extensions/browser/info_map.h" | 12 #include "extensions/browser/info_map.h" |
| 12 #include "extensions/common/extension.h" | 13 #include "extensions/common/extension.h" |
| 13 #include "extensions/common/manifest_handlers/icons_handler.h" | 14 #include "extensions/common/manifest_handlers/icons_handler.h" |
| 14 #include "extensions/common/manifest_handlers/web_accessible_resources_info.h" | 15 #include "extensions/common/manifest_handlers/web_accessible_resources_info.h" |
| 15 #include "extensions/common/manifest_handlers/webview_info.h" | 16 #include "extensions/common/manifest_handlers/webview_info.h" |
| 16 #include "net/url_request/url_request.h" | 17 #include "net/url_request/url_request.h" |
| 17 | 18 |
| 18 namespace extensions { | 19 namespace extensions { |
| 19 namespace url_request_util { | 20 namespace url_request_util { |
| 20 | 21 |
| 21 bool AllowCrossRendererResourceLoad(net::URLRequest* request, | 22 bool AllowCrossRendererResourceLoad(net::URLRequest* request, |
| 22 bool is_incognito, | 23 bool is_incognito, |
| 23 const Extension* extension, | 24 const Extension* extension, |
| 24 InfoMap* extension_info_map, | 25 InfoMap* extension_info_map, |
| 25 bool* allowed) { | 26 bool* allowed) { |
| 26 const content::ResourceRequestInfo* info = | 27 const content::ResourceRequestInfo* info = |
| 27 content::ResourceRequestInfo::ForRequest(request); | 28 content::ResourceRequestInfo::ForRequest(request); |
| 28 | |
| 29 // Extensions with webview: allow loading certain resources by guest renderers | |
| 30 // with privileged partition IDs as specified in owner's extension the | |
| 31 // manifest file. | |
| 32 std::string owner_extension_id; | |
| 33 int owner_process_id; | |
| 34 WebViewRendererState::GetInstance()->GetOwnerInfo( | |
| 35 info->GetChildID(), &owner_process_id, &owner_extension_id); | |
| 36 const Extension* owner_extension = | |
| 37 extension_info_map->extensions().GetByID(owner_extension_id); | |
| 38 std::string partition_id; | |
| 39 bool is_guest = WebViewRendererState::GetInstance()->GetPartitionID( | |
| 40 info->GetChildID(), &partition_id); | |
| 41 std::string resource_path = request->url().path(); | 29 std::string resource_path = request->url().path(); |
| 42 | 30 |
| 43 // |owner_extension == extension| needs to be checked because extension | 31 // PlzNavigate: this logic is performed for main frame requests in |
| 44 // resources should only be accessible to WebViews owned by that extension. | 32 // ExtensionNavigationThrottle::WillStartRequest. |
| 45 if (is_guest && owner_extension == extension && | 33 if (info->GetChildID() != -1 || |
| 46 WebviewInfo::IsResourceWebviewAccessible(extension, partition_id, | 34 info->GetResourceType() != content::RESOURCE_TYPE_MAIN_FRAME || |
| 47 resource_path)) { | 35 !content::IsBrowserSideNavigationEnabled()) { |
| 48 *allowed = true; | 36 // Extensions with webview: allow loading certain resources by guest |
| 49 return true; | 37 // renderers with privileged partition IDs as specified in owner's extension |
| 50 } | 38 // the manifest file. |
| 39 std::string owner_extension_id; | |
| 40 int owner_process_id; | |
| 41 WebViewRendererState::GetInstance()->GetOwnerInfo( | |
| 42 info->GetChildID(), &owner_process_id, &owner_extension_id); | |
| 43 const Extension* owner_extension = | |
| 44 extension_info_map->extensions().GetByID(owner_extension_id); | |
| 45 std::string partition_id; | |
| 46 bool is_guest = WebViewRendererState::GetInstance()->GetPartitionID( | |
| 47 info->GetChildID(), &partition_id); | |
| 51 | 48 |
| 52 if (is_guest && | 49 if (AllowCrossRendererResourceLoad(is_guest, extension, owner_extension, |
|
Fady Samuel
2016/10/13 15:33:01
Can we call this something else? It's a bit confus
jam
2016/10/13 16:30:06
Done.
| |
| 53 !ui::PageTransitionIsWebTriggerable(info->GetPageTransition())) { | 50 partition_id, resource_path, |
| 54 *allowed = false; | 51 info->GetPageTransition(), allowed)) { |
| 55 return true; | 52 return true; |
| 53 } | |
| 56 } | 54 } |
| 57 | 55 |
| 58 // The following checks require that we have an actual extension object. If we | 56 // The following checks require that we have an actual extension object. If we |
| 59 // don't have it, allow the request handling to continue with the rest of the | 57 // don't have it, allow the request handling to continue with the rest of the |
| 60 // checks. | 58 // checks. |
| 61 if (!extension) { | 59 if (!extension) { |
| 62 *allowed = true; | 60 *allowed = true; |
| 63 return true; | 61 return true; |
| 64 } | 62 } |
| 65 | 63 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 | 128 |
| 131 bool IsWebViewRequest(const net::URLRequest* request) { | 129 bool IsWebViewRequest(const net::URLRequest* request) { |
| 132 const content::ResourceRequestInfo* info = | 130 const content::ResourceRequestInfo* info = |
| 133 content::ResourceRequestInfo::ForRequest(request); | 131 content::ResourceRequestInfo::ForRequest(request); |
| 134 // |info| can be NULL sometimes: http://crbug.com/370070. | 132 // |info| can be NULL sometimes: http://crbug.com/370070. |
| 135 if (!info) | 133 if (!info) |
| 136 return false; | 134 return false; |
| 137 return WebViewRendererState::GetInstance()->IsGuest(info->GetChildID()); | 135 return WebViewRendererState::GetInstance()->IsGuest(info->GetChildID()); |
| 138 } | 136 } |
| 139 | 137 |
| 138 bool AllowCrossRendererResourceLoad(bool is_guest, | |
| 139 const Extension* extension, | |
| 140 const Extension* owner_extension, | |
| 141 const std::string& partition_id, | |
| 142 const std::string& resource_path, | |
| 143 ui::PageTransition page_transition, | |
| 144 bool* allowed) { | |
| 145 // |owner_extension == extension| needs to be checked because extension | |
| 146 // resources should only be accessible to WebViews owned by that extension. | |
| 147 if (is_guest && owner_extension == extension && | |
| 148 WebviewInfo::IsResourceWebviewAccessible(extension, partition_id, | |
| 149 resource_path)) { | |
| 150 *allowed = true; | |
| 151 return true; | |
| 152 } | |
| 153 | |
| 154 if (is_guest && !ui::PageTransitionIsWebTriggerable(page_transition)) { | |
| 155 *allowed = false; | |
| 156 return true; | |
| 157 } | |
| 158 | |
| 159 return false; | |
| 160 } | |
| 161 | |
| 140 } // namespace url_request_util | 162 } // namespace url_request_util |
| 141 } // namespace extensions | 163 } // namespace extensions |
| OLD | NEW |