Title: [250093] trunk
Revision
250093
Author
[email protected]
Date
2019-09-19 09:11:31 -0700 (Thu, 19 Sep 2019)

Log Message

Create InjectedBundle SPI to better support NSSecureCoding
https://bugs.webkit.org/show_bug.cgi?id=201810
<rdar://problem/55265713>

The encoding/decoding routines used by WebKit’s InjectedBundles are based on NSCoding.
While we have changed WebKit internals to use NSSecureCoding, there are a number of
injected bundles that need to serialize custom classes between the InjectedBundle and
the relevant WebKit UIProcess.

We need to lock down this communications channel by enforcing NSSecureCoding.

This patch creates new SPI to allow the UIProcess to specify classes that it will accept
in messages from the WebContet Process (and Injected Bundle).

It adds the following property to the WKProcessPoolConfiguration:

    @property (nonatomic, copy) NSSet<Class> *customClassesForParameterCoder;

If no custom classes are specified, the standard serialization primitives are supported:
    NSArray, NSData, NSDate, NSDictionary, NSNull, NSNumber, NSSet, NSString,
    NSTimeZone, NSURL, and NSUUID.

Reviewed by Brady Eidson.

Source/WebKit:

* UIProcess/API/APIProcessPoolConfiguration.cpp:
(API::ProcessPoolConfiguration::copy): Copy any custom classes.
* UIProcess/API/APIProcessPoolConfiguration.h:
* UIProcess/API/C/WKContextConfigurationRef.cpp:
(WKContextConfigurationCopyCustomClassesForParameterCoder): Added.
(WKContextConfigurationSetCustomClassesForParameterCoder): Added.
* UIProcess/API/C/WKContextConfigurationRef.h:
* UIProcess/API/Cocoa/WKProcessGroup.h:
* UIProcess/API/Cocoa/WKProcessGroup.mm:
(toStringVector): Added.
(-[WKProcessGroup initWithInjectedBundleURL:andCustomClassesForParameterCoder:]):
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _setInputDelegate:]): Restrict serialization to allowed classes.
* UIProcess/API/Cocoa/_WKProcessPoolConfiguration.h:
* UIProcess/API/Cocoa/_WKProcessPoolConfiguration.mm:
(-[_WKProcessPoolConfiguration customClassesForParameterCoder]): Added.
(-[_WKProcessPoolConfiguration setCustomClassesForParameterCoder:]): Added.
* UIProcess/Cocoa/WebProcessPoolCocoa.mm:
(WebKit::WebProcessPool::platformInitialize): Register any custom classes
provided in the configuraton.
(WebKit::WebProcessPool::initializeClassesForParameterCoding): Added.
(WebKit::WebProcessPool::allowedClassesForParameterCoding const): Added.
* UIProcess/WebProcessPool.h:
* UIProcess/ios/PageClientImplIOS.mm:
(WebKit::PageClientImpl::elementDidFocus): Restrict serialization to allowed
classes only.

Tools:

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKitCocoa/BundleFormDelegate.mm: Added.
(-[BundleFormDelegateRemoteObject didGetFocus]):
(-[FormInputDelegate _webView:decidePolicyForFocusedElement:]):
(TEST):
* TestWebKitAPI/Tests/WebKitCocoa/BundleFormDelegatePlugIn.mm: Added.
(-[BundleFormDelegatePlugIn webProcessPlugIn:didCreateBrowserContextController:]):
(-[BundleFormDelegatePlugIn _webProcessPlugInBrowserContextController:willBeginInputSessionForElement:inFrame:userIsInteracting:]):
(-[BundleFormDelegatePlugIn _webProcessPlugInBrowserContextController:didFocusTextField:inFrame:]):
* TestWebKitAPI/Tests/WebKitCocoa/BundleFormDelegateProtocol.h: Copied from Tools/TestWebKitAPI/WKWebViewConfigurationExtras.h.
* TestWebKitAPI/Tests/WebKitCocoa/WKProcessPoolConfiguration.mm:
(TEST):
* TestWebKitAPI/WKWebViewConfigurationExtras.h:
* TestWebKitAPI/WKWebViewConfigurationExtras.mm:
(+[WKWebViewConfiguration _test_configurationWithTestPlugInClassName:configureJSCForTesting:]):
(+[WKWebViewConfiguration _test_configurationWithTestPlugInClassName:configureJSCForTesting:andCustomParameterClasses:]):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (250092 => 250093)


