1 From: Ubuntu |
1 From: Ubuntu |
2 Subject: introduce a pref to prefer certain plugins for mime-types |
2 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. |
3 |
8 |
4 diff --git a/dom/plugins/base/nsPluginHost.cpp b/dom/plugins/base/nsPluginHost.cpp |
9 diff --git a/dom/plugins/base/nsPluginHost.cpp b/dom/plugins/base/nsPluginHost.cpp |
5 --- a/dom/plugins/base/nsPluginHost.cpp |
10 --- a/dom/plugins/base/nsPluginHost.cpp |
6 +++ b/dom/plugins/base/nsPluginHost.cpp |
11 +++ b/dom/plugins/base/nsPluginHost.cpp |
7 @@ -1580,17 +1580,48 @@ nsPluginHost::FindPluginForType(const ch |
12 @@ -1556,17 +1556,45 @@ nsPluginHost::FindPluginForType(const ch |
8 bool aCheckEnabled) |
13 bool aCheckEnabled) |
9 { |
14 { |
10 if (!aMimeType) { |
15 if (!aMimeType) { |
11 return nsnull; |
16 return nsnull; |
12 } |
17 } |
13 |
18 |
14 LoadPlugins(); |
19 LoadPlugins(); |
15 |
20 |
16 + nsresult res; |
21 + nsCAutoString mimetypePref("modules.plugins.mimetype."); |
17 + nsCOMPtr<nsIPrefBranch> prefB (do_QueryInterface(mPrefService)); |
22 + mimetypePref.Append(aMimeType); |
18 + |
23 + |
19 + char *preferredPluginPath = NULL; |
24 + nsAdoptingCString preferred = Preferences::GetCString(mimetypePref.get()); |
20 + nsCAutoString mimetypePrefString ("modules.plugins.mimetype."); |
|
21 + mimetypePrefString.Append(aMimeType); |
|
22 + const char *mimetypePrefChar = mimetypePrefString.get(); |
|
23 + res = prefB->GetCharPref(mimetypePrefChar, &preferredPluginPath); |
|
24 + |
|
25 + if(!NS_SUCCEEDED(res)) preferredPluginPath = NULL; |
|
26 + |
25 + |
27 nsPluginTag *plugin = mPlugins; |
26 nsPluginTag *plugin = mPlugins; |
28 + if(preferredPluginPath) { |
27 + if(!preferred.IsEmpty()) { |
29 + while (nsnull != plugin) { |
28 + nsCOMPtr<nsILocalFile> file; |
30 + if (0 == PL_strcasecmp(plugin->mFileName.get(), preferredPluginPath) || |
29 + nsresult rv = NS_NewNativeLocalFile(preferred, false, getter_AddRefs(file)); |
31 + 0 == PL_strcasecmp(plugin->mFullPath.get(), preferredPluginPath)) { |
30 + bool isAbsolute = NS_SUCCEEDED(rv); |
32 + return plugin; |
|
33 + } |
|
34 + plugin = plugin->mNext; |
|
35 + } |
|
36 + |
31 + |
37 + // now lets search for substrings |
32 + while (plugin) { |
38 + plugin = mPlugins; |
33 + if (((!isAbsolute && 0 == PL_strcasecmp(plugin->mFileName.get(), preferred.get())) || |
39 + while (nsnull != plugin) { |
34 + (isAbsolute && 0 == PL_strcasecmp(plugin->mFullPath.get(), preferred.get()))) && |
40 + if (nsnull != PL_strstr(plugin->mFileName.get(), preferredPluginPath) || |
35 + (!aCheckEnabled || plugin->IsEnabled())) { |
41 + nsnull != PL_strstr(plugin->mFullPath.get(), preferredPluginPath)) { |
36 + PRInt32 mimeCount = plugin->mMimeTypes.Length(); |
42 + return plugin; |
37 + for (PRInt32 i = 0; i < mimeCount; i++) { |
|
38 + if (0 == PL_strcasecmp(plugin->mMimeTypes[i].get(), aMimeType)) { |
|
39 + return plugin; |
|
40 + } |
|
41 + } |
43 + } |
42 + } |
44 + plugin = plugin->mNext; |
43 + plugin = plugin->mNext; |
45 + } |
44 + } |
46 + } |
45 + } |
47 + |
46 + |
|
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; |
48 while (plugin) { |
50 while (plugin) { |
49 if (!aCheckEnabled || plugin->IsEnabled()) { |
51 if (!aCheckEnabled || plugin->IsEnabled()) { |
50 PRInt32 mimeCount = plugin->mMimeTypes.Length(); |
52 PRInt32 mimeCount = plugin->mMimeTypes.Length(); |
51 for (PRInt32 i = 0; i < mimeCount; i++) { |
53 for (PRInt32 i = 0; i < mimeCount; i++) { |
52 if (0 == PL_strcasecmp(plugin->mMimeTypes[i].get(), aMimeType)) { |
54 if (0 == PL_strcasecmp(plugin->mMimeTypes[i].get(), aMimeType)) { |