| 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/views/accessibility/automation_manager_views.h" | 5 #include "chrome/browser/ui/ash/accessibility/automation_manager_views.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/command_line.h" | |
| 10 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
| 11 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/extensions/api/automation_internal/automation_util.h" | 11 #include "chrome/browser/extensions/api/automation_internal/automation_util.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
| 15 #include "chrome/common/chrome_switches.h" | |
| 16 #include "content/public/browser/ax_event_notification_details.h" | 14 #include "content/public/browser/ax_event_notification_details.h" |
| 15 #include "ui/views/accessibility/ax_aura_obj_cache.h" |
| 16 #include "ui/views/accessibility/ax_aura_obj_wrapper.h" |
| 17 #include "ui/views/view.h" | 17 #include "ui/views/view.h" |
| 18 #include "ui/views/widget/widget.h" | 18 #include "ui/views/widget/widget.h" |
| 19 | 19 |
| 20 // static | 20 // static |
| 21 AutomationManagerViews* AutomationManagerViews::GetInstance() { | 21 AutomationManagerViews* AutomationManagerViews::GetInstance() { |
| 22 return Singleton<AutomationManagerViews>::get(); | 22 return Singleton<AutomationManagerViews>::get(); |
| 23 } | 23 } |
| 24 | 24 |
| 25 void AutomationManagerViews::Enable() { |
| 26 enabled_ = true; |
| 27 if (current_tree_serializer_.get()) |
| 28 current_tree_serializer_->Reset(); |
| 29 } |
| 30 |
| 31 void AutomationManagerViews::Disable() { |
| 32 enabled_ = false; |
| 33 current_tree_serializer_->Reset(); |
| 34 } |
| 35 |
| 25 void AutomationManagerViews::HandleEvent(Profile* profile, | 36 void AutomationManagerViews::HandleEvent(Profile* profile, |
| 26 views::View* view, | 37 views::View* view, |
| 27 ui::AXEvent event_type) { | 38 ui::AXEvent event_type) { |
| 28 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 39 if (!enabled_) { |
| 29 switches::kEnableAutomationAPI)) { | |
| 30 return; | 40 return; |
| 31 } | 41 } |
| 32 | 42 |
| 33 // TODO(dtseng): Events should only be delivered to extensions with the | 43 // TODO(dtseng): Events should only be delivered to extensions with the |
| 34 // desktop permission. | 44 // desktop permission. |
| 35 views::Widget* widget = view->GetWidget(); | 45 views::Widget* widget = view->GetWidget(); |
| 36 if (!widget) | 46 if (!widget) |
| 37 return; | 47 return; |
| 38 | 48 |
| 39 if (!profile && g_browser_process->profile_manager()) { | 49 if (!profile && g_browser_process->profile_manager()) { |
| 40 profile = g_browser_process->profile_manager()->GetLastUsedProfile(); | 50 profile = g_browser_process->profile_manager()->GetLastUsedProfile(); |
| 41 } | 51 } |
| 42 if (!profile) { | 52 if (!profile) { |
| 43 LOG(WARNING) << "Accessibility notification but no profile"; | 53 LOG(WARNING) << "Accessibility notification but no profile"; |
| 44 return; | 54 return; |
| 45 } | 55 } |
| 46 | 56 |
| 47 if (!current_tree_.get() || | 57 if (!current_tree_.get()) { |
| 48 current_tree_->GetRoot()->GetWidget() != widget) { | 58 current_tree_.reset(new AXTreeSourceViews()); |
| 49 current_tree_.reset(new views::AXTreeSourceViews(widget)); | |
| 50 current_tree_serializer_.reset( | 59 current_tree_serializer_.reset( |
| 51 new ui::AXTreeSerializer<views::View*>(current_tree_.get())); | 60 new ui::AXTreeSerializer<views::AXAuraObjWrapper*>( |
| 52 // TODO(dtseng): Need to send a load complete and clear any previous desktop | 61 current_tree_.get())); |
| 53 // trees. | |
| 54 } | 62 } |
| 55 | 63 |
| 56 ui::AXTreeUpdate out_update; | 64 ui::AXTreeUpdate out_update; |
| 57 current_tree_serializer_->SerializeChanges(view, &out_update); | 65 views::AXAuraObjWrapper* aura_obj = |
| 66 views::AXAuraObjCache::GetInstance()->GetOrCreate(view); |
| 67 current_tree_serializer_->SerializeChanges(aura_obj, &out_update); |
| 58 | 68 |
| 59 // Route this event to special process/routing ids recognized by the | 69 // Route this event to special process/routing ids recognized by the |
| 60 // Automation API as the desktop tree. | 70 // Automation API as the desktop tree. |
| 61 | |
| 62 // TODO(dtseng): Would idealy define these special desktop constants in idl. | 71 // TODO(dtseng): Would idealy define these special desktop constants in idl. |
| 63 content::AXEventNotificationDetails detail(out_update.nodes, | 72 content::AXEventNotificationDetails detail(out_update.nodes, |
| 64 event_type, | 73 event_type, |
| 65 current_tree_->GetId(view), | 74 aura_obj->GetID(), |
| 66 0, /* process_id */ | 75 0, /* process_id */ |
| 67 0 /* routing_id */); | 76 0 /* routing_id */); |
| 68 std::vector<content::AXEventNotificationDetails> details; | 77 std::vector<content::AXEventNotificationDetails> details; |
| 69 details.push_back(detail); | 78 details.push_back(detail); |
| 70 extensions::automation_util::DispatchAccessibilityEventsToAutomation( | 79 extensions::automation_util::DispatchAccessibilityEventsToAutomation( |
| 71 details, profile); | 80 details, profile); |
| 72 } | 81 } |
| 73 | 82 |
| 74 AutomationManagerViews::AutomationManagerViews() {} | 83 AutomationManagerViews::AutomationManagerViews() : enabled_(false) {} |
| 75 | 84 |
| 76 AutomationManagerViews:: ~AutomationManagerViews() {} | 85 AutomationManagerViews:: ~AutomationManagerViews() {} |
| OLD | NEW |