Chromium Code Reviews| 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 ResetAccessibilityMode(); |
| 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::ResetAccessibilityMode() { | |
| 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)) { | |
|
David Tseng
2014/02/06 19:13:44
We should remove one of
switches::kDisableRenderer
aboxhall
2014/02/06 21:04:12
Possibly; do you want me to do it in this CL?
| |
| 92 accessibility_mode_ = AccessibilityModeComplete; | |
| 93 } | |
| 94 | |
| 95 // Iterate over all RenderWidgetHosts, even swapped out ones in case | |
| 96 // they become active again. | |
| 97 scoped_ptr<RenderWidgetHostIterator> widgets( | |
| 98 RenderWidgetHostImpl::GetAllRenderWidgetHosts()); | |
| 99 while (RenderWidgetHost* widget = widgets->GetNextHost()) { | |
| 100 // Ignore processes that don't have a connection, such as crashed tabs. | |
| 101 if (!widget->GetProcess()->HasConnection()) | |
| 102 continue; | |
| 103 if (!widget->IsRenderView()) | |
| 104 continue; | |
| 105 | |
| 106 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); | |
| 107 rwhi->ResetAccessibilityMode(); | |
| 108 } | |
| 93 } | 109 } |
| 94 | 110 |
| 95 bool BrowserAccessibilityStateImpl::IsAccessibleBrowser() { | 111 bool BrowserAccessibilityStateImpl::IsAccessibleBrowser() { |
| 96 return (accessibility_mode_ == AccessibilityModeComplete); | 112 return ((accessibility_mode_ & AccessibilityModeComplete) == |
| 113 AccessibilityModeComplete); | |
| 97 } | 114 } |
| 98 | 115 |
| 99 void BrowserAccessibilityStateImpl::AddHistogramCallback( | 116 void BrowserAccessibilityStateImpl::AddHistogramCallback( |
| 100 base::Closure callback) { | 117 base::Closure callback) { |
| 101 histogram_callbacks_.push_back(callback); | 118 histogram_callbacks_.push_back(callback); |
| 102 } | 119 } |
| 103 | 120 |
| 104 void BrowserAccessibilityStateImpl::UpdateHistogramsForTesting() { | 121 void BrowserAccessibilityStateImpl::UpdateHistogramsForTesting() { |
| 105 UpdateHistograms(); | 122 UpdateHistograms(); |
| 106 } | 123 } |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 117 UMA_HISTOGRAM_BOOLEAN("Accessibility.ManuallyEnabled", | 134 UMA_HISTOGRAM_BOOLEAN("Accessibility.ManuallyEnabled", |
| 118 CommandLine::ForCurrentProcess()->HasSwitch( | 135 CommandLine::ForCurrentProcess()->HasSwitch( |
| 119 switches::kForceRendererAccessibility)); | 136 switches::kForceRendererAccessibility)); |
| 120 } | 137 } |
| 121 | 138 |
| 122 #if !defined(OS_WIN) | 139 #if !defined(OS_WIN) |
| 123 void BrowserAccessibilityStateImpl::UpdatePlatformSpecificHistograms() { | 140 void BrowserAccessibilityStateImpl::UpdatePlatformSpecificHistograms() { |
| 124 } | 141 } |
| 125 #endif | 142 #endif |
| 126 | 143 |
| 127 void BrowserAccessibilityStateImpl::SetAccessibilityMode( | 144 void BrowserAccessibilityStateImpl::AddAccessibilityMode( |
| 128 AccessibilityMode mode) { | 145 AccessibilityMode mode) { |
| 129 if (accessibility_mode_ == mode) | 146 if ((accessibility_mode_ & mode) == mode) |
| 130 return; | 147 return; |
| 131 accessibility_mode_ = mode; | |
| 132 | 148 |
| 149 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 150 switches::kDisableRendererAccessibility)) { | |
| 151 return; | |
| 152 } | |
| 153 | |
| 154 accessibility_mode_ = | |
| 155 content::AddAccessibilityModeTo(accessibility_mode_, mode); | |
| 156 | |
| 157 AddOrRemoveFromRenderWidgets(mode, true); | |
| 158 } | |
| 159 | |
| 160 void BrowserAccessibilityStateImpl::RemoveAccessibilityMode( | |
| 161 AccessibilityMode mode) { | |
| 162 if ((accessibility_mode_ ^ mode) == mode) | |
| 163 return; | |
| 164 | |
| 165 accessibility_mode_ = | |
| 166 content::RemoveAccessibilityModeFrom(accessibility_mode_, mode); | |
|
David Tseng
2014/02/06 19:13:44
Seems like the command line switches related to fo
aboxhall
2014/02/06 21:04:12
Done.
| |
| 167 | |
| 168 AddOrRemoveFromRenderWidgets(mode, false); | |
| 169 } | |
| 170 | |
| 171 void BrowserAccessibilityStateImpl::AddOrRemoveFromRenderWidgets( | |
| 172 AccessibilityMode mode, | |
| 173 bool add) { | |
| 133 // Iterate over all RenderWidgetHosts, even swapped out ones in case | 174 // Iterate over all RenderWidgetHosts, even swapped out ones in case |
| 134 // they become active again. | 175 // they become active again. |
| 135 scoped_ptr<RenderWidgetHostIterator> widgets( | 176 scoped_ptr<RenderWidgetHostIterator> widgets( |
| 136 RenderWidgetHostImpl::GetAllRenderWidgetHosts()); | 177 RenderWidgetHostImpl::GetAllRenderWidgetHosts()); |
| 137 while (RenderWidgetHost* widget = widgets->GetNextHost()) { | 178 while (RenderWidgetHost* widget = widgets->GetNextHost()) { |
| 138 // Ignore processes that don't have a connection, such as crashed tabs. | 179 // Ignore processes that don't have a connection, such as crashed tabs. |
| 139 if (!widget->GetProcess()->HasConnection()) | 180 if (!widget->GetProcess()->HasConnection()) |
| 140 continue; | 181 continue; |
| 141 if (!widget->IsRenderView()) | 182 if (!widget->IsRenderView()) |
| 142 continue; | 183 continue; |
| 143 | 184 |
| 144 RenderWidgetHostImpl::From(widget)->SetAccessibilityMode(mode); | 185 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); |
| 186 if (add) | |
| 187 rwhi->AddAccessibilityMode(mode); | |
| 188 else | |
| 189 rwhi->RemoveAccessibilityMode(mode); | |
| 145 } | 190 } |
| 146 } | 191 } |
| 147 | 192 |
| 148 } // namespace content | 193 } // namespace content |
| OLD | NEW |