Title: [188255] trunk
Revision
188255
Author
[email protected]
Date
2015-08-11 09:14:15 -0700 (Tue, 11 Aug 2015)

Log Message

[Cocoa] The UI delegate can't tell if printing was user-initiated
https://bugs.webkit.org/show_bug.cgi?id=147869

Reviewed by Sam Weinig.

Source/WebKit2:

* UIProcess/API/APIUIClient.h:
(API::UIClient::printFrame): Added processingUserGesture argument.

* UIProcess/API/C/WKPage.cpp:
(WKPageSetPageUIClient): Updated for new client function signature.

* UIProcess/API/Cocoa/WKUIDelegatePrivate.h: Added userInitiated boolean argument to
  -_webView:printFrame:.

* UIProcess/Cocoa/UIDelegate.h: Added bool to m_delegateMethods for the new method.
* UIProcess/Cocoa/UIDelegate.mm:
(WebKit::UIDelegate::UIDelegate):
(WebKit::UIDelegate::setDelegate): Initialized new bool.
(WebKit::UIDelegate::UIClient::printFrame): Pass processingUserGesture as the delegate’s
  userInitiated argument.

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::printFrame): Added processingUserGesture argument, passing it along
  to the client.
* UIProcess/WebPageProxy.h:

* UIProcess/WebPageProxy.messages.in: Added processingUserGesture argument to printFrame.

* WebProcess/WebCoreSupport/WebChromeClient.cpp:
(WebKit::WebChromeClient::print): Pass new argument.

Tools:

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit2Cocoa/PrintFrame.mm: Added.
(-[PrintFrameController webView:didFinishNavigation:]):
(-[PrintFrameController _webView:printFrame:userInitiated:]):
(TEST):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (188254 => 188255)


--- trunk/Source/WebKit2/ChangeLog	2015-08-11 14:56:37 UTC (rev 188254)
+++ trunk/Source/WebKit2/ChangeLog	2015-08-11 16:14:15 UTC (rev 188255)
@@ -1,3 +1,36 @@
+2015-08-11  Dan Bernstein  <[email protected]>
+
+        [Cocoa] The UI delegate can't tell if printing was user-initiated
+        https://bugs.webkit.org/show_bug.cgi?id=147869
+
+        Reviewed by Sam Weinig.
+
+        * UIProcess/API/APIUIClient.h:
+        (API::UIClient::printFrame): Added processingUserGesture argument.
+
+        * UIProcess/API/C/WKPage.cpp:
+        (WKPageSetPageUIClient): Updated for new client function signature.
+
+        * UIProcess/API/Cocoa/WKUIDelegatePrivate.h: Added userInitiated boolean argument to
+          -_webView:printFrame:.
+
+        * UIProcess/Cocoa/UIDelegate.h: Added bool to m_delegateMethods for the new method.
+        * UIProcess/Cocoa/UIDelegate.mm:
+        (WebKit::UIDelegate::UIDelegate):
+        (WebKit::UIDelegate::setDelegate): Initialized new bool.
+        (WebKit::UIDelegate::UIClient::printFrame): Pass processingUserGesture as the delegate’s
+          userInitiated argument.
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::printFrame): Added processingUserGesture argument, passing it along
+          to the client.
+        * UIProcess/WebPageProxy.h:
+
+        * UIProcess/WebPageProxy.messages.in: Added processingUserGesture argument to printFrame.
+
+        * WebProcess/WebCoreSupport/WebChromeClient.cpp:
+        (WebKit::WebChromeClient::print): Pass new argument.
+
 2015-08-10  Matthew Daiter  <[email protected]>
 
         Add MediaDeviceIdentifier to WebsiteDataTypes

Modified: trunk/Source/WebKit2/UIProcess/API/APIUIClient.h (188254 => 188255)


