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 <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
225 return; | 225 return; |
226 | 226 |
227 WebContents* web_contents = web_contents_android->web_contents(); | 227 WebContents* web_contents = web_contents_android->web_contents(); |
228 if (!web_contents) | 228 if (!web_contents) |
229 return; | 229 return; |
230 | 230 |
231 delete web_contents; | 231 delete web_contents; |
232 } | 232 } |
233 | 233 |
234 // static | 234 // static |
235 ScopedJavaLocalRef<jobject> FromRenderFrameHost( | |
boliu
2017/02/16 01:00:58
this is a really convoluted way to implement this.
rwlbuis
2017/03/01 21:53:57
Ok I added RenderFrameHostDelegate.
| |
236 JNIEnv* env, | |
237 const JavaParamRef<jclass>& clazz, | |
238 const JavaParamRef<jobject>& jrender_frame_host_android) { | |
239 RenderFrameHost* rfh = | |
240 RenderFrameHost::FromJavaRenderFrameHost(jrender_frame_host_android); | |
241 if (!rfh) | |
242 return ScopedJavaLocalRef<jobject>(); | |
243 | |
244 WebContents* webContents = WebContents::FromRenderFrameHost(rfh); | |
245 if (!webContents) | |
246 return ScopedJavaLocalRef<jobject>(); | |
247 | |
248 return webContents->GetJavaWebContents(); | |
249 } | |
250 | |
251 // static | |
235 ScopedJavaLocalRef<jobject> FromNativePtr(JNIEnv* env, | 252 ScopedJavaLocalRef<jobject> FromNativePtr(JNIEnv* env, |
236 const JavaParamRef<jclass>& clazz, | 253 const JavaParamRef<jclass>& clazz, |
237 jlong web_contents_ptr) { | 254 jlong web_contents_ptr) { |
238 WebContentsAndroid* web_contents_android = | 255 WebContentsAndroid* web_contents_android = |
239 reinterpret_cast<WebContentsAndroid*>(web_contents_ptr); | 256 reinterpret_cast<WebContentsAndroid*>(web_contents_ptr); |
240 | 257 |
241 if (!web_contents_android) | 258 if (!web_contents_android) |
242 return ScopedJavaLocalRef<jobject>(); | 259 return ScopedJavaLocalRef<jobject>(); |
243 | 260 |
244 // Check to make sure this object hasn't been destroyed. | 261 // Check to make sure this object hasn't been destroyed. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
278 g_allocated_web_contents_androids.Get().end()); | 295 g_allocated_web_contents_androids.Get().end()); |
279 g_allocated_web_contents_androids.Get().erase(this); | 296 g_allocated_web_contents_androids.Get().erase(this); |
280 Java_WebContentsImpl_clearNativePtr(AttachCurrentThread(), obj_); | 297 Java_WebContentsImpl_clearNativePtr(AttachCurrentThread(), obj_); |
281 } | 298 } |
282 | 299 |
283 base::android::ScopedJavaLocalRef<jobject> | 300 base::android::ScopedJavaLocalRef<jobject> |
284 WebContentsAndroid::GetJavaObject() { | 301 WebContentsAndroid::GetJavaObject() { |
285 return base::android::ScopedJavaLocalRef<jobject>(obj_); | 302 return base::android::ScopedJavaLocalRef<jobject>(obj_); |
286 } | 303 } |
287 | 304 |
305 ScopedJavaLocalRef<jobject> WebContentsAndroid::GetMainFrame( | |
306 JNIEnv* env, | |
307 const JavaParamRef<jobject>& obj) const { | |
308 return web_contents_->GetMainFrame()->GetJavaRenderFrameHost(); | |
309 } | |
310 | |
288 ScopedJavaLocalRef<jstring> WebContentsAndroid::GetTitle( | 311 ScopedJavaLocalRef<jstring> WebContentsAndroid::GetTitle( |
289 JNIEnv* env, | 312 JNIEnv* env, |
290 const JavaParamRef<jobject>& obj) const { | 313 const JavaParamRef<jobject>& obj) const { |
291 return base::android::ConvertUTF16ToJavaString(env, | 314 return base::android::ConvertUTF16ToJavaString(env, |
292 web_contents_->GetTitle()); | 315 web_contents_->GetTitle()); |
293 } | 316 } |
294 | 317 |
295 ScopedJavaLocalRef<jstring> WebContentsAndroid::GetVisibleURL( | 318 ScopedJavaLocalRef<jstring> WebContentsAndroid::GetVisibleURL( |
296 JNIEnv* env, | 319 JNIEnv* env, |
297 const JavaParamRef<jobject>& obj) const { | 320 const JavaParamRef<jobject>& obj) const { |
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
763 env, obj, callback, id, http_status_code, jurl, jbitmaps, jsizes); | 786 env, obj, callback, id, http_status_code, jurl, jbitmaps, jsizes); |
764 } | 787 } |
765 | 788 |
766 void WebContentsAndroid::SetMediaSession( | 789 void WebContentsAndroid::SetMediaSession( |
767 const ScopedJavaLocalRef<jobject>& j_media_session) { | 790 const ScopedJavaLocalRef<jobject>& j_media_session) { |
768 JNIEnv* env = base::android::AttachCurrentThread(); | 791 JNIEnv* env = base::android::AttachCurrentThread(); |
769 Java_WebContentsImpl_setMediaSession(env, obj_, j_media_session); | 792 Java_WebContentsImpl_setMediaSession(env, obj_, j_media_session); |
770 } | 793 } |
771 | 794 |
772 } // namespace content | 795 } // namespace content |
OLD | NEW |