Index: content/browser/web_contents/web_contents_android.cc |
diff --git a/content/browser/web_contents/web_contents_android.cc b/content/browser/web_contents/web_contents_android.cc |
index 4afd1e8ef374a23e17328d889ce461cb213edc60..b666d3de7fe9433b61e21ce42e5d899f4a61b42b 100644 |
--- a/content/browser/web_contents/web_contents_android.cc |
+++ b/content/browser/web_contents/web_contents_android.cc |
@@ -5,10 +5,13 @@ |
#include "content/browser/web_contents/web_contents_android.h" |
#include "base/android/jni_android.h" |
+#include "base/android/jni_array.h" |
#include "base/android/jni_string.h" |
#include "base/command_line.h" |
#include "base/json/json_writer.h" |
#include "base/logging.h" |
+#include "content/browser/accessibility/browser_accessibility_android.h" |
+#include "content/browser/accessibility/browser_accessibility_manager.h" |
#include "content/browser/android/interstitial_page_delegate_android.h" |
#include "content/browser/frame_host/interstitial_page_impl.h" |
#include "content/browser/media/android/browser_media_player_manager.h" |
@@ -25,12 +28,17 @@ |
#include "content/public/common/content_switches.h" |
#include "jni/WebContentsImpl_jni.h" |
#include "net/android/network_library.h" |
+#include "ui/accessibility/ax_node_data.h" |
using base::android::AttachCurrentThread; |
using base::android::ConvertJavaStringToUTF8; |
using base::android::ConvertJavaStringToUTF16; |
using base::android::ConvertUTF8ToJavaString; |
+using base::android::ConvertUTF16ToJavaString; |
using base::android::ScopedJavaGlobalRef; |
+using base::android::ToJavaIntArray; |
+ |
+namespace content { |
namespace { |
@@ -40,14 +48,55 @@ void JavaScriptResultCallback(const ScopedJavaGlobalRef<jobject>& callback, |
std::string json; |
base::JSONWriter::Write(result, &json); |
ScopedJavaLocalRef<jstring> j_json = ConvertUTF8ToJavaString(env, json); |
- content::Java_WebContentsImpl_onEvaluateJavaScriptResult( |
+ Java_WebContentsImpl_onEvaluateJavaScriptResult( |
env, j_json.obj(), callback.obj()); |
} |
-void ReleaseAllMediaPlayers(content::WebContents* web_contents, |
- content::RenderFrameHost* render_frame_host) { |
- content::BrowserMediaPlayerManager* manager = |
- static_cast<content::WebContentsImpl*>(web_contents)-> |
+ScopedJavaLocalRef<jobject> WalkAXTreeDepthFirst(JNIEnv* env, |
+ BrowserAccessibilityAndroid* node) { |
+ |
+ ScopedJavaLocalRef<jstring> j_text = |
+ ConvertUTF16ToJavaString(env, node->GetText()); |
+ ScopedJavaLocalRef<jstring> j_class = |
+ ConvertUTF8ToJavaString(env, node->GetClassName()); |
+ const gfx::Rect& location = node->GetLocation(); |
+ ScopedJavaLocalRef<jobject> j_node = |
+ Java_WebContentsImpl_createAccessibilitySnapshotNode(env, |
+ location.x(), location.y(), node->GetScrollX(), |
+ node->GetScrollY(), location.width(), location.height(), |
+ j_text.obj(), j_class.obj()); |
+ |
+ for(uint32 i = 0; i < node->PlatformChildCount(); i++) { |
+ BrowserAccessibilityAndroid* child = |
+ static_cast<BrowserAccessibilityAndroid*>( |
+ node->PlatformGetChild(i)); |
+ Java_WebContentsImpl_addAccessibilityNodeAsChild(env, |
+ j_node.obj(), WalkAXTreeDepthFirst(env, child).obj()); |
+ } |
+ return j_node; |
+} |
+ |
+// Walks over the AXTreeUpdate and creates a light weight snapshot. |
+void AXTreeSnapshotCallback(const ScopedJavaGlobalRef<jobject>& callback, |
+ const ui::AXTreeUpdate& result) { |
+ JNIEnv* env = base::android::AttachCurrentThread(); |
+ if (result.nodes.empty()) { |
+ Java_WebContentsImpl_onAccessibilitySnapshot(env, nullptr, callback.obj()); |
+ return; |
+ } |
+ scoped_ptr<BrowserAccessibilityManager> manager( |
+ BrowserAccessibilityManager::Create(result, nullptr)); |
+ BrowserAccessibilityAndroid* root = |
+ static_cast<BrowserAccessibilityAndroid*>(manager->GetRoot()); |
+ ScopedJavaLocalRef<jobject> j_root = WalkAXTreeDepthFirst(env, root); |
+ Java_WebContentsImpl_onAccessibilitySnapshot( |
+ env, j_root.obj(), callback.obj()); |
+} |
+ |
+void ReleaseAllMediaPlayers(WebContents* web_contents, |
+ RenderFrameHost* render_frame_host) { |
+ BrowserMediaPlayerManager* manager = |
+ static_cast<WebContentsImpl*>(web_contents)-> |
media_web_contents_observer()->GetMediaPlayerManager( |
render_frame_host); |
if (manager) |
@@ -56,8 +105,6 @@ void ReleaseAllMediaPlayers(content::WebContents* web_contents, |
} // namespace |
-namespace content { |
- |
// static |
WebContents* WebContents::FromJavaWebContents( |
jobject jweb_contents_android) { |
@@ -83,7 +130,7 @@ static void DestroyWebContents(JNIEnv* env, |
if (!web_contents_android) |
return; |
- content::WebContents* web_contents = web_contents_android->web_contents(); |
+ WebContents* web_contents = web_contents_android->web_contents(); |
if (!web_contents) |
return; |
@@ -475,7 +522,7 @@ void WebContentsAndroid::EvaluateJavaScript(JNIEnv* env, |
// base::Callback. |
ScopedJavaGlobalRef<jobject> j_callback; |
j_callback.Reset(env, callback); |
- content::RenderFrameHost::JavaScriptResultCallback js_callback = |
+ RenderFrameHost::JavaScriptResultCallback js_callback = |
base::Bind(&JavaScriptResultCallback, j_callback); |
web_contents_->GetMainFrame()->ExecuteJavaScript( |
@@ -498,7 +545,7 @@ void WebContentsAndroid::AddMessageToDevToolsConsole(JNIEnv* env, |
jboolean WebContentsAndroid::HasAccessedInitialDocument( |
JNIEnv* env, |
jobject jobj) { |
- return static_cast<content::WebContentsImpl*>(web_contents_)-> |
+ return static_cast<WebContentsImpl*>(web_contents_)-> |
HasAccessedInitialDocument(); |
} |
@@ -506,4 +553,18 @@ jint WebContentsAndroid::GetThemeColor(JNIEnv* env, jobject obj) { |
return web_contents_->GetThemeColor(); |
} |
+void WebContentsAndroid::RequestAccessibilitySnapshot(JNIEnv* env, |
+ jobject obj, |
+ jobject callback) { |
+ // Secure the Java callback in a scoped object and give ownership of it to the |
+ // base::Callback. |
+ ScopedJavaGlobalRef<jobject> j_callback; |
+ j_callback.Reset(env, callback); |
+ WebContentsImpl::AXTreeSnapshotCallback snapshot_callback = |
+ base::Bind(&AXTreeSnapshotCallback, j_callback); |
+ |
+ static_cast<WebContentsImpl*>(web_contents_)->RequestAXTreeSnapshot( |
+ snapshot_callback); |
+} |
+ |
} // namespace content |