In WebCore::ResourceLoadObserver, use document.sessionID().isEphemeral() when possibl...
authorwilander@apple.com <wilander@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 2 Nov 2018 00:51:12 +0000 (00:51 +0000)
committerwilander@apple.com <wilander@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 2 Nov 2018 00:51:12 +0000 (00:51 +0000)
https://bugs.webkit.org/show_bug.cgi?id=191119
<rdar://problem/44176965>

Reviewed by Chris Dumez.

Source/WebCore:

New API test added.

* loader/ResourceLoadObserver.cpp:
(WebCore::ResourceLoadObserver::logSubresourceLoading):
(WebCore::ResourceLoadObserver::logUserInteractionWithReducedTimeResolution):

Tools:

This is an API test for a WebKitLegacy WebView that is first closed and then
JavaScript is handed a keyboard event.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKitLegacy/mac/ClosingWebView.mm: Added.
(-[ClosingWebViewThenSendingItAKeyDownEventLoadDelegate webView:didFinishLoadForFrame:]):
(-[KeyboardEventListener handleEvent:]):
(TestWebKitAPI::TEST):

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

Source/WebCore/ChangeLog
Source/WebCore/loader/ResourceLoadObserver.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKitLegacy/mac/ClosingWebView.mm [new file with mode: 0644]

index c389aaf..0ad714c 100644 (file)
@@ -1,3 +1,17 @@
+2018-11-01  John Wilander  <wilander@apple.com>
+
+        In WebCore::ResourceLoadObserver, use document.sessionID().isEphemeral() when possible and check for page existence when not
+        https://bugs.webkit.org/show_bug.cgi?id=191119
+        <rdar://problem/44176965>
+
+        Reviewed by Chris Dumez.
+
+        New API test added.
+
+        * loader/ResourceLoadObserver.cpp:
+        (WebCore::ResourceLoadObserver::logSubresourceLoading):
+        (WebCore::ResourceLoadObserver::logUserInteractionWithReducedTimeResolution):
+
 2018-11-01  Devin Rousso  <drousso@apple.com>
 
         Web Inspector: Network: remove unnecessary media event tracking
index a73fcfa..95d6595 100644 (file)
@@ -88,8 +88,11 @@ void ResourceLoadObserver::logSubresourceLoading(const Frame* frame, const Resou
 {
     ASSERT(frame->page());
 
+    if (!frame)
+        return;
+
     auto* page = frame->page();
-    if (!shouldLog(page->usesEphemeralSession()))
+    if (!page || !shouldLog(page->usesEphemeralSession()))
         return;
 
     bool isRedirect = is3xxRedirect(redirectResponse);
@@ -157,9 +160,7 @@ void ResourceLoadObserver::logWebSocketLoading(const URL& targetURL, const URL&
 
 void ResourceLoadObserver::logUserInteractionWithReducedTimeResolution(const Document& document)
 {
-    ASSERT(document.page());
-
-    if (!shouldLog(document.page()->usesEphemeralSession()))
+    if (!shouldLog(document.sessionID().isEphemeral()))
         return;
 
     auto& url = document.url();
index ba23204..8ae775f 100644 (file)
@@ -1,3 +1,20 @@
+2018-11-01  John Wilander  <wilander@apple.com>
+
+        In WebCore::ResourceLoadObserver, use document.sessionID().isEphemeral() when possible and check for page existence when not
+        https://bugs.webkit.org/show_bug.cgi?id=191119
+        <rdar://problem/44176965>
+
+        Reviewed by Chris Dumez.
+
+        This is an API test for a WebKitLegacy WebView that is first closed and then
+        JavaScript is handed a keyboard event.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKitLegacy/mac/ClosingWebView.mm: Added.
+        (-[ClosingWebViewThenSendingItAKeyDownEventLoadDelegate webView:didFinishLoadForFrame:]):
+        (-[KeyboardEventListener handleEvent:]):
+        (TestWebKitAPI::TEST):
+
 2018-11-01  Sihui Liu  <sihui_liu@apple.com>
 
         Add a storage limit for IndexedDB
index d5f9b77..2190f57 100644 (file)
                636353A71E98665D0009F8AF /* GeolocationGetCurrentPositionResult.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 636353A61E9861940009F8AF /* GeolocationGetCurrentPositionResult.html */; };
                63A61B8B1FAD251100F06885 /* display-mode.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 63A61B8A1FAD204D00F06885 /* display-mode.html */; };
                63F668221F97F7F90032EE51 /* ApplicationManifest.mm in Sources */ = {isa = PBXBuildFile; fileRef = 63F668201F97C3AA0032EE51 /* ApplicationManifest.mm */; };
+               6B306106218A372900F5A802 /* ClosingWebView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 6B306105218A372900F5A802 /* ClosingWebView.mm */; };
                6B9ABE122086952F00D75DE6 /* HTTPParsers.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B9ABE112086952F00D75DE6 /* HTTPParsers.cpp */; };
                6BFD294C1D5E6C1D008EC968 /* HashCountedSet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7A38D7E51C752D5F004F157D /* HashCountedSet.cpp */; };
                751B05D61F8EAC410028A09E /* DatabaseTrackerTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = 751B05D51F8EAC1A0028A09E /* DatabaseTrackerTest.mm */; };
                636353A61E9861940009F8AF /* GeolocationGetCurrentPositionResult.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = GeolocationGetCurrentPositionResult.html; sourceTree = "<group>"; };
                63A61B8A1FAD204D00F06885 /* display-mode.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "display-mode.html"; sourceTree = "<group>"; };
                63F668201F97C3AA0032EE51 /* ApplicationManifest.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = ApplicationManifest.mm; sourceTree = "<group>"; };
+               6B306105218A372900F5A802 /* ClosingWebView.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = ClosingWebView.mm; sourceTree = "<group>"; };
                6B9ABE112086952F00D75DE6 /* HTTPParsers.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = HTTPParsers.cpp; sourceTree = "<group>"; };
                751B05D51F8EAC1A0028A09E /* DatabaseTrackerTest.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = DatabaseTrackerTest.mm; sourceTree = "<group>"; };
                754CEC801F6722DC00D0039A /* AutoFillAvailable.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = AutoFillAvailable.mm; sourceTree = "<group>"; };
                        isa = PBXGroup;
                        children = (
                                9BD5111B1FE8E11600D2B630 /* AccessingPastedImage.mm */,
