Plug-ins have no way to find out when the device scale factor changes
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 26 Oct 2011 00:30:39 +0000 (00:30 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 26 Oct 2011 00:30:39 +0000 (00:30 +0000)
https://bugs.webkit.org/show_bug.cgi?id=67226

Reviewed by Sam Weinig.

Source/WebKit2:

* PluginProcess/PluginControllerProxy.cpp:
(WebKit::PluginControllerProxy::geometryDidChange):
* PluginProcess/PluginControllerProxy.h:
This now takes the contentsScaleFactor and calls contentsScaleFactorChanged on its plug-in
if the scale factor changes.

* PluginProcess/PluginControllerProxy.messages.in:
GeometryDidChange now takes a contents scale factor parameter.

* WebProcess/Plugins/Netscape/NetscapePlugin.h:
* WebProcess/Plugins/Netscape/mac/NetscapePluginMac.mm:
(WebKit::NetscapePlugin::contentsScaleFactorChanged):
Implement contentsScaleFactorChanged and call NPP_SetValue with the new scale factor.

* WebProcess/Plugins/PDF/BuiltInPDFView.cpp:
(WebKit::BuiltInPDFView::contentsScaleFactorChanged):
* WebProcess/Plugins/PDF/BuiltInPDFView.h:
Add stub.

* WebProcess/Plugins/Plugin.h:
Add pure virtual contentsScaleFactorChanged member function.

* WebProcess/Plugins/PluginProxy.cpp:
(WebKit::PluginProxy::geometryDidChange):
Add geometryDidChange overload that doesn't take any parameters. Make it send over the
new scale factor to the plug-in process.

(WebKit::PluginProxy::contentsScaleFactorChanged):
Call geometryDidChange.

* WebProcess/Plugins/PluginView.cpp:
(WebKit::PluginView::setDeviceScaleFactor):
Call Plugin::contentsScaleFactorChanged.

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::setDeviceScaleFactor):
Call setDeviceScaleFactor on all registered plug-ins.

Tools:

Keep a cached copy of the contents scale and update it when it changes.

* DumpRenderTree/TestNetscapePlugIn/Tests/mac/ContentsScaleFactor.cpp:
(ContentsScaleFactor::ContentsScaleFactor):
(ContentsScaleFactor::cachedContentsScaleFactor):
(ContentsScaleFactor::ScriptableObject::hasProperty):
(ContentsScaleFactor::ScriptableObject::getProperty):
(ContentsScaleFactor::NPP_New):
(ContentsScaleFactor::NPP_SetValue):

LayoutTests:

Update test to check that the scale factor is updated correctly.

* platform/mac-wk2/plugins/contents-scale-factor.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@98413 268f45cc-cd09-0410-ab3c-d52691b4dbfc

18 files changed:
LayoutTests/ChangeLog
LayoutTests/platform/mac-wk2/plugins/contents-scale-factor.html
Source/WebKit2/ChangeLog
Source/WebKit2/PluginProcess/PluginControllerProxy.cpp
Source/WebKit2/PluginProcess/PluginControllerProxy.h
Source/WebKit2/PluginProcess/PluginControllerProxy.messages.in
Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h
Source/WebKit2/WebProcess/Plugins/Netscape/mac/NetscapePluginMac.mm
Source/WebKit2/WebProcess/Plugins/PDF/BuiltInPDFView.cpp
Source/WebKit2/WebProcess/Plugins/PDF/BuiltInPDFView.h
Source/WebKit2/WebProcess/Plugins/Plugin.h
Source/WebKit2/WebProcess/Plugins/PluginProxy.cpp
Source/WebKit2/WebProcess/Plugins/PluginProxy.h
Source/WebKit2/WebProcess/Plugins/PluginView.cpp
Source/WebKit2/WebProcess/Plugins/PluginView.h
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Tools/ChangeLog
Tools/DumpRenderTree/TestNetscapePlugIn/Tests/mac/ContentsScaleFactor.cpp

