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

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: Fix UAF 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 // TODO(dtseng): Limited to desktop tree for now pending out of proc iframes.
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 content::RenderFrameHost* rfh =
183 content::RenderFrameHost::FromID(frame_id.first, frame_id.second);
184 if (!rfh)
185 return RespondNow(Error("unable to load tab"));
186
187 content::WebContents* contents =
188 content::WebContents::FromRenderFrameHost(rfh);
189 AutomationWebContentsObserver::CreateForWebContents(contents);
190 contents->EnableTreeOnlyAccessibilityMode();
191
192 return RespondNow(NoArguments());
193 #endif
194 return RespondNow(Error("enableFrame is only supported on Chrome OS"));
195 }
171 196
172 ExtensionFunction::ResponseAction 197 ExtensionFunction::ResponseAction
173 AutomationInternalPerformActionFunction::Run() { 198 AutomationInternalPerformActionFunction::Run() {
174 const AutomationInfo* automation_info = AutomationInfo::Get(extension()); 199 const AutomationInfo* automation_info = AutomationInfo::Get(extension());
175 EXTENSION_FUNCTION_VALIDATE(automation_info && automation_info->interact); 200 EXTENSION_FUNCTION_VALIDATE(automation_info && automation_info->interact);
176 201
177 using api::automation_internal::PerformAction::Params; 202 using api::automation_internal::PerformAction::Params;
178 scoped_ptr<Params> params(Params::Create(*args_)); 203 scoped_ptr<Params> params(Params::Create(*args_));
179 EXTENSION_FUNCTION_VALIDATE(params.get()); 204 EXTENSION_FUNCTION_VALIDATE(params.get());
180 205
181 if (params->args.process_id == kDesktopProcessID && 206 if (params->args.tree_id == kDesktopTreeID) {
182 params->args.routing_id == kDesktopRoutingID) {
183 #if defined(OS_CHROMEOS) 207 #if defined(OS_CHROMEOS)
184 return RouteActionToAdapter( 208 return RouteActionToAdapter(
185 params.get(), AutomationManagerAsh::GetInstance()); 209 params.get(), AutomationManagerAsh::GetInstance());
186 #else 210 #else
187 NOTREACHED(); 211 NOTREACHED();
188 return RespondNow(Error("Unexpected action on desktop automation tree;" 212 return RespondNow(Error("Unexpected action on desktop automation tree;"
189 " platform does not support desktop automation")); 213 " platform does not support desktop automation"));
190 #endif // defined(OS_CHROMEOS) 214 #endif // defined(OS_CHROMEOS)
191 } 215 }
216 AXTreeIDRegistry::FrameID frame_id =
217 AXTreeIDRegistry::GetInstance()->GetFrameID(params->args.tree_id);
192 content::RenderFrameHost* rfh = 218 content::RenderFrameHost* rfh =
193 content::RenderFrameHost::FromID(params->args.process_id, 219 content::RenderFrameHost::FromID(frame_id.first, frame_id.second);
194 params->args.routing_id);
195 if (!rfh) 220 if (!rfh)
196 return RespondNow(Error("Ignoring action on destroyed node")); 221 return RespondNow(Error("Ignoring action on destroyed node"));
197 222
198 const content::WebContents* contents = 223 const content::WebContents* contents =
199 content::WebContents::FromRenderFrameHost(rfh); 224 content::WebContents::FromRenderFrameHost(rfh);
200 if (!CanRequestAutomation(extension(), automation_info, contents)) { 225 if (!CanRequestAutomation(extension(), automation_info, contents)) {
201 return RespondNow( 226 return RespondNow(
202 Error(kCannotRequestAutomationOnPage, contents->GetURL().spec())); 227 Error(kCannotRequestAutomationOnPage, contents->GetURL().spec()));
203 } 228 }
204 229
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 return RespondNow(Error("desktop permission must be requested")); 270 return RespondNow(Error("desktop permission must be requested"));
246 271
247 AutomationManagerAsh::GetInstance()->Enable(browser_context()); 272 AutomationManagerAsh::GetInstance()->Enable(browser_context());
248 return RespondNow(NoArguments()); 273 return RespondNow(NoArguments());
249 #else 274 #else
250 return RespondNow(Error("getDesktop is unsupported by this platform")); 275 return RespondNow(Error("getDesktop is unsupported by this platform"));
251 #endif // defined(OS_CHROMEOS) 276 #endif // defined(OS_CHROMEOS)
252 } 277 }
253 278
254 } // namespace extensions 279 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698