Changeset 244299 in webkit
- Timestamp:
- Apr 15, 2019 3:21:59 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r244296 r244299 1 2019-04-15 Brent Fulgham <bfulgham@apple.com> 2 3 InjectedBundle parameters often need initialization function called before unarchiving 4 https://bugs.webkit.org/show_bug.cgi?id=189709 5 <rdar://problem/44573653> 6 7 Reviewed by Ryosuke Niwa. 8 9 Handle the case where the InjectedBundle parameters do not successfully decode because they contain 10 an unexpected class from the embedding program. If this happens, try decoding the bundle parameters 11 after the bundle initialiation function runs, which gives the embedding program the opportunity to 12 register additional classes that are safe for serialization. 13 14 Extend WKWebProcessPlugIn with a method that returns the names of any custom classes that need 15 to be serialized by the InjectedBundle. 16 17 Create a new 'decodeBundleParameters' method that contains the logic that used to live in 'initialize'. 18 Revise 'initialize' to call this new method. 19 20 * WebProcess/InjectedBundle/InjectedBundle.h: 21 * WebProcess/InjectedBundle/mac/InjectedBundleMac.mm: 22 (WebKit::InjectedBundle::initialize): Use the new method. 23 (WebKit::InjectedBundle::decodeBundleParameters): Added. 24 (WebKit::InjectedBundle::setBundleParameters): Use 'decodeObjectOfClasses' with the more complete 25 'classesForCoder' method to unarchive the passed bundle parameters, rather than the 26 NSDictionary-specific method, since InjectedBundles often encode other types of objects, and the 27 NSDictionary object may itself hold other kinds of objects. 28 * WebProcess/InjectedBundle/API/mac/WKWebProcessPlugIn.h: 29 (WebKit::WKWebProcessPlugIn::additionalClassesForParameterCoder): Added. 30 1 31 2019-04-15 Dean Jackson <dino@apple.com> 2 32 -
trunk/Source/WebKit/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugIn.h
r243376 r244299 38 38 - (void)webProcessPlugIn:(WKWebProcessPlugInController *)plugInController didCreateBrowserContextController:(WKWebProcessPlugInBrowserContextController *)browserContextController; 39 39 - (void)webProcessPlugIn:(WKWebProcessPlugInController *)plugInController willDestroyBrowserContextController:(WKWebProcessPlugInBrowserContextController *)browserContextController; 40 - (NSArray *)additionalClassesForParameterCoder; 40 41 @end 41 42 -
trunk/Source/WebKit/WebProcess/InjectedBundle/InjectedBundle.h
r242339 r244299 168 168 explicit InjectedBundle(const WebProcessCreationParameters&); 169 169 170 #if PLATFORM(COCOA) 171 void decodeBundleParameters(API::Data*); 172 #endif 173 170 174 String m_path; 171 175 PlatformBundle m_platformBundle; // This is leaked right now, since we never unload the bundle/module. -
trunk/Source/WebKit/WebProcess/InjectedBundle/mac/InjectedBundleMac.mm
r242339 r244299 74 74 #endif 75 75 76 void InjectedBundle::decodeBundleParameters(API::Data* bundleParameterDataPtr) 77 { 78 if (!bundleParameterDataPtr) 79 return; 80 81 auto bundleParameterData = adoptNS([[NSData alloc] initWithBytesNoCopy:const_cast<void*>(static_cast<const void*>(bundleParameterDataPtr->bytes())) length:bundleParameterDataPtr->size() freeWhenDone:NO]); 82 83 auto unarchiver = secureUnarchiverFromData(bundleParameterData.get()); 84 85 NSDictionary *dictionary = nil; 86 @try { 87 dictionary = [unarchiver.get() decodeObjectOfClasses:classesForCoder() forKey:@"parameters"]; 88 ASSERT([dictionary isKindOfClass:[NSDictionary class]]); 89 } @catch (NSException *exception) { 90 LOG_ERROR("Failed to decode bundle parameters: %@", exception); 91 return; 92 } 93 94 ASSERT(!m_bundleParameters || m_bundleParameters.get()); 95 m_bundleParameters = adoptNS([[WKWebProcessBundleParameters alloc] initWithDictionary:dictionary]); 96 } 97 76 98 bool InjectedBundle::initialize(const WebProcessCreationParameters& parameters, API::Object* initializationUserData) 77 99 { … … 121 143 } 122 144 123 if (parameters.bundleParameterData) {124 auto bundleParameterData = adoptNS([[NSData alloc] initWithBytesNoCopy:const_cast<void*>(static_cast<const void*>(parameters.bundleParameterData->bytes())) length:parameters.bundleParameterData->size() freeWhenDone:NO]);125 126 auto unarchiver = secureUnarchiverFromData(bundleParameterData.get());127 128 NSDictionary *dictionary = nil;129 @try {130 dictionary = [unarchiver.get() decodeObjectOfClass:[NSObject class] forKey:@"parameters"];131 ASSERT([dictionary isKindOfClass:[NSDictionary class]]);132 } @catch (NSException *exception) {133 LOG_ERROR("Failed to decode bundle parameters: %@", exception);134 }135 136 ASSERT(!m_bundleParameters);137 m_bundleParameters = adoptNS([[WKWebProcessBundleParameters alloc] initWithDictionary:dictionary]);138 }139 140 145 #if ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING) 141 146 // Swizzle [NSEvent modiferFlags], since it always returns 0 when the WindowServer is blocked. … … 150 155 if (initializeFunction) { 151 156 initializeFunction(toAPI(this), toAPI(initializationUserData)); 157 decodeBundleParameters(parameters.bundleParameterData.get()); 152 158 return true; 153 159 } … … 173 179 WKWebProcessPlugInController* plugInController = WebKit::wrapper(*this); 174 180 [plugInController _setPrincipalClassInstance:instance]; 181 182 if ([instance respondsToSelector:@selector(additionalClassesForParameterCoder)]) 183 [plugInController extendClassesForParameterCoder:[instance additionalClassesForParameterCoder]]; 184 185 decodeBundleParameters(parameters.bundleParameterData.get()); 175 186 176 187 if ([instance respondsToSelector:@selector(webProcessPlugIn:initializeWithObject:)]) { … … 256 267 NSDictionary *parameters = nil; 257 268 @try { 258 parameters = [unarchiver decodeObjectOfClass :[NSDictionary class]forKey:@"parameters"];269 parameters = [unarchiver decodeObjectOfClasses:classesForCoder() forKey:@"parameters"]; 259 270 } @catch (NSException *exception) { 260 271 LOG_ERROR("Failed to decode bundle parameter: %@", exception); … … 264 275 return; 265 276 277 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION([parameters isKindOfClass:[NSDictionary class]]); 278 266 279 if (!m_bundleParameters) { 267 280 m_bundleParameters = adoptNS([[WKWebProcessBundleParameters alloc] initWithDictionary:parameters]); -
trunk/Tools/ChangeLog
r244289 r244299 1 2019-04-15 Brent Fulgham <bfulgham@apple.com> 2 3 InjectedBundle parameters often need initialization function called before unarchiving 4 https://bugs.webkit.org/show_bug.cgi?id=189709 5 <rdar://problem/44573653> 6 7 Reviewed by Ryosuke Niwa. 8 9 * TestWebKitAPI/cocoa/WebProcessPlugIn/WebProcessPlugIn.mm: 10 (-[WebProcessPlugIn additionalClassesForParameterCoder]): Added. 11 1 12 2019-04-12 Ryosuke Niwa <rniwa@webkit.org> 2 13 -
trunk/Tools/TestWebKitAPI/cocoa/WebProcessPlugIn/WebProcessPlugIn.mm
r242339 r244299 37 37 } 38 38 39 - (NSArray *)additionalClassesForParameterCoder 40 { 41 return @[@"MockContentFilterEnabler"]; 42 } 43 39 44 - (void)webProcessPlugIn:(WKWebProcessPlugInController *)plugInController initializeWithObject:(id)initializationObject 40 45 {
Note: See TracChangeset
for help on using the changeset viewer.