Commit ac9be857 authored by Mustafa Emre Acer's avatar Mustafa Emre Acer Committed by Commit Bot

[SB Delayed Warnings] Add a console message when a download is blocked

SafeBrowsing Delayed Warnings experiment can block a download if the
current page has a delayed warning. In that case, this CL prints a
message to the console.

Bug: 1081317
Change-Id: Ib11dd687ef66eba1dc42e02f1929067f714bb4cc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2215450Reviewed-by: default avatarDaniel Rubery <drubery@chromium.org>
Commit-Queue: Mustafa Emre Acer <meacer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#772499}
parent ecbc9039
......@@ -10,6 +10,12 @@
#include "components/safe_browsing/core/features.h"
#include "content/public/browser/navigation_handle.h"
namespace {
const char kConsoleMessage[] =
"A SafeBrowsing warning is pending on this page, so an attempted download "
"was cancelled. See https://crbug.com/1081317 for details.";
}
namespace safe_browsing {
DelayedWarningNavigationThrottle::DelayedWarningNavigationThrottle(
......@@ -44,6 +50,8 @@ DelayedWarningNavigationThrottle::WillProcessResponse() {
if (navigation_handle()->IsDownload() && observer) {
// If the SafeBrowsing interstitial is delayed on the page, ignore
// downloads. The observer will record the histogram entry for this.
navigation_handle()->GetWebContents()->GetMainFrame()->AddMessageToConsole(
blink::mojom::ConsoleMessageLevel::kWarning, kConsoleMessage);
return content::NavigationThrottle::CANCEL_AND_IGNORE;
}
return content::NavigationThrottle::PROCEED;
......
......@@ -1904,9 +1904,16 @@ class SafeBrowsingBlockingPageDelayedWarningBrowserTest
content::WebContents* contents =
browser->tab_strip_model()->GetActiveWebContents();
content::TestNavigationObserver observer(contents);
content::WebContentsConsoleObserver console_observer(contents);
console_observer.SetPattern(
"A SafeBrowsing warning is pending on this page*");
ui_test_utils::NavigateToURL(
browser, GURL("data:application/octet-stream;base64,SGVsbG8="));
observer.WaitForNavigationFinished();
console_observer.Wait();
ASSERT_EQ(1u, console_observer.messages().size());
}
void NavigateAndAssertNoInterstitial() {
......
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