| 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 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1653 reinterpret_cast<ui::WindowAndroid*>(window_android), | 1564 reinterpret_cast<ui::WindowAndroid*>(window_android), |
| 1654 retained_objects_set); | 1565 retained_objects_set); |
| 1655 return reinterpret_cast<intptr_t>(view); | 1566 return reinterpret_cast<intptr_t>(view); |
| 1656 } | 1567 } |
| 1657 | 1568 |
| 1658 bool RegisterContentViewCore(JNIEnv* env) { | 1569 bool RegisterContentViewCore(JNIEnv* env) { |
| 1659 return RegisterNativesImpl(env); | 1570 return RegisterNativesImpl(env); |
| 1660 } | 1571 } |
| 1661 | 1572 |
| 1662 } // namespace content | 1573 } // namespace content |
| OLD | NEW |