Add WKBundlePageGetBackingScaleFactor
authoraroben@apple.com <aroben@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 27 Oct 2011 16:24:41 +0000 (16:24 +0000)
committeraroben@apple.com <aroben@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 27 Oct 2011 16:24:41 +0000 (16:24 +0000)
Fixes <http://webkit.org/b/71025> <rdar://problem/10355037> REGRESSION (r97191): Clients
can't reliably determine the scale factor of snapshots returned via
WKBundlePageCreateSnapshot* API

Reviewed by Sam Weinig.

Source/WebKit2:

* WebProcess/InjectedBundle/API/c/WKBundlePage.cpp:
(WKBundlePageGetBackingScaleFactor):
* WebProcess/InjectedBundle/API/c/WKBundlePage.h:
Added. Calls through to WebPage::deviceScaleFactor.

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::deviceScaleFactor):
* WebProcess/WebPage/WebPage.h:
Added. Calls through to Page::deviceScaleFactor.

Tools:

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: Added new files.

* TestWebKitAPI/Tests/WebKit2/mac/GetBackingScaleFactor.mm: Added.
(TestWebKitAPI::didReceiveMessageFromInjectedBundle): Record the passed-back scale factor.
(TestWebKitAPI::setInjectedBundleClient): Hook up our didReceiveMessage callback.
(TestWebKitAPI::createWindow): Conjure up a window.
(TestWebKitAPI::TEST): Ask the injected bundle code to call the new
WKBundlePageGetBackingScaleFactor API when the WKView is in windows with various scale
factors and when using a custom scale factor, and check that we get those same scale factors
back.

* TestWebKitAPI/Tests/WebKit2/mac/GetBackingScaleFactor_Bundle.mm: Added.
(TestWebKitAPI::GetBackingScaleFactorTest::GetBackingScaleFactorTest): Just initialize our
members.
(TestWebKitAPI::GetBackingScaleFactorTest::didCreatePage): Store the page for later.
(TestWebKitAPI::GetBackingScaleFactorTest::didReceiveMessage): Get the backing scale factor
from the page using the new API and send it back.

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

Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp
Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePage.h
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.h
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKit2/mac/GetBackingScaleFactor.mm [new file with mode: 0644]
Tools/TestWebKitAPI/Tests/WebKit2/mac/GetBackingScaleFactor_Bundle.mm [new file with mode: 0644]

index 54caa4d..9f717cc 100644 (file)
@@ -1,3 +1,23 @@
+2011-10-27  Adam Roben  <aroben@apple.com>
+
+        Add WKBundlePageGetBackingScaleFactor
+
+        Fixes <http://webkit.org/b/71025> <rdar://problem/10355037> REGRESSION (r97191): Clients
+        can't reliably determine the scale factor of snapshots returned via
+        WKBundlePageCreateSnapshot* API
+
+        Reviewed by Sam Weinig.
+
+        * WebProcess/InjectedBundle/API/c/WKBundlePage.cpp:
+        (WKBundlePageGetBackingScaleFactor):
+        * WebProcess/InjectedBundle/API/c/WKBundlePage.h:
+        Added. Calls through to WebPage::deviceScaleFactor.
+
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::deviceScaleFactor):
+        * WebProcess/WebPage/WebPage.h:
+        Added. Calls through to Page::deviceScaleFactor.
+
 2011-10-27  Zalan Bujtas  <zbujtas@gmail.com>
 
         [Qt][WK2]Add setViewportSize API to WebKit2.
index 98b8224..0a45b6e 100644 (file)
@@ -239,6 +239,11 @@ WKImageRef WKBundlePageCreateScaledSnapshotInDocumentCoordinates(WKBundlePageRef
     return toAPI(webImage.release().leakRef());
 }
 
