Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/web_contents/web_contents_android.h" | 5 #include "content/browser/web_contents/web_contents_android.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "content/browser/android/interstitial_page_delegate_android.h" | |
| 11 #include "content/browser/frame_host/interstitial_page_impl.h" | |
| 12 #include "content/browser/media/media_web_contents_observer.h" | |
| 13 #include "content/browser/renderer_host/render_view_host_impl.h" | |
| 14 #include "content/common/frame_messages.h" | |
| 15 #include "content/common/input_messages.h" | |
| 16 #include "content/common/view_messages.h" | |
| 10 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 11 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
| 12 #include "jni/WebContentsImpl_jni.h" | 19 #include "jni/WebContentsImpl_jni.h" |
| 13 | 20 |
| 14 using base::android::AttachCurrentThread; | 21 using base::android::AttachCurrentThread; |
| 22 using base::android::ConvertJavaStringToUTF8; | |
| 15 | 23 |
| 16 namespace content { | 24 namespace content { |
| 17 | 25 |
| 18 // static | 26 // static |
| 19 WebContents* WebContents::FromJavaWebContents( | 27 WebContents* WebContents::FromJavaWebContents( |
| 20 jobject jweb_contents_android) { | 28 jobject jweb_contents_android) { |
| 21 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 29 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 22 if (!jweb_contents_android) | 30 if (!jweb_contents_android) |
| 23 return NULL; | 31 return NULL; |
| 24 | 32 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 | 78 |
| 71 void WebContentsAndroid::Stop(JNIEnv* env, jobject obj) { | 79 void WebContentsAndroid::Stop(JNIEnv* env, jobject obj) { |
| 72 web_contents_->Stop(); | 80 web_contents_->Stop(); |
| 73 } | 81 } |
| 74 | 82 |
| 75 void WebContentsAndroid::InsertCSS( | 83 void WebContentsAndroid::InsertCSS( |
| 76 JNIEnv* env, jobject jobj, jstring jcss) { | 84 JNIEnv* env, jobject jobj, jstring jcss) { |
| 77 web_contents_->InsertCSS(base::android::ConvertJavaStringToUTF8(env, jcss)); | 85 web_contents_->InsertCSS(base::android::ConvertJavaStringToUTF8(env, jcss)); |
| 78 } | 86 } |
| 79 | 87 |
| 88 RenderWidgetHostViewAndroid* | |
| 89 WebContentsAndroid::GetRenderWidgetHostViewAndroid() { | |
| 90 RenderWidgetHostView* rwhv = NULL; | |
| 91 if (web_contents_) { | |
|
Yaron
2014/07/16 17:14:54
remove if-check. This is constructed with a web co
AKVT
2014/07/17 03:08:32
Done.
| |
| 92 rwhv = web_contents_->GetRenderWidgetHostView(); | |
| 93 if (web_contents_->ShowingInterstitialPage()) { | |
| 94 rwhv = static_cast<InterstitialPageImpl*>( | |
| 95 web_contents_->GetInterstitialPage())-> | |
| 96 GetRenderViewHost()->GetView(); | |
| 97 } | |
| 98 } | |
| 99 return static_cast<RenderWidgetHostViewAndroid*>(rwhv); | |
| 100 } | |
| 101 | |
| 102 jint WebContentsAndroid::GetBackgroundColor(JNIEnv* env, jobject obj) { | |
| 103 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); | |
| 104 if (!rwhva) | |
| 105 return SK_ColorWHITE; | |
| 106 return rwhva->GetCachedBackgroundColor(); | |
| 107 } | |
| 108 | |
| 109 void WebContentsAndroid::OnHide(JNIEnv* env, jobject obj) { | |
| 110 web_contents_->WasHidden(); | |
| 111 PauseVideo(); | |
| 112 } | |
| 113 | |
| 114 void WebContentsAndroid::OnShow(JNIEnv* env, jobject obj) { | |
| 115 web_contents_->WasShown(); | |
| 116 } | |
| 117 | |
| 118 void WebContentsAndroid::PauseVideo() { | |
| 119 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>( | |
| 120 web_contents_->GetRenderViewHost()); | |
| 121 if (rvhi) | |
| 122 rvhi->media_web_contents_observer()->PauseVideo(); | |
| 123 } | |
| 124 | |
| 125 void WebContentsAndroid::AddStyleSheetByURL( | |
| 126 JNIEnv* env, | |
| 127 jobject obj, | |
| 128 jstring url) { | |
| 129 if (!web_contents_) | |
|
Yaron
2014/07/16 17:14:54
remove
AKVT
2014/07/17 03:08:32
Done.
| |
| 130 return; | |
| 131 | |
| 132 web_contents_->GetMainFrame()->Send(new FrameMsg_AddStyleSheetByURL( | |
| 133 web_contents_->GetMainFrame()->GetRoutingID(), | |
| 134 ConvertJavaStringToUTF8(env, url))); | |
| 135 } | |
| 136 | |
| 137 void WebContentsAndroid::ShowInterstitialPage( | |
| 138 JNIEnv* env, | |
| 139 jobject obj, | |
| 140 jstring jurl, | |
| 141 jlong delegate_ptr) { | |
| 142 GURL url(base::android::ConvertJavaStringToUTF8(env, jurl)); | |
| 143 InterstitialPageDelegateAndroid* delegate = | |
| 144 reinterpret_cast<InterstitialPageDelegateAndroid*>(delegate_ptr); | |
| 145 InterstitialPage* interstitial = InterstitialPage::Create( | |
| 146 web_contents_, false, url, delegate); | |
| 147 delegate->set_interstitial_page(interstitial); | |
| 148 interstitial->Show(); | |
| 149 } | |
| 150 | |
| 151 jboolean WebContentsAndroid::IsShowingInterstitialPage(JNIEnv* env, | |
| 152 jobject obj) { | |
| 153 return web_contents_->ShowingInterstitialPage(); | |
| 154 } | |
| 155 | |
| 156 jboolean WebContentsAndroid::IsRenderWidgetHostViewReady( | |
| 157 JNIEnv* env, | |
| 158 jobject obj) { | |
| 159 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); | |
| 160 return view && view->HasValidFrame(); | |
| 161 } | |
| 162 | |
| 163 void WebContentsAndroid::ExitFullscreen(JNIEnv* env, jobject obj) { | |
| 164 RenderViewHost* host = web_contents_->GetRenderViewHost(); | |
| 165 if (!host) | |
| 166 return; | |
| 167 host->ExitFullscreen(); | |
| 168 } | |
| 169 | |
| 170 void WebContentsAndroid::UpdateTopControlsState( | |
| 171 JNIEnv* env, | |
| 172 jobject obj, | |
| 173 bool enable_hiding, | |
| 174 bool enable_showing, | |
| 175 bool animate) { | |
| 176 RenderViewHost* host = web_contents_->GetRenderViewHost(); | |
| 177 if (!host) | |
| 178 return; | |
| 179 host->Send(new ViewMsg_UpdateTopControlsState(host->GetRoutingID(), | |
| 180 enable_hiding, | |
| 181 enable_showing, | |
| 182 animate)); | |
| 183 } | |
| 184 | |
| 185 void WebContentsAndroid::ShowImeIfNeeded(JNIEnv* env, jobject obj) { | |
| 186 RenderViewHost* host = web_contents_->GetRenderViewHost(); | |
| 187 host->Send(new ViewMsg_ShowImeIfNeeded(host->GetRoutingID())); | |
| 188 } | |
| 189 | |
| 190 void WebContentsAndroid::ScrollFocusedEditableNodeIntoView( | |
| 191 JNIEnv* env, | |
| 192 jobject obj) { | |
| 193 RenderViewHost* host = web_contents_->GetRenderViewHost(); | |
| 194 host->Send(new InputMsg_ScrollFocusedEditableNodeIntoRect( | |
| 195 host->GetRoutingID(), gfx::Rect())); | |
| 196 } | |
| 197 | |
| 198 void WebContentsAndroid::SelectWordAroundCaret(JNIEnv* env, jobject obj) { | |
| 199 RenderViewHost* host = web_contents_->GetRenderViewHost(); | |
| 200 if (!host) | |
| 201 return; | |
| 202 host->SelectWordAroundCaret(); | |
| 203 } | |
| 80 } // namespace content | 204 } // namespace content |
| OLD | NEW |