Skip to content

Commit 3f37ff8

Browse files
authored
fix: chrome://accessibility not loading (electron#24437)
1 parent 24fb498 commit 3f37ff8

File tree

11 files changed

+668
-1
lines changed

11 files changed

+668
-1
lines changed

chromium_src/BUILD.gn

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import("//third_party/widevine/cdm/widevine.gni")
1212
static_library("chrome") {
1313
visibility = [ "//electron:electron_lib" ]
1414
sources = [
15+
"//chrome/browser/accessibility/accessibility_ui.cc",
16+
"//chrome/browser/accessibility/accessibility_ui.h",
1517
"//chrome/browser/browser_process.cc",
1618
"//chrome/browser/browser_process.h",
1719
"//chrome/browser/crash_upload_list/crash_upload_list_crashpad.cc",
@@ -66,6 +68,7 @@ static_library("chrome") {
6668
"//chrome/common",
6769
"//chrome/common:version_header",
6870
"//components/keyed_service/content",
71+
"//components/paint_preview/buildflags",
6972
"//components/proxy_config",
7073
"//components/security_state/content",
7174
"//content/public/browser",

electron_paks.gni

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ template("electron_extra_paks") {
5454
])
5555
output = "${invoker.output_dir}/resources.pak"
5656
sources = [
57+
"$root_gen_dir/chrome/dev_ui_browser_resources.pak",
5758
"$root_gen_dir/components/components_resources.pak",
5859
"$root_gen_dir/content/browser/resources/media/media_internals_resources.pak",
5960
"$root_gen_dir/content/browser/tracing/tracing_resources.pak",
@@ -67,6 +68,7 @@ template("electron_extra_paks") {
6768
"$target_gen_dir/electron_resources.pak",
6869
]
6970
deps = [
71+
"//chrome/browser:dev_ui_browser_resources",
7072
"//components/resources",
7173
"//content:content_resources",
7274
"//content:dev_ui_content_resources",

filenames.gni

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,8 @@ filenames = {
398398
"shell/browser/ui/views/submenu_button.h",
399399
"shell/browser/ui/views/win_frame_view.cc",
400400
"shell/browser/ui/views/win_frame_view.h",
401+
"shell/browser/ui/webui/accessibility_ui.cc",
402+
"shell/browser/ui/webui/accessibility_ui.h",
401403
"shell/browser/ui/win/dialog_thread.cc",
402404
"shell/browser/ui/win/dialog_thread.h",
403405
"shell/browser/ui/win/electron_desktop_native_widget_aura.cc",

patches/chromium/.patches

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,5 @@ allow_setting_secondary_label_via_simplemenumodel.patch
9595
fix_swap_global_proxies_before_initializing_the_windows_proxies.patch
9696
feat_add_streaming-protocol_registry_to_multibuffer_data_source.patch
9797
use_electron_resources_in_icon_reader_service.patch
98+
fix_patch_out_profile_refs_in_accessibility_ui.patch
99+
fix_accessibility_label_id_mismatch.patch
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Shelley Vohr <shelley.vohr@gmail.com>
3+
Date: Tue, 14 Jul 2020 09:54:17 -0700
4+
Subject: Fix accessibility label ID mismatch
5+
6+
Refs https://chromium-review.googlesource.com/c/chromium/src/+/2231678.
7+
8+
When the label was updated to use underscores, the associated jQuery
9+
call in accessibility.js was not likewise updated, so it would error
10+
with:
11+
12+
"Uncaught TypeError: Cannot read property 'value' of null"
13+
14+
Upstreamed at https://chromium-review.googlesource.com/c/chromium/src/+/2296883
15+
16+
diff --git a/chrome/browser/resources/accessibility/accessibility.js b/chrome/browser/resources/accessibility/accessibility.js
17+
index d0b0b7f9b922f9c5af180e1bfb22b886b51f90f7..bfa746233310a1150382750030f565fa81e93361 100644
18+
--- a/chrome/browser/resources/accessibility/accessibility.js
19+
+++ b/chrome/browser/resources/accessibility/accessibility.js
20+
@@ -80,7 +80,7 @@ cr.define('accessibility', function() {
21+
// function with the result.
22+
const requestType = element.id.split(':')[1];
23+
if (data.type == 'browser') {
24+
- const delay = $('native_ui_delay').value;
25+
+ const delay = $('native-ui-delay').value;
26+
setTimeout(() => {
27+
chrome.send(
28+
'requestNativeUITree', [{
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Shelley Vohr <shelley.vohr@gmail.com>
3+
Date: Mon, 6 Jul 2020 13:46:06 -0700
4+
Subject: fix: patch out Profile refs in accessibility_ui
5+
6+
This tweaks Chrome's Accessibility support at chrome://accessibility
7+
to make it usable from Electron by removing Profile references.
8+
9+
diff --git a/chrome/browser/accessibility/accessibility_ui.cc b/chrome/browser/accessibility/accessibility_ui.cc
10+
index acec47527e3f14e3c4b4f262da9995a95e6d3355..3a9434cbe7d86a0e99598c64ea756f07b241f74d 100644
11+
--- a/chrome/browser/accessibility/accessibility_ui.cc
12+
+++ b/chrome/browser/accessibility/accessibility_ui.cc
13+
@@ -19,7 +19,9 @@
14+
#include "base/strings/utf_string_conversions.h"
15+
#include "base/values.h"
16+
#include "build/build_config.h"
17+
+#if 0
18+
#include "chrome/browser/profiles/profile.h"
19+
+#endif
20+
#include "chrome/common/chrome_features.h"
21+
#include "chrome/common/pref_names.h"
22+
#include "chrome/common/webui_url_constants.h"
23+
@@ -44,7 +46,7 @@
24+
#include "ui/accessibility/platform/ax_platform_node_delegate.h"
25+
#include "ui/base/webui/web_ui_util.h"
26+
27+
-#if !defined(OS_ANDROID)
28+
+#if 0
29+
#include "chrome/browser/ui/browser.h"
30+
#include "chrome/browser/ui/browser_list.h"
31+
#include "chrome/browser/ui/browser_window.h"
32+
@@ -146,7 +148,7 @@ std::unique_ptr<base::DictionaryValue> BuildTargetDescriptor(
33+
accessibility_mode);
34+
}
35+
36+
-#if !defined(OS_ANDROID)
37+
+#if 0
38+
std::unique_ptr<base::DictionaryValue> BuildTargetDescriptor(Browser* browser) {
39+
std::unique_ptr<base::DictionaryValue> target_data(
40+
new base::DictionaryValue());
41+
@@ -169,7 +171,9 @@ void HandleAccessibilityRequestCallback(
42+
DCHECK(ShouldHandleAccessibilityRequestCallback(path));
43+
44+
base::DictionaryValue data;
45+
+#if 0
46+
PrefService* pref = Profile::FromBrowserContext(current_context)->GetPrefs();
47+
+#endif
48+
ui::AXMode mode =
49+
content::BrowserAccessibilityState::GetInstance()->GetAccessibilityMode();
50+
bool is_native_enabled = content::BrowserAccessibilityState::GetInstance()
51+
@@ -198,9 +202,7 @@ void HandleAccessibilityRequestCallback(
52+
// The "labelImages" flag works only if "web" is enabled, the current profile
53+
// has the kAccessibilityImageLabelsEnabled preference set and the appropriate
54+
// command line switch has been used.
55+
- bool are_accessibility_image_labels_enabled =
56+
- is_web_enabled &&
57+
- pref->GetBoolean(prefs::kAccessibilityImageLabelsEnabled);
58+
+ bool are_accessibility_image_labels_enabled = is_web_enabled;
59+
bool label_images = mode.has_mode(ui::AXMode::kLabelImages);
60+
data.SetString(kLabelImages, are_accessibility_image_labels_enabled
61+
? (label_images ? kOn : kOff)
62+
@@ -209,7 +211,7 @@ void HandleAccessibilityRequestCallback(
63+
// The "pdf" flag is independent of the others.
64+
data.SetString(kPDF, pdf ? kOn : kOff);
65+
66+
- bool show_internal = pref->GetBoolean(prefs::kShowInternalAccessibilityTree);
67+
+ bool show_internal = true;
68+
data.SetString(kInternal, show_internal ? kOn : kOff);
69+
70+
std::unique_ptr<base::ListValue> rvh_list(new base::ListValue());
71+
@@ -246,11 +248,11 @@ void HandleAccessibilityRequestCallback(
72+
data.Set(kPagesField, std::move(rvh_list));
73+
74+
std::unique_ptr<base::ListValue> browser_list(new base::ListValue());
75+
-#if !defined(OS_ANDROID)
76+
+#if 0
77+
for (Browser* browser : *BrowserList::GetInstance()) {
78+
browser_list->Append(BuildTargetDescriptor(browser));
79+
}
80+
-#endif // !defined(OS_ANDROID)
81+
+#endif // !defined(OS_ANDROID)
82+
data.Set(kBrowsersField, std::move(browser_list));
83+
84+
std::string json_string;
85+
@@ -477,8 +479,10 @@ void AccessibilityUIMessageHandler::SetGlobalFlag(const base::ListValue* args) {
86+
87+
AllowJavascript();
88+
if (flag_name_str == kInternal) {
89+
+#if 0
90+
PrefService* pref = Profile::FromWebUI(web_ui())->GetPrefs();
91+
pref->SetBoolean(prefs::kShowInternalAccessibilityTree, enabled);
92+
+#endif
93+
return;
94+
}
95+
96+
@@ -581,11 +585,12 @@ void AccessibilityUIMessageHandler::RequestWebContentsTree(
97+
content::AccessibilityTreeFormatter::PropertyFilter::ALLOW_EMPTY);
98+
AddPropertyFilters(property_filters, deny,
99+
content::AccessibilityTreeFormatter::PropertyFilter::DENY);
100+
-
101+
+#if 0
102+
PrefService* pref = Profile::FromWebUI(web_ui())->GetPrefs();
103+
bool internal = pref->GetBoolean(prefs::kShowInternalAccessibilityTree);
104+
+#endif
105+
base::string16 accessibility_contents_utf16 =
106+
- web_contents->DumpAccessibilityTree(internal, property_filters);
107+
+ web_contents->DumpAccessibilityTree(true, property_filters);
108+
result->SetString(kTreeField,
109+
base::UTF16ToUTF8(accessibility_contents_utf16));
110+
CallJavascriptFunction(request_type, *(result.get()));
111+
@@ -626,7 +631,8 @@ void AccessibilityUIMessageHandler::RequestNativeUITree(
112+
content::AccessibilityTreeFormatter::PropertyFilter::ALLOW_EMPTY);
113+
AddPropertyFilters(property_filters, deny,
114+
content::AccessibilityTreeFormatter::PropertyFilter::DENY);
115+
-
116+
+#endif
117+
+#if 0
118+
for (Browser* browser : *BrowserList::GetInstance()) {
119+
if (browser->session_id().id() == session_id) {
120+
std::unique_ptr<base::DictionaryValue> result(
121+
@@ -707,5 +713,7 @@ void AccessibilityUIMessageHandler::RequestAccessibilityEvents(
122+
// static
123+
void AccessibilityUIMessageHandler::RegisterProfilePrefs(
124+
user_prefs::PrefRegistrySyncable* registry) {
125+
+#if 0
126+
registry->RegisterBooleanPref(prefs::kShowInternalAccessibilityTree, false);
127+
+#endif
128+
}
129+
diff --git a/chrome/browser/accessibility/accessibility_ui.h b/chrome/browser/accessibility/accessibility_ui.h
130+
index 906b24117cdf584dc4935e81c61fe664c48d552b..7a542240c77877a19d0e80649605a1fee393c50f 100644
131+
--- a/chrome/browser/accessibility/accessibility_ui.h
132+
+++ b/chrome/browser/accessibility/accessibility_ui.h
133+
@@ -24,6 +24,8 @@ struct AXEventNotificationDetails;
134+
class WebContents;
135+
} // namespace content
136+
137+
+class ElectronAccessibilityUIMessageHandler;
138+
+
139+
namespace user_prefs {
140+
class PrefRegistrySyncable;
141+
} // namespace user_prefs
142+
@@ -60,6 +62,8 @@ class AccessibilityUIMessageHandler : public content::WebUIMessageHandler {
143+
static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
144+
145+
private:
146+
+ friend class ElectronAccessibilityUIMessageHandler;
147+
+
148+
std::vector<std::string> event_logs_;
149+
std::unique_ptr<AccessibilityUIObserver> observer_;
150+

shell/browser/electron_web_ui_controller_factory.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "content/public/browser/web_contents.h"
1111
#include "electron/buildflags/buildflags.h"
1212
#include "shell/browser/ui/devtools_ui.h"
13+
#include "shell/browser/ui/webui/accessibility_ui.h"
1314

1415
namespace electron {
1516

@@ -25,7 +26,8 @@ ElectronWebUIControllerFactory::~ElectronWebUIControllerFactory() = default;
2526
content::WebUI::TypeID ElectronWebUIControllerFactory::GetWebUIType(
2627
content::BrowserContext* browser_context,
2728
const GURL& url) {
28-
if (url.host() == chrome::kChromeUIDevToolsHost) {
29+
if (url.host() == chrome::kChromeUIDevToolsHost ||
30+
url.host() == chrome::kChromeUIAccessibilityHost) {
2931
return const_cast<ElectronWebUIControllerFactory*>(this);
3032
}
3133

@@ -51,7 +53,10 @@ ElectronWebUIControllerFactory::CreateWebUIControllerForURL(
5153
if (url.host() == chrome::kChromeUIDevToolsHost) {
5254
auto* browser_context = web_ui->GetWebContents()->GetBrowserContext();
5355
return std::make_unique<DevToolsUI>(browser_context, web_ui);
56+
} else if (url.host() == chrome::kChromeUIAccessibilityHost) {
57+
return std::make_unique<ElectronAccessibilityUI>(web_ui);
5458
}
59+
5560
return std::unique_ptr<content::WebUIController>();
5661
}
5762

shell/browser/native_window.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ gfx::Size GetExpandedWindowSize(const NativeWindow* window, gfx::Size size) {
4949
NativeWindow::NativeWindow(const gin_helper::Dictionary& options,
5050
NativeWindow* parent)
5151
: widget_(new views::Widget), parent_(parent), weak_factory_(this) {
52+
++next_id_;
53+
5254
options.Get(options::kFrame, &has_frame_);
5355
options.Get(options::kTransparent, &transparent_);
5456
options.Get(options::kEnableLargerThanScreen, &enable_larger_than_screen_);
@@ -606,6 +608,9 @@ std::string NativeWindow::GetAccessibleTitle() {
606608
return base::UTF16ToUTF8(accessible_title_);
607609
}
608610

611+
// static
612+
int32_t NativeWindow::next_id_ = 0;
613+
609614
// static
610615
void NativeWindowRelay::CreateForWebContents(
611616
content::WebContents* web_contents,

shell/browser/native_window.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,8 @@ class NativeWindow : public base::SupportsUserData,
308308

309309
std::list<NativeBrowserView*> browser_views() const { return browser_views_; }
310310

311+
int32_t window_id() const { return next_id_; }
312+
311313
protected:
312314
NativeWindow(const gin_helper::Dictionary& options, NativeWindow* parent);
313315

@@ -329,6 +331,8 @@ class NativeWindow : public base::SupportsUserData,
329331
private:
330332
std::unique_ptr<views::Widget> widget_;
331333

334+
static int32_t next_id_;
335+
332336
// The content view, weak ref.
333337
views::View* content_view_ = nullptr;
334338

0 commit comments

Comments
 (0)