• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2006, 2007 Apple Inc.  All rights reserved.
3  * Copyright (C) 2008 Collabora, Ltd.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26 
27 #ifndef PluginPackage_H
28 #define PluginPackage_H
29 
30 #include "FileSystem.h"
31 #include "PlatformString.h"
32 #include "PluginQuirkSet.h"
33 #include "StringHash.h"
34 #include "Timer.h"
35 #include "npruntime_internal.h"
36 #include <wtf/HashMap.h>
37 #include <wtf/RefCounted.h>
38 #if defined(ANDROID_PLUGINS)
39 #include <nativehelper/jni.h>
40 #endif
41 
42 namespace WebCore {
43     typedef HashMap<String, String> MIMEToDescriptionsMap;
44     typedef HashMap<String, Vector<String> > MIMEToExtensionsMap;
45 
46     class PluginPackage : public RefCounted<PluginPackage> {
47     public:
48         ~PluginPackage();
49         static PassRefPtr<PluginPackage> createPackage(const String& path, const time_t& lastModified);
50 
name()51         const String& name() const { return m_name; }
description()52         const String& description() const { return m_description; }
path()53         const String& path() const { return m_path; }
fileName()54         const String& fileName() const { return m_fileName; }
parentDirectory()55         const String& parentDirectory() const { return m_parentDirectory; }
lastModified()56         time_t lastModified() const { return m_lastModified; }
57 
mimeToDescriptions()58         const MIMEToDescriptionsMap& mimeToDescriptions() const { return m_mimeToDescriptions; }
mimeToExtensions()59         const MIMEToExtensionsMap& mimeToExtensions() const { return m_mimeToExtensions; }
60 
61         unsigned hash() const;
62         static bool equal(const PluginPackage& a, const PluginPackage& b);
63 
64         bool load();
65         void unload();
66         void unloadWithoutShutdown();
67 
pluginFuncs()68         const NPPluginFuncs* pluginFuncs() const { return &m_pluginFuncs; }
69         int compareFileVersion(const PlatformModuleVersion&) const;
70         int compare(const PluginPackage&) const;
quirks()71         PluginQuirkSet quirks() const { return m_quirks; }
version()72         const PlatformModuleVersion& version() const { return m_moduleVersion; }
73 
74     private:
75         PluginPackage(const String& path, const time_t& lastModified);
76         bool fetchInfo();
77         bool isPluginBlacklisted();
78         void determineQuirks(const String& mimeType);
79 
80         void determineModuleVersionFromDescription();
81 
82         bool m_isLoaded;
83         int m_loadCount;
84 
85         String m_description;
86         String m_path;
87         String m_fileName;
88         String m_name;
89         String m_parentDirectory;
90 
91         PlatformModuleVersion m_moduleVersion;
92 
93         MIMEToDescriptionsMap m_mimeToDescriptions;
94         MIMEToExtensionsMap m_mimeToExtensions;
95 
96         PlatformModule m_module;
97         time_t m_lastModified;
98 
99         NPP_ShutdownProcPtr m_NPP_Shutdown;
100         NPPluginFuncs m_pluginFuncs;
101         NPNetscapeFuncs m_browserFuncs;
102 
103         void freeLibrarySoon();
104         void freeLibraryTimerFired(Timer<PluginPackage>*);
105         Timer<PluginPackage> m_freeLibraryTimer;
106 
107         PluginQuirkSet m_quirks;
108 
109 #if defined(ANDROID_PLUGINS)
110         // Java Plugin object.
111         jobject m_pluginObject;
112         // Called from unloadWithoutShutdown() to remove the object
113         // from the PluginList.
114         void unregisterPluginObject();
115 #endif
116     };
117 
118     struct PluginPackageHash {
hashPluginPackageHash119         static unsigned hash(const uintptr_t key) { return reinterpret_cast<PluginPackage*>(key)->hash(); }
hashPluginPackageHash120         static unsigned hash(const RefPtr<PluginPackage>& key) { return key->hash(); }
121 
equalPluginPackageHash122         static bool equal(const uintptr_t a, const uintptr_t b) { return equal(reinterpret_cast<PluginPackage*>(a), reinterpret_cast<PluginPackage*>(b)); }
equalPluginPackageHash123         static bool equal(const RefPtr<PluginPackage>& a, const RefPtr<PluginPackage>& b) { return PluginPackage::equal(*a.get(), *b.get()); }
124         static const bool safeToCompareToEmptyOrDeleted = false;
125     };
126 
127 } // namespace WebCore
128 
129 #endif
130