| 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/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 WebContentsAndroid* web_contents_android = | 66 WebContentsAndroid* web_contents_android = |
| 67 reinterpret_cast<WebContentsAndroid*>( | 67 reinterpret_cast<WebContentsAndroid*>( |
| 68 Java_WebContentsImpl_getNativePointer(AttachCurrentThread(), | 68 Java_WebContentsImpl_getNativePointer(AttachCurrentThread(), |
| 69 jweb_contents_android)); | 69 jweb_contents_android)); |
| 70 if (!web_contents_android) | 70 if (!web_contents_android) |
| 71 return NULL; | 71 return NULL; |
| 72 return web_contents_android->web_contents(); | 72 return web_contents_android->web_contents(); |
| 73 } | 73 } |
| 74 | 74 |
| 75 // static | 75 // static |
| 76 static void DestroyWebContents(JNIEnv* env, |
| 77 jclass clazz, |
| 78 jlong jweb_contents_android_ptr) { |
| 79 WebContentsAndroid* web_contents_android = |
| 80 reinterpret_cast<WebContentsAndroid*>(jweb_contents_android_ptr); |
| 81 if (!web_contents_android) |
| 82 return; |
| 83 |
| 84 content::WebContents* web_contents = web_contents_android->web_contents(); |
| 85 if (!web_contents) |
| 86 return; |
| 87 |
| 88 delete web_contents; |
| 89 } |
| 90 |
| 91 // static |
| 76 bool WebContentsAndroid::Register(JNIEnv* env) { | 92 bool WebContentsAndroid::Register(JNIEnv* env) { |
| 77 return RegisterNativesImpl(env); | 93 return RegisterNativesImpl(env); |
| 78 } | 94 } |
| 79 | 95 |
| 80 WebContentsAndroid::WebContentsAndroid(WebContents* web_contents) | 96 WebContentsAndroid::WebContentsAndroid(WebContents* web_contents) |
| 81 : web_contents_(web_contents), | 97 : web_contents_(web_contents), |
| 82 navigation_controller_(&(web_contents->GetController())), | 98 navigation_controller_(&(web_contents->GetController())), |
| 83 weak_factory_(this) { | 99 weak_factory_(this) { |
| 84 JNIEnv* env = AttachCurrentThread(); | 100 JNIEnv* env = AttachCurrentThread(); |
| 85 obj_.Reset(env, | 101 obj_.Reset(env, |
| 86 Java_WebContentsImpl_create( | 102 Java_WebContentsImpl_create( |
| 87 env, | 103 env, |
| 88 reinterpret_cast<intptr_t>(this), | 104 reinterpret_cast<intptr_t>(this), |
| 89 navigation_controller_.GetJavaObject().obj()).obj()); | 105 navigation_controller_.GetJavaObject().obj()).obj()); |
| 90 } | 106 } |
| 91 | 107 |
| 92 WebContentsAndroid::~WebContentsAndroid() { | 108 WebContentsAndroid::~WebContentsAndroid() { |
| 93 Java_WebContentsImpl_destroy(AttachCurrentThread(), obj_.obj()); | 109 Java_WebContentsImpl_clearNativePtr(AttachCurrentThread(), obj_.obj()); |
| 94 } | 110 } |
| 95 | 111 |
| 96 base::android::ScopedJavaLocalRef<jobject> | 112 base::android::ScopedJavaLocalRef<jobject> |
| 97 WebContentsAndroid::GetJavaObject() { | 113 WebContentsAndroid::GetJavaObject() { |
| 98 return base::android::ScopedJavaLocalRef<jobject>(obj_); | 114 return base::android::ScopedJavaLocalRef<jobject>(obj_); |
| 99 } | 115 } |
| 100 | 116 |
| 101 ScopedJavaLocalRef<jstring> WebContentsAndroid::GetTitle( | 117 ScopedJavaLocalRef<jstring> WebContentsAndroid::GetTitle( |
| 102 JNIEnv* env, jobject obj) const { | 118 JNIEnv* env, jobject obj) const { |
| 103 return base::android::ConvertUTF16ToJavaString(env, | 119 return base::android::ConvertUTF16ToJavaString(env, |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 ScopedJavaGlobalRef<jobject> j_callback; | 460 ScopedJavaGlobalRef<jobject> j_callback; |
| 445 j_callback.Reset(env, callback); | 461 j_callback.Reset(env, callback); |
| 446 content::RenderFrameHost::JavaScriptResultCallback js_callback = | 462 content::RenderFrameHost::JavaScriptResultCallback js_callback = |
| 447 base::Bind(&JavaScriptResultCallback, j_callback); | 463 base::Bind(&JavaScriptResultCallback, j_callback); |
| 448 | 464 |
| 449 web_contents_->GetMainFrame()->ExecuteJavaScript( | 465 web_contents_->GetMainFrame()->ExecuteJavaScript( |
| 450 ConvertJavaStringToUTF16(env, script), js_callback); | 466 ConvertJavaStringToUTF16(env, script), js_callback); |
| 451 } | 467 } |
| 452 | 468 |
| 453 } // namespace content | 469 } // namespace content |
| OLD | NEW |