| 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* router = AutomationEventRouter::GetInstance(); |
| 260 router->AddListener(source_process_id(), |
| 261 params->args.routing_id, |
| 262 ax_tree_id, |
| 263 false); |
| 264 |
| 254 return RespondNow(ArgumentList( | 265 return RespondNow(ArgumentList( |
| 255 api::automation_internal::EnableTab::Results::Create(ax_tree_id))); | 266 api::automation_internal::EnableTab::Results::Create(ax_tree_id))); |
| 256 } | 267 } |
| 257 | 268 |
| 258 ExtensionFunction::ResponseAction AutomationInternalEnableFrameFunction::Run() { | 269 ExtensionFunction::ResponseAction AutomationInternalEnableFrameFunction::Run() { |
| 259 // TODO(dtseng): Limited to desktop tree for now pending out of proc iframes. | 270 // TODO(dtseng): Limited to desktop tree for now pending out of proc iframes. |
| 260 using api::automation_internal::EnableFrame::Params; | 271 using api::automation_internal::EnableFrame::Params; |
| 261 | 272 |
| 262 scoped_ptr<Params> params(Params::Create(*args_)); | 273 scoped_ptr<Params> params(Params::Create(*args_)); |
| 263 EXTENSION_FUNCTION_VALIDATE(params.get()); | 274 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 return RespondNow(NoArguments()); | 355 return RespondNow(NoArguments()); |
| 345 } | 356 } |
| 346 | 357 |
| 347 ExtensionFunction::ResponseAction | 358 ExtensionFunction::ResponseAction |
| 348 AutomationInternalEnableDesktopFunction::Run() { | 359 AutomationInternalEnableDesktopFunction::Run() { |
| 349 #if defined(USE_AURA) | 360 #if defined(USE_AURA) |
| 350 const AutomationInfo* automation_info = AutomationInfo::Get(extension()); | 361 const AutomationInfo* automation_info = AutomationInfo::Get(extension()); |
| 351 if (!automation_info || !automation_info->desktop) | 362 if (!automation_info || !automation_info->desktop) |
| 352 return RespondNow(Error("desktop permission must be requested")); | 363 return RespondNow(Error("desktop permission must be requested")); |
| 353 | 364 |
| 365 using api::automation_internal::EnableDesktop::Params; |
| 366 scoped_ptr<Params> params(Params::Create(*args_)); |
| 367 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 368 |
| 369 // This gets removed when the extension process dies. |
| 370 AutomationEventRouter* router = AutomationEventRouter::GetInstance(); |
| 371 router->AddListener(source_process_id(), |
| 372 params->routing_id, |
| 373 0, // DESKTOP tree id |
| 374 true); |
| 375 |
| 354 AutomationManagerAura::GetInstance()->Enable(browser_context()); | 376 AutomationManagerAura::GetInstance()->Enable(browser_context()); |
| 355 return RespondNow(NoArguments()); | 377 return RespondNow(NoArguments()); |
| 356 #else | 378 #else |
| 357 return RespondNow(Error("getDesktop is unsupported by this platform")); | 379 return RespondNow(Error("getDesktop is unsupported by this platform")); |
| 358 #endif // defined(USE_AURA) | 380 #endif // defined(USE_AURA) |
| 359 } | 381 } |
| 360 | 382 |
| 361 // static | 383 // static |
| 362 int AutomationInternalQuerySelectorFunction::query_request_id_counter_ = 0; | 384 int AutomationInternalQuerySelectorFunction::query_request_id_counter_ = 0; |
| 363 | 385 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 int result_acc_obj_id) { | 422 int result_acc_obj_id) { |
| 401 if (!error.empty()) { | 423 if (!error.empty()) { |
| 402 Respond(Error(error)); | 424 Respond(Error(error)); |
| 403 return; | 425 return; |
| 404 } | 426 } |
| 405 | 427 |
| 406 Respond(OneArgument(new base::FundamentalValue(result_acc_obj_id))); | 428 Respond(OneArgument(new base::FundamentalValue(result_acc_obj_id))); |
| 407 } | 429 } |
| 408 | 430 |
| 409 } // namespace extensions | 431 } // namespace extensions |
| OLD | NEW |