From c71e024222b8c9301714e9418929004be05b1864 Mon Sep 17 00:00:00 2001 From: Benjamin Smedberg Date: Tue, 29 Jun 2010 16:56:13 -0400 Subject: [PATCH] Bug 574457 - Back out the functional changes from revision 0327e126ea24, bug 569644, because of 100ms (20%) Ts regression on Linux/Mac. This leaves the nsIContentUtils helper function, but restores the plugin host category entry munging. --- .../components/preferences/applications.js | 13 +++ content/base/src/nsContentUtils.cpp | 31 ++---- modules/plugin/base/public/nsIPluginHost.idl | 19 ---- modules/plugin/base/src/nsPluginHost.cpp | 39 +------- modules/plugin/base/src/nsPluginTags.cpp | 94 +++++++++++++++++++ modules/plugin/base/src/nsPluginTags.h | 7 ++ 6 files changed, 123 insertions(+), 80 deletions(-) diff --git a/browser/components/preferences/applications.js b/browser/components/preferences/applications.js index 1c3bb506793..5e05e0e41f8 100644 --- a/browser/components/preferences/applications.js +++ b/browser/components/preferences/applications.js @@ -438,6 +438,11 @@ HandlerInfoWrapper.prototype = { this._prefSvc.setCharPref(PREF_DISABLED_PLUGIN_TYPES, disabledPluginTypes.join(",")); + + // Update the category manager so existing browser windows update. + this._categoryMgr.deleteCategoryEntry("Gecko-Content-Viewers", + this.type, + false); }, enablePluginType: function() { @@ -448,6 +453,14 @@ HandlerInfoWrapper.prototype = { this._prefSvc.setCharPref(PREF_DISABLED_PLUGIN_TYPES, disabledPluginTypes.join(",")); + + // Update the category manager so existing browser windows update. + this._categoryMgr. + addCategoryEntry("Gecko-Content-Viewers", + this.type, + "@mozilla.org/content/plugin/document-loader-factory;1", + false, + true); }, diff --git a/content/base/src/nsContentUtils.cpp b/content/base/src/nsContentUtils.cpp index 8ed480b528a..488c2446eff 100644 --- a/content/base/src/nsContentUtils.cpp +++ b/content/base/src/nsContentUtils.cpp @@ -6183,41 +6183,22 @@ nsIContentUtils::FindInternalContentViewer(const char* aType, if (!catMan) return NULL; - FullPagePluginEnabledType pluginEnabled = NOT_ENABLED; - - nsCOMPtr pluginHost = - do_GetService(MOZ_PLUGIN_HOST_CONTRACTID); - if (pluginHost) { - pluginHost->IsFullPagePluginEnabledForType(aType, &pluginEnabled); - } - nsCOMPtr docFactory; - if (OVERRIDE_BUILTIN == pluginEnabled) { - docFactory = do_GetService(PLUGIN_DLF_CONTRACTID); - if (docFactory && aLoaderType) { - *aLoaderType = TYPE_PLUGIN; - } - return docFactory.forget(); - } - nsXPIDLCString contractID; nsresult rv = catMan->GetCategoryEntry("Gecko-Content-Viewers", aType, getter_Copies(contractID)); if (NS_SUCCEEDED(rv)) { docFactory = do_GetService(contractID); if (docFactory && aLoaderType) { - *aLoaderType = contractID.EqualsLiteral(CONTENT_DLF_CONTRACTID) ? TYPE_CONTENT : TYPE_UNKNOWN; + if (contractID.EqualsLiteral(CONTENT_DLF_CONTRACTID)) + *aLoaderType = TYPE_CONTENT; + else if (contractID.EqualsLiteral(PLUGIN_DLF_CONTRACTID)) + *aLoaderType = TYPE_PLUGIN; + else + *aLoaderType = TYPE_UNKNOWN; } return docFactory.forget(); } - if (AVAILABLE == pluginEnabled) { - docFactory = do_GetService(PLUGIN_DLF_CONTRACTID); - if (docFactory && aLoaderType) { - *aLoaderType = TYPE_PLUGIN; - } - return docFactory.forget(); - } - return NULL; } diff --git a/modules/plugin/base/public/nsIPluginHost.idl b/modules/plugin/base/public/nsIPluginHost.idl index 73ae6d2aa60..1232cf13264 100644 --- a/modules/plugin/base/public/nsIPluginHost.idl +++ b/modules/plugin/base/public/nsIPluginHost.idl @@ -64,23 +64,6 @@ interface nsIPluginStreamListener; [ptr] native PRLibraryPtr(PRLibrary); [ref] native nsIStreamListenerRef(nsIStreamListener *); [ptr] native nsPluginNativeWindowPtr(nsPluginNativeWindow); -native FullPagePluginEnabledType(FullPagePluginEnabledType); - -%{C++ -enum FullPagePluginEnabledType -{ - // No plugin was found for this MIME type. - NOT_ENABLED, - - // A plugin is available and should take precedence over builtin - // content viewers. - OVERRIDE_BUILTIN, - - // A plugin is available, but a builtin content viewers should be used if - // present. - AVAILABLE -}; -%} [scriptable, uuid(D419142E-0571-416B-B797-2A8E6624491D)] interface nsIPluginHost : nsISupports @@ -123,8 +106,6 @@ interface nsIPluginHost : nsISupports // NS_ERROR_FAILURE if there is no plugin for this type. [noscript] void isPluginEnabledForType(in string aMimeType); - [noscript] FullPagePluginEnabledType isFullPagePluginEnabledForType(in string aMimeType); - // The return code is NS_OK if the plugin is enabled and NS_ERROR_FAILURE if // the plugin is explicitly disabled or there is no plugin. [noscript] void isPluginEnabledForExtension(in string aExtension, in constCharStarRef aMimeType); diff --git a/modules/plugin/base/src/nsPluginHost.cpp b/modules/plugin/base/src/nsPluginHost.cpp index 9e2dc639c56..a338cf2d835 100644 --- a/modules/plugin/base/src/nsPluginHost.cpp +++ b/modules/plugin/base/src/nsPluginHost.cpp @@ -2606,42 +2606,6 @@ nsPluginHost::IsPluginEnabledForType(const char* aMimeType) return NS_OK; } -NS_IMETHODIMP -nsPluginHost::IsFullPagePluginEnabledForType(const char* aMimeType, - FullPagePluginEnabledType* aResult) -{ - *aResult = NOT_ENABLED; - - nsCOMPtr psvc(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (!psvc) - return NS_OK; - - // A preference controls whether or not the full page plugin is disabled for - // a particular type. The string must be in the form: - // type1,type2,type3,type4 - // Note: need an actual interface to control this and subsequent disabling - // (and other plugin host settings) so applications can reliably disable - // plugins - without relying on implementation details such as prefs/category - // manager entries. - nsXPIDLCString overrideTypes; - psvc->GetCharPref("plugin.disable_full_page_plugin_for_types", getter_Copies(overrideTypes)); - overrideTypes.Insert(',', 0); - overrideTypes.Append(','); - - nsCAutoString commaSeparated(','); - commaSeparated.Append(aMimeType); - commaSeparated.Append(','); - if (overrideTypes.Find(commaSeparated) != kNotFound) - return NS_OK; - - nsPluginTag* plugin = FindPluginForType(aMimeType, PR_TRUE); - if (!plugin || !plugin->IsEnabled()) - return NS_OK; - - *aResult = mOverrideInternalTypes ? OVERRIDE_BUILTIN : AVAILABLE; - return NS_OK; -} - // check comma delimitered extensions static int CompareExtensions(const char *aExtensionList, const char *aExtension) { @@ -3386,6 +3350,9 @@ nsresult nsPluginHost::ScanPluginsDirectory(nsIFile * pluginsDir, pluginTag->SetHost(this); pluginTag->mNext = mPlugins; mPlugins = pluginTag; + + if (pluginTag->IsEnabled()) + pluginTag->RegisterWithCategoryManager(mOverrideInternalTypes); } } diff --git a/modules/plugin/base/src/nsPluginTags.cpp b/modules/plugin/base/src/nsPluginTags.cpp index 42bed19c836..0e6c037b1f1 100644 --- a/modules/plugin/base/src/nsPluginTags.cpp +++ b/modules/plugin/base/src/nsPluginTags.cpp @@ -412,16 +412,104 @@ nsPluginTag::SetBlocklisted(PRBool aBlocklisted) return NS_OK; } +void +nsPluginTag::RegisterWithCategoryManager(PRBool aOverrideInternalTypes, + nsPluginTag::nsRegisterType aType) +{ + if (!mMimeTypeArray) + return; + + PLUGIN_LOG(PLUGIN_LOG_NORMAL, + ("nsPluginTag::RegisterWithCategoryManager plugin=%s, removing = %s\n", + mFileName.get(), aType == ePluginUnregister ? "yes" : "no")); + + nsCOMPtr catMan = do_GetService(NS_CATEGORYMANAGER_CONTRACTID); + if (!catMan) + return; + + const char *contractId = "@mozilla.org/content/plugin/document-loader-factory;1"; + + nsCOMPtr psvc(do_GetService(NS_PREFSERVICE_CONTRACTID)); + if (!psvc) + return; // NS_ERROR_OUT_OF_MEMORY + + // A preference controls whether or not the full page plugin is disabled for + // a particular type. The string must be in the form: + // type1,type2,type3,type4 + // Note: need an actual interface to control this and subsequent disabling + // (and other plugin host settings) so applications can reliably disable + // plugins - without relying on implementation details such as prefs/category + // manager entries. + nsXPIDLCString overrideTypes; + psvc->GetCharPref("plugin.disable_full_page_plugin_for_types", getter_Copies(overrideTypes)); + nsCAutoString overrideTypesFormatted; + overrideTypesFormatted.Assign(','); + overrideTypesFormatted += overrideTypes; + overrideTypesFormatted.Append(','); + + nsACString::const_iterator start, end; + for (int i = 0; i < mVariants; i++) { + if (aType == ePluginUnregister) { + nsXPIDLCString value; + if (NS_SUCCEEDED(catMan->GetCategoryEntry("Gecko-Content-Viewers", + mMimeTypeArray[i], + getter_Copies(value)))) { + // Only delete the entry if a plugin registered for it + if (strcmp(value, contractId) == 0) { + catMan->DeleteCategoryEntry("Gecko-Content-Viewers", + mMimeTypeArray[i], + PR_TRUE); + } + } + } else { + overrideTypesFormatted.BeginReading(start); + overrideTypesFormatted.EndReading(end); + + nsDependentCString mimeType(mMimeTypeArray[i]); + nsCAutoString commaSeparated; + commaSeparated.Assign(','); + commaSeparated += mimeType; + commaSeparated.Append(','); + if (!FindInReadable(commaSeparated, start, end)) { + catMan->AddCategoryEntry("Gecko-Content-Viewers", + mMimeTypeArray[i], + contractId, + PR_FALSE, /* persist: broken by bug 193031 */ + aOverrideInternalTypes, /* replace if we're told to */ + nsnull); + } + } + + PLUGIN_LOG(PLUGIN_LOG_NOISY, + ("nsPluginTag::RegisterWithCategoryManager mime=%s, plugin=%s\n", + mMimeTypeArray[i], mFileName.get())); + } +} + void nsPluginTag::Mark(PRUint32 mask) { PRBool wasEnabled = IsEnabled(); mFlags |= mask; + // Update entries in the category manager if necessary. + if (mPluginHost && wasEnabled != IsEnabled()) { + if (wasEnabled) + RegisterWithCategoryManager(PR_FALSE, nsPluginTag::ePluginUnregister); + else + RegisterWithCategoryManager(PR_FALSE, nsPluginTag::ePluginRegister); + } } void nsPluginTag::UnMark(PRUint32 mask) { PRBool wasEnabled = IsEnabled(); mFlags &= ~mask; + // Update entries in the category manager if necessary. + if (mPluginHost && wasEnabled != IsEnabled()) { + if (wasEnabled) + RegisterWithCategoryManager(PR_FALSE, nsPluginTag::ePluginUnregister); + else + RegisterWithCategoryManager(PR_FALSE, nsPluginTag::ePluginRegister); + } } PRBool nsPluginTag::HasFlag(PRUint32 flag) @@ -475,6 +563,12 @@ void nsPluginTag::TryUnloadPlugin() // again so the calling code should not be fooled and reload // the library fresh mLibrary = nsnull; + + // Remove mime types added to the category manager + // only if we were made 'active' by setting the host + if (mPluginHost) { + RegisterWithCategoryManager(PR_FALSE, nsPluginTag::ePluginUnregister); + } } /* nsPluginInstanceTag */ diff --git a/modules/plugin/base/src/nsPluginTags.h b/modules/plugin/base/src/nsPluginTags.h index dc42120c2b4..0f62a564816 100644 --- a/modules/plugin/base/src/nsPluginTags.h +++ b/modules/plugin/base/src/nsPluginTags.h @@ -66,6 +66,11 @@ struct nsPluginInfo; class nsPluginTag : public nsIPluginTag { public: + enum nsRegisterType { + ePluginRegister, + ePluginUnregister + }; + NS_DECL_ISUPPORTS NS_DECL_NSIPLUGINTAG @@ -93,6 +98,8 @@ public: PRUint32 Flags(); PRBool Equals(nsPluginTag* aPluginTag); PRBool IsEnabled(); + void RegisterWithCategoryManager(PRBool aOverrideInternalTypes, + nsRegisterType aType = ePluginRegister); nsRefPtr mNext; nsPluginHost *mPluginHost;