Title: [190678] trunk/Source/WebKit2
Revision
190678
Author
[email protected]
Date
2015-10-07 12:40:17 -0700 (Wed, 07 Oct 2015)

Log Message

Add -[WKProcessPool _setObjectsForBundleParametersWithDictionary:]
https://bugs.webkit.org/show_bug.cgi?id=149887

Reviewed by Tim Horton.

* UIProcess/API/Cocoa/WKProcessPool.mm:
(-[WKProcessPool _setObjectsForBundleParametersWithDictionary:]):
Copy the dictionary, archive it, and set the values on the UI side bundle parameter data struct.

* UIProcess/API/Cocoa/WKProcessPoolPrivate.h:
Add new SPI.

* WebProcess/InjectedBundle/API/Cocoa/WKWebProcessBundleParameters.h:
* WebProcess/InjectedBundle/API/Cocoa/WKWebProcessBundleParameters.mm:
(-[WKWebProcessBundleParameters setParameter:forKey:]):
We can just call setValue:forKey: on the dictionary; it will do the right thing if value is nil.

(-[WKWebProcessBundleParameters setParametersForKeyWithDictionary:]):
Enumerate the dictionary and call setValue:forKey: on each key/value pair.

* WebProcess/InjectedBundle/InjectedBundle.h:
* WebProcess/InjectedBundle/mac/InjectedBundleMac.mm:
(WebKit::InjectedBundle::setBundleParameter):
If we fail to unarchive a parameter, don't set it to null.

(WebKit::InjectedBundle::setBundleParameters):
Unarchive the dictionary and update the bundle parameters.

* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::setInjectedBundleParameters):
Call the injected bundle.

* WebProcess/WebProcess.h:
* WebProcess/WebProcess.messages.in:
Add new message.

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (190677 => 190678)


--- trunk/Source/WebKit2/ChangeLog	2015-10-07 19:28:29 UTC (rev 190677)
+++ trunk/Source/WebKit2/ChangeLog	2015-10-07 19:40:17 UTC (rev 190678)
@@ -1,3 +1,41 @@
+2015-10-07  Anders Carlsson  <[email protected]>
+
+        Add -[WKProcessPool _setObjectsForBundleParametersWithDictionary:]
+        https://bugs.webkit.org/show_bug.cgi?id=149887
+
+        Reviewed by Tim Horton.
+
+        * UIProcess/API/Cocoa/WKProcessPool.mm:
+        (-[WKProcessPool _setObjectsForBundleParametersWithDictionary:]):
+        Copy the dictionary, archive it, and set the values on the UI side bundle parameter data struct.
+
+        * UIProcess/API/Cocoa/WKProcessPoolPrivate.h:
+        Add new SPI.
+
+        * WebProcess/InjectedBundle/API/Cocoa/WKWebProcessBundleParameters.h:
+        * WebProcess/InjectedBundle/API/Cocoa/WKWebProcessBundleParameters.mm:
+        (-[WKWebProcessBundleParameters setParameter:forKey:]):
+        We can just call setValue:forKey: on the dictionary; it will do the right thing if value is nil.
+
+        (-[WKWebProcessBundleParameters setParametersForKeyWithDictionary:]):
+        Enumerate the dictionary and call setValue:forKey: on each key/value pair.
+
+        * WebProcess/InjectedBundle/InjectedBundle.h:
+        * WebProcess/InjectedBundle/mac/InjectedBundleMac.mm:
+        (WebKit::InjectedBundle::setBundleParameter):
+        If we fail to unarchive a parameter, don't set it to null.
+
+        (WebKit::InjectedBundle::setBundleParameters):
+        Unarchive the dictionary and update the bundle parameters.
+
+        * WebProcess/WebProcess.cpp:
+        (WebKit::WebProcess::setInjectedBundleParameters):
+        Call the injected bundle.
+
+        * WebProcess/WebProcess.h:
+        * WebProcess/WebProcess.messages.in:
+        Add new message.
+
 2015-10-06  Anders Carlsson  <[email protected]>
 
         Expose the bundle parameter object on WKBundleRef

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKProcessPool.mm (190677 => 190678)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKProcessPool.mm	2015-10-07 19:28:29 UTC (rev 190677)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKProcessPool.mm	2015-10-07 19:40:17 UTC (rev 190678)
@@ -188,6 +188,27 @@
     _processPool->sendToAllProcesses(Messages::WebProcess::SetInjectedBundleParameter(parameter, IPC::DataReference(static_cast<const uint8_t*>([data bytes]), [data length])));
 }
 
