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

Side by Side Diff: content/browser/android/content_view_core_impl.cc

Issue 406023002: Restructuring NavigationController functionalities from ContentViewCore to NavigationController (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased the patch with findbugs_known_bugs.txt changes. Created 6 years, 3 months 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
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"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "cc/layers/layer.h" 16 #include "cc/layers/layer.h"
17 #include "cc/layers/solid_color_layer.h" 17 #include "cc/layers/solid_color_layer.h"
18 #include "cc/output/begin_frame_args.h" 18 #include "cc/output/begin_frame_args.h"
19 #include "content/browser/accessibility/browser_accessibility_state_impl.h" 19 #include "content/browser/accessibility/browser_accessibility_state_impl.h"
20 #include "content/browser/android/gesture_event_type.h" 20 #include "content/browser/android/gesture_event_type.h"
21 #include "content/browser/android/interstitial_page_delegate_android.h" 21 #include "content/browser/android/interstitial_page_delegate_android.h"
22 #include "content/browser/android/java/gin_java_bridge_dispatcher_host.h" 22 #include "content/browser/android/java/gin_java_bridge_dispatcher_host.h"
23 #include "content/browser/android/load_url_params.h" 23 #include "content/browser/android/load_url_params.h"
24 #include "content/browser/android/popup_touch_handle_drawable.h" 24 #include "content/browser/android/popup_touch_handle_drawable.h"
25 #include "content/browser/frame_host/interstitial_page_impl.h" 25 #include "content/browser/frame_host/interstitial_page_impl.h"
26 #include "content/browser/frame_host/navigation_controller_impl.h"
27 #include "content/browser/frame_host/navigation_entry_impl.h"
28 #include "content/browser/frame_host/render_frame_host_impl.h"
29 #include "content/browser/geolocation/geolocation_dispatcher_host.h" 26 #include "content/browser/geolocation/geolocation_dispatcher_host.h"
30 #include "content/browser/media/media_web_contents_observer.h" 27 #include "content/browser/media/media_web_contents_observer.h"
31 #include "content/browser/renderer_host/compositor_impl_android.h" 28 #include "content/browser/renderer_host/compositor_impl_android.h"
32 #include "content/browser/renderer_host/input/motion_event_android.h" 29 #include "content/browser/renderer_host/input/motion_event_android.h"
33 #include "content/browser/renderer_host/input/web_input_event_builders_android.h " 30 #include "content/browser/renderer_host/input/web_input_event_builders_android.h "
34 #include "content/browser/renderer_host/input/web_input_event_util.h" 31 #include "content/browser/renderer_host/input/web_input_event_util.h"
35 #include "content/browser/renderer_host/render_view_host_impl.h" 32 #include "content/browser/renderer_host/render_view_host_impl.h"
36 #include "content/browser/renderer_host/render_widget_host_impl.h" 33 #include "content/browser/renderer_host/render_widget_host_impl.h"
37 #include "content/browser/renderer_host/render_widget_host_view_android.h" 34 #include "content/browser/renderer_host/render_widget_host_view_android.h"
38 #include "content/browser/screen_orientation/screen_orientation_dispatcher_host. h" 35 #include "content/browser/screen_orientation/screen_orientation_dispatcher_host. h"
(...skipping 748 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 return; 784 return;
788 785
789 gfx::Point start_point = gfx::Point(start.x(), start.y()); 786 gfx::Point start_point = gfx::Point(start.x(), start.y());
790 gfx::Point end_point = gfx::Point(end.x(), end.y()); 787 gfx::Point end_point = gfx::Point(end.x(), end.y());
791 if (start_point == end_point) 788 if (start_point == end_point)
792 return; 789 return;
793 790
794 web_contents_->SelectRange(start_point, end_point); 791 web_contents_->SelectRange(start_point, end_point);
795 } 792 }
796 793
797 void ContentViewCoreImpl::LoadUrl(
798 NavigationController::LoadURLParams& params) {
799 GetWebContents()->GetController().LoadURLWithParams(params);
800 }
801
802 ui::ViewAndroid* ContentViewCoreImpl::GetViewAndroid() const { 794 ui::ViewAndroid* ContentViewCoreImpl::GetViewAndroid() const {
803 return view_android_; 795 return view_android_;
804 } 796 }
805 797
806 ui::WindowAndroid* ContentViewCoreImpl::GetWindowAndroid() const { 798 ui::WindowAndroid* ContentViewCoreImpl::GetWindowAndroid() const {
807 return window_android_; 799 return window_android_;
808 } 800 }
809 801
810 scoped_refptr<cc::Layer> ContentViewCoreImpl::GetLayer() const { 802 scoped_refptr<cc::Layer> ContentViewCoreImpl::GetLayer() const {
811 return root_layer_.get(); 803 return root_layer_.get();
(...skipping 17 matching lines...) Expand all
829 821
830 int selected_count = env->GetArrayLength(indices); 822 int selected_count = env->GetArrayLength(indices);
831 std::vector<int> selected_indices; 823 std::vector<int> selected_indices;
832 jint* indices_ptr = env->GetIntArrayElements(indices, NULL); 824 jint* indices_ptr = env->GetIntArrayElements(indices, NULL);
833 for (int i = 0; i < selected_count; ++i) 825 for (int i = 0; i < selected_count; ++i)
834 selected_indices.push_back(indices_ptr[i]); 826 selected_indices.push_back(indices_ptr[i]);
835 env->ReleaseIntArrayElements(indices, indices_ptr, JNI_ABORT); 827 env->ReleaseIntArrayElements(indices, indices_ptr, JNI_ABORT);
836 rfhi->DidSelectPopupMenuItems(selected_indices); 828 rfhi->DidSelectPopupMenuItems(selected_indices);
837 } 829 }
838 830
839 void ContentViewCoreImpl::LoadUrl(
840 JNIEnv* env, jobject obj,
841 jstring url,
842 jint load_url_type,
843 jint transition_type,
844 jstring j_referrer_url,
845 jint referrer_policy,
846 jint ua_override_option,
847 jstring extra_headers,
848 jbyteArray post_data,
849 jstring base_url_for_data_url,
850 jstring virtual_url_for_data_url,
851 jboolean can_load_local_resources,
852 jboolean is_renderer_initiated) {
853 DCHECK(url);
854 NavigationController::LoadURLParams params(
855 GURL(ConvertJavaStringToUTF8(env, url)));
856
857 params.load_type = static_cast<NavigationController::LoadURLType>(
858 load_url_type);
859 params.transition_type = PageTransitionFromInt(transition_type);
860 params.override_user_agent =
861 static_cast<NavigationController::UserAgentOverrideOption>(
862 ua_override_option);
863
864 if (extra_headers)
865 params.extra_headers = ConvertJavaStringToUTF8(env, extra_headers);
866
867 if (post_data) {
868 std::vector<uint8> http_body_vector;
869 base::android::JavaByteArrayToByteVector(env, post_data, &http_body_vector);
870 params.browser_initiated_post_data =
871 base::RefCountedBytes::TakeVector(&http_body_vector);
872 }
873
874 if (base_url_for_data_url) {
875 params.base_url_for_data_url =
876 GURL(ConvertJavaStringToUTF8(env, base_url_for_data_url));
877 }
878
879 if (virtual_url_for_data_url) {
880 params.virtual_url_for_data_url =
881 GURL(ConvertJavaStringToUTF8(env, virtual_url_for_data_url));
882 }
883
884 params.can_load_local_resources = can_load_local_resources;
885 if (j_referrer_url) {
886 params.referrer = content::Referrer(
887 GURL(ConvertJavaStringToUTF8(env, j_referrer_url)),
888 static_cast<blink::WebReferrerPolicy>(referrer_policy));
889 }
890
891 params.is_renderer_initiated = is_renderer_initiated;
892
893 LoadUrl(params);
894 }
895
896 WebContents* ContentViewCoreImpl::GetWebContents() const { 831 WebContents* ContentViewCoreImpl::GetWebContents() const {
897 return web_contents_; 832 return web_contents_;
898 } 833 }
899 834
900 void ContentViewCoreImpl::SetFocus(JNIEnv* env, jobject obj, jboolean focused) { 835 void ContentViewCoreImpl::SetFocus(JNIEnv* env, jobject obj, jboolean focused) {
901 SetFocusInternal(focused); 836 SetFocusInternal(focused);
902 } 837 }
903 838
904 void ContentViewCoreImpl::SetFocusInternal(bool focused) { 839 void ContentViewCoreImpl::SetFocusInternal(bool focused) {
905 if (!GetRenderWidgetHostViewAndroid()) 840 if (!GetRenderWidgetHostViewAndroid())
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
1174 } 1109 }
1175 1110
1176 void ContentViewCoreImpl::SetMultiTouchZoomSupportEnabled(JNIEnv* env, 1111 void ContentViewCoreImpl::SetMultiTouchZoomSupportEnabled(JNIEnv* env,
1177 jobject obj, 1112 jobject obj,
1178 jboolean enabled) { 1113 jboolean enabled) {
1179 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); 1114 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid();
1180 if (rwhv) 1115 if (rwhv)
1181 rwhv->SetMultiTouchZoomSupportEnabled(enabled); 1116 rwhv->SetMultiTouchZoomSupportEnabled(enabled);
1182 } 1117 }
1183 1118
1184 void ContentViewCoreImpl::ClearHistory(JNIEnv* env, jobject obj) {
1185 // TODO(creis): Do callers of this need to know if it fails?
1186 if (web_contents_->GetController().CanPruneAllButLastCommitted())
1187 web_contents_->GetController().PruneAllButLastCommitted();
1188 }
1189
1190 void ContentViewCoreImpl::SetAllowJavascriptInterfacesInspection( 1119 void ContentViewCoreImpl::SetAllowJavascriptInterfacesInspection(
1191 JNIEnv* env, 1120 JNIEnv* env,
1192 jobject obj, 1121 jobject obj,
1193 jboolean allow) { 1122 jboolean allow) {
1194 java_bridge_dispatcher_host_->SetAllowObjectContentsInspection(allow); 1123 java_bridge_dispatcher_host_->SetAllowObjectContentsInspection(allow);
1195 } 1124 }
1196 1125
1197 void ContentViewCoreImpl::AddJavascriptInterface( 1126 void ContentViewCoreImpl::AddJavascriptInterface(
1198 JNIEnv* env, 1127 JNIEnv* env,
1199 jobject /* obj */, 1128 jobject /* obj */,
(...skipping 21 matching lines...) Expand all
1221 root_layer_->SetBounds(physical_size); 1150 root_layer_->SetBounds(physical_size);
1222 1151
1223 if (view) { 1152 if (view) {
1224 RenderWidgetHostImpl* host = RenderWidgetHostImpl::From( 1153 RenderWidgetHostImpl* host = RenderWidgetHostImpl::From(
1225 view->GetRenderWidgetHost()); 1154 view->GetRenderWidgetHost());
1226 host->SendScreenRects(); 1155 host->SendScreenRects();
1227 view->WasResized(); 1156 view->WasResized();
1228 } 1157 }
1229 } 1158 }
1230 1159
1231 namespace {
1232
1233 static void AddNavigationEntryToHistory(JNIEnv* env, jobject obj,
1234 jobject history,
1235 NavigationEntry* entry,
1236 int index) {
1237 // Get the details of the current entry
1238 ScopedJavaLocalRef<jstring> j_url(
1239 ConvertUTF8ToJavaString(env, entry->GetURL().spec()));
1240 ScopedJavaLocalRef<jstring> j_virtual_url(
1241 ConvertUTF8ToJavaString(env, entry->GetVirtualURL().spec()));
1242 ScopedJavaLocalRef<jstring> j_original_url(
1243 ConvertUTF8ToJavaString(env, entry->GetOriginalRequestURL().spec()));
1244 ScopedJavaLocalRef<jstring> j_title(
1245 ConvertUTF16ToJavaString(env, entry->GetTitle()));
1246 ScopedJavaLocalRef<jobject> j_bitmap;
1247 const FaviconStatus& status = entry->GetFavicon();
1248 if (status.valid && status.image.ToSkBitmap()->getSize() > 0)
1249 j_bitmap = gfx::ConvertToJavaBitmap(status.image.ToSkBitmap());
1250
1251 // Add the item to the list
1252 Java_ContentViewCore_addToNavigationHistory(
1253 env, obj, history, index, j_url.obj(), j_virtual_url.obj(),
1254 j_original_url.obj(), j_title.obj(), j_bitmap.obj());
1255 }
1256
1257 } // namespace
1258
1259 int ContentViewCoreImpl::GetNavigationHistory(JNIEnv* env,
1260 jobject obj,
1261 jobject history) {
1262 // Iterate through navigation entries to populate the list
1263 const NavigationController& controller = web_contents_->GetController();
1264 int count = controller.GetEntryCount();
1265 for (int i = 0; i < count; ++i) {
1266 AddNavigationEntryToHistory(
1267 env, obj, history, controller.GetEntryAtIndex(i), i);
1268 }
1269
1270 return controller.GetCurrentEntryIndex();
1271 }
1272
1273 void ContentViewCoreImpl::GetDirectedNavigationHistory(JNIEnv* env,
1274 jobject obj,
1275 jobject history,
1276 jboolean is_forward,
1277 jint max_entries) {
1278 // Iterate through navigation entries to populate the list
1279 const NavigationController& controller = web_contents_->GetController();
1280 int count = controller.GetEntryCount();
1281 int num_added = 0;
1282 int increment_value = is_forward ? 1 : -1;
1283 for (int i = controller.GetCurrentEntryIndex() + increment_value;
1284 i >= 0 && i < count;
1285 i += increment_value) {
1286 if (num_added >= max_entries)
1287 break;
1288
1289 AddNavigationEntryToHistory(
1290 env, obj, history, controller.GetEntryAtIndex(i), i);
1291 num_added++;
1292 }
1293 }
1294
1295 ScopedJavaLocalRef<jstring>
1296 ContentViewCoreImpl::GetOriginalUrlForActiveNavigationEntry(JNIEnv* env,
1297 jobject obj) {
1298 NavigationEntry* entry = web_contents_->GetController().GetVisibleEntry();
1299 if (entry == NULL)
1300 return ScopedJavaLocalRef<jstring>(env, NULL);
1301 return ConvertUTF8ToJavaString(env, entry->GetOriginalRequestURL().spec());
1302 }
1303
1304 long ContentViewCoreImpl::GetNativeImeAdapter(JNIEnv* env, jobject obj) { 1160 long ContentViewCoreImpl::GetNativeImeAdapter(JNIEnv* env, jobject obj) {
1305 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); 1161 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid();
1306 if (!rwhva) 1162 if (!rwhva)
1307 return 0; 1163 return 0;
1308 return rwhva->GetNativeImeAdapter(); 1164 return rwhva->GetNativeImeAdapter();
1309 } 1165 }
1310 1166
1311 // TODO(sgurun) add support for posting a frame whose name is known (only 1167 // TODO(sgurun) add support for posting a frame whose name is known (only
1312 // main frame is supported at this time, see crbug.com/389721) 1168 // main frame is supported at this time, see crbug.com/389721)
1313 // TODO(sgurun) add support for passing message ports 1169 // TODO(sgurun) add support for passing message ports
1314 void ContentViewCoreImpl::PostMessageToFrame(JNIEnv* env, jobject obj, 1170 void ContentViewCoreImpl::PostMessageToFrame(JNIEnv* env, jobject obj,
1315 jstring frame_name, jstring message, jstring source_origin, 1171 jstring frame_name, jstring message, jstring source_origin,
1316 jstring target_origin) { 1172 jstring target_origin) {
1317 1173
1318 RenderViewHost* host = web_contents_->GetRenderViewHost(); 1174 RenderViewHost* host = web_contents_->GetRenderViewHost();
1319 if (!host) 1175 if (!host)
1320 return; 1176 return;
1321 ViewMsg_PostMessage_Params params; 1177 ViewMsg_PostMessage_Params params;
1322 params.source_origin = ConvertJavaStringToUTF16(env, source_origin); 1178 params.source_origin = ConvertJavaStringToUTF16(env, source_origin);
1323 params.target_origin = ConvertJavaStringToUTF16(env, target_origin); 1179 params.target_origin = ConvertJavaStringToUTF16(env, target_origin);
1324 params.data = ConvertJavaStringToUTF16(env, message); 1180 params.data = ConvertJavaStringToUTF16(env, message);
1325 params.is_data_raw_string = true; 1181 params.is_data_raw_string = true;
1326 params.source_routing_id = MSG_ROUTING_NONE; 1182 params.source_routing_id = MSG_ROUTING_NONE;
1327 host->Send(new ViewMsg_PostMessageEvent(host->GetRoutingID(), params)); 1183 host->Send(new ViewMsg_PostMessageEvent(host->GetRoutingID(), params));
1328 } 1184 }
1329 1185
1330
1331 bool ContentViewCoreImpl::GetUseDesktopUserAgent(
1332 JNIEnv* env, jobject obj) {
1333 NavigationEntry* entry = web_contents_->GetController().GetVisibleEntry();
1334 return entry && entry->GetIsOverridingUserAgent();
1335 }
1336
1337 void ContentViewCoreImpl::UpdateImeAdapter(long native_ime_adapter, 1186 void ContentViewCoreImpl::UpdateImeAdapter(long native_ime_adapter,
1338 int text_input_type, 1187 int text_input_type,
1339 int text_input_flags, 1188 int text_input_flags,
1340 const std::string& text, 1189 const std::string& text,
1341 int selection_start, 1190 int selection_start,
1342 int selection_end, 1191 int selection_end,
1343 int composition_start, 1192 int composition_start,
1344 int composition_end, 1193 int composition_end,
1345 bool show_ime_if_needed, 1194 bool show_ime_if_needed,
1346 bool is_non_ime_change) { 1195 bool is_non_ime_change) {
(...skipping 10 matching lines...) Expand all
1357 text_input_flags, 1206 text_input_flags,
1358 jstring_text.obj(), 1207 jstring_text.obj(),
1359 selection_start, 1208 selection_start,
1360 selection_end, 1209 selection_end,
1361 composition_start, 1210 composition_start,
1362 composition_end, 1211 composition_end,
1363 show_ime_if_needed, 1212 show_ime_if_needed,
1364 is_non_ime_change); 1213 is_non_ime_change);
1365 } 1214 }
1366 1215
1367 void ContentViewCoreImpl::ClearSslPreferences(JNIEnv* env, jobject obj) {
1368 content::SSLHostStateDelegate* delegate =
1369 web_contents_->
1370 GetController().
1371 GetBrowserContext()->
1372 GetSSLHostStateDelegate();
1373 if (delegate)
1374 delegate->Clear();
1375 }
1376
1377 void ContentViewCoreImpl::SetUseDesktopUserAgent(
1378 JNIEnv* env,
1379 jobject obj,
1380 jboolean enabled,
1381 jboolean reload_on_state_change) {
1382 if (GetUseDesktopUserAgent(env, obj) == enabled)
1383 return;
1384
1385 // Make sure the navigation entry actually exists.
1386 NavigationEntry* entry = web_contents_->GetController().GetVisibleEntry();
1387 if (!entry)
1388 return;
1389
1390 // Set the flag in the NavigationEntry.
1391 entry->SetIsOverridingUserAgent(enabled);
1392
1393 // Send the override to the renderer.
1394 if (reload_on_state_change) {
1395 // Reloading the page will send the override down as part of the
1396 // navigation IPC message.
1397 NavigationControllerImpl& controller =
1398 static_cast<NavigationControllerImpl&>(web_contents_->GetController());
1399 controller.ReloadOriginalRequestURL(false);
1400 }
1401 }
1402
1403 void ContentViewCoreImpl::SetAccessibilityEnabled(JNIEnv* env, jobject obj, 1216 void ContentViewCoreImpl::SetAccessibilityEnabled(JNIEnv* env, jobject obj,
1404 bool enabled) { 1217 bool enabled) {
1405 SetAccessibilityEnabledInternal(enabled); 1218 SetAccessibilityEnabledInternal(enabled);
1406 } 1219 }
1407 1220
1408 bool ContentViewCoreImpl::IsFullscreenRequiredForOrientationLock() const { 1221 bool ContentViewCoreImpl::IsFullscreenRequiredForOrientationLock() const {
1409 JNIEnv* env = AttachCurrentThread(); 1222 JNIEnv* env = AttachCurrentThread();
1410 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 1223 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
1411 if (obj.is_null()) 1224 if (obj.is_null())
1412 return true; 1225 return true;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1524 reinterpret_cast<ui::WindowAndroid*>(window_android), 1337 reinterpret_cast<ui::WindowAndroid*>(window_android),
1525 retained_objects_set); 1338 retained_objects_set);
1526 return reinterpret_cast<intptr_t>(view); 1339 return reinterpret_cast<intptr_t>(view);
1527 } 1340 }
1528 1341
1529 bool RegisterContentViewCore(JNIEnv* env) { 1342 bool RegisterContentViewCore(JNIEnv* env) {
1530 return RegisterNativesImpl(env); 1343 return RegisterNativesImpl(env);
1531 } 1344 }
1532 1345
1533 } // namespace content 1346 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/android/content_view_core_impl.h ('k') | content/browser/frame_host/navigation_controller_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698