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

Side by Side Diff: android_webview/native/aw_settings.cc

Issue 143803016: [Android WebView] Fix thread unsafety in accessing Java side getters (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed maybeRunOnUiThreadBlocking in a better way Created 6 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "android_webview/native/aw_settings.h" 5 #include "android_webview/native/aw_settings.h"
6 6
7 #include "android_webview/browser/renderer_host/aw_render_view_host_ext.h" 7 #include "android_webview/browser/renderer_host/aw_render_view_host_ext.h"
8 #include "android_webview/native/aw_contents.h" 8 #include "android_webview/native/aw_contents.h"
9 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "base/android/jni_string.h" 10 #include "base/android/jni_string.h"
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 181
182 // static 182 // static
183 void AwSettings::PopulateFixedPreferences(WebPreferences* web_prefs) { 183 void AwSettings::PopulateFixedPreferences(WebPreferences* web_prefs) {
184 web_prefs->shrinks_standalone_images_to_fit = false; 184 web_prefs->shrinks_standalone_images_to_fit = false;
185 web_prefs->should_clear_document_background = false; 185 web_prefs->should_clear_document_background = false;
186 } 186 }
187 187
188 void AwSettings::PopulateWebPreferences(WebPreferences* web_prefs) { 188 void AwSettings::PopulateWebPreferences(WebPreferences* web_prefs) {
189 JNIEnv* env = base::android::AttachCurrentThread(); 189 JNIEnv* env = base::android::AttachCurrentThread();
190 CHECK(env); 190 CHECK(env);
191 ScopedJavaLocalRef<jobject> scoped_obj = aw_settings_.get(env);
192 jobject obj = scoped_obj.obj();
193 if (!obj) return;
194 // Grab the lock and call PopulateWebPreferencesLocked.
195 Java_AwSettings_populateWebPreferences(
196 env, obj, reinterpret_cast<jlong>(web_prefs));
197 }
191 198
199 void AwSettings::PopulateWebPreferencesLocked(
200 JNIEnv* env, jobject obj, jlong web_prefs_ptr) {
192 AwRenderViewHostExt* render_view_host_ext = GetAwRenderViewHostExt(); 201 AwRenderViewHostExt* render_view_host_ext = GetAwRenderViewHostExt();
193 if (!render_view_host_ext) return; 202 if (!render_view_host_ext) return;
194 203
195 ScopedJavaLocalRef<jobject> scoped_obj = aw_settings_.get(env); 204 WebPreferences* web_prefs = reinterpret_cast<WebPreferences*>(web_prefs_ptr);
196 jobject obj = scoped_obj.obj();
197 if (!obj) return;
198
199 PopulateFixedPreferences(web_prefs); 205 PopulateFixedPreferences(web_prefs);
200 206
201 web_prefs->text_autosizing_enabled = 207 web_prefs->text_autosizing_enabled =
202 Java_AwSettings_getTextAutosizingEnabledLocked(env, obj); 208 Java_AwSettings_getTextAutosizingEnabledLocked(env, obj);
203 209
204 int text_size_percent = Java_AwSettings_getTextSizePercentLocked(env, obj); 210 int text_size_percent = Java_AwSettings_getTextSizePercentLocked(env, obj);
205 if (web_prefs->text_autosizing_enabled) { 211 if (web_prefs->text_autosizing_enabled) {
206 web_prefs->font_scale_factor = text_size_percent / 100.0f; 212 web_prefs->font_scale_factor = text_size_percent / 100.0f;
207 web_prefs->force_enable_zoom = text_size_percent >= 130; 213 web_prefs->force_enable_zoom = text_size_percent >= 130;
208 // Use the default zoom factor value when Text Autosizer is turned on. 214 // Use the default zoom factor value when Text Autosizer is turned on.
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 static jstring GetDefaultUserAgent(JNIEnv* env, jclass clazz) { 340 static jstring GetDefaultUserAgent(JNIEnv* env, jclass clazz) {
335 return base::android::ConvertUTF8ToJavaString( 341 return base::android::ConvertUTF8ToJavaString(
336 env, content::GetUserAgent(GURL())).Release(); 342 env, content::GetUserAgent(GURL())).Release();
337 } 343 }
338 344
339 bool RegisterAwSettings(JNIEnv* env) { 345 bool RegisterAwSettings(JNIEnv* env) {
340 return RegisterNativesImpl(env) >= 0; 346 return RegisterNativesImpl(env) >= 0;
341 } 347 }
342 348
343 } // namespace android_webview 349 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698