| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/extensions/extension_tabs_module.h" | 5 #include "chrome/browser/extensions/extension_tabs_module.h" |
| 6 | 6 |
| 7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
| 8 #include "base/stl_util-inl.h" | 8 #include "base/stl_util-inl.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 std::string ControlInfoToJsonString(const AccessibilityControlInfo* info) { | 27 std::string ControlInfoToJsonString(const AccessibilityControlInfo* info) { |
| 28 ListValue args; | 28 ListValue args; |
| 29 DictionaryValue* dict = new DictionaryValue(); | 29 DictionaryValue* dict = new DictionaryValue(); |
| 30 info->SerializeToDict(dict); | 30 info->SerializeToDict(dict); |
| 31 args.Append(dict); | 31 args.Append(dict); |
| 32 std::string json_args; | 32 std::string json_args; |
| 33 base::JSONWriter::Write(&args, false, &json_args); | 33 base::JSONWriter::Write(&args, false, &json_args); |
| 34 return json_args; | 34 return json_args; |
| 35 } | 35 } |
| 36 | 36 |
| 37 ExtensionAccessibilityEventRouter* | 37 ExtensionAccessibilityEventRouter::ExtensionAccessibilityEventRouter() |
| 38 ExtensionAccessibilityEventRouter::GetInstance() { | 38 : enabled_(false) { |
| 39 return Singleton<ExtensionAccessibilityEventRouter>::get(); | |
| 40 } | 39 } |
| 41 | 40 |
| 42 ExtensionAccessibilityEventRouter::ExtensionAccessibilityEventRouter() | |
| 43 : enabled_(false) {} | |
| 44 | |
| 45 ExtensionAccessibilityEventRouter::~ExtensionAccessibilityEventRouter() { | 41 ExtensionAccessibilityEventRouter::~ExtensionAccessibilityEventRouter() { |
| 46 STLDeleteElements(&on_enabled_listeners_); | 42 STLDeleteElements(&on_enabled_listeners_); |
| 47 STLDeleteElements(&on_disabled_listeners_); | 43 STLDeleteElements(&on_disabled_listeners_); |
| 48 } | 44 } |
| 49 | 45 |
| 50 void ExtensionAccessibilityEventRouter::ObserveProfile(Profile* profile) { | 46 void ExtensionAccessibilityEventRouter::Init() { |
| 51 last_focused_control_dict_.Clear(); | 47 last_focused_control_dict_.Clear(); |
| 52 | 48 |
| 53 if (registrar_.IsEmpty()) { | 49 if (registrar_.IsEmpty()) { |
| 54 registrar_.Add(this, | 50 registrar_.Add(this, |
| 55 NotificationType::ACCESSIBILITY_WINDOW_OPENED, | 51 NotificationType::ACCESSIBILITY_WINDOW_OPENED, |
| 56 NotificationService::AllSources()); | 52 NotificationService::AllSources()); |
| 57 registrar_.Add(this, | 53 registrar_.Add(this, |
| 58 NotificationType::ACCESSIBILITY_WINDOW_CLOSED, | 54 NotificationType::ACCESSIBILITY_WINDOW_CLOSED, |
| 59 NotificationService::AllSources()); | 55 NotificationService::AllSources()); |
| 60 registrar_.Add(this, | 56 registrar_.Add(this, |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 const std::string& json_args) { | 181 const std::string& json_args) { |
| 186 if (enabled_ && profile && profile->GetExtensionEventRouter()) { | 182 if (enabled_ && profile && profile->GetExtensionEventRouter()) { |
| 187 profile->GetExtensionEventRouter()->DispatchEventToRenderers( | 183 profile->GetExtensionEventRouter()->DispatchEventToRenderers( |
| 188 event_name, json_args, NULL, GURL()); | 184 event_name, json_args, NULL, GURL()); |
| 189 } | 185 } |
| 190 } | 186 } |
| 191 | 187 |
| 192 bool SetAccessibilityEnabledFunction::RunImpl() { | 188 bool SetAccessibilityEnabledFunction::RunImpl() { |
| 193 bool enabled; | 189 bool enabled; |
| 194 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(0, &enabled)); | 190 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(0, &enabled)); |
| 195 ExtensionAccessibilityEventRouter::GetInstance() | 191 ExtensionAccessibilityEventRouter* accessibility_event_router = |
| 196 ->SetAccessibilityEnabled(enabled); | 192 profile()->GetExtensionService()->accessibility_event_router(); |
| 193 accessibility_event_router->SetAccessibilityEnabled(enabled); |
| 197 return true; | 194 return true; |
| 198 } | 195 } |
| 199 | 196 |
| 200 bool GetFocusedControlFunction::RunImpl() { | 197 bool GetFocusedControlFunction::RunImpl() { |
| 201 // Get the serialized dict from the last focused control and return it. | 198 // Get the serialized dict from the last focused control and return it. |
| 202 // However, if the dict is empty, that means we haven't seen any focus | 199 // However, if the dict is empty, that means we haven't seen any focus |
| 203 // events yet, so return null instead. | 200 // events yet, so return null instead. |
| 204 ExtensionAccessibilityEventRouter *accessibility_event_router = | 201 ExtensionAccessibilityEventRouter* accessibility_event_router = |
| 205 ExtensionAccessibilityEventRouter::GetInstance(); | 202 profile()->GetExtensionService()->accessibility_event_router(); |
| 206 DictionaryValue *last_focused_control_dict = | 203 DictionaryValue *last_focused_control_dict = |
| 207 accessibility_event_router->last_focused_control_dict(); | 204 accessibility_event_router->last_focused_control_dict(); |
| 208 if (last_focused_control_dict->size()) { | 205 if (last_focused_control_dict->size()) { |
| 209 result_.reset(last_focused_control_dict->DeepCopyWithoutEmptyChildren()); | 206 result_.reset(last_focused_control_dict->DeepCopyWithoutEmptyChildren()); |
| 210 } else { | 207 } else { |
| 211 result_.reset(Value::CreateNullValue()); | 208 result_.reset(Value::CreateNullValue()); |
| 212 } | 209 } |
| 213 return true; | 210 return true; |
| 214 } | 211 } |
| OLD | NEW |