Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(888)

Side by Side Diff: chrome/browser/extensions/api/automation_internal/automation_internal_api.cc

Issue 1003283002: Enable chrome.automation.getDesktop on all aura platforms. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_util.h" 14 #include "chrome/browser/extensions/api/automation_internal/automation_util.h"
15 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" 15 #include "chrome/browser/extensions/api/tabs/tabs_constants.h"
16 #include "chrome/browser/extensions/extension_tab_util.h" 16 #include "chrome/browser/extensions/extension_tab_util.h"
17 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/ui/aura/accessibility/automation_manager_aura.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"
21 #include "chrome/common/extensions/manifest_handlers/automation.h" 22 #include "chrome/common/extensions/manifest_handlers/automation.h"
22 #include "content/public/browser/ax_event_notification_details.h" 23 #include "content/public/browser/ax_event_notification_details.h"
23 #include "content/public/browser/browser_accessibility_state.h" 24 #include "content/public/browser/browser_accessibility_state.h"
24 #include "content/public/browser/render_frame_host.h" 25 #include "content/public/browser/render_frame_host.h"
25 #include "content/public/browser/render_process_host.h" 26 #include "content/public/browser/render_process_host.h"
26 #include "content/public/browser/render_view_host.h" 27 #include "content/public/browser/render_view_host.h"
27 #include "content/public/browser/render_widget_host.h" 28 #include "content/public/browser/render_widget_host.h"
28 #include "content/public/browser/render_widget_host_view.h" 29 #include "content/public/browser/render_widget_host_view.h"
29 #include "content/public/browser/web_contents.h" 30 #include "content/public/browser/web_contents.h"
30 #include "extensions/common/extension_messages.h" 31 #include "extensions/common/extension_messages.h"
31 #include "extensions/common/permissions/permissions_data.h" 32 #include "extensions/common/permissions/permissions_data.h"
32 33
33 #if defined(OS_CHROMEOS)
34 #include "chrome/browser/ui/ash/accessibility/automation_manager_ash.h"
35 #endif
36
37 namespace extensions { 34 namespace extensions {
38 class AutomationWebContentsObserver; 35 class AutomationWebContentsObserver;
39 } // namespace extensions 36 } // namespace extensions
40 37
41 DEFINE_WEB_CONTENTS_USER_DATA_KEY(extensions::AutomationWebContentsObserver); 38 DEFINE_WEB_CONTENTS_USER_DATA_KEY(extensions::AutomationWebContentsObserver);
42 39
43 namespace extensions { 40 namespace extensions {
44 41
45 namespace { 42 namespace {
46 const int kDesktopTreeID = 0; 43 const int kDesktopTreeID = 0;
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 AutomationWebContentsObserver::CreateForWebContents(contents); 247 AutomationWebContentsObserver::CreateForWebContents(contents);
251 contents->EnableTreeOnlyAccessibilityMode(); 248 contents->EnableTreeOnlyAccessibilityMode();
252 int ax_tree_id = AXTreeIDRegistry::GetInstance()->GetOrCreateAXTreeID( 249 int ax_tree_id = AXTreeIDRegistry::GetInstance()->GetOrCreateAXTreeID(
253 rfh->GetProcess()->GetID(), rfh->GetRoutingID()); 250 rfh->GetProcess()->GetID(), rfh->GetRoutingID());
254 return RespondNow(ArgumentList( 251 return RespondNow(ArgumentList(
255 api::automation_internal::EnableTab::Results::Create(ax_tree_id))); 252 api::automation_internal::EnableTab::Results::Create(ax_tree_id)));
256 } 253 }
257 254
258 ExtensionFunction::ResponseAction AutomationInternalEnableFrameFunction::Run() { 255 ExtensionFunction::ResponseAction AutomationInternalEnableFrameFunction::Run() {
259 // TODO(dtseng): Limited to desktop tree for now pending out of proc iframes. 256 // TODO(dtseng): Limited to desktop tree for now pending out of proc iframes.
260 #if defined(OS_CHROMEOS)
261 using api::automation_internal::EnableFrame::Params; 257 using api::automation_internal::EnableFrame::Params;
262 258
263 scoped_ptr<Params> params(Params::Create(*args_)); 259 scoped_ptr<Params> params(Params::Create(*args_));
264 EXTENSION_FUNCTION_VALIDATE(params.get()); 260 EXTENSION_FUNCTION_VALIDATE(params.get());
265 AXTreeIDRegistry::FrameID frame_id = 261 AXTreeIDRegistry::FrameID frame_id =
266 AXTreeIDRegistry::GetInstance()->GetFrameID(params->tree_id); 262 AXTreeIDRegistry::GetInstance()->GetFrameID(params->tree_id);
267 content::RenderFrameHost* rfh = 263 content::RenderFrameHost* rfh =
268 content::RenderFrameHost::FromID(frame_id.first, frame_id.second); 264 content::RenderFrameHost::FromID(frame_id.first, frame_id.second);
269 if (!rfh) 265 if (!rfh)
270 return RespondNow(Error("unable to load tab")); 266 return RespondNow(Error("unable to load tab"));
271 267
272 content::WebContents* contents = 268 content::WebContents* contents =
273 content::WebContents::FromRenderFrameHost(rfh); 269 content::WebContents::FromRenderFrameHost(rfh);
274 AutomationWebContentsObserver::CreateForWebContents(contents); 270 AutomationWebContentsObserver::CreateForWebContents(contents);
275 contents->EnableTreeOnlyAccessibilityMode(); 271 contents->EnableTreeOnlyAccessibilityMode();
276 272
277 return RespondNow(NoArguments()); 273 return RespondNow(NoArguments());
278 #endif
279 return RespondNow(Error("enableFrame is only supported on Chrome OS"));
280 } 274 }
281 275
282 ExtensionFunction::ResponseAction 276 ExtensionFunction::ResponseAction
283 AutomationInternalPerformActionFunction::Run() { 277 AutomationInternalPerformActionFunction::Run() {
284 const AutomationInfo* automation_info = AutomationInfo::Get(extension()); 278 const AutomationInfo* automation_info = AutomationInfo::Get(extension());
285 EXTENSION_FUNCTION_VALIDATE(automation_info && automation_info->interact); 279 EXTENSION_FUNCTION_VALIDATE(automation_info && automation_info->interact);
286 280
287 using api::automation_internal::PerformAction::Params; 281 using api::automation_internal::PerformAction::Params;
288 scoped_ptr<Params> params(Params::Create(*args_)); 282 scoped_ptr<Params> params(Params::Create(*args_));
289 EXTENSION_FUNCTION_VALIDATE(params.get()); 283 EXTENSION_FUNCTION_VALIDATE(params.get());
290 284
291 if (params->args.tree_id == kDesktopTreeID) { 285 if (params->args.tree_id == kDesktopTreeID) {
292 #if defined(OS_CHROMEOS) 286 #if defined(OS_CHROMEOS)
293 return RouteActionToAdapter( 287 return RouteActionToAdapter(params.get(),
294 params.get(), AutomationManagerAsh::GetInstance()); 288 AutomationManagerAura::GetInstance());
295 #else 289 #else
296 NOTREACHED(); 290 NOTREACHED();
297 return RespondNow(Error("Unexpected action on desktop automation tree;" 291 return RespondNow(Error("Unexpected action on desktop automation tree;"
298 " platform does not support desktop automation")); 292 " platform does not support desktop automation"));
299 #endif // defined(OS_CHROMEOS) 293 #endif // defined(OS_CHROMEOS)
300 } 294 }
301 AXTreeIDRegistry::FrameID frame_id = 295 AXTreeIDRegistry::FrameID frame_id =
302 AXTreeIDRegistry::GetInstance()->GetFrameID(params->args.tree_id); 296 AXTreeIDRegistry::GetInstance()->GetFrameID(params->args.tree_id);
303 content::RenderFrameHost* rfh = 297 content::RenderFrameHost* rfh =
304 content::RenderFrameHost::FromID(frame_id.first, frame_id.second); 298 content::RenderFrameHost::FromID(frame_id.first, frame_id.second);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 break; 336 break;
343 } 337 }
344 default: 338 default:
345 NOTREACHED(); 339 NOTREACHED();
346 } 340 }
347 return RespondNow(NoArguments()); 341 return RespondNow(NoArguments());
348 } 342 }
349 343
350 ExtensionFunction::ResponseAction 344 ExtensionFunction::ResponseAction
351 AutomationInternalEnableDesktopFunction::Run() { 345 AutomationInternalEnableDesktopFunction::Run() {
352 #if defined(OS_CHROMEOS)
353 const AutomationInfo* automation_info = AutomationInfo::Get(extension()); 346 const AutomationInfo* automation_info = AutomationInfo::Get(extension());
354 if (!automation_info || !automation_info->desktop) 347 if (!automation_info || !automation_info->desktop)
355 return RespondNow(Error("desktop permission must be requested")); 348 return RespondNow(Error("desktop permission must be requested"));
356 349
357 AutomationManagerAsh::GetInstance()->Enable(browser_context()); 350 AutomationManagerAura::GetInstance()->Enable(browser_context());
358 return RespondNow(NoArguments()); 351 return RespondNow(NoArguments());
359 #else
360 return RespondNow(Error("getDesktop is unsupported by this platform"));
361 #endif // defined(OS_CHROMEOS)
362 } 352 }
363 353
364 // static 354 // static
365 int AutomationInternalQuerySelectorFunction::query_request_id_counter_ = 0; 355 int AutomationInternalQuerySelectorFunction::query_request_id_counter_ = 0;
366 356
367 ExtensionFunction::ResponseAction 357 ExtensionFunction::ResponseAction
368 AutomationInternalQuerySelectorFunction::Run() { 358 AutomationInternalQuerySelectorFunction::Run() {
369 const AutomationInfo* automation_info = AutomationInfo::Get(extension()); 359 const AutomationInfo* automation_info = AutomationInfo::Get(extension());
370 EXTENSION_FUNCTION_VALIDATE(automation_info); 360 EXTENSION_FUNCTION_VALIDATE(automation_info);
371 361
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 int result_acc_obj_id) { 393 int result_acc_obj_id) {
404 if (!error.empty()) { 394 if (!error.empty()) {
405 Respond(Error(error)); 395 Respond(Error(error));
406 return; 396 return;
407 } 397 }
408 398
409 Respond(OneArgument(new base::FundamentalValue(result_acc_obj_id))); 399 Respond(OneArgument(new base::FundamentalValue(result_acc_obj_id)));
410 } 400 }
411 401
412 } // namespace extensions 402 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698