Index: content/browser/web_contents/web_contents_android.cc |
diff --git a/content/browser/web_contents/web_contents_android.cc b/content/browser/web_contents/web_contents_android.cc |
index c86f394c0361f650b97fb0efa254cfee34c76ab3..f580fba9df2c518ee1a842a8ee879dd1ac5423d8 100644 |
--- a/content/browser/web_contents/web_contents_android.cc |
+++ b/content/browser/web_contents/web_contents_android.cc |
@@ -7,11 +7,24 @@ |
#include "base/android/jni_android.h" |
#include "base/android/jni_string.h" |
#include "base/logging.h" |
+#include "content/browser/android/interstitial_page_delegate_android.h" |
+#include "content/browser/frame_host/interstitial_page_impl.h" |
+#include "content/browser/frame_host/navigation_controller_impl.h" |
+#include "content/browser/frame_host/navigation_entry_impl.h" |
+#include "content/browser/media/media_web_contents_observer.h" |
+#include "content/browser/renderer_host/render_view_host_impl.h" |
+#include "content/browser/ssl/ssl_host_state.h" |
+#include "content/common/frame_messages.h" |
+#include "content/common/input_messages.h" |
+#include "content/common/view_messages.h" |
#include "content/public/browser/browser_thread.h" |
#include "content/public/browser/web_contents.h" |
#include "jni/WebContentsImpl_jni.h" |
+#include "ui/gfx/screen.h" |
using base::android::AttachCurrentThread; |
+using base::android::ConvertJavaStringToUTF8; |
+using base::android::ConvertUTF8ToJavaString; |
namespace content { |
@@ -36,9 +49,16 @@ bool WebContentsAndroid::Register(JNIEnv* env) { |
return RegisterNativesImpl(env); |
} |
+float GetPrimaryDisplayDeviceScaleFactor() { |
+ const gfx::Display& display = |
+ gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
+ return display.device_scale_factor(); |
+} |
+ |
WebContentsAndroid::WebContentsAndroid(WebContents* web_contents) |
: web_contents_(web_contents), |
- navigation_controller_(&(web_contents->GetController())) { |
+ navigation_controller_(&(web_contents->GetController())), |
+ dpi_scale_(GetPrimaryDisplayDeviceScaleFactor()) { |
JNIEnv* env = AttachCurrentThread(); |
obj_.Reset(env, |
Java_WebContentsImpl_create( |
@@ -77,4 +97,195 @@ void WebContentsAndroid::InsertCSS( |
web_contents_->InsertCSS(base::android::ConvertJavaStringToUTF8(env, jcss)); |
} |
+RenderWidgetHostViewAndroid* |
+ WebContentsAndroid::GetRenderWidgetHostViewAndroid() { |
+ RenderWidgetHostView* rwhv = NULL; |
+ if (web_contents_) { |
+ rwhv = web_contents_->GetRenderWidgetHostView(); |
+ if (web_contents_->ShowingInterstitialPage()) { |
+ rwhv = static_cast<InterstitialPageImpl*>( |
+ web_contents_->GetInterstitialPage())-> |
+ GetRenderViewHost()->GetView(); |
+ } |
+ } |
+ return static_cast<RenderWidgetHostViewAndroid*>(rwhv); |
+} |
+ |
+jint WebContentsAndroid::GetBackgroundColor(JNIEnv* env, jobject obj) { |
+ RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); |
+ if (!rwhva) |
+ return SK_ColorWHITE; |
+ return rwhva->GetCachedBackgroundColor(); |
+} |
+ |
+void WebContentsAndroid::OnHide(JNIEnv* env, jobject obj) { |
+ web_contents_->WasHidden(); |
+ PauseVideo(); |
+} |
+ |
+void WebContentsAndroid::OnShow(JNIEnv* env, jobject obj) { |
+ web_contents_->WasShown(); |
+} |
+ |
+void WebContentsAndroid::PauseVideo() { |
+ RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>( |
+ web_contents_->GetRenderViewHost()); |
+ if (rvhi) |
+ rvhi->media_web_contents_observer()->PauseVideo(); |
+} |
+ |
+void WebContentsAndroid::AddStyleSheetByURL( |
+ JNIEnv* env, |
+ jobject obj, |
+ jstring url) { |
+ if (!web_contents_) |
+ return; |
+ |
+ web_contents_->GetMainFrame()->Send(new FrameMsg_AddStyleSheetByURL( |
+ web_contents_->GetMainFrame()->GetRoutingID(), |
+ ConvertJavaStringToUTF8(env, url))); |
+} |
+ |
+void WebContentsAndroid::ShowInterstitialPage( |
+ JNIEnv* env, |
+ jobject obj, |
+ jstring jurl, |
+ jlong delegate_ptr) { |
+ GURL url(base::android::ConvertJavaStringToUTF8(env, jurl)); |
+ InterstitialPageDelegateAndroid* delegate = |
+ reinterpret_cast<InterstitialPageDelegateAndroid*>(delegate_ptr); |
+ InterstitialPage* interstitial = InterstitialPage::Create( |
+ web_contents_, false, url, delegate); |
+ delegate->set_interstitial_page(interstitial); |
+ interstitial->Show(); |
+} |
+ |
+jboolean WebContentsAndroid::IsShowingInterstitialPage(JNIEnv* env, |
+ jobject obj) { |
+ return web_contents_->ShowingInterstitialPage(); |
+} |
+ |
+jboolean WebContentsAndroid::IsRenderWidgetHostViewReady( |
+ JNIEnv* env, |
+ jobject obj) { |
+ RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); |
+ return view && view->HasValidFrame(); |
+} |
+ |
+void WebContentsAndroid::ExitFullscreen(JNIEnv* env, jobject obj) { |
+ RenderViewHost* host = web_contents_->GetRenderViewHost(); |
+ if (!host) |
+ return; |
+ host->ExitFullscreen(); |
+} |
+ |
+void WebContentsAndroid::UpdateTopControlsState( |
+ JNIEnv* env, |
+ jobject obj, |
+ bool enable_hiding, |
+ bool enable_showing, |
+ bool animate) { |
+ RenderViewHost* host = web_contents_->GetRenderViewHost(); |
+ if (!host) |
+ return; |
+ host->Send(new ViewMsg_UpdateTopControlsState(host->GetRoutingID(), |
+ enable_hiding, |
+ enable_showing, |
+ animate)); |
+} |
+ |
+void WebContentsAndroid::ShowImeIfNeeded(JNIEnv* env, jobject obj) { |
+ RenderViewHost* host = web_contents_->GetRenderViewHost(); |
+ host->Send(new ViewMsg_ShowImeIfNeeded(host->GetRoutingID())); |
+} |
+ |
+void WebContentsAndroid::ScrollFocusedEditableNodeIntoView( |
+ JNIEnv* env, |
+ jobject obj) { |
+ RenderViewHost* host = web_contents_->GetRenderViewHost(); |
+ host->Send(new InputMsg_ScrollFocusedEditableNodeIntoRect( |
+ host->GetRoutingID(), gfx::Rect())); |
+} |
+ |
+void WebContentsAndroid::SelectWordAroundCaret(JNIEnv* env, jobject obj) { |
+ RenderViewHost* host = web_contents_->GetRenderViewHost(); |
+ if (!host) |
+ return; |
+ host->SelectWordAroundCaret(); |
+} |
+ |
+ScopedJavaLocalRef<jstring> |
+WebContentsAndroid::GetOriginalUrlForActiveNavigationEntry( |
+ JNIEnv* env, |
+ jobject obj) { |
+ NavigationEntry* entry = web_contents_->GetController().GetVisibleEntry(); |
Yaron
2014/07/15 21:23:48
Seems like this would be better in NavigationContr
AKVT
2014/07/16 09:53:47
Will take care in next patch when I handle Navigat
|
+ if (entry == NULL) |
+ return ScopedJavaLocalRef<jstring>(env, NULL); |
+ return ConvertUTF8ToJavaString(env, entry->GetOriginalRequestURL().spec()); |
+} |
+ |
+long WebContentsAndroid::GetNativeImeAdapter(JNIEnv* env, jobject obj) { |
+ RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); |
+ if (!rwhva) |
+ return 0; |
+ return rwhva->GetNativeImeAdapter(); |
+} |
+ |
+bool WebContentsAndroid::GetUseDesktopUserAgent( |
+ JNIEnv* env, |
+ jobject obj) { |
+ NavigationEntry* entry = web_contents_->GetController().GetVisibleEntry(); |
+ return entry && entry->GetIsOverridingUserAgent(); |
+} |
+ |
+void WebContentsAndroid::ClearSslPreferences(JNIEnv* env, jobject obj) { |
+ SSLHostState* state = SSLHostState::GetFor( |
+ web_contents_->GetController().GetBrowserContext()); |
+ state->Clear(); |
+} |
+ |
+void WebContentsAndroid::SetUseDesktopUserAgent( |
+ JNIEnv* env, |
+ jobject obj, |
+ jboolean enabled, |
+ jboolean reload_on_state_change) { |
+ if (GetUseDesktopUserAgent(env, obj) == enabled) |
+ return; |
+ |
+ // Make sure the navigation entry actually exists. |
+ NavigationEntry* entry = web_contents_->GetController().GetVisibleEntry(); |
+ if (!entry) |
+ return; |
+ |
+ // Set the flag in the NavigationEntry. |
+ entry->SetIsOverridingUserAgent(enabled); |
+ |
+ // Send the override to the renderer. |
+ if (reload_on_state_change) { |
+ // Reloading the page will send the override down as part of the |
+ // navigation IPC message. |
+ NavigationControllerImpl& controller = |
+ static_cast<NavigationControllerImpl&>(web_contents_->GetController()); |
+ controller.ReloadOriginalRequestURL(false); |
+ } |
+} |
+ |
+void WebContentsAndroid::ExtractSmartClipData( |
+ JNIEnv* env, |
+ jobject obj, |
+ jint x, |
+ jint y, |
+ jint width, |
+ jint height) { |
+ gfx::Rect rect( |
+ static_cast<int>(x / dpi_scale()), |
+ static_cast<int>(y / dpi_scale()), |
+ static_cast<int>((width > 0 && width < dpi_scale()) ? |
+ 1 : (int)(width / dpi_scale())), |
+ static_cast<int>((height > 0 && height < dpi_scale()) ? |
+ 1 : (int)(height / dpi_scale()))); |
+ web_contents_->Send(new ViewMsg_ExtractSmartClipData( |
+ web_contents_->GetRoutingID(), rect)); |
+} |
+ |
} // namespace content |