Changeset 233207 in webkit
- Timestamp:
- Jun 26, 2018 11:16:57 AM (6 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 9 edited
- 3 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r233203 r233207 1 2018-06-26 Brent Fulgham <bfulgham@apple.com> 2 3 Provide a way for Injected Bundles to indicate classes approved for NSSecureCoding 4 https://bugs.webkit.org/show_bug.cgi?id=186788 5 <rdar://problem/41094167> 6 7 Reviewed by Chris Dumez. 8 9 InjectedBundles support a mechanism to serialize data between the UIProcess and the 10 WebContent process hosting the bundle. In some cases, we want to be able to serialize 11 a custom data object that is not part of WebKit's native data types. 12 13 After switching to strict NSSecureCoding, WebKit clients attempting to serialize these 14 custom objects trigger a failure. 15 16 This patch makes it possible for the InjectedBundle author to specify one (or more) data 17 classes that are allowed to be serialized between the two processes. 18 19 * WebProcess/InjectedBundle/API/c/WKBundle.cpp: 20 (WKBundleExtendClassesForParameterCoder): Added. 21 * WebProcess/InjectedBundle/API/c/WKBundlePrivate.h: 22 * WebProcess/InjectedBundle/API/mac/WKWebProcessPlugIn.h: 23 * WebProcess/InjectedBundle/API/mac/WKWebProcessPlugIn.mm: 24 (createWKArray): Added. 25 (-[WKWebProcessPlugInController extendClassesForParameterCoder:]): Added. 26 * WebProcess/InjectedBundle/InjectedBundle.h: 27 * WebProcess/InjectedBundle/mac/InjectedBundleMac.mm: 28 (WebKit::InjectedBundle::extendClassesForParameterCoder): Added. 29 (WebKit::InjectedBundle::classesForCoder): New helper function. 30 (WebKit::InjectedBundle::setBundleParameter): Modified to use the new set of valid 31 classes for NSSecureCoding. 32 1 33 2018-06-26 Eric Carlson <eric.carlson@apple.com> 2 34 -
trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundle.cpp
r226510 r233207 294 294 ResourceLoadObserver::shared().notifyObserver(); 295 295 } 296 297 298 void WKBundleExtendClassesForParameterCoder(WKBundleRef bundle, WKArrayRef classes) 299 { 300 #if WK_API_ENABLED 301 auto classList = WebKit::toImpl(classes); 302 if (!classList) 303 return; 304 305 toImpl(bundle)->extendClassesForParameterCoder(*classList); 306 #endif 307 } -
trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePrivate.h
r223565 r233207 95 95 WK_EXPORT void WKBundleResourceLoadStatisticsNotifyObserver(WKBundleRef); 96 96 97 WK_EXPORT void WKBundleExtendClassesForParameterCoder(WKBundleRef bundle, WKArrayRef classes); 98 97 99 #ifdef __cplusplus 98 100 } -
trunk/Source/WebKit/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugIn.h
r202789 r233207 44 44 WK_CLASS_AVAILABLE(macosx(10.10), ios(8.0)) 45 45 @interface WKWebProcessPlugInController : NSObject 46 - (void)extendClassesForParameterCoder:(NSArray *)classes; 46 47 47 48 @property (readonly) WKConnection *connection; -
trunk/Source/WebKit/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugIn.mm
r232520 r233207 1 1 /* 2 * Copyright (C) 2012 Apple Inc. All rights reserved.2 * Copyright (C) 2012-2018 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 29 29 #if WK_API_ENABLED 30 30 31 #import "APIArray.h" 31 32 #import "WKConnectionInternal.h" 32 33 #import "WKBundle.h" 33 34 #import "WKBundleAPICast.h" 34 35 #import "WKRetainPtr.h" 36 #import "WKStringCF.h" 35 37 #import "WKWebProcessPlugInBrowserContextControllerInternal.h" 36 38 #import <wtf/RetainPtr.h> … … 102 104 } 103 105 106 static Ref<API::Array> createWKArray(NSArray *array) 107 { 108 NSUInteger count = [array count]; 109 Vector<RefPtr<API::Object>> strings; 110 strings.reserveInitialCapacity(count); 111 112 for (id entry in array) { 113 if ([entry isKindOfClass:[NSString class]]) 114 strings.uncheckedAppend(adoptRef(toImpl(WKStringCreateWithCFString((__bridge CFStringRef)entry)))); 115 } 116 117 return API::Array::create(WTFMove(strings)); 118 } 119 120 - (void)extendClassesForParameterCoder:(NSArray *)classes 121 { 122 auto classList = createWKArray(classes); 123 _bundle->extendClassesForParameterCoder(classList.get()); 124 } 125 104 126 #pragma mark WKObject protocol implementation 105 127 -
trunk/Source/WebKit/WebProcess/InjectedBundle/InjectedBundle.h
r231798 r233207 1 1 /* 2 * Copyright (C) 2010-201 6Apple Inc. All rights reserved.2 * Copyright (C) 2010-2018 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 41 41 42 42 #if USE(FOUNDATION) 43 OBJC_CLASS NSSet; 43 44 OBJC_CLASS NSBundle; 44 45 OBJC_CLASS NSMutableDictionary; … … 157 158 #if PLATFORM(COCOA) && WK_API_ENABLED 158 159 WKWebProcessBundleParameters *bundleParameters(); 160 161 void extendClassesForParameterCoder(API::Array& classes); 162 NSSet* classesForCoder(); 159 163 #endif 160 164 … … 171 175 #if PLATFORM(COCOA) && WK_API_ENABLED 172 176 RetainPtr<WKWebProcessBundleParameters> m_bundleParameters; 177 RetainPtr<NSSet> m_classesForCoder; 173 178 #endif 174 179 }; -
trunk/Source/WebKit/WebProcess/InjectedBundle/mac/InjectedBundleMac.mm
r232520 r233207 1 1 /* 2 * Copyright (C) 2010 Apple Inc. All rights reserved.2 * Copyright (C) 2010-2018 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 27 27 #import "InjectedBundle.h" 28 28 29 #import "APIArray.h" 29 30 #import "APIData.h" 30 31 #import "ObjCObjectGraph.h" … … 37 38 #import <Foundation/NSBundle.h> 38 39 #import <dlfcn.h> 40 #import <objc/runtime.h> 39 41 #import <pal/spi/cocoa/NSKeyedArchiverSPI.h> 40 42 #import <stdio.h> … … 171 173 return m_bundleParameters.get(); 172 174 } 175 176 void InjectedBundle::extendClassesForParameterCoder(API::Array& classes) 177 { 178 size_t size = classes.size(); 179 180 auto mutableSet = adoptNS([classesForCoder() mutableCopy]); 181 182 for (size_t i = 0; i < size; ++i) { 183 API::String* classNameString = classes.at<API::String>(i); 184 if (!classNameString) { 185 WTFLogAlways("InjectedBundle::extendClassesForParameterCoder - No class provided as argument %d.\n", i); 186 break; 187 } 188 189 CString className = classNameString->string().utf8(); 190 Class objectClass = objc_lookUpClass(className.data()); 191 if (!objectClass) { 192 WTFLogAlways("InjectedBundle::extendClassesForParameterCoder - Class %s is not a valid Objective C class.\n", className.data()); 193 break; 194 } 195 196 [mutableSet.get() addObject:objectClass]; 197 } 198 199 m_classesForCoder = mutableSet; 200 } 201 202 NSSet* InjectedBundle::classesForCoder() 203 { 204 if (!m_classesForCoder) 205 m_classesForCoder = retainPtr([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]); 206 207 return m_classesForCoder.get(); 208 } 173 209 #endif 174 210 … … 182 218 id parameter = nil; 183 219 @try { 184 parameter = [unarchiver decodeObjectOfClasses: [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]forKey:@"parameter"];220 parameter = [unarchiver decodeObjectOfClasses:classesForCoder() forKey:@"parameter"]; 185 221 } @catch (NSException *exception) { 186 222 LOG_ERROR("Failed to decode bundle parameter: %@", exception); -
trunk/Tools/ChangeLog
r233190 r233207 1 2018-06-26 Brent Fulgham <bfulgham@apple.com> 2 3 Provide a way for Injected Bundles to indicate classes approved for NSSecureCoding 4 https://bugs.webkit.org/show_bug.cgi?id=186788 5 <rdar://problem/41094167> 6 7 Reviewed by Chris Dumez. 8 9 Add a new test case to exercise the class check during NSSecureCoding. 10 11 * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: 12 * TestWebKitAPI/Tests/WebKit/mac/CustomBundleObject.h: Added. 13 * TestWebKitAPI/Tests/WebKit/mac/CustomBundleObject.mm: Added. 14 (-[CustomBundleObject initWithValue:]): 15 (+[CustomBundleObject supportsSecureCoding]): 16 (-[CustomBundleObject copyWithZone:]): 17 (-[CustomBundleObject initWithCoder:]): 18 (-[CustomBundleObject encodeWithCoder:]): 19 * TestWebKitAPI/Tests/WebKit/mac/CustomBundleParameter.mm: Added. 20 (TestWebKitAPI::didReceiveMessageFromInjectedBundle): 21 (TestWebKitAPI::didFinishLoadForFrame): 22 * TestWebKitAPI/Tests/WebKit/mac/CustomBundleParameter_Bundle.mm: Added. 23 (TestWebKitAPI::CustomBundleParameterTest::CustomBundleParameterTest): 24 (TestWebKitAPI::CustomBundleParameterTest::didCreatePage): 25 1 26 2018-06-25 Daniel Bates <dabates@apple.com> 2 27 -
trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
r233025 r233207 322 322 7A95BDE11E9BEC5F00865498 /* InjectedBundleAppleEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7A95BDE01E9BEC4000865498 /* InjectedBundleAppleEvent.cpp */; }; 323 323 7A95BDE21E9BEC7400865498 /* InjectedBundleAppleEvent_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7A95BDDF1E9BEC4000865498 /* InjectedBundleAppleEvent_Bundle.cpp */; }; 324 7AC7B56D20D9769F002C09A0 /* CustomBundleParameter.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7AC7B56C20D9768F002C09A0 /* CustomBundleParameter.mm */; }; 325 7AC7B56E20D976A7002C09A0 /* CustomBundleParameter_Bundle.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7AC7B56B20D9768E002C09A0 /* CustomBundleParameter_Bundle.mm */; }; 326 7AC7B57020D9BA5B002C09A0 /* CustomBundleObject.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7AC7B56F20D9BA5B002C09A0 /* CustomBundleObject.mm */; }; 327 7AC7B57120D9BA5B002C09A0 /* CustomBundleObject.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7AC7B56F20D9BA5B002C09A0 /* CustomBundleObject.mm */; }; 324 328 7AD3FE8E1D76131200B169A4 /* TransformationMatrix.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7AD3FE8D1D75FB8D00B169A4 /* TransformationMatrix.cpp */; }; 325 329 7AE9E5091AE5AE8B00CF874B /* test.pdf in Copy Resources */ = {isa = PBXBuildFile; fileRef = 7AE9E5081AE5AE8B00CF874B /* test.pdf */; }; … … 1566 1570 7AA021BA1AB09EA70052953F /* DateMath.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DateMath.cpp; sourceTree = "<group>"; }; 1567 1571 7AA6A1511AAC0B31002B2ED3 /* WorkQueue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WorkQueue.cpp; sourceTree = "<group>"; }; 1572 7AC7B56B20D9768E002C09A0 /* CustomBundleParameter_Bundle.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = CustomBundleParameter_Bundle.mm; sourceTree = "<group>"; }; 1573 7AC7B56C20D9768F002C09A0 /* CustomBundleParameter.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = CustomBundleParameter.mm; sourceTree = "<group>"; }; 1574 7AC7B56F20D9BA5B002C09A0 /* CustomBundleObject.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = CustomBundleObject.mm; sourceTree = "<group>"; }; 1575 7AC7B57220D9BAF0002C09A0 /* CustomBundleObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomBundleObject.h; sourceTree = "<group>"; }; 1568 1576 7AD3FE8D1D75FB8D00B169A4 /* TransformationMatrix.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TransformationMatrix.cpp; sourceTree = "<group>"; }; 1569 1577 7AE9E5081AE5AE8B00CF874B /* test.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = test.pdf; sourceTree = "<group>"; }; … … 3183 3191 CD0BD0A71F7997C2001AB2CF /* ContextMenuImgWithVideo.html */, 3184 3192 CD0BD0A51F799220001AB2CF /* ContextMenuImgWithVideo.mm */, 3193 7AC7B57220D9BAF0002C09A0 /* CustomBundleObject.h */, 3194 7AC7B56F20D9BA5B002C09A0 /* CustomBundleObject.mm */, 3195 7AC7B56C20D9768F002C09A0 /* CustomBundleParameter.mm */, 3196 7AC7B56B20D9768E002C09A0 /* CustomBundleParameter_Bundle.mm */, 3185 3197 BCAA485714A044D40088FAC4 /* EditorCommands.mm */, 3186 3198 C0C5D3BC14598B6F00A802A6 /* GetBackingScaleFactor.mm */, … … 3564 3576 7AEAD47F1E20116C00416EFE /* CrossPartitionFileSchemeAccess.mm in Sources */, 3565 3577 7CCE7EDB1A411A9200447C4C /* CSSParser.cpp in Sources */, 3578 7AC7B57020D9BA5B002C09A0 /* CustomBundleObject.mm in Sources */, 3579 7AC7B56D20D9769F002C09A0 /* CustomBundleParameter.mm in Sources */, 3566 3580 7CCE7F291A411B1000447C4C /* CustomProtocolsInvalidScheme.mm in Sources */, 3567 3581 7CCE7F2A1A411B1000447C4C /* CustomProtocolsSyncXHRTest.mm in Sources */, … … 3947 3961 files = ( 3948 3962 BC246D9C132F1FF000B56D7C /* CanHandleRequest_Bundle.cpp in Sources */, 3963 7AC7B57120D9BA5B002C09A0 /* CustomBundleObject.mm in Sources */, 3964 7AC7B56E20D976A7002C09A0 /* CustomBundleParameter_Bundle.mm in Sources */, 3949 3965 297234B7173AFAC700983601 /* CustomProtocolsInvalidScheme_Bundle.cpp in Sources */, 3950 3966 F6B7BE9517469212008A3445 /* DidAssociateFormControls_Bundle.cpp in Sources */, -
trunk/Tools/TestWebKitAPI/Tests/WebKit/mac/CustomBundleObject.h
r233206 r233207 1 1 /* 2 * Copyright (C) 201 2Apple Inc. All rights reserved.2 * Copyright (C) 2018 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 24 24 */ 25 25 26 # import <WebKit/WKFoundation.h>26 #pragma once 27 27 28 #if WK_API_ENABLED 28 @interface CustomBundleObject : NSObject <NSCopying, NSSecureCoding> { 29 long _somePayload; 30 } 29 31 30 #import <Foundation/Foundation.h> 31 #import <WebKit/WKBase.h> 32 @property (nonatomic) long somePayload; 32 33 33 @class WKConnection; 34 @class WKWebProcessPlugInController; 35 @class WKWebProcessPlugInBrowserContextController; 36 37 @protocol WKWebProcessPlugIn <NSObject> 38 @optional 39 - (void)webProcessPlugIn:(WKWebProcessPlugInController *)plugInController initializeWithObject:(id)initializationObject; 40 - (void)webProcessPlugIn:(WKWebProcessPlugInController *)plugInController didCreateBrowserContextController:(WKWebProcessPlugInBrowserContextController *)browserContextController; 41 - (void)webProcessPlugIn:(WKWebProcessPlugInController *)plugInController willDestroyBrowserContextController:(WKWebProcessPlugInBrowserContextController *)browserContextController; 34 - (id)initWithValue:(long)value; 42 35 @end 43 44 WK_CLASS_AVAILABLE(macosx(10.10), ios(8.0))45 @interface WKWebProcessPlugInController : NSObject46 47 @property (readonly) WKConnection *connection;48 49 @property (readonly) id parameters;50 51 @end52 53 #endif // WK_API_ENABLED -
trunk/Tools/TestWebKitAPI/Tests/WebKit/mac/CustomBundleObject.mm
r233206 r233207 1 1 /* 2 * Copyright (C) 201 2Apple Inc. All rights reserved.2 * Copyright (C) 2018 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 24 24 */ 25 25 26 #import <WebKit/WKFoundation.h> 26 #import "config.h" 27 #import "CustomBundleObject.h" 27 28 28 #if WK_ API_ENABLED29 #if WK_HAVE_C_SPI 29 30 30 31 #import <Foundation/Foundation.h> 31 #import <WebKit/WKBase.h>32 32 33 @class WKConnection; 34 @class WKWebProcessPlugInController; 35 @class WKWebProcessPlugInBrowserContextController; 33 @implementation CustomBundleObject 36 34 37 @protocol WKWebProcessPlugIn <NSObject> 38 @optional 39 - (void)webProcessPlugIn:(WKWebProcessPlugInController *)plugInController initializeWithObject:(id)initializationObject; 40 - (void)webProcessPlugIn:(WKWebProcessPlugInController *)plugInController didCreateBrowserContextController:(WKWebProcessPlugInBrowserContextController *)browserContextController; 41 - (void)webProcessPlugIn:(WKWebProcessPlugInController *)plugInController willDestroyBrowserContextController:(WKWebProcessPlugInBrowserContextController *)browserContextController; 35 @synthesize somePayload=_somePayload; 36 37 - (id)initWithValue:(long)value 38 { 39 self = [super init]; 40 if (!self) 41 return nil; 42 43 self.somePayload = value; 44 return self; 45 } 46 47 + (BOOL)supportsSecureCoding 48 { 49 return YES; 50 } 51 52 - (id)copyWithZone:(NSZone *)zone 53 { 54 return [self retain]; 55 } 56 57 - (instancetype)initWithCoder:(NSCoder *)decoder 58 { 59 self = [super init]; 60 if (!self) 61 return nil; 62 63 self.somePayload = [decoder decodeIntForKey:@"Payload"]; 64 return self; 65 } 66 67 - (void)encodeWithCoder:(NSCoder *)coder 68 { 69 [coder encodeInt:static_cast<long>(_somePayload) forKey:@"Payload"]; 70 } 42 71 @end 43 72 44 WK_CLASS_AVAILABLE(macosx(10.10), ios(8.0)) 45 @interface WKWebProcessPlugInController : NSObject 46 47 @property (readonly) WKConnection *connection; 48 49 @property (readonly) id parameters; 50 51 @end 52 53 #endif // WK_API_ENABLED 73 #endif -
trunk/Tools/TestWebKitAPI/Tests/WebKit/mac/CustomBundleParameter_Bundle.mm
r233206 r233207 1 1 /* 2 * Copyright (C) 201 2Apple Inc. All rights reserved.2 * Copyright (C) 2017 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 24 24 */ 25 25 26 #i mport <WebKit/WKFoundation.h>26 #include "config.h" 27 27 28 #if WK_ API_ENABLED28 #if WK_HAVE_C_SPI 29 29 30 #import <Foundation/Foundation.h> 31 #import <WebKit/WKBase.h> 30 #import "CustomBundleObject.h" 31 #import "InjectedBundleTest.h" 32 #import "PlatformUtilities.h" 33 #import <WebKit/WKBundlePrivate.h> 34 #import <WebKit/WKRetainPtr.h> 35 #import <WebKit/WKStringCF.h> 32 36 33 @class WKConnection; 34 @class WKWebProcessPlugInController; 35 @class WKWebProcessPlugInBrowserContextController; 37 namespace TestWebKitAPI { 38 39 class CustomBundleParameterTest : public InjectedBundleTest { 40 public: 41 CustomBundleParameterTest(const std::string& identifier) 42 : InjectedBundleTest(identifier) 43 { 44 } 45 46 virtual void didCreatePage(WKBundleRef bundle, WKBundlePageRef page) 47 { 48 WKTypeRef typeName = WKStringCreateWithCFString((__bridge CFStringRef)[CustomBundleObject className]); 49 auto array = adoptWK(WKArrayCreateAdoptingValues(&typeName, 1)); 36 50 37 @protocol WKWebProcessPlugIn <NSObject> 38 @optional 39 - (void)webProcessPlugIn:(WKWebProcessPlugInController *)plugInController initializeWithObject:(id)initializationObject;40 - (void)webProcessPlugIn:(WKWebProcessPlugInController *)plugInController didCreateBrowserContextController:(WKWebProcessPlugInBrowserContextController *)browserContextController;41 - (void)webProcessPlugIn:(WKWebProcessPlugInController *)plugInController willDestroyBrowserContextController:(WKWebProcessPlugInBrowserContextController *)browserContextController; 42 @end 51 WKBundleExtendClassesForParameterCoder(bundle, array.get()); 52 53 WKRetainPtr<WKDoubleRef> returnCode = adoptWK(WKDoubleCreate(1234)); 54 WKBundlePostMessage(bundle, Util::toWK("DidRegisterCustomClass").get(), returnCode.get()); 55 } 56 }; 43 57 44 WK_CLASS_AVAILABLE(macosx(10.10), ios(8.0)) 45 @interface WKWebProcessPlugInController : NSObject 58 static InjectedBundleTest::Register<CustomBundleParameterTest> registrar("CustomBundleParameterTest"); 59 60 } // namespace TestWebKitAPI 46 61 47 @property (readonly) WKConnection *connection; 48 49 @property (readonly) id parameters; 50 51 @end 52 53 #endif // WK_API_ENABLED 62 #endif
Note: See TracChangeset
for help on using the changeset viewer.