| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/accessibility/browser_accessibility_state_impl.h" | 5 #include "content/browser/accessibility/browser_accessibility_state_impl.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/timer/timer.h" | 9 #include "base/timer/timer.h" |
| 10 #include "content/browser/accessibility/accessibility_mode_helper.h" |
| 10 #include "content/browser/renderer_host/render_widget_host_impl.h" | 11 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 11 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 12 #include "content/public/browser/render_process_host.h" | 13 #include "content/public/browser/render_process_host.h" |
| 13 #include "content/public/browser/render_widget_host_iterator.h" | 14 #include "content/public/browser/render_widget_host_iterator.h" |
| 14 #include "content/public/common/content_switches.h" | 15 #include "content/public/common/content_switches.h" |
| 15 #include "ui/gfx/sys_color_change_listener.h" | 16 #include "ui/gfx/sys_color_change_listener.h" |
| 16 | 17 |
| 17 #if defined(OS_WIN) | 18 #if defined(OS_WIN) |
| 18 #include "base/win/windows_version.h" | 19 #include "base/win/windows_version.h" |
| 19 #endif | 20 #endif |
| (...skipping 10 matching lines...) Expand all Loading... |
| 30 | 31 |
| 31 // static | 32 // static |
| 32 BrowserAccessibilityStateImpl* BrowserAccessibilityStateImpl::GetInstance() { | 33 BrowserAccessibilityStateImpl* BrowserAccessibilityStateImpl::GetInstance() { |
| 33 return Singleton<BrowserAccessibilityStateImpl, | 34 return Singleton<BrowserAccessibilityStateImpl, |
| 34 LeakySingletonTraits<BrowserAccessibilityStateImpl> >::get(); | 35 LeakySingletonTraits<BrowserAccessibilityStateImpl> >::get(); |
| 35 } | 36 } |
| 36 | 37 |
| 37 BrowserAccessibilityStateImpl::BrowserAccessibilityStateImpl() | 38 BrowserAccessibilityStateImpl::BrowserAccessibilityStateImpl() |
| 38 : BrowserAccessibilityState(), | 39 : BrowserAccessibilityState(), |
| 39 accessibility_mode_(AccessibilityModeOff) { | 40 accessibility_mode_(AccessibilityModeOff) { |
| 40 #if defined(OS_WIN) | 41 ResetAccessibilityModeValue(); |
| 41 // On Windows 8, always enable accessibility for editable text controls | |
| 42 // so we can show the virtual keyboard when one is enabled. | |
| 43 if (base::win::GetVersion() >= base::win::VERSION_WIN8 && | |
| 44 !CommandLine::ForCurrentProcess()->HasSwitch( | |
| 45 switches::kDisableRendererAccessibility)) { | |
| 46 accessibility_mode_ = AccessibilityModeEditableTextOnly; | |
| 47 } | |
| 48 #endif // defined(OS_WIN) | |
| 49 | |
| 50 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 51 switches::kForceRendererAccessibility)) { | |
| 52 accessibility_mode_ = AccessibilityModeComplete; | |
| 53 } | |
| 54 | |
| 55 #if defined(OS_WIN) | 42 #if defined(OS_WIN) |
| 56 // On Windows, UpdateHistograms calls some system functions with unknown | 43 // On Windows, UpdateHistograms calls some system functions with unknown |
| 57 // runtime, so call it on the file thread to ensure there's no jank. | 44 // runtime, so call it on the file thread to ensure there's no jank. |
| 58 // Everything in that method must be safe to call on another thread. | 45 // Everything in that method must be safe to call on another thread. |
| 59 BrowserThread::ID update_histogram_thread = BrowserThread::FILE; | 46 BrowserThread::ID update_histogram_thread = BrowserThread::FILE; |
| 60 #else | 47 #else |
| 61 // On all other platforms, UpdateHistograms should be called on the main | 48 // On all other platforms, UpdateHistograms should be called on the main |
| 62 // thread. | 49 // thread. |
| 63 BrowserThread::ID update_histogram_thread = BrowserThread::UI; | 50 BrowserThread::ID update_histogram_thread = BrowserThread::UI; |
| 64 #endif | 51 #endif |
| 65 | 52 |
| 66 // We need to AddRef() the leaky singleton so that Bind doesn't | 53 // We need to AddRef() the leaky singleton so that Bind doesn't |
| 67 // delete it prematurely. | 54 // delete it prematurely. |
| 68 AddRef(); | 55 AddRef(); |
| 69 BrowserThread::PostDelayedTask( | 56 BrowserThread::PostDelayedTask( |
| 70 update_histogram_thread, FROM_HERE, | 57 update_histogram_thread, FROM_HERE, |
| 71 base::Bind(&BrowserAccessibilityStateImpl::UpdateHistograms, this), | 58 base::Bind(&BrowserAccessibilityStateImpl::UpdateHistograms, this), |
| 72 base::TimeDelta::FromSeconds(kAccessibilityHistogramDelaySecs)); | 59 base::TimeDelta::FromSeconds(kAccessibilityHistogramDelaySecs)); |
| 73 } | 60 } |
| 74 | 61 |
| 75 BrowserAccessibilityStateImpl::~BrowserAccessibilityStateImpl() { | 62 BrowserAccessibilityStateImpl::~BrowserAccessibilityStateImpl() { |
| 76 } | 63 } |
| 77 | 64 |
| 78 void BrowserAccessibilityStateImpl::OnScreenReaderDetected() { | 65 void BrowserAccessibilityStateImpl::OnScreenReaderDetected() { |
| 79 if (CommandLine::ForCurrentProcess()->HasSwitch( | 66 AddAccessibilityMode(AccessibilityModeComplete); |
| 80 switches::kDisableRendererAccessibility)) { | |
| 81 return; | |
| 82 } | |
| 83 SetAccessibilityMode(AccessibilityModeComplete); | |
| 84 } | 67 } |
| 85 | 68 |
| 86 void BrowserAccessibilityStateImpl::EnableAccessibility() { | 69 void BrowserAccessibilityStateImpl::EnableAccessibility() { |
| 87 // We may want to do something different with this later. | 70 // We may want to do something different with this later. |
| 88 SetAccessibilityMode(AccessibilityModeComplete); | 71 AddAccessibilityMode(AccessibilityModeComplete); |
| 89 } | 72 } |
| 90 | 73 |
| 91 void BrowserAccessibilityStateImpl::DisableAccessibility() { | 74 void BrowserAccessibilityStateImpl::DisableAccessibility() { |
| 92 SetAccessibilityMode(AccessibilityModeOff); | 75 ResetAccessibilityMode(); |
| 76 } |
| 77 |
| 78 void BrowserAccessibilityStateImpl::ResetAccessibilityModeValue() { |
| 79 accessibility_mode_ = AccessibilityModeOff; |
| 80 #if defined(OS_WIN) |
| 81 // On Windows 8, always enable accessibility for editable text controls |
| 82 // so we can show the virtual keyboard when one is enabled. |
| 83 if (base::win::GetVersion() >= base::win::VERSION_WIN8 && |
| 84 !CommandLine::ForCurrentProcess()->HasSwitch( |
| 85 switches::kDisableRendererAccessibility)) { |
| 86 accessibility_mode_ = AccessibilityModeEditableTextOnly; |
| 87 } |
| 88 #endif // defined(OS_WIN) |
| 89 |
| 90 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 91 switches::kForceRendererAccessibility)) { |
| 92 accessibility_mode_ = AccessibilityModeComplete; |
| 93 } |
| 94 } |
| 95 |
| 96 void BrowserAccessibilityStateImpl::ResetAccessibilityMode() { |
| 97 ResetAccessibilityModeValue(); |
| 98 |
| 99 // Iterate over all RenderWidgetHosts, even swapped out ones in case |
| 100 // they become active again. |
| 101 scoped_ptr<RenderWidgetHostIterator> widgets( |
| 102 RenderWidgetHostImpl::GetAllRenderWidgetHosts()); |
| 103 while (RenderWidgetHost* widget = widgets->GetNextHost()) { |
| 104 // Ignore processes that don't have a connection, such as crashed tabs. |
| 105 if (!widget->GetProcess()->HasConnection()) |
| 106 continue; |
| 107 if (!widget->IsRenderView()) |
| 108 continue; |
| 109 |
| 110 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); |
| 111 rwhi->ResetAccessibilityMode(); |
| 112 } |
| 93 } | 113 } |
| 94 | 114 |
| 95 bool BrowserAccessibilityStateImpl::IsAccessibleBrowser() { | 115 bool BrowserAccessibilityStateImpl::IsAccessibleBrowser() { |
| 96 return (accessibility_mode_ == AccessibilityModeComplete); | 116 return ((accessibility_mode_ & AccessibilityModeComplete) == |
| 117 AccessibilityModeComplete); |
| 97 } | 118 } |
| 98 | 119 |
| 99 void BrowserAccessibilityStateImpl::AddHistogramCallback( | 120 void BrowserAccessibilityStateImpl::AddHistogramCallback( |
| 100 base::Closure callback) { | 121 base::Closure callback) { |
| 101 histogram_callbacks_.push_back(callback); | 122 histogram_callbacks_.push_back(callback); |
| 102 } | 123 } |
| 103 | 124 |
| 104 void BrowserAccessibilityStateImpl::UpdateHistogramsForTesting() { | 125 void BrowserAccessibilityStateImpl::UpdateHistogramsForTesting() { |
| 105 UpdateHistograms(); | 126 UpdateHistograms(); |
| 106 } | 127 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 117 UMA_HISTOGRAM_BOOLEAN("Accessibility.ManuallyEnabled", | 138 UMA_HISTOGRAM_BOOLEAN("Accessibility.ManuallyEnabled", |
| 118 CommandLine::ForCurrentProcess()->HasSwitch( | 139 CommandLine::ForCurrentProcess()->HasSwitch( |
| 119 switches::kForceRendererAccessibility)); | 140 switches::kForceRendererAccessibility)); |
| 120 } | 141 } |
| 121 | 142 |
| 122 #if !defined(OS_WIN) | 143 #if !defined(OS_WIN) |
| 123 void BrowserAccessibilityStateImpl::UpdatePlatformSpecificHistograms() { | 144 void BrowserAccessibilityStateImpl::UpdatePlatformSpecificHistograms() { |
| 124 } | 145 } |
| 125 #endif | 146 #endif |
| 126 | 147 |
| 127 void BrowserAccessibilityStateImpl::SetAccessibilityMode( | 148 void BrowserAccessibilityStateImpl::AddAccessibilityMode( |
| 128 AccessibilityMode mode) { | 149 AccessibilityMode mode) { |
| 129 if (accessibility_mode_ == mode) | 150 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 151 switches::kDisableRendererAccessibility)) { |
| 130 return; | 152 return; |
| 131 accessibility_mode_ = mode; | 153 } |
| 132 | 154 |
| 155 accessibility_mode_ = |
| 156 content::AddAccessibilityModeTo(accessibility_mode_, mode); |
| 157 |
| 158 AddOrRemoveFromRenderWidgets(mode, true); |
| 159 } |
| 160 |
| 161 void BrowserAccessibilityStateImpl::RemoveAccessibilityMode( |
| 162 AccessibilityMode mode) { |
| 163 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 164 switches::kForceRendererAccessibility) && |
| 165 mode == AccessibilityModeComplete) { |
| 166 return; |
| 167 } |
| 168 |
| 169 accessibility_mode_ = |
| 170 content::RemoveAccessibilityModeFrom(accessibility_mode_, mode); |
| 171 |
| 172 AddOrRemoveFromRenderWidgets(mode, false); |
| 173 } |
| 174 |
| 175 void BrowserAccessibilityStateImpl::AddOrRemoveFromRenderWidgets( |
| 176 AccessibilityMode mode, |
| 177 bool add) { |
| 133 // Iterate over all RenderWidgetHosts, even swapped out ones in case | 178 // Iterate over all RenderWidgetHosts, even swapped out ones in case |
| 134 // they become active again. | 179 // they become active again. |
| 135 scoped_ptr<RenderWidgetHostIterator> widgets( | 180 scoped_ptr<RenderWidgetHostIterator> widgets( |
| 136 RenderWidgetHostImpl::GetAllRenderWidgetHosts()); | 181 RenderWidgetHostImpl::GetAllRenderWidgetHosts()); |
| 137 while (RenderWidgetHost* widget = widgets->GetNextHost()) { | 182 while (RenderWidgetHost* widget = widgets->GetNextHost()) { |
| 138 // Ignore processes that don't have a connection, such as crashed tabs. | 183 // Ignore processes that don't have a connection, such as crashed tabs. |
| 139 if (!widget->GetProcess()->HasConnection()) | 184 if (!widget->GetProcess()->HasConnection()) |
| 140 continue; | 185 continue; |
| 141 if (!widget->IsRenderView()) | 186 if (!widget->IsRenderView()) |
| 142 continue; | 187 continue; |
| 143 | 188 |
| 144 RenderWidgetHostImpl::From(widget)->SetAccessibilityMode(mode); | 189 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); |
| 190 if (add) |
| 191 rwhi->AddAccessibilityMode(mode); |
| 192 else |
| 193 rwhi->RemoveAccessibilityMode(mode); |
| 145 } | 194 } |
| 146 } | 195 } |
| 147 | 196 |
| 148 } // namespace content | 197 } // namespace content |
| OLD | NEW |