From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Shelley Vohr <shelley.vohr@gmail.com>
Date: Mon, 6 Jul 2020 13:46:06 -0700
Subject: fix: patch out Profile refs in accessibility_ui

This tweaks Chrome's Accessibility support at chrome://accessibility
to make it usable from Electron by removing Profile references.

diff --git a/chrome/browser/ui/webui/accessibility/accessibility_ui.cc b/chrome/browser/ui/webui/accessibility/accessibility_ui.cc
index 180e18a01f82542b55fc9d7b8615b1731ff31d75..f9289b0103d85083c936788ed0c165b661a91cb9 100644
--- a/chrome/browser/ui/webui/accessibility/accessibility_ui.cc
+++ b/chrome/browser/ui/webui/accessibility/accessibility_ui.cc
@@ -22,7 +22,10 @@
 #include "base/trace_event/trace_event.h"
 #include "build/build_config.h"
 #include "build/chromeos_buildflags.h"
+#if 0
 #include "chrome/browser/profiles/profile.h"
+#endif
+#include "chrome/common/chrome_features.h"
 #include "chrome/common/pref_names.h"
 #include "chrome/common/webui_url_constants.h"
 #include "chrome/grit/accessibility_resources.h"
@@ -32,6 +35,7 @@
 #include "content/public/browser/ax_event_notification_details.h"
 #include "content/public/browser/ax_inspect_factory.h"
 #include "content/public/browser/browser_accessibility_state.h"
+#include "content/public/browser/browser_context.h"
 #include "content/public/browser/browser_thread.h"
 #include "content/public/browser/favicon_status.h"
 #include "content/public/browser/navigation_entry.h"
@@ -51,9 +55,11 @@
 #include "ui/views/accessibility/view_accessibility.h"
 
 #if !BUILDFLAG(IS_ANDROID)
+#if 0
 #include "chrome/browser/ui/browser.h"
 #include "chrome/browser/ui/browser_list.h"
 #include "chrome/browser/ui/browser_window.h"
+#endif
 #include "ui/views/accessibility/widget_ax_tree_id_map.h"
 #include "ui/views/widget/widget.h"
 #include "ui/views/widget/widget_delegate.h"
@@ -165,7 +171,7 @@ base::Value::Dict BuildTargetDescriptor(content::RenderViewHost* rvh) {
                                accessibility_mode);
 }
 
-#if !BUILDFLAG(IS_ANDROID)
+#if 0
 base::Value::Dict BuildTargetDescriptor(Browser* browser) {
   base::Value::Dict target_data;
   target_data.Set(kSessionIdField, browser->session_id().id());
@@ -199,7 +205,9 @@ void HandleAccessibilityRequestCallback(
   DCHECK(ShouldHandleAccessibilityRequestCallback(path));
 
   base::Value::Dict data;
+#if 0
   PrefService* pref = Profile::FromBrowserContext(current_context)->GetPrefs();
+#endif
   ui::AXMode mode =
       content::BrowserAccessibilityState::GetInstance()->GetAccessibilityMode();
   bool is_native_enabled = content::BrowserAccessibilityState::GetInstance()
@@ -231,7 +239,7 @@ void HandleAccessibilityRequestCallback(
   // enabled.
   data.Set(kViewsAccessibility, features::IsAccessibilityTreeForViewsEnabled());
 
-  bool show_internal = pref->GetBoolean(prefs::kShowInternalAccessibilityTree);
+  bool show_internal = true;
   data.Set(kInternal, show_internal ? kOn : kOff);
 
   bool is_mode_locked = !content::BrowserAccessibilityState::GetInstance()
@@ -278,11 +286,11 @@ void HandleAccessibilityRequestCallback(
   data.Set(kPagesField, std::move(page_list));
 
   base::Value::List browser_list;
-#if !BUILDFLAG(IS_ANDROID)
+#if 0
   for (Browser* browser : *BrowserList::GetInstance()) {
     browser_list.Append(BuildTargetDescriptor(browser));
   }
-#endif  // !BUILDFLAG(IS_ANDROID)
+#endif // !BUILDFLAG(IS_ANDROID)
   data.Set(kBrowsersField, std::move(browser_list));
 
   base::Value::List widgets_list;
@@ -554,8 +562,10 @@ void AccessibilityUIMessageHandler::SetGlobalFlag(
 
   AllowJavascript();
   if (flag_name_str == kInternal) {
+#if 0
     PrefService* pref = Profile::FromWebUI(web_ui())->GetPrefs();
     pref->SetBoolean(prefs::kShowInternalAccessibilityTree, enabled);
+#endif
     return;
   } else if (flag_name_str == kLocked) {
     content::BrowserAccessibilityState::GetInstance()->SetAXModeChangeAllowed(
@@ -669,8 +679,12 @@ void AccessibilityUIMessageHandler::RequestWebContentsTree(
                      AXPropertyFilter::ALLOW_EMPTY);
   AddPropertyFilters(property_filters, deny, AXPropertyFilter::DENY);
 
+#if 0
   PrefService* pref = Profile::FromWebUI(web_ui())->GetPrefs();
   bool internal = pref->GetBoolean(prefs::kShowInternalAccessibilityTree);
+#else
+  bool internal = true;
+#endif
   std::string accessibility_contents =
       web_contents->DumpAccessibilityTree(internal, property_filters);
   result.Set(kTreeField, accessibility_contents);
@@ -695,6 +709,7 @@ void AccessibilityUIMessageHandler::RequestNativeUITree(
                      AXPropertyFilter::ALLOW_EMPTY);
   AddPropertyFilters(property_filters, deny, AXPropertyFilter::DENY);
 
+#if 0
   for (Browser* browser : *BrowserList::GetInstance()) {
     if (browser->session_id().id() == session_id) {
       base::Value::Dict result = BuildTargetDescriptor(browser);
@@ -707,6 +722,7 @@ void AccessibilityUIMessageHandler::RequestNativeUITree(
       return;
     }
   }
+#endif
 #endif  // !BUILDFLAG(IS_ANDROID)
   // No browser with the specified |session_id| was found.
   base::Value::Dict result;
@@ -819,5 +835,7 @@ void AccessibilityUIMessageHandler::RequestAccessibilityEvents(
 // static
 void AccessibilityUIMessageHandler::RegisterProfilePrefs(
     user_prefs::PrefRegistrySyncable* registry) {
+#if 0
   registry->RegisterBooleanPref(prefs::kShowInternalAccessibilityTree, false);
+#endif
 }
diff --git a/chrome/browser/ui/webui/accessibility/accessibility_ui.h b/chrome/browser/ui/webui/accessibility/accessibility_ui.h
index 0ce6849ebef640b23e439fbbe70d6f76fe9d8df3..f4840644583c7dd966538635c8cdf225efa70e92 100644
--- a/chrome/browser/ui/webui/accessibility/accessibility_ui.h
+++ b/chrome/browser/ui/webui/accessibility/accessibility_ui.h
@@ -26,6 +26,8 @@ class ScopedAccessibilityMode;
 class WebContents;
 }  // namespace content
 
+class ElectronAccessibilityUIMessageHandler;
+
 namespace user_prefs {
 class PrefRegistrySyncable;
 }  // namespace user_prefs
@@ -78,6 +80,8 @@ class AccessibilityUIMessageHandler : public content::WebUIMessageHandler {
   static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
 
  private:
+  friend class ElectronAccessibilityUIMessageHandler;
+
   // Applies `mode` to `web_contents` for the lifetime of the accessibility
   // UI page.
   void SetAccessibilityModeForWebContents(content::WebContents* web_contents,
