Skip to content

Commit

Permalink
Fix Mail after 278564@main
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=273955
rdar://127819455

Reviewed by Brady Eidson.

Mail uses WKObjCTypeWrapperGetObject which of course has 0 tests.
It expected an ObjCObjectGraph, but I'm now giving it an API::Data.
Make it handle an API::Data.

* Source/WebKit/Shared/API/c/mac/WKObjCTypeWrapperRef.mm:
(WKObjCTypeWrapperGetObject):
* Tools/TestWebKitAPI/Tests/WebKitCocoa/BundleParameters.mm:
(TEST(WebKit, LoadDataWithUserData)):
* Tools/TestWebKitAPI/Tests/WebKitCocoa/BundleParametersPlugIn.mm:
(-[BundleParametersPlugIn webProcessPlugIn:didCreateBrowserContextController:]):

Canonical link: https://commits.webkit.org/278579@main
  • Loading branch information
achristensen07 committed May 9, 2024
1 parent 7a7a9a5 commit f1fd721
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Source/WebKit/Shared/API/c/mac/WKObjCTypeWrapperRef.mm
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
#import "WKObjCTypeWrapperRef.h"

#import "ObjCObjectGraph.h"
#import "WKData.h"
#import "WKNSData.h"
#import "WKSharedAPICast.h"
#import "WKType.h"

WKTypeID WKObjCTypeWrapperGetTypeID()
{
Expand All @@ -36,5 +39,7 @@ WKTypeID WKObjCTypeWrapperGetTypeID()

id WKObjCTypeWrapperGetObject(WKObjCTypeWrapperRef wrapperRef)
{
if (wrapperRef && WKGetTypeID(wrapperRef) == WKDataGetTypeID())
return WebKit::wrapper(WebKit::toImpl((WKDataRef)wrapperRef));
return WebKit::toImpl(wrapperRef)->rootObject();
}
11 changes: 11 additions & 0 deletions Tools/TestWebKitAPI/Tests/WebKitCocoa/BundleParameters.mm
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
#import "DeprecatedGlobalValues.h"
#import "PlatformUtilities.h"
#import "Test.h"
#import "TestNavigationDelegate.h"
#import "WKWebViewConfigurationExtras.h"
#import <WebKit/WKProcessPoolPrivate.h>
#import <WebKit/WKWebViewPrivate.h>
#import <wtf/RetainPtr.h>

TEST(WebKit, BundleParameters)
Expand Down Expand Up @@ -110,3 +112,12 @@
TestWebKitAPI::Util::run(&isDone);
}
}

TEST(WebKit, LoadDataWithUserData)
{
NSString * const testPlugInClassName = @"BundleParametersPlugIn";
auto configuration = retainPtr([WKWebViewConfiguration _test_configurationWithTestPlugInClassName:testPlugInClassName]);
auto webView = adoptNS([[WKWebView alloc] initWithFrame:CGRectZero configuration:configuration.get()]);
[webView _loadData:NSData.data MIMEType:@"text/html" characterEncodingName:@"utf-8" baseURL:[NSURL URLWithString:@"https://webkit.org/"] userData:NSData.data];
[webView _test_waitForDidFinishNavigation];
}
17 changes: 17 additions & 0 deletions Tools/TestWebKitAPI/Tests/WebKitCocoa/BundleParametersPlugIn.mm
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@
#import <WebKit/WKWebProcessPlugInScriptWorld.h>
#import <wtf/RetainPtr.h>

#if WK_HAVE_C_SPI
#import <WebKit/WKBundlePage.h>
#import <WebKit/WKBundlePageLoaderClient.h>
#import <WebKit/WKObjCTypeWrapperRef.h>
#import <WebKit/WKType.h>
#endif

static NSString * const testParameter1 = @"TestParameter1";
static NSString * const testParameter2 = @"TestParameter2";

Expand All @@ -52,6 +59,16 @@ - (void)webProcessPlugIn:(WKWebProcessPlugInController *)plugInController didCre
[plugInController.parameters addObserver:self forKeyPath:testParameter1 options:NSKeyValueObservingOptionInitial context:NULL];
[plugInController.parameters addObserver:self forKeyPath:testParameter2 options:NSKeyValueObservingOptionInitial context:NULL];
[plugInController.parameters addObserver:self forKeyPath:TestWebKitAPI::Util::TestPlugInClassNameParameter options:NSKeyValueObservingOptionInitial context:NULL];

#if WK_HAVE_C_SPI
WKBundlePageLoaderClientV6 loaderClient = { };
loaderClient.base.version = 6;
loaderClient.willLoadDataRequest = [] (WKBundlePageRef page, WKURLRequestRef, WKDataRef, WKStringRef, WKStringRef, WKURLRef, WKTypeRef userData, const void*) {
id data = WKObjCTypeWrapperGetObject((WKObjCTypeWrapperRef)userData);
RELEASE_ASSERT([data isKindOfClass:NSData.class]);
};
WKBundlePageSetPageLoaderClient(static_cast<WKBundlePageRef>(browserContextController), &loaderClient.base);
#endif
}

- (void)dealloc
Expand Down

0 comments on commit f1fd721

Please sign in to comment.