+                               6B306105218A372900F5A802 /* ClosingWebView.mm */,
                        );
                        path = mac;
                        sourceTree = "<group>";
                                7CCE7EE51A411AE600447C4C /* CloseThenTerminate.cpp in Sources */,
                                CDF92237216D186400647AA7 /* CloseWebViewAfterEnterFullscreen.mm in Sources */,
                                CDF0B78A216D48DC00421ECC /* CloseWebViewDuringEnterFullscreen.mm in Sources */,
+                               6B306106218A372900F5A802 /* ClosingWebView.mm in Sources */,
                                7C83E0BA1D0A64FB00FEBCF3 /* Coding.mm in Sources */,
                                7C3965061CDD74F90094DBB8 /* Color.cpp in Sources */,
                                7C3DB8E41D12129B00AE8CC3 /* CommandBackForward.mm in Sources */,
diff --git a/Tools/TestWebKitAPI/Tests/WebKitLegacy/mac/ClosingWebView.mm b/Tools/TestWebKitAPI/Tests/WebKitLegacy/mac/ClosingWebView.mm
new file mode 100644 (file)
index 0000000..4b3d35e
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2018 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 "WTFStringUtilities.h"
+
+#import <Carbon/Carbon.h>
+#import <JavaScriptCore/JSContext.h>
+#import <JavaScriptCore/JSExport.h>
+#import <WebKit/WebHTMLView.h>
+#import <WebKit/WebViewPrivate.h>
+#import <wtf/RetainPtr.h>
+
+#if JSC_OBJC_API_ENABLED
+
+static bool didFinishLoad = false;
+static RetainPtr<WebView> webView;
+
+@interface ClosingWebViewThenSendingItAKeyDownEventLoadDelegate : NSObject <WebFrameLoadDelegate>
+@end
+
+@implementation ClosingWebViewThenSendingItAKeyDownEventLoadDelegate
+- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
+{
+    didFinishLoad = true;
+}
+@end
+
+@interface KeyboardEventListener : NSObject <DOMEventListener>
+@end
+
+@implementation KeyboardEventListener
+- (void)handleEvent:(DOMEvent *)event
+{
+    if ([event isKindOfClass:[DOMKeyboardEvent class]])
+        [webView _close];
+}
+@end
+
+namespace TestWebKitAPI {
+
+TEST(WebKitLegacy, ClosingWebViewThenSendingItAKeyDownEvent)
+{
+    webView = adoptNS([[WebView alloc] initWithFrame:NSMakeRect(0, 0, 400, 400) frameName:nil groupName:nil]);
+    auto* webHTMLView = (WebHTMLView *)[[[webView mainFrame] frameView] documentView];
+    
+    EXPECT_TRUE([webView respondsToSelector:@selector(_close)]);
+    EXPECT_TRUE([webHTMLView respondsToSelector:@selector(keyDown:)]);
+    EXPECT_TRUE([webHTMLView respondsToSelector:@selector(keyUp:)]);
+
+    auto loadDelegate = adoptNS([[ClosingWebViewThenSendingItAKeyDownEventLoadDelegate alloc] init]);
+    webView.get().frameLoadDelegate = loadDelegate.get();
+    
+    [[webView mainFrame] loadHTMLString:@"<html><body contenteditable><script>function addKeyPressHandler() { document.body.addEventListener('keypress', function(event) { event.preventDefault(); }, true) }; document.body.focus();</script></body></html>" baseURL:nil];
+
+    Util::run(&didFinishLoad);
+
+    // First, add a native event listener that closes the WebView.
+    [[[webView mainFrameDocument] body] addEventListener:@"keypress" listener:[[KeyboardEventListener alloc] init] useCapture:NO];
+
+    // Second, add a JavaScript event handler that consumes the event.
+    [[[webView mainFrame] javaScriptContext] evaluateScript:@"addKeyPressHandler()"];
+
+    // Finally, fire an event that triggers both handlers. This should not crash.
+    NSEvent *spaceBarDown = [NSEvent keyEventWithType:NSEventTypeKeyDown
+                                             location:NSMakePoint(5, 5)
+                                        modifierFlags:0
+                                            timestamp:GetCurrentEventTime()
+                                         windowNumber:[[webView window] windowNumber]
+                                              context:[NSGraphicsContext currentContext]
+                                           characters:@" "
+                          charactersIgnoringModifiers:@" "
+                                            isARepeat:NO
+                                              keyCode:0x31];
+    [webHTMLView keyDown:spaceBarDown];
+}
+
+} // namespace TestWebKitAPI
+
+#endif // ENABLE(JSC_OBJC_API)