<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[169422] trunk/Source/WebKit2</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/169422">169422</a></dd>
<dt>Author</dt> <dd>mitz@apple.com</dd>
<dt>Date</dt> <dd>2014-05-28 07:28:56 -0700 (Wed, 28 May 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>[Cocoa] Can't use bundle-defined classes for bundle parameters
https://bugs.webkit.org/show_bug.cgi?id=133339

Reviewed by Anders Carlsson.

Ensure that bundle parameters are decoded only after the injected bundle is loaded.

* WebProcess/InjectedBundle/InjectedBundle.cpp:
(WebKit::InjectedBundle::create): Moved the definition from the header to here, added the
lagacy initializationUserData as a parameter, and made this function set the sandbox
extension and load the bundle.
(WebKit::InjectedBundle::InjectedBundle): Removed call to platformInitialize.
* WebProcess/InjectedBundle/InjectedBundle.h:
(WebKit::InjectedBundle::setSandboxExtension): Deleted.
* WebProcess/InjectedBundle/mac/InjectedBundleMac.mm:
(WebKit::InjectedBundle::initialize): Renamed the load function to this, and added the
creation parameters as a parameter. Moved code to initialize the bundle paramters from
platformInitialize to here. Changed the class passed to -decodeObjectOfClass:forKey: to
NSObject, to allow arbitrary types in the values, and added an assertion that the
top-level object is a dictionary.
(WebKit::InjectedBundle::platformInitialize): Deleted.
* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::initializeWebProcess): Changed to pass the legacy initialization user
data to InjectedBundle::create() and removed code to separately set the sandbox extension
and load the bundle, which is now done by create().</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2WebProcessInjectedBundleInjectedBundlecpp">trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundle.cpp</a></li>
<li><a href="#trunkSourceWebKit2WebProcessInjectedBundleInjectedBundleh">trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundle.h</a></li>
<li><a href="#trunkSourceWebKit2WebProcessInjectedBundleeflInjectedBundleEflcpp">trunk/Source/WebKit2/WebProcess/InjectedBundle/efl/InjectedBundleEfl.cpp</a></li>
<li><a href="#trunkSourceWebKit2WebProcessInjectedBundlegtkInjectedBundleGtkcpp">trunk/Source/WebKit2/WebProcess/InjectedBundle/gtk/InjectedBundleGtk.cpp</a></li>
<li><a href="#trunkSourceWebKit2WebProcessInjectedBundlemacInjectedBundleMacmm">trunk/Source/WebKit2/WebProcess/InjectedBundle/mac/InjectedBundleMac.mm</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebProcesscpp">trunk/Source/WebKit2/WebProcess/WebProcess.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (169421 => 169422)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2014-05-28 13:28:43 UTC (rev 169421)
+++ trunk/Source/WebKit2/ChangeLog        2014-05-28 14:28:56 UTC (rev 169422)
</span><span class="lines">@@ -1,3 +1,31 @@
</span><ins>+2014-05-28  Dan Bernstein  &lt;mitz@apple.com&gt;
+
+        [Cocoa] Can't use bundle-defined classes for bundle parameters
+        https://bugs.webkit.org/show_bug.cgi?id=133339
+
+        Reviewed by Anders Carlsson.
+
+        Ensure that bundle parameters are decoded only after the injected bundle is loaded.
+
+        * WebProcess/InjectedBundle/InjectedBundle.cpp:
+        (WebKit::InjectedBundle::create): Moved the definition from the header to here, added the
+        lagacy initializationUserData as a parameter, and made this function set the sandbox
+        extension and load the bundle.
+        (WebKit::InjectedBundle::InjectedBundle): Removed call to platformInitialize.
+        * WebProcess/InjectedBundle/InjectedBundle.h:
+        (WebKit::InjectedBundle::setSandboxExtension): Deleted.
+        * WebProcess/InjectedBundle/mac/InjectedBundleMac.mm:
+        (WebKit::InjectedBundle::initialize): Renamed the load function to this, and added the
+        creation parameters as a parameter. Moved code to initialize the bundle paramters from
+        platformInitialize to here. Changed the class passed to -decodeObjectOfClass:forKey: to
+        NSObject, to allow arbitrary types in the values, and added an assertion that the
+        top-level object is a dictionary.
+        (WebKit::InjectedBundle::platformInitialize): Deleted.
+        * WebProcess/WebProcess.cpp:
+        (WebKit::WebProcess::initializeWebProcess): Changed to pass the legacy initialization user
+        data to InjectedBundle::create() and removed code to separately set the sandbox extension
+        and load the bundle, which is now done by create().
+
</ins><span class="cx"> 2014-05-28  Alberto Garcia  &lt;berto@igalia.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Unreviewed. Fix warning: unused parameter 'frame'
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessInjectedBundleInjectedBundlecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundle.cpp (169421 => 169422)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundle.cpp        2014-05-28 13:28:43 UTC (rev 169421)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundle.cpp        2014-05-28 14:28:56 UTC (rev 169422)
</span><span class="lines">@@ -85,11 +85,21 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebKit {
</span><span class="cx"> 
</span><ins>+PassRefPtr&lt;InjectedBundle&gt; InjectedBundle::create(const WebProcessCreationParameters&amp; parameters, API::Object* initializationUserData)
+{
+    RefPtr&lt;InjectedBundle&gt; bundle = adoptRef(new InjectedBundle(parameters));
+
+    bundle-&gt;m_sandboxExtension = SandboxExtension::create(parameters.injectedBundlePathExtensionHandle);
+    if (!bundle-&gt;initialize(parameters, initializationUserData))
+        return nullptr;
+
+    return bundle.release();
+}
+
</ins><span class="cx"> InjectedBundle::InjectedBundle(const WebProcessCreationParameters&amp; parameters)
</span><span class="cx">     : m_path(parameters.injectedBundlePath)
</span><span class="cx">     , m_platformBundle(0)
</span><span class="cx"> {
</span><del>-    platformInitialize(parameters);
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> InjectedBundle::~InjectedBundle()
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessInjectedBundleInjectedBundleh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundle.h (169421 => 169422)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundle.h        2014-05-28 13:28:43 UTC (rev 169421)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundle.h        2014-05-28 14:28:56 UTC (rev 169422)
</span><span class="lines">@@ -81,14 +81,11 @@
</span><span class="cx"> 
</span><span class="cx"> class InjectedBundle : public API::ObjectImpl&lt;API::Object::Type::Bundle&gt; {
</span><span class="cx"> public:
</span><del>-    static PassRefPtr&lt;InjectedBundle&gt; create(const WebProcessCreationParameters&amp; parameters)
-    {
-        return adoptRef(new InjectedBundle(parameters));
-    }
</del><ins>+    static PassRefPtr&lt;InjectedBundle&gt; create(const WebProcessCreationParameters&amp;, API::Object* initializationUserData);
+
</ins><span class="cx">     ~InjectedBundle();
</span><span class="cx"> 
</span><del>-    bool load(API::Object* initializationUserData);
-    void setSandboxExtension(PassRefPtr&lt;SandboxExtension&gt; sandboxExtension) { m_sandboxExtension = sandboxExtension; }
</del><ins>+    bool initialize(const WebProcessCreationParameters&amp;, API::Object* initializationUserData);
</ins><span class="cx"> 
</span><span class="cx">     void setBundleParameter(const String&amp; key, const IPC::DataReference&amp;);
</span><span class="cx"> 
</span><span class="lines">@@ -181,8 +178,6 @@
</span><span class="cx"> private:
</span><span class="cx">     explicit InjectedBundle(const WebProcessCreationParameters&amp;);
</span><span class="cx"> 
</span><del>-    void platformInitialize(const WebProcessCreationParameters&amp;);
-
</del><span class="cx">     String m_path;
</span><span class="cx">     PlatformBundle m_platformBundle; // This is leaked right now, since we never unload the bundle/module.
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessInjectedBundleeflInjectedBundleEflcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/efl/InjectedBundleEfl.cpp (169421 => 169422)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/InjectedBundle/efl/InjectedBundleEfl.cpp        2014-05-28 13:28:43 UTC (rev 169421)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/efl/InjectedBundleEfl.cpp        2014-05-28 14:28:56 UTC (rev 169422)
</span><span class="lines">@@ -34,7 +34,7 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebKit {
</span><span class="cx"> 
</span><del>-bool InjectedBundle::load(API::Object* initializationUserData)
</del><ins>+bool InjectedBundle::initialize(const WebProcessCreationParameters&amp;, API::Object* initializationUserData)
</ins><span class="cx"> {
</span><span class="cx">     m_platformBundle = eina_module_new(m_path.utf8().data());
</span><span class="cx">     if (!m_platformBundle) {
</span><span class="lines">@@ -66,8 +66,4 @@
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void InjectedBundle::platformInitialize(const WebProcessCreationParameters&amp;)
-{
-}
-
</del><span class="cx"> } // namespace WebKit
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessInjectedBundlegtkInjectedBundleGtkcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/gtk/InjectedBundleGtk.cpp (169421 => 169422)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/InjectedBundle/gtk/InjectedBundleGtk.cpp        2014-05-28 13:28:43 UTC (rev 169421)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/gtk/InjectedBundleGtk.cpp        2014-05-28 14:28:56 UTC (rev 169422)
</span><span class="lines">@@ -36,7 +36,7 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebKit {
</span><span class="cx"> 
</span><del>-bool InjectedBundle::load(API::Object* initializationUserData)
</del><ins>+bool InjectedBundle::initialize(const WebProcessCreationParameters&amp;, API::Object* initializationUserData)
</ins><span class="cx"> {
</span><span class="cx">     m_platformBundle = g_module_open(fileSystemRepresentation(m_path).data(), G_MODULE_BIND_LOCAL);
</span><span class="cx">     if (!m_platformBundle) {
</span><span class="lines">@@ -58,10 +58,6 @@
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void InjectedBundle::platformInitialize(const WebProcessCreationParameters&amp;)
-{
-}
-
</del><span class="cx"> void InjectedBundle::setBundleParameter(WTF::String const&amp;, IPC::DataReference const&amp;)
</span><span class="cx"> {
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessInjectedBundlemacInjectedBundleMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/mac/InjectedBundleMac.mm (169421 => 169422)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/InjectedBundle/mac/InjectedBundleMac.mm        2014-05-28 13:28:43 UTC (rev 169421)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/mac/InjectedBundleMac.mm        2014-05-28 14:28:56 UTC (rev 169422)
</span><span class="lines">@@ -47,7 +47,7 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebKit {
</span><span class="cx"> 
</span><del>-bool InjectedBundle::load(API::Object* initializationUserData)
</del><ins>+bool InjectedBundle::initialize(const WebProcessCreationParameters&amp; parameters, API::Object* initializationUserData)
</ins><span class="cx"> {
</span><span class="cx">     if (m_sandboxExtension) {
</span><span class="cx">         if (!m_sandboxExtension-&gt;consumePermanently()) {
</span><span class="lines">@@ -89,6 +89,23 @@
</span><span class="cx">     }
</span><span class="cx">     
</span><span class="cx"> #if WK_API_ENABLED
</span><ins>+    if (parameters.bundleParameterData) {
+        auto bundleParameterData = adoptNS([[NSData alloc] initWithBytesNoCopy:const_cast&lt;void*&gt;(static_cast&lt;const void*&gt;(parameters.bundleParameterData-&gt;bytes())) length:parameters.bundleParameterData-&gt;size() freeWhenDone:NO]);
+
+        auto unarchiver = adoptNS([[NSKeyedUnarchiver alloc] initForReadingWithData:bundleParameterData.get()]);
+        [unarchiver setRequiresSecureCoding:YES];
+
+        NSDictionary *dictionary = nil;
+        @try {
+            dictionary = [unarchiver.get() decodeObjectOfClass:[NSObject class] forKey:@&quot;parameters&quot;];
+            ASSERT([dictionary isKindOfClass:[NSDictionary class]]);
+        } @catch (NSException *exception) {
+            LOG_ERROR(&quot;Failed to decode bundle parameters: %@&quot;, exception);
+        }
+
+        m_bundleParameters = adoptNS([[WKWebProcessBundleParameters alloc] initWithDictionary:dictionary]);
+    }
+
</ins><span class="cx">     // Otherwise, look to see if the bundle has a principal class
</span><span class="cx">     Class principalClass = [m_platformBundle principalClass];
</span><span class="cx">     if (!principalClass) {
</span><span class="lines">@@ -162,27 +179,4 @@
</span><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-
-void InjectedBundle::platformInitialize(const WebProcessCreationParameters&amp; parameters)
-{
-#if WK_API_ENABLED
-    if (!parameters.bundleParameterData)
-        return;
-
-    auto bundleParameterData = adoptNS([[NSData alloc] initWithBytesNoCopy:const_cast&lt;void*&gt;(static_cast&lt;const void*&gt;(parameters.bundleParameterData-&gt;bytes())) length:parameters.bundleParameterData-&gt;size() freeWhenDone:NO]);
-
-    auto unarchiver = adoptNS([[NSKeyedUnarchiver alloc] initForReadingWithData:bundleParameterData.get()]);
-    [unarchiver setRequiresSecureCoding:YES];
-
-    NSDictionary *dictionary = nil;
-    @try {
-        dictionary = [unarchiver.get() decodeObjectOfClass:[NSDictionary class] forKey:@&quot;parameters&quot;];
-    } @catch (NSException *exception) {
-        LOG_ERROR(&quot;Failed to decode bundle parameters: %@&quot;, exception);
-    }
-
-    m_bundleParameters = adoptNS([[WKWebProcessBundleParameters alloc] initWithDictionary:dictionary]);
-#endif
-}
-
</del><span class="cx"> } // namespace WebKit
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebProcesscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebProcess.cpp (169421 => 169422)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebProcess.cpp        2014-05-28 13:28:43 UTC (rev 169421)
+++ trunk/Source/WebKit2/WebProcess/WebProcess.cpp        2014-05-28 14:28:56 UTC (rev 169422)
</span><span class="lines">@@ -277,16 +277,9 @@
</span><span class="cx">     if (!decoder.decode(messageDecoder))
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    if (!parameters.injectedBundlePath.isEmpty()) {
-        m_injectedBundle = InjectedBundle::create(parameters);
-        m_injectedBundle-&gt;setSandboxExtension(SandboxExtension::create(parameters.injectedBundlePathExtensionHandle));
</del><ins>+    if (!parameters.injectedBundlePath.isEmpty())
+        m_injectedBundle = InjectedBundle::create(parameters, injectedBundleInitializationUserData.get());
</ins><span class="cx"> 
</span><del>-        if (!m_injectedBundle-&gt;load(injectedBundleInitializationUserData.get())) {
-            // Don't keep around the InjectedBundle reference if the load fails.
-            m_injectedBundle.clear();
-        }
-    }
-
</del><span class="cx">     WebProcessSupplementMap::const_iterator it = m_supplements.begin();
</span><span class="cx">     WebProcessSupplementMap::const_iterator end = m_supplements.end();
</span><span class="cx">     for (; it != end; ++it)
</span></span></pre>
</div>
</div>

</body>
</html>