mozilla-prefer_plugin_pref.patch
author Wolfgang Rosenauer <wr@rosenauer.org>
Fri, 27 Aug 2010 08:34:04 +0200
changeset 149 89644d97e55f
parent 123 1d88ea95ad20
child 289 3c0dff7ca9c4
permissions -rw-r--r--
fix whitespaces

From: Ubuntu
Subject: introduce a pref to prefer certain plugins for mime-types

diff --git a/modules/plugin/base/src/nsPluginHost.cpp b/modules/plugin/base/src/nsPluginHost.cpp
--- a/modules/plugin/base/src/nsPluginHost.cpp
+++ b/modules/plugin/base/src/nsPluginHost.cpp
@@ -1620,17 +1620,47 @@ nsPluginHost::FindPluginForType(const ch
   nsPluginTag *plugins = nsnull;
   PRInt32     variants, cnt;
 
   LoadPlugins();
 
   // if we have a mimetype passed in, search the mPlugins
   // linked list for a match
   if (aMimeType) {
+    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;
+
     plugins = mPlugins;
+    if(preferredPluginPath) {
+      while (nsnull != plugins) {
+        if (0 == PL_strcasecmp(plugins->mFileName.get(), preferredPluginPath) ||
+            0 == PL_strcasecmp(plugins->mFullPath.get(), preferredPluginPath)) {
+          return plugins;
+        }
+        plugins = plugins->mNext;
+      }
+
+      // now lets search for substrings
+      plugins=mPlugins;
+      while (nsnull != plugins) {
+        if (nsnull != PL_strstr(plugins->mFileName.get(), preferredPluginPath) ||
+            nsnull != PL_strstr(plugins->mFullPath.get(), preferredPluginPath)) {
+          return plugins;
+        }
+        plugins = plugins->mNext;
+      }
+    }
 
     while (plugins) {
       variants = plugins->mVariants;
       for (cnt = 0; cnt < variants; cnt++) {
         if ((!aCheckEnabled || plugins->IsEnabled()) &&
             plugins->mMimeTypeArray[cnt] &&
             (0 == PL_strcasecmp(plugins->mMimeTypeArray[cnt], aMimeType))) {
           return plugins;