+double WKBundlePageGetBackingScaleFactor(WKBundlePageRef pageRef)
+{
+    return toImpl(pageRef)->deviceScaleFactor();
+}
+
 #if defined(ENABLE_INSPECTOR) && ENABLE_INSPECTOR
 WKBundleInspectorRef WKBundlePageGetInspector(WKBundlePageRef pageRef)
 {
index 9eb0ab2..2a4d4d1 100644 (file)
@@ -339,6 +339,8 @@ WK_EXPORT WKImageRef WKBundlePageCreateSnapshotInViewCoordinates(WKBundlePageRef
 WK_EXPORT WKImageRef WKBundlePageCreateSnapshotInDocumentCoordinates(WKBundlePageRef page, WKRect rect, WKImageOptions options);
 WK_EXPORT WKImageRef WKBundlePageCreateScaledSnapshotInDocumentCoordinates(WKBundlePageRef page, WKRect rect, double scaleFactor, WKImageOptions options);
 
+WK_EXPORT double WKBundlePageGetBackingScaleFactor(WKBundlePageRef page);
+
 #if defined(ENABLE_INSPECTOR) && ENABLE_INSPECTOR
 WK_EXPORT WKBundleInspectorRef WKBundlePageGetInspector(WKBundlePageRef page);
 #endif
index 3df52d3..998de9f 100644 (file)
@@ -872,6 +872,11 @@ void WebPage::setDeviceScaleFactor(float scaleFactor)
 #endif
 }
 
+float WebPage::deviceScaleFactor() const
+{
+    return m_page->deviceScaleFactor();
+}
+
 void WebPage::setUseFixedLayout(bool fixed)
 {
     Frame* frame = m_mainFrame->coreFrame();
index 6a9af3d..1b1896b 100644 (file)
@@ -431,6 +431,7 @@ public:
     void runModal();
 
     void setDeviceScaleFactor(float);
+    float deviceScaleFactor() const;
 
     void setMemoryCacheMessagesEnabled(bool);
 
index 57c9c46..6a659af 100644 (file)
@@ -1,3 +1,31 @@
+2011-10-27  Adam Roben  <aroben@apple.com>
+
+        Test WKBundlePageGetBackingScaleFactor
+
+        Test for <http://webkit.org/b/71025> <rdar://problem/10355037> REGRESSION (r97191): Clients
+        can't reliably determine the scale factor of snapshots returned via
+        WKBundlePageCreateSnapshot* API
+
+        Reviewed by Sam Weinig.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: Added new files.
+
+        * TestWebKitAPI/Tests/WebKit2/mac/GetBackingScaleFactor.mm: Added.
+        (TestWebKitAPI::didReceiveMessageFromInjectedBundle): Record the passed-back scale factor.
+        (TestWebKitAPI::setInjectedBundleClient): Hook up our didReceiveMessage callback.
+        (TestWebKitAPI::createWindow): Conjure up a window.
+        (TestWebKitAPI::TEST): Ask the injected bundle code to call the new
+        WKBundlePageGetBackingScaleFactor API when the WKView is in windows with various scale
+        factors and when using a custom scale factor, and check that we get those same scale factors
+        back.
+
+        * TestWebKitAPI/Tests/WebKit2/mac/GetBackingScaleFactor_Bundle.mm: Added.
+        (TestWebKitAPI::GetBackingScaleFactorTest::GetBackingScaleFactorTest): Just initialize our
+        members.
+        (TestWebKitAPI::GetBackingScaleFactorTest::didCreatePage): Store the page for later.
+        (TestWebKitAPI::GetBackingScaleFactorTest::didReceiveMessage): Get the backing scale factor
+        from the page using the new API and send it back.
+
 2011-10-27  Balazs Kelemen  <kbalazs@webkit.org>
 
         [Qt][WK2] MiniBrowser crashes when started with 0 arguments
index d813363..bd25ad0 100644 (file)
@@ -90,6 +90,8 @@
                C0ADBE9612FCA79B00D2C129 /* simple-form.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C0ADBE8412FCA6B600D2C129 /* simple-form.html */; };
                C0BD669D131D3CF700E18F2A /* ResponsivenessTimerDoesntFireEarly.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C0BD669C131D3CF700E18F2A /* ResponsivenessTimerDoesntFireEarly.cpp */; };
                C0BD669F131D3CFF00E18F2A /* ResponsivenessTimerDoesntFireEarly_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C0BD669E131D3CFF00E18F2A /* ResponsivenessTimerDoesntFireEarly_Bundle.cpp */; };