--- trunk/Source/WebKit/ChangeLog	2019-09-19 15:52:43 UTC (rev 250092)
+++ trunk/Source/WebKit/ChangeLog	2019-09-19 16:11:31 UTC (rev 250093)
@@ -1,3 +1,56 @@
+2019-09-19  Brent Fulgham  <[email protected]>
+
+        Create InjectedBundle SPI to better support NSSecureCoding
+        https://bugs.webkit.org/show_bug.cgi?id=201810
+        <rdar://problem/55265713>
+
+        The encoding/decoding routines used by WebKit’s InjectedBundles are based on NSCoding.
+        While we have changed WebKit internals to use NSSecureCoding, there are a number of
+        injected bundles that need to serialize custom classes between the InjectedBundle and
+        the relevant WebKit UIProcess.
+
+        We need to lock down this communications channel by enforcing NSSecureCoding.
+
+        This patch creates new SPI to allow the UIProcess to specify classes that it will accept
+        in messages from the WebContet Process (and Injected Bundle).
+
+        It adds the following property to the WKProcessPoolConfiguration:
+
+            @property (nonatomic, copy) NSSet<Class> *customClassesForParameterCoder;
+
+        If no custom classes are specified, the standard serialization primitives are supported:
+            NSArray, NSData, NSDate, NSDictionary, NSNull, NSNumber, NSSet, NSString,
+            NSTimeZone, NSURL, and NSUUID.
+
+        Reviewed by Brady Eidson.
+
+        * UIProcess/API/APIProcessPoolConfiguration.cpp:
+        (API::ProcessPoolConfiguration::copy): Copy any custom classes.
+        * UIProcess/API/APIProcessPoolConfiguration.h:
+        * UIProcess/API/C/WKContextConfigurationRef.cpp:
+        (WKContextConfigurationCopyCustomClassesForParameterCoder): Added.
+        (WKContextConfigurationSetCustomClassesForParameterCoder): Added.
+        * UIProcess/API/C/WKContextConfigurationRef.h:
+        * UIProcess/API/Cocoa/WKProcessGroup.h:
+        * UIProcess/API/Cocoa/WKProcessGroup.mm:
+        (toStringVector): Added.
+        (-[WKProcessGroup initWithInjectedBundleURL:andCustomClassesForParameterCoder:]):
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _setInputDelegate:]): Restrict serialization to allowed classes.
+        * UIProcess/API/Cocoa/_WKProcessPoolConfiguration.h:
+        * UIProcess/API/Cocoa/_WKProcessPoolConfiguration.mm:
+        (-[_WKProcessPoolConfiguration customClassesForParameterCoder]): Added.
+        (-[_WKProcessPoolConfiguration setCustomClassesForParameterCoder:]): Added.
+        * UIProcess/Cocoa/WebProcessPoolCocoa.mm:
+        (WebKit::WebProcessPool::platformInitialize): Register any custom classes
+        provided in the configuraton.
+        (WebKit::WebProcessPool::initializeClassesForParameterCoding): Added.
+        (WebKit::WebProcessPool::allowedClassesForParameterCoding const): Added.
+        * UIProcess/WebProcessPool.h:
+        * UIProcess/ios/PageClientImplIOS.mm:
+        (WebKit::PageClientImpl::elementDidFocus): Restrict serialization to allowed
+        classes only.
+
 2019-09-18  Chris Dumez  <[email protected]>
 
         AddPlugInAutoStartOriginHash / PlugInDidReceiveUserInteraction IPC should not need to pass a SessionID

Modified: trunk/Source/WebKit/UIProcess/API/APIProcessPoolConfiguration.cpp (250092 => 250093)


--- trunk/Source/WebKit/UIProcess/API/APIProcessPoolConfiguration.cpp	2019-09-19 15:52:43 UTC (rev 250092)
+++ trunk/Source/WebKit/UIProcess/API/APIProcessPoolConfiguration.cpp	2019-09-19 16:11:31 UTC (rev 250093)
@@ -84,6 +84,7 @@
     copy->m_mediaCacheDirectory = this->m_mediaCacheDirectory;
     copy->m_indexedDBDatabaseDirectory = this->m_indexedDBDatabaseDirectory;
     copy->m_injectedBundlePath = this->m_injectedBundlePath;
+    copy->m_customClassesForParameterCoder = this->m_customClassesForParameterCoder;
     copy->m_localStorageDirectory = this->m_localStorageDirectory;
     copy->m_deviceIdHashSaltsStorageDirectory = this->m_deviceIdHashSaltsStorageDirectory;
     copy->m_mediaKeysStorageDirectory = this->m_mediaKeysStorageDirectory;

Modified: trunk/Source/WebKit/UIProcess/API/APIProcessPoolConfiguration.h (250092 => 250093)


--- trunk/Source/WebKit/UIProcess/API/APIProcessPoolConfiguration.h	2019-09-19 15:52:43 UTC (rev 250092)
+++ trunk/Source/WebKit/UIProcess/API/APIProcessPoolConfiguration.h	2019-09-19 16:11:31 UTC (rev 250093)
@@ -111,6 +111,9 @@
     const WTF::String& resourceLoadStatisticsDirectory() const { return m_resourceLoadStatisticsDirectory; }
     void setResourceLoadStatisticsDirectory(const WTF::String& resourceLoadStatisticsDirectory) { m_resourceLoadStatisticsDirectory = resourceLoadStatisticsDirectory; }
 
+    const Vector<WTF::String>& customClassesForParameterCoder() const { return m_customClassesForParameterCoder; }
+    void setCustomClassesForParameterCoder(Vector<WTF::String>&& classesForCoder) { m_customClassesForParameterCoder = WTFMove(classesForCoder); }
+
     const Vector<WTF::String>& cachePartitionedURLSchemes() { return m_cachePartitionedURLSchemes; }
     void setCachePartitionedURLSchemes(Vector<WTF::String>&& cachePartitionedURLSchemes) { m_cachePartitionedURLSchemes = WTFMove(cachePartitionedURLSchemes); }
 
@@ -199,6 +202,7 @@
     WTF::String m_webSQLDatabaseDirectory;
     WTF::String m_mediaKeysStorageDirectory;
     WTF::String m_resourceLoadStatisticsDirectory;
+    Vector<WTF::String> m_customClassesForParameterCoder;
     Vector<WTF::String> m_cachePartitionedURLSchemes;
     Vector<WTF::String> m_alwaysRevalidatedURLSchemes;
     Vector<WTF::CString> m_additionalReadAccessAllowedPaths;

Modified: trunk/Source/WebKit/UIProcess/API/C/WKContextConfigurationRef.cpp (250092 => 250093)


--- trunk/Source/WebKit/UIProcess/API/C/WKContextConfigurationRef.cpp	2019-09-19 15:52:43 UTC (rev 250092)
+++ trunk/Source/WebKit/UIProcess/API/C/WKContextConfigurationRef.cpp	2019-09-19 16:11:31 UTC (rev 250093)
@@ -79,6 +79,16 @@
     toImpl(configuration)->setInjectedBundlePath(toImpl(injectedBundlePath)->string());
 }
 
