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

Side by Side Diff: content/browser/android/content_view_core_impl.cc

Issue 11971007: Pass ScopedJavaGlobalRef to bind() by value (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: avi comments Created 7 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « android_webview/native/aw_contents.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/android/content_view_core_impl.h" 5 #include "content/browser/android/content_view_core_impl.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_array.h" 8 #include "base/android/jni_array.h"
9 #include "base/android/jni_string.h" 9 #include "base/android/jni_string.h"
10 #include "base/android/scoped_java_ref.h" 10 #include "base/android/scoped_java_ref.h"
(...skipping 1239 matching lines...) Expand 10 before | Expand all | Expand 10 after
1250 1250
1251 void ContentViewCoreImpl::UndoScrollFocusedEditableNodeIntoView( 1251 void ContentViewCoreImpl::UndoScrollFocusedEditableNodeIntoView(
1252 JNIEnv* env, 1252 JNIEnv* env,
1253 jobject obj) { 1253 jobject obj) {
1254 RenderViewHost* host = web_contents_->GetRenderViewHost(); 1254 RenderViewHost* host = web_contents_->GetRenderViewHost();
1255 host->Send( 1255 host->Send(
1256 new ViewMsg_UndoScrollFocusedEditableNodeIntoView(host->GetRoutingID())); 1256 new ViewMsg_UndoScrollFocusedEditableNodeIntoView(host->GetRoutingID()));
1257 } 1257 }
1258 1258
1259 namespace { 1259 namespace {
1260 void JavaScriptResultCallback(ScopedJavaGlobalRef<jobject>* callback, 1260 void JavaScriptResultCallback(const ScopedJavaGlobalRef<jobject>& callback,
1261 const base::Value* result) { 1261 const base::Value* result) {
1262 // |callback| is passed as base::Owned, so it will automatically be deleted
1263 // when this base::Callback goes out of scope.
1264 JNIEnv* env = base::android::AttachCurrentThread(); 1262 JNIEnv* env = base::android::AttachCurrentThread();
1265 std::string json; 1263 std::string json;
1266 base::JSONWriter::Write(result, &json); 1264 base::JSONWriter::Write(result, &json);
1267 ScopedJavaLocalRef<jstring> j_json = ConvertUTF8ToJavaString(env, json); 1265 ScopedJavaLocalRef<jstring> j_json = ConvertUTF8ToJavaString(env, json);
1268 Java_ContentViewCore_onEvaluateJavaScriptResult(env, 1266 Java_ContentViewCore_onEvaluateJavaScriptResult(env,
1269 j_json.obj(), 1267 j_json.obj(),
1270 callback->obj()); 1268 callback.obj());
1271 } 1269 }
1272 } // namespace 1270 } // namespace
1273 1271
1274 void ContentViewCoreImpl::EvaluateJavaScript(JNIEnv* env, 1272 void ContentViewCoreImpl::EvaluateJavaScript(JNIEnv* env,
1275 jobject obj, 1273 jobject obj,
1276 jstring script, 1274 jstring script,
1277 jobject callback) { 1275 jobject callback) {
1278 RenderViewHost* host = web_contents_->GetRenderViewHost(); 1276 RenderViewHost* host = web_contents_->GetRenderViewHost();
1279 DCHECK(host); 1277 DCHECK(host);
1280 1278
1281 if (!callback) { 1279 if (!callback) {
1282 // No callback requested. 1280 // No callback requested.
1283 host->ExecuteJavascriptInWebFrame(string16(), // frame_xpath 1281 host->ExecuteJavascriptInWebFrame(string16(), // frame_xpath
1284 ConvertJavaStringToUTF16(env, script)); 1282 ConvertJavaStringToUTF16(env, script));
1285 return; 1283 return;
1286 } 1284 }
1287 1285
1288 // Secure the Java callback in a scoped object and give ownership of it to the 1286 // Secure the Java callback in a scoped object and give ownership of it to the
1289 // base::Callback. 1287 // base::Callback.
1290 ScopedJavaGlobalRef<jobject>* j_callback = new ScopedJavaGlobalRef<jobject>(); 1288 ScopedJavaGlobalRef<jobject> j_callback;
1291 j_callback->Reset(env, callback); 1289 j_callback.Reset(env, callback);
1292 content::RenderViewHost::JavascriptResultCallback c_callback = 1290 content::RenderViewHost::JavascriptResultCallback c_callback =
1293 base::Bind(&JavaScriptResultCallback, base::Owned(j_callback)); 1291 base::Bind(&JavaScriptResultCallback, j_callback);
1294 1292
1295 host->ExecuteJavascriptInWebFrameCallbackResult( 1293 host->ExecuteJavascriptInWebFrameCallbackResult(
1296 string16(), // frame_xpath 1294 string16(), // frame_xpath
1297 ConvertJavaStringToUTF16(env, script), 1295 ConvertJavaStringToUTF16(env, script),
1298 c_callback); 1296 c_callback);
1299 } 1297 }
1300 1298
1301 bool ContentViewCoreImpl::GetUseDesktopUserAgent( 1299 bool ContentViewCoreImpl::GetUseDesktopUserAgent(
1302 JNIEnv* env, jobject obj) { 1300 JNIEnv* env, jobject obj) {
1303 NavigationEntry* entry = web_contents_->GetController().GetActiveEntry(); 1301 NavigationEntry* entry = web_contents_->GetController().GetActiveEntry();
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1380 if (!HasField(env, clazz, "mNativeContentViewCore", "I")) { 1378 if (!HasField(env, clazz, "mNativeContentViewCore", "I")) {
1381 DLOG(ERROR) << "Unable to find ContentView.mNativeContentViewCore!"; 1379 DLOG(ERROR) << "Unable to find ContentView.mNativeContentViewCore!";
1382 return false; 1380 return false;
1383 } 1381 }
1384 g_native_content_view = GetFieldID(env, clazz, "mNativeContentViewCore", "I"); 1382 g_native_content_view = GetFieldID(env, clazz, "mNativeContentViewCore", "I");
1385 1383
1386 return RegisterNativesImpl(env) >= 0; 1384 return RegisterNativesImpl(env) >= 0;
1387 } 1385 }
1388 1386
1389 } // namespace content 1387 } // namespace content
OLDNEW
« no previous file with comments | « android_webview/native/aw_contents.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698