Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Side by Side Diff: extensions/browser/extension_navigation_throttle.cc

Issue 2875493002: Block navigations to hosted apps non-icon resources with PlzNavigate. (Closed)
Patch Set: Rebase on nick@'s recent changes. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/extension_navigation_throttle.h" 5 #include "extensions/browser/extension_navigation_throttle.h"
6 6
7 #include "components/guest_view/browser/guest_view_base.h" 7 #include "components/guest_view/browser/guest_view_base.h"
8 #include "content/public/browser/browser_thread.h" 8 #include "content/public/browser/browser_thread.h"
9 #include "content/public/browser/navigation_handle.h" 9 #include "content/public/browser/navigation_handle.h"
10 #include "content/public/browser/render_frame_host.h" 10 #include "content/public/browser/render_frame_host.h"
11 #include "content/public/browser/web_contents.h" 11 #include "content/public/browser/web_contents.h"
12 #include "content/public/common/browser_side_navigation_policy.h" 12 #include "content/public/common/browser_side_navigation_policy.h"
13 #include "content/public/common/url_constants.h" 13 #include "content/public/common/url_constants.h"
14 #include "extensions/browser/extension_registry.h" 14 #include "extensions/browser/extension_registry.h"
15 #include "extensions/browser/guest_view/web_view/web_view_guest.h" 15 #include "extensions/browser/guest_view/web_view/web_view_guest.h"
16 #include "extensions/browser/url_request_util.h" 16 #include "extensions/browser/url_request_util.h"
17 #include "extensions/common/constants.h" 17 #include "extensions/common/constants.h"
18 #include "extensions/common/extension.h" 18 #include "extensions/common/extension.h"
19 #include "extensions/common/extension_set.h" 19 #include "extensions/common/extension_set.h"
20 #include "extensions/common/manifest_handlers/icons_handler.h"
20 #include "extensions/common/manifest_handlers/web_accessible_resources_info.h" 21 #include "extensions/common/manifest_handlers/web_accessible_resources_info.h"
21 #include "extensions/common/manifest_handlers/webview_info.h" 22 #include "extensions/common/manifest_handlers/webview_info.h"
22 #include "extensions/common/permissions/api_permission.h" 23 #include "extensions/common/permissions/api_permission.h"
23 #include "extensions/common/permissions/permissions_data.h" 24 #include "extensions/common/permissions/permissions_data.h"
24 #include "ui/base/page_transition_types.h" 25 #include "ui/base/page_transition_types.h"
25 26
26 namespace extensions { 27 namespace extensions {
27 28
28 ExtensionNavigationThrottle::ExtensionNavigationThrottle( 29 ExtensionNavigationThrottle::ExtensionNavigationThrottle(
29 content::NavigationHandle* navigation_handle) 30 content::NavigationHandle* navigation_handle)
(...skipping 28 matching lines...) Expand all
58 return content::NavigationThrottle::PROCEED; 59 return content::NavigationThrottle::PROCEED;
59 } 60 }
60 61
61 // If the navigation is to an unknown or disabled extension, block it. 62 // If the navigation is to an unknown or disabled extension, block it.
62 if (!target_extension) { 63 if (!target_extension) {
63 // TODO(nick): This yields an unsatisfying error page; use a different error 64 // TODO(nick): This yields an unsatisfying error page; use a different error
64 // code once that's supported. https://crbug.com/649869 65 // code once that's supported. https://crbug.com/649869
65 return content::NavigationThrottle::BLOCK_REQUEST; 66 return content::NavigationThrottle::BLOCK_REQUEST;
66 } 67 }
67 68
69 // Hosted apps don't have any associated resources outside of icons, so
70 // block any requests to URLs in their extension origin.
71 if (target_extension->is_hosted_app()) {
Devlin 2017/05/24 17:27:19 Will the old check in chrome/renderer/extensions/r
nasko 2017/05/24 17:37:16 Yes, it can be removed, as it will be redundant an
72 base::StringPiece resource_root_relative_path =
73 url.path_piece().empty() ? base::StringPiece()
74 : url.path_piece().substr(1);
75 if (!IconsInfo::GetIcons(target_extension)
76 .ContainsPath(resource_root_relative_path)) {
77 return content::NavigationThrottle::BLOCK_REQUEST;
78 }
79 }
80
68 if (navigation_handle()->IsInMainFrame()) { 81 if (navigation_handle()->IsInMainFrame()) {
69 // Block top-level navigations to blob: or filesystem: URLs with extension 82 // Block top-level navigations to blob: or filesystem: URLs with extension
70 // origin from non-extension processes. See https://crbug.com/645028. 83 // origin from non-extension processes. See https://crbug.com/645028.
71 bool current_frame_is_extension_process = 84 bool current_frame_is_extension_process =
72 !!registry->enabled_extensions().GetExtensionOrAppByURL( 85 !!registry->enabled_extensions().GetExtensionOrAppByURL(
73 navigation_handle()->GetStartingSiteInstance()->GetSiteURL()); 86 navigation_handle()->GetStartingSiteInstance()->GetSiteURL());
74 87
75 if (!url_has_extension_scheme && !current_frame_is_extension_process) { 88 if (!url_has_extension_scheme && !current_frame_is_extension_process) {
76 // Relax this restriction for apps that use <webview>. See 89 // Relax this restriction for apps that use <webview>. See
77 // https://crbug.com/652077. 90 // https://crbug.com/652077.
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 return CANCEL; 180 return CANCEL;
168 } 181 }
169 return result; 182 return result;
170 } 183 }
171 184
172 const char* ExtensionNavigationThrottle::GetNameForLogging() { 185 const char* ExtensionNavigationThrottle::GetNameForLogging() {
173 return "ExtensionNavigationThrottle"; 186 return "ExtensionNavigationThrottle";
174 } 187 }
175 188
176 } // namespace extensions 189 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698