summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--android_webview/javatests/src/org/chromium/android_webview/test/AwTargetDensityDpiTest.java54
-rw-r--r--content/browser/android/content_settings.cc6
-rw-r--r--content/public/android/java/src/org/chromium/content/browser/ContentSettings.java3
-rw-r--r--content/public/common/common_param_traits_macros.h1
-rw-r--r--webkit/glue/webpreferences.cc5
-rw-r--r--webkit/glue/webpreferences.h1
6 files changed, 69 insertions, 1 deletions
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AwTargetDensityDpiTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/AwTargetDensityDpiTest.java
new file mode 100644
index 0000000..4bc3a07
--- /dev/null
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwTargetDensityDpiTest.java
@@ -0,0 +1,54 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.android_webview.test;
+
+import android.test.suitebuilder.annotation.MediumTest;
+import org.chromium.android_webview.AwContents;
+import org.chromium.base.test.util.Feature;
+import org.chromium.content.browser.ContentSettings;
+import org.chromium.content.browser.test.util.CallbackHelper;
+import org.chromium.ui.gfx.DeviceDisplayInfo;
+
+public class AwTargetDensityDpiTest extends AwTestBase {
+
+ @MediumTest
+ @Feature({"AndroidWebView"})
+ public void testTargetDensityDpi() throws Throwable {
+ final TestAwContentsClient contentClient = new TestAwContentsClient();
+ final AwTestContainerView testContainerView =
+ createAwTestContainerViewOnMainSync(contentClient);
+ final AwContents awContents = testContainerView.getAwContents();
+ ContentSettings settings = getContentSettingsOnUiThread(awContents);
+ CallbackHelper onPageFinishedHelper = contentClient.getOnPageFinishedHelper();
+
+ final String pageTemplate = "<html><head>" +
+ "<meta name='viewport' content='width=device-width, target-densityDpi=%s' />" +
+ "</head><body onload='document.title=document.body.clientWidth'></body></html>";
+ final String pageDeviceDpi = String.format(pageTemplate, "device-dpi");
+ final String pageHighDpi = String.format(pageTemplate, "high-dpi");
+ final String pageDpi100 = String.format(pageTemplate, "100");
+
+ settings.setJavaScriptEnabled(true);
+ // TODO(mnaganov): Should not be needed. See b/8487489.
+ settings.setUseWideViewPort(true);
+ awContents.getSettings().setEnableFixedLayoutMode(true);
+
+ DeviceDisplayInfo deviceInfo =
+ DeviceDisplayInfo.create(getInstrumentation().getTargetContext());
+ loadDataSync(awContents, onPageFinishedHelper, pageDeviceDpi, "text/html", false);
+ int actualWidth = Integer.parseInt(getTitleOnUiThread(awContents));
+ assertEquals((float)deviceInfo.getDisplayWidth(), (float)actualWidth, 10f);
+
+ float displayWidth = (float)(deviceInfo.getDisplayWidth() / deviceInfo.getDIPScale());
+ float deviceDpi = (float)(120f * deviceInfo.getDIPScale());
+ loadDataSync(awContents, onPageFinishedHelper, pageHighDpi, "text/html", false);
+ actualWidth = Integer.parseInt(getTitleOnUiThread(awContents));
+ assertEquals(displayWidth * (240f / deviceDpi), (float)actualWidth, 10f);
+
+ loadDataSync(awContents, onPageFinishedHelper, pageDpi100, "text/html", false);
+ actualWidth = Integer.parseInt(getTitleOnUiThread(awContents));
+ assertEquals(displayWidth * (100f / deviceDpi), (float)actualWidth, 10f);
+ }
+}
diff --git a/content/browser/android/content_settings.cc b/content/browser/android/content_settings.cc
index 60a6e23..3216ce6 100644
--- a/content/browser/android/content_settings.cc
+++ b/content/browser/android/content_settings.cc
@@ -90,6 +90,8 @@ struct ContentSettings::FieldIds {
GetFieldID(env, clazz, "mMediaPlaybackRequiresUserGesture", "Z");
default_video_poster_url =
GetFieldID(env, clazz, "mDefaultVideoPosterURL", kStringClassName);
+ support_deprecated_target_density_dpi =
+ GetFieldID(env, clazz, "mSupportDeprecatedTargetDensityDPI", "Z");
}
// Field ids
@@ -119,6 +121,7 @@ struct ContentSettings::FieldIds {
jfieldID load_with_overview_mode;
jfieldID media_playback_requires_user_gesture;
jfieldID default_video_poster_url;
+ jfieldID support_deprecated_target_density_dpi;
};
ContentSettings::ContentSettings(JNIEnv* env,
@@ -428,6 +431,9 @@ void ContentSettings::SyncToNativeImpl() {
prefs.default_video_poster_url = str.obj() ?
GURL(ConvertJavaStringToUTF8(str)) : GURL();
+ prefs.support_deprecated_target_density_dpi = env->GetBooleanField(
+ obj, field_ids_->support_deprecated_target_density_dpi);
+
render_view_host->UpdateWebkitPreferences(prefs);
}
diff --git a/content/public/android/java/src/org/chromium/content/browser/ContentSettings.java b/content/public/android/java/src/org/chromium/content/browser/ContentSettings.java
index 5f3e8d3..bd5f04a 100644
--- a/content/public/android/java/src/org/chromium/content/browser/ContentSettings.java
+++ b/content/public/android/java/src/org/chromium/content/browser/ContentSettings.java
@@ -96,6 +96,8 @@ public class ContentSettings {
private boolean mMediaPlaybackRequiresUserGesture = true;
private String mDefaultVideoPosterURL;
+ private boolean mSupportDeprecatedTargetDensityDPI = false;
+
// Not accessed by the native side.
private boolean mSupportZoom = true;
private boolean mBuiltInZoomControls = false;
@@ -229,6 +231,7 @@ public class ContentSettings {
if (mCanModifySettings) {
// PERSONALITY_VIEW
mUserAgent = LazyDefaultUserAgent.sInstance;
+ mSupportDeprecatedTargetDensityDPI = true;
syncToNativeOnUiThread();
} else {
// PERSONALITY_CHROME
diff --git a/content/public/common/common_param_traits_macros.h b/content/public/common/common_param_traits_macros.h
index 9e9213c..85438c4 100644
--- a/content/public/common/common_param_traits_macros.h
+++ b/content/public/common/common_param_traits_macros.h
@@ -202,6 +202,7 @@ IPC_STRUCT_TRAITS_BEGIN(webkit_glue::WebPreferences)
IPC_STRUCT_TRAITS_MEMBER(double_tap_to_zoom_enabled)
IPC_STRUCT_TRAITS_MEMBER(user_gesture_required_for_media_playback)
IPC_STRUCT_TRAITS_MEMBER(default_video_poster_url)
+ IPC_STRUCT_TRAITS_MEMBER(support_deprecated_target_density_dpi)
#endif
IPC_STRUCT_TRAITS_END()
diff --git a/webkit/glue/webpreferences.cc b/webkit/glue/webpreferences.cc
index 44eea33..b07dd0d 100644
--- a/webkit/glue/webpreferences.cc
+++ b/webkit/glue/webpreferences.cc
@@ -145,7 +145,8 @@ WebPreferences::WebPreferences()
font_scale_factor(1.0f),
force_enable_zoom(false),
double_tap_to_zoom_enabled(true),
- user_gesture_required_for_media_playback(true)
+ user_gesture_required_for_media_playback(true),
+ support_deprecated_target_density_dpi(false)
#endif
{
standard_font_family_map[kCommonScript] =
@@ -470,6 +471,8 @@ void WebPreferences::Apply(WebView* web_view) const {
user_gesture_required_for_media_playback);
settings->setDefaultVideoPosterURL(
ASCIIToUTF16(default_video_poster_url.spec()));
+ settings->setSupportDeprecatedTargetDensityDPI(
+ support_deprecated_target_density_dpi);
#endif
WebNetworkStateNotifier::setOnLine(is_online);
diff --git a/webkit/glue/webpreferences.h b/webkit/glue/webpreferences.h
index 891111d..5811f83 100644
--- a/webkit/glue/webpreferences.h
+++ b/webkit/glue/webpreferences.h
@@ -163,6 +163,7 @@ struct WEBKIT_GLUE_EXPORT WebPreferences {
bool double_tap_to_zoom_enabled;
bool user_gesture_required_for_media_playback;
GURL default_video_poster_url;
+ bool support_deprecated_target_density_dpi;
#endif
// We try to keep the default values the same as the default values in