Commit 65576448 authored by Carlos IL's avatar Carlos IL Committed by Commit Bot

Implementation of SB committed interstitials for webview

The code in this CL does not include handling user interaction with the
interstitials, so they will be displayed, but will not react to
commands. Bindings for commands will be added in a follow up CL.

Bug: 1016581
Change-Id: I7817205e6f48b0380e8e15a3faa9b8d134028624
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1872945Reviewed-by: default avatarDaniel Rubery <drubery@chromium.org>
Reviewed-by: default avatarChangwan Ryu <changwan@chromium.org>
Reviewed-by: default avatarNate Fischer <ntfschr@chromium.org>
Commit-Queue: Carlos IL <carlosil@chromium.org>
Cr-Commit-Position: refs/heads/master@{#710461}
parent fc636b51
...@@ -163,6 +163,8 @@ source_set("browser") { ...@@ -163,6 +163,8 @@ source_set("browser") {
"renderer_host/aw_render_view_host_ext.h", "renderer_host/aw_render_view_host_ext.h",
"safe_browsing/aw_safe_browsing_blocking_page.cc", "safe_browsing/aw_safe_browsing_blocking_page.cc",
"safe_browsing/aw_safe_browsing_blocking_page.h", "safe_browsing/aw_safe_browsing_blocking_page.h",
"safe_browsing/aw_safe_browsing_navigation_throttle.cc",
"safe_browsing/aw_safe_browsing_navigation_throttle.h",
"safe_browsing/aw_safe_browsing_ui_manager.cc", "safe_browsing/aw_safe_browsing_ui_manager.cc",
"safe_browsing/aw_safe_browsing_ui_manager.h", "safe_browsing/aw_safe_browsing_ui_manager.h",
"safe_browsing/aw_safe_browsing_whitelist_manager.cc", "safe_browsing/aw_safe_browsing_whitelist_manager.cc",
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "android_webview/browser/network_service/aw_proxying_restricted_cookie_manager.h" #include "android_webview/browser/network_service/aw_proxying_restricted_cookie_manager.h"
#include "android_webview/browser/network_service/aw_proxying_url_loader_factory.h" #include "android_webview/browser/network_service/aw_proxying_url_loader_factory.h"
#include "android_webview/browser/network_service/aw_url_loader_throttle.h" #include "android_webview/browser/network_service/aw_url_loader_throttle.h"
#include "android_webview/browser/safe_browsing/aw_safe_browsing_navigation_throttle.h"
#include "android_webview/browser/safe_browsing/aw_url_checker_delegate_impl.h" #include "android_webview/browser/safe_browsing/aw_url_checker_delegate_impl.h"
#include "android_webview/browser/tracing/aw_tracing_delegate.h" #include "android_webview/browser/tracing/aw_tracing_delegate.h"
#include "android_webview/common/aw_content_client.h" #include "android_webview/common/aw_content_client.h"
...@@ -676,6 +677,11 @@ AwContentBrowserClient::CreateThrottlesForNavigation( ...@@ -676,6 +677,11 @@ AwContentBrowserClient::CreateThrottlesForNavigation(
throttles.push_back(std::make_unique<PolicyBlacklistNavigationThrottle>( throttles.push_back(std::make_unique<PolicyBlacklistNavigationThrottle>(
navigation_handle, AwBrowserContext::FromWebContents( navigation_handle, AwBrowserContext::FromWebContents(
navigation_handle->GetWebContents()))); navigation_handle->GetWebContents())));
if (base::FeatureList::IsEnabled(
safe_browsing::kCommittedSBInterstitials)) {
throttles.push_back(std::make_unique<AwSafeBrowsingNavigationThrottle>(
navigation_handle));
}
} }
return throttles; return throttles;
} }
......
...@@ -10,9 +10,11 @@ ...@@ -10,9 +10,11 @@
#include "android_webview/browser/aw_browser_context.h" #include "android_webview/browser/aw_browser_context.h"
#include "android_webview/browser/aw_browser_process.h" #include "android_webview/browser/aw_browser_process.h"
#include "android_webview/browser/safe_browsing/aw_safe_browsing_ui_manager.h" #include "android_webview/browser/safe_browsing/aw_safe_browsing_ui_manager.h"
#include "base/feature_list.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/safe_browsing/browser/threat_details.h" #include "components/safe_browsing/browser/threat_details.h"
#include "components/safe_browsing/features.h"
#include "components/safe_browsing/triggers/trigger_manager.h" #include "components/safe_browsing/triggers/trigger_manager.h"
#include "components/security_interstitials/content/security_interstitial_controller_client.h" #include "components/security_interstitials/content/security_interstitial_controller_client.h"
#include "components/security_interstitials/content/unsafe_resource.h" #include "components/security_interstitials/content/unsafe_resource.h"
...@@ -93,38 +95,52 @@ void AwSafeBrowsingBlockingPage::ShowBlockingPage( ...@@ -93,38 +95,52 @@ void AwSafeBrowsingBlockingPage::ShowBlockingPage(
// There is no interstitial currently showing, or we are about to display a // There is no interstitial currently showing, or we are about to display a
// new one for the main frame. If there is already an interstitial, showing // new one for the main frame. If there is already an interstitial, showing
// the new one will automatically hide the old one. // the new one will automatically hide the old one.
content::NavigationEntry* entry = AwSafeBrowsingBlockingPage* blocking_page = CreateBlockingPage(
unsafe_resource.GetNavigationEntryForResource(); ui_manager, unsafe_resource.web_contents_getter.Run(), GURL(),
const UnsafeResourceList unsafe_resources{unsafe_resource}; unsafe_resource);
AwBrowserContext* browser_context =
AwBrowserContext::FromWebContents(web_contents);
PrefService* pref_service = browser_context->GetPrefService();
BaseSafeBrowsingErrorUI::SBErrorDisplayOptions display_options =
BaseSafeBrowsingErrorUI::SBErrorDisplayOptions(
IsMainPageLoadBlocked(unsafe_resources),
safe_browsing::IsExtendedReportingOptInAllowed(*pref_service),
browser_context->IsOffTheRecord(),
safe_browsing::IsExtendedReportingEnabled(*pref_service),
safe_browsing::IsExtendedReportingPolicyManaged(*pref_service),
pref_service->GetBoolean(
::prefs::kSafeBrowsingProceedAnywayDisabled),
false, // should_open_links_in_new_tab
false, // always_show_back_to_safety
"cpn_safe_browsing_wv"); // help_center_article_link
ErrorUiType errorType =
static_cast<ErrorUiType>(ui_manager->GetErrorUiType(unsafe_resource));
AwSafeBrowsingBlockingPage* blocking_page = new AwSafeBrowsingBlockingPage(
ui_manager, web_contents, entry ? entry->GetURL() : GURL(),
unsafe_resources,
CreateControllerClient(web_contents, unsafe_resources, ui_manager,
pref_service),
display_options, errorType);
blocking_page->Show(); blocking_page->Show();
} }
} }
AwSafeBrowsingBlockingPage* AwSafeBrowsingBlockingPage::CreateBlockingPage(
AwSafeBrowsingUIManager* ui_manager,
content::WebContents* web_contents,
const GURL& main_frame_url,
const UnsafeResource& unsafe_resource) {
const UnsafeResourceList unsafe_resources{unsafe_resource};
AwBrowserContext* browser_context =
AwBrowserContext::FromWebContents(web_contents);
PrefService* pref_service = browser_context->GetPrefService();
BaseSafeBrowsingErrorUI::SBErrorDisplayOptions display_options =
BaseSafeBrowsingErrorUI::SBErrorDisplayOptions(
IsMainPageLoadBlocked(unsafe_resources),
safe_browsing::IsExtendedReportingOptInAllowed(*pref_service),
browser_context->IsOffTheRecord(),
safe_browsing::IsExtendedReportingEnabled(*pref_service),
safe_browsing::IsExtendedReportingPolicyManaged(*pref_service),
pref_service->GetBoolean(::prefs::kSafeBrowsingProceedAnywayDisabled),
false, // should_open_links_in_new_tab
false, // always_show_back_to_safety
"cpn_safe_browsing_wv"); // help_center_article_link
ErrorUiType errorType =
static_cast<ErrorUiType>(ui_manager->GetErrorUiType(web_contents));
// TODO(carlosil): This logic is necessary to support committed and non
// committed interstitials, it can be cleaned up when removing non-committed
// interstitials.
content::NavigationEntry* entry =
unsafe_resource.GetNavigationEntryForResource();
GURL url =
(main_frame_url.is_empty() && entry) ? entry->GetURL() : main_frame_url;
return new AwSafeBrowsingBlockingPage(
ui_manager, web_contents, url, unsafe_resources,
CreateControllerClient(web_contents, unsafe_resources, ui_manager,
pref_service),
display_options, errorType);
}
void AwSafeBrowsingBlockingPage::FinishThreatDetails( void AwSafeBrowsingBlockingPage::FinishThreatDetails(
const base::TimeDelta& delay, const base::TimeDelta& delay,
bool did_proceed, bool did_proceed,
......
...@@ -14,6 +14,10 @@ namespace security_interstitials { ...@@ -14,6 +14,10 @@ namespace security_interstitials {
struct UnsafeResource; struct UnsafeResource;
} // namespace security_interstitials } // namespace security_interstitials
namespace content {
class WebContents;
} // namespace content
namespace android_webview { namespace android_webview {
class AwSafeBrowsingUIManager; class AwSafeBrowsingUIManager;
...@@ -25,6 +29,12 @@ class AwSafeBrowsingBlockingPage : public safe_browsing::BaseBlockingPage { ...@@ -25,6 +29,12 @@ class AwSafeBrowsingBlockingPage : public safe_browsing::BaseBlockingPage {
static void ShowBlockingPage(AwSafeBrowsingUIManager* ui_manager, static void ShowBlockingPage(AwSafeBrowsingUIManager* ui_manager,
const UnsafeResource& unsafe_resource); const UnsafeResource& unsafe_resource);
static AwSafeBrowsingBlockingPage* CreateBlockingPage(
AwSafeBrowsingUIManager* ui_manager,
content::WebContents* web_contents,
const GURL& main_frame_url,
const UnsafeResource& unsafe_resource);
protected: protected:
// Used to specify which BaseSafeBrowsingErrorUI to instantiate, and // Used to specify which BaseSafeBrowsingErrorUI to instantiate, and
// parameters they require. // parameters they require.
......
// Copyright 2019 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 "android_webview/browser/safe_browsing/aw_safe_browsing_navigation_throttle.h"
#include "android_webview/browser/aw_browser_process.h"
#include "android_webview/browser/safe_browsing/aw_safe_browsing_blocking_page.h"
#include "android_webview/browser/safe_browsing/aw_safe_browsing_ui_manager.h"
#include "base/memory/ptr_util.h"
#include "components/security_interstitials/content/security_interstitial_tab_helper.h"
#include "components/security_interstitials/content/unsafe_resource.h"
#include "content/public/browser/navigation_handle.h"
namespace android_webview {
AwSafeBrowsingNavigationThrottle::AwSafeBrowsingNavigationThrottle(
content::NavigationHandle* handle)
: content::NavigationThrottle(handle) {}
const char* AwSafeBrowsingNavigationThrottle::GetNameForLogging() {
return "AwSafeBrowsingNavigationThrottle";
}
content::NavigationThrottle::ThrottleCheckResult
AwSafeBrowsingNavigationThrottle::WillFailRequest() {
AwSafeBrowsingUIManager* manager =
AwBrowserProcess::GetInstance()->GetSafeBrowsingUIManager();
if (manager) {
security_interstitials::UnsafeResource resource;
content::NavigationHandle* handle = navigation_handle();
if (manager->PopUnsafeResourceForURL(handle->GetURL(), &resource)) {
AwSafeBrowsingBlockingPage* blocking_page =
AwSafeBrowsingBlockingPage::CreateBlockingPage(
manager, handle->GetWebContents(), handle->GetURL(), resource);
std::string error_page_content = blocking_page->GetHTMLContents();
security_interstitials::SecurityInterstitialTabHelper::
AssociateBlockingPage(handle->GetWebContents(),
handle->GetNavigationId(),
base::WrapUnique(blocking_page));
return content::NavigationThrottle::ThrottleCheckResult(
CANCEL, net::ERR_BLOCKED_BY_CLIENT, error_page_content);
}
}
return content::NavigationThrottle::PROCEED;
}
} // namespace android_webview
// Copyright 2019 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 ANDROID_WEBVIEW_BROWSER_SAFE_BROWSING_AW_SAFE_BROWSING_NAVIGATION_THROTTLE_H_
#define ANDROID_WEBVIEW_BROWSER_SAFE_BROWSING_AW_SAFE_BROWSING_NAVIGATION_THROTTLE_H_
#include "content/public/browser/navigation_throttle.h"
namespace content {
class NavigationHandle;
} // namespace content
namespace android_webview {
class AwSafeBrowsingNavigationThrottle : public content::NavigationThrottle {
public:
explicit AwSafeBrowsingNavigationThrottle(content::NavigationHandle* handle);
~AwSafeBrowsingNavigationThrottle() override {}
const char* GetNameForLogging() override;
content::NavigationThrottle::ThrottleCheckResult WillFailRequest() override;
};
} // namespace android_webview
#endif // ANDROID_WEBVIEW_BROWSER_SAFE_BROWSING_AW_SAFE_BROWSING_NAVIGATION_THROTTLE_H_
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
#include "components/safe_browsing/ping_manager.h" #include "components/safe_browsing/ping_manager.h"
#include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_entry.h"
#include "services/network/public/mojom/network_service.mojom.h" #include "services/network/public/mojom/network_service.mojom.h"
using content::BrowserThread; using content::BrowserThread;
...@@ -108,8 +110,7 @@ AwSafeBrowsingUIManager::GetURLLoaderFactoryOnIOThread() { ...@@ -108,8 +110,7 @@ AwSafeBrowsingUIManager::GetURLLoaderFactoryOnIOThread() {
} }
int AwSafeBrowsingUIManager::GetErrorUiType( int AwSafeBrowsingUIManager::GetErrorUiType(
const UnsafeResource& resource) const { content::WebContents* web_contents) const {
WebContents* web_contents = resource.web_contents_getter.Run();
UIManagerClient* client = UIManagerClient::FromWebContents(web_contents); UIManagerClient* client = UIManagerClient::FromWebContents(web_contents);
DCHECK(client); DCHECK(client);
return client->GetErrorUiType(); return client->GetErrorUiType();
...@@ -133,6 +134,17 @@ void AwSafeBrowsingUIManager::SendSerializedThreatDetails( ...@@ -133,6 +134,17 @@ void AwSafeBrowsingUIManager::SendSerializedThreatDetails(
} }
} }
safe_browsing::BaseBlockingPage*
AwSafeBrowsingUIManager::CreateBlockingPageForSubresource(
content::WebContents* contents,
const GURL& blocked_url,
const UnsafeResource& unsafe_resource) {
AwSafeBrowsingBlockingPage* blocking_page =
AwSafeBrowsingBlockingPage::CreateBlockingPage(
this, contents, blocked_url, unsafe_resource);
return blocking_page;
}
void AwSafeBrowsingUIManager::CreateURLLoaderFactoryForIO( void AwSafeBrowsingUIManager::CreateURLLoaderFactoryForIO(
mojo::PendingReceiver<network::mojom::URLLoaderFactory> receiver) { mojo::PendingReceiver<network::mojom::URLLoaderFactory> receiver) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <string> #include <string>
#include "components/safe_browsing/base_ui_manager.h" #include "components/safe_browsing/base_ui_manager.h"
#include "components/security_interstitials/content/unsafe_resource.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/remote.h" #include "mojo/public/cpp/bindings/remote.h"
...@@ -19,6 +20,7 @@ class SharedURLLoaderFactory; ...@@ -19,6 +20,7 @@ class SharedURLLoaderFactory;
} }
namespace safe_browsing { namespace safe_browsing {
class BaseBlockingPage;
class PingManager; class PingManager;
class SafeBrowsingNetworkContext; class SafeBrowsingNetworkContext;
} // namespace safe_browsing } // namespace safe_browsing
...@@ -45,7 +47,7 @@ class AwSafeBrowsingUIManager : public safe_browsing::BaseUIManager { ...@@ -45,7 +47,7 @@ class AwSafeBrowsingUIManager : public safe_browsing::BaseUIManager {
AwSafeBrowsingUIManager(); AwSafeBrowsingUIManager();
// Gets the correct ErrorUiType for the web contents // Gets the correct ErrorUiType for the web contents
int GetErrorUiType(const UnsafeResource& resource) const; int GetErrorUiType(content::WebContents* web_contents) const;
// BaseUIManager methods: // BaseUIManager methods:
void DisplayBlockingPage(const UnsafeResource& resource) override; void DisplayBlockingPage(const UnsafeResource& resource) override;
...@@ -65,6 +67,11 @@ class AwSafeBrowsingUIManager : public safe_browsing::BaseUIManager { ...@@ -65,6 +67,11 @@ class AwSafeBrowsingUIManager : public safe_browsing::BaseUIManager {
void ShowBlockingPageForResource(const UnsafeResource& resource) override; void ShowBlockingPageForResource(const UnsafeResource& resource) override;
private: private:
safe_browsing::BaseBlockingPage* CreateBlockingPageForSubresource(
content::WebContents* contents,
const GURL& blocked_url,
const UnsafeResource& unsafe_resource) override;
// Called on the UI thread to create a URLLoaderFactory interface ptr for // Called on the UI thread to create a URLLoaderFactory interface ptr for
// the IO thread. // the IO thread.
void CreateURLLoaderFactoryForIO( void CreateURLLoaderFactoryForIO(
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/feature_list.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/threading/thread.h" #include "base/threading/thread.h"
...@@ -25,7 +24,6 @@ ...@@ -25,7 +24,6 @@
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/safe_browsing/browser/threat_details.h" #include "components/safe_browsing/browser/threat_details.h"
#include "components/safe_browsing/common/safe_browsing_prefs.h" #include "components/safe_browsing/common/safe_browsing_prefs.h"
#include "components/safe_browsing/features.h"
#include "components/safe_browsing/ping_manager.h" #include "components/safe_browsing/ping_manager.h"
#include "components/security_interstitials/content/security_interstitial_tab_helper.h" #include "components/security_interstitials/content/security_interstitial_tab_helper.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
...@@ -108,10 +106,6 @@ void SafeBrowsingUIManager::ShowBlockingPageForResource( ...@@ -108,10 +106,6 @@ void SafeBrowsingUIManager::ShowBlockingPageForResource(
SafeBrowsingBlockingPage::ShowBlockingPage(this, resource); SafeBrowsingBlockingPage::ShowBlockingPage(this, resource);
} }
bool SafeBrowsingUIManager::SafeBrowsingInterstitialsAreCommittedNavigations() {
return base::FeatureList::IsEnabled(kCommittedSBInterstitials);
}
// static // static
bool SafeBrowsingUIManager::ShouldSendHitReport(const HitReport& hit_report, bool SafeBrowsingUIManager::ShouldSendHitReport(const HitReport& hit_report,
WebContents* web_contents) { WebContents* web_contents) {
......
...@@ -107,9 +107,6 @@ class SafeBrowsingUIManager : public BaseUIManager { ...@@ -107,9 +107,6 @@ class SafeBrowsingUIManager : public BaseUIManager {
// Calls SafeBrowsingBlockingPage::ShowBlockingPage(). // Calls SafeBrowsingBlockingPage::ShowBlockingPage().
void ShowBlockingPageForResource(const UnsafeResource& resource) override; void ShowBlockingPageForResource(const UnsafeResource& resource) override;
// Returns true if SB committed interstitials are enabled.
bool SafeBrowsingInterstitialsAreCommittedNavigations() override;
// Helper method to ensure hit reports are only sent when the user has // Helper method to ensure hit reports are only sent when the user has
// opted in to extended reporting and is not currently in incognito mode. // opted in to extended reporting and is not currently in incognito mode.
static bool ShouldSendHitReport(const HitReport& hit_report, static bool ShouldSendHitReport(const HitReport& hit_report,
......
...@@ -8,10 +8,12 @@ ...@@ -8,10 +8,12 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/feature_list.h"
#include "base/i18n/rtl.h" #include "base/i18n/rtl.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/supports_user_data.h" #include "base/supports_user_data.h"
#include "components/safe_browsing/base_blocking_page.h" #include "components/safe_browsing/base_blocking_page.h"
#include "components/safe_browsing/features.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/navigation_entry.h" #include "content/public/browser/navigation_entry.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
...@@ -288,7 +290,7 @@ void BaseUIManager::ShowBlockingPageForResource( ...@@ -288,7 +290,7 @@ void BaseUIManager::ShowBlockingPageForResource(
} }
bool BaseUIManager::SafeBrowsingInterstitialsAreCommittedNavigations() { bool BaseUIManager::SafeBrowsingInterstitialsAreCommittedNavigations() {
return false; return base::FeatureList::IsEnabled(kCommittedSBInterstitials);
} }
BaseBlockingPage* BaseUIManager::CreateBlockingPageForSubresource( BaseBlockingPage* BaseUIManager::CreateBlockingPageForSubresource(
......
...@@ -145,9 +145,8 @@ class BaseUIManager ...@@ -145,9 +145,8 @@ class BaseUIManager
private: private:
// When true, we immediately cancel navigations that have been blocked by Safe // When true, we immediately cancel navigations that have been blocked by Safe
// Browsing, otherwise we call show on the interstitial. Currently this is // Browsing, otherwise we call show on the interstitial.
// only enabled for main frame navigations. bool SafeBrowsingInterstitialsAreCommittedNavigations();
virtual bool SafeBrowsingInterstitialsAreCommittedNavigations();
friend class base::RefCountedThreadSafe<BaseUIManager>; friend class base::RefCountedThreadSafe<BaseUIManager>;
......
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