| 1 | /* |
| 2 | * Copyright (C) 2010 Apple Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
| 14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
| 17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 23 | * THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #ifndef NetscapePluginModule_h |
| 27 | #define NetscapePluginModule_h |
| 28 | |
| 29 | #if ENABLE(NETSCAPE_PLUGIN_API) |
| 30 | |
| 31 | #include "Module.h" |
| 32 | #include "PluginModuleInfo.h" |
| 33 | #include "PluginQuirks.h" |
| 34 | #include <WebCore/npruntime_internal.h> |
| 35 | #include <wtf/RefCounted.h> |
| 36 | #include <wtf/text/WTFString.h> |
| 37 | |
| 38 | namespace WebCore { |
| 39 | struct MimeClassInfo; |
| 40 | } |
| 41 | |
| 42 | namespace WebKit { |
| 43 | |
| 44 | struct RawPluginMetaData; |
| 45 | |
| 46 | class NetscapePluginModule : public RefCounted<NetscapePluginModule> { |
| 47 | public: |
| 48 | static RefPtr<NetscapePluginModule> getOrCreate(const String& pluginPath); |
| 49 | ~NetscapePluginModule(); |
| 50 | |
| 51 | const NPPluginFuncs& pluginFuncs() const { return m_pluginFuncs; } |
| 52 | |
| 53 | void incrementLoadCount(); |
| 54 | void decrementLoadCount(); |
| 55 | |
| 56 | static bool getPluginInfo(const String& pluginPath, PluginModuleInfo&); |
| 57 | |
| 58 | const PluginQuirks& pluginQuirks() const { return m_pluginQuirks; } |
| 59 | |
| 60 | // Return a list of domains for which the plug-in has data stored. |
| 61 | Vector<String> sitesWithData(); |
| 62 | |
| 63 | // Request that the plug-in clear the site data. |
| 64 | bool clearSiteData(const String& site, uint64_t flags, uint64_t maxAge); |
| 65 | |
| 66 | Module* module() const { return m_module.get(); } |
| 67 | |
| 68 | #if PLUGIN_ARCHITECTURE(UNIX) |
| 69 | static bool scanPlugin(const String& pluginPath); |
| 70 | static void parseMIMEDescription(const String& mimeDescription, Vector<WebCore::MimeClassInfo>& result); |
| 71 | static String buildMIMEDescription(const Vector<WebCore::MimeClassInfo>&); |
| 72 | #endif |
| 73 | |
| 74 | private: |
| 75 | explicit NetscapePluginModule(const String& pluginPath); |
| 76 | |
| 77 | void determineQuirks(); |
| 78 | |
| 79 | #if PLUGIN_ARCHITECTURE(UNIX) |
| 80 | bool getPluginInfoForLoadedPlugin(RawPluginMetaData&); |
| 81 | #endif |
| 82 | |
| 83 | bool tryGetSitesWithData(Vector<String>&); |
| 84 | bool tryClearSiteData(const String& site, uint64_t flags, uint64_t maxAge); |
| 85 | |
| 86 | bool tryLoad(); |
| 87 | bool load(); |
| 88 | void unload(); |
| 89 | |
| 90 | void shutdown(); |
| 91 | |
| 92 | String m_pluginPath; |
| 93 | bool m_isInitialized; |
| 94 | unsigned m_loadCount; |
| 95 | |
| 96 | PluginQuirks m_pluginQuirks; |
| 97 | |
| 98 | NPP_ShutdownProcPtr m_shutdownProcPtr; |
| 99 | NPPluginFuncs m_pluginFuncs; |
| 100 | |
| 101 | std::unique_ptr<Module> m_module; |
| 102 | }; |
| 103 | |
| 104 | } // namespace WebKit |
| 105 | |
| 106 | #endif // ENABLE(NETSCAPE_PLUGIN_API) |
| 107 | |
| 108 | #endif // NetscapePluginModule_h |
| 109 | |