diff options
Diffstat (limited to 'Source/WebKit2/UIProcess/Plugins/gtk')
-rw-r--r-- | Source/WebKit2/UIProcess/Plugins/gtk/PluginInfoCache.cpp | 52 | ||||
-rw-r--r-- | Source/WebKit2/UIProcess/Plugins/gtk/PluginInfoCache.h | 10 |
2 files changed, 36 insertions, 26 deletions
diff --git a/Source/WebKit2/UIProcess/Plugins/gtk/PluginInfoCache.cpp b/Source/WebKit2/UIProcess/Plugins/gtk/PluginInfoCache.cpp index c6e46524d..3e1c2ef5a 100644 --- a/Source/WebKit2/UIProcess/Plugins/gtk/PluginInfoCache.cpp +++ b/Source/WebKit2/UIProcess/Plugins/gtk/PluginInfoCache.cpp @@ -30,26 +30,48 @@ #include "NetscapePluginModule.h" #include <WebCore/FileSystem.h> +#include <WebCore/PlatformDisplay.h> #include <wtf/text/CString.h> namespace WebKit { -static const unsigned gSchemaVersion = 1; +static const unsigned gSchemaVersion = 3; -PluginInfoCache& PluginInfoCache::shared() +PluginInfoCache& PluginInfoCache::singleton() { static NeverDestroyed<PluginInfoCache> pluginInfoCache; return pluginInfoCache; } +static inline const char* cacheFilenameForCurrentDisplay() +{ +#if PLATFORM(X11) + if (WebCore::PlatformDisplay::sharedDisplay().type() == WebCore::PlatformDisplay::Type::X11) + return "plugins-x11"; +#endif +#if PLATFORM(WAYLAND) + if (WebCore::PlatformDisplay::sharedDisplay().type() == WebCore::PlatformDisplay::Type::Wayland) + return "plugins-wayland"; +#endif + + ASSERT_NOT_REACHED(); + return "plugins"; +} + PluginInfoCache::PluginInfoCache() : m_cacheFile(g_key_file_new()) - , m_saveToFileIdleId(0) + , m_saveToFileIdle(RunLoop::main(), this, &PluginInfoCache::saveToFile) , m_readOnlyMode(false) { + m_saveToFileIdle.setPriority(G_PRIORITY_DEFAULT_IDLE); + GUniquePtr<char> cacheDirectory(g_build_filename(g_get_user_cache_dir(), "webkitgtk", nullptr)); if (WebCore::makeAllDirectories(cacheDirectory.get())) { - m_cachePath.reset(g_build_filename(cacheDirectory.get(), "plugins", nullptr)); + // Delete old cache file. + GUniquePtr<char> oldCachePath(g_build_filename(cacheDirectory.get(), "plugins", nullptr)); + WebCore::deleteFile(WebCore::stringFromFileSystemRepresentation(oldCachePath.get())); + + m_cachePath.reset(g_build_filename(cacheDirectory.get(), cacheFilenameForCurrentDisplay(), nullptr)); g_key_file_load_from_file(m_cacheFile.get(), m_cachePath.get(), G_KEY_FILE_NONE, nullptr); } @@ -72,23 +94,10 @@ PluginInfoCache::PluginInfoCache() PluginInfoCache::~PluginInfoCache() { - if (m_saveToFileIdleId) { - g_source_remove(m_saveToFileIdleId); - saveToFile(); - } -} - -gboolean PluginInfoCache::saveToFileIdleCallback(PluginInfoCache* cache) -{ - cache->saveToFile(); - return FALSE; } void PluginInfoCache::saveToFile() { - std::lock_guard<std::mutex> lock(m_mutex); - m_saveToFileIdleId = 0; - gsize dataLength; GUniquePtr<char> data(g_key_file_to_data(m_cacheFile.get(), &dataLength, nullptr)); if (!data) @@ -124,6 +133,8 @@ bool PluginInfoCache::getPluginInfo(const String& pluginPath, PluginModuleInfo& NetscapePluginModule::parseMIMEDescription(String::fromUTF8(stringValue.get()), plugin.info.mimes); #endif + plugin.requiresGtk2 = g_key_file_get_boolean(m_cacheFile.get(), pluginGroup.data(), "requires-gtk2", nullptr); + return true; } @@ -143,14 +154,15 @@ void PluginInfoCache::updatePluginInfo(const String& pluginPath, const PluginMod g_key_file_set_string(m_cacheFile.get(), pluginGroup.data(), "mime-description", mimeDescription.utf8().data()); #endif + g_key_file_set_boolean(m_cacheFile.get(), pluginGroup.data(), "requires-gtk2", plugin.requiresGtk2); + if (m_cachePath && !m_readOnlyMode) { // 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<std::mutex> lock(m_mutex); - if (m_saveToFileIdleId) + if (m_saveToFileIdle.isActive()) return; - m_saveToFileIdleId = g_idle_add(reinterpret_cast<GSourceFunc>(PluginInfoCache::saveToFileIdleCallback), this); + m_saveToFileIdle.startOneShot(0); } } diff --git a/Source/WebKit2/UIProcess/Plugins/gtk/PluginInfoCache.h b/Source/WebKit2/UIProcess/Plugins/gtk/PluginInfoCache.h index 872f1eb01..1af7085e2 100644 --- a/Source/WebKit2/UIProcess/Plugins/gtk/PluginInfoCache.h +++ b/Source/WebKit2/UIProcess/Plugins/gtk/PluginInfoCache.h @@ -29,9 +29,9 @@ #if ENABLE(NETSCAPE_PLUGIN_API) #include "PluginModuleInfo.h" -#include <mutex> #include <wtf/NeverDestroyed.h> -#include <wtf/gobject/GUniquePtr.h> +#include <wtf/RunLoop.h> +#include <wtf/glib/GUniquePtr.h> namespace WebKit { @@ -39,7 +39,7 @@ class PluginInfoCache { WTF_MAKE_NONCOPYABLE(PluginInfoCache); friend class NeverDestroyed<PluginInfoCache>; public: - static PluginInfoCache& shared(); + static PluginInfoCache& singleton(); bool getPluginInfo(const String& pluginPath, PluginModuleInfo&); void updatePluginInfo(const String& pluginPath, const PluginModuleInfo&); @@ -49,13 +49,11 @@ private: ~PluginInfoCache(); void saveToFile(); - static gboolean saveToFileIdleCallback(PluginInfoCache*); GUniquePtr<GKeyFile> m_cacheFile; GUniquePtr<char> m_cachePath; - unsigned m_saveToFileIdleId; + RunLoop::Timer<PluginInfoCache> m_saveToFileIdle; bool m_readOnlyMode; - std::mutex m_mutex; }; } // namespace WebKit |