Title: [272654] trunk
Revision
272654
Author
bfulg...@apple.com
Date
2021-02-10 07:58:57 -0800 (Wed, 10 Feb 2021)

Log Message

Create stub methods to support finer-grained control over loading
https://bugs.webkit.org/show_bug.cgi?id=221430
<rdar://problem/73999547>

Reviewed by Geoffrey Garen.

Source/WebKit:

Create three new WebKit Cocoa methods that accept NSURLRequest, rather than URL. This allows
us to pass additional hints to the networking subsystem.

Tested with new API Tests.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView loadSimulatedRequest:withResponse:responseData:]):
(-[WKWebView loadSimulatedRequest:withResponseHTMLString:]):
(-[WKWebView loadFileRequest:allowingReadAccessToURL:]):
* UIProcess/API/Cocoa/WKWebViewPrivate.h:

Tools:

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKitCocoa/WKWebViewLoadAPIs.mm: Added.
(TEST):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (272653 => 272654)


--- trunk/Source/WebKit/ChangeLog	2021-02-10 15:46:06 UTC (rev 272653)
+++ trunk/Source/WebKit/ChangeLog	2021-02-10 15:58:57 UTC (rev 272654)
@@ -1,3 +1,22 @@
+2021-02-10  Brent Fulgham  <bfulg...@apple.com>
+
+        Create stub methods to support finer-grained control over loading
+        https://bugs.webkit.org/show_bug.cgi?id=221430
+        <rdar://problem/73999547>
+
+        Reviewed by Geoffrey Garen.
+
+        Create three new WebKit Cocoa methods that accept NSURLRequest, rather than URL. This allows
+        us to pass additional hints to the networking subsystem.
+
+        Tested with new API Tests.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView loadSimulatedRequest:withResponse:responseData:]):
+        (-[WKWebView loadSimulatedRequest:withResponseHTMLString:]):
+        (-[WKWebView loadFileRequest:allowingReadAccessToURL:]):
+        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+
 2021-02-10  Sam Weinig  <wei...@apple.com>
 
         Workaround some order dependent issues by parenting remote layers before applying other properties

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm (272653 => 272654)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm	2021-02-10 15:46:06 UTC (rev 272653)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm	2021-02-10 15:58:57 UTC (rev 272654)
@@ -2086,6 +2086,32 @@
     return wrapper(_page->loadRequest(request, policy));
 }
 
