mozilla-prefer_plugin_pref.patch
branchfirefox14
changeset 490 be017dcbd7af
parent 439 7704a021055f
child 492 c0088c242dab
--- a/mozilla-prefer_plugin_pref.patch	Wed Jun 20 21:17:20 2012 +0200
+++ b/mozilla-prefer_plugin_pref.patch	Mon Jun 25 22:09:15 2012 +0200
@@ -1,15 +1,10 @@
 From: Ubuntu
-Introduce a pref to prefer certain plugins for mime-types
-
-For example:
- pref ("modules.plugins.mimetype.application/x-shockwave-flash", "/usr/lib/firefox-3.0.1/plugins/libflashplayer.so")
-
- would make the flashplyer installed in that location the preferred one to use.
+Subject: introduce a pref to prefer certain plugins for mime-types
 
 diff --git a/dom/plugins/base/nsPluginHost.cpp b/dom/plugins/base/nsPluginHost.cpp
 --- a/dom/plugins/base/nsPluginHost.cpp
 +++ b/dom/plugins/base/nsPluginHost.cpp
-@@ -1556,17 +1556,45 @@ nsPluginHost::FindPluginForType(const ch
+@@ -1581,19 +1581,51 @@ nsPluginHost::FindPluginForType(const ch
                                  bool aCheckEnabled)
  {
    if (!aMimeType) {
@@ -18,40 +13,46 @@
  
    LoadPlugins();
  
-+  nsCAutoString mimetypePref("modules.plugins.mimetype.");
-+  mimetypePref.Append(aMimeType);
-+
-+  nsAdoptingCString preferred = Preferences::GetCString(mimetypePref.get());
++  nsresult res;
++  nsCOMPtr<nsIPrefBranch> prefB (do_QueryInterface(mPrefService));
 +
++  char *preferredPluginPath = NULL;
++  nsCAutoString mimetypePrefString ("modules.plugins.mimetype.");
++  mimetypePrefString.Append(aMimeType);
++  const char *mimetypePrefChar = mimetypePrefString.get();
++  res = prefB->GetCharPref(mimetypePrefChar, &preferredPluginPath);
++
++  if(!NS_SUCCEEDED(res)) preferredPluginPath = NULL;
++
+   InfallibleTArray<nsPluginTag*> matchingPlugins;
+ 
    nsPluginTag *plugin = mPlugins;
-+  if(!preferred.IsEmpty()) {
-+    nsCOMPtr<nsILocalFile> file;
-+    nsresult rv = NS_NewNativeLocalFile(preferred, false, getter_AddRefs(file));
-+    bool isAbsolute = NS_SUCCEEDED(rv);
 +
-+    while (plugin) {
-+      if (((!isAbsolute && 0 == PL_strcasecmp(plugin->mFileName.get(), preferred.get())) ||
-+            (isAbsolute && 0 == PL_strcasecmp(plugin->mFullPath.get(), preferred.get()))) &&
-+          (!aCheckEnabled || plugin->IsEnabled())) {
-+        PRInt32 mimeCount = plugin->mMimeTypes.Length();
-+        for (PRInt32 i = 0; i < mimeCount; i++) {
-+          if (0 == PL_strcasecmp(plugin->mMimeTypes[i].get(), aMimeType)) {
-+            return plugin;
-+          }
-+        }
++  if(preferredPluginPath) {
++    while (nsnull != plugin) {
++      if (0 == PL_strcasecmp(plugin->mFileName.get(), preferredPluginPath) ||
++          0 == PL_strcasecmp(plugin->mFullPath.get(), preferredPluginPath)) {
++        matchingPlugins.AppendElement(plugin);
++      }
++      plugin = plugin->mNext;
++    }
++
++    // now lets search for substrings
++    plugin = mPlugins;
++    while (nsnull != plugin) {
++      if (nsnull != PL_strstr(plugin->mFileName.get(), preferredPluginPath) ||
++          nsnull != PL_strstr(plugin->mFullPath.get(), preferredPluginPath)) {
++        matchingPlugins.AppendElement(plugin);
 +      }
 +      plugin = plugin->mNext;
 +    }
 +  }
 +
-+  // if there is no pref for this mime-type, or if the plugin named in pref
-+  // isn't found, we pick the first that matches for this mime-type
-+  plugin = mPlugins;
    while (plugin) {
      if (!aCheckEnabled || plugin->IsEnabled()) {
        PRInt32 mimeCount = plugin->mMimeTypes.Length();
        for (PRInt32 i = 0; i < mimeCount; i++) {
          if (0 == PL_strcasecmp(plugin->mMimeTypes[i].get(), aMimeType)) {
-           return plugin;
+           matchingPlugins.AppendElement(plugin);
+           break;
          }
-       }