#include "config.h"
#include "core/dom/ViewportDescription.h"
+#include "core/dom/Document.h"
+#include "core/frame/FrameHost.h"
+#include "core/frame/FrameView.h"
+#include "core/frame/LocalFrame.h"
+#include "core/frame/Settings.h"
+#include "platform/weborigin/KURL.h"
+#include "public/platform/Platform.h"
+
using namespace std;
namespace WebCore {
return ViewportDescription::ValueAuto;
}
-PageScaleConstraints ViewportDescription::resolve(const FloatSize& initialViewportSize) const
+PageScaleConstraints ViewportDescription::resolve(const FloatSize& initialViewportSize, Length legacyFallbackWidth) const
{
float resultWidth = ValueAuto;
- float resultMaxWidth = resolveViewportLength(maxWidth, initialViewportSize, Horizontal);
- float resultMinWidth = resolveViewportLength(minWidth, initialViewportSize, Horizontal);
+
+ Length copyMaxWidth = maxWidth;
+ Length copyMinWidth = minWidth;
+ // In case the width (used for min- and max-width) is undefined.
+ if (isLegacyViewportType() && maxWidth.isAuto()) {
+ // The width viewport META property is translated into 'width' descriptors, setting
+ // the 'min' value to 'extend-to-zoom' and the 'max' value to the intended length.
+ // In case the UA-defines a min-width, use that as length.
+ if (zoom == ViewportDescription::ValueAuto) {
+ copyMinWidth = Length(ExtendToZoom);
+ copyMaxWidth = legacyFallbackWidth;
+ } else if (maxHeight.isAuto()) {
+ copyMinWidth = Length(ExtendToZoom);
+ copyMaxWidth = Length(ExtendToZoom);
+ }
+ }
+
+ float resultMaxWidth = resolveViewportLength(copyMaxWidth, initialViewportSize, Horizontal);
+ float resultMinWidth = resolveViewportLength(copyMinWidth, initialViewportSize, Horizontal);
+
float resultHeight = ValueAuto;
float resultMaxHeight = resolveViewportLength(maxHeight, initialViewportSize, Vertical);
float resultMinHeight = resolveViewportLength(minHeight, initialViewportSize, Vertical);
float resultZoom = zoom;
float resultMinZoom = minZoom;
float resultMaxZoom = maxZoom;
- float resultUserZoom = userZoom;
+ bool resultUserZoom = userZoom;
// 1. Resolve min-zoom and max-zoom values.
if (resultMinZoom != ViewportDescription::ValueAuto && resultMaxZoom != ViewportDescription::ValueAuto)
return result;
}
+void ViewportDescription::reportMobilePageStats(const LocalFrame* mainFrame) const
+{
+#if OS(ANDROID)
+ enum ViewportUMAType {
+ NoViewportTag,
+ DeviceWidth,
+ ConstantWidth,
+ MetaWidthOther,
+ MetaHandheldFriendly,
+ MetaMobileOptimized,
+ XhtmlMobileProfile,
+ TypeCount
+ };
+
+ if (!mainFrame || !mainFrame->host() || !mainFrame->view() || !mainFrame->document())
+ return;
+
+ // Avoid chrome:// pages like the new-tab page (on Android new tab is non-http).
+ if (!mainFrame->document()->url().protocolIsInHTTPFamily())
+ return;
+
+ if (!isSpecifiedByAuthor()) {
+ if (mainFrame->document()->isMobileDocument())
+ blink::Platform::current()->histogramEnumeration("Viewport.MetaTagType", XhtmlMobileProfile, TypeCount);
+ else
+ blink::Platform::current()->histogramEnumeration("Viewport.MetaTagType", NoViewportTag, TypeCount);
+
+ return;
+ }
+
+ if (isMetaViewportType()) {
+ if (maxWidth.type() == WebCore::Fixed) {
+ blink::Platform::current()->histogramEnumeration("Viewport.MetaTagType", ConstantWidth, TypeCount);
+
+ if (mainFrame->view()) {
+ // To get an idea of how "far" the viewport is from the device's ideal width, we
+ // report the zoom level that we'd need to be at for the entire page to be visible.
+ int viewportWidth = maxWidth.intValue();
+ int windowWidth = mainFrame->document()->settings()->pinchVirtualViewportEnabled()
+ ? mainFrame->host()->pinchViewport().size().width()
+ : mainFrame->view()->frameRect().width();
+ int overviewZoomPercent = 100 * windowWidth / static_cast<float>(viewportWidth);
+ blink::Platform::current()->histogramSparse("Viewport.OverviewZoom", overviewZoomPercent);
+ }
+
+ } else if (maxWidth.type() == WebCore::DeviceWidth || maxWidth.type() == WebCore::ExtendToZoom) {
+ blink::Platform::current()->histogramEnumeration("Viewport.MetaTagType", DeviceWidth, TypeCount);
+ } else {
+ // Overflow bucket for cases we may be unaware of.
+ blink::Platform::current()->histogramEnumeration("Viewport.MetaTagType", MetaWidthOther, TypeCount);
+ }
+ } else if (type == ViewportDescription::HandheldFriendlyMeta) {
+ blink::Platform::current()->histogramEnumeration("Viewport.MetaTagType", MetaHandheldFriendly, TypeCount);
+ } else if (type == ViewportDescription::MobileOptimizedMeta) {
+ blink::Platform::current()->histogramEnumeration("Viewport.MetaTagType", MobileOptimizedMeta, TypeCount);
+ }
+#endif
+}
+
} // namespace WebCore