+- (WKNavigation *)loadSimulatedRequest:(NSURLRequest *)request withResponse:(NSURLResponse *)response responseData:(NSData *)data
+{
+    return wrapper(_page->loadData({ static_cast<const uint8_t*>(data.bytes), data.length }, response.MIMEType, response.textEncodingName, request.URL.absoluteString));
+}
+
+- (WKNavigation *)loadSimulatedRequest:(NSURLRequest *)request withResponseHTMLString:(NSString *)string
+{
+    NSData *data = "" dataUsingEncoding:NSUTF8StringEncoding];
+    NSURLResponse *response = [[NSURLResponse alloc] initWithURL:request.URL MIMEType:@"text/html" expectedContentLength:string.length textEncodingName:@"UTF-8"];
+
+    return [self loadSimulatedRequest:request withResponse:response responseData:data];
+}
+
+- (WKNavigation *)loadFileRequest:(NSURLRequest *)request allowingReadAccessToURL:(NSURL *)readAccessURL
+{
+    auto URL = ""
+
+    if (![URL isFileURL])
+        [NSException raise:NSInvalidArgumentException format:@"%@ is not a file URL", URL];
+
+    if (![readAccessURL isFileURL])
+        [NSException raise:NSInvalidArgumentException format:@"%@ is not a file URL", readAccessURL];
+
+    return wrapper(_page->loadFile(URL.absoluteString, readAccessURL.absoluteString));
+}
+
 - (NSArray *)_certificateChain
 {
     if (WebKit::WebFrameProxy* mainFrame = _page->mainFrame())

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h (272653 => 272654)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h	2021-02-10 15:46:06 UTC (rev 272653)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h	2021-02-10 15:58:57 UTC (rev 272654)
@@ -391,6 +391,39 @@
 @property (nonatomic, readonly) NSColor *_pageExtendedBackgroundColor;
 #endif
 
+/*! @abstract Sets the webpage contents from the passed data as if it was the
+ response to the supplied request. The request is never actually sent to the
+ supplied URL, though loads of resources defined in the NSData object would
+ be performed.
+ @param request The request specifying the base URL and other loading details
+ to be used while interpreting the supplied data object.
+ @param response A response that is used to interpret the supplied data object.
+ @param data The data to use as the contents of the webpage.
+ @result A new navigation.
+*/
+- (WKNavigation *)loadSimulatedRequest:(NSURLRequest *)request withResponse:(NSURLResponse *)response responseData:(NSData *)data WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
+
+/*! @abstract Navigates to the requested file URL on the filesystem.
+ @param request The request specifying the file URL to which to navigate.
+ @param readAccessURL The URL to allow read access to.
+ @discussion If readAccessURL references a single file, only that file may be
+ loaded by WebKit.
+ If readAccessURL references a directory, files inside that file may be loaded by WebKit.
+ @result A new navigation for the given file URL.
+*/
+- (WKNavigation *)loadFileRequest:(NSURLRequest *)request allowingReadAccessToURL:(NSURL *)readAccessURL WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
+
+/*! @abstract Sets the webpage contents from the passed HTML string as if it was
+ the response to the supplied request. The request is never actually sent to the
+ supplied URL, though loads of resources defined in the HTML string would be
+ performed.
+ @param request The request specifying the base URL and other loading details
+ to be used while interpreting the supplied data object.
+ @param string The data to use as the contents of the webpage.
+ @result A new navigation.
+*/
+- (WKNavigation *)loadSimulatedRequest:(NSURLRequest *)request withResponseHTMLString:(NSString *)string WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
+
 @end
 
 #if TARGET_OS_IPHONE

Modified: trunk/Tools/ChangeLog (272653 => 272654)


--- trunk/Tools/ChangeLog	2021-02-10 15:46:06 UTC (rev 272653)
+++ trunk/Tools/ChangeLog	2021-02-10 15:58:57 UTC (rev 272654)
@@ -1,3 +1,15 @@
+2021-02-10  Brent Fulgham  <bfulg...@apple.com>
+
+        Create stub methods to support finer-grained control over loading
+        https://bugs.webkit.org/show_bug.cgi?id=221430
+        <rdar://problem/73999547>
+
+        Reviewed by Geoffrey Garen.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKitCocoa/WKWebViewLoadAPIs.mm: Added.
+        (TEST):
+
 2021-02-10  Lauro Moura  <lmo...@igalia.com>
 
         [GTK] Gardening TestResources failures after r272636

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (272653 => 272654)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2021-02-10 15:46:06 UTC (rev 272653)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2021-02-10 15:58:57 UTC (rev 272654)
@@ -539,6 +539,7 @@
 		7A0509411FB9F06400B33FB8 /* JSONValue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7A0509401FB9F04400B33FB8 /* JSONValue.cpp */; };
 		7A1458FC1AD5C07000E06772 /* mouse-button-listener.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 7A1458FB1AD5C03500E06772 /* mouse-button-listener.html */; };
 		7A32D74A1F02151500162C44 /* FileMonitor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7A32D7491F02151500162C44 /* FileMonitor.cpp */; };
+		7A42ABD725CCD0F500980BCA /* WKWebViewLoadAPIs.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7A42ABD625CCD0F500980BCA /* WKWebViewLoadAPIs.mm */; };
 		7A66BDB81EAF18D500CCC924 /* set-long-title.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 7A66BDB71EAF150100CCC924 /* set-long-title.html */; };
 		7A6A2C701DCCFA8C00C0D085 /* LocalStorageQuirkTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7A6A2C6F1DCCF87B00C0D085 /* LocalStorageQuirkTest.mm */; };
 		7A6A2C721DCCFB5200C0D085 /* LocalStorageQuirkEnabled.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 7A6A2C711DCCFB0200C0D085 /* LocalStorageQuirkEnabled.html */; };
@@ -2336,6 +2337,7 @@
 		7A1458FB1AD5C03500E06772 /* mouse-button-listener.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "mouse-button-listener.html"; sourceTree = "<group>"; };
 		7A32D7491F02151500162C44 /* FileMonitor.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = FileMonitor.cpp; sourceTree = "<group>"; };
 		7A38D7E51C752D5F004F157D /* HashCountedSet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HashCountedSet.cpp; sourceTree = "<group>"; };
+		7A42ABD625CCD0F500980BCA /* WKWebViewLoadAPIs.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewLoadAPIs.mm; sourceTree = "<group>"; };
 		7A5623101AD5AF3E0096B920 /* MenuTypesForMouseEvents.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MenuTypesForMouseEvents.cpp; sourceTree = "<group>"; };
 		7A66BDB71EAF150100CCC924 /* set-long-title.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "set-long-title.html"; sourceTree = "<group>"; };
 		7A6A2C6F1DCCF87B00C0D085 /* LocalStorageQuirkTest.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LocalStorageQuirkTest.mm; sourceTree = "<group>"; };
@@ -3510,6 +3512,7 @@
 				CE449E1021AE0F7200E7ADA1 /* WKWebViewFindString.mm */,
 				F4106C6821ACBF84004B89A1 /* WKWebViewFirstResponderTests.mm */,
 				D3BE5E341E4CE85E00FD563A /* WKWebViewGetContents.mm */,
