| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/ui/aura/accessibility/automation_manager_aura.h" | 5 #include "chrome/browser/ui/aura/accessibility/automation_manager_aura.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
| 12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/extensions/api/automation_internal/automation_event_rou
ter.h" | 14 #include "chrome/browser/extensions/api/automation_internal/automation_event_rou
ter.h" |
| 15 #include "chrome/browser/profiles/profile_manager.h" | 15 #include "chrome/browser/profiles/profile_manager.h" |
| 16 #include "chrome/common/extensions/chrome_extension_messages.h" | 16 #include "chrome/common/extensions/chrome_extension_messages.h" |
| 17 #include "content/public/browser/ax_event_notification_details.h" | 17 #include "content/public/browser/ax_event_notification_details.h" |
| 18 #include "content/public/browser/browser_context.h" | 18 #include "content/public/browser/browser_context.h" |
| 19 #include "ui/aura/window.h" | 19 #include "ui/aura/window.h" |
| 20 #include "ui/views/accessibility/ax_aura_obj_cache.h" | |
| 21 #include "ui/views/accessibility/ax_aura_obj_wrapper.h" | 20 #include "ui/views/accessibility/ax_aura_obj_wrapper.h" |
| 22 #include "ui/views/view.h" | 21 #include "ui/views/view.h" |
| 23 #include "ui/views/widget/widget.h" | 22 #include "ui/views/widget/widget.h" |
| 24 | 23 |
| 25 #if defined(OS_CHROMEOS) | 24 #if defined(OS_CHROMEOS) |
| 26 #include "ash/wm/window_util.h" // nogncheck | 25 #include "ash/wm/window_util.h" // nogncheck |
| 27 #endif | 26 #endif |
| 28 | 27 |
| 29 using content::BrowserContext; | 28 using content::BrowserContext; |
| 30 using extensions::AutomationEventRouter; | 29 using extensions::AutomationEventRouter; |
| 31 | 30 |
| 32 // static | 31 // static |
| 33 AutomationManagerAura* AutomationManagerAura::GetInstance() { | 32 AutomationManagerAura* AutomationManagerAura::GetInstance() { |
| 34 return base::Singleton<AutomationManagerAura>::get(); | 33 return base::Singleton<AutomationManagerAura>::get(); |
| 35 } | 34 } |
| 36 | 35 |
| 37 void AutomationManagerAura::Enable(BrowserContext* context) { | 36 void AutomationManagerAura::Enable(BrowserContext* context) { |
| 38 enabled_ = true; | 37 enabled_ = true; |
| 39 if (!current_tree_.get()) | 38 if (!current_tree_.get()) |
| 40 current_tree_.reset(new AXTreeSourceAura()); | 39 current_tree_.reset(new AXTreeSourceAura()); |
| 41 ResetSerializer(); | 40 ResetSerializer(); |
| 42 | 41 |
| 43 SendEvent(context, current_tree_->GetRoot(), ui::AX_EVENT_LOAD_COMPLETE); | 42 SendEvent(context, current_tree_->GetRoot(), ui::AX_EVENT_LOAD_COMPLETE); |
| 43 views::AXAuraObjCache::GetInstance()->SetDelegate(this); |
| 44 | 44 |
| 45 #if defined(OS_CHROMEOS) | 45 #if defined(OS_CHROMEOS) |
| 46 aura::Window* active_window = ash::wm::GetActiveWindow(); | 46 aura::Window* active_window = ash::wm::GetActiveWindow(); |
| 47 if (active_window) { | 47 if (active_window) { |
| 48 views::AXAuraObjWrapper* focus = | 48 views::AXAuraObjWrapper* focus = |
| 49 views::AXAuraObjCache::GetInstance()->GetOrCreate(active_window); | 49 views::AXAuraObjCache::GetInstance()->GetOrCreate(active_window); |
| 50 SendEvent(context, focus, ui::AX_EVENT_CHILDREN_CHANGED); | 50 SendEvent(context, focus, ui::AX_EVENT_CHILDREN_CHANGED); |
| 51 } | 51 } |
| 52 #endif | 52 #endif |
| 53 } | 53 } |
| 54 | 54 |
| 55 void AutomationManagerAura::Disable() { | 55 void AutomationManagerAura::Disable() { |
| 56 enabled_ = false; | 56 enabled_ = false; |
| 57 | 57 |
| 58 // Reset the serializer to save memory. | 58 // Reset the serializer to save memory. |
| 59 current_tree_serializer_->Reset(); | 59 current_tree_serializer_->Reset(); |
| 60 } | 60 } |
| 61 | 61 |
| 62 void AutomationManagerAura::HandleEvent(BrowserContext* context, | 62 void AutomationManagerAura::HandleEvent(BrowserContext* context, |
| 63 views::View* view, | 63 views::View* view, |
| 64 ui::AXEvent event_type) { | 64 ui::AXEvent event_type) { |
| 65 if (!enabled_) | 65 if (!enabled_) |
| 66 return; | 66 return; |
| 67 | 67 |
| 68 if (!context && g_browser_process->profile_manager()) | |
| 69 context = g_browser_process->profile_manager()->GetLastUsedProfile(); | |
| 70 | |
| 71 if (!context) { | |
| 72 LOG(WARNING) << "Accessibility notification but no browser context"; | |
| 73 return; | |
| 74 } | |
| 75 | |
| 76 views::AXAuraObjWrapper* aura_obj = | 68 views::AXAuraObjWrapper* aura_obj = |
| 77 views::AXAuraObjCache::GetInstance()->GetOrCreate(view); | 69 views::AXAuraObjCache::GetInstance()->GetOrCreate(view); |
| 78 SendEvent(context, aura_obj, event_type); | 70 SendEvent(nullptr, aura_obj, event_type); |
| 79 } | 71 } |
| 80 | 72 |
| 81 void AutomationManagerAura::HandleAlert(content::BrowserContext* context, | 73 void AutomationManagerAura::HandleAlert(content::BrowserContext* context, |
| 82 const std::string& text) { | 74 const std::string& text) { |
| 83 if (!enabled_) | 75 if (!enabled_) |
| 84 return; | 76 return; |
| 85 | 77 |
| 86 views::AXAuraObjWrapper* obj = | 78 views::AXAuraObjWrapper* obj = |
| 87 static_cast<AXRootObjWrapper*>(current_tree_->GetRoot()) | 79 static_cast<AXRootObjWrapper*>(current_tree_->GetRoot()) |
| 88 ->GetAlertForText(text); | 80 ->GetAlertForText(text); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 114 return; | 106 return; |
| 115 } | 107 } |
| 116 current_tree_->SetSelection(anchor_id, anchor_offset, focus_offset); | 108 current_tree_->SetSelection(anchor_id, anchor_offset, focus_offset); |
| 117 } | 109 } |
| 118 | 110 |
| 119 void AutomationManagerAura::ShowContextMenu(int32_t id) { | 111 void AutomationManagerAura::ShowContextMenu(int32_t id) { |
| 120 CHECK(enabled_); | 112 CHECK(enabled_); |
| 121 current_tree_->ShowContextMenu(id); | 113 current_tree_->ShowContextMenu(id); |
| 122 } | 114 } |
| 123 | 115 |
| 116 void AutomationManagerAura::OnChildWindowRemoved( |
| 117 views::AXAuraObjWrapper* parent) { |
| 118 if (!enabled_) |
| 119 return; |
| 120 |
| 121 if (!parent) |
| 122 parent = current_tree_->GetRoot(); |
| 123 |
| 124 SendEvent(nullptr, parent, ui::AX_EVENT_CHILDREN_CHANGED); |
| 125 } |
| 126 |
| 124 AutomationManagerAura::AutomationManagerAura() | 127 AutomationManagerAura::AutomationManagerAura() |
| 125 : enabled_(false), processing_events_(false) {} | 128 : enabled_(false), processing_events_(false) {} |
| 126 | 129 |
| 127 AutomationManagerAura::~AutomationManagerAura() { | 130 AutomationManagerAura::~AutomationManagerAura() { |
| 128 } | 131 } |
| 129 | 132 |
| 130 void AutomationManagerAura::ResetSerializer() { | 133 void AutomationManagerAura::ResetSerializer() { |
| 131 current_tree_serializer_.reset( | 134 current_tree_serializer_.reset( |
| 132 new AuraAXTreeSerializer(current_tree_.get())); | 135 new AuraAXTreeSerializer(current_tree_.get())); |
| 133 } | 136 } |
| 134 | 137 |
| 135 void AutomationManagerAura::SendEvent(BrowserContext* context, | 138 void AutomationManagerAura::SendEvent(BrowserContext* context, |
| 136 views::AXAuraObjWrapper* aura_obj, | 139 views::AXAuraObjWrapper* aura_obj, |
| 137 ui::AXEvent event_type) { | 140 ui::AXEvent event_type) { |
| 141 if (!context && g_browser_process->profile_manager()) { |
| 142 context = g_browser_process->profile_manager()->GetLastUsedProfile(); |
| 143 } |
| 144 |
| 145 if (!context) { |
| 146 LOG(WARNING) << "Accessibility notification but no browser context"; |
| 147 return; |
| 148 } |
| 149 |
| 138 if (processing_events_) { | 150 if (processing_events_) { |
| 139 pending_events_.push_back(std::make_pair(aura_obj, event_type)); | 151 pending_events_.push_back(std::make_pair(aura_obj, event_type)); |
| 140 return; | 152 return; |
| 141 } | 153 } |
| 142 processing_events_ = true; | 154 processing_events_ = true; |
| 143 | 155 |
| 144 ExtensionMsg_AccessibilityEventParams params; | 156 ExtensionMsg_AccessibilityEventParams params; |
| 145 if (!current_tree_serializer_->SerializeChanges(aura_obj, ¶ms.update)) { | 157 if (!current_tree_serializer_->SerializeChanges(aura_obj, ¶ms.update)) { |
| 146 LOG(ERROR) << "Unable to serialize one accessibility event."; | 158 LOG(ERROR) << "Unable to serialize one accessibility event."; |
| 147 return; | 159 return; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 161 | 173 |
| 162 processing_events_ = false; | 174 processing_events_ = false; |
| 163 auto pending_events_copy = pending_events_; | 175 auto pending_events_copy = pending_events_; |
| 164 pending_events_.clear(); | 176 pending_events_.clear(); |
| 165 for (size_t i = 0; i < pending_events_copy.size(); ++i) { | 177 for (size_t i = 0; i < pending_events_copy.size(); ++i) { |
| 166 SendEvent(context, | 178 SendEvent(context, |
| 167 pending_events_copy[i].first, | 179 pending_events_copy[i].first, |
| 168 pending_events_copy[i].second); | 180 pending_events_copy[i].second); |
| 169 } | 181 } |
| 170 } | 182 } |
| OLD | NEW |