Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Side by Side Diff: content/browser/frame_host/render_frame_host_android.cc

Issue 2681933002: Add Java wrapper for RenderFrameHost (Closed)
Patch Set: Try to address all review comments Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/frame_host/render_frame_host_android.h"
6
7 #include "base/android/jni_string.h"
8 #include "base/logging.h"
9 #include "content/browser/frame_host/render_frame_host_delegate.h"
10 #include "content/browser/frame_host/render_frame_host_impl.h"
11 #include "jni/RenderFrameHostImpl_jni.h"
12
13 using base::android::AttachCurrentThread;
14 using base::android::ConvertUTF8ToJavaString;
15 using base::android::JavaParamRef;
16 using base::android::JavaRef;
17 using base::android::ScopedJavaLocalRef;
18
19 namespace content {
20
21 // static
22 bool RenderFrameHostAndroid::Register(JNIEnv* env) {
23 return RegisterNativesImpl(env);
24 }
25
26 RenderFrameHostAndroid::RenderFrameHostAndroid(
27 RenderFrameHostImpl* render_frame_host)
28 : render_frame_host_(render_frame_host) {
29 JNIEnv* env = AttachCurrentThread();
30 ScopedJavaLocalRef<jobject> obj = Java_RenderFrameHostImpl_create(
31 env, reinterpret_cast<intptr_t>(this),
32 render_frame_host->delegate()->GetJavaRenderFrameHostDelegate());
33 obj_ = JavaObjectWeakGlobalRef(env, obj);
34 }
35
36 RenderFrameHostAndroid::~RenderFrameHostAndroid() {
37 ScopedJavaLocalRef<jobject> jobj = GetJavaObject();
38 if (!jobj.is_null()) {
39 Java_RenderFrameHostImpl_clearNativePtr(AttachCurrentThread(), jobj);
40 obj_.reset();
41 }
42 }
43
44 base::android::ScopedJavaLocalRef<jobject>
45 RenderFrameHostAndroid::GetJavaObject() {
46 JNIEnv* env = base::android::AttachCurrentThread();
47 return obj_.get(env);
48 }
49
50 ScopedJavaLocalRef<jstring> RenderFrameHostAndroid::GetLastCommittedURL(
51 JNIEnv* env,
52 const JavaParamRef<jobject>& obj) const {
53 return ConvertUTF8ToJavaString(
54 env, render_frame_host_->GetLastCommittedURL().spec());
55 }
56
57 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698