+				7A42ABD625CCD0F500980BCA /* WKWebViewLoadAPIs.mm */,
 				2D01D06D23218FEE0039AA3A /* WKWebViewPrintFormatter.mm */,
 				37A9DBE7213B4C9300D261A2 /* WKWebViewServerTrustKVC.mm */,
 				93F56DA81E5F9181003EDE84 /* WKWebViewSnapshot.mm */,
@@ -5696,6 +5699,7 @@
 				CE449E1121AE0F7200E7ADA1 /* WKWebViewFindString.mm in Sources */,
 				F4106C6921ACBF84004B89A1 /* WKWebViewFirstResponderTests.mm in Sources */,
 				D34E08761E4E42E1005FF14A /* WKWebViewGetContents.mm in Sources */,
+				7A42ABD725CCD0F500980BCA /* WKWebViewLoadAPIs.mm in Sources */,
 				F4FA91811E61849B007B8C1D /* WKWebViewMacEditingTests.mm in Sources */,
 				1CACADA1230620AE0007D54C /* WKWebViewOpaque.mm in Sources */,
 				CD27A1C123C661ED006E11DD /* WKWebViewPausePlayingAudioTests.mm in Sources */,

Added: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewLoadAPIs.mm (0 => 272654)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewLoadAPIs.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewLoadAPIs.mm	2021-02-10 15:58:57 UTC (rev 272654)
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2021 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 <WebKit/WKFoundation.h>
+
+#import "PlatformUtilities.h"
+#import "Test.h"
+#import "TestNavigationDelegate.h"
+#import <WebKit/WKWebViewPrivate.h>
+#import <wtf/RetainPtr.h>
+#import <wtf/cocoa/NSURLExtras.h>
+
+static NSURL *exampleURL = [NSURL URLWithString:@"https://example.com"];
+static NSString *htmlString = @"<html><body><h1>Hello, world!</h1></body></html>";
+
+TEST(WKWebView, LoadSimulatedRequestUsingResponseHTMLString)
+{
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+
+    auto delegate = adoptNS([[TestNavigationDelegate alloc] init]);
+    [webView setNavigationDelegate:delegate.get()];
+
+    NSURLRequest *loadRequest = [NSURLRequest requestWithURL:exampleURL];
+
+    [webView loadSimulatedRequest:loadRequest withResponseHTMLString:htmlString];
+    [delegate waitForDidFinishNavigation];
+}
+
+TEST(WKWebView, LoadSimulatedRequestUsingResponseData)
+{
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+
+    auto delegate = adoptNS([[TestNavigationDelegate alloc] init]);
+    [webView setNavigationDelegate:delegate.get()];
+
+    NSURLRequest *loadRequest = [NSURLRequest requestWithURL:exampleURL];
+
+    NSData *data = "" dataUsingEncoding:NSUTF8StringEncoding];
+    auto response = adoptNS([[NSURLResponse alloc] initWithURL:exampleURL MIMEType:@"text/HTML" expectedContentLength:[data length] textEncodingName:@"UTF-8"]);
+
+    [webView loadSimulatedRequest:loadRequest withResponse:response.get() responseData:data];
+    [delegate waitForDidFinishNavigation];
+}
+
+TEST(WKWebView, LoadFileRequest)
+{
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+
+    auto delegate = adoptNS([[TestNavigationDelegate alloc] init]);
+    [webView setNavigationDelegate:delegate.get()];
+
+    NSURL *file = [[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
+    NSURLRequest *request = [NSURLRequest requestWithURL:file];
+    [webView loadFileRequest:request allowingReadAccessToURL:file.URLByDeletingLastPathComponent];
+    [delegate waitForDidFinishNavigation];
+    EXPECT_WK_STREQ(webView.get()._resourceDirectoryURL.path, file.URLByDeletingLastPathComponent.path);
+}
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to