+WKArrayRef WKContextConfigurationCopyCustomClassesForParameterCoder(WKContextConfigurationRef configuration)
+{
+    return toAPI(&API::Array::createStringArray(toImpl(configuration)->customClassesForParameterCoder()).leakRef());
+}
+
+void WKContextConfigurationSetCustomClassesForParameterCoder(WKContextConfigurationRef configuration, WKArrayRef classesForCoder)
+{
+    toImpl(configuration)->setCustomClassesForParameterCoder(toImpl(classesForCoder)->toStringVector());
+}
+
 WKStringRef WKContextConfigurationCopyLocalStorageDirectory(WKContextConfigurationRef)
 {
     return nullptr;

Modified: trunk/Source/WebKit/UIProcess/API/C/WKContextConfigurationRef.h (250092 => 250093)


--- trunk/Source/WebKit/UIProcess/API/C/WKContextConfigurationRef.h	2019-09-19 15:52:43 UTC (rev 250092)
+++ trunk/Source/WebKit/UIProcess/API/C/WKContextConfigurationRef.h	2019-09-19 16:11:31 UTC (rev 250093)
@@ -48,6 +48,9 @@
 WK_EXPORT WKStringRef WKContextConfigurationCopyInjectedBundlePath(WKContextConfigurationRef configuration);
 WK_EXPORT void WKContextConfigurationSetInjectedBundlePath(WKContextConfigurationRef configuration, WKStringRef injectedBundlePath);
 
+WK_EXPORT WKArrayRef WKContextConfigurationCopyCustomClassesForParameterCoder(WKContextConfigurationRef configuration);
+WK_EXPORT void WKContextConfigurationSetCustomClassesForParameterCoder(WKContextConfigurationRef configuration, WKArrayRef classesForCoder);
+
 WK_EXPORT WKStringRef WKContextConfigurationCopyLocalStorageDirectory(WKContextConfigurationRef configuration) WK_C_API_DEPRECATED_WITH_REPLACEMENT(WKWebsiteDataStoreConfigurationCopyLocalStorageDirectory);
 WK_EXPORT void WKContextConfigurationSetLocalStorageDirectory(WKContextConfigurationRef configuration, WKStringRef localStorageDirectory) WK_C_API_DEPRECATED_WITH_REPLACEMENT(WKWebsiteDataStoreConfigurationSetLocalStorageDirectory);
 

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessGroup.h (250092 => 250093)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessGroup.h	2019-09-19 15:52:43 UTC (rev 250092)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessGroup.h	2019-09-19 16:11:31 UTC (rev 250093)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 Apple Inc. All rights reserved.
+ * Copyright (C) 2011-2019 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -48,8 +48,8 @@
 @interface WKProcessGroup : NSObject
 
 - (id)initWithInjectedBundleURL:(NSURL *)bundleURL;
+- (id)initWithInjectedBundleURL:(NSURL *)bundleURL andCustomClassesForParameterCoder:(NSSet *)classesForCoder;
 
-
 #pragma mark Delegates
 
 @property (assign) id <WKProcessGroupDelegate> delegate;

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessGroup.mm (250092 => 250093)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessGroup.mm	2019-09-19 15:52:43 UTC (rev 250092)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessGroup.mm	2019-09-19 16:11:31 UTC (rev 250093)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 Apple Inc. All rights reserved.
+ * Copyright (C) 2011-2019 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -207,6 +207,41 @@
     return self;
 }
 
+static Vector<WTF::String> toStringVector(NSSet *input)
+{
+    Vector<WTF::String> vector;
+
+    NSUInteger size = input.count;
+    if (!size)
+        return vector;
+
+    vector.reserveInitialCapacity(size);
+    for (id classObj : input) {
+        if (auto* string = NSStringFromClass(classObj))
+            vector.uncheckedAppend(string);
+    }
+    return vector;
+}
+
+- (id)initWithInjectedBundleURL:(NSURL *)bundleURL andCustomClassesForParameterCoder:(NSSet *)classesForCoder
+{
+    self = [super init];
+    if (!self)
+        return nil;
+
+    auto configuration = API::ProcessPoolConfiguration::create();
+    configuration->setInjectedBundlePath(bundleURL ? String(bundleURL.path) : String());
+    configuration->setCustomClassesForParameterCoder(toStringVector(classesForCoder));
+
+    _processPool = WebKit::WebProcessPool::create(configuration);
+
+    setUpConnectionClient(self, toAPI(_processPool.get()));
+    setUpInjectedBundleClient(self, toAPI(_processPool.get()));
+    setUpHistoryClient(self, toAPI(_processPool.get()));
+
+    return self;
+}
+
 - (id <WKProcessGroupDelegate>)delegate
 {
     return _delegate.getAutoreleased();

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


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm	2019-09-19 15:52:43 UTC (rev 250092)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm	2019-09-19 16:11:31 UTC (rev 250093)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014-2018 Apple Inc. All rights reserved.
+ * Copyright (C) 2014-2019 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -5699,7 +5699,10 @@
                 auto nsData = adoptNS([[NSData alloc] initWithBytesNoCopy:const_cast<void*>(static_cast<const void*>(data->bytes())) length:data->size() freeWhenDone:NO]);
                 auto unarchiver = secureUnarchiverFromData(nsData.get());
                 @try {
-                    userObject = [unarchiver decodeObjectOfClass:[NSObject class] forKey:@"userObject"];
+                    if (auto* allowedClasses = m_webView->_page->process().processPool().allowedClassesForParameterCoding())
+                        userObject = [unarchiver decodeObjectOfClasses:allowedClasses forKey:@"userObject"];
+                    else
+                        userObject = [unarchiver decodeObjectOfClass:[NSObject class] forKey:@"userObject"];
                 } @catch (NSException *exception) {
                     LOG_ERROR("Failed to decode user data: %@", exception);
                 }

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKProcessPoolConfiguration.h (250092 => 250093)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKProcessPoolConfiguration.h	2019-09-19 15:52:43 UTC (rev 250092)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKProcessPoolConfiguration.h	2019-09-19 16:11:31 UTC (rev 250093)
@@ -32,6 +32,7 @@
 @interface _WKProcessPoolConfiguration : NSObject <NSCopying>
 
 @property (nonatomic, copy) NSURL *injectedBundleURL;
+@property (nonatomic, copy) NSSet<Class> *customClassesForParameterCoder WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
 @property (nonatomic) NSUInteger maximumProcessCount WK_API_DEPRECATED("It is no longer possible to limit the number of processes", macos(WK_MAC_TBA, WK_MAC_TBA), ios(WK_IOS_TBA, WK_IOS_TBA));
 @property (nonatomic) BOOL usesSingleWebProcess WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
 @property (nonatomic, nullable, copy) NSString *customWebContentServiceBundleIdentifier WK_API_AVAILABLE(macos(10.14.4), ios(12.2));

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKProcessPoolConfiguration.mm (250092 => 250093)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKProcessPoolConfiguration.mm	2019-09-19 15:52:43 UTC (rev 250092)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKProcessPoolConfiguration.mm	2019-09-19 16:11:31 UTC (rev 250093)
@@ -26,6 +26,7 @@
 #import "config.h"
 #import "_WKProcessPoolConfigurationInternal.h"
 
+#import <objc/runtime.h>
 #import <wtf/RetainPtr.h>
 
 @implementation _WKProcessPoolConfiguration
@@ -60,6 +61,31 @@
     _processPoolConfiguration->setInjectedBundlePath(injectedBundleURL.path);
 }
 