index 049dd1d..60bd7fd 100644 (file)
@@ -1,3 +1,14 @@
+2011-10-25  Anders Carlsson  <andersca@apple.com>
+
+        Plug-ins have no way to find out when the device scale factor changes
+        https://bugs.webkit.org/show_bug.cgi?id=67226
+
+        Reviewed by Sam Weinig.
+
+        Update test to check that the scale factor is updated correctly.
+
+        * platform/mac-wk2/plugins/contents-scale-factor.html:
+
 2011-10-25  Fady Samuel  <fsamuel@chromium.org>
 
         Made Table tests for Bug 70678 Platform Independent
index 858ccd1..226bef3 100644 (file)
@@ -28,14 +28,18 @@ function runTest()
     document.body.appendChild(plugin1);
     
     shouldBe("plugin1.contentsScaleFactor", "1.0");
+    shouldBe("plugin1.cachedContentsScaleFactor", "1.0");
 
     // Now change the backing scale factor.
     layoutTestController.setBackingScaleFactor(2, function() {
+        shouldBe("plugin1.contentsScaleFactor", "2.0");
+        shouldBe("plugin1.cachedContentsScaleFactor", "2.0");
     
         plugin2 = createTestPlugin('contents-scale-factor');
         document.body.appendChild(plugin2);
     
         shouldBe("plugin2.contentsScaleFactor", "2.0");
+        shouldBe("plugin2.cachedContentsScaleFactor", "2.0");
 
         layoutTestController.notifyDone();
     });
index fb9fafe..29e9a47 100644 (file)
@@ -1,3 +1,48 @@
+2011-10-25  Anders Carlsson  <andersca@apple.com>
+
+        Plug-ins have no way to find out when the device scale factor changes
+        https://bugs.webkit.org/show_bug.cgi?id=67226
+
+        Reviewed by Sam Weinig.
+
+        * PluginProcess/PluginControllerProxy.cpp:
+        (WebKit::PluginControllerProxy::geometryDidChange):
+        * PluginProcess/PluginControllerProxy.h:
+        This now takes the contentsScaleFactor and calls contentsScaleFactorChanged on its plug-in
+        if the scale factor changes.
+
+        * PluginProcess/PluginControllerProxy.messages.in:
+        GeometryDidChange now takes a contents scale factor parameter.
+
+        * WebProcess/Plugins/Netscape/NetscapePlugin.h:
+        * WebProcess/Plugins/Netscape/mac/NetscapePluginMac.mm:
+        (WebKit::NetscapePlugin::contentsScaleFactorChanged):
+        Implement contentsScaleFactorChanged and call NPP_SetValue with the new scale factor.
+
+        * WebProcess/Plugins/PDF/BuiltInPDFView.cpp:
+        (WebKit::BuiltInPDFView::contentsScaleFactorChanged):
+        * WebProcess/Plugins/PDF/BuiltInPDFView.h:
+        Add stub.
+
+        * WebProcess/Plugins/Plugin.h:
+        Add pure virtual contentsScaleFactorChanged member function.
+
+        * WebProcess/Plugins/PluginProxy.cpp:
+        (WebKit::PluginProxy::geometryDidChange):
+        Add geometryDidChange overload that doesn't take any parameters. Make it send over the
+        new scale factor to the plug-in process.
+
+        (WebKit::PluginProxy::contentsScaleFactorChanged):
+        Call geometryDidChange.
+
+        * WebProcess/Plugins/PluginView.cpp:
+        (WebKit::PluginView::setDeviceScaleFactor):
+        Call Plugin::contentsScaleFactorChanged.
+
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::setDeviceScaleFactor):
+        Call setDeviceScaleFactor on all registered plug-ins.
+
 2011-10-25  Beth Dakin  <bdakin@apple.com>
 
         https://bugs.webkit.org/show_bug.cgi?id=70852
index fe5244e..c4aa415 100644 (file)
@@ -423,13 +423,18 @@ void PluginControllerProxy::frameDidFail(uint64_t requestID, bool wasCancelled)
     m_plugin->frameDidFail(requestID, wasCancelled);
 }
 
