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

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: Removed unwanted headers Created 6 years, 5 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/json/json_writer.h" 12 #include "base/json/json_writer.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "cc/layers/layer.h" 17 #include "cc/layers/layer.h"
18 #include "cc/layers/solid_color_layer.h" 18 #include "cc/layers/solid_color_layer.h"
19 #include "cc/output/begin_frame_args.h" 19 #include "cc/output/begin_frame_args.h"
20 #include "content/browser/accessibility/browser_accessibility_state_impl.h" 20 #include "content/browser/accessibility/browser_accessibility_state_impl.h"
21 #include "content/browser/android/gesture_event_type.h" 21 #include "content/browser/android/gesture_event_type.h"
22 #include "content/browser/android/interstitial_page_delegate_android.h" 22 #include "content/browser/android/interstitial_page_delegate_android.h"
23 #include "content/browser/android/java/gin_java_bridge_dispatcher_host.h" 23 #include "content/browser/android/java/gin_java_bridge_dispatcher_host.h"
24 #include "content/browser/android/load_url_params.h" 24 #include "content/browser/android/load_url_params.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" 26 #include "content/browser/frame_host/navigation_controller_impl.h"
Yaron 2014/07/22 20:49:05 can you remove these 2 inclues?
AKVT 2014/07/23 11:49:23 Done.
27 #include "content/browser/frame_host/navigation_entry_impl.h" 27 #include "content/browser/frame_host/navigation_entry_impl.h"
28 #include "content/browser/geolocation/geolocation_dispatcher_host.h" 28 #include "content/browser/geolocation/geolocation_dispatcher_host.h"
29 #include "content/browser/media/media_web_contents_observer.h" 29 #include "content/browser/media/media_web_contents_observer.h"
30 #include "content/browser/renderer_host/compositor_impl_android.h" 30 #include "content/browser/renderer_host/compositor_impl_android.h"
31 #include "content/browser/renderer_host/input/motion_event_android.h" 31 #include "content/browser/renderer_host/input/motion_event_android.h"
32 #include "content/browser/renderer_host/input/web_input_event_builders_android.h " 32 #include "content/browser/renderer_host/input/web_input_event_builders_android.h "
33 #include "content/browser/renderer_host/input/web_input_event_util.h" 33 #include "content/browser/renderer_host/input/web_input_event_util.h"
34 #include "content/browser/renderer_host/render_view_host_impl.h" 34 #include "content/browser/renderer_host/render_view_host_impl.h"
35 #include "content/browser/renderer_host/render_widget_host_impl.h" 35 #include "content/browser/renderer_host/render_widget_host_impl.h"
36 #include "content/browser/renderer_host/render_widget_host_view_android.h" 36 #include "content/browser/renderer_host/render_widget_host_view_android.h"
(...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 root_layer_->SetIsDrawable(false); 775 root_layer_->SetIsDrawable(false);
776 } 776 }
777 777
778 void ContentViewCoreImpl::RemoveLayer(scoped_refptr<cc::Layer> layer) { 778 void ContentViewCoreImpl::RemoveLayer(scoped_refptr<cc::Layer> layer) {
779 layer->RemoveFromParent(); 779 layer->RemoveFromParent();
780 780
781 if (!root_layer_->children().size()) 781 if (!root_layer_->children().size())
782 root_layer_->SetIsDrawable(true); 782 root_layer_->SetIsDrawable(true);
783 } 783 }
784 784
785 void ContentViewCoreImpl::LoadUrl(
786 NavigationController::LoadURLParams& params) {
787 GetWebContents()->GetController().LoadURLWithParams(params);
788 }
789
790 ui::ViewAndroid* ContentViewCoreImpl::GetViewAndroid() const { 785 ui::ViewAndroid* ContentViewCoreImpl::GetViewAndroid() const {
791 return view_android_; 786 return view_android_;
792 } 787 }
793 788
794 ui::WindowAndroid* ContentViewCoreImpl::GetWindowAndroid() const { 789 ui::WindowAndroid* ContentViewCoreImpl::GetWindowAndroid() const {
795 return window_android_; 790 return window_android_;
796 } 791 }
797 792
798 scoped_refptr<cc::Layer> ContentViewCoreImpl::GetLayer() const { 793 scoped_refptr<cc::Layer> ContentViewCoreImpl::GetLayer() const {
799 return root_layer_.get(); 794 return root_layer_.get();
(...skipping 15 matching lines...) Expand all
815 810
816 int selected_count = env->GetArrayLength(indices); 811 int selected_count = env->GetArrayLength(indices);
817 std::vector<int> selected_indices; 812 std::vector<int> selected_indices;
818 jint* indices_ptr = env->GetIntArrayElements(indices, NULL); 813 jint* indices_ptr = env->GetIntArrayElements(indices, NULL);
819 for (int i = 0; i < selected_count; ++i) 814 for (int i = 0; i < selected_count; ++i)
820 selected_indices.push_back(indices_ptr[i]); 815 selected_indices.push_back(indices_ptr[i]);
821 env->ReleaseIntArrayElements(indices, indices_ptr, JNI_ABORT); 816 env->ReleaseIntArrayElements(indices, indices_ptr, JNI_ABORT);
822 rvhi->DidSelectPopupMenuItems(selected_indices); 817 rvhi->DidSelectPopupMenuItems(selected_indices);
823 } 818 }
824 819
825 void ContentViewCoreImpl::LoadUrl(
826 JNIEnv* env, jobject obj,
827 jstring url,
828 jint load_url_type,
829 jint transition_type,
830 jstring j_referrer_url,
831 jint referrer_policy,
832 jint ua_override_option,
833 jstring extra_headers,
834 jbyteArray post_data,
835 jstring base_url_for_data_url,
836 jstring virtual_url_for_data_url,
837 jboolean can_load_local_resources,
838 jboolean is_renderer_initiated) {
839 DCHECK(url);
840 NavigationController::LoadURLParams params(
841 GURL(ConvertJavaStringToUTF8(env, url)));
842
843 params.load_type = static_cast<NavigationController::LoadURLType>(
844 load_url_type);
845 params.transition_type = PageTransitionFromInt(transition_type);
846 params.override_user_agent =
847 static_cast<NavigationController::UserAgentOverrideOption>(
848 ua_override_option);
849
850 if (extra_headers)
851 params.extra_headers = ConvertJavaStringToUTF8(env, extra_headers);
852
853 if (post_data) {
854 std::vector<uint8> http_body_vector;
855 base::android::JavaByteArrayToByteVector(env, post_data, &http_body_vector);
856 params.browser_initiated_post_data =
857 base::RefCountedBytes::TakeVector(&http_body_vector);
858 }
859
860 if (base_url_for_data_url) {
861 params.base_url_for_data_url =
862 GURL(ConvertJavaStringToUTF8(env, base_url_for_data_url));
863 }
864
865 if (virtual_url_for_data_url) {
866 params.virtual_url_for_data_url =
867 GURL(ConvertJavaStringToUTF8(env, virtual_url_for_data_url));
868 }
869
870 params.can_load_local_resources = can_load_local_resources;
871 if (j_referrer_url) {
872 params.referrer = content::Referrer(
873 GURL(ConvertJavaStringToUTF8(env, j_referrer_url)),
874 static_cast<blink::WebReferrerPolicy>(referrer_policy));
875 }
876
877 params.is_renderer_initiated = is_renderer_initiated;
878
879 LoadUrl(params);
880 }
881
882 ScopedJavaLocalRef<jstring> ContentViewCoreImpl::GetURL( 820 ScopedJavaLocalRef<jstring> ContentViewCoreImpl::GetURL(
883 JNIEnv* env, jobject) const { 821 JNIEnv* env, jobject) const {
884 return ConvertUTF8ToJavaString(env, GetWebContents()->GetURL().spec()); 822 return ConvertUTF8ToJavaString(env, GetWebContents()->GetURL().spec());
885 } 823 }
886 824
887 jboolean ContentViewCoreImpl::IsIncognito(JNIEnv* env, jobject obj) { 825 jboolean ContentViewCoreImpl::IsIncognito(JNIEnv* env, jobject obj) {
888 return GetWebContents()->GetBrowserContext()->IsOffTheRecord(); 826 return GetWebContents()->GetBrowserContext()->IsOffTheRecord();
889 } 827 }
890 828
891 WebContents* ContentViewCoreImpl::GetWebContents() const { 829 WebContents* ContentViewCoreImpl::GetWebContents() const {
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
1158 } 1096 }
1159 1097
1160 void ContentViewCoreImpl::SetMultiTouchZoomSupportEnabled(JNIEnv* env, 1098 void ContentViewCoreImpl::SetMultiTouchZoomSupportEnabled(JNIEnv* env,
1161 jobject obj, 1099 jobject obj,
1162 jboolean enabled) { 1100 jboolean enabled) {
1163 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); 1101 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid();
1164 if (rwhv) 1102 if (rwhv)
1165 rwhv->SetMultiTouchZoomSupportEnabled(enabled); 1103 rwhv->SetMultiTouchZoomSupportEnabled(enabled);
1166 } 1104 }
1167 1105
1168 void ContentViewCoreImpl::ClearHistory(JNIEnv* env, jobject obj) {
1169 // TODO(creis): Do callers of this need to know if it fails?
1170 if (web_contents_->GetController().CanPruneAllButLastCommitted())
1171 web_contents_->GetController().PruneAllButLastCommitted();
1172 }
1173
1174 void ContentViewCoreImpl::SetAllowJavascriptInterfacesInspection( 1106 void ContentViewCoreImpl::SetAllowJavascriptInterfacesInspection(
1175 JNIEnv* env, 1107 JNIEnv* env,
1176 jobject obj, 1108 jobject obj,
1177 jboolean allow) { 1109 jboolean allow) {
1178 java_bridge_dispatcher_host_->SetAllowObjectContentsInspection(allow); 1110 java_bridge_dispatcher_host_->SetAllowObjectContentsInspection(allow);
1179 } 1111 }
1180 1112
1181 void ContentViewCoreImpl::AddJavascriptInterface( 1113 void ContentViewCoreImpl::AddJavascriptInterface(
1182 JNIEnv* env, 1114 JNIEnv* env,
1183 jobject /* obj */, 1115 jobject /* obj */,
(...skipping 21 matching lines...) Expand all
1205 root_layer_->SetBounds(physical_size); 1137 root_layer_->SetBounds(physical_size);
1206 1138
1207 if (view) { 1139 if (view) {
1208 RenderWidgetHostImpl* host = RenderWidgetHostImpl::From( 1140 RenderWidgetHostImpl* host = RenderWidgetHostImpl::From(
1209 view->GetRenderWidgetHost()); 1141 view->GetRenderWidgetHost());
1210 host->SendScreenRects(); 1142 host->SendScreenRects();
1211 view->WasResized(); 1143 view->WasResized();
1212 } 1144 }
1213 } 1145 }
1214 1146
1215 namespace {
1216
1217 static void AddNavigationEntryToHistory(JNIEnv* env, jobject obj,
1218 jobject history,
1219 NavigationEntry* entry,
1220 int index) {
1221 // Get the details of the current entry
1222 ScopedJavaLocalRef<jstring> j_url(
1223 ConvertUTF8ToJavaString(env, entry->GetURL().spec()));
1224 ScopedJavaLocalRef<jstring> j_virtual_url(
1225 ConvertUTF8ToJavaString(env, entry->GetVirtualURL().spec()));
1226 ScopedJavaLocalRef<jstring> j_original_url(
1227 ConvertUTF8ToJavaString(env, entry->GetOriginalRequestURL().spec()));
1228 ScopedJavaLocalRef<jstring> j_title(
1229 ConvertUTF16ToJavaString(env, entry->GetTitle()));
1230 ScopedJavaLocalRef<jobject> j_bitmap;
1231 const FaviconStatus& status = entry->GetFavicon();
1232 if (status.valid && status.image.ToSkBitmap()->getSize() > 0)
1233 j_bitmap = gfx::ConvertToJavaBitmap(status.image.ToSkBitmap());
1234
1235 // Add the item to the list
1236 Java_ContentViewCore_addToNavigationHistory(
1237 env, obj, history, index, j_url.obj(), j_virtual_url.obj(),
1238 j_original_url.obj(), j_title.obj(), j_bitmap.obj());
1239 }
1240
1241 } // namespace
1242
1243 int ContentViewCoreImpl::GetNavigationHistory(JNIEnv* env,
1244 jobject obj,
1245 jobject history) {
1246 // Iterate through navigation entries to populate the list
1247 const NavigationController& controller = web_contents_->GetController();
1248 int count = controller.GetEntryCount();
1249 for (int i = 0; i < count; ++i) {
1250 AddNavigationEntryToHistory(
1251 env, obj, history, controller.GetEntryAtIndex(i), i);
1252 }
1253
1254 return controller.GetCurrentEntryIndex();
1255 }
1256
1257 void ContentViewCoreImpl::GetDirectedNavigationHistory(JNIEnv* env,
1258 jobject obj,
1259 jobject history,
1260 jboolean is_forward,
1261 jint max_entries) {
1262 // Iterate through navigation entries to populate the list
1263 const NavigationController& controller = web_contents_->GetController();
1264 int count = controller.GetEntryCount();
1265 int num_added = 0;
1266 int increment_value = is_forward ? 1 : -1;
1267 for (int i = controller.GetCurrentEntryIndex() + increment_value;
1268 i >= 0 && i < count;
1269 i += increment_value) {
1270 if (num_added >= max_entries)
1271 break;
1272
1273 AddNavigationEntryToHistory(
1274 env, obj, history, controller.GetEntryAtIndex(i), i);
1275 num_added++;
1276 }
1277 }
1278
1279 ScopedJavaLocalRef<jstring>
1280 ContentViewCoreImpl::GetOriginalUrlForActiveNavigationEntry(JNIEnv* env,
1281 jobject obj) {
1282 NavigationEntry* entry = web_contents_->GetController().GetVisibleEntry();
1283 if (entry == NULL)
1284 return ScopedJavaLocalRef<jstring>(env, NULL);
1285 return ConvertUTF8ToJavaString(env, entry->GetOriginalRequestURL().spec());
1286 }
1287
1288 long ContentViewCoreImpl::GetNativeImeAdapter(JNIEnv* env, jobject obj) { 1147 long ContentViewCoreImpl::GetNativeImeAdapter(JNIEnv* env, jobject obj) {
1289 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); 1148 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid();
1290 if (!rwhva) 1149 if (!rwhva)
1291 return 0; 1150 return 0;
1292 return rwhva->GetNativeImeAdapter(); 1151 return rwhva->GetNativeImeAdapter();
1293 } 1152 }
1294 1153
1295 namespace { 1154 namespace {
1296 void JavaScriptResultCallback(const ScopedJavaGlobalRef<jobject>& callback, 1155 void JavaScriptResultCallback(const ScopedJavaGlobalRef<jobject>& callback,
1297 const base::Value* result) { 1156 const base::Value* result) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1351 return; 1210 return;
1352 ViewMsg_PostMessage_Params params; 1211 ViewMsg_PostMessage_Params params;
1353 params.source_origin = ConvertJavaStringToUTF16(env, source_origin); 1212 params.source_origin = ConvertJavaStringToUTF16(env, source_origin);
1354 params.target_origin = ConvertJavaStringToUTF16(env, target_origin); 1213 params.target_origin = ConvertJavaStringToUTF16(env, target_origin);
1355 params.data = ConvertJavaStringToUTF16(env, message); 1214 params.data = ConvertJavaStringToUTF16(env, message);
1356 params.is_data_raw_string = true; 1215 params.is_data_raw_string = true;
1357 params.source_routing_id = MSG_ROUTING_NONE; 1216 params.source_routing_id = MSG_ROUTING_NONE;
1358 host->Send(new ViewMsg_PostMessageEvent(host->GetRoutingID(), params)); 1217 host->Send(new ViewMsg_PostMessageEvent(host->GetRoutingID(), params));
1359 } 1218 }
1360 1219
1361
1362 bool ContentViewCoreImpl::GetUseDesktopUserAgent(
1363 JNIEnv* env, jobject obj) {
1364 NavigationEntry* entry = web_contents_->GetController().GetVisibleEntry();
1365 return entry && entry->GetIsOverridingUserAgent();
1366 }
1367
1368 void ContentViewCoreImpl::UpdateImeAdapter(long native_ime_adapter, 1220 void ContentViewCoreImpl::UpdateImeAdapter(long native_ime_adapter,
1369 int text_input_type, 1221 int text_input_type,
1370 const std::string& text, 1222 const std::string& text,
1371 int selection_start, 1223 int selection_start,
1372 int selection_end, 1224 int selection_end,
1373 int composition_start, 1225 int composition_start,
1374 int composition_end, 1226 int composition_end,
1375 bool show_ime_if_needed, 1227 bool show_ime_if_needed,
1376 bool is_non_ime_change) { 1228 bool is_non_ime_change) {
1377 JNIEnv* env = AttachCurrentThread(); 1229 JNIEnv* env = AttachCurrentThread();
1378 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 1230 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
1379 if (obj.is_null()) 1231 if (obj.is_null())
1380 return; 1232 return;
1381 1233
1382 ScopedJavaLocalRef<jstring> jstring_text = ConvertUTF8ToJavaString(env, text); 1234 ScopedJavaLocalRef<jstring> jstring_text = ConvertUTF8ToJavaString(env, text);
1383 Java_ContentViewCore_updateImeAdapter(env, obj.obj(), 1235 Java_ContentViewCore_updateImeAdapter(env, obj.obj(),
1384 native_ime_adapter, text_input_type, 1236 native_ime_adapter, text_input_type,
1385 jstring_text.obj(), 1237 jstring_text.obj(),
1386 selection_start, selection_end, 1238 selection_start, selection_end,
1387 composition_start, composition_end, 1239 composition_start, composition_end,
1388 show_ime_if_needed, is_non_ime_change); 1240 show_ime_if_needed, is_non_ime_change);
1389 } 1241 }
1390 1242
1391 void ContentViewCoreImpl::ClearSslPreferences(JNIEnv* env, jobject obj) {
1392 SSLHostState* state = SSLHostState::GetFor(
1393 web_contents_->GetController().GetBrowserContext());
1394 state->Clear();
1395 }
1396
1397 void ContentViewCoreImpl::SetUseDesktopUserAgent(
1398 JNIEnv* env,
1399 jobject obj,
1400 jboolean enabled,
1401 jboolean reload_on_state_change) {
1402 if (GetUseDesktopUserAgent(env, obj) == enabled)
1403 return;
1404
1405 // Make sure the navigation entry actually exists.
1406 NavigationEntry* entry = web_contents_->GetController().GetVisibleEntry();
1407 if (!entry)
1408 return;
1409
1410 // Set the flag in the NavigationEntry.
1411 entry->SetIsOverridingUserAgent(enabled);
1412
1413 // Send the override to the renderer.
1414 if (reload_on_state_change) {
1415 // Reloading the page will send the override down as part of the
1416 // navigation IPC message.
1417 NavigationControllerImpl& controller =
1418 static_cast<NavigationControllerImpl&>(web_contents_->GetController());
1419 controller.ReloadOriginalRequestURL(false);
1420 }
1421 }
1422
1423 void ContentViewCoreImpl::SetAccessibilityEnabled(JNIEnv* env, jobject obj, 1243 void ContentViewCoreImpl::SetAccessibilityEnabled(JNIEnv* env, jobject obj,
1424 bool enabled) { 1244 bool enabled) {
1425 SetAccessibilityEnabledInternal(enabled); 1245 SetAccessibilityEnabledInternal(enabled);
1426 } 1246 }
1427 1247
1428 void ContentViewCoreImpl::ShowSelectionHandlesAutomatically() const { 1248 void ContentViewCoreImpl::ShowSelectionHandlesAutomatically() const {
1429 JNIEnv* env = AttachCurrentThread(); 1249 JNIEnv* env = AttachCurrentThread();
1430 ScopedJavaLocalRef<jobject> obj(java_ref_.get(env)); 1250 ScopedJavaLocalRef<jobject> obj(java_ref_.get(env));
1431 if (obj.is_null()) 1251 if (obj.is_null())
1432 return; 1252 return;
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
1592 reinterpret_cast<ui::WindowAndroid*>(window_android), 1412 reinterpret_cast<ui::WindowAndroid*>(window_android),
1593 retained_objects_set); 1413 retained_objects_set);
1594 return reinterpret_cast<intptr_t>(view); 1414 return reinterpret_cast<intptr_t>(view);
1595 } 1415 }
1596 1416
1597 bool RegisterContentViewCore(JNIEnv* env) { 1417 bool RegisterContentViewCore(JNIEnv* env) {
1598 return RegisterNativesImpl(env); 1418 return RegisterNativesImpl(env);
1599 } 1419 }
1600 1420
1601 } // namespace content 1421 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698