1 From: Ubuntu |
1 From: Ubuntu |
2 Introduce a pref to prefer certain plugins for mime-types |
2 Subject: introduce a pref to prefer certain plugins for mime-types |
3 |
|
4 For example: |
|
5 pref ("modules.plugins.mimetype.application/x-shockwave-flash", "/usr/lib/firefox-3.0.1/plugins/libflashplayer.so") |
|
6 |
|
7 would make the flashplyer installed in that location the preferred one to use. |
|
8 |
3 |
9 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 |
10 --- a/dom/plugins/base/nsPluginHost.cpp |
5 --- a/dom/plugins/base/nsPluginHost.cpp |
11 +++ b/dom/plugins/base/nsPluginHost.cpp |
6 +++ b/dom/plugins/base/nsPluginHost.cpp |
12 @@ -1556,17 +1556,45 @@ nsPluginHost::FindPluginForType(const ch |
7 @@ -1581,19 +1581,51 @@ nsPluginHost::FindPluginForType(const ch |
13 bool aCheckEnabled) |
8 bool aCheckEnabled) |
14 { |
9 { |
15 if (!aMimeType) { |
10 if (!aMimeType) { |
16 return nsnull; |
11 return nsnull; |
17 } |
12 } |
18 |
13 |
19 LoadPlugins(); |
14 LoadPlugins(); |
20 |
15 |
21 + nsCAutoString mimetypePref("modules.plugins.mimetype."); |
16 + nsresult res; |
22 + mimetypePref.Append(aMimeType); |
17 + nsCOMPtr<nsIPrefBranch> prefB (do_QueryInterface(mPrefService)); |
23 + |
18 + |
24 + nsAdoptingCString preferred = Preferences::GetCString(mimetypePref.get()); |
19 + char *preferredPluginPath = NULL; |
|
20 + nsCAutoString mimetypePrefString ("modules.plugins.mimetype."); |
|
21 + mimetypePrefString.Append(aMimeType); |
|
22 + const char *mimetypePrefChar = mimetypePrefString.get(); |
|
23 + res = prefB->GetCharPref(mimetypePrefChar, &preferredPluginPath); |
25 + |
24 + |
|
25 + if(!NS_SUCCEEDED(res)) preferredPluginPath = NULL; |
|
26 + |
|
27 InfallibleTArray<nsPluginTag*> matchingPlugins; |
|
28 |
26 nsPluginTag *plugin = mPlugins; |
29 nsPluginTag *plugin = mPlugins; |
27 + if(!preferred.IsEmpty()) { |
|
28 + nsCOMPtr<nsILocalFile> file; |
|
29 + nsresult rv = NS_NewNativeLocalFile(preferred, false, getter_AddRefs(file)); |
|
30 + bool isAbsolute = NS_SUCCEEDED(rv); |
|
31 + |
30 + |
32 + while (plugin) { |
31 + if(preferredPluginPath) { |
33 + if (((!isAbsolute && 0 == PL_strcasecmp(plugin->mFileName.get(), preferred.get())) || |
32 + while (nsnull != plugin) { |
34 + (isAbsolute && 0 == PL_strcasecmp(plugin->mFullPath.get(), preferred.get()))) && |
33 + if (0 == PL_strcasecmp(plugin->mFileName.get(), preferredPluginPath) || |
35 + (!aCheckEnabled || plugin->IsEnabled())) { |
34 + 0 == PL_strcasecmp(plugin->mFullPath.get(), preferredPluginPath)) { |
36 + PRInt32 mimeCount = plugin->mMimeTypes.Length(); |
35 + matchingPlugins.AppendElement(plugin); |
37 + for (PRInt32 i = 0; i < mimeCount; i++) { |
36 + } |
38 + if (0 == PL_strcasecmp(plugin->mMimeTypes[i].get(), aMimeType)) { |
37 + plugin = plugin->mNext; |
39 + return plugin; |
38 + } |
40 + } |
39 + |
41 + } |
40 + // now lets search for substrings |
|
41 + plugin = mPlugins; |
|
42 + while (nsnull != plugin) { |
|
43 + if (nsnull != PL_strstr(plugin->mFileName.get(), preferredPluginPath) || |
|
44 + nsnull != PL_strstr(plugin->mFullPath.get(), preferredPluginPath)) { |
|
45 + matchingPlugins.AppendElement(plugin); |
42 + } |
46 + } |
43 + plugin = plugin->mNext; |
47 + plugin = plugin->mNext; |
44 + } |
48 + } |
45 + } |
49 + } |
46 + |
50 + |
47 + // if there is no pref for this mime-type, or if the plugin named in pref |
|
48 + // isn't found, we pick the first that matches for this mime-type |
|
49 + plugin = mPlugins; |
|
50 while (plugin) { |
51 while (plugin) { |
51 if (!aCheckEnabled || plugin->IsEnabled()) { |
52 if (!aCheckEnabled || plugin->IsEnabled()) { |
52 PRInt32 mimeCount = plugin->mMimeTypes.Length(); |
53 PRInt32 mimeCount = plugin->mMimeTypes.Length(); |
53 for (PRInt32 i = 0; i < mimeCount; i++) { |
54 for (PRInt32 i = 0; i < mimeCount; i++) { |
54 if (0 == PL_strcasecmp(plugin->mMimeTypes[i].get(), aMimeType)) { |
55 if (0 == PL_strcasecmp(plugin->mMimeTypes[i].get(), aMimeType)) { |
55 return plugin; |
56 matchingPlugins.AppendElement(plugin); |
|
57 break; |
56 } |
58 } |
57 } |
|