OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/web_contents/web_contents_android.h" | 5 #include "content/browser/web_contents/web_contents_android.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 | 65 |
66 void JavaScriptResultCallback(const ScopedJavaGlobalRef<jobject>& callback, | 66 void JavaScriptResultCallback(const ScopedJavaGlobalRef<jobject>& callback, |
67 const base::Value* result) { | 67 const base::Value* result) { |
68 JNIEnv* env = base::android::AttachCurrentThread(); | 68 JNIEnv* env = base::android::AttachCurrentThread(); |
69 std::string json; | 69 std::string json; |
70 base::JSONWriter::Write(*result, &json); | 70 base::JSONWriter::Write(*result, &json); |
71 ScopedJavaLocalRef<jstring> j_json = ConvertUTF8ToJavaString(env, json); | 71 ScopedJavaLocalRef<jstring> j_json = ConvertUTF8ToJavaString(env, json); |
72 Java_WebContentsImpl_onEvaluateJavaScriptResult(env, j_json, callback); | 72 Java_WebContentsImpl_onEvaluateJavaScriptResult(env, j_json, callback); |
73 } | 73 } |
74 | 74 |
| 75 void SmartClipCallback(const ScopedJavaGlobalRef<jobject>& callback, |
| 76 const base::string16& text, |
| 77 const base::string16& html) { |
| 78 JNIEnv* env = base::android::AttachCurrentThread(); |
| 79 ScopedJavaLocalRef<jstring> jtext = ConvertUTF16ToJavaString(env, text); |
| 80 ScopedJavaLocalRef<jstring> jhtml = ConvertUTF16ToJavaString(env, html); |
| 81 Java_WebContentsImpl_onSmartClipDataExtracted(env, jtext, jhtml, callback); |
| 82 } |
| 83 |
75 struct AccessibilitySnapshotParams { | 84 struct AccessibilitySnapshotParams { |
76 AccessibilitySnapshotParams() | 85 AccessibilitySnapshotParams() |
77 : has_tree_data(false), should_select_leaf_nodes(false) {} | 86 : has_tree_data(false), should_select_leaf_nodes(false) {} |
78 | 87 |
79 bool has_tree_data; | 88 bool has_tree_data; |
80 // The current text selection within this tree, if any, expressed as the | 89 // The current text selection within this tree, if any, expressed as the |
81 // node ID and character offset of the anchor (selection start) and focus | 90 // node ID and character offset of the anchor (selection start) and focus |
82 // (selection end). | 91 // (selection end). |
83 int32_t sel_anchor_object_id; | 92 int32_t sel_anchor_object_id; |
84 int32_t sel_anchor_offset; | 93 int32_t sel_anchor_offset; |
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 const JavaParamRef<jobject>& jobj) { | 599 const JavaParamRef<jobject>& jobj) { |
591 return static_cast<WebContentsImpl*>(web_contents_)-> | 600 return static_cast<WebContentsImpl*>(web_contents_)-> |
592 HasAccessedInitialDocument(); | 601 HasAccessedInitialDocument(); |
593 } | 602 } |
594 | 603 |
595 jint WebContentsAndroid::GetThemeColor(JNIEnv* env, | 604 jint WebContentsAndroid::GetThemeColor(JNIEnv* env, |
596 const JavaParamRef<jobject>& obj) { | 605 const JavaParamRef<jobject>& obj) { |
597 return web_contents_->GetThemeColor(); | 606 return web_contents_->GetThemeColor(); |
598 } | 607 } |
599 | 608 |
| 609 void WebContentsAndroid::RequestSmartClipExtract( |
| 610 JNIEnv* env, |
| 611 const JavaParamRef<jobject>& obj, |
| 612 const JavaParamRef<jobject>& callback, |
| 613 jint x, |
| 614 jint y, |
| 615 jint width, |
| 616 jint height) { |
| 617 // Secure the Java callback in a scoped object and give ownership of it to the |
| 618 // base::Callback. |
| 619 ScopedJavaGlobalRef<jobject> j_callback; |
| 620 j_callback.Reset(env, callback); |
| 621 |
| 622 RenderFrameHostImpl::SmartClipCallback smart_clip_callback = |
| 623 base::Bind(&SmartClipCallback, j_callback); |
| 624 |
| 625 web_contents_->GetMainFrame()->RequestSmartClipExtract( |
| 626 smart_clip_callback, gfx::Rect(x, y, width, height)); |
| 627 } |
| 628 |
600 void WebContentsAndroid::RequestAccessibilitySnapshot( | 629 void WebContentsAndroid::RequestAccessibilitySnapshot( |
601 JNIEnv* env, | 630 JNIEnv* env, |
602 const JavaParamRef<jobject>& obj, | 631 const JavaParamRef<jobject>& obj, |
603 const JavaParamRef<jobject>& callback) { | 632 const JavaParamRef<jobject>& callback) { |
604 // Secure the Java callback in a scoped object and give ownership of it to the | 633 // Secure the Java callback in a scoped object and give ownership of it to the |
605 // base::Callback. | 634 // base::Callback. |
606 ScopedJavaGlobalRef<jobject> j_callback; | 635 ScopedJavaGlobalRef<jobject> j_callback; |
607 j_callback.Reset(env, callback); | 636 j_callback.Reset(env, callback); |
608 | 637 |
609 WebContentsImpl::AXTreeSnapshotCallback snapshot_callback = | 638 WebContentsImpl::AXTreeSnapshotCallback snapshot_callback = |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 env, obj, callback, id, http_status_code, jurl, jbitmaps, jsizes); | 763 env, obj, callback, id, http_status_code, jurl, jbitmaps, jsizes); |
735 } | 764 } |
736 | 765 |
737 void WebContentsAndroid::SetMediaSession( | 766 void WebContentsAndroid::SetMediaSession( |
738 const ScopedJavaLocalRef<jobject>& j_media_session) { | 767 const ScopedJavaLocalRef<jobject>& j_media_session) { |
739 JNIEnv* env = base::android::AttachCurrentThread(); | 768 JNIEnv* env = base::android::AttachCurrentThread(); |
740 Java_WebContentsImpl_setMediaSession(env, obj_, j_media_session); | 769 Java_WebContentsImpl_setMediaSession(env, obj_, j_media_session); |
741 } | 770 } |
742 | 771 |
743 } // namespace content | 772 } // namespace content |
OLD | NEW |