[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

commit-queue at webkit.org commit-queue at webkit.org
Wed Dec 22 12:44:47 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit 67b334a60da0e3fe0933df6f06a09dde2afbdaea
Author: commit-queue at webkit.org <commit-queue at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Sat Aug 28 04:32:17 2010 +0000

    2010-08-27  Kimmo Kinnunen  <kimmo.t.kinnunen at nokia.com>
    
            Reviewed by Kenneth Rohde Christiansen.
    
            [Qt] NPAPI Plugin metadata should be cached, and loading a plugin should not require loading every plugin
            https://bugs.webkit.org/show_bug.cgi?id=43179
    
            Add ENABLE_NETSCAPE_PLUGIN_METADATA_CACHE flag to enable persistent
            NPAPI Plugin Cache. The flag is enabled by default.
    
            * wtf/Platform.h: Add ENABLE_NETSCAPE_PLUGIN_METADATA_CACHE
    2010-08-27  Kimmo Kinnunen  <kimmo.t.kinnunen at nokia.com>
    
            Reviewed by Kenneth Rohde Christiansen.
    
            [Qt] Cache plugin info to a persistent database
    
            https://bugs.webkit.org/show_bug.cgi?id=43179
    
            Implement a cache of NPAPI plugin metadata. Write the metadata to aa
            file that gets rewritten if any plugin is added / removed.  Compilation
            of the feature is controlled by #if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE)
    
            Currently only enabled for Qt UNIX flavors.
    
            * WebCore.pro:  Enable NETSCAPE_PLUGIN_METADATA_CACHE for UNIX builds
            * platform/qt/FileSystemQt.cpp:
            (WebCore::openFile): Added.
            (WebCore::readFromFile): Added.
            * plugins/PluginDatabase.cpp:
            (WebCore::persistentPluginMetadataCachePath): Static accessor for the path
            (WebCore::PluginDatabase::PluginDatabase): Add instance variable.
            (WebCore::PluginDatabase::refresh):
            (WebCore::PluginDatabase::pluginForMIMEType): Ensure returned plugin is loaded.
            (WebCore::PluginDatabase::MIMETypeForExtension): Ensure returned plugin is loaded.
            (WebCore::PluginDatabase::clear):
            (WebCore::fillBufferWithContentsOfFile): Static helper function.
            (WebCore::readUTF8String): Static helper function.
            (WebCore::readTime): Static helper function.
            (WebCore::PluginDatabase::loadPersistentMetadataCache):
            (WebCore::writeUTF8String): Static helper function.
            (WebCore::writeTime): Static helper function.
            (WebCore::PluginDatabase::updatePersistentMetadataCache): Added.
            (WebCore::PluginDatabase::isPersistentMetadataCacheEnabled): Added.
            (WebCore::PluginDatabase::setPersistentMetadataCacheEnabled):Added.
            (WebCore::PluginDatabase::persistentMetadataCachePath): Added.
            (WebCore::PluginDatabase::setPersistentMetadataCachePath): Added.
            * plugins/PluginDatabase.h:
            * plugins/PluginPackage.cpp:
            (WebCore::PluginPackage::PluginPackage): Add instance variable.
            (WebCore::PluginPackage::createPackageFromCache): Added.
            (WebCore::PluginPackage::ensurePluginLoaded): Added.
            * plugins/PluginPackage.h:
            (WebCore::PluginPackage::fullMIMEDescription): Added.
            * plugins/qt/PluginPackageQt.cpp:
            (WebCore::PluginPackage::fetchInfo): Split mime parsing.
            (WebCore::PluginPackage::setMIMEDescription): Added. Mime parsing.
    2010-08-27  Kimmo Kinnunen  <kimmo.t.kinnunen at nokia.com>
    
            Reviewed by Kenneth Rohde Christiansen.
    
            [Qt] Cache plugin info to a persistent database
    
            https://bugs.webkit.org/show_bug.cgi?id=43179
    
            Implement a cache of NPAPI plugin metadata. Write the metadata to aa
            file that gets rewritten if any plugin is added / removed.  Compilation
            of the feature is controlled by #if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE)
    
            Currently only enabled for Qt UNIX flavors.
    
            * Api/qwebplugindatabase.cpp:
            (QWebPluginDatabase::plugins):  Match previous behavior: ensure all returned plugins are loaded.
            * Api/qwebsettings.cpp:
            (QWebSettings::enablePersistentStorage): Set plugin cache path.
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@66297 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/JavaScriptCore/ChangeLog b/JavaScriptCore/ChangeLog
index 196a2d0..ee580e0 100644
--- a/JavaScriptCore/ChangeLog
+++ b/JavaScriptCore/ChangeLog
@@ -1,3 +1,15 @@
+2010-08-27  Kimmo Kinnunen  <kimmo.t.kinnunen at nokia.com>
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        [Qt] NPAPI Plugin metadata should be cached, and loading a plugin should not require loading every plugin
+        https://bugs.webkit.org/show_bug.cgi?id=43179
+
+        Add ENABLE_NETSCAPE_PLUGIN_METADATA_CACHE flag to enable persistent
+        NPAPI Plugin Cache. The flag is enabled by default.
+
+        * wtf/Platform.h: Add ENABLE_NETSCAPE_PLUGIN_METADATA_CACHE
+
 2010-07-27  Jer Noble  <jer.noble at apple.com>
 
         Reviewed by Eric Carlson.
diff --git a/JavaScriptCore/wtf/Platform.h b/JavaScriptCore/wtf/Platform.h
index d58af31..9d27163 100644
--- a/JavaScriptCore/wtf/Platform.h
+++ b/JavaScriptCore/wtf/Platform.h
@@ -857,6 +857,10 @@
 #define ENABLE_NETSCAPE_PLUGIN_API 1
 #endif
 
+#if !defined(ENABLE_NETSCAPE_PLUGIN_METADATA_CACHE)
+#define ENABLE_NETSCAPE_PLUGIN_METADATA_CACHE 0
+#endif
+
 #if !defined(WTF_USE_PLUGIN_HOST_PROCESS)
 #define WTF_USE_PLUGIN_HOST_PROCESS 0
 #endif
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 882112c..687146c 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,50 @@
+2010-08-27  Kimmo Kinnunen  <kimmo.t.kinnunen at nokia.com>
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        [Qt] Cache plugin info to a persistent database
+
+        https://bugs.webkit.org/show_bug.cgi?id=43179
+
+        Implement a cache of NPAPI plugin metadata. Write the metadata to aa
+        file that gets rewritten if any plugin is added / removed.  Compilation
+        of the feature is controlled by #if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE)
+
+        Currently only enabled for Qt UNIX flavors.
+
+        * WebCore.pro:  Enable NETSCAPE_PLUGIN_METADATA_CACHE for UNIX builds
+        * platform/qt/FileSystemQt.cpp:
+        (WebCore::openFile): Added.
+        (WebCore::readFromFile): Added.
+        * plugins/PluginDatabase.cpp:
+        (WebCore::persistentPluginMetadataCachePath): Static accessor for the path
+        (WebCore::PluginDatabase::PluginDatabase): Add instance variable.
+        (WebCore::PluginDatabase::refresh):
+        (WebCore::PluginDatabase::pluginForMIMEType): Ensure returned plugin is loaded.
+        (WebCore::PluginDatabase::MIMETypeForExtension): Ensure returned plugin is loaded.
+        (WebCore::PluginDatabase::clear):
+        (WebCore::fillBufferWithContentsOfFile): Static helper function.
+        (WebCore::readUTF8String): Static helper function.
+        (WebCore::readTime): Static helper function.
+        (WebCore::PluginDatabase::loadPersistentMetadataCache):
+        (WebCore::writeUTF8String): Static helper function.
+        (WebCore::writeTime): Static helper function.
+        (WebCore::PluginDatabase::updatePersistentMetadataCache): Added.
+        (WebCore::PluginDatabase::isPersistentMetadataCacheEnabled): Added.
+        (WebCore::PluginDatabase::setPersistentMetadataCacheEnabled):Added.
+        (WebCore::PluginDatabase::persistentMetadataCachePath): Added.
+        (WebCore::PluginDatabase::setPersistentMetadataCachePath): Added.
+        * plugins/PluginDatabase.h:
+        * plugins/PluginPackage.cpp:
+        (WebCore::PluginPackage::PluginPackage): Add instance variable.
+        (WebCore::PluginPackage::createPackageFromCache): Added.
+        (WebCore::PluginPackage::ensurePluginLoaded): Added.
+        * plugins/PluginPackage.h:
+        (WebCore::PluginPackage::fullMIMEDescription): Added.
+        * plugins/qt/PluginPackageQt.cpp:
+        (WebCore::PluginPackage::fetchInfo): Split mime parsing.
+        (WebCore::PluginPackage::setMIMEDescription): Added. Mime parsing.
+
 2010-08-27  Daniel Bates  <dbates at rim.com>
 
         Reviewed by Darin Adler.
diff --git a/WebCore/WebCore.pro b/WebCore/WebCore.pro
index 7463051..37d4f74 100644
--- a/WebCore/WebCore.pro
+++ b/WebCore/WebCore.pro
@@ -2394,6 +2394,7 @@ contains(DEFINES, ENABLE_NETSCAPE_PLUGIN_API=1) {
                 HEADERS += \
                     plugins/qt/PluginContainerQt.h
                 DEFINES += XP_UNIX
+                DEFINES += ENABLE_NETSCAPE_PLUGIN_METADATA_CACHE=1
             }
         }
     
diff --git a/WebCore/platform/qt/FileSystemQt.cpp b/WebCore/platform/qt/FileSystemQt.cpp
index 96c2093..b384091 100644
--- a/WebCore/platform/qt/FileSystemQt.cpp
+++ b/WebCore/platform/qt/FileSystemQt.cpp
@@ -128,6 +128,33 @@ CString openTemporaryFile(const char* prefix, PlatformFileHandle& handle)
     return CString();
 }
 
+#if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE)
+PlatformFileHandle openFile(const String& path, FileOpenMode mode)
+{
+    QIODevice::OpenMode platformMode;
+
+    if (mode == OpenForRead)
+        platformMode = QIODevice::ReadOnly;
+    else if (mode == OpenForWrite)
+        platformMode = (QIODevice::WriteOnly | QIODevice::Truncate);
+    else
+        return invalidPlatformFileHandle;
+
+    QFile* file = new QFile(path);
+    if (file->open(platformMode))
+        return file;
+
+    return invalidPlatformFileHandle;
+}
+
+int readFromFile(PlatformFileHandle handle, char* data, int length)
+{
+    if (handle && handle->exists() && handle->isReadable())
+        return handle->read(data, length);
+    return 0;
+}
+#endif
+
 void closeFile(PlatformFileHandle& handle)
 {
     if (handle) {
diff --git a/WebCore/plugins/PluginDatabase.cpp b/WebCore/plugins/PluginDatabase.cpp
index 29b6d24..46c7df7 100644
--- a/WebCore/plugins/PluginDatabase.cpp
+++ b/WebCore/plugins/PluginDatabase.cpp
@@ -30,13 +30,31 @@
 #include "Frame.h"
 #include "KURL.h"
 #include "PluginPackage.h"
+#if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE)
+#include "FileSystem.h"
+#endif
 #include <stdlib.h>
 
 namespace WebCore {
 
 typedef HashMap<String, RefPtr<PluginPackage> > PluginPackageByNameMap;
 
+#if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE)
+static const size_t maximumPersistentPluginMetadataCacheSize = 32768;
+
+static bool gPersistentPluginMetadataCacheIsEnabled;
+
+String& persistentPluginMetadataCachePath()
+{
+    DEFINE_STATIC_LOCAL(String, cachePath, ());
+    return cachePath;
+}
+#endif
+
 PluginDatabase::PluginDatabase()
+#if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE)
+    : m_persistentMetadataCacheIsLoaded(false)
+#endif
 {
 }
 
@@ -74,6 +92,10 @@ void PluginDatabase::addExtraPluginDirectory(const String& directory)
 
 bool PluginDatabase::refresh()
 {
+#if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE)
+    if (!m_persistentMetadataCacheIsLoaded)
+        loadPersistentMetadataCache();
+#endif
     bool pluginSetChanged = false;
 
     if (!m_plugins.isEmpty()) {
@@ -126,6 +148,10 @@ bool PluginDatabase::refresh()
     if (!pluginSetChanged)
         return false;
 
+#if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE)
+    updatePersistentMetadataCache();
+#endif
+
     m_registeredMIMETypes.clear();
 
     // Register plug-in MIME types
@@ -182,8 +208,13 @@ PluginPackage* PluginDatabase::pluginForMIMEType(const String& mimeType)
         if (!plugin->isEnabled())
             continue;
 
-        if (plugin->mimeToDescriptions().contains(key))
+        if (plugin->mimeToDescriptions().contains(key)) {
+#if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE)
+            if (!plugin->ensurePluginLoaded())
+                continue;
+#endif
             pluginChoices.append(plugin);
+        }
     }
 
     if (pluginChoices.isEmpty())
@@ -222,6 +253,10 @@ String PluginDatabase::MIMETypeForExtension(const String& extension) const
                     if (preferredPlugin && PluginPackage::equal(*plugin, *preferredPlugin))
                         return mimeType;
 
+#if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE)
+                    if (!plugin->ensurePluginLoaded())
+                        continue;
+#endif
                     pluginChoices.append(plugin);
                     mimeTypeForPlugin.add(plugin, mimeType);
                     foundMapping = true;
@@ -315,6 +350,9 @@ void PluginDatabase::clear()
     m_pluginPathsWithTimes.clear();
     m_registeredMIMETypes.clear();
     m_preferredPlugins.clear();
+#if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE)
+    m_persistentMetadataCacheIsLoaded = false;
+#endif
 }
 
 #if (!OS(WINCE)) && (!OS(SYMBIAN)) && (!OS(WINDOWS) || !ENABLE(NETSCAPE_PLUGIN_API))
@@ -427,4 +465,200 @@ void PluginDatabase::getPluginPathsInDirectories(HashSet<String>& paths) const
 
 #endif // !OS(SYMBIAN) && !OS(WINDOWS)
 
+#if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE)
+
+static void fillBufferWithContentsOfFile(PlatformFileHandle file, Vector<char>& buffer)
+{
+    size_t bufferSize = 0;
+    size_t bufferCapacity = 1024;
+    buffer.resize(bufferCapacity);
+
+    do {
+        bufferSize += readFromFile(file, buffer.data() + bufferSize, bufferCapacity - bufferSize);
+        if (bufferSize == bufferCapacity) {
+            if (bufferCapacity < maximumPersistentPluginMetadataCacheSize) {
+                bufferCapacity *= 2;
+                buffer.resize(bufferCapacity);
+            } else {
+                buffer.clear();
+                return;
+            }
+        } else
+            break;
+    } while (true);
+
+    buffer.shrink(bufferSize);
+}
+
+static bool readUTF8String(String& resultString, char*& start, const char* end)
+{
+    if (start >= end)
+        return false;
+
+    int len = strlen(start);
+    resultString = String::fromUTF8(start, len);
+    start += len + 1;
+
+    return true;
+}
+
+static bool readTime(time_t& resultTime, char*& start, const char* end)
+{
+    if (start + sizeof(time_t) >= end)
+        return false;
+
+    resultTime = *reinterpret_cast<time_t*>(start);
+    start += sizeof(time_t);
+
+    return true;
+}
+
+static const char schemaVersion = '1';
+static const char persistentPluginMetadataCacheFilename[] = "PluginMetadataCache.bin";
+
+void PluginDatabase::loadPersistentMetadataCache()
+{
+    if (!isPersistentMetadataCacheEnabled() || persistentMetadataCachePath().isEmpty())
+        return;
+
+    PlatformFileHandle file;
+    String absoluteCachePath = pathByAppendingComponent(persistentMetadataCachePath(), persistentPluginMetadataCacheFilename);
+    file = openFile(absoluteCachePath, OpenForRead);
+
+    if (!isHandleValid(file))
+        return;
+
+    // Mark cache as loaded regardless of success or failure. If
+    // there's error in the cache, we won't try to load it anymore.
+    m_persistentMetadataCacheIsLoaded = true;
+
+    Vector<char> fileContents;
+    fillBufferWithContentsOfFile(file, fileContents);
+    closeFile(file);
+
+    if (fileContents.size() < 2 || fileContents.first() != schemaVersion || fileContents.last() != '\0') {
+        LOG_ERROR("Unable to read plugin metadata cache: corrupt schema");
+        deleteFile(absoluteCachePath);
+        return;
+    }
+
+    char* bufferPos = fileContents.data() + 1;
+    char* end = fileContents.data() + fileContents.size();
+
+    PluginSet cachedPlugins;
+    HashMap<String, time_t> cachedPluginPathsWithTimes;
+    HashMap<String, RefPtr<PluginPackage> > cachedPluginsByPath;
+
+    while (bufferPos < end) {
+        String path;
+        time_t lastModified;
+        String name;
+        String desc;
+        String mimeDesc;
+        if (!(readUTF8String(path, bufferPos, end)
+              && readTime(lastModified, bufferPos, end)
+              && readUTF8String(name, bufferPos, end)
+              && readUTF8String(desc, bufferPos, end)
+              && readUTF8String(mimeDesc, bufferPos, end))) {
+            LOG_ERROR("Unable to read plugin metadata cache: corrupt data");
+            deleteFile(absoluteCachePath);
+            return;
+        }
+
+        // Skip metadata that points to plugins from directories that
+        // are not part of plugin directory list anymore.
+        String pluginDirectoryName = directoryName(path);
+        if (m_pluginDirectories.find(pluginDirectoryName) == WTF::notFound)
+            continue;
+
+        RefPtr<PluginPackage> package = PluginPackage::createPackageFromCache(path, lastModified, name, desc, mimeDesc);
+
+        if (package && cachedPlugins.add(package).second) {
+            cachedPluginPathsWithTimes.add(package->path(), package->lastModified());
+            cachedPluginsByPath.add(package->path(), package);
+        }
+    }
+
+    m_plugins.swap(cachedPlugins);
+    m_pluginsByPath.swap(cachedPluginsByPath);
+    m_pluginPathsWithTimes.swap(cachedPluginPathsWithTimes);
+}
+
+static bool writeUTF8String(PlatformFileHandle file, const String& string)
+{
+    CString utf8String = string.utf8();
+    int length = utf8String.length() + 1;
+    return writeToFile(file, utf8String.data(), length) == length;
+}
+
+static bool writeTime(PlatformFileHandle file, const time_t& time)
+{
+    return writeToFile(file, reinterpret_cast<const char*>(&time), sizeof(time_t)) == sizeof(time_t);
+}
+
+void PluginDatabase::updatePersistentMetadataCache()
+{
+    if (!isPersistentMetadataCacheEnabled() || persistentMetadataCachePath().isEmpty())
+        return;
+
+    makeAllDirectories(persistentMetadataCachePath());
+    String absoluteCachePath = pathByAppendingComponent(persistentMetadataCachePath(), persistentPluginMetadataCacheFilename);
+    deleteFile(absoluteCachePath);
+
+    if (m_plugins.isEmpty())
+        return;
+
+    PlatformFileHandle file;
+    file = openFile(absoluteCachePath, OpenForWrite);
+
+    if (!isHandleValid(file)) {
+        LOG_ERROR("Unable to open plugin metadata cache for saving");
+        return;
+    }
+
+    char localSchemaVersion = schemaVersion;
+    if (writeToFile(file, &localSchemaVersion, 1) != 1) {
+        LOG_ERROR("Unable to write plugin metadata cache schema");
+        closeFile(file);
+        deleteFile(absoluteCachePath);
+        return;
+    }
+
+    PluginSet::const_iterator end = m_plugins.end();
+    for (PluginSet::const_iterator it = m_plugins.begin(); it != end; ++it) {
+        if (!(writeUTF8String(file, (*it)->path())
+              && writeTime(file, (*it)->lastModified())
+              && writeUTF8String(file, (*it)->name())
+              && writeUTF8String(file, (*it)->description())
+              && writeUTF8String(file, (*it)->fullMIMEDescription()))) {
+            LOG_ERROR("Unable to write plugin metadata to cache");
+            closeFile(file);
+            deleteFile(absoluteCachePath);
+            return;
+        }
+    }
+
+    closeFile(file);
+}
+
+bool PluginDatabase::isPersistentMetadataCacheEnabled()
+{
+    return gPersistentPluginMetadataCacheIsEnabled;
+}
+
+void PluginDatabase::setPersistentMetadataCacheEnabled(bool isEnabled)
+{
+    gPersistentPluginMetadataCacheIsEnabled = isEnabled;
+}
+
+String PluginDatabase::persistentMetadataCachePath()
+{
+    return WebCore::persistentPluginMetadataCachePath();
+}
+
+void PluginDatabase::setPersistentMetadataCachePath(const String& persistentMetadataCachePath)
+{
+    WebCore::persistentPluginMetadataCachePath() = persistentMetadataCachePath;
+}
+#endif
 }
diff --git a/WebCore/plugins/PluginDatabase.h b/WebCore/plugins/PluginDatabase.h
index f80dd8c..b14605f 100644
--- a/WebCore/plugins/PluginDatabase.h
+++ b/WebCore/plugins/PluginDatabase.h
@@ -78,6 +78,12 @@ namespace WebCore {
         Vector<String> pluginDirectories() const { return m_pluginDirectories; }
 
         String MIMETypeForExtension(const String& extension) const;
+#if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE)
+        static bool isPersistentMetadataCacheEnabled();
+        static void setPersistentMetadataCacheEnabled(bool isEnabled);
+        static String persistentMetadataCachePath();
+        static void setPersistentMetadataCachePath(const String& persistentMetadataCachePath);
+#endif
 
     private:
         void getPluginPathsInDirectories(HashSet<String>&) const;
@@ -86,6 +92,10 @@ namespace WebCore {
         // Returns whether the plugin was actually added or not (it won't be added if it's a duplicate of an existing plugin).
         bool add(PassRefPtr<PluginPackage>);
         void remove(PluginPackage*);
+#if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE)
+        void loadPersistentMetadataCache();
+        void updatePersistentMetadataCache();
+#endif
 
         Vector<String> m_pluginDirectories;
         HashSet<String> m_registeredMIMETypes;
@@ -93,6 +103,9 @@ namespace WebCore {
         HashMap<String, RefPtr<PluginPackage> > m_pluginsByPath;
         HashMap<String, time_t> m_pluginPathsWithTimes;
         HashMap<String, RefPtr<PluginPackage> > m_preferredPlugins;
+#if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE)
+        bool m_persistentMetadataCacheIsLoaded;
+#endif
     };
 
 } // namespace WebCore
diff --git a/WebCore/plugins/PluginPackage.cpp b/WebCore/plugins/PluginPackage.cpp
index bf970f2..5f358b1 100644
--- a/WebCore/plugins/PluginPackage.cpp
+++ b/WebCore/plugins/PluginPackage.cpp
@@ -108,6 +108,9 @@ PluginPackage::PluginPackage(const String& path, const time_t& lastModified)
     , m_module(0)
     , m_lastModified(lastModified)
     , m_freeLibraryTimer(this, &PluginPackage::freeLibraryTimerFired)
+#if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE)
+    , m_infoIsFromCache(true)
+#endif
 {
     m_fileName = pathGetFileName(m_path);
     m_parentDirectory = m_path.left(m_path.length() - m_fileName.length() - 1);
@@ -162,6 +165,19 @@ PassRefPtr<PluginPackage> PluginPackage::createPackage(const String& path, const
     return package.release();
 }
 
+#if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE)
+PassRefPtr<PluginPackage> PluginPackage::createPackageFromCache(const String& path, const time_t& lastModified, const String& name, const String& description, const String& mimeDescription)
+{
+    RefPtr<PluginPackage> package = adoptRef(new PluginPackage(path, lastModified));
+    package->m_name = name;
+    package->m_description = description;
+    package->determineModuleVersionFromDescription();
+    package->setMIMEDescription(mimeDescription);
+    package->m_infoIsFromCache = true;
+    return package.release();
+}
+#endif
+
 #if defined(XP_UNIX)
 void PluginPackage::determineQuirks(const String& mimeType)
 {
@@ -343,4 +359,20 @@ int PluginPackage::compareFileVersion(const PlatformModuleVersion& compareVersio
     return 0;
 }
 
+#if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE)
+bool PluginPackage::ensurePluginLoaded()
+{
+    if (!m_infoIsFromCache)
+        return m_isLoaded;
+
+    m_quirks = PluginQuirkSet();
+    m_name = String();
+    m_description = String();
+    m_fullMIMEDescription = String();
+    m_moduleVersion = 0;
+
+    return fetchInfo();
+}
+#endif
+
 }
diff --git a/WebCore/plugins/PluginPackage.h b/WebCore/plugins/PluginPackage.h
index 92a9c52..f4d1dac 100644
--- a/WebCore/plugins/PluginPackage.h
+++ b/WebCore/plugins/PluginPackage.h
@@ -49,6 +49,9 @@ namespace WebCore {
     public:
         ~PluginPackage();
         static PassRefPtr<PluginPackage> createPackage(const String& path, const time_t& lastModified);
+#if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE)
+        static PassRefPtr<PluginPackage> createPackageFromCache(const String& path, const time_t& lastModified, const String& name, const String& description, const String& mimeDescription);
+#endif
 
         const String& name() const { return m_name; }
         const String& description() const { return m_description; }
@@ -80,6 +83,11 @@ namespace WebCore {
         NPInterface* npInterface() const { return m_npInterface; }
 #endif // OS(SYMBIAN)
 
+#if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE)
+        bool ensurePluginLoaded();
+        void setMIMEDescription(const String& mimeDescription);
+        String fullMIMEDescription() const { return m_fullMIMEDescription;}
+#endif
     private:
         PluginPackage(const String& path, const time_t& lastModified);
 
@@ -121,6 +129,10 @@ namespace WebCore {
         Timer<PluginPackage> m_freeLibraryTimer;
 
         PluginQuirkSet m_quirks;
+#if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE)
+        String m_fullMIMEDescription;
+        bool m_infoIsFromCache;
+#endif
     };
 
     struct PluginPackageHash {
diff --git a/WebCore/plugins/qt/PluginPackageQt.cpp b/WebCore/plugins/qt/PluginPackageQt.cpp
index d92fffe..e7058c7 100644
--- a/WebCore/plugins/qt/PluginPackageQt.cpp
+++ b/WebCore/plugins/qt/PluginPackageQt.cpp
@@ -60,9 +60,19 @@ bool PluginPackage::fetchInfo()
     m_description = buf;
     determineModuleVersionFromDescription();
 
-    String s = gm();
+    String mimeDescription = gm();
+    setMIMEDescription(mimeDescription);
+    m_infoIsFromCache = false;
+
+    return true;
+}
+
+void PluginPackage::setMIMEDescription(const String& mimeDescription)
+{
+    m_fullMIMEDescription = mimeDescription;
+
     Vector<String> types;
-    s.split(UChar(';'), false, types);
+    mimeDescription.split(UChar(';'), false, types);
     for (unsigned i = 0; i < types.size(); ++i) {
         Vector<String> mime;
         types[i].split(UChar(':'), true, mime);
@@ -76,8 +86,6 @@ bool PluginPackage::fetchInfo()
                 m_mimeToDescriptions.add(mime[0], mime[2]);
         }
     }
-
-    return true;
 }
 
 static NPError staticPluginQuirkRequiresGtkToolKit_NPN_GetValue(NPP instance, NPNVariable variable, void* value)
@@ -187,4 +195,5 @@ uint16_t PluginPackage::NPVersion() const
 {
     return NP_VERSION_MINOR;
 }
+
 }
diff --git a/WebKit/qt/Api/qwebplugindatabase.cpp b/WebKit/qt/Api/qwebplugindatabase.cpp
index 758e257..8fdbd36 100644
--- a/WebKit/qt/Api/qwebplugindatabase.cpp
+++ b/WebKit/qt/Api/qwebplugindatabase.cpp
@@ -284,7 +284,8 @@ QList<QWebPluginInfo> QWebPluginDatabase::plugins() const
 
     for (unsigned int i = 0; i < plugins.size(); ++i) {
         PluginPackage* plugin = plugins[i];
-        qwebplugins.append(QWebPluginInfo(plugin));
+        if (plugin->ensurePluginLoaded())
+            qwebplugins.append(QWebPluginInfo(plugin));
     }
 
     return qwebplugins;
diff --git a/WebKit/qt/Api/qwebsettings.cpp b/WebKit/qt/Api/qwebsettings.cpp
index edd07da..d88b0da 100644
--- a/WebKit/qt/Api/qwebsettings.cpp
+++ b/WebKit/qt/Api/qwebsettings.cpp
@@ -34,6 +34,7 @@
 #include "KURL.h"
 #include "PlatformString.h"
 #include "IconDatabase.h"
+#include "PluginDatabase.h"
 #include "Image.h"
 #include "IntSize.h"
 #include "ApplicationCacheStorage.h"
@@ -1093,6 +1094,14 @@ void QWebSettings::enablePersistentStorage(const QString& path)
     QWebSettings::globalSettings()->setAttribute(QWebSettings::LocalStorageEnabled, true);
     QWebSettings::globalSettings()->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, true);
     QWebSettings::globalSettings()->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled, true);
+
+#if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE)
+    QFileInfo info(storagePath);
+    if (info.isDir() && info.isWritable()) {
+        WebCore::PluginDatabase::setPersistentMetadataCacheEnabled(true);
+        WebCore::PluginDatabase::setPersistentMetadataCachePath(storagePath);
+    }
+#endif
 }
 
 /*!
diff --git a/WebKit/qt/ChangeLog b/WebKit/qt/ChangeLog
index f69ba16..f456773 100644
--- a/WebKit/qt/ChangeLog
+++ b/WebKit/qt/ChangeLog
@@ -1,3 +1,22 @@
+2010-08-27  Kimmo Kinnunen  <kimmo.t.kinnunen at nokia.com>
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        [Qt] Cache plugin info to a persistent database
+
+        https://bugs.webkit.org/show_bug.cgi?id=43179
+
+        Implement a cache of NPAPI plugin metadata. Write the metadata to aa
+        file that gets rewritten if any plugin is added / removed.  Compilation
+        of the feature is controlled by #if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE)
+
+        Currently only enabled for Qt UNIX flavors.
+
+        * Api/qwebplugindatabase.cpp:
+        (QWebPluginDatabase::plugins):  Match previous behavior: ensure all returned plugins are loaded.
+        * Api/qwebsettings.cpp:
+        (QWebSettings::enablePersistentStorage): Set plugin cache path.
+
 2010-08-27  Benjamin Poulain  <benjamin.poulain at nokia.com>
 
         Reviewed by Kenneth Rohde Christiansen.

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list