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

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: rebase Created 7 years, 11 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 1218 matching lines...) Expand 10 before | Expand all | Expand 10 after
1229 1229
1230 void ContentViewCoreImpl::UndoScrollFocusedEditableNodeIntoView( 1230 void ContentViewCoreImpl::UndoScrollFocusedEditableNodeIntoView(
1231 JNIEnv* env, 1231 JNIEnv* env,
1232 jobject obj) { 1232 jobject obj) {
1233 RenderViewHost* host = web_contents_->GetRenderViewHost(); 1233 RenderViewHost* host = web_contents_->GetRenderViewHost();
1234 host->Send( 1234 host->Send(
1235 new ViewMsg_UndoScrollFocusedEditableNodeIntoView(host->GetRoutingID())); 1235 new ViewMsg_UndoScrollFocusedEditableNodeIntoView(host->GetRoutingID()));
1236 } 1236 }
1237 1237
1238 namespace { 1238 namespace {
1239 void JavaScriptResultCallback(ScopedJavaGlobalRef<jobject>* callback, 1239 void JavaScriptResultCallback(const ScopedJavaGlobalRef<jobject>& callback,
1240 const base::Value* result) { 1240 const base::Value* result) {
1241 // |callback| is passed as base::Owned, so it will automatically be deleted 1241 // |callback| is passed as base::Owned, so it will automatically be deleted
1242 // when this base::Callback goes out of scope. 1242 // when this base::Callback goes out of scope.
Avi (use Gerrit) 2013/01/22 02:21:41 You deleted this comment in the other file, and it
joth 2013/02/05 00:30:30 Done.
1243 JNIEnv* env = base::android::AttachCurrentThread(); 1243 JNIEnv* env = base::android::AttachCurrentThread();
1244 std::string json; 1244 std::string json;
1245 base::JSONWriter::Write(result, &json); 1245 base::JSONWriter::Write(result, &json);
1246 ScopedJavaLocalRef<jstring> j_json = ConvertUTF8ToJavaString(env, json); 1246 ScopedJavaLocalRef<jstring> j_json = ConvertUTF8ToJavaString(env, json);
1247 Java_ContentViewCore_onEvaluateJavaScriptResult(env, 1247 Java_ContentViewCore_onEvaluateJavaScriptResult(env,
1248 j_json.obj(), 1248 j_json.obj(),
1249 callback->obj()); 1249 callback.obj());
1250 } 1250 }
1251 } // namespace 1251 } // namespace
1252 1252
1253 void ContentViewCoreImpl::EvaluateJavaScript(JNIEnv* env, 1253 void ContentViewCoreImpl::EvaluateJavaScript(JNIEnv* env,
1254 jobject obj, 1254 jobject obj,
1255 jstring script, 1255 jstring script,
1256 jobject callback) { 1256 jobject callback) {
1257 RenderViewHost* host = web_contents_->GetRenderViewHost(); 1257 RenderViewHost* host = web_contents_->GetRenderViewHost();
1258 DCHECK(host); 1258 DCHECK(host);
1259 1259
1260 if (!callback) { 1260 if (!callback) {
1261 // No callback requested. 1261 // No callback requested.
1262 host->ExecuteJavascriptInWebFrame(string16(), // frame_xpath 1262 host->ExecuteJavascriptInWebFrame(string16(), // frame_xpath
1263 ConvertJavaStringToUTF16(env, script)); 1263 ConvertJavaStringToUTF16(env, script));
1264 return; 1264 return;
1265 } 1265 }
1266 1266
1267 // Secure the Java callback in a scoped object and give ownership of it to the 1267 // Secure the Java callback in a scoped object and give ownership of it to the
1268 // base::Callback. 1268 // base::Callback.
1269 ScopedJavaGlobalRef<jobject>* j_callback = new ScopedJavaGlobalRef<jobject>(); 1269 ScopedJavaGlobalRef<jobject> j_callback;
1270 j_callback->Reset(env, callback); 1270 j_callback.Reset(env, callback);
1271 content::RenderViewHost::JavascriptResultCallback c_callback = 1271 content::RenderViewHost::JavascriptResultCallback c_callback =
1272 base::Bind(&JavaScriptResultCallback, base::Owned(j_callback)); 1272 base::Bind(&JavaScriptResultCallback, j_callback);
1273 1273
1274 host->ExecuteJavascriptInWebFrameCallbackResult( 1274 host->ExecuteJavascriptInWebFrameCallbackResult(
1275 string16(), // frame_xpath 1275 string16(), // frame_xpath
1276 ConvertJavaStringToUTF16(env, script), 1276 ConvertJavaStringToUTF16(env, script),
1277 c_callback); 1277 c_callback);
1278 } 1278 }
1279 1279
1280 bool ContentViewCoreImpl::GetUseDesktopUserAgent( 1280 bool ContentViewCoreImpl::GetUseDesktopUserAgent(
1281 JNIEnv* env, jobject obj) { 1281 JNIEnv* env, jobject obj) {
1282 NavigationEntry* entry = web_contents_->GetController().GetActiveEntry(); 1282 NavigationEntry* entry = web_contents_->GetController().GetActiveEntry();
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1359 if (!HasField(env, clazz, "mNativeContentViewCore", "I")) { 1359 if (!HasField(env, clazz, "mNativeContentViewCore", "I")) {
1360 DLOG(ERROR) << "Unable to find ContentView.mNativeContentViewCore!"; 1360 DLOG(ERROR) << "Unable to find ContentView.mNativeContentViewCore!";
1361 return false; 1361 return false;
1362 } 1362 }
1363 g_native_content_view = GetFieldID(env, clazz, "mNativeContentViewCore", "I"); 1363 g_native_content_view = GetFieldID(env, clazz, "mNativeContentViewCore", "I");
1364 1364
1365 return RegisterNativesImpl(env) >= 0; 1365 return RegisterNativesImpl(env) >= 0;
1366 } 1366 }
1367 1367
1368 } // namespace content 1368 } // 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