+               C0C5D3BE14598B6F00A802A6 /* GetBackingScaleFactor.mm in Sources */ = {isa = PBXBuildFile; fileRef = C0C5D3BC14598B6F00A802A6 /* GetBackingScaleFactor.mm */; };
+               C0C5D3C61459912900A802A6 /* GetBackingScaleFactor_Bundle.mm in Sources */ = {isa = PBXBuildFile; fileRef = C0C5D3BD14598B6F00A802A6 /* GetBackingScaleFactor_Bundle.mm */; };
                F3FC3EE313678B7300126A65 /* libgtest.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F3FC3EE213678B7300126A65 /* libgtest.a */; };
                F6F3F29113342FEB00A6BF19 /* CookieManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F6F3F29013342FEB00A6BF19 /* CookieManager.cpp */; };
                F6FDDDD314241AD4004F1729 /* PrivateBrowsingPushStateNoHistoryCallback.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F6FDDDD214241AD4004F1729 /* PrivateBrowsingPushStateNoHistoryCallback.cpp */; };
                C0ADBE8412FCA6B600D2C129 /* simple-form.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "simple-form.html"; sourceTree = "<group>"; };
                C0BD669C131D3CF700E18F2A /* ResponsivenessTimerDoesntFireEarly.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ResponsivenessTimerDoesntFireEarly.cpp; sourceTree = "<group>"; };
                C0BD669E131D3CFF00E18F2A /* ResponsivenessTimerDoesntFireEarly_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ResponsivenessTimerDoesntFireEarly_Bundle.cpp; sourceTree = "<group>"; };
+               C0C5D3BC14598B6F00A802A6 /* GetBackingScaleFactor.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = GetBackingScaleFactor.mm; sourceTree = "<group>"; };
+               C0C5D3BD14598B6F00A802A6 /* GetBackingScaleFactor_Bundle.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = GetBackingScaleFactor_Bundle.mm; sourceTree = "<group>"; };
                F3FC3EE213678B7300126A65 /* libgtest.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libgtest.a; sourceTree = BUILT_PRODUCTS_DIR; };
                F6F3F29013342FEB00A6BF19 /* CookieManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CookieManager.cpp; sourceTree = "<group>"; };
                F6FDDDD214241AD4004F1729 /* PrivateBrowsingPushStateNoHistoryCallback.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PrivateBrowsingPushStateNoHistoryCallback.cpp; sourceTree = "<group>"; };
                BC9096411255616000083756 /* WebKit2 */ = {
                        isa = PBXGroup;
                        children = (
+                               C0C5D3BB14598B6F00A802A6 /* mac */,
                                BC90977B125571AE00083756 /* Resources */,
                                BC246D8C132F115A00B56D7C /* AboutBlankLoad.cpp */,
                                BC246D97132F1FE100B56D7C /* CanHandleRequest_Bundle.cpp */,
                        path = WTF/cf;
                        sourceTree = "<group>";
                };
+               C0C5D3BB14598B6F00A802A6 /* mac */ = {
+                       isa = PBXGroup;
+                       children = (
+                               C0C5D3BC14598B6F00A802A6 /* GetBackingScaleFactor.mm */,
+                               C0C5D3BD14598B6F00A802A6 /* GetBackingScaleFactor_Bundle.mm */,
+                       );
+                       path = mac;
+                       sourceTree = "<group>";
+               };
 /* End PBXGroup section */
 
 /* Begin PBXNativeTarget section */
                                52CB47411448FB9300873995 /* LoadAlternateHTMLStringWithNonDirectoryURL.cpp in Sources */,
                                BC3C4C7214575B6A0025FB62 /* WKBrowsingContextLoadDelegateTest.mm in Sources */,
                                BC3C4C7F14587AA60025FB62 /* WKBrowsingContextGroupTest.mm in Sources */,
+                               C0C5D3BE14598B6F00A802A6 /* GetBackingScaleFactor.mm in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                                1AEDE22613E5E7E700E62FE8 /* InjectedBundleControllerMac.mm in Sources */,
                                33DC89141419579F00747EF7 /* LoadCanceledNoServerRedirectCallback_Bundle.cpp in Sources */,
                                520BCF4C141EB09E00937EA8 /* WebArchive_Bundle.cpp in Sources */,
+                               C0C5D3C61459912900A802A6 /* GetBackingScaleFactor_Bundle.mm in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/mac/GetBackingScaleFactor.mm b/Tools/TestWebKitAPI/Tests/WebKit2/mac/GetBackingScaleFactor.mm
new file mode 100644 (file)
index 0000000..4afd72f
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+
+#import "PlatformUtilities.h"
+#import "SyntheticBackingScaleFactorWindow.h"
+#import "Test.h"
+#import <WebKit2/WKViewPrivate.h>
+#import <wtf/RetainPtr.h>
+
+namespace TestWebKitAPI {
+
+static bool messageReceived;
+static double backingScaleFactor;
+
+static void didReceiveMessageFromInjectedBundle(WKContextRef context, WKStringRef messageName, WKTypeRef messageBody, const void*)
+{
+    messageReceived = true;
+    EXPECT_WK_STREQ("DidGetBackingScaleFactor", messageName);
+    ASSERT_NOT_NULL(messageBody);
+    EXPECT_EQ(WKDoubleGetTypeID(), WKGetTypeID(messageBody));
+    backingScaleFactor = WKDoubleGetValue(static_cast<WKDoubleRef>(messageBody));
+}
+
+static void setInjectedBundleClient(WKContextRef context)
+{
+    WKContextInjectedBundleClient injectedBundleClient;
+    memset(&injectedBundleClient, 0, sizeof(injectedBundleClient));
+    injectedBundleClient.didReceiveMessageFromInjectedBundle = didReceiveMessageFromInjectedBundle;
+    WKContextSetInjectedBundleClient(context, &injectedBundleClient);
+}
+
+static RetainPtr<SyntheticBackingScaleFactorWindow> createWindow()
+{
+    RetainPtr<SyntheticBackingScaleFactorWindow> window(AdoptNS, [[SyntheticBackingScaleFactorWindow alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600) styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES]);
+    [window.get() setReleasedWhenClosed:NO];
+    return window;
+}
+
+TEST(WebKit2, GetBackingScaleFactor)
+{
+    WKRetainPtr<WKContextRef> context = adoptWK(Util::createContextForInjectedBundleTest("GetBackingScaleFactorTest"));
+    setInjectedBundleClient(context.get());
+    RetainPtr<WKView> view(AdoptNS, [[WKView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) contextRef:context.get() pageGroupRef:0]);
+
+    RetainPtr<SyntheticBackingScaleFactorWindow> window1 = createWindow();
+    [window1.get() setBackingScaleFactor:1];
+
+    [[window1.get() contentView] addSubview:view.get()];
+    WKContextPostMessageToInjectedBundle(context.get(), Util::toWK("GetBackingScaleFactor").get(), 0);
+    Util::run(&messageReceived);
+    messageReceived = false;
+    EXPECT_EQ(1, backingScaleFactor);
+
+    RetainPtr<SyntheticBackingScaleFactorWindow> window2 = createWindow();
+    [window2.get() setBackingScaleFactor:2];
+
+    [[window2.get() contentView] addSubview:view.get()];
+    WKContextPostMessageToInjectedBundle(context.get(), Util::toWK("GetBackingScaleFactor").get(), 0);
+    Util::run(&messageReceived);
+    messageReceived = false;
+    EXPECT_EQ(2, backingScaleFactor);
+
+    WKPageSetCustomBackingScaleFactor(view.get().pageRef, 3);
+    WKContextPostMessageToInjectedBundle(context.get(), Util::toWK("GetBackingScaleFactor").get(), 0);
+    Util::run(&messageReceived);
+    messageReceived = false;
+    EXPECT_EQ(3, backingScaleFactor);
+}
+
+} // namespace TestWebKitAPI
diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/mac/GetBackingScaleFactor_Bundle.mm b/Tools/TestWebKitAPI/Tests/WebKit2/mac/GetBackingScaleFactor_Bundle.mm
new file mode 100644 (file)
index 0000000..b8bceab
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+
+#import "InjectedBundleTest.h"
+#import "PlatformUtilities.h"
+#import <WebKit2/WKBundlePage.h>
+#import <assert.h>
+
+namespace TestWebKitAPI {
+
+class GetBackingScaleFactorTest : public InjectedBundleTest {
+public:
+    GetBackingScaleFactorTest(const std::string&);
+
+private:
+    virtual void didCreatePage(WKBundleRef, WKBundlePageRef);
+    virtual void didReceiveMessage(WKBundleRef, WKStringRef messageName, WKTypeRef messageBody);
+
+    WKBundlePageRef m_page;
+};
+
+static InjectedBundleTest::Register<GetBackingScaleFactorTest> registrar("GetBackingScaleFactorTest");
+
+GetBackingScaleFactorTest::GetBackingScaleFactorTest(const std::string& identifier)
+    : InjectedBundleTest(identifier)
+    , m_page(0)
+{
+}
+
+void GetBackingScaleFactorTest::didCreatePage(WKBundleRef, WKBundlePageRef page)
+{
+    assert(!m_page);
+    m_page = page;
+}
+
+void GetBackingScaleFactorTest::didReceiveMessage(WKBundleRef bundle, WKStringRef messageName, WKTypeRef messageBody)
+{
+    if (!WKStringIsEqualToUTF8CString(messageName, "GetBackingScaleFactor"))
+        return;
+
+    WKRetainPtr<WKDoubleRef> backingScaleFactor = adoptWK(WKDoubleCreate(WKBundlePageGetBackingScaleFactor(m_page)));
+    WKBundlePostMessage(bundle, Util::toWK("DidGetBackingScaleFactor").get(), backingScaleFactor.get());
+}
+
+} // namespace TestWebKitAPI