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

Side by Side Diff: extensions/renderer/api/automation/automation_api_helper.cc

Issue 655273005: Implement AutomationNode.querySelector(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Address comments 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
(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 request_id,
38 int acc_obj_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 =
Devlin 2014/10/29 21:23:44 I don't know blink accessibility code well enough
aboxhall 2014/10/30 18:34:18 Acknowledged.
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();
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 = result.accessibilityObject();
63 if (!ax_obj.isDetached())
64 result_acc_obj_id = ax_obj.axID();
65 }
66 Send(new ExtensionHostMsg_AutomationQuerySelector_Result(
67 routing_id(), request_id, "", result_acc_obj_id));
68 }
69
70 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698