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 "chrome/browser/accessibility/accessibility_extension_api.h" | 5 #include "chrome/browser/accessibility/accessibility_extension_api.h" |
6 | 6 |
7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/accessibility/accessibility_extension_api_constants.h" | 10 #include "chrome/browser/accessibility/accessibility_extension_api_constants.h" |
11 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | 11 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
12 #include "chrome/browser/extensions/event_router.h" | 12 #include "chrome/browser/extensions/event_router.h" |
13 #include "chrome/browser/extensions/extension_host.h" | |
14 #include "chrome/browser/extensions/extension_service.h" | |
13 #include "chrome/browser/extensions/extension_system.h" | 15 #include "chrome/browser/extensions/extension_system.h" |
14 #include "chrome/browser/extensions/extension_tab_util.h" | 16 #include "chrome/browser/extensions/extension_tab_util.h" |
17 #include "chrome/browser/extensions/lazy_background_task_queue.h" | |
15 #include "chrome/browser/infobars/confirm_infobar_delegate.h" | 18 #include "chrome/browser/infobars/confirm_infobar_delegate.h" |
16 #include "chrome/browser/infobars/infobar_delegate.h" | 19 #include "chrome/browser/infobars/infobar_delegate.h" |
17 #include "chrome/browser/infobars/infobar_service.h" | 20 #include "chrome/browser/infobars/infobar_service.h" |
18 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/common/extensions/api/experimental_accessibility.h" | 22 #include "chrome/common/extensions/api/experimental_accessibility.h" |
23 #include "chrome/common/extensions/background_info.h" | |
20 #include "content/public/browser/browser_accessibility_state.h" | 24 #include "content/public/browser/browser_accessibility_state.h" |
21 #include "extensions/common/error_utils.h" | 25 #include "extensions/common/error_utils.h" |
22 | 26 |
23 namespace keys = extension_accessibility_api_constants; | 27 namespace keys = extension_accessibility_api_constants; |
24 namespace experimental_accessibility = | 28 namespace experimental_accessibility = |
25 extensions::api::experimental_accessibility; | 29 extensions::api::experimental_accessibility; |
26 | 30 |
27 // Returns the AccessibilityControlInfo serialized into a JSON string, | 31 // Returns the AccessibilityControlInfo serialized into a JSON string, |
28 // consisting of an array of a single object of type AccessibilityObject, | 32 // consisting of an array of a single object of type AccessibilityObject, |
29 // as defined in the accessibility extension api's json schema. | 33 // as defined in the accessibility extension api's json schema. |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 } | 161 } |
158 | 162 |
159 void ExtensionAccessibilityEventRouter::OnMenuClosed( | 163 void ExtensionAccessibilityEventRouter::OnMenuClosed( |
160 const AccessibilityMenuInfo* info) { | 164 const AccessibilityMenuInfo* info) { |
161 scoped_ptr<ListValue> args(ControlInfoToEventArguments(info)); | 165 scoped_ptr<ListValue> args(ControlInfoToEventArguments(info)); |
162 DispatchEvent(info->profile(), | 166 DispatchEvent(info->profile(), |
163 experimental_accessibility::OnMenuClosed::kEventName, | 167 experimental_accessibility::OnMenuClosed::kEventName, |
164 args.Pass()); | 168 args.Pass()); |
165 } | 169 } |
166 | 170 |
171 void ExtensionAccessibilityEventRouter:: | |
172 OnSpokenFeedbackEnabled(Profile* profile, bool make_announcements) { | |
173 scoped_ptr<base::ListValue> event_args(new base::ListValue()); | |
174 event_args->Append(base::Value::CreateBooleanValue(make_announcements)); | |
175 ExtensionAccessibilityEventRouter::DispatchEventToChromeVox(profile, | |
176 experimental_accessibility::OnSpokenFeedbackEnabled::kEventName, | |
177 event_args.Pass(), | |
178 true, | |
179 NULL); | |
180 } | |
181 | |
182 void ExtensionAccessibilityEventRouter:: | |
183 OnSpokenFeedbackDisabled(Profile* profile) { | |
184 scoped_ptr<base::ListValue> event_args(new base::ListValue()); | |
185 ExtensionAccessibilityEventRouter::DispatchEventToChromeVox(profile, | |
186 experimental_accessibility::OnSpokenFeedbackDisabled::kEventName, | |
187 event_args.Pass(), | |
188 true, | |
189 NULL); | |
190 } | |
191 | |
192 // Static. | |
193 void ExtensionAccessibilityEventRouter::DispatchEventToChromeVox( | |
194 Profile* profile, | |
195 const char* event_name, | |
196 scoped_ptr<base::ListValue> event_args, | |
197 bool first_call, | |
198 extensions::ExtensionHost* host) { | |
199 if (!first_call && !host) | |
200 return; | |
201 | |
202 extensions::ExtensionSystem* system = | |
203 extensions::ExtensionSystem::Get(profile); | |
204 if (!system) | |
205 return; | |
206 | |
207 const char* extension_id = extension_misc::kChromeVoxExtensionId; | |
208 // If this is a persistent background page, we want to wait for it to load | |
209 // (it might not be ready, since this is startup). But only enqueue once. | |
210 // If it fails to load the first time, don't bother trying again. | |
211 const extensions::Extension* extension = | |
212 system->extension_service()->extensions()->GetByID(extension_id); | |
213 if (extension && | |
214 extensions::BackgroundInfo::HasPersistentBackgroundPage(extension) && | |
215 first_call && | |
216 system->lazy_background_task_queue()-> | |
217 ShouldEnqueueTask(profile, extension)) { | |
218 extensions::LazyBackgroundTaskQueue* queue = | |
dmazzoni
2013/10/29 19:08:44
Move this to before the "if" because the condition
| |
219 system->lazy_background_task_queue(); | |
220 const extensions::LazyBackgroundTaskQueue::PendingTask callback = | |
221 base::Bind(&DispatchEventToChromeVox, | |
222 profile, | |
223 event_name, | |
224 base::Passed(&event_args), | |
225 false); | |
226 queue->AddPendingTask(profile, extension_id, callback); | |
227 return; | |
228 } | |
229 | |
230 scoped_ptr<extensions::Event> event(new extensions::Event(event_name, | |
231 event_args.Pass())); | |
232 system->event_router()->DispatchEventToExtension( | |
233 extension_id, event.Pass()); | |
234 } | |
235 | |
167 void ExtensionAccessibilityEventRouter::DispatchEvent( | 236 void ExtensionAccessibilityEventRouter::DispatchEvent( |
168 Profile* profile, | 237 Profile* profile, |
169 const char* event_name, | 238 const char* event_name, |
170 scoped_ptr<base::ListValue> event_args) { | 239 scoped_ptr<base::ListValue> event_args) { |
171 if (enabled_ && profile && | 240 if (enabled_ && profile && |
172 extensions::ExtensionSystem::Get(profile)->event_router()) { | 241 extensions::ExtensionSystem::Get(profile)->event_router()) { |
173 scoped_ptr<extensions::Event> event(new extensions::Event( | 242 scoped_ptr<extensions::Event> event(new extensions::Event( |
174 event_name, event_args.Pass())); | 243 event_name, event_args.Pass())); |
175 extensions::ExtensionSystem::Get(profile)->event_router()-> | 244 extensions::ExtensionSystem::Get(profile)->event_router()-> |
176 BroadcastEvent(event.Pass()); | 245 BroadcastEvent(event.Pass()); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
240 DictionaryValue* alert_value = new DictionaryValue; | 309 DictionaryValue* alert_value = new DictionaryValue; |
241 const string16 message_text = confirm_infobar_delegate->GetMessageText(); | 310 const string16 message_text = confirm_infobar_delegate->GetMessageText(); |
242 alert_value->SetString(keys::kMessageKey, message_text); | 311 alert_value->SetString(keys::kMessageKey, message_text); |
243 alerts_value->Append(alert_value); | 312 alerts_value->Append(alert_value); |
244 } | 313 } |
245 } | 314 } |
246 | 315 |
247 SetResult(alerts_value); | 316 SetResult(alerts_value); |
248 return true; | 317 return true; |
249 } | 318 } |
OLD | NEW |