--- trunk/Source/WebKit2/UIProcess/API/APIUIClient.h	2015-08-11 14:56:37 UTC (rev 188254)
+++ trunk/Source/WebKit2/UIProcess/API/APIUIClient.h	2015-08-11 16:14:15 UTC (rev 188255)
@@ -139,7 +139,7 @@
     virtual float footerHeight(WebKit::WebPageProxy*, WebKit::WebFrameProxy*) { return 0; }
     virtual void drawHeader(WebKit::WebPageProxy*, WebKit::WebFrameProxy*, const WebCore::FloatRect&) { }
     virtual void drawFooter(WebKit::WebPageProxy*, WebKit::WebFrameProxy*, const WebCore::FloatRect&) { }
-    virtual void printFrame(WebKit::WebPageProxy*, WebKit::WebFrameProxy*) { }
+    virtual void printFrame(WebKit::WebPageProxy*, WebKit::WebFrameProxy*, bool processingUserGesture) { }
 
     virtual bool canRunModal() const { return false; }
     virtual void runModal(WebKit::WebPageProxy*) { }

Modified: trunk/Source/WebKit2/UIProcess/API/C/WKPage.cpp (188254 => 188255)


--- trunk/Source/WebKit2/UIProcess/API/C/WKPage.cpp	2015-08-11 14:56:37 UTC (rev 188254)
+++ trunk/Source/WebKit2/UIProcess/API/C/WKPage.cpp	2015-08-11 16:14:15 UTC (rev 188255)
@@ -1730,7 +1730,7 @@
             m_client.drawFooter(toAPI(page), toAPI(frame), toAPI(rect), m_client.base.clientInfo);
         }
 
-        virtual void printFrame(WebPageProxy* page, WebFrameProxy* frame) override
+        virtual void printFrame(WebPageProxy* page, WebFrameProxy* frame, bool) override
         {
             if (!m_client.printFrame)
                 return;

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKUIDelegatePrivate.h (188254 => 188255)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKUIDelegatePrivate.h	2015-08-11 14:56:37 UTC (rev 188254)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKUIDelegatePrivate.h	2015-08-11 16:14:15 UTC (rev 188255)
@@ -48,7 +48,7 @@
 // FIXME: This should be handled by the WKWebsiteDataStore delegate.
 - (void)_webView:(WKWebView *)webView decideWebApplicationCacheQuotaForSecurityOrigin:(WKSecurityOrigin *)securityOrigin currentQuota:(unsigned long long)currentQuota totalBytesNeeded:(unsigned long long)totalBytesNeeded decisionHandler:(void (^)(unsigned long long newQuota))decisionHandler;
 
-- (void)_webView:(WKWebView *)webView printFrame:(_WKFrameHandle *)frame;
+- (void)_webView:(WKWebView *)webView printFrame:(_WKFrameHandle *)frame userInitiated:(BOOL)userInitiated WK_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA);
 
 - (void)_webViewClose:(WKWebView *)webView;
 - (void)_webViewFullscreenMayReturnToInline:(WKWebView *)webView;

Modified: trunk/Source/WebKit2/UIProcess/Cocoa/UIDelegate.h (188254 => 188255)


--- trunk/Source/WebKit2/UIProcess/Cocoa/UIDelegate.h	2015-08-11 14:56:37 UTC (rev 188254)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/UIDelegate.h	2015-08-11 16:14:15 UTC (rev 188255)
@@ -68,7 +68,7 @@
         virtual void runJavaScriptPrompt(WebKit::WebPageProxy*, const WTF::String&, const WTF::String&, WebKit::WebFrameProxy*, const WebKit::SecurityOriginData&, std::function<void (const WTF::String&)> completionHandler) override;
         virtual void exceededDatabaseQuota(WebPageProxy*, WebFrameProxy*, API::SecurityOrigin*, const WTF::String& databaseName, const WTF::String& displayName, unsigned long long currentQuota, unsigned long long currentOriginUsage, unsigned long long currentUsage, unsigned long long expectedUsage, std::function<void (unsigned long long)>) override;
         virtual void reachedApplicationCacheOriginQuota(WebPageProxy*, const WebCore::SecurityOrigin&, uint64_t currentQuota, uint64_t totalBytesNeeded, std::function<void (unsigned long long)> completionHandler) override;