+- (NSSet<Class> *)customClassesForParameterCoder
+{
+    auto classes = _processPoolConfiguration->customClassesForParameterCoder();
+    if (classes.isEmpty())
+        return [NSSet set];
+
+    NSMutableSet *result = [[NSMutableSet alloc] initWithCapacity:classes.size()];
+    for (const auto& value : classes)
+        [result addObject: objc_lookUpClass(value.utf8().data())];
+
+    return [result autorelease];
+}
+
+- (void)setCustomClassesForParameterCoder:(NSSet<Class> *)classesForCoder
+{
+    Vector<WTF::String> classes;
+    classes.reserveInitialCapacity(classesForCoder.count);
+    for (id classObj : classesForCoder) {
+        if (auto* string = NSStringFromClass(classObj))
+            classes.uncheckedAppend(string);
+    }
+
+    _processPoolConfiguration->setCustomClassesForParameterCoder(WTFMove(classes));
+}
+
 - (NSUInteger)maximumProcessCount
 {
     // Deprecated.

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm (250092 => 250093)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm	2019-09-19 15:52:43 UTC (rev 250092)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm	2019-09-19 16:11:31 UTC (rev 250093)
@@ -50,6 +50,7 @@
 #import <WebCore/PlatformPasteboard.h>
 #import <WebCore/RuntimeApplicationChecks.h>
 #import <WebCore/SharedBuffer.h>
+#import <objc/runtime.h>
 #import <pal/spi/cf/CFNetworkSPI.h>
 #import <pal/spi/cocoa/NSKeyedArchiverSPI.h>
 #import <sys/param.h>
@@ -128,6 +129,7 @@
 {
     registerUserDefaultsIfNeeded();
     registerNotificationObservers();
+    initializeClassesForParameterCoding();
 
     // FIXME: This should be able to share code with WebCore's MemoryPressureHandler (and be platform independent).
     // Right now it cannot because WebKit1 and WebKit2 need to be able to coexist in the UI process,
@@ -592,4 +594,34 @@
 }
 #endif
 
+void WebProcessPool::initializeClassesForParameterCoding()
+{
+    const auto& customClasses = m_configuration->customClassesForParameterCoder();
+    if (customClasses.isEmpty())
+        return;
+
+    auto standardClasses = [NSSet setWithObjects:[NSArray class], [NSData class], [NSDate class], [NSDictionary class], [NSNull class],
+        [NSNumber class], [NSSet class], [NSString class], [NSTimeZone class], [NSURL class], [NSUUID class], nil];
+    
+    auto mutableSet = adoptNS([standardClasses mutableCopy]);
+
+    for (const auto& customClass : customClasses) {
+        const auto* className = customClass.utf8().data();
+        Class objectClass = objc_lookUpClass(className);
+        if (!objectClass) {
+            WTFLogAlways("InjectedBundle::extendClassesForParameterCoder - Class %s is not a valid Objective C class.\n", className);
+            break;
+        }
+
+        [mutableSet.get() addObject:objectClass];
+    }
+
+    m_classesForParameterCoder = mutableSet;
+}
+
+NSSet *WebProcessPool::allowedClassesForParameterCoding() const
+{
+    return m_classesForParameterCoder.get();
+}
+
 } // namespace WebKit

Modified: trunk/Source/WebKit/UIProcess/WebProcessPool.h (250092 => 250093)


--- trunk/Source/WebKit/UIProcess/WebProcessPool.h	2019-09-19 15:52:43 UTC (rev 250092)
+++ trunk/Source/WebKit/UIProcess/WebProcessPool.h	2019-09-19 16:11:31 UTC (rev 250093)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2016 Apple Inc. All rights reserved.
+ * Copyright (C) 2010-2019 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -71,6 +71,7 @@
 #if PLATFORM(COCOA)
 OBJC_CLASS NSMutableDictionary;
 OBJC_CLASS NSObject;
+OBJC_CLASS NSSet;
 OBJC_CLASS NSString;
 #endif
 
@@ -213,6 +214,10 @@
     bool hasPagesUsingWebsiteDataStore(WebsiteDataStore&) const;
 
     const String& injectedBundlePath() const { return m_configuration->injectedBundlePath(); }
+#if PLATFORM(COCOA)
+    NSSet *allowedClassesForParameterCoding() const;
+    void initializeClassesForParameterCoding();
+#endif
 
     DownloadProxy& download(WebPageProxy* initiatingPage, const WebCore::ResourceRequest&, const String& suggestedFilename = { });
     DownloadProxy& resumeDownload(WebPageProxy* initiatingPage, const API::Data* resumeData, const String& path);
@@ -737,6 +742,7 @@
 #if PLATFORM(COCOA)
     RetainPtr<NSMutableDictionary> m_bundleParameters;
     ProcessSuppressionDisabledToken m_pluginProcessManagerProcessSuppressionDisabledToken;
+    mutable RetainPtr<NSSet> m_classesForParameterCoder;
 #endif
 
 #if ENABLE(CONTENT_EXTENSIONS)

Modified: trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.mm (250092 => 250093)


--- trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.mm	2019-09-19 15:52:43 UTC (rev 250092)
+++ trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.mm	2019-09-19 16:11:31 UTC (rev 250093)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012-2016 Apple Inc. All rights reserved.
+ * Copyright (C) 2012-2019 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -549,7 +549,10 @@
         auto nsData = adoptNS([[NSData alloc] initWithBytesNoCopy:const_cast<void*>(static_cast<const void*>(data->bytes())) length:data->size() freeWhenDone:NO]);
         auto unarchiver = secureUnarchiverFromData(nsData.get());
         @try {
-            userObject = [unarchiver decodeObjectOfClass:[NSObject class] forKey:@"userObject"];
+            if (auto* allowedClasses = m_webView.get()->_page->process().processPool().allowedClassesForParameterCoding())
+                userObject = [unarchiver decodeObjectOfClasses:allowedClasses forKey:@"userObject"];
+            else
+                userObject = [unarchiver decodeObjectOfClass:[NSObject class] forKey:@"userObject"];
         } @catch (NSException *exception) {
             LOG_ERROR("Failed to decode user data: %@", exception);
         }

Modified: trunk/Tools/ChangeLog (250092 => 250093)


--- trunk/Tools/ChangeLog	2019-09-19 15:52:43 UTC (rev 250092)
+++ trunk/Tools/ChangeLog	2019-09-19 16:11:31 UTC (rev 250093)
@@ -1,3 +1,46 @@
+2019-09-19  Brent Fulgham  <[email protected]>
+
+        Create InjectedBundle SPI to better support NSSecureCoding
+        https://bugs.webkit.org/show_bug.cgi?id=201810
+        <rdar://problem/55265713>
+
+        The encoding/decoding routines used by WebKit’s InjectedBundles are based on NSCoding.
+        While we have changed WebKit internals to use NSSecureCoding, there are a number of
+        injected bundles that need to serialize custom classes between the InjectedBundle and
+        the relevant WebKit UIProcess.
+
+        We need to lock down this communications channel by enforcing NSSecureCoding.
+
+        This patch creates new SPI to allow the UIProcess to specify classes that it will accept
+        in messages from the WebContet Process (and Injected Bundle).
+
+        It adds the following property to the WKProcessPoolConfiguration:
+
+            @property (nonatomic, copy) NSSet<Class> *customClassesForParameterCoder;
+
+        If no custom classes are specified, the standard serialization primitives are supported:
+            NSArray, NSData, NSDate, NSDictionary, NSNull, NSNumber, NSSet, NSString,
+            NSTimeZone, NSURL, and NSUUID.
+
+        Reviewed by Brady Eidson.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKitCocoa/BundleFormDelegate.mm: Added.
+        (-[BundleFormDelegateRemoteObject didGetFocus]):
+        (-[FormInputDelegate _webView:decidePolicyForFocusedElement:]):
+        (TEST):
+        * TestWebKitAPI/Tests/WebKitCocoa/BundleFormDelegatePlugIn.mm: Added.
+        (-[BundleFormDelegatePlugIn webProcessPlugIn:didCreateBrowserContextController:]):
+        (-[BundleFormDelegatePlugIn _webProcessPlugInBrowserContextController:willBeginInputSessionForElement:inFrame:userIsInteracting:]):
+        (-[BundleFormDelegatePlugIn _webProcessPlugInBrowserContextController:didFocusTextField:inFrame:]):
+        * TestWebKitAPI/Tests/WebKitCocoa/BundleFormDelegateProtocol.h: Copied from Tools/TestWebKitAPI/WKWebViewConfigurationExtras.h.
+        * TestWebKitAPI/Tests/WebKitCocoa/WKProcessPoolConfiguration.mm:
+        (TEST):
+        * TestWebKitAPI/WKWebViewConfigurationExtras.h:
+        * TestWebKitAPI/WKWebViewConfigurationExtras.mm:
+        (+[WKWebViewConfiguration _test_configurationWithTestPlugInClassName:configureJSCForTesting:]):
+        (+[WKWebViewConfiguration _test_configurationWithTestPlugInClassName:configureJSCForTesting:andCustomParameterClasses:]):
+
 2019-09-18  Zhifei Fang  <[email protected]>
 
         [results.webkit.org] fix missing col classes

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (250092 => 250093)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2019-09-19 15:52:43 UTC (rev 250092)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2019-09-19 16:11:31 UTC (rev 250093)
@@ -439,6 +439,8 @@
 		7A6A2C701DCCFA8C00C0D085 /* LocalStorageQuirkTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7A6A2C6F1DCCF87B00C0D085 /* LocalStorageQuirkTest.mm */; };
 		7A6A2C721DCCFB5200C0D085 /* LocalStorageQuirkEnabled.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 7A6A2C711DCCFB0200C0D085 /* LocalStorageQuirkEnabled.html */; };
 		7A7B0E7F1EAFE4C3006AB8AE /* LimitTitleSize.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7A7B0E7E1EAFE454006AB8AE /* LimitTitleSize.mm */; };
+		7A89BB67233164320042CB1E /* BundleFormDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7A89BB652331635D0042CB1E /* BundleFormDelegate.mm */; };
+		7A89BB682331643A0042CB1E /* BundleFormDelegatePlugIn.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7A89BB662331635D0042CB1E /* BundleFormDelegatePlugIn.mm */; };
 		7A909A7D1D877480007E10F8 /* AffineTransform.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7A909A6F1D877475007E10F8 /* AffineTransform.cpp */; };
 		7A909A7E1D877480007E10F8 /* FloatPoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7A909A701D877475007E10F8 /* FloatPoint.cpp */; };
 		7A909A7F1D877480007E10F8 /* FloatRect.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7A909A711D877475007E10F8 /* FloatRect.cpp */; };
