Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: chrome://accessibility not loading #24437

Merged
merged 12 commits into from Jul 16, 2020
3 changes: 3 additions & 0 deletions chromium_src/BUILD.gn
Expand Up @@ -12,6 +12,8 @@ import("//third_party/widevine/cdm/widevine.gni")
static_library("chrome") {
visibility = [ "//electron:electron_lib" ]
sources = [
"//chrome/browser/accessibility/accessibility_ui.cc",
"//chrome/browser/accessibility/accessibility_ui.h",
"//chrome/browser/browser_process.cc",
"//chrome/browser/browser_process.h",
"//chrome/browser/crash_upload_list/crash_upload_list_crashpad.cc",
Expand Down Expand Up @@ -66,6 +68,7 @@ static_library("chrome") {
"//chrome/common",
"//chrome/common:version_header",
"//components/keyed_service/content",
"//components/paint_preview/buildflags",
"//components/proxy_config",
"//components/security_state/content",
"//content/public/browser",
Expand Down
2 changes: 2 additions & 0 deletions electron_paks.gni
Expand Up @@ -54,6 +54,7 @@ template("electron_extra_paks") {
])
output = "${invoker.output_dir}/resources.pak"
sources = [
"$root_gen_dir/chrome/dev_ui_browser_resources.pak",
"$root_gen_dir/components/components_resources.pak",
"$root_gen_dir/content/browser/resources/media/media_internals_resources.pak",
"$root_gen_dir/content/browser/tracing/tracing_resources.pak",
Expand All @@ -67,6 +68,7 @@ template("electron_extra_paks") {
"$target_gen_dir/electron_resources.pak",
]
deps = [
"//chrome/browser:dev_ui_browser_resources",
"//components/resources",
"//content:content_resources",
"//content:dev_ui_content_resources",
Expand Down
2 changes: 2 additions & 0 deletions filenames.gni
Expand Up @@ -398,6 +398,8 @@ filenames = {
"shell/browser/ui/views/submenu_button.h",
"shell/browser/ui/views/win_frame_view.cc",
"shell/browser/ui/views/win_frame_view.h",
"shell/browser/ui/webui/accessibility_ui.cc",
"shell/browser/ui/webui/accessibility_ui.h",
"shell/browser/ui/win/dialog_thread.cc",
"shell/browser/ui/win/dialog_thread.h",
"shell/browser/ui/win/electron_desktop_native_widget_aura.cc",
Expand Down
2 changes: 2 additions & 0 deletions patches/chromium/.patches
Expand Up @@ -95,3 +95,5 @@ allow_setting_secondary_label_via_simplemenumodel.patch
fix_swap_global_proxies_before_initializing_the_windows_proxies.patch
feat_add_streaming-protocol_registry_to_multibuffer_data_source.patch
use_electron_resources_in_icon_reader_service.patch
fix_patch_out_profile_refs_in_accessibility_ui.patch
fix_accessibility_label_id_mismatch.patch
28 changes: 28 additions & 0 deletions patches/chromium/fix_accessibility_label_id_mismatch.patch
@@ -0,0 +1,28 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Shelley Vohr <shelley.vohr@gmail.com>
Date: Tue, 14 Jul 2020 09:54:17 -0700
Subject: Fix accessibility label ID mismatch

Refs https://chromium-review.googlesource.com/c/chromium/src/+/2231678.

When the label was updated to use underscores, the associated jQuery
call in accessibility.js was not likewise updated, so it would error
with:

"Uncaught TypeError: Cannot read property 'value' of null"

Upstreamed at https://chromium-review.googlesource.com/c/chromium/src/+/2296883

diff --git a/chrome/browser/resources/accessibility/accessibility.js b/chrome/browser/resources/accessibility/accessibility.js
index d0b0b7f9b922f9c5af180e1bfb22b886b51f90f7..bfa746233310a1150382750030f565fa81e93361 100644
--- a/chrome/browser/resources/accessibility/accessibility.js
+++ b/chrome/browser/resources/accessibility/accessibility.js
@@ -80,7 +80,7 @@ cr.define('accessibility', function() {
// function with the result.
const requestType = element.id.split(':')[1];
if (data.type == 'browser') {
- const delay = $('native_ui_delay').value;
+ const delay = $('native-ui-delay').value;
setTimeout(() => {
chrome.send(
'requestNativeUITree', [{
150 changes: 150 additions & 0 deletions patches/chromium/fix_patch_out_profile_refs_in_accessibility_ui.patch
@@ -0,0 +1,150 @@
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 acec47527e3f14e3c4b4f262da9995a95e6d3355..3a9434cbe7d86a0e99598c64ea756f07b241f74d 100644
--- a/chrome/browser/accessibility/accessibility_ui.cc
+++ b/chrome/browser/accessibility/accessibility_ui.cc
@@ -19,7 +19,9 @@
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "build/build_config.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"
@@ -44,7 +46,7 @@
#include "ui/accessibility/platform/ax_platform_node_delegate.h"
#include "ui/base/webui/web_ui_util.h"

-#if !defined(OS_ANDROID)
+#if 0
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h"
@@ -146,7 +148,7 @@ std::unique_ptr<base::DictionaryValue> BuildTargetDescriptor(
accessibility_mode);
}

-#if !defined(OS_ANDROID)
+#if 0
std::unique_ptr<base::DictionaryValue> BuildTargetDescriptor(Browser* browser) {
std::unique_ptr<base::DictionaryValue> target_data(
new base::DictionaryValue());
@@ -169,7 +171,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()
@@ -198,9 +202,7 @@ void HandleAccessibilityRequestCallback(
// The "labelImages" flag works only if "web" is enabled, the current profile
// has the kAccessibilityImageLabelsEnabled preference set and the appropriate
// command line switch has been used.
- bool are_accessibility_image_labels_enabled =
- is_web_enabled &&
- pref->GetBoolean(prefs::kAccessibilityImageLabelsEnabled);
+ bool are_accessibility_image_labels_enabled = is_web_enabled;
bool label_images = mode.has_mode(ui::AXMode::kLabelImages);
data.SetString(kLabelImages, are_accessibility_image_labels_enabled
? (label_images ? kOn : kOff)
@@ -209,7 +211,7 @@ void HandleAccessibilityRequestCallback(
// The "pdf" flag is independent of the others.
data.SetString(kPDF, pdf ? kOn : kOff);

- bool show_internal = pref->GetBoolean(prefs::kShowInternalAccessibilityTree);
+ bool show_internal = true;
data.SetString(kInternal, show_internal ? kOn : kOff);

std::unique_ptr<base::ListValue> rvh_list(new base::ListValue());
@@ -246,11 +248,11 @@ void HandleAccessibilityRequestCallback(
data.Set(kPagesField, std::move(rvh_list));

std::unique_ptr<base::ListValue> browser_list(new base::ListValue());
-#if !defined(OS_ANDROID)
+#if 0
for (Browser* browser : *BrowserList::GetInstance()) {
browser_list->Append(BuildTargetDescriptor(browser));
}
-#endif // !defined(OS_ANDROID)
+#endif // !defined(OS_ANDROID)
data.Set(kBrowsersField, std::move(browser_list));

std::string json_string;
@@ -477,8 +479,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;
}

@@ -581,11 +585,12 @@ void AccessibilityUIMessageHandler::RequestWebContentsTree(
content::AccessibilityTreeFormatter::PropertyFilter::ALLOW_EMPTY);
AddPropertyFilters(property_filters, deny,
content::AccessibilityTreeFormatter::PropertyFilter::DENY);
-
+#if 0
PrefService* pref = Profile::FromWebUI(web_ui())->GetPrefs();
bool internal = pref->GetBoolean(prefs::kShowInternalAccessibilityTree);
+#endif
base::string16 accessibility_contents_utf16 =
- web_contents->DumpAccessibilityTree(internal, property_filters);
+ web_contents->DumpAccessibilityTree(true, property_filters);
result->SetString(kTreeField,
codebytere marked this conversation as resolved.
Show resolved Hide resolved
base::UTF16ToUTF8(accessibility_contents_utf16));
CallJavascriptFunction(request_type, *(result.get()));
@@ -626,7 +631,8 @@ void AccessibilityUIMessageHandler::RequestNativeUITree(
content::AccessibilityTreeFormatter::PropertyFilter::ALLOW_EMPTY);
AddPropertyFilters(property_filters, deny,
content::AccessibilityTreeFormatter::PropertyFilter::DENY);
-
+#endif
+#if 0
for (Browser* browser : *BrowserList::GetInstance()) {
codebytere marked this conversation as resolved.
Show resolved Hide resolved
if (browser->session_id().id() == session_id) {
std::unique_ptr<base::DictionaryValue> result(
@@ -707,5 +713,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 906b24117cdf584dc4935e81c61fe664c48d552b..7a542240c77877a19d0e80649605a1fee393c50f 100644
--- a/chrome/browser/accessibility/accessibility_ui.h
+++ b/chrome/browser/accessibility/accessibility_ui.h
@@ -24,6 +24,8 @@ struct AXEventNotificationDetails;
class WebContents;
} // namespace content

+class ElectronAccessibilityUIMessageHandler;
+
namespace user_prefs {
class PrefRegistrySyncable;
} // namespace user_prefs
@@ -60,6 +62,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_;

7 changes: 6 additions & 1 deletion shell/browser/electron_web_ui_controller_factory.cc
Expand Up @@ -10,6 +10,7 @@
#include "content/public/browser/web_contents.h"
#include "electron/buildflags/buildflags.h"
#include "shell/browser/ui/devtools_ui.h"
#include "shell/browser/ui/webui/accessibility_ui.h"

namespace electron {

Expand All @@ -25,7 +26,8 @@ ElectronWebUIControllerFactory::~ElectronWebUIControllerFactory() = default;
content::WebUI::TypeID ElectronWebUIControllerFactory::GetWebUIType(
content::BrowserContext* browser_context,
const GURL& url) {
if (url.host() == chrome::kChromeUIDevToolsHost) {
if (url.host() == chrome::kChromeUIDevToolsHost ||
url.host() == chrome::kChromeUIAccessibilityHost) {
return const_cast<ElectronWebUIControllerFactory*>(this);
}

Expand All @@ -51,7 +53,10 @@ ElectronWebUIControllerFactory::CreateWebUIControllerForURL(
if (url.host() == chrome::kChromeUIDevToolsHost) {
auto* browser_context = web_ui->GetWebContents()->GetBrowserContext();
return std::make_unique<DevToolsUI>(browser_context, web_ui);
} else if (url.host() == chrome::kChromeUIAccessibilityHost) {
return std::make_unique<ElectronAccessibilityUI>(web_ui);
}

return std::unique_ptr<content::WebUIController>();
}

Expand Down
5 changes: 5 additions & 0 deletions shell/browser/native_window.cc
Expand Up @@ -49,6 +49,8 @@ gfx::Size GetExpandedWindowSize(const NativeWindow* window, gfx::Size size) {
NativeWindow::NativeWindow(const gin_helper::Dictionary& options,
NativeWindow* parent)
: widget_(new views::Widget), parent_(parent), weak_factory_(this) {
++next_id_;

options.Get(options::kFrame, &has_frame_);
options.Get(options::kTransparent, &transparent_);
options.Get(options::kEnableLargerThanScreen, &enable_larger_than_screen_);
Expand Down Expand Up @@ -606,6 +608,9 @@ std::string NativeWindow::GetAccessibleTitle() {
return base::UTF16ToUTF8(accessible_title_);
}

// static
int32_t NativeWindow::next_id_ = 0;
codebytere marked this conversation as resolved.
Show resolved Hide resolved

// static
void NativeWindowRelay::CreateForWebContents(
content::WebContents* web_contents,
Expand Down
4 changes: 4 additions & 0 deletions shell/browser/native_window.h
Expand Up @@ -308,6 +308,8 @@ class NativeWindow : public base::SupportsUserData,

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

int32_t window_id() const { return next_id_; }

protected:
NativeWindow(const gin_helper::Dictionary& options, NativeWindow* parent);

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

static int32_t next_id_;

// The content view, weak ref.
views::View* content_view_ = nullptr;

Expand Down