OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "extensions/renderer/api/automation/automation_api_helper.h" | |
6 | |
7 #include "content/public/renderer/render_view.h" | |
8 #include "extensions/common/extension_messages.h" | |
9 #include "third_party/WebKit/public/web/WebAXObject.h" | |
10 #include "third_party/WebKit/public/web/WebDocument.h" | |
11 #include "third_party/WebKit/public/web/WebElement.h" | |
12 #include "third_party/WebKit/public/web/WebExceptionCode.h" | |
13 #include "third_party/WebKit/public/web/WebFrame.h" | |
14 #include "third_party/WebKit/public/web/WebNode.h" | |
15 #include "third_party/WebKit/public/web/WebView.h" | |
16 | |
17 namespace extensions { | |
18 | |
19 AutomationApiHelper::AutomationApiHelper(content::RenderView* render_view) | |
20 : content::RenderViewObserver(render_view) { | |
21 } | |
22 | |
23 AutomationApiHelper::~AutomationApiHelper() { | |
24 } | |
25 | |
26 bool AutomationApiHelper::OnMessageReceived(const IPC::Message& message) { | |
27 bool handled = true; | |
28 IPC_BEGIN_MESSAGE_MAP(AutomationApiHelper, message) | |
29 IPC_MESSAGE_HANDLER(ExtensionMsg_AutomationQuerySelector, OnQuerySelector) | |
30 IPC_MESSAGE_UNHANDLED(handled = false) | |
31 IPC_END_MESSAGE_MAP() | |
32 return handled; | |
33 } | |
34 | |
35 void AutomationApiHelper::OnQuerySelector(int request_id, | |
36 int acc_obj_id, | |
37 const base::string16& selector) { | |
38 if (!render_view() || !render_view()->GetWebView() || | |
39 !render_view()->GetWebView()->mainFrame()) { | |
40 Send(new ExtensionHostMsg_AutomationQuerySelector_Result( | |
41 routing_id(), request_id, "No main frame", 0)); | |
42 return; | |
43 } | |
44 blink::WebDocument document = | |
45 render_view()->GetWebView()->mainFrame()->document(); | |
46 if (document.isNull()) { | |
47 Send(new ExtensionHostMsg_AutomationQuerySelector_Result( | |
48 routing_id(), request_id, "No document", 0)); | |
49 return; | |
50 } | |
51 blink::WebNode node = document; | |
52 if (acc_obj_id > 0) { | |
53 blink::WebAXObject obj = document.accessibilityObjectFromID(acc_obj_id); | |
54 node = obj.node(); | |
55 while (node.isNull()) { | |
dmazzoni
2014/10/30 23:32:42
I'm worried this could give you an endless loop if
aboxhall
2014/10/31 20:32:22
Good point. I think it's actually an error if that
| |
56 obj = obj.parentObject(); | |
57 node = obj.node(); | |
58 } | |
59 } | |
60 blink::WebString web_selector(selector); | |
61 blink::WebExceptionCode ec = 0; | |
62 blink::WebElement result = node.querySelector(web_selector, ec); | |
63 int result_acc_obj_id = 0; | |
64 if (!ec && !result.isNull()) { | |
65 blink::WebAXObject ax_obj = result.accessibilityObject(); | |
66 if (!ax_obj.isDetached()) { | |
67 while (ax_obj.accessibilityIsIgnored()) | |
68 ax_obj = ax_obj.parentObject(); | |
dmazzoni
2014/10/30 23:32:42
nit: you can just call ax_obj.parentObjectUnignore
aboxhall
2014/10/31 20:32:22
It's not in the public api ;_;
| |
69 | |
70 result_acc_obj_id = ax_obj.axID(); | |
71 } | |
72 } | |
73 Send(new ExtensionHostMsg_AutomationQuerySelector_Result( | |
74 routing_id(), request_id, "", result_acc_obj_id)); | |
75 } | |
76 | |
77 } // namespace extensions | |
OLD | NEW |