+- (void)_setObjectsForBundleParametersWithDictionary:(NSDictionary *)dictionary
+{
+    auto copy = adoptNS([[NSDictionary alloc] initWithDictionary:dictionary copyItems:YES]);
+
+    auto data = "" alloc] init]);
+    auto keyedArchiver = adoptNS([[NSKeyedArchiver alloc] initForWritingWithMutableData:data.get()]);
+    [keyedArchiver setRequiresSecureCoding:YES];
+
+    @try {
+        [keyedArchiver encodeObject:copy.get() forKey:@"parameters"];
+        [keyedArchiver finishEncoding];
+    } @catch (NSException *exception) {
+        LOG_ERROR("Failed to encode bundle parameters: %@", exception);
+    }
+
+    [_processPool->ensureBundleParameters() setValuesForKeysWithDictionary:copy.get()];
+
+    _processPool->sendToAllProcesses(Messages::WebProcess::SetInjectedBundleParameters(IPC::DataReference(static_cast<const uint8_t*>([data bytes]), [data length])));
+}
+
+
 - (id <_WKDownloadDelegate>)_downloadDelegate
 {
     return _downloadDelegate.getAutoreleased();

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKProcessPoolPrivate.h (190677 => 190678)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKProcessPoolPrivate.h	2015-10-07 19:28:29 UTC (rev 190677)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKProcessPoolPrivate.h	2015-10-07 19:40:17 UTC (rev 190678)
@@ -44,6 +44,8 @@
 
 - (id)_objectForBundleParameter:(NSString *)parameter;
 - (void)_setObject:(id <NSCopying, NSSecureCoding>)object forBundleParameter:(NSString *)parameter;
+// FIXME: This should be NSDictionary<NSString *, id <NSCopying, NSSecureCoding>>
+- (void)_setObjectsForBundleParametersWithDictionary:(NSDictionary *)dictionary WK_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA);
 
 @property (nonatomic, weak, setter=_setDownloadDelegate:) id <_WKDownloadDelegate> _downloadDelegate;
 

Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessBundleParameters.h (190677 => 190678)


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessBundleParameters.h	2015-10-07 19:28:29 UTC (rev 190677)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessBundleParameters.h	2015-10-07 19:40:17 UTC (rev 190678)
@@ -32,6 +32,7 @@
 - (instancetype)initWithDictionary:(NSDictionary *)dictionary;
 
 - (void)setParameter:(id)parameter forKey:(NSString *)key;
+- (void)setParametersForKeyWithDictionary:(NSDictionary *)dictionary;
 
 @end
 

Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessBundleParameters.mm (190677 => 190678)


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessBundleParameters.mm	2015-10-07 19:28:29 UTC (rev 190677)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessBundleParameters.mm	2015-10-07 19:40:17 UTC (rev 190678)
@@ -57,13 +57,17 @@
 - (void)setParameter:(id)parameter forKey:(NSString *)key
 {
     [self willChangeValueForKey:key];
-    if (parameter)
-        [_parameters setValue:parameter forKey:key];
-    else
-        [_parameters removeObjectForKey:key];
+    [_parameters setValue:parameter forKey:key];
     [self didChangeValueForKey:key];
 }
 
+- (void)setParametersForKeyWithDictionary:(NSDictionary *)dictionary
+{
+    [dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *key, id parameter, BOOL*) {
+        [self setParameter:key forKey:parameter];
+    }];
+}
+
 @end
 
 #endif

Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundle.h (190677 => 190678)


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundle.h	2015-10-07 19:28:29 UTC (rev 190677)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundle.h	2015-10-07 19:40:17 UTC (rev 190678)
@@ -87,7 +87,8 @@
 
     bool initialize(const WebProcessCreationParameters&, API::Object* initializationUserData);
 
