in shell/browser/ui/webui/accessibility_ui.cc [213:305]
void HandleAccessibilityRequestCallback(
content::BrowserContext* current_context,
const std::string& path,
content::WebUIDataSource::GotDataCallback callback) {
DCHECK(ShouldHandleAccessibilityRequestCallback(path));
base::DictionaryValue data;
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);
bool pdf = mode.has_mode(ui::AXMode::kPDF);
// The "native" and "web" flags are disabled if
// --disable-renderer-accessibility is set.
data.SetString(kNative,
is_native_enabled ? (native ? kOn : kOff) : kDisabled);
data.SetString(kWeb, is_native_enabled ? (web ? kOn : kOff) : kDisabled);
// The "text", "screenreader" and "html" flags are only
// meaningful if "web" is enabled.
bool is_web_enabled = is_native_enabled && web;
data.SetString(kText, is_web_enabled ? (text ? kOn : kOff) : kDisabled);
data.SetString(kScreenReader,
is_web_enabled ? (screenreader ? kOn : kOff) : kDisabled);
data.SetString(kHTML, is_web_enabled ? (html ? kOn : kOff) : kDisabled);
// TODO(codebytere): enable use of this flag.
//
// 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. Since this is so closely tied into user
// prefs and causes bugs, we're disabling it for now.
bool are_accessibility_image_labels_enabled = is_web_enabled;
data.SetString(kLabelImages, kDisabled);
// The "pdf" flag is independent of the others.
data.SetString(kPDF, pdf ? kOn : kOff);
// Always dump the Accessibility tree.
data.SetString(kInternal, kOn);
auto rvh_list = std::make_unique<base::ListValue>();
std::unique_ptr<content::RenderWidgetHostIterator> widgets(
content::RenderWidgetHost::GetRenderWidgetHosts());
while (content::RenderWidgetHost* widget = widgets->GetNextHost()) {
// Ignore processes that don't have a connection, such as crashed tabs.
if (!widget->GetProcess()->IsInitializedAndNotDead())
continue;
content::RenderViewHost* rvh = content::RenderViewHost::From(widget);
if (!rvh)
continue;
content::WebContents* web_contents =
content::WebContents::FromRenderViewHost(rvh);
content::WebContentsDelegate* delegate = web_contents->GetDelegate();
if (!delegate)
continue;
// Ignore views that are never user-visible, like background pages.
if (delegate->IsNeverComposited(web_contents))
continue;
content::BrowserContext* context = rvh->GetProcess()->GetBrowserContext();
if (context != current_context)
continue;
std::unique_ptr<base::DictionaryValue> descriptor =
BuildTargetDescriptor(rvh);
descriptor->SetBoolean(kNative, is_native_enabled);
descriptor->SetBoolean(kWeb, is_web_enabled);
descriptor->SetBoolean(kLabelImages,
are_accessibility_image_labels_enabled);
rvh_list->Append(std::move(descriptor));
}
data.Set(kPagesField, std::move(rvh_list));
auto window_list = std::make_unique<base::ListValue>();
for (auto* window : electron::WindowList::GetWindows()) {
window_list->Append(BuildTargetDescriptor(window));
}
data.Set(kBrowsersField, std::move(window_list));
std::string json_string;
base::JSONWriter::Write(data, &json_string);
std::move(callback).Run(base::RefCountedString::TakeString(&json_string));
}