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
3 // found in the LICENSE file.
5 #include "content/browser/web_contents/web_contents_android.h"
7 #include "base/android/jni_android.h"
8 #include "base/logging.h"
9 #include "content/public/browser/browser_thread.h"
10 #include "content/public/browser/web_contents.h"
11 #include "jni/WebContentsImpl_jni.h"
13 using base::android::AttachCurrentThread
;
18 WebContents
* WebContents::FromJavaWebContents(
19 jobject jweb_contents_android
) {
20 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
21 if (!jweb_contents_android
)
24 WebContentsAndroid
* web_contents_android
=
25 reinterpret_cast<WebContentsAndroid
*>(
26 Java_WebContentsImpl_getNativePointer(AttachCurrentThread(),
27 jweb_contents_android
));
28 if (!web_contents_android
)
30 return web_contents_android
->web_contents();
34 bool WebContentsAndroid::Register(JNIEnv
* env
) {
35 return RegisterNativesImpl(env
);
38 WebContentsAndroid::WebContentsAndroid(WebContents
* web_contents
)
39 : web_contents_(web_contents
),
40 navigation_controller_(&(web_contents
->GetController())) {
41 JNIEnv
* env
= AttachCurrentThread();
43 Java_WebContentsImpl_create(
45 reinterpret_cast<intptr_t>(this),
46 navigation_controller_
.GetJavaObject().obj()).obj());
49 WebContentsAndroid::~WebContentsAndroid() {
50 Java_WebContentsImpl_destroy(AttachCurrentThread(), obj_
.obj());
53 base::android::ScopedJavaLocalRef
<jobject
>
54 WebContentsAndroid::GetJavaObject() {
55 return base::android::ScopedJavaLocalRef
<jobject
>(obj_
);
58 } // namespace content