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

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

Issue 2295693004: Pass JavaRef to Java methods in android_webview. (Closed)
Patch Set: Created 4 years, 3 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
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/aw_content_browser_client.h" 7 #include "android_webview/browser/aw_content_browser_client.h"
8 #include "android_webview/browser/renderer_host/aw_render_view_host_ext.h" 8 #include "android_webview/browser/renderer_host/aw_render_view_host_ext.h"
9 #include "android_webview/common/aw_content_client.h" 9 #include "android_webview/common/aw_content_client.h"
10 #include "android_webview/native/aw_contents.h" 10 #include "android_webview/native/aw_contents.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 new AwSettingsUserData(this)); 83 new AwSettingsUserData(this));
84 } 84 }
85 85
86 AwSettings::~AwSettings() { 86 AwSettings::~AwSettings() {
87 if (web_contents()) { 87 if (web_contents()) {
88 web_contents()->SetUserData(kAwSettingsUserDataKey, NULL); 88 web_contents()->SetUserData(kAwSettingsUserDataKey, NULL);
89 } 89 }
90 90
91 JNIEnv* env = base::android::AttachCurrentThread(); 91 JNIEnv* env = base::android::AttachCurrentThread();
92 ScopedJavaLocalRef<jobject> scoped_obj = aw_settings_.get(env); 92 ScopedJavaLocalRef<jobject> scoped_obj = aw_settings_.get(env);
93 jobject obj = scoped_obj.obj(); 93 if (scoped_obj.is_null())
94 if (!obj) return; 94 return;
95 Java_AwSettings_nativeAwSettingsGone(env, obj, 95 Java_AwSettings_nativeAwSettingsGone(env, scoped_obj,
96 reinterpret_cast<intptr_t>(this)); 96 reinterpret_cast<intptr_t>(this));
97 } 97 }
98 98
99 void AwSettings::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) { 99 void AwSettings::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) {
100 delete this; 100 delete this;
101 } 101 }
102 102
103 AwSettings* AwSettings::FromWebContents(content::WebContents* web_contents) { 103 AwSettings* AwSettings::FromWebContents(content::WebContents* web_contents) {
104 return AwSettingsUserData::GetSettings(web_contents); 104 return AwSettingsUserData::GetSettings(web_contents);
105 } 105 }
106 106
107 AwRenderViewHostExt* AwSettings::GetAwRenderViewHostExt() { 107 AwRenderViewHostExt* AwSettings::GetAwRenderViewHostExt() {
108 if (!web_contents()) return NULL; 108 if (!web_contents()) return NULL;
109 AwContents* contents = AwContents::FromWebContents(web_contents()); 109 AwContents* contents = AwContents::FromWebContents(web_contents());
110 if (!contents) return NULL; 110 if (!contents) return NULL;
111 return contents->render_view_host_ext(); 111 return contents->render_view_host_ext();
112 } 112 }
113 113
114 void AwSettings::ResetScrollAndScaleState(JNIEnv* env, 114 void AwSettings::ResetScrollAndScaleState(JNIEnv* env,
115 const JavaParamRef<jobject>& obj) { 115 const JavaParamRef<jobject>& obj) {
116 AwRenderViewHostExt* rvhe = GetAwRenderViewHostExt(); 116 AwRenderViewHostExt* rvhe = GetAwRenderViewHostExt();
117 if (!rvhe) return; 117 if (!rvhe) return;
118 rvhe->ResetScrollAndScaleState(); 118 rvhe->ResetScrollAndScaleState();
119 } 119 }
120 120
121 void AwSettings::UpdateEverything() { 121 void AwSettings::UpdateEverything() {
122 JNIEnv* env = base::android::AttachCurrentThread(); 122 JNIEnv* env = base::android::AttachCurrentThread();
123 CHECK(env); 123 CHECK(env);
124 ScopedJavaLocalRef<jobject> scoped_obj = aw_settings_.get(env); 124 ScopedJavaLocalRef<jobject> scoped_obj = aw_settings_.get(env);
125 jobject obj = scoped_obj.obj(); 125 if (scoped_obj.is_null())
126 if (!obj) return; 126 return;
127 // Grab the lock and call UpdateEverythingLocked. 127 // Grab the lock and call UpdateEverythingLocked.
128 Java_AwSettings_updateEverything(env, obj); 128 Java_AwSettings_updateEverything(env, scoped_obj);
129 } 129 }
130 130
131 void AwSettings::UpdateEverythingLocked(JNIEnv* env, 131 void AwSettings::UpdateEverythingLocked(JNIEnv* env,
132 const JavaParamRef<jobject>& obj) { 132 const JavaParamRef<jobject>& obj) {
133 UpdateInitialPageScaleLocked(env, obj); 133 UpdateInitialPageScaleLocked(env, obj);
134 UpdateWebkitPreferencesLocked(env, obj); 134 UpdateWebkitPreferencesLocked(env, obj);
135 UpdateUserAgentLocked(env, obj); 135 UpdateUserAgentLocked(env, obj);
136 ResetScrollAndScaleState(env, obj); 136 ResetScrollAndScaleState(env, obj);
137 UpdateFormDataPreferencesLocked(env, obj); 137 UpdateFormDataPreferencesLocked(env, obj);
138 UpdateRendererPreferencesLocked(env, obj); 138 UpdateRendererPreferencesLocked(env, obj);
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 } 253 }
254 254
255 void AwSettings::WebContentsDestroyed() { 255 void AwSettings::WebContentsDestroyed() {
256 delete this; 256 delete this;
257 } 257 }
258 258
259 void AwSettings::PopulateWebPreferences(WebPreferences* web_prefs) { 259 void AwSettings::PopulateWebPreferences(WebPreferences* web_prefs) {
260 JNIEnv* env = base::android::AttachCurrentThread(); 260 JNIEnv* env = base::android::AttachCurrentThread();
261 CHECK(env); 261 CHECK(env);
262 ScopedJavaLocalRef<jobject> scoped_obj = aw_settings_.get(env); 262 ScopedJavaLocalRef<jobject> scoped_obj = aw_settings_.get(env);
263 jobject obj = scoped_obj.obj(); 263 if (scoped_obj.is_null())
264 if (!obj) return; 264 return;
265 // Grab the lock and call PopulateWebPreferencesLocked. 265 // Grab the lock and call PopulateWebPreferencesLocked.
266 Java_AwSettings_populateWebPreferences( 266 Java_AwSettings_populateWebPreferences(env, scoped_obj,
267 env, obj, reinterpret_cast<jlong>(web_prefs)); 267 reinterpret_cast<jlong>(web_prefs));
268 } 268 }
269 269
270 void AwSettings::PopulateWebPreferencesLocked(JNIEnv* env, 270 void AwSettings::PopulateWebPreferencesLocked(JNIEnv* env,
271 const JavaParamRef<jobject>& obj, 271 const JavaParamRef<jobject>& obj,
272 jlong web_prefs_ptr) { 272 jlong web_prefs_ptr) {
273 AwRenderViewHostExt* render_view_host_ext = GetAwRenderViewHostExt(); 273 AwRenderViewHostExt* render_view_host_ext = GetAwRenderViewHostExt();
274 if (!render_view_host_ext) return; 274 if (!render_view_host_ext) return;
275 275
276 WebPreferences* web_prefs = reinterpret_cast<WebPreferences*>(web_prefs_ptr); 276 WebPreferences* web_prefs = reinterpret_cast<WebPreferences*>(web_prefs_ptr);
277 PopulateFixedWebPreferences(web_prefs); 277 PopulateFixedWebPreferences(web_prefs);
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 JNIEnv* env, 458 JNIEnv* env,
459 const JavaParamRef<jclass>& clazz) { 459 const JavaParamRef<jclass>& clazz) {
460 return base::android::ConvertUTF8ToJavaString(env, GetUserAgent()); 460 return base::android::ConvertUTF8ToJavaString(env, GetUserAgent());
461 } 461 }
462 462
463 bool RegisterAwSettings(JNIEnv* env) { 463 bool RegisterAwSettings(JNIEnv* env) {
464 return RegisterNativesImpl(env); 464 return RegisterNativesImpl(env);
465 } 465 }
466 466
467 } // namespace android_webview 467 } // namespace android_webview
OLDNEW
« no previous file with comments | « android_webview/native/aw_pdf_exporter.cc ('k') | android_webview/native/aw_web_contents_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698