@@ -87,6 +87,18 @@ @interface WKSecureCodingArchivingDelegate : NSObject <NSKeyedArchiverDelegate,
8787@property (nonatomic , assign ) BOOL transformURLs;
8888@end
8989
90+ // WKSecureCodingURLWrapper wasn't added until about iOS 15
91+ // After that, we get XPC messages that use the system version
92+ // Objective-C is incapable of dealing with two classes of the same name,
93+ // so the only way we can work around it is renaming our class
94+ #if !PLATFORM(IOS) || __IPHONE_OS_VERSION_MIN_REQUIRED >= 150000
95+ #define HAVE_SYSTEM_WKSECURECODINGURLWRAPPER 1
96+ #endif
97+
98+ #if HAVE(SYSTEM_WKSECURECODINGURLWRAPPER)
99+ #define WKSecureCodingURLWrapper WKCyberKitSecureCodingURLWrapper
100+ #endif
101+
90102@interface WKSecureCodingURLWrapper : NSURL <NSSecureCoding >
91103- (instancetype )initWithURL : (NSURL *)wrappedURL ;
92104@property (nonatomic , readonly ) NSURL * wrappedURL;
@@ -142,8 +154,9 @@ - (id)archiver:(NSKeyedArchiver *)archiver willEncodeObject:(id)object
142154- (id )unarchiver : (NSKeyedUnarchiver *)unarchiver didDecodeObject : (id ) NS_RELEASES_ARGUMENT object NS_RETURNS_RETAINED
143155{
144156 auto adoptedObject = adoptNS (object);
145- if (auto wrapper = dynamic_objc_cast<WKSecureCodingURLWrapper>(adoptedObject.get ()))
146- return retainPtr (wrapper.wrappedURL ).leakRef ();
157+ // We know this is a WKSecureCodingURLWrapper, which one is not important
158+ if (auto wrapper = dynamic_objc_cast<NSURL >(adoptedObject.get ()))
159+ return retainPtr ([wrapper valueForKey: @" wrappedURL" ]).leakRef ();
147160
148161 if (auto wrapper = dynamic_objc_cast<WKSecureCodingCGColorWrapper>(adoptedObject.get ()))
149162 return static_cast <id >(retainPtr (wrapper.wrappedColor ).leakRef ());
@@ -591,6 +604,15 @@ static bool shouldEnableStrictMode(Decoder& decoder, const HashSet<Class>& allow
591604 allowedClasses.add (NSMutableArray .class );
592605 allowedClasses.add (NSMutableDictionary .class );
593606 allowedClasses.add (NSMutableData .class );
607+
608+ #if HAVE(SYSTEM_WKSECURECODINGURLWRAPPER)
609+ #undef WKSecureCodingURLWrapper
610+ NSBundle *bundle = [[NSBundle alloc ] initWithPath: @" /System/Library/Frameworks/WebKit.framework" ];
611+ [bundle load ];
612+ Class cls = [bundle classNamed: @" WKSecureCodingURLWrapper" ];
613+ allowedClasses.add (cls);
614+ [bundle unload ];
615+ #endif
594616 }
595617
596618 if (allowedClasses.contains (NSParagraphStyle .class ))
0 commit comments