2020-07-16 17:14:54 +00:00
|
|
|
// Copyright (c) 2020 Microsoft, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "shell/browser/ui/webui/accessibility_ui.h"
|
|
|
|
|
2021-06-01 01:34:44 +00:00
|
|
|
#include <memory>
|
2024-01-10 22:23:35 +00:00
|
|
|
#include <optional>
|
2021-06-01 01:34:44 +00:00
|
|
|
#include <string>
|
2020-07-16 17:14:54 +00:00
|
|
|
#include <utility>
|
2021-06-01 01:34:44 +00:00
|
|
|
#include <vector>
|
2020-07-16 17:14:54 +00:00
|
|
|
|
|
|
|
#include "base/command_line.h"
|
2023-02-03 11:43:42 +00:00
|
|
|
#include "base/functional/bind.h"
|
|
|
|
#include "base/functional/callback_helpers.h"
|
2020-07-16 17:14:54 +00:00
|
|
|
#include "base/json/json_writer.h"
|
2022-05-17 16:48:40 +00:00
|
|
|
#include "base/strings/escape.h"
|
2020-07-16 17:14:54 +00:00
|
|
|
#include "base/strings/pattern.h"
|
|
|
|
#include "base/strings/utf_string_conversions.h"
|
|
|
|
#include "base/values.h"
|
|
|
|
#include "build/build_config.h"
|
|
|
|
#include "chrome/common/pref_names.h"
|
|
|
|
#include "chrome/common/webui_url_constants.h"
|
2023-06-09 23:08:36 +00:00
|
|
|
#include "chrome/grit/accessibility_resources.h" // nogncheck
|
|
|
|
#include "chrome/grit/accessibility_resources_map.h" // nogncheck
|
2020-07-16 17:14:54 +00:00
|
|
|
#include "components/pref_registry/pref_registry_syncable.h"
|
|
|
|
#include "components/prefs/pref_service.h"
|
2020-12-14 18:57:36 +00:00
|
|
|
#include "content/public/browser/ax_inspect_factory.h"
|
2020-07-16 17:14:54 +00:00
|
|
|
#include "content/public/browser/browser_accessibility_state.h"
|
chore: bump chromium to 118.0.5975.0 (main) (#39531)
* chore: bump chromium in DEPS to 118.0.5951.0
* chore: update printing.patch
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4727894
No logic changes, but patch needed to be manually re-applied due to upstream code shear
* chore: update port_autofill_colors_to_the_color_pipeline.patch
No manual changes; patch applied with fuzz
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5953.0
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5955.0
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5957.0
* chore: update patches
* chore: include path of native_web_keyboard_event.h
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4758689
* chore: remove reference to eextensions/browser/notification-types.h
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4771627
* chore: update references to renamed upstream field NativeWebKeyboardEvent.skip_if_unhandled (formerly known as skip_in_browser
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4758689
Need a second pair of eyes on this commit. In particular the reference in content_converter.cc, skipInBrowser, seems to not be set or documented anywhere? Is this unused/vestigal code?
* chore: sync signature of ElectronExtensionsBrowserClient::IsValidContext() to upstream change
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4784198
* chore: add auto_pip_setting_helper.[cc,h] to chromium_src build
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4688277
Exiting upstream code used by chromium_src now depends on this new upstream class
* chore: bump chromium in DEPS to 118.0.5959.0
* chore: update add_maximized_parameter_to_linuxui_getwindowframeprovider.patch
Xref: add_maximized_parameter_to_linuxui_getwindowframeprovider.patch
manually adjust patch to minor upstream chagnes
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5961.0
* chore: bump chromium in DEPS to 118.0.5963.0
* chore: update patches
* 4780994: Rename various base files to "apple" since iOS uses them too
https://chromium-review.googlesource.com/c/chromium/src/+/4780994
* Many files moved from `mac` -> `apple`
This commit follows a handful of CLs that simply rename files/symbols to change `mac`
to `apple`
to signify their use across both macOS and iOS:
- 4784010: Move scoped_nsautorelease_pool to base/apple, leave a forwarding header
- 4790744: Move foundation_util to base/apple, leave a forwarding header
- 4790741: Move scoped_cftypreref to base/apple, leave a forwarding header
- 4787627: Move and rename macOS+iOS base/ files in PA to "apple"
- 4780399: Move OSStatus logging to base/apple
- 4787387: Remove forwarding headers
- 4781113: Rename message_pump_mac to "apple" because iOS uses it too
* fixup minor patch update error
A function param got dropped from this patch somewhere earlier
* chore: bump chromium in DEPS to 118.0.5965.2
* chore: update patches
* 4799213: Move ScopedTypeRef and ScopedCFTypeRef into base::apple::
https://chromium-review.googlesource.com/c/chromium/src/+/4799213
* Fix removed include to BrowserContext
In crrev.com/c/4767962 an include to BrowserContext was removed,
which was necessary for compilation. This broke only for us because
"chrome/browser/profiles/profile.h" includes that class, but we remove
all references to profiles.
* chore: bump chromium in DEPS to 118.0.5967.0
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5969.0
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5971.0
* chore: bump chromium in DEPS to 118.0.5973.0
* chore: update patches
* 4772121: [OOPIF PDF] Replace PDFWebContentsHelper with PDFDocumentHelper
https://chromium-review.googlesource.com/c/chromium/src/+/4772121
* 4811164: [Extensions] Do some cleanup in ChromeManagementAPIDelegate.
https://chromium-review.googlesource.com/c/chromium/src/+/4811164
* 4809488: Remove duplicate dnd functionality between Web and Renderer prefs
https://chromium-review.googlesource.com/c/chromium/src/+/4809488
Given that this is no longer an option of web preferences, we should
consider deprecating this option and then removing it.
* chore: bump chromium in DEPS to 118.0.5975.0
* chore: update patches
* fixup! chore: add auto_pip_settings_helper.{cc|h} to chromium_src build
* Reland "[windows] Remove RegKey::DeleteEmptyKey"
Refs https://chromium-review.googlesource.com/c/chromium/src/+/4813255
* Ensure StrCat means StrCat
Refs https://chromium-review.googlesource.com/c/chromium/src/+/1117180
* fixup! Remove RegKey::DeleteEmptyKey
* Consistently reject large p and large q in DH
Refs https://boringssl-review.googlesource.com/c/boringssl/+/62226
---------
Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
Co-authored-by: clavin <clavin@electronjs.org>
Co-authored-by: deepak1556 <hop2deep@gmail.com>
2023-09-01 06:54:59 +00:00
|
|
|
#include "content/public/browser/browser_context.h"
|
2020-07-16 17:14:54 +00:00
|
|
|
#include "content/public/browser/browser_thread.h"
|
|
|
|
#include "content/public/browser/favicon_status.h"
|
|
|
|
#include "content/public/browser/navigation_entry.h"
|
|
|
|
#include "content/public/browser/render_process_host.h"
|
|
|
|
#include "content/public/browser/render_view_host.h"
|
|
|
|
#include "content/public/browser/render_widget_host.h"
|
|
|
|
#include "content/public/browser/render_widget_host_iterator.h"
|
|
|
|
#include "content/public/browser/web_contents.h"
|
|
|
|
#include "content/public/browser/web_contents_delegate.h"
|
|
|
|
#include "content/public/browser/web_ui_data_source.h"
|
2024-04-23 15:30:47 +00:00
|
|
|
#include "shell/browser/electron_browser_context.h"
|
2020-07-16 17:14:54 +00:00
|
|
|
#include "shell/browser/native_window.h"
|
|
|
|
#include "shell/browser/window_list.h"
|
2024-04-23 15:30:47 +00:00
|
|
|
#include "ui/accessibility/accessibility_features.h"
|
2024-05-10 15:21:10 +00:00
|
|
|
#include "ui/accessibility/ax_updates_and_events.h"
|
2020-07-16 17:14:54 +00:00
|
|
|
#include "ui/accessibility/platform/ax_platform_node.h"
|
|
|
|
#include "ui/accessibility/platform/ax_platform_node_delegate.h"
|
|
|
|
#include "ui/base/webui/web_ui_util.h"
|
2024-04-23 15:30:47 +00:00
|
|
|
#include "ui/views/accessibility/view_accessibility.h"
|
|
|
|
#include "ui/views/accessibility/widget_ax_tree_id_map.h"
|
|
|
|
#include "ui/views/widget/widget.h"
|
|
|
|
#include "ui/views/widget/widget_delegate.h"
|
2020-07-16 17:14:54 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
static const char kTargetsDataFile[] = "targets-data.json";
|
|
|
|
|
|
|
|
static const char kAccessibilityModeField[] = "a11yMode";
|
|
|
|
static const char kBrowsersField[] = "browsers";
|
|
|
|
static const char kErrorField[] = "error";
|
|
|
|
static const char kFaviconUrlField[] = "faviconUrl";
|
|
|
|
static const char kNameField[] = "name";
|
|
|
|
static const char kPagesField[] = "pages";
|
|
|
|
static const char kPidField[] = "pid";
|
|
|
|
static const char kProcessIdField[] = "processId";
|
|
|
|
static const char kRequestTypeField[] = "requestType";
|
|
|
|
static const char kRoutingIdField[] = "routingId";
|
2024-04-23 15:30:47 +00:00
|
|
|
static const char kSessionIdField[] = "sessionId";
|
|
|
|
static const char kSupportedApiTypesField[] = "supportedApiTypes";
|
|
|
|
static const char kTreeField[] = "tree";
|
2020-07-16 17:14:54 +00:00
|
|
|
static const char kTypeField[] = "type";
|
|
|
|
static const char kUrlField[] = "url";
|
2024-04-23 15:30:47 +00:00
|
|
|
static const char kWidgetsField[] = "widgets";
|
|
|
|
static const char kApiTypeField[] = "apiType";
|
|
|
|
|
|
|
|
#if defined(USE_AURA)
|
|
|
|
static const char kWidgetIdField[] = "widgetId";
|
|
|
|
static const char kWidget[] = "widget";
|
|
|
|
#endif
|
2020-07-16 17:14:54 +00:00
|
|
|
|
|
|
|
// Global flags
|
|
|
|
static const char kBrowser[] = "browser";
|
|
|
|
static const char kCopyTree[] = "copyTree";
|
|
|
|
static const char kHTML[] = "html";
|
2024-04-23 15:30:47 +00:00
|
|
|
static const char kLocked[] = "locked";
|
2020-07-16 17:14:54 +00:00
|
|
|
static const char kNative[] = "native";
|
|
|
|
static const char kPage[] = "page";
|
2024-04-23 15:30:47 +00:00
|
|
|
static const char kPDFPrinting[] = "pdfPrinting";
|
2020-07-16 17:14:54 +00:00
|
|
|
static const char kScreenReader[] = "screenreader";
|
|
|
|
static const char kShowOrRefreshTree[] = "showOrRefreshTree";
|
|
|
|
static const char kText[] = "text";
|
2024-04-23 15:30:47 +00:00
|
|
|
static const char kViewsAccessibility[] = "viewsAccessibility";
|
2020-07-16 17:14:54 +00:00
|
|
|
static const char kWeb[] = "web";
|
|
|
|
|
|
|
|
// Possible global flag values
|
|
|
|
static const char kDisabled[] = "disabled";
|
|
|
|
static const char kOff[] = "off";
|
|
|
|
static const char kOn[] = "on";
|
|
|
|
|
2022-06-28 23:40:56 +00:00
|
|
|
base::Value::Dict BuildTargetDescriptor(
|
2020-07-16 17:14:54 +00:00
|
|
|
const GURL& url,
|
|
|
|
const std::string& name,
|
|
|
|
const GURL& favicon_url,
|
|
|
|
int process_id,
|
|
|
|
int routing_id,
|
|
|
|
ui::AXMode accessibility_mode,
|
|
|
|
base::ProcessHandle handle = base::kNullProcessHandle) {
|
2022-06-28 23:40:56 +00:00
|
|
|
base::Value::Dict target_data;
|
|
|
|
target_data.Set(kProcessIdField, process_id);
|
|
|
|
target_data.Set(kRoutingIdField, routing_id);
|
|
|
|
target_data.Set(kUrlField, url.spec());
|
|
|
|
target_data.Set(kNameField, base::EscapeForHTML(name));
|
|
|
|
target_data.Set(kPidField, static_cast<int>(base::GetProcId(handle)));
|
|
|
|
target_data.Set(kFaviconUrlField, favicon_url.spec());
|
|
|
|
target_data.Set(kAccessibilityModeField,
|
2022-12-05 22:59:19 +00:00
|
|
|
static_cast<int>(accessibility_mode.flags()));
|
2022-06-28 23:40:56 +00:00
|
|
|
target_data.Set(kTypeField, kPage);
|
2020-07-16 17:14:54 +00:00
|
|
|
return target_data;
|
|
|
|
}
|
|
|
|
|
2022-06-28 23:40:56 +00:00
|
|
|
base::Value::Dict BuildTargetDescriptor(content::RenderViewHost* rvh) {
|
2020-07-16 17:14:54 +00:00
|
|
|
content::WebContents* web_contents =
|
|
|
|
content::WebContents::FromRenderViewHost(rvh);
|
|
|
|
ui::AXMode accessibility_mode;
|
|
|
|
|
|
|
|
std::string title;
|
|
|
|
GURL url;
|
|
|
|
GURL favicon_url;
|
|
|
|
if (web_contents) {
|
|
|
|
url = web_contents->GetURL();
|
|
|
|
title = base::UTF16ToUTF8(web_contents->GetTitle());
|
|
|
|
content::NavigationController& controller = web_contents->GetController();
|
|
|
|
content::NavigationEntry* entry = controller.GetVisibleEntry();
|
|
|
|
if (entry != nullptr && entry->GetURL().is_valid()) {
|
|
|
|
gfx::Image favicon_image = entry->GetFavicon().image;
|
|
|
|
if (!favicon_image.IsEmpty()) {
|
|
|
|
const SkBitmap* favicon_bitmap = favicon_image.ToSkBitmap();
|
|
|
|
favicon_url = GURL(webui::GetBitmapDataUrl(*favicon_bitmap));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
accessibility_mode = web_contents->GetAccessibilityMode();
|
|
|
|
}
|
|
|
|
|
|
|
|
return BuildTargetDescriptor(url, title, favicon_url,
|
|
|
|
rvh->GetProcess()->GetID(), rvh->GetRoutingID(),
|
|
|
|
accessibility_mode);
|
|
|
|
}
|
|
|
|
|
2022-06-28 23:40:56 +00:00
|
|
|
base::Value::Dict BuildTargetDescriptor(electron::NativeWindow* window) {
|
|
|
|
base::Value::Dict target_data;
|
|
|
|
target_data.Set(kSessionIdField, window->window_id());
|
|
|
|
target_data.Set(kNameField, window->GetTitle());
|
|
|
|
target_data.Set(kTypeField, kBrowser);
|
2020-07-16 17:14:54 +00:00
|
|
|
return target_data;
|
|
|
|
}
|
|
|
|
|
2024-04-23 15:30:47 +00:00
|
|
|
#if defined(USE_AURA)
|
|
|
|
base::Value::Dict BuildTargetDescriptor(views::Widget* widget) {
|
|
|
|
base::Value::Dict widget_data;
|
|
|
|
widget_data.Set(kNameField, widget->widget_delegate()->GetWindowTitle());
|
|
|
|
widget_data.Set(kTypeField, kWidget);
|
2020-07-16 17:14:54 +00:00
|
|
|
|
2024-04-23 15:30:47 +00:00
|
|
|
// Use the Widget's root view ViewAccessibility's unique ID for lookup.
|
|
|
|
int id = widget->GetRootView()->GetViewAccessibility().GetUniqueId().Get();
|
|
|
|
widget_data.Set(kWidgetIdField, id);
|
|
|
|
return widget_data;
|
2020-07-16 17:14:54 +00:00
|
|
|
}
|
2024-04-23 15:30:47 +00:00
|
|
|
#endif // defined(USE_AURA)
|
2020-07-16 17:14:54 +00:00
|
|
|
|
2024-04-23 15:30:47 +00:00
|
|
|
bool ShouldHandleAccessibilityRequestCallback(const std::string& path) {
|
|
|
|
return path == kTargetsDataFile;
|
2020-07-16 17:14:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void HandleAccessibilityRequestCallback(
|
|
|
|
content::BrowserContext* current_context,
|
|
|
|
const std::string& path,
|
|
|
|
content::WebUIDataSource::GotDataCallback callback) {
|
|
|
|
DCHECK(ShouldHandleAccessibilityRequestCallback(path));
|
|
|
|
|
2022-06-28 23:40:56 +00:00
|
|
|
base::Value::Dict data;
|
2024-04-23 15:30:47 +00:00
|
|
|
PrefService* pref =
|
|
|
|
static_cast<electron::ElectronBrowserContext*>(current_context)->prefs();
|
2020-07-16 17:14:54 +00:00
|
|
|
ui::AXMode mode =
|
|
|
|
content::BrowserAccessibilityState::GetInstance()->GetAccessibilityMode();
|
|
|
|
bool is_native_enabled = content::BrowserAccessibilityState::GetInstance()
|
|
|
|
->IsRendererAccessibilityEnabled();
|
|
|
|
bool native = mode.has_mode(ui::AXMode::kNativeAPIs);
|
|
|
|
bool web = mode.has_mode(ui::AXMode::kWebContents);
|
|
|
|
bool text = mode.has_mode(ui::AXMode::kInlineTextBoxes);
|
|
|
|
bool screenreader = mode.has_mode(ui::AXMode::kScreenReader);
|
|
|
|
bool html = mode.has_mode(ui::AXMode::kHTML);
|
2024-04-23 15:30:47 +00:00
|
|
|
bool pdf_printing = mode.has_mode(ui::AXMode::kPDFPrinting);
|
2020-07-16 17:14:54 +00:00
|
|
|
|
|
|
|
// The "native" and "web" flags are disabled if
|
|
|
|
// --disable-renderer-accessibility is set.
|
2022-06-28 23:40:56 +00:00
|
|
|
data.Set(kNative, is_native_enabled ? (native ? kOn : kOff) : kDisabled);
|
|
|
|
data.Set(kWeb, is_native_enabled ? (web ? kOn : kOff) : kDisabled);
|
2020-07-16 17:14:54 +00:00
|
|
|
|
|
|
|
// The "text", "screenreader" and "html" flags are only
|
|
|
|
// meaningful if "web" is enabled.
|
|
|
|
bool is_web_enabled = is_native_enabled && web;
|
2022-06-28 23:40:56 +00:00
|
|
|
data.Set(kText, is_web_enabled ? (text ? kOn : kOff) : kDisabled);
|
|
|
|
data.Set(kScreenReader,
|
|
|
|
is_web_enabled ? (screenreader ? kOn : kOff) : kDisabled);
|
|
|
|
data.Set(kHTML, is_web_enabled ? (html ? kOn : kOff) : kDisabled);
|
2020-07-16 17:14:54 +00:00
|
|
|
|
2024-04-23 15:30:47 +00:00
|
|
|
// The "pdfPrinting" flag is independent of the others.
|
|
|
|
data.Set(kPDFPrinting, pdf_printing ? kOn : kOff);
|
|
|
|
|
|
|
|
// The "Top Level Widgets" section is only relevant if views accessibility is
|
|
|
|
// enabled.
|
|
|
|
data.Set(kViewsAccessibility, features::IsAccessibilityTreeForViewsEnabled());
|
|
|
|
|
|
|
|
std::string pref_api_type =
|
|
|
|
std::string(pref->GetString(prefs::kShownAccessibilityApiType));
|
|
|
|
bool pref_api_type_supported = false;
|
|
|
|
|
|
|
|
std::vector<ui::AXApiType::Type> supported_api_types =
|
|
|
|
content::AXInspectFactory::SupportedApis();
|
|
|
|
base::Value::List supported_api_list;
|
|
|
|
supported_api_list.reserve(supported_api_types.size());
|
|
|
|
for (ui::AXApiType::Type type : supported_api_types) {
|
|
|
|
supported_api_list.Append(std::string_view(type));
|
|
|
|
if (type == ui::AXApiType::From(pref_api_type)) {
|
|
|
|
pref_api_type_supported = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
data.Set(kSupportedApiTypesField, std::move(supported_api_list));
|
2020-07-16 17:14:54 +00:00
|
|
|
|
2024-04-23 15:30:47 +00:00
|
|
|
// If the saved API type is not supported, use the default platform formatter
|
|
|
|
// API type.
|
|
|
|
if (!pref_api_type_supported) {
|
|
|
|
pref_api_type = std::string_view(
|
|
|
|
content::AXInspectFactory::DefaultPlatformFormatterType());
|
|
|
|
}
|
|
|
|
data.Set(kApiTypeField, pref_api_type);
|
2020-07-16 17:14:54 +00:00
|
|
|
|
2024-04-23 15:30:47 +00:00
|
|
|
bool is_mode_locked = !content::BrowserAccessibilityState::GetInstance()
|
|
|
|
->IsAXModeChangeAllowed();
|
|
|
|
data.Set(kLocked, is_mode_locked ? kOn : kOff);
|
2020-07-16 17:14:54 +00:00
|
|
|
|
2024-04-23 15:30:47 +00:00
|
|
|
base::Value::List page_list;
|
|
|
|
std::unique_ptr<content::RenderWidgetHostIterator> widget_iter(
|
2020-07-16 17:14:54 +00:00
|
|
|
content::RenderWidgetHost::GetRenderWidgetHosts());
|
|
|
|
|
2024-04-23 15:30:47 +00:00
|
|
|
while (content::RenderWidgetHost* widget = widget_iter->GetNextHost()) {
|
2020-07-16 17:14:54 +00:00
|
|
|
// Ignore processes that don't have a connection, such as crashed tabs.
|
2024-04-23 15:30:47 +00:00
|
|
|
if (!widget->GetProcess()->IsInitializedAndNotDead()) {
|
2020-07-16 17:14:54 +00:00
|
|
|
continue;
|
2024-04-23 15:30:47 +00:00
|
|
|
}
|
2020-07-16 17:14:54 +00:00
|
|
|
content::RenderViewHost* rvh = content::RenderViewHost::From(widget);
|
2024-04-23 15:30:47 +00:00
|
|
|
if (!rvh) {
|
2020-07-16 17:14:54 +00:00
|
|
|
continue;
|
2024-04-23 15:30:47 +00:00
|
|
|
}
|
2020-07-16 17:14:54 +00:00
|
|
|
content::WebContents* web_contents =
|
|
|
|
content::WebContents::FromRenderViewHost(rvh);
|
|
|
|
content::WebContentsDelegate* delegate = web_contents->GetDelegate();
|
2024-04-23 15:30:47 +00:00
|
|
|
if (!delegate) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (web_contents->GetPrimaryMainFrame()->GetRenderViewHost() != rvh) {
|
2020-07-16 17:14:54 +00:00
|
|
|
continue;
|
2024-04-23 15:30:47 +00:00
|
|
|
}
|
2020-07-16 17:14:54 +00:00
|
|
|
// Ignore views that are never user-visible, like background pages.
|
2024-04-23 15:30:47 +00:00
|
|
|
if (delegate->IsNeverComposited(web_contents)) {
|
2020-07-16 17:14:54 +00:00
|
|
|
continue;
|
2024-04-23 15:30:47 +00:00
|
|
|
}
|
2020-07-16 17:14:54 +00:00
|
|
|
content::BrowserContext* context = rvh->GetProcess()->GetBrowserContext();
|
2024-04-23 15:30:47 +00:00
|
|
|
if (context != current_context) {
|
2020-07-16 17:14:54 +00:00
|
|
|
continue;
|
2024-04-23 15:30:47 +00:00
|
|
|
}
|
2020-07-16 17:14:54 +00:00
|
|
|
|
2022-06-28 23:40:56 +00:00
|
|
|
base::Value::Dict descriptor = BuildTargetDescriptor(rvh);
|
|
|
|
descriptor.Set(kNative, is_native_enabled);
|
2024-04-23 15:30:47 +00:00
|
|
|
descriptor.Set(kScreenReader, is_web_enabled && screenreader);
|
2022-06-28 23:40:56 +00:00
|
|
|
descriptor.Set(kWeb, is_web_enabled);
|
2024-04-23 15:30:47 +00:00
|
|
|
page_list.Append(std::move(descriptor));
|
2020-07-16 17:14:54 +00:00
|
|
|
}
|
2024-04-23 15:30:47 +00:00
|
|
|
data.Set(kPagesField, std::move(page_list));
|
2020-07-16 17:14:54 +00:00
|
|
|
|
2022-06-28 23:40:56 +00:00
|
|
|
base::Value::List window_list;
|
2020-07-16 17:14:54 +00:00
|
|
|
for (auto* window : electron::WindowList::GetWindows()) {
|
2022-06-28 23:40:56 +00:00
|
|
|
window_list.Append(BuildTargetDescriptor(window));
|
2020-07-16 17:14:54 +00:00
|
|
|
}
|
|
|
|
data.Set(kBrowsersField, std::move(window_list));
|
|
|
|
|
2024-04-23 15:30:47 +00:00
|
|
|
base::Value::List widgets_list;
|
|
|
|
#if defined(USE_AURA)
|
|
|
|
if (features::IsAccessibilityTreeForViewsEnabled()) {
|
|
|
|
views::WidgetAXTreeIDMap& manager_map =
|
|
|
|
views::WidgetAXTreeIDMap::GetInstance();
|
|
|
|
const std::vector<views::Widget*> widgets = manager_map.GetWidgets();
|
|
|
|
for (views::Widget* widget : widgets) {
|
|
|
|
widgets_list.Append(BuildTargetDescriptor(widget));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // defined(USE_AURA)
|
|
|
|
data.Set(kWidgetsField, std::move(widgets_list));
|
|
|
|
|
2024-02-02 18:25:58 +00:00
|
|
|
std::move(callback).Run(base::MakeRefCounted<base::RefCountedString>(
|
|
|
|
base::WriteJson(data).value_or("")));
|
2020-07-16 17:14:54 +00:00
|
|
|
}
|
|
|
|
|
2024-04-23 15:30:47 +00:00
|
|
|
std::string RecursiveDumpAXPlatformNodeAsString(
|
|
|
|
ui::AXPlatformNode* node,
|
|
|
|
int indent,
|
|
|
|
const std::vector<ui::AXPropertyFilter>& property_filters) {
|
|
|
|
if (!node) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
std::string str(2 * indent, '+');
|
|
|
|
std::string line = node->GetDelegate()->GetData().ToString();
|
|
|
|
std::vector<std::string> attributes = base::SplitString(
|
|
|
|
line, " ", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
|
|
|
|
for (std::string attribute : attributes) {
|
|
|
|
if (ui::AXTreeFormatter::MatchesPropertyFilters(property_filters, attribute,
|
|
|
|
false)) {
|
|
|
|
str += attribute + " ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
str += "\n";
|
|
|
|
for (size_t i = 0; i < node->GetDelegate()->GetChildCount(); i++) {
|
|
|
|
gfx::NativeViewAccessible child = node->GetDelegate()->ChildAtIndex(i);
|
|
|
|
ui::AXPlatformNode* child_node =
|
|
|
|
ui::AXPlatformNode::FromNativeViewAccessible(child);
|
|
|
|
str += RecursiveDumpAXPlatformNodeAsString(child_node, indent + 1,
|
|
|
|
property_filters);
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add property filters to the property_filters vector for the given property
|
|
|
|
// filter type. The attributes are passed in as a string with each attribute
|
|
|
|
// separated by a space.
|
|
|
|
void AddPropertyFilters(std::vector<ui::AXPropertyFilter>& property_filters,
|
|
|
|
const std::string& attributes,
|
|
|
|
ui::AXPropertyFilter::Type type) {
|
|
|
|
for (const std::string& attribute : base::SplitString(
|
|
|
|
attributes, " ", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY)) {
|
|
|
|
property_filters.emplace_back(attribute, type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsValidJSValue(const std::string* str) {
|
|
|
|
return str && str->length() < 5000U;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string& CheckJSValue(const std::string* str) {
|
|
|
|
CHECK(IsValidJSValue(str));
|
|
|
|
return *str;
|
|
|
|
}
|
|
|
|
|
2020-07-16 17:14:54 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
ElectronAccessibilityUI::ElectronAccessibilityUI(content::WebUI* web_ui)
|
|
|
|
: content::WebUIController(web_ui) {
|
2024-04-23 15:30:47 +00:00
|
|
|
auto* const browser_context = web_ui->GetWebContents()->GetBrowserContext();
|
2020-07-16 17:14:54 +00:00
|
|
|
// Set up the chrome://accessibility source.
|
|
|
|
content::WebUIDataSource* html_source =
|
2023-03-21 01:37:21 +00:00
|
|
|
content::WebUIDataSource::CreateAndAdd(
|
2024-04-23 15:30:47 +00:00
|
|
|
browser_context, chrome::kChromeUIAccessibilityHost);
|
2020-07-16 17:14:54 +00:00
|
|
|
|
|
|
|
// Add required resources.
|
|
|
|
html_source->UseStringsJs();
|
2023-06-09 23:08:36 +00:00
|
|
|
html_source->AddResourcePaths(
|
|
|
|
base::make_span(kAccessibilityResources, kAccessibilityResourcesSize));
|
|
|
|
html_source->SetDefaultResource(IDR_ACCESSIBILITY_ACCESSIBILITY_HTML);
|
2020-07-16 17:14:54 +00:00
|
|
|
html_source->SetRequestFilter(
|
|
|
|
base::BindRepeating(&ShouldHandleAccessibilityRequestCallback),
|
|
|
|
base::BindRepeating(&HandleAccessibilityRequestCallback,
|
2024-04-23 15:30:47 +00:00
|
|
|
browser_context));
|
2023-05-08 08:39:04 +00:00
|
|
|
html_source->OverrideContentSecurityPolicy(
|
|
|
|
network::mojom::CSPDirectiveName::TrustedTypes,
|
|
|
|
"trusted-types parse-html-subset sanitize-inner-html;");
|
|
|
|
|
2020-07-16 17:14:54 +00:00
|
|
|
web_ui->AddMessageHandler(
|
|
|
|
std::make_unique<ElectronAccessibilityUIMessageHandler>());
|
|
|
|
}
|
|
|
|
|
|
|
|
ElectronAccessibilityUI::~ElectronAccessibilityUI() = default;
|
|
|
|
|
|
|
|
ElectronAccessibilityUIMessageHandler::ElectronAccessibilityUIMessageHandler() =
|
|
|
|
default;
|
|
|
|
|
2024-04-23 15:30:47 +00:00
|
|
|
void ElectronAccessibilityUIMessageHandler::GetRequestTypeAndFilters(
|
|
|
|
const base::Value::Dict& data,
|
|
|
|
std::string& request_type,
|
|
|
|
std::string& allow,
|
|
|
|
std::string& allow_empty,
|
|
|
|
std::string& deny) {
|
|
|
|
request_type = CheckJSValue(data.FindString(kRequestTypeField));
|
|
|
|
CHECK(request_type == kShowOrRefreshTree || request_type == kCopyTree);
|
|
|
|
allow = CheckJSValue(data.FindStringByDottedPath("filters.allow"));
|
|
|
|
allow_empty = CheckJSValue(data.FindStringByDottedPath("filters.allowEmpty"));
|
|
|
|
deny = CheckJSValue(data.FindStringByDottedPath("filters.deny"));
|
|
|
|
}
|
|
|
|
|
2020-07-16 17:14:54 +00:00
|
|
|
void ElectronAccessibilityUIMessageHandler::RequestNativeUITree(
|
2022-07-13 21:26:16 +00:00
|
|
|
const base::Value::List& args) {
|
|
|
|
const base::Value::Dict& data = args.front().GetDict();
|
2020-07-16 17:14:54 +00:00
|
|
|
|
2024-04-23 15:30:47 +00:00
|
|
|
std::string request_type, allow, allow_empty, deny;
|
|
|
|
GetRequestTypeAndFilters(data, request_type, allow, allow_empty, deny);
|
2020-07-16 17:14:54 +00:00
|
|
|
|
2024-04-23 15:30:47 +00:00
|
|
|
int window_id = *data.FindInt(kSessionIdField);
|
2020-07-16 17:14:54 +00:00
|
|
|
|
|
|
|
AllowJavascript();
|
|
|
|
|
2020-10-16 01:30:41 +00:00
|
|
|
std::vector<ui::AXPropertyFilter> property_filters;
|
2024-04-23 15:30:47 +00:00
|
|
|
AddPropertyFilters(property_filters, allow, ui::AXPropertyFilter::ALLOW);
|
|
|
|
AddPropertyFilters(property_filters, allow_empty,
|
2020-10-16 01:30:41 +00:00
|
|
|
ui::AXPropertyFilter::ALLOW_EMPTY);
|
2024-04-23 15:30:47 +00:00
|
|
|
AddPropertyFilters(property_filters, deny, ui::AXPropertyFilter::DENY);
|
2020-07-16 17:14:54 +00:00
|
|
|
|
|
|
|
for (auto* window : electron::WindowList::GetWindows()) {
|
|
|
|
if (window->window_id() == window_id) {
|
2022-06-28 23:40:56 +00:00
|
|
|
base::Value::Dict result = BuildTargetDescriptor(window);
|
2020-07-16 17:14:54 +00:00
|
|
|
gfx::NativeWindow native_window = window->GetNativeWindow();
|
|
|
|
ui::AXPlatformNode* node =
|
|
|
|
ui::AXPlatformNode::FromNativeWindow(native_window);
|
2024-04-23 15:30:47 +00:00
|
|
|
result.Set(kTreeField, RecursiveDumpAXPlatformNodeAsString(
|
|
|
|
node, 0, property_filters));
|
|
|
|
FireWebUIListener(request_type, result);
|
2020-07-16 17:14:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// No browser with the specified |id| was found.
|
2022-06-28 23:40:56 +00:00
|
|
|
base::Value::Dict result;
|
|
|
|
result.Set(kSessionIdField, window_id);
|
|
|
|
result.Set(kTypeField, kBrowser);
|
|
|
|
result.Set(kErrorField, "Window no longer exists.");
|
2024-04-23 15:30:47 +00:00
|
|
|
FireWebUIListener(request_type, result);
|
2020-07-16 17:14:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ElectronAccessibilityUIMessageHandler::RegisterMessages() {
|
|
|
|
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
|
|
|
|
2022-07-13 21:26:16 +00:00
|
|
|
web_ui()->RegisterMessageCallback(
|
2020-07-16 17:14:54 +00:00
|
|
|
"toggleAccessibility",
|
2024-01-31 23:04:13 +00:00
|
|
|
base::BindRepeating(
|
|
|
|
&AccessibilityUIMessageHandler::ToggleAccessibilityForWebContents,
|
|
|
|
base::Unretained(this)));
|
2022-07-13 21:26:16 +00:00
|
|
|
web_ui()->RegisterMessageCallback(
|
2020-07-16 17:14:54 +00:00
|
|
|
"setGlobalFlag",
|
|
|
|
base::BindRepeating(&AccessibilityUIMessageHandler::SetGlobalFlag,
|
|
|
|
base::Unretained(this)));
|
2024-04-23 15:30:47 +00:00
|
|
|
web_ui()->RegisterMessageCallback(
|
|
|
|
"setGlobalString",
|
|
|
|
base::BindRepeating(&AccessibilityUIMessageHandler::SetGlobalString,
|
|
|
|
base::Unretained(this)));
|
2022-07-13 21:26:16 +00:00
|
|
|
web_ui()->RegisterMessageCallback(
|
2020-07-16 17:14:54 +00:00
|
|
|
"requestWebContentsTree",
|
|
|
|
base::BindRepeating(
|
|
|
|
&AccessibilityUIMessageHandler::RequestWebContentsTree,
|
|
|
|
base::Unretained(this)));
|
2022-07-13 21:26:16 +00:00
|
|
|
web_ui()->RegisterMessageCallback(
|
2020-07-16 17:14:54 +00:00
|
|
|
"requestNativeUITree",
|
|
|
|
base::BindRepeating(
|
|
|
|
&ElectronAccessibilityUIMessageHandler::RequestNativeUITree,
|
|
|
|
base::Unretained(this)));
|
2024-04-23 15:30:47 +00:00
|
|
|
#if defined(USE_AURA)
|
|
|
|
web_ui()->RegisterMessageCallback(
|
|
|
|
"requestWidgetsTree",
|
|
|
|
base::BindRepeating(&AccessibilityUIMessageHandler::RequestWidgetsTree,
|
|
|
|
base::Unretained(this)));
|
|
|
|
#endif
|
2022-07-13 21:26:16 +00:00
|
|
|
web_ui()->RegisterMessageCallback(
|
2020-07-16 17:14:54 +00:00
|
|
|
"requestAccessibilityEvents",
|
|
|
|
base::BindRepeating(
|
|
|
|
&AccessibilityUIMessageHandler::RequestAccessibilityEvents,
|
|
|
|
base::Unretained(this)));
|
|
|
|
}
|
2024-04-23 15:30:47 +00:00
|
|
|
|
|
|
|
// static
|
|
|
|
void ElectronAccessibilityUIMessageHandler::RegisterPrefs(
|
|
|
|
user_prefs::PrefRegistrySyncable* registry) {
|
|
|
|
const std::string_view default_api_type =
|
|
|
|
std::string_view(ui::AXApiType::Type(ui::AXApiType::kBlink));
|
|
|
|
registry->RegisterStringPref(prefs::kShownAccessibilityApiType,
|
|
|
|
std::string(default_api_type));
|
|
|
|
}
|