summaryrefslogtreecommitdiffstats
path: root/extensions/renderer/api
diff options
context:
space:
mode:
authoraboxhall <aboxhall@chromium.org>2014-11-05 18:03:05 -0800
committerCommit bot <commit-bot@chromium.org>2014-11-06 02:04:15 +0000
commit7abfb3db96dc7d87c9f1282b5fc81328ec9c787c (patch)
treee371fa0db7b2963765dd8e8ff4a4b7cce18e19db /extensions/renderer/api
parentfb2145ccc9bf28832d63f16e5deeb727aa18b7e9 (diff)
downloadchromium_src-7abfb3db96dc7d87c9f1282b5fc81328ec9c787c.zip
chromium_src-7abfb3db96dc7d87c9f1282b5fc81328ec9c787c.tar.gz
chromium_src-7abfb3db96dc7d87c9f1282b5fc81328ec9c787c.tar.bz2
Implement AutomationNode.querySelector().
BUG=404710 Review URL: https://codereview.chromium.org/655273005 Cr-Commit-Position: refs/heads/master@{#302944}
Diffstat (limited to 'extensions/renderer/api')
-rw-r--r--extensions/renderer/api/automation/automation_api_helper.cc90
-rw-r--r--extensions/renderer/api/automation/automation_api_helper.h33
2 files changed, 123 insertions, 0 deletions
diff --git a/extensions/renderer/api/automation/automation_api_helper.cc b/extensions/renderer/api/automation/automation_api_helper.cc
new file mode 100644
index 0000000..ab10682
--- /dev/null
+++ b/extensions/renderer/api/automation/automation_api_helper.cc
@@ -0,0 +1,90 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "extensions/renderer/api/automation/automation_api_helper.h"
+
+#include "content/public/renderer/render_view.h"
+#include "extensions/common/extension_messages.h"
+#include "third_party/WebKit/public/web/WebAXObject.h"
+#include "third_party/WebKit/public/web/WebDocument.h"
+#include "third_party/WebKit/public/web/WebElement.h"
+#include "third_party/WebKit/public/web/WebExceptionCode.h"
+#include "third_party/WebKit/public/web/WebFrame.h"
+#include "third_party/WebKit/public/web/WebNode.h"
+#include "third_party/WebKit/public/web/WebView.h"
+
+namespace extensions {
+
+AutomationApiHelper::AutomationApiHelper(content::RenderView* render_view)
+ : content::RenderViewObserver(render_view) {
+}
+
+AutomationApiHelper::~AutomationApiHelper() {
+}
+
+bool AutomationApiHelper::OnMessageReceived(const IPC::Message& message) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(AutomationApiHelper, message)
+ IPC_MESSAGE_HANDLER(ExtensionMsg_AutomationQuerySelector, OnQuerySelector)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+}
+
+void AutomationApiHelper::OnQuerySelector(int request_id,
+ int acc_obj_id,
+ const base::string16& selector) {
+ ExtensionHostMsg_AutomationQuerySelector_Error error;
+ if (!render_view() || !render_view()->GetWebView() ||
+ !render_view()->GetWebView()->mainFrame()) {
+ error.value = ExtensionHostMsg_AutomationQuerySelector_Error::kNoMainFrame;
+ Send(new ExtensionHostMsg_AutomationQuerySelector_Result(
+ routing_id(), request_id, error, 0));
+ return;
+ }
+ blink::WebDocument document =
+ render_view()->GetWebView()->mainFrame()->document();
+ if (document.isNull()) {
+ error.value =
+ ExtensionHostMsg_AutomationQuerySelector_Error::kNoDocument;
+ Send(new ExtensionHostMsg_AutomationQuerySelector_Result(
+ routing_id(), request_id, error, 0));
+ return;
+ }
+ blink::WebNode start_node = document;
+ if (acc_obj_id > 0) {
+ blink::WebAXObject start_acc_obj =
+ document.accessibilityObjectFromID(acc_obj_id);
+ if (start_acc_obj.isNull()) {
+ error.value =
+ ExtensionHostMsg_AutomationQuerySelector_Error::kNodeDestroyed;
+ Send(new ExtensionHostMsg_AutomationQuerySelector_Result(
+ routing_id(), request_id, error, 0));
+ return;
+ }
+
+ start_node = start_acc_obj.node();
+ while (start_node.isNull()) {
+ start_acc_obj = start_acc_obj.parentObject();
+ start_node = start_acc_obj.node();
+ }
+ }
+ blink::WebString web_selector(selector);
+ blink::WebExceptionCode ec = 0;
+ blink::WebElement result_element = start_node.querySelector(web_selector, ec);
+ int result_acc_obj_id = 0;
+ if (!ec && !result_element.isNull()) {
+ blink::WebAXObject result_acc_obj = result_element.accessibilityObject();
+ if (!result_acc_obj.isDetached()) {
+ while (result_acc_obj.accessibilityIsIgnored())
+ result_acc_obj = result_acc_obj.parentObject();
+
+ result_acc_obj_id = result_acc_obj.axID();
+ }
+ }
+ Send(new ExtensionHostMsg_AutomationQuerySelector_Result(
+ routing_id(), request_id, error, result_acc_obj_id));
+}
+
+} // namespace extensions
diff --git a/extensions/renderer/api/automation/automation_api_helper.h b/extensions/renderer/api/automation/automation_api_helper.h
new file mode 100644
index 0000000..0f1c8b0
--- /dev/null
+++ b/extensions/renderer/api/automation/automation_api_helper.h
@@ -0,0 +1,33 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef EXTENSIONS_RENDERER_API_AUTOMATION_AUTOMATION_API_HELPER_H_
+#define EXTENSIONS_RENDERER_API_AUTOMATION_AUTOMATION_API_HELPER_H_
+
+#include "base/strings/string16.h"
+#include "content/public/renderer/render_view_observer.h"
+
+namespace extensions {
+
+// Renderer-side implementation for chrome.automation API (for the few pieces
+// which aren't built in to the existing accessibility system).
+class AutomationApiHelper : public content::RenderViewObserver {
+ public:
+ explicit AutomationApiHelper(content::RenderView* render_view);
+ ~AutomationApiHelper() override;
+
+ private:
+ // RenderViewObserver implementation.
+ bool OnMessageReceived(const IPC::Message& message) override;
+
+ void OnQuerySelector(int acc_obj_id,
+ int request_id,
+ const base::string16& selector);
+
+ DISALLOW_COPY_AND_ASSIGN(AutomationApiHelper);
+};
+
+} // namespace extensions
+
+#endif // EXTENSIONS_RENDERER_API_AUTOMATION_AUTOMATION_API_HELPER_H_