Index: extensions/browser/extension_navigation_throttle.cc |
diff --git a/extensions/browser/extension_navigation_throttle.cc b/extensions/browser/extension_navigation_throttle.cc |
index 4e511a5f7272b64f1ce7a86c1f999599afa51f9c..68c0a92e340da9750e1fcff31bd267476f9f0e00 100644 |
--- a/extensions/browser/extension_navigation_throttle.cc |
+++ b/extensions/browser/extension_navigation_throttle.cc |
@@ -4,18 +4,24 @@ |
#include "extensions/browser/extension_navigation_throttle.h" |
+#include "components/guest_view/browser/guest_view_base.h" |
#include "content/public/browser/browser_thread.h" |
#include "content/public/browser/navigation_handle.h" |
#include "content/public/browser/render_frame_host.h" |
#include "content/public/browser/web_contents.h" |
+#include "content/public/common/browser_side_navigation_policy.h" |
#include "content/public/common/url_constants.h" |
#include "extensions/browser/extension_registry.h" |
+#include "extensions/browser/guest_view/web_view/web_view_guest.h" |
+#include "extensions/browser/url_request_util.h" |
#include "extensions/common/constants.h" |
#include "extensions/common/extension.h" |
#include "extensions/common/extension_set.h" |
#include "extensions/common/manifest_handlers/web_accessible_resources_info.h" |
+#include "extensions/common/manifest_handlers/webview_info.h" |
#include "extensions/common/permissions/api_permission.h" |
#include "extensions/common/permissions/permissions_data.h" |
+#include "ui/base/page_transition_types.h" |
namespace extensions { |
@@ -29,8 +35,9 @@ content::NavigationThrottle::ThrottleCheckResult |
ExtensionNavigationThrottle::WillStartRequest() { |
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
GURL url(navigation_handle()->GetURL()); |
- ExtensionRegistry* registry = ExtensionRegistry::Get( |
- navigation_handle()->GetWebContents()->GetBrowserContext()); |
+ content::WebContents* web_contents = navigation_handle()->GetWebContents(); |
+ ExtensionRegistry* registry = |
+ ExtensionRegistry::Get(web_contents->GetBrowserContext()); |
if (navigation_handle()->IsInMainFrame()) { |
// Block top-level navigations to blob: or filesystem: URLs with extension |
@@ -57,6 +64,36 @@ ExtensionNavigationThrottle::WillStartRequest() { |
return content::NavigationThrottle::CANCEL; |
} |
+ if (content::IsBrowserSideNavigationEnabled() && |
+ url.scheme() == extensions::kExtensionScheme) { |
+ // This logic is performed for PlzNavigate sub-resources and for |
+ // non-PlzNavigate in |
+ // extensions::url_request_util::AllowCrossRendererResourceLoad. |
+ const Extension* extension = |
+ registry->enabled_extensions().GetExtensionOrAppByURL(url); |
+ guest_view::GuestViewBase* guest = |
+ guest_view::GuestViewBase::FromWebContents(web_contents); |
+ if (guest) { |
+ std::string owner_extension_id = guest->owner_host(); |
+ const Extension* owner_extension = |
+ registry->enabled_extensions().GetByID(owner_extension_id); |
+ |
+ std::string partition_domain, partition_id; |
+ bool in_memory; |
+ std::string resource_path = url.path(); |
+ bool is_guest = WebViewGuest::GetGuestPartitionConfigForSite( |
+ navigation_handle()->GetStartingSiteInstance()->GetSiteURL(), |
+ &partition_domain, &partition_id, &in_memory); |
+ |
+ bool allowed = true; |
+ url_request_util::AllowCrossRendererResourceLoadHelper( |
+ is_guest, extension, owner_extension, partition_id, resource_path, |
+ navigation_handle()->GetPageTransition(), &allowed); |
+ if (!allowed) |
+ return content::NavigationThrottle::CANCEL; |
+ } |
+ } |
+ |
return content::NavigationThrottle::PROCEED; |
} |
@@ -76,7 +113,7 @@ ExtensionNavigationThrottle::WillStartRequest() { |
// the ancestor chain, so find the current RenderFrameHost and use it to |
// traverse up to the main frame. |
content::RenderFrameHost* navigating_frame = nullptr; |
- for (auto* frame : navigation_handle()->GetWebContents()->GetAllFrames()) { |
+ for (auto* frame : web_contents->GetAllFrames()) { |
if (frame->GetFrameTreeNodeId() == |
navigation_handle()->GetFrameTreeNodeId()) { |
navigating_frame = frame; |