-        virtual void printFrame(WebKit::WebPageProxy*, WebKit::WebFrameProxy*) override;
+        virtual void printFrame(WebKit::WebPageProxy*, WebKit::WebFrameProxy*, bool processingUserGesture) override;
 #if PLATFORM(IOS)
 #if HAVE(APP_LINKS)
         virtual bool shouldIncludeAppLinkActionsForElement(_WKActivatedElementInfo *) override;
@@ -94,6 +94,7 @@
         bool webViewDecideDatabaseQuotaForSecurityOriginCurrentQuotaCurrentOriginUsageCurrentDatabaseUsageExpectedUsageDecisionHandler : 1;
         bool webViewDecideWebApplicationCacheQuotaForSecurityOriginCurrentQuotaTotalBytesNeeded : 1;
         bool webViewPrintFrame : 1;
+        bool webViewPrintFrameUserInitiated : 1;
         bool webViewDidClose : 1;
         bool webViewClose : 1;
         bool webViewFullscreenMayReturnToInline : 1;

Modified: trunk/Source/WebKit2/UIProcess/Cocoa/UIDelegate.mm (188254 => 188255)


--- trunk/Source/WebKit2/UIProcess/Cocoa/UIDelegate.mm	2015-08-11 14:56:37 UTC (rev 188254)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/UIDelegate.mm	2015-08-11 16:14:15 UTC (rev 188255)
@@ -41,6 +41,11 @@
 #import "_WKFrameHandleInternal.h"
 #import <WebCore/URL.h>
 
+@protocol WKUIDelegatePrivateDeprecated <WKUIDelegatePrivate>
+@optional
+- (void)_webView:(WKWebView *)webView printFrame:(_WKFrameHandle *)frame;
+@end
+
 namespace WebKit {
 
 UIDelegate::UIDelegate(WKWebView *webView)
@@ -73,6 +78,7 @@
     m_delegateMethods.webViewDecideDatabaseQuotaForSecurityOriginCurrentQuotaCurrentOriginUsageCurrentDatabaseUsageExpectedUsageDecisionHandler = [delegate respondsToSelector:@selector(_webView:decideDatabaseQuotaForSecurityOrigin:currentQuota:currentOriginUsage:currentDatabaseUsage:expectedUsage:decisionHandler:)];
     m_delegateMethods.webViewDecideWebApplicationCacheQuotaForSecurityOriginCurrentQuotaTotalBytesNeeded = [delegate respondsToSelector:@selector(_webView:decideWebApplicationCacheQuotaForSecurityOrigin:currentQuota:totalBytesNeeded:decisionHandler:)];
     m_delegateMethods.webViewPrintFrame = [delegate respondsToSelector:@selector(_webView:printFrame:)];
+    m_delegateMethods.webViewPrintFrameUserInitiated = [delegate respondsToSelector:@selector(_webView:printFrame:userInitiated:)];
     m_delegateMethods.webViewDidClose = [delegate respondsToSelector:@selector(webViewDidClose:)];
     m_delegateMethods.webViewClose = [delegate respondsToSelector:@selector(_webViewClose:)];
     m_delegateMethods.webViewFullscreenMayReturnToInline = [delegate respondsToSelector:@selector(_webViewFullscreenMayReturnToInline:)];
@@ -230,18 +236,21 @@
     }];
 }
 
-void UIDelegate::UIClient::printFrame(WebKit::WebPageProxy*, WebKit::WebFrameProxy* webFrameProxy)
+void UIDelegate::UIClient::printFrame(WebKit::WebPageProxy*, WebKit::WebFrameProxy* webFrameProxy, bool processingUserGesture)
 {
     ASSERT_ARG(webFrameProxy, webFrameProxy);
 
-    if (!m_uiDelegate.m_delegateMethods.webViewPrintFrame)
+    if (!m_uiDelegate.m_delegateMethods.webViewPrintFrame  && !m_uiDelegate.m_delegateMethods.webViewPrintFrameUserInitiated)
         return;
 
     auto delegate = m_uiDelegate.m_delegate.get();
     if (!delegate)
         return;
 
-    [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView printFrame:wrapper(API::FrameHandle::create(webFrameProxy->frameID()))];
+    if (m_uiDelegate.m_delegateMethods.webViewPrintFrameUserInitiated)
+        [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView printFrame:wrapper(API::FrameHandle::create(webFrameProxy->frameID())) userInitiated:processingUserGesture];
+    else
+        [(id <WKUIDelegatePrivateDeprecated>)delegate _webView:m_uiDelegate.m_webView printFrame:wrapper(API::FrameHandle::create(webFrameProxy->frameID()))];
 }
 
 void UIDelegate::UIClient::close(WebKit::WebPageProxy*)

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (188254 => 188255)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp	2015-08-11 14:56:37 UTC (rev 188254)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp	2015-08-11 16:14:15 UTC (rev 188255)
@@ -3836,7 +3836,7 @@
     }
 }
 
