OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/android/content_view_core_impl.h" | 5 #include "content/browser/android/content_view_core_impl.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/jni_array.h" | 8 #include "base/android/jni_array.h" |
9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
10 #include "base/android/scoped_java_ref.h" | 10 #include "base/android/scoped_java_ref.h" |
(...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
812 } | 812 } |
813 | 813 |
814 scoped_refptr<cc::Layer> ContentViewCoreImpl::GetLayer() const { | 814 scoped_refptr<cc::Layer> ContentViewCoreImpl::GetLayer() const { |
815 return root_layer_.get(); | 815 return root_layer_.get(); |
816 } | 816 } |
817 | 817 |
818 // ---------------------------------------------------------------------------- | 818 // ---------------------------------------------------------------------------- |
819 // Methods called from Java via JNI | 819 // Methods called from Java via JNI |
820 // ---------------------------------------------------------------------------- | 820 // ---------------------------------------------------------------------------- |
821 | 821 |
822 void ContentViewCoreImpl::SelectPopupMenuItems(JNIEnv* env, jobject obj, | |
823 jintArray indices) { | |
824 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>( | |
825 web_contents_->GetRenderViewHost()); | |
826 DCHECK(rvhi); | |
827 if (indices == NULL) { | |
828 rvhi->DidCancelPopupMenu(); | |
829 return; | |
830 } | |
831 | |
832 int selected_count = env->GetArrayLength(indices); | |
833 std::vector<int> selected_indices; | |
834 jint* indices_ptr = env->GetIntArrayElements(indices, NULL); | |
835 for (int i = 0; i < selected_count; ++i) | |
836 selected_indices.push_back(indices_ptr[i]); | |
837 env->ReleaseIntArrayElements(indices, indices_ptr, JNI_ABORT); | |
838 rvhi->DidSelectPopupMenuItems(selected_indices); | |
839 } | |
840 | |
841 void ContentViewCoreImpl::LoadUrl( | 822 void ContentViewCoreImpl::LoadUrl( |
842 JNIEnv* env, jobject obj, | 823 JNIEnv* env, jobject obj, |
843 jstring url, | 824 jstring url, |
844 jint load_url_type, | 825 jint load_url_type, |
845 jint transition_type, | 826 jint transition_type, |
846 jstring j_referrer_url, | 827 jstring j_referrer_url, |
847 jint referrer_policy, | 828 jint referrer_policy, |
848 jint ua_override_option, | 829 jint ua_override_option, |
849 jstring extra_headers, | 830 jstring extra_headers, |
850 jbyteArray post_data, | 831 jbyteArray post_data, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
888 params.referrer = content::Referrer( | 869 params.referrer = content::Referrer( |
889 GURL(ConvertJavaStringToUTF8(env, j_referrer_url)), | 870 GURL(ConvertJavaStringToUTF8(env, j_referrer_url)), |
890 static_cast<blink::WebReferrerPolicy>(referrer_policy)); | 871 static_cast<blink::WebReferrerPolicy>(referrer_policy)); |
891 } | 872 } |
892 | 873 |
893 params.is_renderer_initiated = is_renderer_initiated; | 874 params.is_renderer_initiated = is_renderer_initiated; |
894 | 875 |
895 LoadUrl(params); | 876 LoadUrl(params); |
896 } | 877 } |
897 | 878 |
898 ScopedJavaLocalRef<jstring> ContentViewCoreImpl::GetURL( | |
899 JNIEnv* env, jobject) const { | |
900 return ConvertUTF8ToJavaString(env, GetWebContents()->GetURL().spec()); | |
901 } | |
902 | |
903 jboolean ContentViewCoreImpl::IsIncognito(JNIEnv* env, jobject obj) { | |
904 return GetWebContents()->GetBrowserContext()->IsOffTheRecord(); | |
905 } | |
906 | |
907 WebContents* ContentViewCoreImpl::GetWebContents() const { | 879 WebContents* ContentViewCoreImpl::GetWebContents() const { |
908 return web_contents_; | 880 return web_contents_; |
909 } | 881 } |
910 | 882 |
911 void ContentViewCoreImpl::SetFocus(JNIEnv* env, jobject obj, jboolean focused) { | 883 void ContentViewCoreImpl::SetFocus(JNIEnv* env, jobject obj, jboolean focused) { |
912 SetFocusInternal(focused); | 884 SetFocusInternal(focused); |
913 } | 885 } |
914 | 886 |
915 void ContentViewCoreImpl::SetFocusInternal(bool focused) { | 887 void ContentViewCoreImpl::SetFocusInternal(bool focused) { |
916 if (!GetRenderWidgetHostViewAndroid()) | 888 if (!GetRenderWidgetHostViewAndroid()) |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1150 } | 1122 } |
1151 | 1123 |
1152 void ContentViewCoreImpl::MoveCaret(JNIEnv* env, jobject obj, | 1124 void ContentViewCoreImpl::MoveCaret(JNIEnv* env, jobject obj, |
1153 jfloat x, jfloat y) { | 1125 jfloat x, jfloat y) { |
1154 if (GetRenderWidgetHostViewAndroid()) { | 1126 if (GetRenderWidgetHostViewAndroid()) { |
1155 GetRenderWidgetHostViewAndroid()->MoveCaret( | 1127 GetRenderWidgetHostViewAndroid()->MoveCaret( |
1156 gfx::Point(x / dpi_scale_, y / dpi_scale_)); | 1128 gfx::Point(x / dpi_scale_, y / dpi_scale_)); |
1157 } | 1129 } |
1158 } | 1130 } |
1159 | 1131 |
1160 void ContentViewCoreImpl::HideTextHandles(JNIEnv* env, jobject obj) { | |
1161 if (GetRenderWidgetHostViewAndroid()) | |
1162 GetRenderWidgetHostViewAndroid()->HideTextHandles(); | |
1163 } | |
1164 | |
1165 void ContentViewCoreImpl::ResetGestureDetection(JNIEnv* env, jobject obj) { | |
1166 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); | |
Yaron
2014/07/29 00:05:58
Ted, feel free to disagree but I'm thinking to not
AKVT
2014/07/29 04:01:30
@Yaron MoveCaret() requires dpi_scale. I was not s
Ted C
2014/07/30 17:46:58
I agree. For now, only things that directly deal
| |
1167 if (rwhv) | |
1168 rwhv->ResetGestureDetection(); | |
1169 } | |
1170 | |
1171 void ContentViewCoreImpl::SetDoubleTapSupportEnabled(JNIEnv* env, | |
1172 jobject obj, | |
1173 jboolean enabled) { | |
1174 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); | |
1175 if (rwhv) | |
1176 rwhv->SetDoubleTapSupportEnabled(enabled); | |
1177 } | |
1178 | |
1179 void ContentViewCoreImpl::SetMultiTouchZoomSupportEnabled(JNIEnv* env, | |
1180 jobject obj, | |
1181 jboolean enabled) { | |
1182 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); | |
1183 if (rwhv) | |
1184 rwhv->SetMultiTouchZoomSupportEnabled(enabled); | |
1185 } | |
1186 | |
1187 void ContentViewCoreImpl::ClearHistory(JNIEnv* env, jobject obj) { | 1132 void ContentViewCoreImpl::ClearHistory(JNIEnv* env, jobject obj) { |
1188 // TODO(creis): Do callers of this need to know if it fails? | 1133 // TODO(creis): Do callers of this need to know if it fails? |
1189 if (web_contents_->GetController().CanPruneAllButLastCommitted()) | 1134 if (web_contents_->GetController().CanPruneAllButLastCommitted()) |
1190 web_contents_->GetController().PruneAllButLastCommitted(); | 1135 web_contents_->GetController().PruneAllButLastCommitted(); |
1191 } | 1136 } |
1192 | 1137 |
1193 void ContentViewCoreImpl::SetAllowJavascriptInterfacesInspection( | 1138 void ContentViewCoreImpl::SetAllowJavascriptInterfacesInspection( |
1194 JNIEnv* env, | 1139 JNIEnv* env, |
1195 jobject obj, | 1140 jobject obj, |
1196 jboolean allow) { | 1141 jboolean allow) { |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1495 static_cast<int>(x / dpi_scale()), | 1440 static_cast<int>(x / dpi_scale()), |
1496 static_cast<int>(y / dpi_scale()), | 1441 static_cast<int>(y / dpi_scale()), |
1497 static_cast<int>((width > 0 && width < dpi_scale()) ? | 1442 static_cast<int>((width > 0 && width < dpi_scale()) ? |
1498 1 : (int)(width / dpi_scale())), | 1443 1 : (int)(width / dpi_scale())), |
1499 static_cast<int>((height > 0 && height < dpi_scale()) ? | 1444 static_cast<int>((height > 0 && height < dpi_scale()) ? |
1500 1 : (int)(height / dpi_scale()))); | 1445 1 : (int)(height / dpi_scale()))); |
1501 GetWebContents()->Send(new ViewMsg_ExtractSmartClipData( | 1446 GetWebContents()->Send(new ViewMsg_ExtractSmartClipData( |
1502 GetWebContents()->GetRoutingID(), rect)); | 1447 GetWebContents()->GetRoutingID(), rect)); |
1503 } | 1448 } |
1504 | 1449 |
1505 void ContentViewCoreImpl::ResumeResponseDeferredAtStart(JNIEnv* env, | |
1506 jobject obj) { | |
1507 static_cast<WebContentsImpl*>(GetWebContents())-> | |
1508 ResumeResponseDeferredAtStart(); | |
1509 } | |
1510 | |
1511 void ContentViewCoreImpl::SetHasPendingNavigationTransitionForTesting( | |
1512 JNIEnv* env, | |
1513 jobject obj) { | |
1514 RenderFrameHost* frame = static_cast<WebContentsImpl*>(GetWebContents())-> | |
1515 GetMainFrame(); | |
1516 BrowserThread::PostTask( | |
1517 BrowserThread::IO, | |
1518 FROM_HERE, | |
1519 base::Bind( | |
1520 &TransitionRequestManager::SetHasPendingTransitionRequest, | |
1521 base::Unretained(TransitionRequestManager::GetInstance()), | |
1522 frame->GetProcess()->GetID(), | |
1523 frame->GetRoutingID(), | |
1524 true)); | |
1525 } | |
1526 | |
1527 jint ContentViewCoreImpl::GetCurrentRenderProcessId(JNIEnv* env, jobject obj) { | 1450 jint ContentViewCoreImpl::GetCurrentRenderProcessId(JNIEnv* env, jobject obj) { |
1528 return GetRenderProcessIdFromRenderViewHost( | 1451 return GetRenderProcessIdFromRenderViewHost( |
1529 web_contents_->GetRenderViewHost()); | 1452 web_contents_->GetRenderViewHost()); |
1530 } | 1453 } |
1531 | 1454 |
1532 void ContentViewCoreImpl::SetBackgroundOpaque(JNIEnv* env, jobject jobj, | |
1533 jboolean opaque) { | |
1534 if (GetRenderWidgetHostViewAndroid()) | |
1535 GetRenderWidgetHostViewAndroid()->SetBackgroundOpaque(opaque); | |
1536 } | |
1537 | |
1538 void ContentViewCoreImpl::RequestTextSurroundingSelection( | |
1539 int max_length, | |
1540 const base::Callback< | |
1541 void(const base::string16& content, int start_offset, int end_offset)>& | |
1542 callback) { | |
1543 DCHECK(!callback.is_null()); | |
1544 RenderFrameHost* focused_frame = web_contents_->GetFocusedFrame(); | |
1545 if (!focused_frame) | |
1546 return; | |
1547 if (GetRenderWidgetHostViewAndroid()) { | |
1548 GetRenderWidgetHostViewAndroid()->SetTextSurroundingSelectionCallback( | |
1549 callback); | |
1550 focused_frame->Send(new FrameMsg_TextSurroundingSelectionRequest( | |
1551 focused_frame->GetRoutingID(), max_length)); | |
1552 } | |
1553 } | |
1554 | |
1555 void ContentViewCoreImpl::DidDeferAfterResponseStarted( | 1455 void ContentViewCoreImpl::DidDeferAfterResponseStarted( |
1556 const scoped_refptr<net::HttpResponseHeaders>& headers, | 1456 const scoped_refptr<net::HttpResponseHeaders>& headers, |
1557 const GURL& url) { | 1457 const GURL& url) { |
1558 JNIEnv* env = AttachCurrentThread(); | 1458 JNIEnv* env = AttachCurrentThread(); |
1559 ScopedJavaLocalRef<jobject> obj(java_ref_.get(env)); | 1459 ScopedJavaLocalRef<jobject> obj(java_ref_.get(env)); |
1560 if (obj.is_null()) | 1460 if (obj.is_null()) |
1561 return; | 1461 return; |
1562 | 1462 |
1563 std::vector<GURL> entering_stylesheets; | 1463 std::vector<GURL> entering_stylesheets; |
1564 if (headers) | 1464 if (headers) |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1622 reinterpret_cast<ui::WindowAndroid*>(window_android), | 1522 reinterpret_cast<ui::WindowAndroid*>(window_android), |
1623 retained_objects_set); | 1523 retained_objects_set); |
1624 return reinterpret_cast<intptr_t>(view); | 1524 return reinterpret_cast<intptr_t>(view); |
1625 } | 1525 } |
1626 | 1526 |
1627 bool RegisterContentViewCore(JNIEnv* env) { | 1527 bool RegisterContentViewCore(JNIEnv* env) { |
1628 return RegisterNativesImpl(env); | 1528 return RegisterNativesImpl(env); |
1629 } | 1529 } |
1630 | 1530 |
1631 } // namespace content | 1531 } // namespace content |
OLD | NEW |