Commit f0482a55 authored by Sean Topping's avatar Sean Topping Committed by Commit Bot

[Chromecast] Cancel navigations in CastWebViewExtension

Cast extensions and embedded frames should not navigate by default.

Bug: internal b/74124275
Bug: internal b/112805642

Test: Try to navigate extension page, verify the navigation is blocked.
Change-Id: I84174d9ed2d48038edfef0fcb17511694dbdbe3c
Reviewed-on: https://chromium-review.googlesource.com/1212344Reviewed-by: default avatarLuke Halliwell <halliwell@chromium.org>
Commit-Queue: Sean Topping <seantopping@chromium.org>
Cr-Commit-Position: refs/heads/master@{#589591}
parent 5672ffd5
...@@ -57,6 +57,8 @@ cast_source_set("browser") { ...@@ -57,6 +57,8 @@ cast_source_set("browser") {
"cast_web_view_default.h", "cast_web_view_default.h",
"cast_web_view_factory.cc", "cast_web_view_factory.cc",
"cast_web_view_factory.h", "cast_web_view_factory.h",
"default_navigation_throttle.cc",
"default_navigation_throttle.h",
"devtools/cast_devtools_manager_delegate.cc", "devtools/cast_devtools_manager_delegate.cc",
"devtools/cast_devtools_manager_delegate.h", "devtools/cast_devtools_manager_delegate.h",
"devtools/remote_debugging_server.cc", "devtools/remote_debugging_server.cc",
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "chromecast/browser/cast_network_delegate.h" #include "chromecast/browser/cast_network_delegate.h"
#include "chromecast/browser/cast_quota_permission_context.h" #include "chromecast/browser/cast_quota_permission_context.h"
#include "chromecast/browser/cast_resource_dispatcher_host_delegate.h" #include "chromecast/browser/cast_resource_dispatcher_host_delegate.h"
#include "chromecast/browser/default_navigation_throttle.h"
#include "chromecast/browser/devtools/cast_devtools_manager_delegate.h" #include "chromecast/browser/devtools/cast_devtools_manager_delegate.h"
#include "chromecast/browser/grit/cast_browser_resources.h" #include "chromecast/browser/grit/cast_browser_resources.h"
#include "chromecast/browser/media/media_caps_impl.h" #include "chromecast/browser/media/media_caps_impl.h"
...@@ -54,6 +55,7 @@ ...@@ -54,6 +55,7 @@
#include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
#include "content/public/browser/resource_dispatcher_host.h" #include "content/public/browser/resource_dispatcher_host.h"
#include "content/public/browser/site_instance.h"
#include "content/public/browser/storage_partition.h" #include "content/public/browser/storage_partition.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/common/content_descriptors.h" #include "content/public/common/content_descriptors.h"
...@@ -791,5 +793,27 @@ CastContentBrowserClient::CreateCrashHandlerHost( ...@@ -791,5 +793,27 @@ CastContentBrowserClient::CreateCrashHandlerHost(
} }
#endif // !defined(OS_ANDROID) #endif // !defined(OS_ANDROID)
std::vector<std::unique_ptr<content::NavigationThrottle>>
CastContentBrowserClient::CreateThrottlesForNavigation(
content::NavigationHandle* handle) {
std::vector<std::unique_ptr<content::NavigationThrottle>> throttles;
#if BUILDFLAG(ENABLE_CHROMECAST_EXTENSIONS)
// If this isn't an extension renderer there's nothing to do.
content::SiteInstance* site_instance = handle->GetStartingSiteInstance();
if (site_instance) {
extensions::ExtensionRegistry* registry =
extensions::ExtensionRegistry::Get(site_instance->GetBrowserContext());
const extensions::Extension* extension =
registry->enabled_extensions().GetExtensionOrAppByURL(
site_instance->GetSiteURL());
if (extension) {
throttles.push_back(std::make_unique<DefaultNavigationThrottle>(
handle, content::NavigationThrottle::CANCEL_AND_IGNORE));
}
}
#endif
return throttles;
}
} // namespace shell } // namespace shell
} // namespace chromecast } // namespace chromecast
...@@ -192,6 +192,8 @@ class CastContentBrowserClient : public content::ContentBrowserClient { ...@@ -192,6 +192,8 @@ class CastContentBrowserClient : public content::ContentBrowserClient {
std::unique_ptr<content::NavigationUIData> GetNavigationUIData( std::unique_ptr<content::NavigationUIData> GetNavigationUIData(
content::NavigationHandle* navigation_handle) override; content::NavigationHandle* navigation_handle) override;
bool ShouldEnableStrictSiteIsolation() override; bool ShouldEnableStrictSiteIsolation() override;
std::vector<std::unique_ptr<content::NavigationThrottle>>
CreateThrottlesForNavigation(content::NavigationHandle* handle) override;
#if BUILDFLAG(USE_CHROMECAST_CDMS) #if BUILDFLAG(USE_CHROMECAST_CDMS)
virtual std::unique_ptr<::media::CdmFactory> CreateCdmFactory(); virtual std::unique_ptr<::media::CdmFactory> CreateCdmFactory();
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chromecast/browser/default_navigation_throttle.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/site_instance.h"
DefaultNavigationThrottle::DefaultNavigationThrottle(
content::NavigationHandle* navigation_handle,
content::NavigationThrottle::ThrottleAction default_action)
: content::NavigationThrottle(navigation_handle),
default_action_(default_action) {}
DefaultNavigationThrottle::~DefaultNavigationThrottle() {}
const char* DefaultNavigationThrottle::GetNameForLogging() {
return "DefaultNavigationThrottle";
}
content::NavigationThrottle::ThrottleCheckResult
DefaultNavigationThrottle::WillStartRequest() {
// Perform the default action for all requests except the first.
if (navigation_handle()->HasUserGesture() &&
(navigation_handle()->GetStartingSiteInstance()->GetSiteURL() !=
navigation_handle()->GetURL())) {
return default_action_;
}
return content::NavigationThrottle::PROCEED;
}
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROMECAST_BROWSER_DEFAULT_NAVIGATION_THROTTLE_H_
#define CHROMECAST_BROWSER_DEFAULT_NAVIGATION_THROTTLE_H_
#include <memory>
#include "base/macros.h"
#include "content/public/browser/navigation_throttle.h"
namespace content {
class NavigationHandle;
} // namespace content
class DefaultNavigationThrottle : public content::NavigationThrottle {
public:
DefaultNavigationThrottle(content::NavigationHandle* handle,
NavigationThrottle::ThrottleAction default_action);
~DefaultNavigationThrottle() override;
// content::NavigationThrottle implementation:
ThrottleCheckResult WillStartRequest() override;
const char* GetNameForLogging() override;
private:
content::NavigationThrottle::ThrottleAction const default_action_;
};
#endif // CHROMECAST_BROWSER_DEFAULT_NAVIGATION_THROTTLE_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment