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.

This commit is contained in:
Benjamin Smedberg 2010-06-29 16:56:13 -04:00
parent a0f3acaf98
commit c71e024222
6 changed files with 123 additions and 80 deletions

View File

@ -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);
},

View File

@ -6183,41 +6183,22 @@ nsIContentUtils::FindInternalContentViewer(const char* aType,
if (!catMan)
return NULL;
FullPagePluginEnabledType pluginEnabled = NOT_ENABLED;
nsCOMPtr<nsIPluginHost> pluginHost =
do_GetService(MOZ_PLUGIN_HOST_CONTRACTID);
if (pluginHost) {
pluginHost->IsFullPagePluginEnabledForType(aType, &pluginEnabled);
}
nsCOMPtr<nsIDocumentLoaderFactory> 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;
}

View File

@ -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);

View File

@ -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<nsIPrefBranch> 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);
}
}

View File

@ -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<nsICategoryManager> catMan = do_GetService(NS_CATEGORYMANAGER_CONTRACTID);
if (!catMan)
return;
const char *contractId = "@mozilla.org/content/plugin/document-loader-factory;1";
nsCOMPtr<nsIPrefBranch> 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 */

View File

@ -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<nsPluginTag> mNext;
nsPluginHost *mPluginHost;