-void WebPageProxy::printFrame(uint64_t frameID)
+void WebPageProxy::printFrame(uint64_t frameID, bool processingUserGesture)
 {
     ASSERT(!m_isPerformingDOMPrintOperation);
     m_isPerformingDOMPrintOperation = true;
@@ -3844,17 +3844,12 @@
     WebFrameProxy* frame = m_process->webFrame(frameID);
     MESSAGE_CHECK(frame);
 
-    m_uiClient->printFrame(this, frame);
+    m_uiClient->printFrame(this, frame, processingUserGesture);
 
     endPrinting(); // Send a message synchronously while m_isPerformingDOMPrintOperation is still true.
     m_isPerformingDOMPrintOperation = false;
 }
 
-void WebPageProxy::printMainFrame()
-{
-    printFrame(m_mainFrame->frameID());
-}
-
 void WebPageProxy::setMediaVolume(float volume)
 {
     if (volume == m_mediaVolume)

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (188254 => 188255)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2015-08-11 14:56:37 UTC (rev 188254)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2015-08-11 16:14:15 UTC (rev 188255)
@@ -913,8 +913,6 @@
 
     void setShouldSendEventsSynchronously(bool sync) { m_shouldSendEventsSynchronously = sync; };
 
-    void printMainFrame();
-    
     void setMediaVolume(float);
     void setMuted(bool);
     void setMayStartMediaWhenInWindow(bool);
@@ -1180,7 +1178,7 @@
     void didChangeViewportProperties(const WebCore::ViewportAttributes&);
     void pageDidScroll();
     void runOpenPanel(uint64_t frameID, const WebCore::FileChooserSettings&);
-    void printFrame(uint64_t frameID);
+    void printFrame(uint64_t frameID, bool processingUserGesture);
     void exceededDatabaseQuota(uint64_t frameID, const String& originIdentifier, const String& databaseName, const String& displayName, uint64_t currentQuota, uint64_t currentOriginUsage, uint64_t currentDatabaseUsage, uint64_t expectedUsage, PassRefPtr<Messages::WebPageProxy::ExceededDatabaseQuota::DelayedReply>);
     void reachedApplicationCacheOriginQuota(const String& originIdentifier, uint64_t currentQuota, uint64_t totalBytesNeeded, PassRefPtr<Messages::WebPageProxy::ReachedApplicationCacheOriginQuota::DelayedReply>);
     void requestGeolocationPermissionForFrame(uint64_t geolocationID, uint64_t frameID, String originIdentifier);

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in (188254 => 188255)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in	2015-08-11 14:56:37 UTC (rev 188254)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in	2015-08-11 16:14:15 UTC (rev 188255)
@@ -76,7 +76,7 @@
     RunBeforeUnloadConfirmPanel(String message, uint64_t frameID) -> (bool shouldClose)
     PageDidScroll()
     RunOpenPanel(uint64_t frameID, struct WebCore::FileChooserSettings parameters)
-    PrintFrame(uint64_t frameID) -> ()
+    PrintFrame(uint64_t frameID, bool processingUserGesture) -> ()
     RunModal()
     NotifyScrollerThumbIsVisibleInRect(WebCore::IntRect scrollerThumb)
     RecommendedScrollbarStyleDidChange(int32_t newStyle)

Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp (188254 => 188255)


--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp	2015-08-11 14:56:37 UTC (rev 188254)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp	2015-08-11 16:14:15 UTC (rev 188255)
@@ -680,7 +680,7 @@
     if (WebPage::synchronousMessagesShouldSpinRunLoop())
         syncSendFlags |= IPC::SpinRunLoopWhileWaitingForReply;
     
-    m_page->sendSync(Messages::WebPageProxy::PrintFrame(webFrame->frameID()), Messages::WebPageProxy::PrintFrame::Reply(), std::chrono::milliseconds::max(), syncSendFlags);
+    m_page->sendSync(Messages::WebPageProxy::PrintFrame(webFrame->frameID(), ScriptController::processingUserGesture()), Messages::WebPageProxy::PrintFrame::Reply(), std::chrono::milliseconds::max(), syncSendFlags);
 }
 
 void WebChromeClient::exceededDatabaseQuota(Frame* frame, const String& databaseName, DatabaseDetails details)

