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 <string> | |
8 | |
9 #include "content/public/renderer/render_view.h" | |
10 #include "extensions/common/extension_messages.h" | |
11 #include "third_party/WebKit/public/web/WebAXObject.h" | |
12 #include "third_party/WebKit/public/web/WebDocument.h" | |
13 #include "third_party/WebKit/public/web/WebElement.h" | |
14 #include "third_party/WebKit/public/web/WebExceptionCode.h" | |
15 #include "third_party/WebKit/public/web/WebFrame.h" | |
16 #include "third_party/WebKit/public/web/WebNode.h" | |
17 #include "third_party/WebKit/public/web/WebView.h" | |
18 | |
19 namespace extensions { | |
20 | |
21 AutomationApiHelper::AutomationApiHelper(content::RenderView* render_view) | |
22 : content::RenderViewObserver(render_view) { | |
23 } | |
24 | |
25 AutomationApiHelper::~AutomationApiHelper() { | |
26 } | |
27 | |
28 bool AutomationApiHelper::OnMessageReceived(const IPC::Message& message) { | |
29 bool handled = true; | |
30 IPC_BEGIN_MESSAGE_MAP(AutomationApiHelper, message) | |
31 IPC_MESSAGE_HANDLER(ExtensionMsg_AutomationQuerySelector, OnQuerySelector) | |
32 IPC_MESSAGE_UNHANDLED(handled = false) | |
33 IPC_END_MESSAGE_MAP() | |
34 return handled; | |
35 } | |
36 | |
37 void AutomationApiHelper::OnQuerySelector(int acc_obj_id, | |
38 int request_id, | |
39 const base::string16& selector) { | |
40 if (!render_view() || !render_view()->GetWebView() || | |
41 !render_view()->GetWebView()->mainFrame()) { | |
42 LOG(WARNING) << "No main frame"; | |
43 // TODO(aboxhall): return error result | |
44 } | |
45 blink::WebDocument document = | |
46 render_view()->GetWebView()->mainFrame()->document(); | |
47 if (document.isNull()) { | |
48 LOG(WARNING) << "Document is null"; | |
49 // TODO(aboxhall): return error result | |
50 } | |
51 blink::WebNode node = document; | |
52 if (acc_obj_id > 0) { | |
53 const blink::WebAXObject& obj = | |
54 document.accessibilityObjectFromID(acc_obj_id); | |
55 node = obj.node(); | |
dmazzoni
2014/10/29 00:00:10
One subtle nuance here - not every AXObject corres
aboxhall
2014/10/30 18:36:44
PTAL - I've tried to address this.
| |
56 } | |
57 blink::WebString web_selector(selector); | |
58 blink::WebExceptionCode ec = 0; | |
59 blink::WebElement result = node.querySelector(web_selector, ec); | |
60 int result_acc_obj_id = 0; | |
61 if (!ec && !result.isNull()) { | |
62 blink::WebAXObject ax_obj = document.accessibilityObjectFromNode(result); | |
63 result_acc_obj_id = ax_obj.axID(); | |
dmazzoni
2014/10/27 18:47:36
Need to check if ax_obj is valid - the best way is
aboxhall
2014/10/28 23:43:57
Done.
| |
64 } | |
65 Send(new ExtensionHostMsg_AutomationQuerySelector_Result( | |
66 routing_id(), request_id, "", result_acc_obj_id)); | |
67 } | |
68 | |
69 } // namespace extensions | |
OLD | NEW |