This source file includes following definitions.
- GetInstance
- GetInstance
- accessibility_mode_
- OnScreenReaderDetected
- EnableAccessibility
- DisableAccessibility
- ResetAccessibilityModeValue
- ResetAccessibilityMode
- IsAccessibleBrowser
- AddHistogramCallback
- UpdateHistogramsForTesting
- UpdateHistograms
- UpdatePlatformSpecificHistograms
- AddAccessibilityMode
- RemoveAccessibilityMode
- AddOrRemoveFromRenderWidgets
#include "content/browser/accessibility/browser_accessibility_state_impl.h"
#include "base/command_line.h"
#include "base/metrics/histogram.h"
#include "base/timer/timer.h"
#include "content/browser/accessibility/accessibility_mode_helper.h"
#include "content/browser/renderer_host/render_widget_host_impl.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_widget_host_iterator.h"
#include "content/public/common/content_switches.h"
#include "ui/gfx/sys_color_change_listener.h"
#if defined(OS_WIN)
#include "base/win/windows_version.h"
#endif
namespace content {
static const int kAccessibilityHistogramDelaySecs = 45;
BrowserAccessibilityState* BrowserAccessibilityState::GetInstance() {
return BrowserAccessibilityStateImpl::GetInstance();
}
BrowserAccessibilityStateImpl* BrowserAccessibilityStateImpl::GetInstance() {
return Singleton<BrowserAccessibilityStateImpl,
LeakySingletonTraits<BrowserAccessibilityStateImpl> >::get();
}
BrowserAccessibilityStateImpl::BrowserAccessibilityStateImpl()
: BrowserAccessibilityState(),
accessibility_mode_(AccessibilityModeOff) {
ResetAccessibilityModeValue();
#if defined(OS_WIN)
BrowserThread::ID update_histogram_thread = BrowserThread::FILE;
#else
BrowserThread::ID update_histogram_thread = BrowserThread::UI;
#endif
AddRef();
BrowserThread::PostDelayedTask(
update_histogram_thread, FROM_HERE,
base::Bind(&BrowserAccessibilityStateImpl::UpdateHistograms, this),
base::TimeDelta::FromSeconds(kAccessibilityHistogramDelaySecs));
}
BrowserAccessibilityStateImpl::~BrowserAccessibilityStateImpl() {
}
void BrowserAccessibilityStateImpl::OnScreenReaderDetected() {
if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableRendererAccessibility)) {
return;
}
EnableAccessibility();
}
void BrowserAccessibilityStateImpl::EnableAccessibility() {
AddAccessibilityMode(AccessibilityModeComplete);
}
void BrowserAccessibilityStateImpl::DisableAccessibility() {
ResetAccessibilityMode();
}
void BrowserAccessibilityStateImpl::ResetAccessibilityModeValue() {
accessibility_mode_ = AccessibilityModeOff;
#if defined(OS_WIN)
if (base::win::GetVersion() >= base::win::VERSION_WIN8 &&
!CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableRendererAccessibility)) {
accessibility_mode_ = AccessibilityModeEditableTextOnly;
}
#endif
if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kForceRendererAccessibility)) {
accessibility_mode_ = AccessibilityModeComplete;
}
}
void BrowserAccessibilityStateImpl::ResetAccessibilityMode() {
ResetAccessibilityModeValue();
scoped_ptr<RenderWidgetHostIterator> widgets(
RenderWidgetHostImpl::GetAllRenderWidgetHosts());
while (RenderWidgetHost* widget = widgets->GetNextHost()) {
if (!widget->GetProcess()->HasConnection())
continue;
if (!widget->IsRenderView())
continue;
RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget);
rwhi->ResetAccessibilityMode();
}
}
bool BrowserAccessibilityStateImpl::IsAccessibleBrowser() {
return ((accessibility_mode_ & AccessibilityModeComplete) ==
AccessibilityModeComplete);
}
void BrowserAccessibilityStateImpl::AddHistogramCallback(
base::Closure callback) {
histogram_callbacks_.push_back(callback);
}
void BrowserAccessibilityStateImpl::UpdateHistogramsForTesting() {
UpdateHistograms();
}
void BrowserAccessibilityStateImpl::UpdateHistograms() {
UpdatePlatformSpecificHistograms();
for (size_t i = 0; i < histogram_callbacks_.size(); ++i)
histogram_callbacks_[i].Run();
UMA_HISTOGRAM_BOOLEAN("Accessibility.State", IsAccessibleBrowser());
UMA_HISTOGRAM_BOOLEAN("Accessibility.InvertedColors",
gfx::IsInvertedColorScheme());
UMA_HISTOGRAM_BOOLEAN("Accessibility.ManuallyEnabled",
CommandLine::ForCurrentProcess()->HasSwitch(
switches::kForceRendererAccessibility));
}
#if !defined(OS_WIN)
void BrowserAccessibilityStateImpl::UpdatePlatformSpecificHistograms() {
}
#endif
void BrowserAccessibilityStateImpl::AddAccessibilityMode(
AccessibilityMode mode) {
if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableRendererAccessibility)) {
return;
}
accessibility_mode_ =
content::AddAccessibilityModeTo(accessibility_mode_, mode);
AddOrRemoveFromRenderWidgets(mode, true);
}
void BrowserAccessibilityStateImpl::RemoveAccessibilityMode(
AccessibilityMode mode) {
if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kForceRendererAccessibility) &&
mode == AccessibilityModeComplete) {
return;
}
accessibility_mode_ =
content::RemoveAccessibilityModeFrom(accessibility_mode_, mode);
AddOrRemoveFromRenderWidgets(mode, false);
}
void BrowserAccessibilityStateImpl::AddOrRemoveFromRenderWidgets(
AccessibilityMode mode,
bool add) {
scoped_ptr<RenderWidgetHostIterator> widgets(
RenderWidgetHostImpl::GetAllRenderWidgetHosts());
while (RenderWidgetHost* widget = widgets->GetNextHost()) {
if (!widget->GetProcess()->HasConnection())
continue;
if (!widget->IsRenderView())
continue;
RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget);
if (add)
rwhi->AddAccessibilityMode(mode);
else
rwhi->RemoveAccessibilityMode(mode);
}
}
}