summaryrefslogtreecommitdiffstats
path: root/android_webview/native/aw_settings.cc
diff options
context:
space:
mode:
Diffstat (limited to 'android_webview/native/aw_settings.cc')
-rw-r--r--android_webview/native/aw_settings.cc41
1 files changed, 38 insertions, 3 deletions
diff --git a/android_webview/native/aw_settings.cc b/android_webview/native/aw_settings.cc
index 8ab91dd..81ff074 100644
--- a/android_webview/native/aw_settings.cc
+++ b/android_webview/native/aw_settings.cc
@@ -6,6 +6,8 @@
#include "android_webview/browser/renderer_host/aw_render_view_host_ext.h"
#include "android_webview/native/aw_contents.h"
+#include "content/public/browser/render_view_host.h"
+#include "content/public/browser/web_contents.h"
#include "jni/AwSettings_jni.h"
#include "webkit/glue/webkit_glue.h"
@@ -50,8 +52,15 @@ void AwSettings::SetTextZoom(JNIEnv* env, jobject obj, jint text_zoom_percent) {
UpdateTextZoom();
}
-void AwSettings::SetWebContents(JNIEnv* env, jobject obj, jint web_contents) {
- Observe(reinterpret_cast<content::WebContents*>(web_contents));
+void AwSettings::SetWebContents(JNIEnv* env, jobject obj, jint jweb_contents) {
+ content::WebContents* web_contents =
+ reinterpret_cast<content::WebContents*>(jweb_contents);
+ Observe(web_contents);
+
+ UpdateRenderViewHostExtSettings();
+ if (web_contents->GetRenderViewHost()) {
+ UpdateRenderViewHostSettings(web_contents->GetRenderViewHost());
+ }
}
void AwSettings::UpdateInitialPageScale() {
@@ -76,11 +85,37 @@ void AwSettings::UpdateTextZoom() {
}
}
-void AwSettings::RenderViewCreated(content::RenderViewHost* render_view_host) {
+void AwSettings::UpdatePreferredSizeMode(
+ content::RenderViewHost* render_view_host) {
+ render_view_host->EnablePreferredSizeMode();
+}
+
+void AwSettings::UpdateRenderViewHostExtSettings() {
UpdateInitialPageScale();
UpdateTextZoom();
}
+void AwSettings::UpdateRenderViewHostSettings(
+ content::RenderViewHost* render_view_host) {
+ UpdatePreferredSizeMode(render_view_host);
+}
+
+void AwSettings::RenderViewCreated(content::RenderViewHost* render_view_host) {
+ // A single WebContents can normally have 0, 1 or 2 RenderViewHost instances
+ // associated with it.
+ // This is important since there is only one RenderViewHostExt instance per
+ // WebContents (and not one RVHExt per RVH, as you might expect) and updating
+ // settings via RVHExt only ever updates the 'current' RVH.
+ // In android_webview we don't swap out the RVH on cross-site navigations, so
+ // we shouldn't have to deal with the multiple RVH per WebContents case. That
+ // in turn means that the newly created RVH is always the 'current' RVH
+ // (since we only ever go from 0 to 1 RVH instances) and hence the DCHECK.
+ DCHECK(web_contents()->GetRenderViewHost() == render_view_host);
+
+ UpdateRenderViewHostExtSettings();
+ UpdateRenderViewHostSettings(render_view_host);
+}
+
static jint Init(JNIEnv* env,
jobject obj,
jint web_contents) {