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 ExtensionHostMsg_AutomationQuerySelector_Error error; | |
39 if (!render_view() || !render_view()->GetWebView() || | |
40 !render_view()->GetWebView()->mainFrame()) { | |
41 error.value = ExtensionHostMsg_AutomationQuerySelector_Error::kNoMainFrame; | |
42 Send(new ExtensionHostMsg_AutomationQuerySelector_Result( | |
43 routing_id(), request_id, error, 0)); | |
44 return; | |
45 } | |
46 blink::WebDocument document = | |
47 render_view()->GetWebView()->mainFrame()->document(); | |
48 if (document.isNull()) { | |
49 error.value = | |
50 ExtensionHostMsg_AutomationQuerySelector_Error::kNoDocument; | |
51 Send(new ExtensionHostMsg_AutomationQuerySelector_Result( | |
52 routing_id(), request_id, error, 0)); | |
53 return; | |
54 } | |
55 blink::WebNode node = document; | |
56 if (acc_obj_id > 0) { | |
57 blink::WebAXObject obj = document.accessibilityObjectFromID(acc_obj_id); | |
palmer
2014/11/04 19:39:22
Nit: "accessibility object" is sometimes "acc_obj"
aboxhall
2014/11/04 22:13:49
Done.
| |
58 if (obj.isNull()) { | |
59 error.value = | |
60 ExtensionHostMsg_AutomationQuerySelector_Error::kNodeDestroyed; | |
61 Send(new ExtensionHostMsg_AutomationQuerySelector_Result( | |
62 routing_id(), request_id, error, 0)); | |
63 return; | |
64 } | |
65 | |
66 node = obj.node(); | |
67 while (node.isNull()) { | |
68 obj = obj.parentObject(); | |
69 node = obj.node(); | |
70 } | |
71 } | |
72 blink::WebString web_selector(selector); | |
73 blink::WebExceptionCode ec = 0; | |
74 blink::WebElement result = node.querySelector(web_selector, ec); | |
75 int result_acc_obj_id = 0; | |
76 if (!ec && !result.isNull()) { | |
77 blink::WebAXObject ax_obj = result.accessibilityObject(); | |
78 if (!ax_obj.isDetached()) { | |
79 while (ax_obj.accessibilityIsIgnored()) | |
80 ax_obj = ax_obj.parentObject(); | |
81 | |
82 result_acc_obj_id = ax_obj.axID(); | |
83 } | |
84 } | |
85 Send(new ExtensionHostMsg_AutomationQuerySelector_Result( | |
86 routing_id(), request_id, error, result_acc_obj_id)); | |
87 } | |
88 | |
89 } // namespace extensions | |
OLD | NEW |