Modified: trunk/Tools/ChangeLog (188254 => 188255)


--- trunk/Tools/ChangeLog	2015-08-11 14:56:37 UTC (rev 188254)
+++ trunk/Tools/ChangeLog	2015-08-11 16:14:15 UTC (rev 188255)
@@ -1,3 +1,16 @@
+2015-08-11  Dan Bernstein  <[email protected]>
+
+        [Cocoa] The UI delegate can't tell if printing was user-initiated
+        https://bugs.webkit.org/show_bug.cgi?id=147869
+
+        Reviewed by Sam Weinig.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKit2Cocoa/PrintFrame.mm: Added.
+        (-[PrintFrameController webView:didFinishNavigation:]):
+        (-[PrintFrameController _webView:printFrame:userInitiated:]):
+        (TEST):
+
 2015-08-10  Alex Christensen  <[email protected]>
 
         Another build fix after r188239.

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (188254 => 188255)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2015-08-11 14:56:37 UTC (rev 188254)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2015-08-11 16:14:15 UTC (rev 188255)
@@ -39,6 +39,7 @@
 		33DC8912141955FE00747EF7 /* simple-iframe.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 33DC890E1419539300747EF7 /* simple-iframe.html */; };
 		33DC89141419579F00747EF7 /* LoadCanceledNoServerRedirectCallback_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 33DC89131419579F00747EF7 /* LoadCanceledNoServerRedirectCallback_Bundle.cpp */; };
 		33E79E06137B5FD900E32D99 /* mouse-move-listener.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 33E79E05137B5FCE00E32D99 /* mouse-move-listener.html */; };
+		376481801B79CD8D00D24B97 /* PrintFrame.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3764817D1B79CD7D00D24B97 /* PrintFrame.mm */; settings = {ASSET_TAGS = (); }; };
 		378E64771632655E00B6C676 /* InjectedBundleFrameHitTest_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 378E64751632655D00B6C676 /* InjectedBundleFrameHitTest_Bundle.cpp */; };
 		378E64791632707400B6C676 /* link-with-title.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 378E647816326FDF00B6C676 /* link-with-title.html */; };
 		379028B914FAC24C007E6B43 /* acceptsFirstMouse.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 379028B814FABE49007E6B43 /* acceptsFirstMouse.html */; };
@@ -496,6 +497,7 @@
 		33E79E05137B5FCE00E32D99 /* mouse-move-listener.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "mouse-move-listener.html"; sourceTree = "<group>"; };
 		3722C8681461E03E00C45D00 /* RenderedImageFromDOMRange.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RenderedImageFromDOMRange.mm; sourceTree = "<group>"; };
 		3751AF7A169518F800764319 /* DOMNodeFromJSObject.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DOMNodeFromJSObject.mm; sourceTree = "<group>"; };
+		3764817D1B79CD7D00D24B97 /* PrintFrame.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PrintFrame.mm; sourceTree = "<group>"; };
 		3776BC62150946BC0043A66D /* DeviceScaleFactorInDashboardRegions.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DeviceScaleFactorInDashboardRegions.mm; sourceTree = "<group>"; };
 		378E64711632646D00B6C676 /* InjectedBundleFrameHitTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InjectedBundleFrameHitTest.cpp; sourceTree = "<group>"; };
 		378E64751632655D00B6C676 /* InjectedBundleFrameHitTest_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InjectedBundleFrameHitTest_Bundle.cpp; sourceTree = "<group>"; };
@@ -866,6 +868,7 @@
 				1ABC3DED1899BE6D004F0626 /* Navigation.mm */,
 				CEA6CF2219CCF5BD0064F5A7 /* OpenAndCloseWindow.mm */,
 				C95501BE19AD2FAF0049BE3E /* Preferences.mm */,