@@ -1960,6 +1962,9 @@
 		7A6A2C6F1DCCF87B00C0D085 /* LocalStorageQuirkTest.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LocalStorageQuirkTest.mm; sourceTree = "<group>"; };
 		7A6A2C711DCCFB0200C0D085 /* LocalStorageQuirkEnabled.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = LocalStorageQuirkEnabled.html; sourceTree = "<group>"; };
 		7A7B0E7E1EAFE454006AB8AE /* LimitTitleSize.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LimitTitleSize.mm; sourceTree = "<group>"; };
+		7A89BB652331635D0042CB1E /* BundleFormDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = BundleFormDelegate.mm; sourceTree = "<group>"; };
+		7A89BB662331635D0042CB1E /* BundleFormDelegatePlugIn.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = BundleFormDelegatePlugIn.mm; sourceTree = "<group>"; };
+		7A89BB69233165650042CB1E /* BundleFormDelegateProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BundleFormDelegateProtocol.h; sourceTree = "<group>"; };
 		7A909A6F1D877475007E10F8 /* AffineTransform.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AffineTransform.cpp; sourceTree = "<group>"; };
 		7A909A701D877475007E10F8 /* FloatPoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FloatPoint.cpp; sourceTree = "<group>"; };
 		7A909A711D877475007E10F8 /* FloatRect.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FloatRect.cpp; sourceTree = "<group>"; };
@@ -2738,6 +2743,9 @@
 				374B7A5E1DF36EEE00ACCB6C /* BundleEditingDelegate.mm */,
 				374B7A5F1DF36EEE00ACCB6C /* BundleEditingDelegatePlugIn.mm */,
 				374B7A621DF3734C00ACCB6C /* BundleEditingDelegateProtocol.h */,
+				7A89BB652331635D0042CB1E /* BundleFormDelegate.mm */,
+				7A89BB662331635D0042CB1E /* BundleFormDelegatePlugIn.mm */,
+				7A89BB69233165650042CB1E /* BundleFormDelegateProtocol.h */,
 				A13EBBAC1B87436F00097110 /* BundleParameters.mm */,
 				A13EBBAE1B87436F00097110 /* BundleParametersPlugIn.mm */,
 				37A709AD1E3EA8B000CA5969 /* BundleRangeHandle.mm */,
@@ -4405,6 +4413,7 @@
 				7CCE7EB51A411A7E00447C4C /* BackForwardList.mm in Sources */,
 				1C7FEB20207C0F2E00D23278 /* BackgroundColor.mm in Sources */,
 				374B7A601DF36EEE00ACCB6C /* BundleEditingDelegate.mm in Sources */,
+				7A89BB67233164320042CB1E /* BundleFormDelegate.mm in Sources */,
 				A13EBBB11B87438000097110 /* BundleParameters.mm in Sources */,
 				37A709AE1E3EA8B000CA5969 /* BundleRangeHandle.mm in Sources */,
 				7CCE7EDC1A411A9200447C4C /* CalculationValue.cpp in Sources */,
@@ -4897,6 +4906,7 @@
 				754CEC811F6722F200D0039A /* AutoFillAvailable.mm in Sources */,
 				5C4259462266A68A0039AA7A /* BasicProposedCredentialPlugIn.mm in Sources */,
 				374B7A611DF371CF00ACCB6C /* BundleEditingDelegatePlugIn.mm in Sources */,
+				7A89BB682331643A0042CB1E /* BundleFormDelegatePlugIn.mm in Sources */,
 				A13EBBB01B87436F00097110 /* BundleParametersPlugIn.mm in Sources */,
 				37A709AF1E3EA97E00CA5969 /* BundleRangeHandlePlugIn.mm in Sources */,
 				5C75716122124C5200B9E5AC /* BundleRetainPagePlugIn.mm in Sources */,