-    void setBundleParameter(const String& key, const IPC::DataReference&);
+    void setBundleParameter(const String&, const IPC::DataReference&);
+    void setBundleParameters(const IPC::DataReference&);
 
     // API
     void initializeClient(const WKBundleClientBase*);

Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/mac/InjectedBundleMac.mm (190677 => 190678)


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/mac/InjectedBundleMac.mm	2015-10-07 19:28:29 UTC (rev 190677)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/mac/InjectedBundleMac.mm	2015-10-07 19:40:17 UTC (rev 190678)
@@ -168,6 +168,7 @@
         parameter = [unarchiver decodeObjectOfClass:[NSObject class] forKey:@"parameter"];
     } @catch (NSException *exception) {
         LOG_ERROR("Failed to decode bundle parameter: %@", exception);
+        return;
     }
 
     if (!m_bundleParameters && parameter)
@@ -177,4 +178,31 @@
 #endif
 }
 
+void InjectedBundle::setBundleParameters(const IPC::DataReference& value)
+{
+#if WK_API_ENABLED
+    auto bundleParametersData = adoptNS([[NSData alloc] initWithBytesNoCopy:const_cast<void*>(static_cast<const void*>(value.data())) length:value.size() freeWhenDone:NO]);
+
+    auto unarchiver = adoptNS([[NSKeyedUnarchiver alloc] initForReadingWithData:bundleParametersData.get()]);
+    [unarchiver setRequiresSecureCoding:YES];
+
+    NSDictionary *parameters = nil;
+    @try {
+        parameters = [unarchiver decodeObjectOfClass:[NSDictionary class] forKey:@"parameters"];
+    } @catch (NSException *exception) {
+        LOG_ERROR("Failed to decode bundle parameter: %@", exception);
+    }
+
+    if (!parameters)
+        return;
+
+    if (!m_bundleParameters) {
+        m_bundleParameters = adoptNS([[WKWebProcessBundleParameters alloc] initWithDictionary:parameters]);
+        return;
+    }
+
+    [m_bundleParameters setParametersForKeyWithDictionary:parameters];
+#endif
+}
+
 } // namespace WebKit

Modified: trunk/Source/WebKit2/WebProcess/WebProcess.cpp (190677 => 190678)


--- trunk/Source/WebKit2/WebProcess/WebProcess.cpp	2015-10-07 19:28:29 UTC (rev 190677)
+++ trunk/Source/WebKit2/WebProcess/WebProcess.cpp	2015-10-07 19:40:17 UTC (rev 190678)
@@ -1011,6 +1011,15 @@
     injectedBundle->setBundleParameter(key, value);
 }
 
+void WebProcess::setInjectedBundleParameters(const IPC::DataReference& value)
+{
+    InjectedBundle* injectedBundle = WebProcess::singleton().injectedBundle();
+    if (!injectedBundle)
+        return;
+
+    injectedBundle->setBundleParameters(value);
+}
+
 bool WebProcess::usesNetworkProcess() const
 {
 #if ENABLE(NETWORK_PROCESS)

Modified: trunk/Source/WebKit2/WebProcess/WebProcess.h (190677 => 190678)


--- trunk/Source/WebKit2/WebProcess/WebProcess.h	2015-10-07 19:28:29 UTC (rev 190677)
+++ trunk/Source/WebKit2/WebProcess/WebProcess.h	2015-10-07 19:40:17 UTC (rev 190678)
@@ -287,6 +287,7 @@
 
     void handleInjectedBundleMessage(const String& messageName, const UserData& messageBody);
     void setInjectedBundleParameter(const String& key, const IPC::DataReference&);
+    void setInjectedBundleParameters(const IPC::DataReference&);
 
     enum class ShouldAcknowledgeWhenReadyToSuspend { No, Yes };
     void actualPrepareToSuspend(ShouldAcknowledgeWhenReadyToSuspend);

Modified: trunk/Source/WebKit2/WebProcess/WebProcess.messages.in (190677 => 190678)


--- trunk/Source/WebKit2/WebProcess/WebProcess.messages.in	2015-10-07 19:28:29 UTC (rev 190677)
+++ trunk/Source/WebKit2/WebProcess/WebProcess.messages.in	2015-10-07 19:40:17 UTC (rev 190678)
@@ -77,6 +77,7 @@
     SetJavaScriptGarbageCollectorTimerEnabled(bool enable)
 
     SetInjectedBundleParameter(String parameter, IPC::DataReference value);
+    SetInjectedBundleParameters(IPC::DataReference parameters);
     HandleInjectedBundleMessage(String messageName, WebKit::UserData messageBody);
 
     ReleasePageCache()
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to