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/accessibility/accessibility_ui.cc b/chrome/browser/accessibility/accessibility_ui.cc
index 555dba06e99bd7294f88a21ddaf3b86a12fdd5ac..8064592eb285d1407ff8334149c27e3a65560d9e 100644
--- a/chrome/browser/accessibility/accessibility_ui.cc
+++ b/chrome/browser/accessibility/accessibility_ui.cc
@@ -20,7 +20,10 @@
 #include "base/values.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/dev_ui_browser_resources.h"
@@ -49,9 +52,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"
@@ -163,7 +168,7 @@ std::unique_ptr<base::DictionaryValue> BuildTargetDescriptor(
                                accessibility_mode);
 }
 
-#if !BUILDFLAG(IS_ANDROID)
+#if 0
 std::unique_ptr<base::DictionaryValue> BuildTargetDescriptor(Browser* browser) {
   std::unique_ptr<base::DictionaryValue> target_data(
       new base::DictionaryValue());
@@ -202,7 +207,9 @@ void HandleAccessibilityRequestCallback(
   DCHECK(ShouldHandleAccessibilityRequestCallback(path));
 
   base::DictionaryValue 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()
@@ -236,7 +243,7 @@ void HandleAccessibilityRequestCallback(
   data.SetBoolKey(kViewsAccessibility,
                   features::IsAccessibilityTreeForViewsEnabled());
 
-  bool show_internal = pref->GetBoolean(prefs::kShowInternalAccessibilityTree);
+  bool show_internal = true;
   data.SetStringKey(kInternal, show_internal ? kOn : kOff);
 
   std::unique_ptr<base::ListValue> rvh_list(new base::ListValue());
@@ -271,11 +278,11 @@ void HandleAccessibilityRequestCallback(
   data.Set(kPagesField, std::move(rvh_list));
 
   std::unique_ptr<base::ListValue> browser_list(new base::ListValue());
-#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));
 
   std::unique_ptr<base::ListValue> widgets_list(new base::ListValue());
@@ -491,8 +498,10 @@ void AccessibilityUIMessageHandler::SetGlobalFlag(const base::ListValue* args) {
 
   AllowJavascript();
   if (flag_name_str == kInternal) {
+#if 0
     PrefService* pref = Profile::FromWebUI(web_ui())->GetPrefs();
     pref->SetBoolean(prefs::kShowInternalAccessibilityTree, enabled);
+#endif
     return;
   }
 
@@ -599,10 +608,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);
+#endif
   std::string accessibility_contents =
-      web_contents->DumpAccessibilityTree(internal, property_filters);
+      web_contents->DumpAccessibilityTree(true, property_filters);
   result->SetStringKey(kTreeField, accessibility_contents);
   FireWebUIListener(request_type, *(result.get()));
 }
@@ -627,6 +638,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) {
       std::unique_ptr<base::DictionaryValue> result(
@@ -641,6 +653,7 @@ void AccessibilityUIMessageHandler::RequestNativeUITree(
       return;
     }
   }
+#endif
 #endif  // !BUILDFLAG(IS_ANDROID)
   // No browser with the specified |session_id| was found.
   std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue());
@@ -757,5 +770,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/accessibility/accessibility_ui.h b/chrome/browser/accessibility/accessibility_ui.h
index 0f73d3883093f6e49427ac6fe6428e97282a1e03..9041c90d13b07b03cc96e8a03a3821ef54a69a7d 100644
--- a/chrome/browser/accessibility/accessibility_ui.h
+++ b/chrome/browser/accessibility/accessibility_ui.h
@@ -26,6 +26,8 @@ struct AXEventNotificationDetails;
 class WebContents;
 }  // namespace content
 
+class ElectronAccessibilityUIMessageHandler;
+
 namespace user_prefs {
 class PrefRegistrySyncable;
 }  // namespace user_prefs
@@ -67,6 +69,8 @@ class AccessibilityUIMessageHandler : public content::WebUIMessageHandler {
   static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
 
  private:
+  friend class ElectronAccessibilityUIMessageHandler;
+
   std::vector<std::string> event_logs_;
   std::unique_ptr<AccessibilityUIObserver> observer_;
 
