Commit e005fff9 authored by Matt Menke's avatar Matt Menke Committed by Commit Bot

Disable network diagnostics link in incognito and guest mode on Windows.

The link opens up the system diagnostics tool, if there is one. On
Windows, URLs the diagnostics tool is used on is logged to disk.

Bug: 929141
Change-Id: I4130279eec02e932cf846017bab2e8956d9b79f8
Reviewed-on: https://chromium-review.googlesource.com/c/1456685
Commit-Queue: Matt Menke <mmenke@chromium.org>
Reviewed-by: default avatarEric Roman <eroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#629773}
parent 8ed76970
......@@ -199,6 +199,17 @@ std::string GetShowSavedButtonLabel() {
return l10n_util::GetStringUTF8(IDS_ERRORPAGES_BUTTON_SHOW_SAVED_COPY);
}
// Returns true if the platform has support for a diagnostics tool, and it
// can be launched from |web_contents|.
bool WebContentsCanShowDiagnosticsTool(content::WebContents* web_contents) {
#if defined(OS_CHROMEOS)
// ChromeOS uses an extension instead of a diagnostics dialog.
return true;
#else
return CanShowNetworkDiagnosticsDialog(web_contents);
#endif
}
class ErrorPageTest : public InProcessBrowserTest {
public:
enum HistoryNavigationDirection {
......@@ -1004,6 +1015,34 @@ IN_PROC_BROWSER_TEST_F(DNSErrorPageTest, CheckEasterEggIsNotDisabled) {
EXPECT_EQ(1, result);
}
// Test error page in incognito mode. The two major things are that navigation
// corrections are not fetched (Only one navigation, display local error page),
// and that no network diagnostic link is included, except on ChromeOS.
IN_PROC_BROWSER_TEST_F(DNSErrorPageTest, Incognito) {
Browser* incognito_browser = CreateIncognitoBrowser();
ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
incognito_browser,
URLRequestFailedJob::GetMockHttpUrl(net::ERR_NAME_NOT_RESOLVED), 1);
// Verify that the expected error page is being displayed.
ExpectDisplayingLocalErrorPage(
embedded_test_server()->GetURL("mock.http", "/title2.html").spec(),
incognito_browser, net::ERR_NAME_NOT_RESOLVED);
#if !defined(OS_CHROMEOS)
// Can't currently show the diagnostics in incognito on any platform but
// ChromeOS.
EXPECT_FALSE(WebContentsCanShowDiagnosticsTool(
incognito_browser->tab_strip_model()->GetActiveWebContents()));
#endif
// Diagnostics button should be displayed, if available.
EXPECT_EQ(WebContentsCanShowDiagnosticsTool(
incognito_browser->tab_strip_model()->GetActiveWebContents()),
IsDisplayingDiagnosticsLink(incognito_browser));
}
class ErrorPageAutoReloadTest : public InProcessBrowserTest {
public:
void SetUpCommandLine(base::CommandLine* command_line) override {
......@@ -1168,23 +1207,12 @@ class ErrorPageNavigationCorrectionsFailTest : public ErrorPageTest {
void TearDownOnMainThread() override { url_loader_interceptor_.reset(); }
// Returns true if the platform has support for a diagnostics tool, which
// can be launched from the error page.
bool PlatformSupportsDiagnosticsTool() {
#if defined(OS_CHROMEOS)
// ChromeOS uses an extension instead of a diagnostics dialog.
return true;
#else
return CanShowNetworkDiagnosticsDialog();
#endif
}
private:
std::unique_ptr<content::URLLoaderInterceptor> url_loader_interceptor_;
};
// Make sure that when corrections fail to load, the network error page is
// successfully loaded.
// successfully loaded and shows a link to the diagnostics too, if appropriate.
IN_PROC_BROWSER_TEST_F(ErrorPageNavigationCorrectionsFailTest,
FetchCorrectionsFails) {
ASSERT_TRUE(embedded_test_server()->Start());
......@@ -1198,8 +1226,9 @@ IN_PROC_BROWSER_TEST_F(ErrorPageNavigationCorrectionsFailTest,
embedded_test_server()->GetURL("mock.http", "/title2.html").spec(),
browser(), net::ERR_NAME_NOT_RESOLVED);
// Diagnostics button should be displayed, if available on this platform.
EXPECT_EQ(PlatformSupportsDiagnosticsTool(),
// Diagnostics button should be displayed, if available.
EXPECT_EQ(WebContentsCanShowDiagnosticsTool(
browser()->tab_strip_model()->GetActiveWebContents()),
IsDisplayingDiagnosticsLink(browser()));
}
......
......@@ -11,9 +11,11 @@ namespace content {
class WebContents;
}
// Returns true if the platform has a supported tool for diagnosing network
// errors encountered when requesting URLs.
bool CanShowNetworkDiagnosticsDialog();
// Returns true if a tool for diagnosing network errors encountered when
// requesting URLs can be shown for the provided WebContents. The ability to
// show the diagnostic tool depends on the host platform, and whether the
// WebContents is incognito.
bool CanShowNetworkDiagnosticsDialog(content::WebContents* web_contents);
// Shows a dialog for investigating an error received when requesting
// |failed_url|. May only be called when CanShowNetworkDiagnosticsDialog()
......
......@@ -6,7 +6,7 @@
#include "base/logging.h"
bool CanShowNetworkDiagnosticsDialog() {
bool CanShowNetworkDiagnosticsDialog(content::WebContents* web_contents) {
return false;
}
......
......@@ -24,6 +24,7 @@
#include "base/strings/utf_string_conversions.h"
#include "base/task_runner.h"
#include "base/threading/thread.h"
#include "chrome/browser/profiles/profile.h"
#include "content/public/browser/web_contents.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/shell_dialogs/base_shell_dialog_win.h"
......@@ -82,13 +83,17 @@ class NetErrorDiagnosticsDialog : public ui::BaseShellDialogImpl {
} // namespace
bool CanShowNetworkDiagnosticsDialog() {
return true;
bool CanShowNetworkDiagnosticsDialog(content::WebContents* web_contents) {
Profile* profile =
Profile::FromBrowserContext(web_contents->GetBrowserContext());
// The Windows diagnostic tool logs URLs it's run with, so it shouldn't be
// used with incognito or guest profiles. See https://crbug.com/929141
return !profile->IsOffTheRecord() && !profile->IsGuestSession();
}
void ShowNetworkDiagnosticsDialog(content::WebContents* web_contents,
const std::string& failed_url) {
DCHECK(CanShowNetworkDiagnosticsDialog());
DCHECK(CanShowNetworkDiagnosticsDialog(web_contents));
NetErrorDiagnosticsDialog* dialog = new NetErrorDiagnosticsDialog();
dialog->Show(
......
......@@ -89,7 +89,8 @@ void NetErrorTabHelper::RenderFrameCreated(
chrome::mojom::NetworkDiagnosticsClientAssociatedPtr client;
render_frame_host->GetRemoteAssociatedInterfaces()->GetInterface(&client);
client->SetCanShowNetworkDiagnosticsDialog(CanShowNetworkDiagnosticsDialog());
client->SetCanShowNetworkDiagnosticsDialog(
CanShowNetworkDiagnosticsDialog(web_contents()));
}
void NetErrorTabHelper::DidStartNavigation(
......@@ -293,6 +294,11 @@ void NetErrorTabHelper::RunNetworkDiagnostics(const GURL& url) {
void NetErrorTabHelper::RunNetworkDiagnosticsHelper(
const std::string& sanitized_url) {
// The button shouldn't even be shown in this case, but still best to be safe,
// since the renderer isn't trusted.
if (!CanShowNetworkDiagnosticsDialog(web_contents()))
return;
if (network_diagnostics_bindings_.GetCurrentTargetFrame()
!= web_contents()->GetMainFrame()) {
return;
......
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