+				3764817D1B79CD7D00D24B97 /* PrintFrame.mm */,
 				37D36F311B004DD400BAF5D9 /* ProvisionalURLChange.mm */,
 				37BCA61B1B596BA9002012CA /* ShouldOpenExternalURLsInNewWindowActions.mm */,
 				2D9A53AE1B31FA8D0074D5AA /* ShrinkToFit.mm */,
@@ -1561,6 +1564,7 @@
 				7CCE7F0B1A411AE600447C4C /* PreventEmptyUserAgent.cpp in Sources */,
 				7CCE7F2C1A411B1000447C4C /* PreventImageLoadWithAutoResizing.mm in Sources */,
 				7CCE7F0C1A411AE600447C4C /* PrivateBrowsingPushStateNoHistoryCallback.cpp in Sources */,
+				376481801B79CD8D00D24B97 /* PrintFrame.mm in Sources */,
 				7CCE7EC81A411A7E00447C4C /* PublicSuffix.mm in Sources */,
 				7CCE7F3E1A411B8E00447C4C /* RedBlackTree.cpp in Sources */,
 				7CCE7F3F1A411B8E00447C4C /* Ref.cpp in Sources */,

Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/PrintFrame.mm (0 => 188255)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/PrintFrame.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/PrintFrame.mm	2015-08-11 16:14:15 UTC (rev 188255)
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2015 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"
+
+#if PLATFORM(MAC)
+
+#import "PlatformUtilities.h"
+#import <WebKit/WKUIDelegatePrivate.h>
+#import <WebKit/WKWebView.h>
+#import <wtf/RetainPtr.h>
+
+#if WK_API_ENABLED
+
+static bool isDone;
+static bool isUserInitiated;
+
+@interface PrintFrameController : NSObject <WKNavigationDelegate, WKUIDelegate>
+@end
+
+@implementation PrintFrameController
+
+- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
+{
+    isDone = true;
+}
+
+- (void)_webView:(WKWebView *)webView printFrame:(_WKFrameHandle *)frame userInitiated:(BOOL)userInitiated
+{
+    isUserInitiated = userInitiated;
+    isDone = true;
+}
+
+@end
+
+TEST(WebKit2, PrintFrame)
+{
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+
+    auto window = adoptNS([[NSWindow alloc] initWithContentRect:[webView frame] styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES]);
+    [[window contentView] addSubview:webView.get()];
+
+    auto controller = adoptNS([[PrintFrameController alloc] init]);
+    [webView setNavigationDelegate:controller.get()];
+    [webView setUIDelegate:controller.get()];
+
+    [webView loadHTMLString:@"<body _onclick_=\"print()\">" baseURL:nil];
+    TestWebKitAPI::Util::run(&isDone);
+    isDone = false;
+
+    NSPoint clickPoint = NSMakePoint(100, 100);
+
+    [[webView hitTest:clickPoint] mouseDown:[NSEvent mouseEventWithType:NSLeftMouseDown location:clickPoint modifierFlags:0 timestamp:0 windowNumber:[window windowNumber] context:nil eventNumber:0 clickCount:1 pressure:1]];
+    [[webView hitTest:clickPoint] mouseUp:[NSEvent mouseEventWithType:NSLeftMouseUp location:clickPoint modifierFlags:0 timestamp:0 windowNumber:[window windowNumber] context:nil eventNumber:0 clickCount:1 pressure:1]];
+    TestWebKitAPI::Util::run(&isDone);
+    isDone = false;
+
+    ASSERT_TRUE(isUserInitiated);
+
+    [webView evaluateJavaScript:@"print()" completionHandler:nil];
+
+    TestWebKitAPI::Util::run(&isDone);
+    isDone = false;
+
+    ASSERT_FALSE(isUserInitiated);
+}
+
+#endif
+
+#endif
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to