[go: up one dir, main page]

[DevTools] Use OriginalProfile for DevTools window if possible

Because of the temporary nature of non-primary OTR profiles, DevTools
windows should not use them, but instead use the original profile the
OTR profile is based on.

This does not apply to primary OTR profiles (incognito and guest mode),
for which this could cause privacy issues. But because primary OTR
profiles are not temporary, they can be used by the DevTools window
directly instead.

(cherry picked from commit 591ad549a72dffe416b4d85f450875c6910b0dba)

Bug: 1175058, 1120880
Change-Id: I516c4c4ad78a93f2e40316f7c715fd6f643b63af
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2772983
Reviewed-by: Andrey Kosyakov <caseq@chromium.org>
Reviewed-by: Ramin Halavati <rhalavati@chromium.org>
Reviewed-by: Mihai Sardarescu <msarda@chromium.org>
Commit-Queue: Wolfgang Beyer <wolfi@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#870876}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2820932
Reviewed-by: Sigurd Schneider <sigurds@chromium.org>
Cr-Commit-Position: refs/branch-heads/4430@{#1308}
Cr-Branched-From: e5ce7dc4f7518237b3d9bb93cccca35d25216cbe-refs/heads/master@{#857950}
diff --git a/chrome/browser/devtools/devtools_window.cc b/chrome/browser/devtools/devtools_window.cc
index 78f6754..eb0d4c5 100644
--- a/chrome/browser/devtools/devtools_window.cc
+++ b/chrome/browser/devtools/devtools_window.cc
@@ -401,8 +401,7 @@
       : keep_alive_(KeepAliveOrigin::DEVTOOLS_WINDOW,
                     KeepAliveRestartOption::DISABLED),
         web_contents_(std::move(web_contents)) {
-    Profile* profile =
-        Profile::FromBrowserContext(web_contents_->GetBrowserContext());
+    Profile* profile = GetProfileForDevToolsWindow(web_contents_.get());
     DCHECK(profile);
     if (!profile->IsOffTheRecord()) {
       // ScopedProfileKeepAlive does not support OTR profiles.
@@ -715,6 +714,17 @@
 }
 
 // static
+Profile* DevToolsWindow::GetProfileForDevToolsWindow(
+    content::WebContents* web_contents) {
+  Profile* profile =
+      Profile::FromBrowserContext(web_contents->GetBrowserContext());
+  if (profile->IsPrimaryOTRProfile()) {
+    return profile;
+  }
+  return profile->GetOriginalProfile();
+}
+
+// static
 void DevToolsWindow::ToggleDevToolsWindow(
     content::WebContents* inspected_web_contents,
     bool force_open,
@@ -726,8 +736,7 @@
   DevToolsWindow* window = FindDevToolsWindow(agent.get());
   bool do_open = force_open;
   if (!window) {
-    Profile* profile = Profile::FromBrowserContext(
-        inspected_web_contents->GetBrowserContext());
+    Profile* profile = GetProfileForDevToolsWindow(inspected_web_contents);
     base::RecordAction(base::UserMetricsAction("DevTools_InspectRenderer"));
     std::string panel;
     switch (action.type()) {
diff --git a/chrome/browser/devtools/devtools_window.h b/chrome/browser/devtools/devtools_window.h
index 688ff3a..106035c 100644
--- a/chrome/browser/devtools/devtools_window.h
+++ b/chrome/browser/devtools/devtools_window.h
@@ -335,6 +335,8 @@
       const DevToolsToggleAction& action,
       const std::string& settings,
       DevToolsOpenedByAction opened_by = DevToolsOpenedByAction::kUnknown);
+  static Profile* GetProfileForDevToolsWindow(
+      content::WebContents* web_contents);
 
   // content::WebContentsDelegate:
   void ActivateContents(content::WebContents* contents) override;