Chromium Code Reviews| 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 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 343 return java_ref_.get(env); | 343 return java_ref_.get(env); |
| 344 } | 344 } |
| 345 | 345 |
| 346 jint ContentViewCoreImpl::GetBackgroundColor(JNIEnv* env, jobject obj) { | 346 jint ContentViewCoreImpl::GetBackgroundColor(JNIEnv* env, jobject obj) { |
| 347 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); | 347 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); |
| 348 if (!rwhva) | 348 if (!rwhva) |
| 349 return SK_ColorWHITE; | 349 return SK_ColorWHITE; |
| 350 return rwhva->GetCachedBackgroundColor(); | 350 return rwhva->GetCachedBackgroundColor(); |
| 351 } | 351 } |
| 352 | 352 |
| 353 void ContentViewCoreImpl::OnHide(JNIEnv* env, jobject obj) { | |
| 354 Hide(); | |
| 355 } | |
| 356 | |
| 357 void ContentViewCoreImpl::OnShow(JNIEnv* env, jobject obj) { | |
| 358 Show(); | |
| 359 } | |
| 360 | |
| 361 void ContentViewCoreImpl::Show() { | |
| 362 GetWebContents()->WasShown(); | |
| 363 } | |
| 364 | |
| 365 void ContentViewCoreImpl::Hide() { | |
| 366 GetWebContents()->WasHidden(); | |
| 367 PauseVideo(); | |
| 368 } | |
| 369 | |
| 370 void ContentViewCoreImpl::PauseVideo() { | 353 void ContentViewCoreImpl::PauseVideo() { |
| 371 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>( | 354 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>( |
| 372 web_contents_->GetRenderViewHost()); | 355 web_contents_->GetRenderViewHost()); |
| 373 if (rvhi) | 356 if (rvhi) |
| 374 rvhi->media_web_contents_observer()->PauseVideo(); | 357 rvhi->media_web_contents_observer()->PauseVideo(); |
| 375 } | 358 } |
| 376 | 359 |
| 377 void ContentViewCoreImpl::PauseOrResumeGeolocation(bool should_pause) { | 360 void ContentViewCoreImpl::PauseOrResumeGeolocation(bool should_pause) { |
| 378 web_contents_->geolocation_dispatcher_host()->PauseOrResume(should_pause); | 361 web_contents_->geolocation_dispatcher_host()->PauseOrResume(should_pause); |
| 379 } | 362 } |
| (...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1172 if (rwhv) | 1155 if (rwhv) |
| 1173 rwhv->SetMultiTouchZoomSupportEnabled(enabled); | 1156 rwhv->SetMultiTouchZoomSupportEnabled(enabled); |
| 1174 } | 1157 } |
| 1175 | 1158 |
| 1176 void ContentViewCoreImpl::ClearHistory(JNIEnv* env, jobject obj) { | 1159 void ContentViewCoreImpl::ClearHistory(JNIEnv* env, jobject obj) { |
| 1177 // TODO(creis): Do callers of this need to know if it fails? | 1160 // TODO(creis): Do callers of this need to know if it fails? |
| 1178 if (web_contents_->GetController().CanPruneAllButLastCommitted()) | 1161 if (web_contents_->GetController().CanPruneAllButLastCommitted()) |
| 1179 web_contents_->GetController().PruneAllButLastCommitted(); | 1162 web_contents_->GetController().PruneAllButLastCommitted(); |
| 1180 } | 1163 } |
| 1181 | 1164 |
| 1182 void ContentViewCoreImpl::AddStyleSheetByURL( | |
| 1183 JNIEnv* env, jobject obj, jstring url) { | |
| 1184 if (!web_contents_) | |
| 1185 return; | |
| 1186 | |
| 1187 web_contents_->GetMainFrame()->Send(new FrameMsg_AddStyleSheetByURL( | |
| 1188 web_contents_->GetMainFrame()->GetRoutingID(), | |
| 1189 ConvertJavaStringToUTF8(env, url))); | |
| 1190 } | |
| 1191 | |
| 1192 void ContentViewCoreImpl::SetAllowJavascriptInterfacesInspection( | 1165 void ContentViewCoreImpl::SetAllowJavascriptInterfacesInspection( |
| 1193 JNIEnv* env, | 1166 JNIEnv* env, |
| 1194 jobject obj, | 1167 jobject obj, |
| 1195 jboolean allow) { | 1168 jboolean allow) { |
| 1196 java_bridge_dispatcher_host_->SetAllowObjectContentsInspection(allow); | 1169 java_bridge_dispatcher_host_->SetAllowObjectContentsInspection(allow); |
| 1197 } | 1170 } |
| 1198 | 1171 |
| 1199 void ContentViewCoreImpl::AddJavascriptInterface( | 1172 void ContentViewCoreImpl::AddJavascriptInterface( |
| 1200 JNIEnv* env, | 1173 JNIEnv* env, |
| 1201 jobject /* obj */, | 1174 jobject /* obj */, |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 1223 root_layer_->SetBounds(physical_size); | 1196 root_layer_->SetBounds(physical_size); |
| 1224 | 1197 |
| 1225 if (view) { | 1198 if (view) { |
| 1226 RenderWidgetHostImpl* host = RenderWidgetHostImpl::From( | 1199 RenderWidgetHostImpl* host = RenderWidgetHostImpl::From( |
| 1227 view->GetRenderWidgetHost()); | 1200 view->GetRenderWidgetHost()); |
| 1228 host->SendScreenRects(); | 1201 host->SendScreenRects(); |
| 1229 view->WasResized(); | 1202 view->WasResized(); |
| 1230 } | 1203 } |
| 1231 } | 1204 } |
| 1232 | 1205 |
| 1233 void ContentViewCoreImpl::ShowInterstitialPage( | |
| 1234 JNIEnv* env, jobject obj, jstring jurl, jlong delegate_ptr) { | |
| 1235 GURL url(base::android::ConvertJavaStringToUTF8(env, jurl)); | |
| 1236 InterstitialPageDelegateAndroid* delegate = | |
| 1237 reinterpret_cast<InterstitialPageDelegateAndroid*>(delegate_ptr); | |
| 1238 InterstitialPage* interstitial = InterstitialPage::Create( | |
| 1239 web_contents_, false, url, delegate); | |
| 1240 delegate->set_interstitial_page(interstitial); | |
| 1241 interstitial->Show(); | |
| 1242 } | |
| 1243 | |
| 1244 jboolean ContentViewCoreImpl::IsShowingInterstitialPage(JNIEnv* env, | |
| 1245 jobject obj) { | |
| 1246 return web_contents_->ShowingInterstitialPage(); | |
| 1247 } | |
| 1248 | |
| 1249 jboolean ContentViewCoreImpl::IsRenderWidgetHostViewReady(JNIEnv* env, | |
| 1250 jobject obj) { | |
| 1251 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); | |
| 1252 return view && view->HasValidFrame(); | |
| 1253 } | |
| 1254 | |
| 1255 void ContentViewCoreImpl::ExitFullscreen(JNIEnv* env, jobject obj) { | |
| 1256 RenderViewHost* host = web_contents_->GetRenderViewHost(); | |
| 1257 if (!host) | |
| 1258 return; | |
| 1259 host->ExitFullscreen(); | |
| 1260 } | |
| 1261 | |
| 1262 void ContentViewCoreImpl::UpdateTopControlsState(JNIEnv* env, | |
| 1263 jobject obj, | |
| 1264 bool enable_hiding, | |
| 1265 bool enable_showing, | |
| 1266 bool animate) { | |
| 1267 RenderViewHost* host = web_contents_->GetRenderViewHost(); | |
| 1268 if (!host) | |
| 1269 return; | |
| 1270 host->Send(new ViewMsg_UpdateTopControlsState(host->GetRoutingID(), | |
| 1271 enable_hiding, | |
| 1272 enable_showing, | |
| 1273 animate)); | |
| 1274 } | |
| 1275 | |
| 1276 void ContentViewCoreImpl::ShowImeIfNeeded(JNIEnv* env, jobject obj) { | |
| 1277 RenderViewHost* host = web_contents_->GetRenderViewHost(); | |
| 1278 host->Send(new ViewMsg_ShowImeIfNeeded(host->GetRoutingID())); | |
| 1279 } | |
| 1280 | |
| 1281 void ContentViewCoreImpl::ScrollFocusedEditableNodeIntoView(JNIEnv* env, | |
| 1282 jobject obj) { | |
| 1283 RenderViewHost* host = web_contents_->GetRenderViewHost(); | |
| 1284 host->Send(new InputMsg_ScrollFocusedEditableNodeIntoRect( | |
| 1285 host->GetRoutingID(), gfx::Rect())); | |
| 1286 } | |
| 1287 | |
| 1288 void ContentViewCoreImpl::SelectWordAroundCaret(JNIEnv* env, jobject obj) { | |
| 1289 RenderViewHost* host = web_contents_->GetRenderViewHost(); | |
| 1290 if (!host) | |
| 1291 return; | |
| 1292 host->SelectWordAroundCaret(); | |
| 1293 } | |
| 1294 | |
| 1295 namespace { | 1206 namespace { |
| 1296 | 1207 |
| 1297 static void AddNavigationEntryToHistory(JNIEnv* env, jobject obj, | 1208 static void AddNavigationEntryToHistory(JNIEnv* env, jobject obj, |
| 1298 jobject history, | 1209 jobject history, |
| 1299 NavigationEntry* entry, | 1210 NavigationEntry* entry, |
| 1300 int index) { | 1211 int index) { |
| 1301 // Get the details of the current entry | 1212 // Get the details of the current entry |
| 1302 ScopedJavaLocalRef<jstring> j_url( | 1213 ScopedJavaLocalRef<jstring> j_url( |
| 1303 ConvertUTF8ToJavaString(env, entry->GetURL().spec())); | 1214 ConvertUTF8ToJavaString(env, entry->GetURL().spec())); |
| 1304 ScopedJavaLocalRef<jstring> j_virtual_url( | 1215 ScopedJavaLocalRef<jstring> j_virtual_url( |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1349 i += increment_value) { | 1260 i += increment_value) { |
| 1350 if (num_added >= max_entries) | 1261 if (num_added >= max_entries) |
| 1351 break; | 1262 break; |
| 1352 | 1263 |
| 1353 AddNavigationEntryToHistory( | 1264 AddNavigationEntryToHistory( |
| 1354 env, obj, history, controller.GetEntryAtIndex(i), i); | 1265 env, obj, history, controller.GetEntryAtIndex(i), i); |
| 1355 num_added++; | 1266 num_added++; |
| 1356 } | 1267 } |
| 1357 } | 1268 } |
| 1358 | 1269 |
| 1359 ScopedJavaLocalRef<jstring> | |
| 1360 ContentViewCoreImpl::GetOriginalUrlForActiveNavigationEntry(JNIEnv* env, | |
| 1361 jobject obj) { | |
| 1362 NavigationEntry* entry = web_contents_->GetController().GetVisibleEntry(); | |
| 1363 if (entry == NULL) | |
| 1364 return ScopedJavaLocalRef<jstring>(env, NULL); | |
| 1365 return ConvertUTF8ToJavaString(env, entry->GetOriginalRequestURL().spec()); | |
| 1366 } | |
| 1367 | |
| 1368 long ContentViewCoreImpl::GetNativeImeAdapter(JNIEnv* env, jobject obj) { | |
|
Yaron
2014/07/15 21:23:48
I don't think it makes sense to move this out. You
AKVT
2014/07/16 09:53:47
Thanks, IME changes I am keeping untouched time be
| |
| 1369 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); | |
| 1370 if (!rwhva) | |
| 1371 return 0; | |
| 1372 return rwhva->GetNativeImeAdapter(); | |
| 1373 } | |
| 1374 | |
| 1375 namespace { | 1270 namespace { |
| 1376 void JavaScriptResultCallback(const ScopedJavaGlobalRef<jobject>& callback, | 1271 void JavaScriptResultCallback(const ScopedJavaGlobalRef<jobject>& callback, |
| 1377 const base::Value* result) { | 1272 const base::Value* result) { |
| 1378 JNIEnv* env = base::android::AttachCurrentThread(); | 1273 JNIEnv* env = base::android::AttachCurrentThread(); |
| 1379 std::string json; | 1274 std::string json; |
| 1380 base::JSONWriter::Write(result, &json); | 1275 base::JSONWriter::Write(result, &json); |
| 1381 ScopedJavaLocalRef<jstring> j_json = ConvertUTF8ToJavaString(env, json); | 1276 ScopedJavaLocalRef<jstring> j_json = ConvertUTF8ToJavaString(env, json); |
| 1382 Java_ContentViewCore_onEvaluateJavaScriptResult(env, | 1277 Java_ContentViewCore_onEvaluateJavaScriptResult(env, |
| 1383 j_json.obj(), | 1278 j_json.obj(), |
| 1384 callback.obj()); | 1279 callback.obj()); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 1412 ScopedJavaGlobalRef<jobject> j_callback; | 1307 ScopedJavaGlobalRef<jobject> j_callback; |
| 1413 j_callback.Reset(env, callback); | 1308 j_callback.Reset(env, callback); |
| 1414 content::RenderFrameHost::JavaScriptResultCallback c_callback = | 1309 content::RenderFrameHost::JavaScriptResultCallback c_callback = |
| 1415 base::Bind(&JavaScriptResultCallback, j_callback); | 1310 base::Bind(&JavaScriptResultCallback, j_callback); |
| 1416 | 1311 |
| 1417 web_contents_->GetMainFrame()->ExecuteJavaScript( | 1312 web_contents_->GetMainFrame()->ExecuteJavaScript( |
| 1418 ConvertJavaStringToUTF16(env, script), | 1313 ConvertJavaStringToUTF16(env, script), |
| 1419 c_callback); | 1314 c_callback); |
| 1420 } | 1315 } |
| 1421 | 1316 |
| 1422 bool ContentViewCoreImpl::GetUseDesktopUserAgent( | |
| 1423 JNIEnv* env, jobject obj) { | |
| 1424 NavigationEntry* entry = web_contents_->GetController().GetVisibleEntry(); | |
| 1425 return entry && entry->GetIsOverridingUserAgent(); | |
| 1426 } | |
| 1427 | |
| 1428 void ContentViewCoreImpl::UpdateImeAdapter(long native_ime_adapter, | 1317 void ContentViewCoreImpl::UpdateImeAdapter(long native_ime_adapter, |
| 1429 int text_input_type, | 1318 int text_input_type, |
| 1430 const std::string& text, | 1319 const std::string& text, |
| 1431 int selection_start, | 1320 int selection_start, |
| 1432 int selection_end, | 1321 int selection_end, |
| 1433 int composition_start, | 1322 int composition_start, |
| 1434 int composition_end, | 1323 int composition_end, |
| 1435 bool show_ime_if_needed, | 1324 bool show_ime_if_needed, |
| 1436 bool is_non_ime_change) { | 1325 bool is_non_ime_change) { |
| 1437 JNIEnv* env = AttachCurrentThread(); | 1326 JNIEnv* env = AttachCurrentThread(); |
| 1438 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 1327 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 1439 if (obj.is_null()) | 1328 if (obj.is_null()) |
| 1440 return; | 1329 return; |
| 1441 | 1330 |
| 1442 ScopedJavaLocalRef<jstring> jstring_text = ConvertUTF8ToJavaString(env, text); | 1331 ScopedJavaLocalRef<jstring> jstring_text = ConvertUTF8ToJavaString(env, text); |
| 1443 Java_ContentViewCore_updateImeAdapter(env, obj.obj(), | 1332 Java_ContentViewCore_updateImeAdapter(env, obj.obj(), |
| 1444 native_ime_adapter, text_input_type, | 1333 native_ime_adapter, text_input_type, |
| 1445 jstring_text.obj(), | 1334 jstring_text.obj(), |
| 1446 selection_start, selection_end, | 1335 selection_start, selection_end, |
| 1447 composition_start, composition_end, | 1336 composition_start, composition_end, |
| 1448 show_ime_if_needed, is_non_ime_change); | 1337 show_ime_if_needed, is_non_ime_change); |
| 1449 } | 1338 } |
| 1450 | 1339 |
| 1451 void ContentViewCoreImpl::ClearSslPreferences(JNIEnv* env, jobject obj) { | |
| 1452 SSLHostState* state = SSLHostState::GetFor( | |
| 1453 web_contents_->GetController().GetBrowserContext()); | |
| 1454 state->Clear(); | |
| 1455 } | |
| 1456 | |
| 1457 void ContentViewCoreImpl::SetUseDesktopUserAgent( | |
| 1458 JNIEnv* env, | |
| 1459 jobject obj, | |
| 1460 jboolean enabled, | |
| 1461 jboolean reload_on_state_change) { | |
| 1462 if (GetUseDesktopUserAgent(env, obj) == enabled) | |
| 1463 return; | |
| 1464 | |
| 1465 // Make sure the navigation entry actually exists. | |
| 1466 NavigationEntry* entry = web_contents_->GetController().GetVisibleEntry(); | |
| 1467 if (!entry) | |
| 1468 return; | |
| 1469 | |
| 1470 // Set the flag in the NavigationEntry. | |
| 1471 entry->SetIsOverridingUserAgent(enabled); | |
| 1472 | |
| 1473 // Send the override to the renderer. | |
| 1474 if (reload_on_state_change) { | |
| 1475 // Reloading the page will send the override down as part of the | |
| 1476 // navigation IPC message. | |
| 1477 NavigationControllerImpl& controller = | |
| 1478 static_cast<NavigationControllerImpl&>(web_contents_->GetController()); | |
| 1479 controller.ReloadOriginalRequestURL(false); | |
| 1480 } | |
| 1481 } | |
| 1482 | |
| 1483 void ContentViewCoreImpl::SetAccessibilityEnabled(JNIEnv* env, jobject obj, | 1340 void ContentViewCoreImpl::SetAccessibilityEnabled(JNIEnv* env, jobject obj, |
| 1484 bool enabled) { | 1341 bool enabled) { |
| 1485 SetAccessibilityEnabledInternal(enabled); | 1342 SetAccessibilityEnabledInternal(enabled); |
| 1486 } | 1343 } |
| 1487 | 1344 |
| 1488 void ContentViewCoreImpl::ShowSelectionHandlesAutomatically() const { | 1345 void ContentViewCoreImpl::ShowSelectionHandlesAutomatically() const { |
| 1489 JNIEnv* env = AttachCurrentThread(); | 1346 JNIEnv* env = AttachCurrentThread(); |
| 1490 ScopedJavaLocalRef<jobject> obj(java_ref_.get(env)); | 1347 ScopedJavaLocalRef<jobject> obj(java_ref_.get(env)); |
| 1491 if (obj.is_null()) | 1348 if (obj.is_null()) |
| 1492 return; | 1349 return; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1527 | 1384 |
| 1528 void ContentViewCoreImpl::SendOrientationChangeEventInternal() { | 1385 void ContentViewCoreImpl::SendOrientationChangeEventInternal() { |
| 1529 static_cast<WebContentsImpl*>(web_contents())-> | 1386 static_cast<WebContentsImpl*>(web_contents())-> |
| 1530 screen_orientation_dispatcher_host()->OnOrientationChange(); | 1387 screen_orientation_dispatcher_host()->OnOrientationChange(); |
| 1531 | 1388 |
| 1532 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); | 1389 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); |
| 1533 if (rwhv) | 1390 if (rwhv) |
| 1534 rwhv->UpdateScreenInfo(GetViewAndroid()); | 1391 rwhv->UpdateScreenInfo(GetViewAndroid()); |
| 1535 } | 1392 } |
| 1536 | 1393 |
| 1537 void ContentViewCoreImpl::ExtractSmartClipData(JNIEnv* env, | |
| 1538 jobject obj, | |
| 1539 jint x, | |
| 1540 jint y, | |
| 1541 jint width, | |
| 1542 jint height) { | |
| 1543 gfx::Rect rect( | |
| 1544 static_cast<int>(x / dpi_scale()), | |
| 1545 static_cast<int>(y / dpi_scale()), | |
| 1546 static_cast<int>((width > 0 && width < dpi_scale()) ? | |
| 1547 1 : (int)(width / dpi_scale())), | |
| 1548 static_cast<int>((height > 0 && height < dpi_scale()) ? | |
| 1549 1 : (int)(height / dpi_scale()))); | |
| 1550 GetWebContents()->Send(new ViewMsg_ExtractSmartClipData( | |
| 1551 GetWebContents()->GetRoutingID(), rect)); | |
| 1552 } | |
| 1553 | |
| 1554 void ContentViewCoreImpl::ResumeResponseDeferredAtStart(JNIEnv* env, | 1394 void ContentViewCoreImpl::ResumeResponseDeferredAtStart(JNIEnv* env, |
| 1555 jobject obj) { | 1395 jobject obj) { |
| 1556 static_cast<WebContentsImpl*>(GetWebContents())-> | 1396 static_cast<WebContentsImpl*>(GetWebContents())-> |
| 1557 ResumeResponseDeferredAtStart(); | 1397 ResumeResponseDeferredAtStart(); |
| 1558 } | 1398 } |
| 1559 | 1399 |
| 1560 void ContentViewCoreImpl::SetHasPendingNavigationTransitionForTesting( | 1400 void ContentViewCoreImpl::SetHasPendingNavigationTransitionForTesting( |
| 1561 JNIEnv* env, | 1401 JNIEnv* env, |
| 1562 jobject obj) { | 1402 jobject obj) { |
| 1563 RenderFrameHost* frame = static_cast<WebContentsImpl*>(GetWebContents())-> | 1403 RenderFrameHost* frame = static_cast<WebContentsImpl*>(GetWebContents())-> |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1653 reinterpret_cast<ui::WindowAndroid*>(window_android), | 1493 reinterpret_cast<ui::WindowAndroid*>(window_android), |
| 1654 retained_objects_set); | 1494 retained_objects_set); |
| 1655 return reinterpret_cast<intptr_t>(view); | 1495 return reinterpret_cast<intptr_t>(view); |
| 1656 } | 1496 } |
| 1657 | 1497 |
| 1658 bool RegisterContentViewCore(JNIEnv* env) { | 1498 bool RegisterContentViewCore(JNIEnv* env) { |
| 1659 return RegisterNativesImpl(env); | 1499 return RegisterNativesImpl(env); |
| 1660 } | 1500 } |
| 1661 | 1501 |
| 1662 } // namespace content | 1502 } // namespace content |
| OLD | NEW |