| Index: third_party/WebKit/Source/web/WebViewImpl.cpp
 | 
| diff --git a/third_party/WebKit/Source/web/WebViewImpl.cpp b/third_party/WebKit/Source/web/WebViewImpl.cpp
 | 
| index 3e92e32a2f867341300bb60c550f5729a13a1c55..22bb37d2f703d040b1712d3261b0758e80120ef5 100644
 | 
| --- a/third_party/WebKit/Source/web/WebViewImpl.cpp
 | 
| +++ b/third_party/WebKit/Source/web/WebViewImpl.cpp
 | 
| @@ -56,6 +56,7 @@
 | 
|  #include "core/frame/LocalFrame.h"
 | 
|  #include "core/frame/PageScaleConstraintsSet.h"
 | 
|  #include "core/frame/RemoteFrame.h"
 | 
| +#include "core/frame/ScrollAndScaleEmulator.h"
 | 
|  #include "core/frame/Settings.h"
 | 
|  #include "core/frame/SmartClip.h"
 | 
|  #include "core/frame/TopControls.h"
 | 
| @@ -3208,6 +3209,31 @@ WebFloatSize WebViewImpl::visualViewportSize() const
 | 
|      return page()->frameHost().visualViewport().visibleRect().size();
 | 
|  }
 | 
|  
 | 
| +void WebViewImpl::setScrollAndScaleOverride(const WebDeviceEmulationParams& params)
 | 
| +{
 | 
| +    if (!page())
 | 
| +        return;
 | 
| +
 | 
| +    if (!m_scrollAndScaleEmulator) {
 | 
| +        m_scrollAndScaleEmulator = ScrollAndScaleEmulator::create(page());
 | 
| +    }
 | 
| +
 | 
| +    m_scrollAndScaleEmulator->update(
 | 
| +        page(), static_cast<IntPoint>(params.scrollPosition),
 | 
| +        static_cast<FloatPoint>(params.visualViewportPosition),
 | 
| +        params.visualViewportScale);
 | 
| +}
 | 
| +
 | 
| +void WebViewImpl::clearScrollAndScaleOverride()
 | 
| +{
 | 
| +    if (!m_scrollAndScaleEmulator || !page())
 | 
| +        return;
 | 
| +
 | 
| +    m_scrollAndScaleEmulator->clear(page());
 | 
| +    m_scrollAndScaleEmulator.clear();
 | 
| +    resetScrollAndScaleState();
 | 
| +}
 | 
| +
 | 
|  void WebViewImpl::scrollAndRescaleViewports(float scaleFactor,
 | 
|      const IntPoint& mainFrameOrigin,
 | 
|      const FloatPoint& visualViewportOrigin)
 | 
| @@ -3343,7 +3369,13 @@ void WebViewImpl::setIgnoreViewportTagScaleLimits(bool ignore)
 | 
|  IntSize WebViewImpl::mainFrameSize()
 | 
|  {
 | 
|      // The frame size should match the viewport size at minimum scale, since the
 | 
| -    // viewport must always be contained by the frame.
 | 
| +    // viewport must always be contained by the frame. As ScrollAndScaleEmulator
 | 
| +    // may override the minimum scale, it is responsible for this calculation if
 | 
| +    // it is active.
 | 
| +    if (m_scrollAndScaleEmulator) {
 | 
| +        return m_scrollAndScaleEmulator->mainFrameSize(page(), m_size);
 | 
| +    }
 | 
| +
 | 
|      FloatSize frameSize(m_size);
 | 
|      frameSize.scale(1 / minimumPageScaleFactor());
 | 
|      return expandedIntSize(frameSize);
 | 
| @@ -3834,10 +3866,12 @@ void WebViewImpl::setRootLayerTransform(const WebSize& rootLayerOffset, float ro
 | 
|  void WebViewImpl::enableDeviceEmulation(const WebDeviceEmulationParams& params)
 | 
|  {
 | 
|      m_devToolsEmulator->enableDeviceEmulation(params);
 | 
| +    setScrollAndScaleOverride(params);
 | 
|  }
 | 
|  
 | 
|  void WebViewImpl::disableDeviceEmulation()
 | 
|  {
 | 
| +    clearScrollAndScaleOverride();
 | 
|      m_devToolsEmulator->disableDeviceEmulation();
 | 
|  }
 | 
|  
 | 
| 
 |