Changeset 62600 in webkit
- Timestamp:
- Jul 6, 2010 3:52:46 PM (14 years ago)
- Location:
- trunk/WebKit2
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebKit2/ChangeLog
r62590 r62600 1 2010-07-06 Anders Carlsson <andersca@apple.com> 2 3 Reviewed by Sam Weinig. 4 5 Add PluginInfoStore::findPlugin 6 https://bugs.webkit.org/show_bug.cgi?id=41719 7 8 * UIProcess/Plugins/PluginInfoStore.cpp: 9 (WebKit::PluginInfoStore::getPlugins): 10 (WebKit::PluginInfoStore::findPluginForMIMEType): 11 (WebKit::PluginInfoStore::findPluginForExtension): 12 (WebKit::pathExtension): 13 (WebKit::PluginInfoStore::findPlugin): 14 * UIProcess/Plugins/PluginInfoStore.h: 15 * UIProcess/Plugins/mac/PluginInfoStoreMac.mm: 16 (WebKit::PluginInfoStore::mimeTypeFromExtension): 17 1 18 2010-07-06 Sam Weinig <sam@webkit.org> 2 19 -
trunk/WebKit2/UIProcess/Plugins/PluginInfoStore.cpp
r61591 r62600 26 26 #include "PluginInfoStore.h" 27 27 28 #include <algorithm> 29 #include <WebCore/KURL.h> 28 30 #include <wtf/StdLibExtras.h> 29 31 32 using namespace std; 30 33 using namespace WebCore; 31 34 … … 83 86 } 84 87 85 void PluginInfoStore::getPlugins(Vector< WebCore::PluginInfo>& plugins)88 void PluginInfoStore::getPlugins(Vector<PluginInfo>& plugins) 86 89 { 87 90 loadPluginsIfNecessary(); … … 91 94 } 92 95 96 PluginInfoStore::Plugin PluginInfoStore::findPluginForMIMEType(const String& mimeType) 97 { 98 ASSERT(!mimeType.isNull()); 99 100 for (size_t i = 0; i < m_plugins.size(); ++i) { 101 const Plugin& plugin = m_plugins[i]; 102 103 for (size_t j = 0; j < plugin.info.mimes.size(); ++j) { 104 const MimeClassInfo& mimeClassInfo = plugin.info.mimes[j]; 105 if (mimeClassInfo.type == mimeType) 106 return plugin; 107 } 108 } 109 110 return Plugin(); 111 } 112 113 PluginInfoStore::Plugin PluginInfoStore::findPluginForExtension(const String& extension, String& mimeType) 114 { 115 ASSERT(!extension.isNull()); 116 117 for (size_t i = 0; i < m_plugins.size(); ++i) { 118 const Plugin& plugin = m_plugins[i]; 119 120 for (size_t j = 0; j < plugin.info.mimes.size(); ++j) { 121 const MimeClassInfo& mimeClassInfo = plugin.info.mimes[j]; 122 123 const Vector<String>& extensions = mimeClassInfo.extensions; 124 125 if (find(extensions.begin(), extensions.end(), extension) != extensions.end()) { 126 // We found a supported extension, set the correct MIME type. 127 mimeType = mimeClassInfo.type; 128 return plugin; 129 } 130 } 131 } 132 133 return Plugin(); 134 } 135 136 static inline String pathExtension(const KURL& url) 137 { 138 String extension; 139 String filename = url.lastPathComponent(); 140 if (!filename.endsWith("/")) { 141 int extensionPos = filename.reverseFind('.'); 142 if (extensionPos != -1) 143 extension = filename.substring(extensionPos + 1); 144 } 145 146 return extension; 147 } 148 149 PluginInfoStore::Plugin PluginInfoStore::findPlugin(String& mimeType, const KURL& url) 150 { 151 loadPluginsIfNecessary(); 152 153 // First, check if we can get the plug-in based on its MIME type. 154 if (!mimeType.isNull()) { 155 Plugin plugin = findPluginForMIMEType(mimeType); 156 if (!plugin.path.isNull()) 157 return plugin; 158 } 159 160 // Next, check if any plug-ins claim to support the URL extension. 161 String extension = pathExtension(url).lower(); 162 if (!extension.isNull()) { 163 Plugin plugin = findPluginForExtension(extension, mimeType); 164 if (!plugin.path.isNull()) 165 return plugin; 166 167 // Finally, try to get the MIME type from the extension in a platform specific manner and use that. 168 String extensionMimeType = mimeTypeFromExtension(extension); 169 if (!extensionMimeType.isNull()) { 170 Plugin plugin = findPluginForMIMEType(extensionMimeType); 171 if (!plugin.path.isNull()) { 172 mimeType = extensionMimeType; 173 return plugin; 174 } 175 } 176 } 177 178 return Plugin(); 179 } 180 93 181 } // namespace WebKit -
trunk/WebKit2/UIProcess/Plugins/PluginInfoStore.h
r61624 r62600 29 29 #include <WebCore/PluginData.h> 30 30 31 namespace WebCore { 32 class KURL; 33 } 34 31 35 namespace WebKit { 32 36 … … 38 42 void getPlugins(Vector<WebCore::PluginInfo>& plugins); 39 43 40 private:41 PluginInfoStore();42 43 44 // Represents a single plug-in. 44 45 struct Plugin { … … 52 53 }; 53 54 55 // Returns the info for a plug-in that can handle the given MIME type. 56 // If the MIME type is null, the file extension of the given url will be used to infer the 57 // plug-in type. In that case, mimeType will be filled in with the right MIME type. 58 Plugin findPlugin(WebCore::String& mimeType, const WebCore::KURL& url); 59 60 private: 61 PluginInfoStore(); 62 63 Plugin findPluginForMIMEType(const WebCore::String& mimeType); 64 Plugin findPluginForExtension(const WebCore::String& extension, WebCore::String& mimeType); 65 54 66 void loadPluginsIfNecessary(); 55 67 void loadPluginsInDirectory(const WebCore::String& directory); … … 61 73 static bool getPluginInfo(const WebCore::String& pluginPath, Plugin& plugin); 62 74 static bool shouldUsePlugin(const Plugin& plugin, const Vector<Plugin>& loadedPlugins); 75 static WebCore::String mimeTypeFromExtension(const WebCore::String& extension); 63 76 64 77 Vector<Plugin> m_plugins; -
trunk/WebKit2/UIProcess/Plugins/mac/PluginInfoStoreMac.mm
r61725 r62600 29 29 #include <wtf/HashSet.h> 30 30 #include <wtf/RetainPtr.h> 31 #include "WebKitSystemInterface.h" 31 32 32 33 using namespace WebCore; … … 368 369 } 369 370 371 String PluginInfoStore::mimeTypeFromExtension(const WebCore::String& extension) 372 { 373 RetainPtr<CFStringRef> extensionCF(AdoptCF, safeCreateCFString(extension)); 374 375 return WKGetMIMETypeForExtension((NSString *)extensionCF.get()); 376 } 377 370 378 } // namespace WebKit
Note: See TracChangeset
for help on using the changeset viewer.