String PluginDatabase::MIMETypeForExtension(const String& extension) const { if (extension.isEmpty()) return String(); PluginSet::const_iterator end = m_plugins.end(); String mimeType; Vector<PluginPackage*, 2> pluginChoices; HashMap<PluginPackage*, String> mimeTypeForPlugin; for (PluginSet::const_iterator it = m_plugins.begin(); it != end; ++it) { if (!(*it)->isEnabled()) continue; MIMEToExtensionsMap::const_iterator mime_end = (*it)->mimeToExtensions().end(); for (MIMEToExtensionsMap::const_iterator mime_it = (*it)->mimeToExtensions().begin(); mime_it != mime_end; ++mime_it) { mimeType = mime_it->first; PluginPackage* preferredPlugin = m_preferredPlugins.get(mimeType).get(); const Vector<String>& extensions = mime_it->second; bool foundMapping = false; for (unsigned i = 0; i < extensions.size(); i++) { if (equalIgnoringCase(extensions[i], extension)) { PluginPackage* plugin = (*it).get(); if (preferredPlugin && PluginPackage::equal(*plugin, *preferredPlugin)) return mimeType; #if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE) if (!plugin->ensurePluginLoaded()) continue; #endif pluginChoices.append(plugin); mimeTypeForPlugin.add(plugin, mimeType); foundMapping = true; break; } } if (foundMapping) break; } } if (pluginChoices.isEmpty()) return String(); qsort(pluginChoices.data(), pluginChoices.size(), sizeof(PluginPackage*), PluginDatabase::preferredPluginCompare); return mimeTypeForPlugin.get(pluginChoices[0]); }
PluginPackage* PluginDatabase::pluginForMIMEType(const String& mimeType) { if (mimeType.isEmpty()) return 0; String key = mimeType.lower(); PluginSet::const_iterator end = m_plugins.end(); PluginPackage* preferredPlugin = m_preferredPlugins.get(key).get(); if (preferredPlugin && preferredPlugin->isEnabled() && preferredPlugin->mimeToDescriptions().contains(key)) { return preferredPlugin; } Vector<PluginPackage*, 2> pluginChoices; for (PluginSet::const_iterator it = m_plugins.begin(); it != end; ++it) { PluginPackage* plugin = (*it).get(); if (!plugin->isEnabled()) continue; if (plugin->mimeToDescriptions().contains(key)) { #if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE) if (!plugin->ensurePluginLoaded()) continue; #endif pluginChoices.append(plugin); } } if (pluginChoices.isEmpty()) return 0; qsort(pluginChoices.data(), pluginChoices.size(), sizeof(PluginPackage*), PluginDatabase::preferredPluginCompare); return pluginChoices[0]; }