Skip to content

Commit

Permalink
Generate patches from Chrome fix for crbug929141, minus browsertest
Browse files Browse the repository at this point in the history
Cherry-pick of
https://chromium.googlesource.com/chromium/src.git/+/e005fff9c838a13ff1402b01617adca691187a6b.
Needed for brave/brave-browser#3249.

deleted the browsertest part of this patch as requested by brianj

Please revert this commit when Brave's chromium src is rebased to
include e005fff9c838a13ff1402b01617adca691187a6b. (Expected to be in C74)
  • Loading branch information
diracdeltas committed Feb 14, 2019
1 parent f5d5c95 commit a774c56
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 0 deletions.
19 changes: 19 additions & 0 deletions patches/chrome-browser-net-net_error_diagnostics_dialog.h.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
diff --git a/chrome/browser/net/net_error_diagnostics_dialog.h b/chrome/browser/net/net_error_diagnostics_dialog.h
index 2d3089a5cef0b9bc89bdc64f3068b324197cfb38..6b2f88cba88b26f9f960812763012f1933c5260d 100644
--- a/chrome/browser/net/net_error_diagnostics_dialog.h
+++ b/chrome/browser/net/net_error_diagnostics_dialog.h
@@ -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()
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/chrome/browser/net/net_error_diagnostics_dialog_posix.cc b/chrome/browser/net/net_error_diagnostics_dialog_posix.cc
index e2866f851389a1e645b133419834bab26c5f68dc..2c21794a89878b5921c8fe8cf0bc32620946aabe 100644
--- a/chrome/browser/net/net_error_diagnostics_dialog_posix.cc
+++ b/chrome/browser/net/net_error_diagnostics_dialog_posix.cc
@@ -6,7 +6,7 @@

#include "base/logging.h"

-bool CanShowNetworkDiagnosticsDialog() {
+bool CanShowNetworkDiagnosticsDialog(content::WebContents* web_contents) {
return false;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
diff --git a/chrome/browser/net/net_error_diagnostics_dialog_win.cc b/chrome/browser/net/net_error_diagnostics_dialog_win.cc
index 4a3768f6b14d1f66482999366f85772073302e65..ea046e11d3aff8690f294831c98829de9b35b183 100644
--- a/chrome/browser/net/net_error_diagnostics_dialog_win.cc
+++ b/chrome/browser/net/net_error_diagnostics_dialog_win.cc
@@ -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(
26 changes: 26 additions & 0 deletions patches/chrome-browser-net-net_error_tab_helper.cc.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
diff --git a/chrome/browser/net/net_error_tab_helper.cc b/chrome/browser/net/net_error_tab_helper.cc
index 0d094df161accd5740306543fc938ab6e58da296..91daf4ecf22ab5c1dbee3e6c2aa857d986e62dea 100644
--- a/chrome/browser/net/net_error_tab_helper.cc
+++ b/chrome/browser/net/net_error_tab_helper.cc
@@ -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;

0 comments on commit a774c56

Please sign in to comment.