Commit 0b184003 authored by Tim Volodine's avatar Tim Volodine Committed by Commit Bot

[AW][AW NS] Implement on-change caching for GetAllowFileAccess setting

Make sure to cache the GetAllowFileAccess setting on the native side
and on update, so that it can be retrieved efficiently inside the
AwContentBrowserClient class. In particular in the
RegisterNonNetworkSubresourceURLLoaderFactories() method which is
executed on page and subresource loads.

BUG=949590

Change-Id: I55ab035530b2b342285ed42dfd55cc2c7d9a9940
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1814777
Commit-Queue: Tim Volodine <timvolodine@chromium.org>
Reviewed-by: default avatarTobias Sargeant <tobiasjs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#698875}
parent 63153e71
...@@ -73,6 +73,7 @@ AwSettings::AwSettings(JNIEnv* env, ...@@ -73,6 +73,7 @@ AwSettings::AwSettings(JNIEnv* env,
renderer_prefs_initialized_(false), renderer_prefs_initialized_(false),
javascript_can_open_windows_automatically_(false), javascript_can_open_windows_automatically_(false),
allow_third_party_cookies_(false), allow_third_party_cookies_(false),
allow_file_access_(false),
aw_settings_(env, obj) { aw_settings_(env, obj) {
web_contents->SetUserData(kAwSettingsUserDataKey, web_contents->SetUserData(kAwSettingsUserDataKey,
std::make_unique<AwSettingsUserData>(this)); std::make_unique<AwSettingsUserData>(this));
...@@ -150,6 +151,7 @@ void AwSettings::UpdateEverythingLocked(JNIEnv* env, ...@@ -150,6 +151,7 @@ void AwSettings::UpdateEverythingLocked(JNIEnv* env,
UpdateOffscreenPreRasterLocked(env, obj); UpdateOffscreenPreRasterLocked(env, obj);
UpdateWillSuppressErrorStateLocked(env, obj); UpdateWillSuppressErrorStateLocked(env, obj);
UpdateCookiePolicyLocked(env, obj); UpdateCookiePolicyLocked(env, obj);
UpdateAllowFileAccessLocked(env, obj);
} }
void AwSettings::UpdateUserAgentLocked(JNIEnv* env, void AwSettings::UpdateUserAgentLocked(JNIEnv* env,
...@@ -287,6 +289,14 @@ void AwSettings::UpdateOffscreenPreRasterLocked( ...@@ -287,6 +289,14 @@ void AwSettings::UpdateOffscreenPreRasterLocked(
} }
} }
void AwSettings::UpdateAllowFileAccessLocked(JNIEnv* env,
const JavaParamRef<jobject>& obj) {
if (!web_contents())
return;
allow_file_access_ = Java_AwSettings_getAllowFileAccess(env, obj);
}
void AwSettings::RenderViewHostChanged(content::RenderViewHost* old_host, void AwSettings::RenderViewHostChanged(content::RenderViewHost* old_host,
content::RenderViewHost* new_host) { content::RenderViewHost* new_host) {
DCHECK_EQ(new_host, web_contents()->GetRenderViewHost()); DCHECK_EQ(new_host, web_contents()->GetRenderViewHost());
...@@ -547,13 +557,7 @@ void AwSettings::PopulateWebPreferencesLocked(JNIEnv* env, ...@@ -547,13 +557,7 @@ void AwSettings::PopulateWebPreferencesLocked(JNIEnv* env,
} }
bool AwSettings::GetAllowFileAccess() { bool AwSettings::GetAllowFileAccess() {
// TODO(timvolodine): cache this lazily on update, crbug.com/949590 return allow_file_access_;
JNIEnv* env = base::android::AttachCurrentThread();
CHECK(env);
ScopedJavaLocalRef<jobject> scoped_obj = aw_settings_.get(env);
if (scoped_obj.is_null())
return true;
return Java_AwSettings_getAllowFileAccess(env, scoped_obj);
} }
static jlong JNI_AwSettings_Init(JNIEnv* env, static jlong JNI_AwSettings_Init(JNIEnv* env,
......
...@@ -79,6 +79,9 @@ class AwSettings : public content::WebContentsObserver { ...@@ -79,6 +79,9 @@ class AwSettings : public content::WebContentsObserver {
void UpdateOffscreenPreRasterLocked( void UpdateOffscreenPreRasterLocked(
JNIEnv* env, JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj); const base::android::JavaParamRef<jobject>& obj);
void UpdateAllowFileAccessLocked(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj);
void PopulateWebPreferences(content::WebPreferences* web_prefs); void PopulateWebPreferences(content::WebPreferences* web_prefs);
bool GetAllowFileAccess(); bool GetAllowFileAccess();
...@@ -95,6 +98,7 @@ class AwSettings : public content::WebContentsObserver { ...@@ -95,6 +98,7 @@ class AwSettings : public content::WebContentsObserver {
bool renderer_prefs_initialized_; bool renderer_prefs_initialized_;
bool javascript_can_open_windows_automatically_; bool javascript_can_open_windows_automatically_;
bool allow_third_party_cookies_; bool allow_third_party_cookies_;
bool allow_file_access_;
JavaObjectWeakGlobalRef aw_settings_; JavaObjectWeakGlobalRef aw_settings_;
}; };
......
...@@ -241,6 +241,10 @@ public class AwSettings { ...@@ -241,6 +241,10 @@ public class AwSettings {
void updateCookiePolicyLocked() { void updateCookiePolicyLocked() {
runOnUiThreadBlockingAndLocked(() -> updateCookiePolicyOnUiThreadLocked()); runOnUiThreadBlockingAndLocked(() -> updateCookiePolicyOnUiThreadLocked());
} }
void updateAllowFileAccessLocked() {
runOnUiThreadBlockingAndLocked(() -> updateAllowFileAccessOnUiThreadLocked());
}
} }
interface ZoomSupportChangeListener { interface ZoomSupportChangeListener {
...@@ -424,6 +428,7 @@ public class AwSettings { ...@@ -424,6 +428,7 @@ public class AwSettings {
if (TRACE) Log.i(LOGTAG, "setAllowFileAccess=" + allow); if (TRACE) Log.i(LOGTAG, "setAllowFileAccess=" + allow);
synchronized (mAwSettingsLock) { synchronized (mAwSettingsLock) {
mAllowFileUrlAccess = allow; mAllowFileUrlAccess = allow;
mEventHandler.updateAllowFileAccessLocked();
} }
} }
...@@ -1888,6 +1893,14 @@ public class AwSettings { ...@@ -1888,6 +1893,14 @@ public class AwSettings {
} }
} }
private void updateAllowFileAccessOnUiThreadLocked() {
assert mEventHandler.mHandler != null;
ThreadUtils.assertOnUiThread();
if (mNativeAwSettings != 0) {
AwSettingsJni.get().updateAllowFileAccessLocked(mNativeAwSettings, AwSettings.this);
}
}
@NativeMethods @NativeMethods
interface Natives { interface Natives {
long init(AwSettings caller, WebContents webContents); long init(AwSettings caller, WebContents webContents);
...@@ -1905,5 +1918,6 @@ public class AwSettings { ...@@ -1905,5 +1918,6 @@ public class AwSettings {
void updateOffscreenPreRasterLocked(long nativeAwSettings, AwSettings caller); void updateOffscreenPreRasterLocked(long nativeAwSettings, AwSettings caller);
void updateWillSuppressErrorStateLocked(long nativeAwSettings, AwSettings caller); void updateWillSuppressErrorStateLocked(long nativeAwSettings, AwSettings caller);
void updateCookiePolicyLocked(long nativeAwSettings, AwSettings caller); void updateCookiePolicyLocked(long nativeAwSettings, AwSettings caller);
void updateAllowFileAccessLocked(long nativeAwSettings, AwSettings caller);
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment