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

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

Issue 667713006: Implement automatic load of composed/embedded automation trees (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkcr
Patch Set: Created 6 years, 1 month 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/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "chrome/browser/accessibility/ax_tree_id_registry.h"
10 #include "chrome/browser/extensions/api/automation_internal/automation_action_ad apter.h" 11 #include "chrome/browser/extensions/api/automation_internal/automation_action_ad apter.h"
11 #include "chrome/browser/extensions/api/automation_internal/automation_util.h" 12 #include "chrome/browser/extensions/api/automation_internal/automation_util.h"
12 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" 13 #include "chrome/browser/extensions/api/tabs/tabs_constants.h"
13 #include "chrome/browser/extensions/extension_tab_util.h" 14 #include "chrome/browser/extensions/extension_tab_util.h"
14 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" 17 #include "chrome/browser/ui/tabs/tab_strip_model.h"
17 #include "chrome/common/extensions/api/automation_internal.h" 18 #include "chrome/common/extensions/api/automation_internal.h"
18 #include "chrome/common/extensions/manifest_handlers/automation.h" 19 #include "chrome/common/extensions/manifest_handlers/automation.h"
19 #include "content/public/browser/ax_event_notification_details.h" 20 #include "content/public/browser/ax_event_notification_details.h"
21 #include "content/public/browser/browser_accessibility_state.h"
20 #include "content/public/browser/render_frame_host.h" 22 #include "content/public/browser/render_frame_host.h"
21 #include "content/public/browser/render_process_host.h" 23 #include "content/public/browser/render_process_host.h"
22 #include "content/public/browser/render_widget_host.h" 24 #include "content/public/browser/render_widget_host.h"
23 #include "content/public/browser/render_widget_host_view.h" 25 #include "content/public/browser/render_widget_host_view.h"
24 #include "content/public/browser/web_contents.h" 26 #include "content/public/browser/web_contents.h"
25 #include "extensions/common/permissions/permissions_data.h" 27 #include "extensions/common/permissions/permissions_data.h"
26 28
27 #if defined(OS_CHROMEOS) 29 #if defined(OS_CHROMEOS)
28 #include "chrome/browser/ui/ash/accessibility/automation_manager_ash.h" 30 #include "chrome/browser/ui/ash/accessibility/automation_manager_ash.h"
29 #endif 31 #endif
30 32
31 namespace extensions { 33 namespace extensions {
32 class AutomationWebContentsObserver; 34 class AutomationWebContentsObserver;
33 } // namespace extensions 35 } // namespace extensions
34 36
35 DEFINE_WEB_CONTENTS_USER_DATA_KEY(extensions::AutomationWebContentsObserver); 37 DEFINE_WEB_CONTENTS_USER_DATA_KEY(extensions::AutomationWebContentsObserver);
36 38
37 namespace { 39 namespace {
38 const int kDesktopProcessID = 0; 40 const int kDesktopTreeID = 0;
39 const int kDesktopRoutingID = 0;
40
41 const char kCannotRequestAutomationOnPage[] = 41 const char kCannotRequestAutomationOnPage[] =
42 "Cannot request automation tree on url \"*\". " 42 "Cannot request automation tree on url \"*\". "
43 "Extension manifest must request permission to access this host."; 43 "Extension manifest must request permission to access this host.";
44 } // namespace 44 } // namespace
45 45
46 namespace extensions { 46 namespace extensions {
47 47
48 bool CanRequestAutomation(const Extension* extension, 48 bool CanRequestAutomation(const Extension* extension,
49 const AutomationInfo* automation_info, 49 const AutomationInfo* automation_info,
50 const content::WebContents* contents) { 50 const content::WebContents* contents) {
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 content::RenderFrameHost* rfh = contents->GetMainFrame(); 157 content::RenderFrameHost* rfh = contents->GetMainFrame();
158 if (!rfh) 158 if (!rfh)
159 return RespondNow(Error("Could not enable accessibility for active tab")); 159 return RespondNow(Error("Could not enable accessibility for active tab"));
160 160
161 if (!CanRequestAutomation(extension(), automation_info, contents)) { 161 if (!CanRequestAutomation(extension(), automation_info, contents)) {
162 return RespondNow( 162 return RespondNow(
163 Error(kCannotRequestAutomationOnPage, contents->GetURL().spec())); 163 Error(kCannotRequestAutomationOnPage, contents->GetURL().spec()));
164 } 164 }
165 AutomationWebContentsObserver::CreateForWebContents(contents); 165 AutomationWebContentsObserver::CreateForWebContents(contents);
166 contents->EnableTreeOnlyAccessibilityMode(); 166 contents->EnableTreeOnlyAccessibilityMode();
167 return RespondNow( 167 int ax_tree_id = AXTreeIDRegistry::GetInstance()->GetOrCreateAXTreeID(
168 ArgumentList(api::automation_internal::EnableTab::Results::Create( 168 rfh->GetProcess()->GetID(), rfh->GetRoutingID());
169 rfh->GetProcess()->GetID(), rfh->GetRoutingID()))); 169 return RespondNow(ArgumentList(
170 } 170 api::automation_internal::EnableTab::Results::Create(ax_tree_id)));
171 }
172
173 ExtensionFunction::ResponseAction AutomationInternalEnableFrameFunction::Run() {
174 // Limited to desktop tree for now.
aboxhall 2014/11/03 17:15:48 TODO for the circumstances under which it won't be
David Tseng 2014/11/03 19:31:52 Done.
175 #if defined(OS_CHROMEOS)
176 using api::automation_internal::EnableFrame::Params;
177
178 scoped_ptr<Params> params(Params::Create(*args_));
179 EXTENSION_FUNCTION_VALIDATE(params.get());
180 AXTreeIDRegistry::FrameID frame_id =
181 AXTreeIDRegistry::GetInstance()->GetFrameID(params->tree_id);
182 LOG(ERROR) << "trying!" << frame_id.first << " " << frame_id.second;
183 content::RenderFrameHost* rfh =
184 content::RenderFrameHost::FromID(frame_id.first, frame_id.second);
185 if (!rfh)
186 return RespondNow(Error("unable to load tab"));
187
188 content::WebContents* contents =
189 content::WebContents::FromRenderFrameHost(rfh);
190 AutomationWebContentsObserver::CreateForWebContents(contents);
191 contents->EnableTreeOnlyAccessibilityMode();
192
193 return RespondNow(NoArguments());
194 #endif
195 return RespondNow(Error("enableFrame is only supported on Chrome OS"));
196 }
171 197
172 ExtensionFunction::ResponseAction 198 ExtensionFunction::ResponseAction
173 AutomationInternalPerformActionFunction::Run() { 199 AutomationInternalPerformActionFunction::Run() {
174 const AutomationInfo* automation_info = AutomationInfo::Get(extension()); 200 const AutomationInfo* automation_info = AutomationInfo::Get(extension());
175 EXTENSION_FUNCTION_VALIDATE(automation_info && automation_info->interact); 201 EXTENSION_FUNCTION_VALIDATE(automation_info && automation_info->interact);
176 202
177 using api::automation_internal::PerformAction::Params; 203 using api::automation_internal::PerformAction::Params;
178 scoped_ptr<Params> params(Params::Create(*args_)); 204 scoped_ptr<Params> params(Params::Create(*args_));
179 EXTENSION_FUNCTION_VALIDATE(params.get()); 205 EXTENSION_FUNCTION_VALIDATE(params.get());
180 206
181 if (params->args.process_id == kDesktopProcessID && 207 if (params->args.tree_id == kDesktopTreeID) {
182 params->args.routing_id == kDesktopRoutingID) {
183 #if defined(OS_CHROMEOS) 208 #if defined(OS_CHROMEOS)
184 return RouteActionToAdapter( 209 return RouteActionToAdapter(
185 params.get(), AutomationManagerAsh::GetInstance()); 210 params.get(), AutomationManagerAsh::GetInstance());
186 #else 211 #else
187 NOTREACHED(); 212 NOTREACHED();
188 return RespondNow(Error("Unexpected action on desktop automation tree;" 213 return RespondNow(Error("Unexpected action on desktop automation tree;"
189 " platform does not support desktop automation")); 214 " platform does not support desktop automation"));
190 #endif // defined(OS_CHROMEOS) 215 #endif // defined(OS_CHROMEOS)
191 } 216 }
217 AXTreeIDRegistry::FrameID frame_id =
218 AXTreeIDRegistry::GetInstance()->GetFrameID(params->args.tree_id);
192 content::RenderFrameHost* rfh = 219 content::RenderFrameHost* rfh =
193 content::RenderFrameHost::FromID(params->args.process_id, 220 content::RenderFrameHost::FromID(frame_id.first, frame_id.second);
194 params->args.routing_id);
195 if (!rfh) 221 if (!rfh)
196 return RespondNow(Error("Ignoring action on destroyed node")); 222 return RespondNow(Error("Ignoring action on destroyed node"));
197 223
198 const content::WebContents* contents = 224 const content::WebContents* contents =
199 content::WebContents::FromRenderFrameHost(rfh); 225 content::WebContents::FromRenderFrameHost(rfh);
200 if (!CanRequestAutomation(extension(), automation_info, contents)) { 226 if (!CanRequestAutomation(extension(), automation_info, contents)) {
201 return RespondNow( 227 return RespondNow(
202 Error(kCannotRequestAutomationOnPage, contents->GetURL().spec())); 228 Error(kCannotRequestAutomationOnPage, contents->GetURL().spec()));
203 } 229 }
204 230
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 return RespondNow(Error("desktop permission must be requested")); 271 return RespondNow(Error("desktop permission must be requested"));
246 272
247 AutomationManagerAsh::GetInstance()->Enable(browser_context()); 273 AutomationManagerAsh::GetInstance()->Enable(browser_context());
248 return RespondNow(NoArguments()); 274 return RespondNow(NoArguments());
249 #else 275 #else
250 return RespondNow(Error("getDesktop is unsupported by this platform")); 276 return RespondNow(Error("getDesktop is unsupported by this platform"));
251 #endif // defined(OS_CHROMEOS) 277 #endif // defined(OS_CHROMEOS)
252 } 278 }
253 279
254 } // namespace extensions 280 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698