<!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>[164808] 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/164808">164808</a></dd>
<dt>Author</dt> <dd>carlosgc@webkit.org</dd>
<dt>Date</dt> <dd>2014-02-27 09:59:16 -0800 (Thu, 27 Feb 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>[GTK][WK2] Blocks when fetching plugins information
https://bugs.webkit.org/show_bug.cgi?id=115650

Reviewed by Gustavo Noronha Silva.

Use a persistent cache to store the plugins metadata to avoid
having to load all the plugins everytime a plugin is used for the
first time.

* GNUmakefile.am:
* GNUmakefile.list.am:
* PlatformGTK.cmake:
* Shared/Plugins/Netscape/NetscapePluginModule.h:
* Shared/Plugins/Netscape/x11/NetscapePluginModuleX11.cpp:
(WebKit::NetscapePluginModule::parseMIMEDescription): Make this
method public.
(WebKit::NetscapePluginModule::buildMIMEDescription): Added this
helper to build the MIME description string.
* UIProcess/Plugins/gtk/PluginInfoCache.cpp: Added.
(WebKit::PluginInfoCache::shared):
(WebKit::PluginInfoCache::PluginInfoCache):
(WebKit::PluginInfoCache::~PluginInfoCache):
(WebKit::PluginInfoCache::saveToFileIdleCallback):
(WebKit::PluginInfoCache::saveToFile):
(WebKit::PluginInfoCache::getPluginInfo):
(WebKit::PluginInfoCache::updatePluginInfo):
* UIProcess/Plugins/gtk/PluginInfoCache.h: Added.
* UIProcess/Plugins/unix/PluginInfoStoreUnix.cpp:
(WebKit::PluginInfoStore::getPluginInfo): Check first if we have
metadata of the plugin in the cache and update the cache if we
loaded the plugin to get its metadata.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2GNUmakefileam">trunk/Source/WebKit2/GNUmakefile.am</a></li>
<li><a href="#trunkSourceWebKit2GNUmakefilelistam">trunk/Source/WebKit2/GNUmakefile.list.am</a></li>
<li><a href="#trunkSourceWebKit2PlatformGTKcmake">trunk/Source/WebKit2/PlatformGTK.cmake</a></li>
<li><a href="#trunkSourceWebKit2SharedPluginsNetscapeNetscapePluginModuleh">trunk/Source/WebKit2/Shared/Plugins/Netscape/NetscapePluginModule.h</a></li>
<li><a href="#trunkSourceWebKit2SharedPluginsNetscapex11NetscapePluginModuleX11cpp">trunk/Source/WebKit2/Shared/Plugins/Netscape/x11/NetscapePluginModuleX11.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessPluginsunixPluginInfoStoreUnixcpp">trunk/Source/WebKit2/UIProcess/Plugins/unix/PluginInfoStoreUnix.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li>trunk/Source/WebKit2/UIProcess/Plugins/gtk/</li>
<li><a href="#trunkSourceWebKit2UIProcessPluginsgtkPluginInfoCachecpp">trunk/Source/WebKit2/UIProcess/Plugins/gtk/PluginInfoCache.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessPluginsgtkPluginInfoCacheh">trunk/Source/WebKit2/UIProcess/Plugins/gtk/PluginInfoCache.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (164807 => 164808)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2014-02-27 17:49:45 UTC (rev 164807)
+++ trunk/Source/WebKit2/ChangeLog        2014-02-27 17:59:16 UTC (rev 164808)
</span><span class="lines">@@ -1,3 +1,37 @@
</span><ins>+2014-02-27  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
+
+        [GTK][WK2] Blocks when fetching plugins information
+        https://bugs.webkit.org/show_bug.cgi?id=115650
+
+        Reviewed by Gustavo Noronha Silva.
+
+        Use a persistent cache to store the plugins metadata to avoid
+        having to load all the plugins everytime a plugin is used for the
+        first time.
+
+        * GNUmakefile.am:
+        * GNUmakefile.list.am:
+        * PlatformGTK.cmake:
+        * Shared/Plugins/Netscape/NetscapePluginModule.h:
+        * Shared/Plugins/Netscape/x11/NetscapePluginModuleX11.cpp:
+        (WebKit::NetscapePluginModule::parseMIMEDescription): Make this
+        method public.
+        (WebKit::NetscapePluginModule::buildMIMEDescription): Added this
+        helper to build the MIME description string.
+        * UIProcess/Plugins/gtk/PluginInfoCache.cpp: Added.
+        (WebKit::PluginInfoCache::shared):
+        (WebKit::PluginInfoCache::PluginInfoCache):
+        (WebKit::PluginInfoCache::~PluginInfoCache):
+        (WebKit::PluginInfoCache::saveToFileIdleCallback):
+        (WebKit::PluginInfoCache::saveToFile):
+        (WebKit::PluginInfoCache::getPluginInfo):
+        (WebKit::PluginInfoCache::updatePluginInfo):
+        * UIProcess/Plugins/gtk/PluginInfoCache.h: Added.
+        * UIProcess/Plugins/unix/PluginInfoStoreUnix.cpp:
+        (WebKit::PluginInfoStore::getPluginInfo): Check first if we have
+        metadata of the plugin in the cache and update the cache if we
+        loaded the plugin to get its metadata.
+
</ins><span class="cx"> 2014-02-27  Ryan Lortie  &lt;desrt@desrt.ca&gt;
</span><span class="cx"> 
</span><span class="cx">         need to #include &lt;libgen.h&gt; for basename
</span></span></pre></div>
<a id="trunkSourceWebKit2GNUmakefileam"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/GNUmakefile.am (164807 => 164808)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/GNUmakefile.am        2014-02-27 17:49:45 UTC (rev 164807)
+++ trunk/Source/WebKit2/GNUmakefile.am        2014-02-27 17:59:16 UTC (rev 164808)
</span><span class="lines">@@ -126,6 +126,7 @@
</span><span class="cx">         -I$(srcdir)/Source/WebKit2/UIProcess/Network/CustomProtocols/soup \
</span><span class="cx">         -I$(srcdir)/Source/WebKit2/UIProcess/Notifications \
</span><span class="cx">         -I$(srcdir)/Source/WebKit2/UIProcess/Plugins \
</span><ins>+        -I$(srcdir)/Source/WebKit2/UIProcess/Plugins/gtk \
</ins><span class="cx">         -I$(srcdir)/Source/WebKit2/UIProcess/Plugins/unix \
</span><span class="cx">         -I$(srcdir)/Source/WebKit2/UIProcess/Storage \
</span><span class="cx">         -I$(srcdir)/Source/WebKit2/UIProcess/soup \
</span></span></pre></div>
<a id="trunkSourceWebKit2GNUmakefilelistam"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/GNUmakefile.list.am (164807 => 164808)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/GNUmakefile.list.am        2014-02-27 17:49:45 UTC (rev 164807)
+++ trunk/Source/WebKit2/GNUmakefile.list.am        2014-02-27 17:59:16 UTC (rev 164808)
</span><span class="lines">@@ -866,6 +866,8 @@
</span><span class="cx">         Source/WebKit2/UIProcess/Plugins/PluginProcessProxy.h \
</span><span class="cx">         Source/WebKit2/UIProcess/Plugins/WebPluginSiteDataManager.h \
</span><span class="cx">         Source/WebKit2/UIProcess/Plugins/WebPluginSiteDataManager.cpp \
</span><ins>+        Source/WebKit2/UIProcess/Plugins/gtk/PluginInfoCache.cpp \
+        Source/WebKit2/UIProcess/Plugins/gtk/PluginInfoCache.h \
</ins><span class="cx">         Source/WebKit2/UIProcess/Plugins/unix/PluginInfoStoreUnix.cpp \
</span><span class="cx">         Source/WebKit2/UIProcess/Plugins/unix/PluginProcessProxyUnix.cpp \
</span><span class="cx">         Source/WebKit2/UIProcess/ProcessModel.h \
</span></span></pre></div>
<a id="trunkSourceWebKit2PlatformGTKcmake"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/PlatformGTK.cmake (164807 => 164808)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/PlatformGTK.cmake        2014-02-27 17:49:45 UTC (rev 164807)
+++ trunk/Source/WebKit2/PlatformGTK.cmake        2014-02-27 17:59:16 UTC (rev 164808)
</span><span class="lines">@@ -248,6 +248,8 @@
</span><span class="cx">     UIProcess/Network/CustomProtocols/soup/WebSoupCustomProtocolRequestManagerClient.cpp
</span><span class="cx">     UIProcess/Network/CustomProtocols/soup/WebSoupCustomProtocolRequestManager.cpp
</span><span class="cx"> 
</span><ins>+    UIProcess/Plugins/gtk/PluginInfoCache.cpp
+
</ins><span class="cx">     UIProcess/Plugins/unix/PluginInfoStoreUnix.cpp
</span><span class="cx">     UIProcess/Plugins/unix/PluginProcessProxyUnix.cpp
</span><span class="cx"> 
</span><span class="lines">@@ -409,6 +411,7 @@
</span><span class="cx">     &quot;${WEBKIT2_DIR}/UIProcess/API/cpp/gtk&quot;
</span><span class="cx">     &quot;${WEBKIT2_DIR}/UIProcess/API/gtk&quot;
</span><span class="cx">     &quot;${WEBKIT2_DIR}/UIProcess/Network/CustomProtocols/soup&quot;
</span><ins>+    &quot;${WEBKIT2_DIR}/UIProcess/Plugins/gtk&quot;
</ins><span class="cx">     &quot;${WEBKIT2_DIR}/UIProcess/gtk&quot;
</span><span class="cx">     &quot;${WEBKIT2_DIR}/UIProcess/soup&quot;
</span><span class="cx">     &quot;${WEBKIT2_DIR}/WebProcess/InjectedBundle/API/gtk&quot;
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedPluginsNetscapeNetscapePluginModuleh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/Plugins/Netscape/NetscapePluginModule.h (164807 => 164808)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/Plugins/Netscape/NetscapePluginModule.h        2014-02-27 17:49:45 UTC (rev 164807)
+++ trunk/Source/WebKit2/Shared/Plugins/Netscape/NetscapePluginModule.h        2014-02-27 17:59:16 UTC (rev 164808)
</span><span class="lines">@@ -35,6 +35,10 @@
</span><span class="cx"> #include &lt;wtf/RefCounted.h&gt;
</span><span class="cx"> #include &lt;wtf/text/WTFString.h&gt;
</span><span class="cx"> 
</span><ins>+namespace WebCore {
+struct MimeClassInfo;
+}
+
</ins><span class="cx"> namespace WebKit {
</span><span class="cx"> 
</span><span class="cx"> struct RawPluginMetaData;
</span><span class="lines">@@ -67,6 +71,8 @@
</span><span class="cx"> 
</span><span class="cx"> #if PLUGIN_ARCHITECTURE(X11)
</span><span class="cx">     static bool scanPlugin(const String&amp; pluginPath);
</span><ins>+    static void parseMIMEDescription(const String&amp; mimeDescription, Vector&lt;WebCore::MimeClassInfo&gt;&amp; result);
+    static String buildMIMEDescription(const Vector&lt;WebCore::MimeClassInfo&gt;&amp;);
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> private:
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedPluginsNetscapex11NetscapePluginModuleX11cpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/Plugins/Netscape/x11/NetscapePluginModuleX11.cpp (164807 => 164808)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/Plugins/Netscape/x11/NetscapePluginModuleX11.cpp        2014-02-27 17:49:45 UTC (rev 164807)
+++ trunk/Source/WebKit2/Shared/Plugins/Netscape/x11/NetscapePluginModuleX11.cpp        2014-02-27 17:59:16 UTC (rev 164808)
</span><span class="lines">@@ -36,6 +36,7 @@
</span><span class="cx"> #include &lt;sys/stat.h&gt;
</span><span class="cx"> #include &lt;sys/types.h&gt;
</span><span class="cx"> #include &lt;unistd.h&gt;
</span><ins>+#include &lt;wtf/text/StringBuilder.h&gt;
</ins><span class="cx"> 
</span><span class="cx"> using namespace WebCore;
</span><span class="cx"> 
</span><span class="lines">@@ -67,7 +68,7 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-static void parseMIMEDescription(const String&amp; mimeDescription, Vector&lt;MimeClassInfo&gt;&amp; result)
</del><ins>+void NetscapePluginModule::parseMIMEDescription(const String&amp; mimeDescription, Vector&lt;MimeClassInfo&gt;&amp; result)
</ins><span class="cx"> {
</span><span class="cx">     ASSERT_ARG(result, result.isEmpty());
</span><span class="cx"> 
</span><span class="lines">@@ -94,6 +95,32 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+String NetscapePluginModule::buildMIMEDescription(const Vector&lt;MimeClassInfo&gt;&amp; mimeDescription)
+{
+    StringBuilder builder;
+
+    size_t mimeInfoCount = mimeDescription.size();
+    for (size_t i = 0; i &lt; mimeInfoCount; ++i) {
+        const MimeClassInfo&amp; mimeInfo = mimeDescription[i];
+        builder.append(mimeInfo.type);
+        builder.append(':');
+
+        size_t extensionsCount = mimeInfo.extensions.size();
+        for (size_t j = 0; j &lt; extensionsCount; ++j) {
+            builder.append(mimeInfo.extensions[j]);
+            if (j != extensionsCount - 1)
+                builder.append(',');
+        }
+        builder.append(':');
+
+        builder.append(mimeInfo.desc);
+        if (i != mimeInfoCount - 1)
+            builder.append(';');
+    }
+
+    return builder.toString();
+}
+
</ins><span class="cx"> bool NetscapePluginModule::getPluginInfoForLoadedPlugin(RawPluginMetaData&amp; metaData)
</span><span class="cx"> {
</span><span class="cx">     ASSERT(m_isInitialized);
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessPluginsgtkPluginInfoCachecpp"></a>
<div class="addfile"><h4>Added: trunk/Source/WebKit2/UIProcess/Plugins/gtk/PluginInfoCache.cpp (0 => 164808)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/Plugins/gtk/PluginInfoCache.cpp                                (rev 0)
+++ trunk/Source/WebKit2/UIProcess/Plugins/gtk/PluginInfoCache.cpp        2014-02-27 17:59:16 UTC (rev 164808)
</span><span class="lines">@@ -0,0 +1,144 @@
</span><ins>+/*
+ * Copyright (C) 2014 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include &quot;config.h&quot;
+#include &quot;PluginInfoCache.h&quot;
+
+#if ENABLE(NETSCAPE_PLUGIN_API)
+
+#include &quot;NetscapePluginModule.h&quot;
+#include &lt;WebCore/FileSystem.h&gt;
+#include &lt;wtf/text/CString.h&gt;
+
+namespace WebKit {
+
+static const unsigned gSchemaVersion = 1;
+
+PluginInfoCache&amp; PluginInfoCache::shared()
+{
+    static NeverDestroyed&lt;PluginInfoCache&gt; pluginInfoCache;
+    return pluginInfoCache;
+}
+
+PluginInfoCache::PluginInfoCache()
+    : m_cacheFile(g_key_file_new())
+    , m_cachePath(g_build_filename(g_get_user_cache_dir(), &quot;webkitgtk&quot;, &quot;plugins&quot;, nullptr))
+    , m_saveToFileIdleId(0)
+{
+    g_key_file_load_from_file(m_cacheFile.get(), m_cachePath.get(), G_KEY_FILE_NONE, nullptr);
+
+    if (g_key_file_has_group(m_cacheFile.get(), &quot;schema&quot;)) {
+        unsigned schemaVersion = static_cast&lt;unsigned&gt;(g_key_file_get_integer(m_cacheFile.get(), &quot;schema&quot;, &quot;version&quot;, nullptr));
+        if (schemaVersion == gSchemaVersion)
+            return;
+
+        // Cache file using an old schema, create a new empty file.
+        m_cacheFile.reset(g_key_file_new());
+    }
+
+    g_key_file_set_integer(m_cacheFile.get(), &quot;schema&quot;, &quot;version&quot;, static_cast&lt;unsigned&gt;(gSchemaVersion));
+}
+
+PluginInfoCache::~PluginInfoCache()
+{
+    if (m_saveToFileIdleId) {
+        g_source_remove(m_saveToFileIdleId);
+        saveToFile();
+    }
+}
+
+gboolean PluginInfoCache::saveToFileIdleCallback(PluginInfoCache* cache)
+{
+    cache-&gt;saveToFile();
+    return FALSE;
+}
+
+void PluginInfoCache::saveToFile()
+{
+    std::lock_guard&lt;std::mutex&gt; lock(m_mutex);
+    m_saveToFileIdleId = 0;
+
+    gsize dataLength;
+    GUniquePtr&lt;char&gt; data(g_key_file_to_data(m_cacheFile.get(), &amp;dataLength, nullptr));
+    if (!data)
+        return;
+
+    g_file_set_contents(m_cachePath.get(), data.get(), dataLength, nullptr);
+}
+
+bool PluginInfoCache::getPluginInfo(const String&amp; pluginPath, PluginModuleInfo&amp; plugin)
+{
+    CString pluginGroup = pluginPath.utf8();
+    if (!g_key_file_has_group(m_cacheFile.get(), pluginGroup.data()))
+        return false;
+
+    time_t lastModified;
+    if (!WebCore::getFileModificationTime(pluginPath, lastModified))
+        return false;
+    time_t cachedLastModified = static_cast&lt;time_t&gt;(g_key_file_get_uint64(m_cacheFile.get(), pluginGroup.data(), &quot;mtime&quot;, nullptr));
+    if (lastModified != cachedLastModified)
+        return false;
+
+    plugin.path = pluginPath;
+    plugin.info.file = WebCore::pathGetFileName(pluginPath);
+
+    GUniquePtr&lt;char&gt; stringValue(g_key_file_get_string(m_cacheFile.get(), pluginGroup.data(), &quot;name&quot;, nullptr));
+    plugin.info.name = String::fromUTF8(stringValue.get());
+
+    stringValue.reset(g_key_file_get_string(m_cacheFile.get(), pluginGroup.data(), &quot;description&quot;, nullptr));
+    plugin.info.desc = String::fromUTF8(stringValue.get());
+
+    stringValue.reset(g_key_file_get_string(m_cacheFile.get(), pluginGroup.data(), &quot;mime-description&quot;, nullptr));
+    NetscapePluginModule::parseMIMEDescription(String::fromUTF8(stringValue.get()), plugin.info.mimes);
+
+    return true;
+}
+
+void PluginInfoCache::updatePluginInfo(const String&amp; pluginPath, const PluginModuleInfo&amp; plugin)
+{
+    time_t lastModified;
+    if (!WebCore::getFileModificationTime(pluginPath, lastModified))
+        return;
+
+    CString pluginGroup = pluginPath.utf8();
+    g_key_file_set_uint64(m_cacheFile.get(), pluginGroup.data(), &quot;mtime&quot;, static_cast&lt;guint64&gt;(lastModified));
+    g_key_file_set_string(m_cacheFile.get(), pluginGroup.data(), &quot;name&quot;, plugin.info.name.utf8().data());
+    g_key_file_set_string(m_cacheFile.get(), pluginGroup.data(), &quot;description&quot;, plugin.info.desc.utf8().data());
+
+    String mimeDescription = NetscapePluginModule::buildMIMEDescription(plugin.info.mimes);
+    g_key_file_set_string(m_cacheFile.get(), pluginGroup.data(), &quot;mime-description&quot;, mimeDescription.utf8().data());
+
+    // Save the cache file in an idle to make sure it happens in the main thread and
+    // it's done only once when this is called multiple times in a very short time.
+    std::lock_guard&lt;std::mutex&gt; lock(m_mutex);
+    if (m_saveToFileIdleId)
+        return;
+
+    m_saveToFileIdleId = g_idle_add(reinterpret_cast&lt;GSourceFunc&gt;(PluginInfoCache::saveToFileIdleCallback), this);
+}
+
+} // namespace WebKit
+
+#endif // ENABLE(NETSCAPE_PLUGIN_API)
</ins></span></pre></div>
<a id="trunkSourceWebKit2UIProcessPluginsgtkPluginInfoCacheh"></a>
<div class="addfile"><h4>Added: trunk/Source/WebKit2/UIProcess/Plugins/gtk/PluginInfoCache.h (0 => 164808)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/Plugins/gtk/PluginInfoCache.h                                (rev 0)
+++ trunk/Source/WebKit2/UIProcess/Plugins/gtk/PluginInfoCache.h        2014-02-27 17:59:16 UTC (rev 164808)
</span><span class="lines">@@ -0,0 +1,64 @@
</span><ins>+/*
+ * Copyright (C) 2014 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef PluginInfoCache_h
+#define PluginInfoCache_h
+
+#if ENABLE(NETSCAPE_PLUGIN_API)
+
+#include &quot;PluginModuleInfo.h&quot;
+#include &lt;mutex&gt;
+#include &lt;wtf/NeverDestroyed.h&gt;
+#include &lt;wtf/gobject/GUniquePtr.h&gt;
+
+namespace WebKit {
+
+class PluginInfoCache {
+    WTF_MAKE_NONCOPYABLE(PluginInfoCache);
+    friend class NeverDestroyed&lt;PluginInfoCache&gt;;
+public:
+    static PluginInfoCache&amp; shared();
+
+    bool getPluginInfo(const String&amp; pluginPath, PluginModuleInfo&amp;);
+    void updatePluginInfo(const String&amp; pluginPath, const PluginModuleInfo&amp;);
+
+private:
+    PluginInfoCache();
+    ~PluginInfoCache();
+
+    void saveToFile();
+    static gboolean saveToFileIdleCallback(PluginInfoCache*);
+
+    GUniquePtr&lt;GKeyFile&gt; m_cacheFile;
+    GUniquePtr&lt;char&gt; m_cachePath;
+    unsigned m_saveToFileIdleId;
+    std::mutex m_mutex;
+};
+
+} // namespace WebKit
+
+#endif // ENABLE(NETSCAPE_PLUGIN_API)
+
+#endif // PluginInfoCache_h
</ins></span></pre></div>
<a id="trunkSourceWebKit2UIProcessPluginsunixPluginInfoStoreUnixcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/Plugins/unix/PluginInfoStoreUnix.cpp (164807 => 164808)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/Plugins/unix/PluginInfoStoreUnix.cpp        2014-02-27 17:49:45 UTC (rev 164807)
+++ trunk/Source/WebKit2/UIProcess/Plugins/unix/PluginInfoStoreUnix.cpp        2014-02-27 17:59:16 UTC (rev 164808)
</span><span class="lines">@@ -35,6 +35,10 @@
</span><span class="cx"> #include &quot;PluginDatabase.h&quot;
</span><span class="cx"> #include &lt;WebCore/FileSystem.h&gt;
</span><span class="cx"> 
</span><ins>+#if PLATFORM(GTK)
+#include &quot;PluginInfoCache.h&quot;
+#endif
+
</ins><span class="cx"> using namespace WebCore;
</span><span class="cx"> 
</span><span class="cx"> namespace WebKit {
</span><span class="lines">@@ -98,7 +102,18 @@
</span><span class="cx"> 
</span><span class="cx"> bool PluginInfoStore::getPluginInfo(const String&amp; pluginPath, PluginModuleInfo&amp; plugin)
</span><span class="cx"> {
</span><ins>+#if PLATFORM(GTK)
+    if (PluginInfoCache::shared().getPluginInfo(pluginPath, plugin))
+        return true;
+
+    if (NetscapePluginModule::getPluginInfo(pluginPath, plugin)) {
+        PluginInfoCache::shared().updatePluginInfo(pluginPath, plugin);
+        return true;
+    }
+    return false;
+#else
</ins><span class="cx">     return NetscapePluginModule::getPluginInfo(pluginPath, plugin);
</span><ins>+#endif
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool PluginInfoStore::shouldUsePlugin(Vector&lt;PluginModuleInfo&gt;&amp; /*alreadyLoadedPlugins*/, const PluginModuleInfo&amp; /*plugin*/)
</span></span></pre>
</div>
</div>

</body>
</html>