[Cocoa] Crash when setting a bundle parameter to nil
authormitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 20 Apr 2014 20:54:17 +0000 (20:54 +0000)
committermitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 20 Apr 2014 20:54:17 +0000 (20:54 +0000)
https://bugs.webkit.org/show_bug.cgi?id=131917

Reviewed by Sam Weinig.

* UIProcess/API/Cocoa/WKProcessPool.mm:
(-[WKProcessPool _setObject:forBundleParameter:]): If the object is nil, use
-[NSMutableDictionary removeObjectForKey:] rather than -setObject:forKey:.

* WebProcess/InjectedBundle/API/Cocoa/WKWebProcessBundleParameters.mm:
(-[WKWebProcessBundleParameters setParameter:forKey:]): Ditto.

* WebProcess/InjectedBundle/mac/InjectedBundleMac.mm:
(WebKit::InjectedBundle::setBundleParameter): Unrelatedly, create m_bundleParameters if
needed, as it may have not been created on intialization if no bundle parameters were set
at the time.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@167573 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/Cocoa/WKProcessPool.mm
Source/WebKit2/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessBundleParameters.mm
Source/WebKit2/WebProcess/InjectedBundle/mac/InjectedBundleMac.mm

index 20d43df..008dff4 100644 (file)
@@ -1,5 +1,24 @@
 2014-04-20  Dan Bernstein  <mitz@apple.com>
 
+        [Cocoa] Crash when setting a bundle parameter to nil
+        https://bugs.webkit.org/show_bug.cgi?id=131917
+
+        Reviewed by Sam Weinig.
+
+        * UIProcess/API/Cocoa/WKProcessPool.mm:
+        (-[WKProcessPool _setObject:forBundleParameter:]): If the object is nil, use
+        -[NSMutableDictionary removeObjectForKey:] rather than -setObject:forKey:.
+
+        * WebProcess/InjectedBundle/API/Cocoa/WKWebProcessBundleParameters.mm:
+        (-[WKWebProcessBundleParameters setParameter:forKey:]): Ditto.
+
+        * WebProcess/InjectedBundle/mac/InjectedBundleMac.mm:
+        (WebKit::InjectedBundle::setBundleParameter): Unrelatedly, create m_bundleParameters if
+        needed, as it may have not been created on intialization if no bundle parameters were set
+        at the time.
+
+2014-04-20  Dan Bernstein  <mitz@apple.com>
+
         [Cocoa] Remove unused -webView:didFinishLoadingNavigation: delegate method
         https://bugs.webkit.org/show_bug.cgi?id=131914
 
index dc69e59..aa690ca 100644 (file)
@@ -182,7 +182,11 @@ static WebKit::HTTPCookieAcceptPolicy toHTTPCookieAcceptPolicy(NSHTTPCookieAccep
         LOG_ERROR("Failed to encode bundle parameter: %@", exception);
     }
 
-    [_context->ensureBundleParameters() setObject:copy.get() forKey:parameter];
+    if (copy)
+        [_context->ensureBundleParameters() setObject:copy.get() forKey:parameter];
+    else
+        [_context->ensureBundleParameters() removeObjectForKey:parameter];
+
     _context->sendToAllProcesses(Messages::WebProcess::SetInjectedBundleParameter(parameter, IPC::DataReference(static_cast<const uint8_t*>([data bytes]), [data length])));
 }
 
index cac9d5f..3ca38cf 100644 (file)
 - (void)setParameter:(id)parameter forKey:(NSString *)key
 {
     [self willChangeValueForKey:key];
-    [_parameters setValue:parameter forKey:key];
+    if (parameter)
+        [_parameters setValue:parameter forKey:key];
+    else
+        [_parameters removeObjectForKey:key];
     [self didChangeValueForKey:key];
 }
 
index 1913d95..12e7ebb 100644 (file)
@@ -152,6 +152,9 @@ void InjectedBundle::setBundleParameter(const String& key, const IPC::DataRefere
         LOG_ERROR("Failed to decode bundle parameter: %@", exception);
     }
 
+    if (!m_bundleParameters && parameter)
+        m_bundleParameters = adoptNS([[WKWebProcessBundleParameters alloc] initWithDictionary:[NSDictionary dictionary]]);
+
     [m_bundleParameters setParameter:parameter forKey:key];
 #endif
 }