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/extensions/api/automation_internal/automation_internal_
api.h" | 5 #include "chrome/browser/extensions/api/automation_internal/automation_internal_
api.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "chrome/browser/accessibility/ax_tree_id_registry.h" | 12 #include "chrome/browser/accessibility/ax_tree_id_registry.h" |
13 #include "chrome/browser/extensions/api/automation_internal/automation_action_ad
apter.h" | 13 #include "chrome/browser/extensions/api/automation_internal/automation_action_ad
apter.h" |
| 14 #include "chrome/browser/extensions/api/automation_internal/automation_event_rou
ter.h" |
14 #include "chrome/browser/extensions/api/automation_internal/automation_util.h" | 15 #include "chrome/browser/extensions/api/automation_internal/automation_util.h" |
15 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | 16 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
16 #include "chrome/browser/extensions/extension_tab_util.h" | 17 #include "chrome/browser/extensions/extension_tab_util.h" |
17 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
19 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 20 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
20 #include "chrome/common/extensions/api/automation_internal.h" | 21 #include "chrome/common/extensions/api/automation_internal.h" |
| 22 #include "chrome/common/extensions/chrome_extension_messages.h" |
21 #include "chrome/common/extensions/manifest_handlers/automation.h" | 23 #include "chrome/common/extensions/manifest_handlers/automation.h" |
22 #include "content/public/browser/ax_event_notification_details.h" | 24 #include "content/public/browser/ax_event_notification_details.h" |
23 #include "content/public/browser/browser_accessibility_state.h" | 25 #include "content/public/browser/browser_accessibility_state.h" |
24 #include "content/public/browser/render_frame_host.h" | 26 #include "content/public/browser/render_frame_host.h" |
25 #include "content/public/browser/render_process_host.h" | 27 #include "content/public/browser/render_process_host.h" |
26 #include "content/public/browser/render_view_host.h" | 28 #include "content/public/browser/render_view_host.h" |
27 #include "content/public/browser/render_widget_host.h" | 29 #include "content/public/browser/render_widget_host.h" |
28 #include "content/public/browser/render_widget_host_view.h" | 30 #include "content/public/browser/render_widget_host_view.h" |
29 #include "content/public/browser/web_contents.h" | 31 #include "content/public/browser/web_contents.h" |
30 #include "extensions/common/extension_messages.h" | 32 #include "extensions/common/extension_messages.h" |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 | 217 |
216 ExtensionFunction::ResponseAction | 218 ExtensionFunction::ResponseAction |
217 AutomationInternalEnableTabFunction::Run() { | 219 AutomationInternalEnableTabFunction::Run() { |
218 const AutomationInfo* automation_info = AutomationInfo::Get(extension()); | 220 const AutomationInfo* automation_info = AutomationInfo::Get(extension()); |
219 EXTENSION_FUNCTION_VALIDATE(automation_info); | 221 EXTENSION_FUNCTION_VALIDATE(automation_info); |
220 | 222 |
221 using api::automation_internal::EnableTab::Params; | 223 using api::automation_internal::EnableTab::Params; |
222 scoped_ptr<Params> params(Params::Create(*args_)); | 224 scoped_ptr<Params> params(Params::Create(*args_)); |
223 EXTENSION_FUNCTION_VALIDATE(params.get()); | 225 EXTENSION_FUNCTION_VALIDATE(params.get()); |
224 content::WebContents* contents = NULL; | 226 content::WebContents* contents = NULL; |
225 if (params->tab_id.get()) { | 227 if (params->args.tab_id.get()) { |
226 int tab_id = *params->tab_id; | 228 int tab_id = *params->args.tab_id; |
227 if (!ExtensionTabUtil::GetTabById(tab_id, | 229 if (!ExtensionTabUtil::GetTabById(tab_id, |
228 GetProfile(), | 230 GetProfile(), |
229 include_incognito(), | 231 include_incognito(), |
230 NULL, /* browser out param*/ | 232 NULL, /* browser out param*/ |
231 NULL, /* tab_strip out param */ | 233 NULL, /* tab_strip out param */ |
232 &contents, | 234 &contents, |
233 NULL /* tab_index out param */)) { | 235 NULL /* tab_index out param */)) { |
234 return RespondNow( | 236 return RespondNow( |
235 Error(tabs_constants::kTabNotFoundError, base::IntToString(tab_id))); | 237 Error(tabs_constants::kTabNotFoundError, base::IntToString(tab_id))); |
236 } | 238 } |
237 } else { | 239 } else { |
238 contents = GetCurrentBrowser()->tab_strip_model()->GetActiveWebContents(); | 240 contents = GetCurrentBrowser()->tab_strip_model()->GetActiveWebContents(); |
239 if (!contents) | 241 if (!contents) |
240 return RespondNow(Error("No active tab")); | 242 return RespondNow(Error("No active tab")); |
241 } | 243 } |
242 content::RenderFrameHost* rfh = contents->GetMainFrame(); | 244 content::RenderFrameHost* rfh = contents->GetMainFrame(); |
243 if (!rfh) | 245 if (!rfh) |
244 return RespondNow(Error("Could not enable accessibility for active tab")); | 246 return RespondNow(Error("Could not enable accessibility for active tab")); |
245 | 247 |
246 if (!CanRequestAutomation(extension(), automation_info, contents)) { | 248 if (!CanRequestAutomation(extension(), automation_info, contents)) { |
247 return RespondNow( | 249 return RespondNow( |
248 Error(kCannotRequestAutomationOnPage, contents->GetURL().spec())); | 250 Error(kCannotRequestAutomationOnPage, contents->GetURL().spec())); |
249 } | 251 } |
| 252 |
250 AutomationWebContentsObserver::CreateForWebContents(contents); | 253 AutomationWebContentsObserver::CreateForWebContents(contents); |
251 contents->EnableTreeOnlyAccessibilityMode(); | 254 contents->EnableTreeOnlyAccessibilityMode(); |
252 int ax_tree_id = AXTreeIDRegistry::GetInstance()->GetOrCreateAXTreeID( | 255 int ax_tree_id = AXTreeIDRegistry::GetInstance()->GetOrCreateAXTreeID( |
253 rfh->GetProcess()->GetID(), rfh->GetRoutingID()); | 256 rfh->GetProcess()->GetID(), rfh->GetRoutingID()); |
| 257 |
| 258 // This gets removed when the extension process dies. |
| 259 AutomationEventRouter::GetInstance()->RegisterListenerForOneTree( |
| 260 source_process_id(), |
| 261 params->args.routing_id, |
| 262 ax_tree_id); |
| 263 |
254 return RespondNow(ArgumentList( | 264 return RespondNow(ArgumentList( |
255 api::automation_internal::EnableTab::Results::Create(ax_tree_id))); | 265 api::automation_internal::EnableTab::Results::Create(ax_tree_id))); |
256 } | 266 } |
257 | 267 |
258 ExtensionFunction::ResponseAction AutomationInternalEnableFrameFunction::Run() { | 268 ExtensionFunction::ResponseAction AutomationInternalEnableFrameFunction::Run() { |
259 // TODO(dtseng): Limited to desktop tree for now pending out of proc iframes. | 269 // TODO(dtseng): Limited to desktop tree for now pending out of proc iframes. |
260 using api::automation_internal::EnableFrame::Params; | 270 using api::automation_internal::EnableFrame::Params; |
261 | 271 |
262 scoped_ptr<Params> params(Params::Create(*args_)); | 272 scoped_ptr<Params> params(Params::Create(*args_)); |
263 EXTENSION_FUNCTION_VALIDATE(params.get()); | 273 EXTENSION_FUNCTION_VALIDATE(params.get()); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 return RespondNow(NoArguments()); | 354 return RespondNow(NoArguments()); |
345 } | 355 } |
346 | 356 |
347 ExtensionFunction::ResponseAction | 357 ExtensionFunction::ResponseAction |
348 AutomationInternalEnableDesktopFunction::Run() { | 358 AutomationInternalEnableDesktopFunction::Run() { |
349 #if defined(USE_AURA) | 359 #if defined(USE_AURA) |
350 const AutomationInfo* automation_info = AutomationInfo::Get(extension()); | 360 const AutomationInfo* automation_info = AutomationInfo::Get(extension()); |
351 if (!automation_info || !automation_info->desktop) | 361 if (!automation_info || !automation_info->desktop) |
352 return RespondNow(Error("desktop permission must be requested")); | 362 return RespondNow(Error("desktop permission must be requested")); |
353 | 363 |
| 364 using api::automation_internal::EnableDesktop::Params; |
| 365 scoped_ptr<Params> params(Params::Create(*args_)); |
| 366 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 367 |
| 368 // This gets removed when the extension process dies. |
| 369 AutomationEventRouter::GetInstance()->RegisterListenerWithDesktopPermission( |
| 370 source_process_id(), |
| 371 params->routing_id); |
| 372 |
354 AutomationManagerAura::GetInstance()->Enable(browser_context()); | 373 AutomationManagerAura::GetInstance()->Enable(browser_context()); |
355 return RespondNow(NoArguments()); | 374 return RespondNow(NoArguments()); |
356 #else | 375 #else |
357 return RespondNow(Error("getDesktop is unsupported by this platform")); | 376 return RespondNow(Error("getDesktop is unsupported by this platform")); |
358 #endif // defined(USE_AURA) | 377 #endif // defined(USE_AURA) |
359 } | 378 } |
360 | 379 |
361 // static | 380 // static |
362 int AutomationInternalQuerySelectorFunction::query_request_id_counter_ = 0; | 381 int AutomationInternalQuerySelectorFunction::query_request_id_counter_ = 0; |
363 | 382 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 int result_acc_obj_id) { | 419 int result_acc_obj_id) { |
401 if (!error.empty()) { | 420 if (!error.empty()) { |
402 Respond(Error(error)); | 421 Respond(Error(error)); |
403 return; | 422 return; |
404 } | 423 } |
405 | 424 |
406 Respond(OneArgument(new base::FundamentalValue(result_acc_obj_id))); | 425 Respond(OneArgument(new base::FundamentalValue(result_acc_obj_id))); |
407 } | 426 } |
408 | 427 |
409 } // namespace extensions | 428 } // namespace extensions |
OLD | NEW |