-void PluginControllerProxy::geometryDidChange(const IntRect& frameRect, const IntRect& clipRect, const ShareableBitmap::Handle& backingStoreHandle)
+void PluginControllerProxy::geometryDidChange(const IntRect& frameRect, const IntRect& clipRect, float contentsScaleFactor, const ShareableBitmap::Handle& backingStoreHandle)
 {
     m_frameRect = frameRect;
     m_clipRect = clipRect;
 
     ASSERT(m_plugin);
 
+    if (contentsScaleFactor != m_contentsScaleFactor) {
+        m_contentsScaleFactor = contentsScaleFactor;
+        m_plugin->contentsScaleFactorChanged(m_contentsScaleFactor);
+    }
+
     platformGeometryDidChange();
 
     if (!backingStoreHandle.isNull()) {
index fe9280b..a5e6c99 100644 (file)
@@ -113,7 +113,7 @@ private:
     // Message handlers.
     void frameDidFinishLoading(uint64_t requestID);
     void frameDidFail(uint64_t requestID, bool wasCancelled);
-    void geometryDidChange(const WebCore::IntRect& frameRect, const WebCore::IntRect& clipRect, const ShareableBitmap::Handle& backingStoreHandle);
+    void geometryDidChange(const WebCore::IntRect& frameRect, const WebCore::IntRect& clipRect, float contentsScaleFactor, const ShareableBitmap::Handle& backingStoreHandle);
     void didEvaluateJavaScript(uint64_t requestID, const String& result);
     void streamDidReceiveResponse(uint64_t streamID, const String& responseURLString, uint32_t streamLength, uint32_t lastModifiedTime, const String& mimeType, const String& headers);
     void streamDidReceiveData(uint64_t streamID, const CoreIPC::DataReference& data);
index ecb1410..5fc5c48 100644 (file)
@@ -24,7 +24,7 @@
 
 messages -> PluginControllerProxy {
     # Sent when the plug-in geometry changes.
-    GeometryDidChange(WebCore::IntRect frameRect, WebCore::IntRect clipRect, WebKit::ShareableBitmap::Handle backingStoreHandle)
+    GeometryDidChange(WebCore::IntRect frameRect, WebCore::IntRect clipRect, float scaleFactor, WebKit::ShareableBitmap::Handle backingStoreHandle)
 
     # Sent when a frame has finished loading.
     FrameDidFinishLoading(uint64_t requestID)
index e2d9100..5a4bdfa 100644 (file)
@@ -197,6 +197,7 @@ private:
     virtual void windowFocusChanged(bool);
     virtual void windowAndViewFramesChanged(const WebCore::IntRect& windowFrameInScreenCoordinates, const WebCore::IntRect& viewFrameInWindowCoordinates);
     virtual void windowVisibilityChanged(bool);
+    virtual void contentsScaleFactorChanged(float);
 
     virtual uint64_t pluginComplexTextInputIdentifier() const;
     virtual void sendComplexTextInput(const String& textInput);
index 6aca0ca..4a3325d 100644 (file)
@@ -925,6 +925,12 @@ void NetscapePlugin::windowVisibilityChanged(bool)
     // FIXME: Implement.
 }
 
+void NetscapePlugin::contentsScaleFactorChanged(float scaleFactor)
+{
+    double contentsScaleFactor = scaleFactor;
+    NPP_SetValue(NPNVcontentsScaleFactor, &contentsScaleFactor);
+}
+
 uint64_t NetscapePlugin::pluginComplexTextInputIdentifier() const
 {
     // Just return a dummy value; this is only called for in-process plug-ins, which we don't support on Mac.
index 8ab79cd..11a4324 100644 (file)
@@ -507,6 +507,10 @@ void BuiltInPDFView::windowVisibilityChanged(bool)
 {
 }
 
+void BuiltInPDFView::contentsScaleFactorChanged(float)
+{
+}
+
 uint64_t BuiltInPDFView::pluginComplexTextInputIdentifier() const
 {
     return 0;
index b31525d..a590b8b 100644 (file)
@@ -104,6 +104,7 @@ private:
     virtual void windowFocusChanged(bool);
     virtual void windowAndViewFramesChanged(const WebCore::IntRect& windowFrameInScreenCoordinates, const WebCore::IntRect& viewFrameInWindowCoordinates);
     virtual void windowVisibilityChanged(bool);
+    virtual void contentsScaleFactorChanged(float);
     virtual uint64_t pluginComplexTextInputIdentifier() const;
     virtual void sendComplexTextInput(const String& textInput);
 #endif
index bca7475..edeb7c6 100644 (file)
@@ -191,6 +191,9 @@ public:
     // Tells the plug-in about window visibility changes.
     virtual void windowVisibilityChanged(bool) = 0;
 
+    // Tells the plug-in about scale factor changes.
+    virtual void contentsScaleFactorChanged(float) = 0;
+
     // Get the per complex text input identifier.
     virtual uint64_t pluginComplexTextInputIdentifier() const = 0;
 
index 05301c5..28e690e 100644 (file)
@@ -175,25 +175,25 @@ bool PluginProxy::isTransparent()
     return false;
 }
 
-void PluginProxy::geometryDidChange(const IntRect& frameRect, const IntRect& clipRect)
+void PluginProxy::geometryDidChange()
 {
     ASSERT(m_isStarted);
 
-    m_frameRect = frameRect;
+    float contentsScaleFactor = controller()->contentsScaleFactor();
 
     if (m_frameRect.isEmpty() || !needsBackingStore()) {
         ShareableBitmap::Handle pluginBackingStoreHandle;
-        m_connection->connection()->send(Messages::PluginControllerProxy::GeometryDidChange(frameRect, clipRect, pluginBackingStoreHandle), m_pluginInstanceID, CoreIPC::DispatchMessageEvenWhenWaitingForSyncReply);
+        m_connection->connection()->send(Messages::PluginControllerProxy::GeometryDidChange(m_frameRect, m_clipRect, contentsScaleFactor, pluginBackingStoreHandle), m_pluginInstanceID, CoreIPC::DispatchMessageEvenWhenWaitingForSyncReply);
         return;
     }
 
     bool didUpdateBackingStore = false;
     if (!m_backingStore) {
-        m_backingStore = ShareableBitmap::create(frameRect.size(), ShareableBitmap::SupportsAlpha);
+        m_backingStore = ShareableBitmap::create(m_frameRect.size(), ShareableBitmap::SupportsAlpha);
         didUpdateBackingStore = true;
-    } else if (frameRect.size() != m_backingStore->size()) {
+    } else if (m_frameRect.size() != m_backingStore->size()) {
         // The backing store already exists, just resize it.
-        if (!m_backingStore->resize(frameRect.size()))
+        if (!m_backingStore->resize(m_frameRect.size()))
             return;
 
         didUpdateBackingStore = true;
@@ -203,7 +203,7 @@ void PluginProxy::geometryDidChange(const IntRect& frameRect, const IntRect& cli
 
     if (didUpdateBackingStore) {
         // Create a new plug-in backing store.
-        m_pluginBackingStore = ShareableBitmap::createShareable(frameRect.size(), ShareableBitmap::SupportsAlpha);
+        m_pluginBackingStore = ShareableBitmap::createShareable(m_frameRect.size(), ShareableBitmap::SupportsAlpha);
         if (!m_pluginBackingStore)
             return;
 
@@ -216,7 +216,15 @@ void PluginProxy::geometryDidChange(const IntRect& frameRect, const IntRect& cli
         m_pluginBackingStoreContainsValidData = false;
     }
 
-    m_connection->connection()->send(Messages::PluginControllerProxy::GeometryDidChange(frameRect, clipRect, pluginBackingStoreHandle), m_pluginInstanceID, CoreIPC::DispatchMessageEvenWhenWaitingForSyncReply);
+    m_connection->connection()->send(Messages::PluginControllerProxy::GeometryDidChange(m_frameRect, m_clipRect, contentsScaleFactor, pluginBackingStoreHandle), m_pluginInstanceID, CoreIPC::DispatchMessageEvenWhenWaitingForSyncReply);
+}
+
+void PluginProxy::geometryDidChange(const IntRect& frameRect, const IntRect& clipRect)
+{
+    m_frameRect = frameRect;
+    m_clipRect = clipRect;
+
+    geometryDidChange();
 }
 
 void PluginProxy::visibilityDidChange()
@@ -369,6 +377,11 @@ void PluginProxy::windowVisibilityChanged(bool isVisible)
     m_connection->connection()->send(Messages::PluginControllerProxy::WindowVisibilityChanged(isVisible), m_pluginInstanceID);
 }
 
+void PluginProxy::contentsScaleFactorChanged(float scaleFactor)
+{
+    geometryDidChange();
+}
+
 uint64_t PluginProxy::pluginComplexTextInputIdentifier() const
 {
     return m_pluginInstanceID;
index 0dd8edd..a126fa4 100644 (file)
@@ -97,6 +97,7 @@ private:
     virtual void windowFocusChanged(bool);
     virtual void windowAndViewFramesChanged(const WebCore::IntRect& windowFrameInScreenCoordinates, const WebCore::IntRect& viewFrameInWindowCoordinates);
     virtual void windowVisibilityChanged(bool);
+    virtual void contentsScaleFactorChanged(float);
     virtual uint64_t pluginComplexTextInputIdentifier() const;
     virtual void sendComplexTextInput(const String& textInput);
 #endif
@@ -111,6 +112,8 @@ private:
     bool needsBackingStore() const;
     uint64_t windowNPObjectID();
 
+    void geometryDidChange();
+
     // Message handlers.
     void loadURL(uint64_t requestID, const String& method, const String& urlString, const String& target, const WebCore::HTTPHeaderMap& headerFields, const Vector<uint8_t>& httpBody, bool allowPopups);
     void update(const WebCore::IntRect& paintedRect);
@@ -136,6 +139,9 @@ private:
     // The plug-in rect in window coordinates.
     WebCore::IntRect m_frameRect;
 
+    // The plug-in clip rect in window coordinates.
+    WebCore::IntRect m_clipRect;
+
     // This is the backing store that we paint when we're told to paint.
     RefPtr<ShareableBitmap> m_backingStore;
 
index 00e51c8..fbd361f 100644 (file)
@@ -404,6 +404,14 @@ void PluginView::setWindowIsFocused(bool windowIsFocused)
     m_plugin->windowFocusChanged(windowIsFocused);    
 }
 
+void PluginView::setDeviceScaleFactor(float scaleFactor)
+{
+    if (!m_isInitialized || !m_plugin)
+        return;
+
+    m_plugin->contentsScaleFactorChanged(scaleFactor);
+}
+
 void PluginView::windowAndViewFramesChanged(const IntRect& windowFrameInScreenCoordinates, const IntRect& viewFrameInWindowCoordinates)
 {
     if (!m_isInitialized || !m_plugin)
index 21b6e77..203892f 100644 (file)
@@ -63,6 +63,7 @@ public:
 #if PLATFORM(MAC)
     void setWindowIsVisible(bool);
     void setWindowIsFocused(bool);
+    void setDeviceScaleFactor(float);
     void windowAndViewFramesChanged(const WebCore::IntRect& windowFrameInScreenCoordinates, const WebCore::IntRect& viewFrameInWindowCoordinates);
     bool sendComplexTextInput(uint64_t pluginComplexTextInputIdentifier, const String& textInput);
 #endif
index 78d98a1..ad02390 100644 (file)
@@ -850,6 +850,12 @@ void WebPage::setDeviceScaleFactor(float scaleFactor)
         return;
 
     m_page->setDeviceScaleFactor(scaleFactor);
+
+    // Tell all our plug-in views that the device scale factor changed.
+#if PLATFORM(MAC)
+    for (HashSet<PluginView*>::const_iterator it = m_pluginViews.begin(), end = m_pluginViews.end(); it != end; ++it)
+        (*it)->setDeviceScaleFactor(scaleFactor);
+#endif
 }
 
 void WebPage::setUseFixedLayout(bool fixed)
index 50f1a32..f62a128 100644 (file)
@@ -1,3 +1,20 @@
+2011-10-25  Anders Carlsson  <andersca@apple.com>
+
+        Plug-ins have no way to find out when the device scale factor changes
+        https://bugs.webkit.org/show_bug.cgi?id=67226
+
+        Reviewed by Sam Weinig.
+
+        Keep a cached copy of the contents scale and update it when it changes.
+
+        * DumpRenderTree/TestNetscapePlugIn/Tests/mac/ContentsScaleFactor.cpp:
+        (ContentsScaleFactor::ContentsScaleFactor):
+        (ContentsScaleFactor::cachedContentsScaleFactor):
+        (ContentsScaleFactor::ScriptableObject::hasProperty):
+        (ContentsScaleFactor::ScriptableObject::getProperty):
+        (ContentsScaleFactor::NPP_New):
+        (ContentsScaleFactor::NPP_SetValue):
+
 2011-10-25  Sam Weinig  <sam@webkit.org>
 
         Add WKBrowsingContextLoadDelegateTest test for a failed load
index e41b492..5353d83 100644 (file)
@@ -31,6 +31,7 @@ class ContentsScaleFactor : public PluginTest {
 public:
     ContentsScaleFactor(NPP npp, const string& identifier)
         : PluginTest(npp, identifier)
+        , m_cachedContentsScaleFactor(1.0)
     {
     }
 
@@ -42,11 +43,17 @@ private:
         return contentsScaleFactor;
     }
 
+    double cachedContentsScaleFactor()
+    {
+        return m_cachedContentsScaleFactor;
+    }
+
     class ScriptableObject : public Object<ScriptableObject> { 
     public:
         bool hasProperty(NPIdentifier propertyName)
         {
-            return identifierIs(propertyName, "contentsScaleFactor");
+            return identifierIs(propertyName, "contentsScaleFactor")
+            || identifierIs(propertyName, "cachedContentsScaleFactor");
         }
 
         bool getProperty(NPIdentifier propertyName, NPVariant* result)
@@ -56,6 +63,10 @@ private:
                 return true;
             }
 
+            if (identifierIs(propertyName, "cachedContentsScaleFactor")) {
+                DOUBLE_TO_NPVARIANT(pluginTest()->cachedContentsScaleFactor(), *result);
+                return true;
+            }
             return false;
         }
 
@@ -64,6 +75,12 @@ private:
 
     };
 
+    virtual NPError NPP_New(NPMIMEType pluginType, uint16_t mode, int16_t argc, char* argn[], char* argv[], NPSavedData *saved)
+    {
+        m_cachedContentsScaleFactor = contentsScaleFactor();
+        return NPERR_NO_ERROR;
+    }
+
     virtual NPError NPP_GetValue(NPPVariable variable, void* value)
     {
         if (variable != NPPVpluginScriptableNPObject)
@@ -73,6 +90,18 @@ private:
         
         return NPERR_NO_ERROR;
     }
+
+    virtual NPError NPP_SetValue(NPNVariable variable, void* value)
+    {
+        switch (variable) {
+        case NPNVcontentsScaleFactor:
+            m_cachedContentsScaleFactor = *(double*)value;
+            return NPERR_NO_ERROR;
+        default:
+            return NPERR_GENERIC_ERROR;
+        }
+    }
+    double m_cachedContentsScaleFactor;
 };
 
 static PluginTest::Register<ContentsScaleFactor> contentsScaleFactor("contents-scale-factor");