Added: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/BundleFormDelegate.mm (0 => 250093)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/BundleFormDelegate.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/BundleFormDelegate.mm	2019-09-19 16:11:31 UTC (rev 250093)
@@ -0,0 +1,163 @@
+/*
+ * Copyright (C) 2019 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>
+
+#if PLATFORM(IOS_FAMILY)
+
+#import "BundleFormDelegateProtocol.h"
+#import "PlatformUtilities.h"
+#import "Test.h"
+#import "TestNavigationDelegate.h"
+#import "WKWebViewConfigurationExtras.h"
+#import <WebKit/WKProcessPoolPrivate.h>
+#import <WebKit/WKWebViewPrivate.h>
+#import <WebKit/_WKFocusedElementInfo.h>
+#import <WebKit/_WKInputDelegate.h>
+#import <WebKit/_WKRemoteObjectInterface.h>
+#import <WebKit/_WKRemoteObjectRegistry.h>
+#import <wtf/RetainPtr.h>
+
+static bool didGetFocus;
+static bool didGetUserObject;
+static id userObject;
+
+@interface BundleFormDelegateRemoteObject : NSObject <BundleFormDelegateProtocol>
+@end
+
+@implementation BundleFormDelegateRemoteObject
+
+- (void)didGetFocus
+{
+    didGetFocus = true;
+}
+
+@end
+
+@interface FormInputDelegate : NSObject <_WKInputDelegate> {
+@public
+    RetainPtr<id> _userObject;
+}
+@end
+
+@implementation FormInputDelegate
+
+- (_WKFocusStartsInputSessionPolicy)_webView:(WKWebView *)webView decidePolicyForFocusedElement:(id <_WKFocusedElementInfo>)info
+{
+    _userObject = info.userObject;
+    didGetUserObject = true;
+    return _WKFocusStartsInputSessionPolicyAllow;
+}
+
+@end
+
+TEST(WebKit, WKWebProcessPlugInWithoutRegisteredCustomClass)
+{
+    auto delegate = adoptNS([[FormInputDelegate alloc] init]);
+
+    auto configuration = retainPtr([WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"BundleFormDelegatePlugIn"]);
+    [[configuration processPool] _setObject:@YES forBundleParameter:@"FormDelegateShouldAddCustomClass"];
+
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+    [webView _setInputDelegate:delegate.get()];
+    [webView loadHTMLString:@"<input></input><select><option selected>foo</option><option>bar</option></select>" baseURL:nil];
+    [webView _test_waitForDidFinishNavigation];
+
+    auto object = adoptNS([[BundleFormDelegateRemoteObject alloc] init]);
+    _WKRemoteObjectInterface *interface = [_WKRemoteObjectInterface remoteObjectInterfaceWithProtocol:@protocol(BundleFormDelegateProtocol)];
+    [[webView _remoteObjectRegistry] registerExportedObject:object.get() interface:interface];
+
+    [webView evaluateJavaScript:@"document.querySelector('input').focus()" completionHandler:nil];
+
+    userObject = nil;
+    didGetUserObject = false;
+
+    TestWebKitAPI::Util::run(&didGetFocus);
+    TestWebKitAPI::Util::run(&didGetUserObject);
+
+    // We should have serialized the NSUnitConverterLinear, since we did not indicate we wanted
+    // to limit serialization.
+    EXPECT_TRUE([delegate->_userObject isKindOfClass:[NSUnitConverterLinear class]]);
+}
+
+TEST(WebKit, WKWebProcessPlugInWithRegisteredCustomClass)
+{
+    auto delegate = adoptNS([[FormInputDelegate alloc] init]);
+
+    auto configuration = retainPtr([WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"BundleFormDelegatePlugIn"
+        configureJSCForTesting:NO andCustomParameterClasses:[NSSet setWithObjects:[NSUnitConverterLinear class], nil]]);
+    [[configuration processPool] _setObject:@YES forBundleParameter:@"FormDelegateShouldAddCustomClass"];
+
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+    [webView _setInputDelegate:delegate.get()];
+    [webView loadHTMLString:@"<input></input><select><option selected>foo</option><option>bar</option></select>" baseURL:nil];
+    [webView _test_waitForDidFinishNavigation];
+
+    auto object = adoptNS([[BundleFormDelegateRemoteObject alloc] init]);
+    _WKRemoteObjectInterface *interface = [_WKRemoteObjectInterface remoteObjectInterfaceWithProtocol:@protocol(BundleFormDelegateProtocol)];
+    [[webView _remoteObjectRegistry] registerExportedObject:object.get() interface:interface];
+
+    [webView evaluateJavaScript:@"document.querySelector('input').focus()" completionHandler:nil];
+    
+    userObject = nil;
+    didGetUserObject = false;
+
+    TestWebKitAPI::Util::run(&didGetFocus);
+    TestWebKitAPI::Util::run(&didGetUserObject);
+    
+    EXPECT_TRUE([delegate->_userObject isKindOfClass:[NSUnitConverterLinear class]]);
+}
+
+TEST(WebKit, WKWebProcessPlugInWithUnregisteredCustomClass)
+{
+    auto delegate = adoptNS([[FormInputDelegate alloc] init]);
+
+    auto configuration = retainPtr([WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"BundleFormDelegatePlugIn"
+        configureJSCForTesting:NO andCustomParameterClasses:[NSSet setWithObjects:[NSUnitAcceleration class], nil]]);
+    [[configuration processPool] _setObject:@YES forBundleParameter:@"FormDelegateShouldAddCustomClass"];
+
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+    [webView _setInputDelegate:delegate.get()];
+    [webView loadHTMLString:@"<input></input><select><option selected>foo</option><option>bar</option></select>" baseURL:nil];
+    [webView _test_waitForDidFinishNavigation];
+
+    auto object = adoptNS([[BundleFormDelegateRemoteObject alloc] init]);
+    _WKRemoteObjectInterface *interface = [_WKRemoteObjectInterface remoteObjectInterfaceWithProtocol:@protocol(BundleFormDelegateProtocol)];
+    [[webView _remoteObjectRegistry] registerExportedObject:object.get() interface:interface];
+
+    [webView evaluateJavaScript:@"document.querySelector('input').focus()" completionHandler:nil];
+
+    userObject = nil;
+    didGetUserObject = false;
+
+    TestWebKitAPI::Util::run(&didGetFocus);
+    TestWebKitAPI::Util::run(&didGetUserObject);
+
+    // We should not have deserialized the NSUnitConverterLinear, since we did not specify it as valid.
+    EXPECT_NULL(delegate->_userObject);
+}
+
+#endif

Added: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/BundleFormDelegatePlugIn.mm (0 => 250093)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/BundleFormDelegatePlugIn.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/BundleFormDelegatePlugIn.mm	2019-09-19 16:11:31 UTC (rev 250093)
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2019 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 "BundleFormDelegateProtocol.h"
+#import "PlatformUtilities.h"
+#import <WebKit/WKWebProcessPlugIn.h>
+#import <WebKit/WKWebProcessPlugInBrowserContextControllerPrivate.h>
+#import <WebKit/WKWebProcessPlugInFormDelegatePrivate.h>
+#import <WebKit/WKWebProcessPlugInFrame.h>
+#import <WebKit/WKWebProcessPlugInScriptWorld.h>
+#import <WebKit/_WKRemoteObjectInterface.h>
+#import <WebKit/_WKRemoteObjectRegistry.h>
+#import <wtf/RetainPtr.h>
+
+@interface BundleFormDelegatePlugIn : NSObject <WKWebProcessPlugIn, WKWebProcessPlugInFormDelegatePrivate>
+@end
+
+@implementation BundleFormDelegatePlugIn {
+    RetainPtr<WKWebProcessPlugInBrowserContextController> _browserContextController;
+    RetainPtr<WKWebProcessPlugInController> _plugInController;
+    RetainPtr<id <BundleFormDelegateProtocol>> _remoteObject;
+    BOOL _shouldUseCustomClass;
+}
+
+- (void)webProcessPlugIn:(WKWebProcessPlugInController *)plugInController didCreateBrowserContextController:(WKWebProcessPlugInBrowserContextController *)browserContextController
+{
+    ASSERT(!_browserContextController);
+    ASSERT(!_plugInController);
+    _browserContextController = browserContextController;
+    _plugInController = plugInController;
+
+    if (id shouldAddCustomClass = [plugInController.parameters valueForKey:@"FormDelegateShouldAddCustomClass"]) {
+        ASSERT([shouldAddCustomClass isKindOfClass:[NSNumber class]]);
+        _shouldUseCustomClass = [(NSNumber *)shouldAddCustomClass boolValue];
+    } else
+        _shouldUseCustomClass = NO;
+
+    _WKRemoteObjectInterface *interface = [_WKRemoteObjectInterface remoteObjectInterfaceWithProtocol:@protocol(BundleFormDelegateProtocol)];
+    _remoteObject = [browserContextController._remoteObjectRegistry remoteObjectProxyWithInterface:interface];
+
+    [_browserContextController _setFormDelegate:self];
+}
+
+- (NSObject <NSSecureCoding> *)_webProcessPlugInBrowserContextController:(WKWebProcessPlugInBrowserContextController *)controller willBeginInputSessionForElement:(WKWebProcessPlugInNodeHandle *)node inFrame:(WKWebProcessPlugInFrame *)frame userIsInteracting:(BOOL)userIsInteracting
+{
+    if (!_shouldUseCustomClass)
+        return nil;
+
+    NSUnitConverterLinear *kilometersToMeters = [[NSUnitConverterLinear alloc] initWithCoefficient:1000.0 constant:0.0];
+
+    return [kilometersToMeters autorelease];
+}
+
+- (void)_webProcessPlugInBrowserContextController:(WKWebProcessPlugInBrowserContextController *)controller didFocusTextField:(WKWebProcessPlugInNodeHandle *)textField inFrame:(WKWebProcessPlugInFrame *)frame
+{
+    [_remoteObject didGetFocus];
+}
+
+@end

Copied: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/BundleFormDelegateProtocol.h (from rev 250092, trunk/Tools/TestWebKitAPI/WKWebViewConfigurationExtras.h) (0 => 250093)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/BundleFormDelegateProtocol.h	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/BundleFormDelegateProtocol.h	2019-09-19 16:11:31 UTC (rev 250093)
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2019 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 <WebKit/WKFoundation.h>
+
+#import <WebKit/WKWebProcessPlugInFormDelegatePrivate.h>
+
+@protocol BundleFormDelegateProtocol <NSObject>
+
+- (void)didGetFocus;
+
+@end

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKProcessPoolConfiguration.mm (250092 => 250093)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKProcessPoolConfiguration.mm	2019-09-19 15:52:43 UTC (rev 250092)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKProcessPoolConfiguration.mm	2019-09-19 16:11:31 UTC (rev 250093)
@@ -35,7 +35,14 @@
 {
     auto configuration = adoptNS([[_WKProcessPoolConfiguration alloc] init]);
 
+#if PLATFORM(IOS_FAMILY)
+    NSSet<Class> *testSet = [NSSet setWithObjects:[UIColor class], nil];
+#else
+    NSSet<Class> *testSet = [NSSet setWithObjects:[NSColor class], nil];
+#endif
+    
     [configuration setInjectedBundleURL:[NSURL fileURLWithPath:@"/path/to/injected.wkbundle"]];
+    [configuration setCustomClassesForParameterCoder:testSet];
     [configuration setCustomWebContentServiceBundleIdentifier:@"org.webkit.WebContent.custom"];
     [configuration setIgnoreSynchronousMessagingTimeoutsForTesting:YES];
     [configuration setAttrStyleEnabled:YES];
@@ -61,6 +68,7 @@
     auto copy = adoptNS([configuration copy]);
 
     EXPECT_TRUE([[configuration injectedBundleURL] isEqual:[copy injectedBundleURL]]);
+    EXPECT_TRUE([[copy customClassesForParameterCoder] isEqualToSet:testSet]);
     EXPECT_TRUE([[configuration customWebContentServiceBundleIdentifier] isEqual:[copy customWebContentServiceBundleIdentifier]]);
     EXPECT_EQ([configuration ignoreSynchronousMessagingTimeoutsForTesting], [copy ignoreSynchronousMessagingTimeoutsForTesting]);
     EXPECT_EQ([configuration attrStyleEnabled], [copy attrStyleEnabled]);

Modified: trunk/Tools/TestWebKitAPI/WKWebViewConfigurationExtras.h (250092 => 250093)


--- trunk/Tools/TestWebKitAPI/WKWebViewConfigurationExtras.h	2019-09-19 15:52:43 UTC (rev 250092)
+++ trunk/Tools/TestWebKitAPI/WKWebViewConfigurationExtras.h	2019-09-19 16:11:31 UTC (rev 250093)
@@ -28,4 +28,5 @@
 @interface WKWebViewConfiguration (TestWebKitAPIExtras)
 + (instancetype)_test_configurationWithTestPlugInClassName:(NSString *)className;
 + (instancetype)_test_configurationWithTestPlugInClassName:(NSString *)className configureJSCForTesting:(BOOL)value;
++ (instancetype)_test_configurationWithTestPlugInClassName:(NSString *)className configureJSCForTesting:(BOOL)value andCustomParameterClasses:(NSSet<Class> *)parameterClasses;
 @end

Modified: trunk/Tools/TestWebKitAPI/WKWebViewConfigurationExtras.mm (250092 => 250093)


--- trunk/Tools/TestWebKitAPI/WKWebViewConfigurationExtras.mm	2019-09-19 15:52:43 UTC (rev 250092)
+++ trunk/Tools/TestWebKitAPI/WKWebViewConfigurationExtras.mm	2019-09-19 16:11:31 UTC (rev 250093)
@@ -40,10 +40,16 @@
 
 + (instancetype)_test_configurationWithTestPlugInClassName:(NSString *)className configureJSCForTesting:(BOOL)value
 {
+    return [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:className configureJSCForTesting:value andCustomParameterClasses:nil];
+}
+
++ (instancetype)_test_configurationWithTestPlugInClassName:(NSString *)className configureJSCForTesting:(BOOL)value andCustomParameterClasses:(NSSet<Class> *)parameterClasses
+{
     auto processPoolConfiguration = adoptNS([[_WKProcessPoolConfiguration alloc] init]);
     [processPoolConfiguration setInjectedBundleURL:[[NSBundle mainBundle] URLForResource:@"TestWebKitAPI" withExtension:@"wkbundle"]];
     [processPoolConfiguration setConfigureJSCForTesting:value];
-
+    [processPoolConfiguration setCustomClassesForParameterCoder: parameterClasses];
+    
     auto processPool = adoptNS([[WKProcessPool alloc] _initWithConfiguration:processPoolConfiguration.get()]);
     [processPool _setObject:className forBundleParameter:TestWebKitAPI::Util::TestPlugInClassNameParameter];
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to