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 rwhv = web_contents_->GetRenderWidgetHostView(); | |
| 92 if (web_contents_->ShowingInterstitialPage()) { | |
| 93 rwhv = static_cast<InterstitialPageImpl*>( | |
| 94 web_contents_->GetInterstitialPage())-> | |
| 95 GetRenderViewHost()->GetView(); | |
| 96 } | |
| 97 return static_cast<RenderWidgetHostViewAndroid*>(rwhv); | |
| 98 } | |
| 99 | |
| 100 jint WebContentsAndroid::GetBackgroundColor(JNIEnv* env, jobject obj) { | |
| 101 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); | |
| 102 if (!rwhva) | |
| 103 return SK_ColorWHITE; | |
| 104 return rwhva->GetCachedBackgroundColor(); | |
| 105 } | |
| 106 | |
| 107 void WebContentsAndroid::OnHide(JNIEnv* env, jobject obj) { | |
| 108 web_contents_->WasHidden(); | |
| 109 PauseVideo(); | |
| 110 } | |
| 111 | |
| 112 void WebContentsAndroid::OnShow(JNIEnv* env, jobject obj) { | |
| 113 web_contents_->WasShown(); | |
| 114 } | |
| 115 | |
| 116 void WebContentsAndroid::PauseVideo() { | |
| 117 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>( | |
| 118 web_contents_->GetRenderViewHost()); | |
| 119 if (rvhi) | |
| 120 rvhi->media_web_contents_observer()->PauseVideo(); | |
| 121 } | |
| 122 | |
| 123 void WebContentsAndroid::AddStyleSheetByURL( | |
| 124 JNIEnv* env, | |
| 125 jobject obj, | |
| 126 jstring url) { | |
| 127 web_contents_->GetMainFrame()->Send(new FrameMsg_AddStyleSheetByURL( | |
| 128 web_contents_->GetMainFrame()->GetRoutingID(), | |
| 129 ConvertJavaStringToUTF8(env, url))); | |
| 130 } | |
| 131 | |
| 132 void WebContentsAndroid::ShowInterstitialPage( | |
| 133 JNIEnv* env, | |
| 134 jobject obj, | |
| 135 jstring jurl, | |
| 136 jlong delegate_ptr) { | |
| 137 GURL url(base::android::ConvertJavaStringToUTF8(env, jurl)); | |
| 138 InterstitialPageDelegateAndroid* delegate = | |
| 139 reinterpret_cast<InterstitialPageDelegateAndroid*>(delegate_ptr); | |
| 140 InterstitialPage* interstitial = InterstitialPage::Create( | |
| 141 web_contents_, false, url, delegate); | |
| 142 delegate->set_interstitial_page(interstitial); | |
| 143 interstitial->Show(); | |
| 144 } | |
| 145 | |
| 146 jboolean WebContentsAndroid::IsShowingInterstitialPage(JNIEnv* env, | |
| 147 jobject obj) { | |
| 148 return web_contents_->ShowingInterstitialPage(); | |
| 149 } | |
| 150 | |
| 151 jboolean WebContentsAndroid::IsRenderWidgetHostViewReady( | |
| 152 JNIEnv* env, | |
| 153 jobject obj) { | |
| 154 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); | |
| 155 return view && view->HasValidFrame(); | |
| 156 } | |
| 157 | |
| 158 void WebContentsAndroid::ExitFullscreen(JNIEnv* env, jobject obj) { | |
| 159 RenderViewHost* host = web_contents_->GetRenderViewHost(); | |
| 160 if (!host) | |
| 161 return; | |
| 162 host->ExitFullscreen(); | |
| 163 } | |
| 164 | |
| 165 void WebContentsAndroid::UpdateTopControlsState( | |
| 166 JNIEnv* env, | |
| 167 jobject obj, | |
| 168 bool enable_hiding, | |
| 169 bool enable_showing, | |
| 170 bool animate) { | |
| 171 RenderViewHost* host = web_contents_->GetRenderViewHost(); | |
| 172 if (!host) | |
| 173 return; | |
| 174 host->Send(new ViewMsg_UpdateTopControlsState(host->GetRoutingID(), | |
| 175 enable_hiding, | |
| 176 enable_showing, | |
| 177 animate)); | |
| 178 } | |
| 179 | |
| 180 void WebContentsAndroid::ShowImeIfNeeded(JNIEnv* env, jobject obj) { | |
| 181 RenderViewHost* host = web_contents_->GetRenderViewHost(); | |
| 182 host->Send(new ViewMsg_ShowImeIfNeeded(host->GetRoutingID())); | |
| 183 } | |
| 184 | |
| 185 void WebContentsAndroid::ScrollFocusedEditableNodeIntoView( | |
| 186 JNIEnv* env, | |
| 187 jobject obj) { | |
| 188 RenderViewHost* host = web_contents_->GetRenderViewHost(); | |
|
no sievers
2014/07/18 19:42:03
Is there a reason why some call sites do a null-ch
AKVT
2014/07/19 10:39:33
Thanks. null-check has been made as uniform in all
| |
| 189 host->Send(new InputMsg_ScrollFocusedEditableNodeIntoRect( | |
| 190 host->GetRoutingID(), gfx::Rect())); | |
| 191 } | |
| 192 | |
| 193 void WebContentsAndroid::SelectWordAroundCaret(JNIEnv* env, jobject obj) { | |
| 194 RenderViewHost* host = web_contents_->GetRenderViewHost(); | |
| 195 if (!host) | |
| 196 return; | |
| 197 host->SelectWordAroundCaret(); | |
| 198 } | |
| 199 | |
| 80 } // namespace content | 200 } // namespace content |
| OLD | NEW |