mozilla-prefer_plugin_pref.patch
changeset 505 edb0bc96e43b
parent 491 43deb5e6462d
child 541 830e50bbfc79
equal deleted inserted replaced
504:6044341b3987 505:edb0bc96e43b
     2 Subject: introduce a pref to prefer certain plugins for mime-types
     2 Subject: introduce a pref to prefer certain plugins for mime-types
     3 
     3 
     4 diff --git a/dom/plugins/base/nsPluginHost.cpp b/dom/plugins/base/nsPluginHost.cpp
     4 diff --git a/dom/plugins/base/nsPluginHost.cpp b/dom/plugins/base/nsPluginHost.cpp
     5 --- a/dom/plugins/base/nsPluginHost.cpp
     5 --- a/dom/plugins/base/nsPluginHost.cpp
     6 +++ b/dom/plugins/base/nsPluginHost.cpp
     6 +++ b/dom/plugins/base/nsPluginHost.cpp
     7 @@ -1513,19 +1513,51 @@ nsPluginHost::FindPluginForType(const ch
     7 @@ -1561,17 +1561,45 @@ nsPluginHost::FindPluginForType(const ch
     8                                  bool aCheckEnabled)
     8                                  bool aCheckEnabled)
     9  {
     9  {
    10    if (!aMimeType) {
    10    if (!aMimeType) {
    11      return nsnull;
    11      return nsnull;
    12    }
    12    }
    13  
    13  
    14    LoadPlugins();
    14    LoadPlugins();
    15  
    15  
    16 +  nsresult res;
       
    17 +  nsCOMPtr<nsIPrefBranch> prefB (do_QueryInterface(mPrefService));
       
    18 +
       
    19 +  char *preferredPluginPath = NULL;
    16 +  char *preferredPluginPath = NULL;
    20 +  nsCAutoString mimetypePrefString ("modules.plugins.mimetype.");
    17 +  nsCAutoString mimetypePrefString ("modules.plugins.mimetype.");
    21 +  mimetypePrefString.Append(aMimeType);
    18 +  mimetypePrefString.Append(aMimeType);
    22 +  const char *mimetypePrefChar = mimetypePrefString.get();
    19 +  const char *mimetypePrefChar = mimetypePrefString.get();
    23 +  res = prefB->GetCharPref(mimetypePrefChar, &preferredPluginPath);
    20 +  nsAdoptingCString pluginPath = Preferences::GetCString(mimetypePrefChar);
       
    21 +  preferredPluginPath = (char*) pluginPath.get();
    24 +
    22 +
    25 +  if(!NS_SUCCEEDED(res)) preferredPluginPath = NULL;
       
    26 +
       
    27    InfallibleTArray<nsPluginTag*> matchingPlugins;
       
    28  
       
    29    nsPluginTag *plugin = mPlugins;
    23    nsPluginTag *plugin = mPlugins;
    30 +
    24 +
    31 +  if(preferredPluginPath) {
    25 +  if(preferredPluginPath) {
    32 +    while (nsnull != plugin) {
    26 +    while (nsnull != plugin) {
    33 +      if (0 == PL_strcasecmp(plugin->mFileName.get(), preferredPluginPath) ||
    27 +      if (0 == PL_strcasecmp(plugin->mFileName.get(), preferredPluginPath) ||
    34 +          0 == PL_strcasecmp(plugin->mFullPath.get(), preferredPluginPath)) {
    28 +          0 == PL_strcasecmp(plugin->mFullPath.get(), preferredPluginPath)) {
    35 +        matchingPlugins.AppendElement(plugin);
    29 +        return plugin;
    36 +      }
    30 +      }
    37 +      plugin = plugin->mNext;
    31 +      plugin = plugin->mNext;
    38 +    }
    32 +    }
    39 +
    33 +
    40 +    // now lets search for substrings
    34 +    // now lets search for substrings
    41 +    plugin = mPlugins;
    35 +    plugin = mPlugins;
    42 +    while (nsnull != plugin) {
    36 +    while (nsnull != plugin) {
    43 +      if (nsnull != PL_strstr(plugin->mFileName.get(), preferredPluginPath) ||
    37 +      if (nsnull != PL_strstr(plugin->mFileName.get(), preferredPluginPath) ||
    44 +          nsnull != PL_strstr(plugin->mFullPath.get(), preferredPluginPath)) {
    38 +          nsnull != PL_strstr(plugin->mFullPath.get(), preferredPluginPath)) {
    45 +        matchingPlugins.AppendElement(plugin);
    39 +        return plugin;
    46 +      }
    40 +      }
    47 +      plugin = plugin->mNext;
    41 +      plugin = plugin->mNext;
    48 +    }
    42 +    }
    49 +  }
    43 +  }
    50 +
    44 +
    51    while (plugin) {
    45    while (plugin) {
    52      if (!aCheckEnabled || plugin->IsEnabled()) {
    46      if (!aCheckEnabled || plugin->IsEnabled()) {
    53        PRInt32 mimeCount = plugin->mMimeTypes.Length();
    47        PRInt32 mimeCount = plugin->mMimeTypes.Length();
    54        for (PRInt32 i = 0; i < mimeCount; i++) {
    48        for (PRInt32 i = 0; i < mimeCount; i++) {
    55          if (0 == PL_strcasecmp(plugin->mMimeTypes[i].get(), aMimeType)) {
    49          if (0 == PL_strcasecmp(plugin->mMimeTypes[i].get(), aMimeType)) {
    56            matchingPlugins.AppendElement(plugin);
    50            return plugin;
    57            break;
       
    58          }
    51          }
       
    52        }