Home | History | Annotate | Download | only in plugins
      1 /*
      2  * Copyright (C) 2006, 2007 Apple Inc.  All rights reserved.
      3  * Copyright (C) 2008 Collabora, Ltd.  All rights reserved.
      4  * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  *
     15  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
     16  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     18  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
     19  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     20  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     22  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
     23  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26  */
     27 
     28 #ifndef PluginDatabase_h
     29 #define PluginDatabase_h
     30 
     31 #include "PlatformString.h"
     32 #include "PluginPackage.h"
     33 #include <wtf/HashSet.h>
     34 #include <wtf/Vector.h>
     35 #include <wtf/text/StringHash.h>
     36 
     37 #if defined(ANDROID_PLUGINS)
     38 namespace android {
     39     class WebSettings;
     40 }
     41 #endif
     42 
     43 namespace WebCore {
     44     class Element;
     45     class Frame;
     46     class IntSize;
     47     class KURL;
     48     class PluginDatabaseClient;
     49     class PluginPackage;
     50 
     51     typedef HashSet<RefPtr<PluginPackage>, PluginPackageHash> PluginSet;
     52 
     53     class PluginDatabase {
     54         WTF_MAKE_NONCOPYABLE(PluginDatabase); WTF_MAKE_FAST_ALLOCATED;
     55     public:
     56         PluginDatabase();
     57 
     58         // The first call to installedPlugins creates the plugin database
     59         // and by default populates it with the plugins installed on the system.
     60         // For testing purposes, it is possible to not populate the database
     61         // automatically, as the plugins might affect the DRT results by
     62         // writing to a.o. stderr.
     63         static PluginDatabase* installedPlugins(bool populate = true);
     64 
     65         bool refresh();
     66         void clear();
     67         Vector<PluginPackage*> plugins() const;
     68         bool isMIMETypeRegistered(const String& mimeType);
     69         void addExtraPluginDirectory(const String&);
     70 
     71         static bool isPreferredPluginDirectory(const String& directory);
     72         static int preferredPluginCompare(const void*, const void*);
     73 
     74         PluginPackage* findPlugin(const KURL&, String& mimeType);
     75         PluginPackage* pluginForMIMEType(const String& mimeType);
     76         void setPreferredPluginForMIMEType(const String& mimeType, PluginPackage* plugin);
     77 
     78         void setPluginDirectories(const Vector<String>& directories)
     79         {
     80             clear();
     81             m_pluginDirectories = directories;
     82         }
     83 
     84         static Vector<String> defaultPluginDirectories();
     85         Vector<String> pluginDirectories() const { return m_pluginDirectories; }
     86 
     87         String MIMETypeForExtension(const String& extension) const;
     88 #if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE)
     89         static bool isPersistentMetadataCacheEnabled();
     90         static void setPersistentMetadataCacheEnabled(bool isEnabled);
     91         static String persistentMetadataCachePath();
     92         static void setPersistentMetadataCachePath(const String& persistentMetadataCachePath);
     93 #endif
     94 
     95     private:
     96         void getPluginPathsInDirectories(HashSet<String>&) const;
     97         void getDeletedPlugins(PluginSet&) const;
     98 
     99         // Returns whether the plugin was actually added or not (it won't be added if it's a duplicate of an existing plugin).
    100         bool add(PassRefPtr<PluginPackage>);
    101         void remove(PluginPackage*);
    102 #if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE)
    103         void loadPersistentMetadataCache();
    104         void updatePersistentMetadataCache();
    105 #endif
    106 
    107         Vector<String> m_pluginDirectories;
    108         HashSet<String> m_registeredMIMETypes;
    109         PluginSet m_plugins;
    110         HashMap<String, RefPtr<PluginPackage> > m_pluginsByPath;
    111         HashMap<String, time_t> m_pluginPathsWithTimes;
    112 
    113 #if defined(ANDROID_PLUGINS)
    114         // Need access to setPluginDirectories() to change the default
    115         // path after startup.
    116         friend class ::android::WebSettings;
    117 #endif
    118         HashMap<String, RefPtr<PluginPackage> > m_preferredPlugins;
    119 #if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE)
    120         bool m_persistentMetadataCacheIsLoaded;
    121 #endif
    122     };
    123 
    124 } // namespace WebCore
    125 
    126 #endif
    127