Bug 1136379. Clean up the nsPluginHost API a bit. r=bzbarsky

This commit is contained in:
John Schoenick 2015-02-25 11:36:39 -05:00
Родитель d784692baf
Коммит a11862a8ae
12 изменённых файлов: 379 добавлений и 323 удалений

Просмотреть файл

@ -552,26 +552,7 @@ IsPluginEnabledByExtension(nsIURI* uri, nsCString& mimeType)
return false;
}
const char* typeFromExt;
nsresult rv = pluginHost->IsPluginEnabledForExtension(ext.get(), typeFromExt);
if (NS_SUCCEEDED(rv)) {
mimeType = typeFromExt;
return true;
}
return false;
}
bool
PluginExistsForType(const char* aMIMEType)
{
nsRefPtr<nsPluginHost> pluginHost = nsPluginHost::GetInst();
if (!pluginHost) {
NS_NOTREACHED("No pluginhost");
return false;
}
return pluginHost->PluginExistsForType(aMIMEType);
return pluginHost->HavePluginForExtension(ext, mimeType);
}
///
@ -798,7 +779,7 @@ nsObjectLoadingContent::InstantiatePluginInstance(bool aIsLoading)
}
nsRefPtr<nsPluginInstanceOwner> newOwner;
rv = pluginHost->InstantiatePluginInstance(mContentType.get(),
rv = pluginHost->InstantiatePluginInstance(mContentType,
mURI.get(), this,
getter_AddRefs(newOwner));
@ -1616,8 +1597,10 @@ nsObjectLoadingContent::UpdateObjectParameters(bool aJavaURI)
nsAdoptingCString javaMIME = Preferences::GetCString(kPrefJavaMIME);
NS_ASSERTION(IsJavaMIME(javaMIME),
"plugin.mime.java should be recognized as java");
nsRefPtr<nsPluginHost> pluginHost = nsPluginHost::GetInst();
if (StringBeginsWith(classIDAttr, NS_LITERAL_STRING("java:")) &&
PluginExistsForType(javaMIME)) {
pluginHost &&
pluginHost->HavePluginForType(javaMIME)) {
newMime = javaMIME;
isJava = true;
} else {
@ -2600,7 +2583,7 @@ nsObjectLoadingContent::NotifyStateChanged(ObjectType aOldType,
" (sync %i, notify %i)", this, aOldType, aOldState.GetInternalValue(),
mType, ObjectState().GetInternalValue(), aSync, aNotify));
nsCOMPtr<nsIContent> thisContent =
nsCOMPtr<nsIContent> thisContent =
do_QueryInterface(static_cast<nsIImageLoadingContent*>(this));
NS_ASSERTION(thisContent, "must be a content");
@ -2668,7 +2651,10 @@ nsObjectLoadingContent::GetTypeOfContent(const nsCString& aMIMEType)
return eType_Document;
}
if (caps & eSupportPlugins && PluginExistsForType(aMIMEType.get())) {
nsRefPtr<nsPluginHost> pluginHost = nsPluginHost::GetInst();
if ((caps & eSupportPlugins) &&
pluginHost &&
pluginHost->HavePluginForType(aMIMEType, nsPluginHost::eExcludeNone)) {
// ShouldPlay will handle checking for disabled plugins
return eType_Plugin;
}
@ -3206,7 +3192,8 @@ nsObjectLoadingContent::ShouldPlay(FallbackType &aReason, bool aIgnoreCurrentTyp
aReason = eFallbackClickToPlay;
uint32_t enabledState = nsIPluginTag::STATE_DISABLED;
pluginHost->GetStateForType(mContentType, &enabledState);
pluginHost->GetStateForType(mContentType, nsPluginHost::eExcludeNone,
&enabledState);
if (nsIPluginTag::STATE_DISABLED == enabledState) {
aReason = eFallbackDisabled;
return false;
@ -3215,7 +3202,9 @@ nsObjectLoadingContent::ShouldPlay(FallbackType &aReason, bool aIgnoreCurrentTyp
// Before we check permissions, get the blocklist state of this plugin to set
// the fallback reason correctly.
uint32_t blocklistState = nsIBlocklistService::STATE_NOT_BLOCKED;
pluginHost->GetBlocklistStateForType(mContentType.get(), &blocklistState);
pluginHost->GetBlocklistStateForType(mContentType,
nsPluginHost::eExcludeNone,
&blocklistState);
if (blocklistState == nsIBlocklistService::STATE_BLOCKED) {
// no override possible
aReason = eFallbackBlocklisted;
@ -3264,7 +3253,9 @@ nsObjectLoadingContent::ShouldPlay(FallbackType &aReason, bool aIgnoreCurrentTyp
// code here wouldn't matter at all. Bug 775301 is tracking this.
if (!nsContentUtils::IsSystemPrincipal(topDoc->NodePrincipal())) {
nsAutoCString permissionString;
rv = pluginHost->GetPermissionStringForType(mContentType, permissionString);
rv = pluginHost->GetPermissionStringForType(mContentType,
nsPluginHost::eExcludeNone,
permissionString);
NS_ENSURE_SUCCESS(rv, false);
uint32_t permission;
rv = permissionManager->TestPermissionFromPrincipal(topDoc->NodePrincipal(),

Просмотреть файл

@ -27,7 +27,7 @@ interface nsIPluginPlayPreviewInfo : nsISupports
boolean checkWhitelist(in AUTF8String pageURI, in AUTF8String objectURI);
};
[scriptable, uuid(6034e3a0-365b-48a5-a257-586946ff361e)]
[scriptable, uuid(d7d5b2e0-105b-4c9d-8558-b6b31f28b7df)]
interface nsIPluginHost : nsISupports
{
/**
@ -50,6 +50,12 @@ interface nsIPluginHost : nsISupports
const uint32_t FLAG_CLEAR_ALL = 0;
const uint32_t FLAG_CLEAR_CACHE = 1;
/*
* For use with Get*ForType functions
*/
const uint32_t EXCLUDE_NONE = 0;
const uint32_t EXCLUDE_DISABLED = 1 << 0;
/*
* Clear site data for a given plugin.
*
@ -106,7 +112,14 @@ interface nsIPluginHost : nsISupports
nsIPluginPlayPreviewInfo getPlayPreviewInfo(in AUTF8String mimeType);
ACString getPermissionStringForType(in AUTF8String mimeType);
/**
* Get the "permission string" for the plugin. This is a string that can be
* passed to the permission manager to see whether the plugin is allowed to
* run, for example. This will typically be based on the plugin's "nice name"
* and its blocklist state.
*/
ACString getPermissionStringForType(in AUTF8String mimeType,
[optional] in uint32_t excludeFlags);
/**
* Get the nsIPluginTag for this MIME type. This method works with both
@ -116,16 +129,20 @@ interface nsIPluginHost : nsISupports
* @throws NS_ERROR_NOT_AVAILABLE if no plugin is available for this MIME
* type.
*/
nsIPluginTag getPluginTagForType(in AUTF8String mimeType);
nsIPluginTag getPluginTagForType(in AUTF8String mimeType,
[optional] in uint32_t excludeFlags);
/**
* Get the nsIPluginTag state for this MIME type.
* Get the nsIPluginTag enabled state for this MIME type. See
* nsIPluginTag.enabledState.
*/
unsigned long getStateForType(in AUTF8String mimeType);
unsigned long getStateForType(in AUTF8String mimeType,
[optional] in uint32_t excludeFlags);
/**
* Get the blocklist state for a MIME type.
* Get the blocklist state for a MIME type. See nsIPluginTag.blocklistState.
*/
uint32_t getBlocklistStateForType(in string aMimeType);
uint32_t getBlocklistStateForType(in AUTF8String aMimeType,
[optional] in uint32_t excludeFlags);
};

Просмотреть файл

@ -5,7 +5,7 @@
#include "nsISupports.idl"
[scriptable, uuid(231df043-3a32-43c4-aaac-7ad2da81e84f)]
[scriptable, uuid(32563b21-3c5e-4864-baaa-4e49b90b64f2)]
interface nsIPluginTag : nsISupports
{
// enabledState is stored as one of the following as an integer in prefs,
@ -20,6 +20,9 @@ interface nsIPluginTag : nsISupports
readonly attribute AUTF8String version;
readonly attribute AUTF8String name;
// The 'nice' name of this plugin, e.g. 'flash' 'java'
readonly attribute AUTF8String niceName;
/**
* true only if this plugin is "hardblocked" and cannot be enabled.
*/
@ -30,8 +33,15 @@ interface nsIPluginTag : nsISupports
*/
readonly attribute boolean isEnabledStateLocked;
// If this plugin is capable of being used (not disabled, blocklisted, etc)
readonly attribute boolean active;
// Get a specific nsIBlocklistService::STATE_*
readonly attribute unsigned long blocklistState;
readonly attribute boolean disabled;
readonly attribute boolean clicktoplay;
// See the STATE_* values above.
attribute unsigned long enabledState;
readonly attribute PRTime lastModifiedTime;

Просмотреть файл

@ -277,7 +277,7 @@ nsNPAPIPluginInstance::StopTime()
return mStopTime;
}
nsresult nsNPAPIPluginInstance::Initialize(nsNPAPIPlugin *aPlugin, nsPluginInstanceOwner* aOwner, const char* aMIMEType)
nsresult nsNPAPIPluginInstance::Initialize(nsNPAPIPlugin *aPlugin, nsPluginInstanceOwner* aOwner, const nsACString& aMIMEType)
{
PLUGIN_LOG(PLUGIN_LOG_NORMAL, ("nsNPAPIPluginInstance::Initialize this=%p\n",this));
@ -287,11 +287,8 @@ nsresult nsNPAPIPluginInstance::Initialize(nsNPAPIPlugin *aPlugin, nsPluginInsta
mPlugin = aPlugin;
mOwner = aOwner;
if (aMIMEType) {
mMIMEType = (char*)PR_Malloc(strlen(aMIMEType) + 1);
if (mMIMEType) {
PL_strcpy(mMIMEType, aMIMEType);
}
if (!aMIMEType.IsEmpty()) {
mMIMEType = ToNewCString(aMIMEType);
}
return Start();

Просмотреть файл

@ -81,7 +81,7 @@ private:
public:
NS_DECL_THREADSAFE_ISUPPORTS
nsresult Initialize(nsNPAPIPlugin *aPlugin, nsPluginInstanceOwner* aOwner, const char* aMIMEType);
nsresult Initialize(nsNPAPIPlugin *aPlugin, nsPluginInstanceOwner* aOwner, const nsACString& aMIMEType);
nsresult Start();
nsresult Stop();
nsresult SetWindow(NPWindow* window);

Просмотреть файл

@ -119,7 +119,7 @@ using mozilla::plugins::PluginAsyncSurrogate;
{ \
while (list_) { \
type_ temp = list_->mNext_; \
list_->mNext_ = nullptr; \
list_->mNext_ = nullptr; \
list_ = temp; \
} \
}
@ -500,17 +500,17 @@ nsresult nsPluginHost::GetURLWithHeaders(nsNPAPIPluginInstance* pluginInst,
}
nsresult nsPluginHost::PostURL(nsISupports* pluginInst,
const char* url,
uint32_t postDataLen,
const char* postData,
bool isFile,
const char* target,
nsNPAPIPluginStreamListener* streamListener,
const char* altHost,
const char* referrer,
bool forceJSEnabled,
uint32_t postHeadersLength,
const char* postHeaders)
const char* url,
uint32_t postDataLen,
const char* postData,
bool isFile,
const char* target,
nsNPAPIPluginStreamListener* streamListener,
const char* altHost,
const char* referrer,
bool forceJSEnabled,
uint32_t postHeadersLength,
const char* postHeaders)
{
nsresult rv;
@ -667,11 +667,6 @@ nsresult nsPluginHost::FindProxyForURL(const char* url, char* *result)
return res;
}
nsresult nsPluginHost::Init()
{
return NS_OK;
}
nsresult nsPluginHost::UnloadPlugins()
{
PLUGIN_LOG(PLUGIN_LOG_NORMAL, ("nsPluginHost::UnloadPlugins Called\n"));
@ -779,7 +774,7 @@ nsPluginHost::GetPluginTempDir(nsIFile **aDir)
}
nsresult
nsPluginHost::InstantiatePluginInstance(const char *aMimeType, nsIURI* aURL,
nsPluginHost::InstantiatePluginInstance(const nsACString& aMimeType, nsIURI* aURL,
nsObjectLoadingContent *aContent,
nsPluginInstanceOwner** aOwner)
{
@ -792,12 +787,12 @@ nsPluginHost::InstantiatePluginInstance(const char *aMimeType, nsIURI* aURL,
PR_LOG(nsPluginLogging::gPluginLog, PLUGIN_LOG_NORMAL,
("nsPluginHost::InstantiatePlugin Begin mime=%s, url=%s\n",
aMimeType, urlSpec.get()));
PromiseFlatCString(aMimeType).get(), urlSpec.get()));
PR_LogFlush();
#endif
if (!aMimeType) {
if (aMimeType.IsEmpty()) {
NS_NOTREACHED("Attempting to spawn a plugin with no mime type");
return NS_ERROR_FAILURE;
}
@ -851,7 +846,7 @@ nsPluginHost::InstantiatePluginInstance(const char *aMimeType, nsIURI* aURL,
PR_LOG(nsPluginLogging::gPluginLog, PLUGIN_LOG_NORMAL,
("nsPluginHost::InstantiatePlugin Finished mime=%s, rv=%d, url=%s\n",
aMimeType, rv, urlSpec2.get()));
PromiseFlatCString(aMimeType).get(), rv, urlSpec2.get()));
PR_LogFlush();
#endif
@ -885,7 +880,7 @@ nsPluginHost::TagForPlugin(nsNPAPIPlugin* aPlugin)
return nullptr;
}
nsresult nsPluginHost::SetUpPluginInstance(const char *aMimeType,
nsresult nsPluginHost::SetUpPluginInstance(const nsACString &aMimeType,
nsIURI *aURL,
nsPluginInstanceOwner *aOwner)
{
@ -919,7 +914,7 @@ nsresult nsPluginHost::SetUpPluginInstance(const char *aMimeType,
}
nsresult
nsPluginHost::TrySetUpPluginInstance(const char *aMimeType,
nsPluginHost::TrySetUpPluginInstance(const nsACString &aMimeType,
nsIURI *aURL,
nsPluginInstanceOwner *aOwner)
{
@ -929,7 +924,7 @@ nsPluginHost::TrySetUpPluginInstance(const char *aMimeType,
PR_LOG(nsPluginLogging::gPluginLog, PLUGIN_LOG_NORMAL,
("nsPluginHost::TrySetupPluginInstance Begin mime=%s, owner=%p, url=%s\n",
aMimeType, aOwner, urlSpec.get()));
PromiseFlatCString(aMimeType).get(), aOwner, urlSpec.get()));
PR_LogFlush();
#endif
@ -948,7 +943,7 @@ nsPluginHost::TrySetUpPluginInstance(const char *aMimeType,
return NS_ERROR_FAILURE;
}
nsPluginTag* pluginTag = FindPluginForType(aMimeType, true);
nsPluginTag* pluginTag = FindNativePluginForType(aMimeType, true);
NS_ASSERTION(pluginTag, "Must have plugin tag here!");
@ -992,7 +987,7 @@ nsPluginHost::TrySetUpPluginInstance(const char *aMimeType,
PR_LOG(nsPluginLogging::gPluginLog, PLUGIN_LOG_BASIC,
("nsPluginHost::TrySetupPluginInstance Finished mime=%s, rv=%d, owner=%p, url=%s\n",
aMimeType, rv, aOwner, urlSpec2.get()));
PromiseFlatCString(aMimeType).get(), rv, aOwner, urlSpec2.get()));
PR_LogFlush();
#endif
@ -1001,70 +996,77 @@ nsPluginHost::TrySetUpPluginInstance(const char *aMimeType,
}
bool
nsPluginHost::PluginExistsForType(const char* aMimeType)
nsPluginHost::HavePluginForType(const nsACString & aMimeType,
PluginFilter aFilter)
{
nsPluginTag *plugin = FindPluginForType(aMimeType, false);
return nullptr != plugin;
bool checkEnabled = aFilter & eExcludeDisabled;
return FindNativePluginForType(aMimeType, checkEnabled);
}
NS_IMETHODIMP
nsPluginHost::GetPluginTagForType(const nsACString& aMimeType,
uint32_t aExcludeFlags,
nsIPluginTag** aResult)
{
nsPluginTag* plugin = FindPluginForType(aMimeType.Data(), true);
if (!plugin) {
plugin = FindPluginForType(aMimeType.Data(), false);
bool includeDisabled = !(aExcludeFlags & eExcludeDisabled);
nsPluginTag *tag = FindNativePluginForType(aMimeType, true);
// Prefer enabled, but select disabled if none is found
if (includeDisabled && !tag) {
tag = FindNativePluginForType(aMimeType, false);
}
if (!plugin) {
if (!tag) {
return NS_ERROR_NOT_AVAILABLE;
}
NS_ADDREF(*aResult = plugin);
NS_ADDREF(*aResult = tag);
return NS_OK;
}
NS_IMETHODIMP
nsPluginHost::GetStateForType(const nsACString &aMimeType, uint32_t* aResult)
nsPluginHost::GetStateForType(const nsACString &aMimeType,
uint32_t aExcludeFlags,
uint32_t* aResult)
{
nsPluginTag *plugin = FindPluginForType(aMimeType.Data(), true);
if (!plugin) {
plugin = FindPluginForType(aMimeType.Data(), false);
}
if (!plugin) {
return NS_ERROR_UNEXPECTED;
}
nsCOMPtr<nsIPluginTag> tag;
nsresult rv = GetPluginTagForType(aMimeType, aExcludeFlags,
getter_AddRefs(tag));
NS_ENSURE_SUCCESS(rv, rv);
return plugin->GetEnabledState(aResult);
return tag->GetEnabledState(aResult);
}
NS_IMETHODIMP
nsPluginHost::GetBlocklistStateForType(const char *aMimeType, uint32_t *aState)
nsPluginHost::GetBlocklistStateForType(const nsACString &aMimeType,
uint32_t aExcludeFlags,
uint32_t *aState)
{
nsPluginTag *plugin = FindPluginForType(aMimeType, true);
if (!plugin) {
plugin = FindPluginForType(aMimeType, false);
}
if (!plugin) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIPluginTag> tag;
nsresult rv = GetPluginTagForType(aMimeType,
aExcludeFlags,
getter_AddRefs(tag));
NS_ENSURE_SUCCESS(rv, rv);
*aState = plugin->GetBlocklistState();
return NS_OK;
return tag->GetBlocklistState(aState);
}
NS_IMETHODIMP
nsPluginHost::GetPermissionStringForType(const nsACString &aMimeType, nsACString &aPermissionString)
nsPluginHost::GetPermissionStringForType(const nsACString &aMimeType,
uint32_t aExcludeFlags,
nsACString &aPermissionString)
{
nsCOMPtr<nsIPluginTag> tag;
nsresult rv = GetPluginTagForType(aMimeType, aExcludeFlags,
getter_AddRefs(tag));
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(tag, NS_ERROR_FAILURE);
aPermissionString.Truncate();
uint32_t blocklistState;
nsresult rv = GetBlocklistStateForType(aMimeType.Data(), &blocklistState);
rv = tag->GetBlocklistState(&blocklistState);
NS_ENSURE_SUCCESS(rv, rv);
nsPluginTag *tag = FindPluginForType(aMimeType.Data(), true);
if (!tag) {
tag = FindPluginForType(aMimeType.Data(), false);
}
if (!tag) {
return NS_ERROR_FAILURE;
}
if (blocklistState == nsIBlocklistService::STATE_VULNERABLE_UPDATE_AVAILABLE ||
blocklistState == nsIBlocklistService::STATE_VULNERABLE_NO_UPDATE) {
@ -1074,45 +1076,23 @@ nsPluginHost::GetPermissionStringForType(const nsACString &aMimeType, nsACString
aPermissionString.AssignLiteral("plugin:");
}
aPermissionString.Append(tag->GetNiceFileName());
nsCString niceName;
rv = tag->GetNiceName(niceName);
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(!niceName.IsEmpty(), NS_ERROR_FAILURE);
aPermissionString.Append(niceName);
return NS_OK;
}
// check comma delimitered extensions
static int CompareExtensions(const char *aExtensionList, const char *aExtension)
bool
nsPluginHost::HavePluginForExtension(const nsACString & aExtension,
/* out */ nsACString & aMimeType,
PluginFilter aFilter)
{
if (!aExtensionList || !aExtension)
return -1;
const char *pExt = aExtensionList;
const char *pComma = strchr(pExt, ',');
if (!pComma)
return PL_strcasecmp(pExt, aExtension);
int extlen = strlen(aExtension);
while (pComma) {
int length = pComma - pExt;
if (length == extlen && 0 == PL_strncasecmp(aExtension, pExt, length))
return 0;
pComma++;
pExt = pComma;
pComma = strchr(pExt, ',');
}
// the last one
return PL_strcasecmp(pExt, aExtension);
}
nsresult
nsPluginHost::IsPluginEnabledForExtension(const char* aExtension,
const char* &aMimeType)
{
nsPluginTag *plugin = FindPluginEnabledForExtension(aExtension, aMimeType);
if (plugin)
return NS_OK;
return NS_ERROR_FAILURE;
bool checkEnabled = aFilter & eExcludeDisabled;
return FindNativePluginForExtension(aExtension, aMimeType, checkEnabled);
}
void
@ -1185,10 +1165,10 @@ nsPluginHost::FindPreferredPlugin(const InfallibleTArray<nsPluginTag*>& matches)
}
nsPluginTag*
nsPluginHost::FindPluginForType(const char* aMimeType,
bool aCheckEnabled)
nsPluginHost::FindNativePluginForType(const nsACString & aMimeType,
bool aCheckEnabled)
{
if (!aMimeType) {
if (aMimeType.IsEmpty()) {
return nullptr;
}
@ -1198,14 +1178,9 @@ nsPluginHost::FindPluginForType(const char* aMimeType,
nsPluginTag *plugin = mPlugins;
while (plugin) {
if (!aCheckEnabled || plugin->IsActive()) {
int32_t mimeCount = plugin->mMimeTypes.Length();
for (int32_t i = 0; i < mimeCount; i++) {
if (0 == PL_strcasecmp(plugin->mMimeTypes[i].get(), aMimeType)) {
matchingPlugins.AppendElement(plugin);
break;
}
}
if ((!aCheckEnabled || plugin->IsActive()) &&
plugin->HasMimeType(aMimeType)) {
matchingPlugins.AppendElement(plugin);
}
plugin = plugin->mNext;
}
@ -1214,27 +1189,24 @@ nsPluginHost::FindPluginForType(const char* aMimeType,
}
nsPluginTag*
nsPluginHost::FindPluginEnabledForExtension(const char* aExtension,
const char*& aMimeType)
nsPluginHost::FindNativePluginForExtension(const nsACString & aExtension,
/* out */ nsACString & aMimeType,
bool aCheckEnabled)
{
if (!aExtension) {
if (aExtension.IsEmpty()) {
return nullptr;
}
LoadPlugins();
InfallibleTArray<nsPluginTag*> matchingPlugins;
nsCString matchingMime; // Don't mutate aMimeType unless returning a match
nsPluginTag *plugin = mPlugins;
while (plugin) {
if (plugin->IsActive()) {
int32_t variants = plugin->mExtensions.Length();
for (int32_t i = 0; i < variants; i++) {
// mExtensionsArray[cnt] is a list of extensions separated by commas
if (0 == CompareExtensions(plugin->mExtensions[i].get(), aExtension)) {
matchingPlugins.AppendElement(plugin);
break;
}
if (!aCheckEnabled || plugin->IsActive()) {
if (plugin->HasExtension(aExtension, matchingMime)) {
matchingPlugins.AppendElement(plugin);
}
}
plugin = plugin->mNext;
@ -1245,15 +1217,8 @@ nsPluginHost::FindPluginEnabledForExtension(const char* aExtension,
return nullptr;
}
int32_t variants = preferredPlugin->mExtensions.Length();
for (int32_t i = 0; i < variants; i++) {
// mExtensionsArray[cnt] is a list of extensions separated by commas
if (0 == CompareExtensions(preferredPlugin->mExtensions[i].get(), aExtension)) {
aMimeType = preferredPlugin->mMimeTypes[i].get();
break;
}
}
// Re-fetch the matching type because of how FindPreferredPlugin works...
preferredPlugin->HasExtension(aExtension, aMimeType);
return preferredPlugin;
}
@ -1364,27 +1329,26 @@ nsPluginHost::NotifyContentModuleDestroyed(uint32_t aPluginId)
NS_DispatchToMainThread(runnable);
}
nsresult nsPluginHost::GetPlugin(const char *aMimeType, nsNPAPIPlugin** aPlugin)
nsresult nsPluginHost::GetPlugin(const nsACString &aMimeType,
nsNPAPIPlugin** aPlugin)
{
nsresult rv = NS_ERROR_FAILURE;
*aPlugin = nullptr;
if (!aMimeType)
return NS_ERROR_ILLEGAL_VALUE;
// If plugins haven't been scanned yet, do so now
LoadPlugins();
nsPluginTag* pluginTag = FindPluginForType(aMimeType, true);
nsPluginTag* pluginTag = FindNativePluginForType(aMimeType, true);
if (pluginTag) {
rv = NS_OK;
PLUGIN_LOG(PLUGIN_LOG_BASIC,
("nsPluginHost::GetPlugin Begin mime=%s, plugin=%s\n",
aMimeType, pluginTag->mFileName.get()));
PromiseFlatCString(aMimeType).get(), pluginTag->mFileName.get()));
#ifdef DEBUG
if (aMimeType && !pluginTag->mFileName.IsEmpty())
printf("For %s found plugin %s\n", aMimeType, pluginTag->mFileName.get());
if (!pluginTag->mFileName.IsEmpty())
printf("For %s found plugin %s\n",
PromiseFlatCString(aMimeType).get(), pluginTag->mFileName.get());
#endif
rv = EnsurePluginLoaded(pluginTag);
@ -1398,8 +1362,8 @@ nsresult nsPluginHost::GetPlugin(const char *aMimeType, nsNPAPIPlugin** aPlugin)
PLUGIN_LOG(PLUGIN_LOG_NORMAL,
("nsPluginHost::GetPlugin End mime=%s, rv=%d, plugin=%p name=%s\n",
aMimeType, rv, *aPlugin,
(pluginTag ? pluginTag->mFileName.get() : "(not found)")));
PromiseFlatCString(aMimeType).get(), rv, *aPlugin,
(pluginTag ? pluginTag->mFileName.get() : "(not found)")));
return rv;
}
@ -1618,6 +1582,7 @@ nsPluginHost::SiteHasData(nsIPluginTag* plugin, const nsACString& domain,
return NS_ERROR_NOT_AVAILABLE;
}
// FIXME-jsplugins audit casts
nsPluginTag* tag = static_cast<nsPluginTag*>(plugin);
// We only ensure support for clearing Flash site data for now.
@ -2000,7 +1965,9 @@ nsresult nsPluginHost::ScanPluginsDirectory(nsIFile *pluginsDir,
return NS_ERROR_OUT_OF_MEMORY;
pluginTag->mLibrary = library;
uint32_t state = pluginTag->GetBlocklistState();
uint32_t state;
rv = pluginTag->GetBlocklistState(&state);
NS_ENSURE_SUCCESS(rv, rv);
// If the blocklist says it is risky and we have never seen this
// plugin before, then disable it.
@ -2027,7 +1994,7 @@ nsresult nsPluginHost::ScanPluginsDirectory(nsIFile *pluginsDir,
*aPluginsChanged = true;
}
// Avoid adding different versions of the same plugin if they are running
// Avoid adding different versions of the same plugin if they are running
// in-process, otherwise we risk undefined behaviour.
if (!nsNPAPIPlugin::RunPluginOOP(pluginTag)) {
if (HaveSamePlugin(pluginTag)) {
@ -2454,7 +2421,7 @@ nsPluginHost::FindPluginsForContent(uint32_t aPluginEpoch,
}
}
nsresult
void
nsPluginHost::UpdatePluginInfo(nsPluginTag* aPluginTag)
{
MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default);
@ -2465,7 +2432,7 @@ nsPluginHost::UpdatePluginInfo(nsPluginTag* aPluginTag)
NS_ITERATIVE_UNREF_LIST(nsRefPtr<nsInvalidPluginTag>, mInvalidPlugins, mNext);
if (!aPluginTag) {
return NS_OK;
return;
}
// Update types with category manager
@ -2477,8 +2444,8 @@ nsPluginHost::UpdatePluginInfo(nsPluginTag* aPluginTag)
if (IsTypeInList(aPluginTag->mMimeTypes[i], disableFullPage)) {
shouldRegister = ePluginUnregister;
} else {
nsPluginTag *plugin = FindPluginForType(aPluginTag->mMimeTypes[i].get(),
true);
nsPluginTag *plugin = FindNativePluginForType(aPluginTag->mMimeTypes[i],
true);
shouldRegister = plugin ? ePluginRegister : ePluginUnregister;
}
@ -2489,13 +2456,6 @@ nsPluginHost::UpdatePluginInfo(nsPluginTag* aPluginTag)
mozilla::services::GetObserverService();
if (obsService)
obsService->NotifyObservers(nullptr, "plugin-info-updated", nullptr);
// Reload instances if needed
if (aPluginTag->IsActive()) {
return NS_OK;
}
return NS_OK;
}
/* static */ bool
@ -3089,7 +3049,7 @@ nsresult nsPluginHost::NewPluginURLStream(const nsString& aURL,
if (aURL.Length() <= 0)
return NS_OK;
// get the base URI for the plugin to create an absolute url
// get the base URI for the plugin to create an absolute url
// in case aURL is relative
nsRefPtr<nsPluginInstanceOwner> owner = aInstance->GetOwner();
if (owner) {
@ -3355,7 +3315,7 @@ nsPluginHost::StopPluginInstance(nsNPAPIPluginInstance* aInstance)
oldestInstance->Destroy();
mInstances.RemoveElement(oldestInstance);
// TODO: Remove this check once bug 752422 was investigated
if (pluginTag) {
if (pluginTag) {
OnPluginInstanceDestroyed(pluginTag);
}
}
@ -3365,7 +3325,7 @@ nsPluginHost::StopPluginInstance(nsNPAPIPluginInstance* aInstance)
aInstance->Destroy();
mInstances.RemoveElement(aInstance);
// TODO: Remove this check once bug 752422 was investigated
if (pluginTag) {
if (pluginTag) {
OnPluginInstanceDestroyed(pluginTag);
}
}
@ -3919,7 +3879,7 @@ nsPluginHost::InstanceArray()
return &mInstances;
}
void
void
nsPluginHost::DestroyRunningInstances(nsPluginTag* aPluginTag)
{
for (int32_t i = mInstances.Length(); i > 0; i--) {

Просмотреть файл

@ -75,7 +75,9 @@ class nsPluginHost MOZ_FINAL : public nsIPluginHost,
public nsITimerCallback,
public nsSupportsWeakReference
{
friend class nsPluginTag;
virtual ~nsPluginHost();
public:
nsPluginHost();
@ -88,16 +90,26 @@ public:
NS_DECL_NSIOBSERVER
NS_DECL_NSITIMERCALLBACK
nsresult Init();
nsresult LoadPlugins();
nsresult UnloadPlugins();
nsresult SetUpPluginInstance(const char *aMimeType,
nsresult SetUpPluginInstance(const nsACString &aMimeType,
nsIURI *aURL,
nsPluginInstanceOwner *aOwner);
bool PluginExistsForType(const char* aMimeType);
nsresult IsPluginEnabledForExtension(const char* aExtension, const char* &aMimeType);
// Acts like a bitfield
enum PluginFilter {
eExcludeNone = nsIPluginHost::EXCLUDE_NONE,
eExcludeDisabled = nsIPluginHost::EXCLUDE_DISABLED
};
// FIXME-jsplugins comment about fake
bool HavePluginForType(const nsACString & aMimeType,
PluginFilter aFilter = eExcludeDisabled);
// FIXME-jsplugins what if fake has different extensions
bool HavePluginForExtension(const nsACString & aExtension,
/* out */ nsACString & aMimeType,
PluginFilter aFilter = eExcludeDisabled);
void GetPlugins(nsTArray<nsRefPtr<nsPluginTag> >& aPluginArray);
void FindPluginsForContent(uint32_t aPluginEpoch,
@ -126,35 +138,39 @@ public:
nsresult FindProxyForURL(const char* url, char* *result);
nsresult UserAgent(const char **retstring);
nsresult ParsePostBufferToFixHeaders(const char *inPostData, uint32_t inPostDataLen,
char **outPostData, uint32_t *outPostDataLen);
nsresult ParsePostBufferToFixHeaders(const char *inPostData,
uint32_t inPostDataLen,
char **outPostData,
uint32_t *outPostDataLen);
nsresult CreateTempFileToPost(const char *aPostDataURL, nsIFile **aTmpFile);
nsresult NewPluginNativeWindow(nsPluginNativeWindow ** aPluginNativeWindow);
void AddIdleTimeTarget(nsIPluginInstanceOwner* objectFrame, bool isVisible);
void RemoveIdleTimeTarget(nsIPluginInstanceOwner* objectFrame);
nsresult GetPluginName(nsNPAPIPluginInstance *aPluginInstance, const char** aPluginName);
nsresult GetPluginName(nsNPAPIPluginInstance *aPluginInstance,
const char** aPluginName);
nsresult StopPluginInstance(nsNPAPIPluginInstance* aInstance);
nsresult GetPluginTagForInstance(nsNPAPIPluginInstance *aPluginInstance, nsIPluginTag **aPluginTag);
nsresult GetPluginTagForInstance(nsNPAPIPluginInstance *aPluginInstance,
nsIPluginTag **aPluginTag);
nsresult
NewPluginURLStream(const nsString& aURL,
nsNPAPIPluginInstance *aInstance,
NewPluginURLStream(const nsString& aURL,
nsNPAPIPluginInstance *aInstance,
nsNPAPIPluginStreamListener *aListener,
nsIInputStream *aPostStream = nullptr,
const char *aHeadersData = nullptr,
const char *aHeadersData = nullptr,
uint32_t aHeadersDataLen = 0);
nsresult
GetURLWithHeaders(nsNPAPIPluginInstance *pluginInst,
const char* url,
GetURLWithHeaders(nsNPAPIPluginInstance *pluginInst,
const char* url,
const char* target = nullptr,
nsNPAPIPluginStreamListener* streamListener = nullptr,
const char* altHost = nullptr,
const char* referrer = nullptr,
bool forceJSEnabled = false,
uint32_t getHeadersLength = 0,
uint32_t getHeadersLength = 0,
const char* getHeaders = nullptr);
nsresult
@ -162,15 +178,11 @@ public:
const char* aURL);
nsresult
AddHeadersToChannel(const char *aHeadersData, uint32_t aHeadersDataLen,
AddHeadersToChannel(const char *aHeadersData, uint32_t aHeadersDataLen,
nsIChannel *aGenericChannel);
static nsresult GetPluginTempDir(nsIFile **aDir);
// Writes updated plugins settings to disk and unloads the plugin
// if it is now disabled
nsresult UpdatePluginInfo(nsPluginTag* aPluginTag);
// Helper that checks if a type is whitelisted in plugin.allowed_types.
// Always returns true if plugin.allowed_types is not set
static bool IsTypeWhitelisted(const char *aType);
@ -202,14 +214,12 @@ public:
nsTArray< nsRefPtr<nsNPAPIPluginInstance> > *InstanceArray();
void DestroyRunningInstances(nsPluginTag* aPluginTag);
// Return the tag for |aLibrary| if found, nullptr if not.
nsPluginTag* FindTagForLibrary(PRLibrary* aLibrary);
// The last argument should be false if we already have an in-flight stream
// and don't need to set up a new stream.
nsresult InstantiatePluginInstance(const char *aMimeType, nsIURI* aURL,
nsresult InstantiatePluginInstance(const nsACString& aMimeType, nsIURI* aURL,
nsObjectLoadingContent *aContent,
nsPluginInstanceOwner** aOwner);
@ -218,7 +228,7 @@ public:
nsPluginTag* PluginWithId(uint32_t aId);
nsresult GetPlugin(const char *aMimeType, nsNPAPIPlugin** aPlugin);
nsresult GetPlugin(const nsACString &aMimeType, nsNPAPIPlugin** aPlugin);
nsresult GetPluginForContentProcess(uint32_t aPluginId, nsNPAPIPlugin** aPlugin);
void NotifyContentModuleDestroyed(uint32_t aPluginId);
@ -231,19 +241,27 @@ public:
private:
friend class nsPluginUnloadRunnable;
nsresult
TrySetUpPluginInstance(const char *aMimeType, nsIURI *aURL, nsPluginInstanceOwner *aOwner);
void DestroyRunningInstances(nsPluginTag* aPluginTag);
// Writes updated plugins settings to disk and unloads the plugin
// if it is now disabled. Should only be called by the plugin tag in question
void UpdatePluginInfo(nsPluginTag* aPluginTag);
nsresult TrySetUpPluginInstance(const nsACString &aMimeType, nsIURI *aURL,
nsPluginInstanceOwner *aOwner);
// FIXME-jsplugins comment here about when things may be fake
nsPluginTag*
FindPreferredPlugin(const InfallibleTArray<nsPluginTag*>& matches);
// Return an nsPluginTag for this type, if any. If aCheckEnabled is
// true, only enabled plugins will be returned.
nsPluginTag*
FindPluginForType(const char* aMimeType, bool aCheckEnabled);
nsPluginTag* FindNativePluginForType(const nsACString & aMimeType,
bool aCheckEnabled);
nsPluginTag*
FindPluginEnabledForExtension(const char* aExtension, const char* &aMimeType);
nsPluginTag* FindNativePluginForExtension(const nsACString & aExtension,
/* out */ nsACString & aMimeType,
bool aCheckEnabled);
nsresult
FindStoppedPluginForURL(nsIURI* aURL, nsIPluginInstanceOwner *aOwner);
@ -253,6 +271,7 @@ private:
nsresult
FindPlugins(bool aCreatePluginList, bool * aPluginsChanged);
// FIXME revisit, no ns prefix
// Registers or unregisters the given mime type with the category manager
// (performs no checks - see UpdateCategoryManager)
enum nsRegisterType { ePluginRegister, ePluginUnregister };
@ -287,10 +306,10 @@ private:
// Checks to see if a tag object is in our list of live tags.
bool IsLiveTag(nsIPluginTag* tag);
// Checks our list of live tags for an equivalent tag.
nsPluginTag* HaveSamePlugin(const nsPluginTag * aPluginTag);
// Returns the first plugin at |path|
nsPluginTag* FirstPluginWithPath(const nsCString& path);

Просмотреть файл

@ -15,6 +15,7 @@
#include "nsIPlatformCharset.h"
#include "nsPluginLogging.h"
#include "nsNPAPIPlugin.h"
#include "nsCharSeparatedTokenizer.h"
#include "mozilla/Preferences.h"
#include "mozilla/unused.h"
#include <cctype>
@ -34,15 +35,65 @@ using namespace mozilla;
static const char kPrefDefaultEnabledState[] = "plugin.default.state";
static const char kPrefDefaultEnabledStateXpi[] = "plugin.defaultXpi.state";
inline char* new_str(const char* str)
// check comma delimited extensions
static bool ExtensionInList(const nsCString& aExtensionList,
const nsACString& aExtension)
{
if (str == nullptr)
return nullptr;
char* result = new char[strlen(str) + 1];
if (result != nullptr)
return strcpy(result, str);
return result;
nsCCharSeparatedTokenizer extensions(aExtensionList, ',');
while (extensions.hasMoreTokens()) {
const nsCSubstring& extension = extensions.nextToken();
if (extension.Equals(aExtension, nsCaseInsensitiveCStringComparator())) {
return true;
}
}
return false;
}
// Search for an extension in an extensions array, and return its
// matching mime type
static bool SearchExtensions(const nsTArray<nsCString> & aExtensions,
const nsTArray<nsCString> & aMimeTypes,
const nsACString & aFindExtension,
nsACString & aMatchingType)
{
uint32_t mimes = aMimeTypes.Length();
MOZ_ASSERT(mimes == aExtensions.Length(),
"These arrays should have matching elements");
aMatchingType.Truncate();
for (uint32_t i = 0; i < mimes; i++) {
if (ExtensionInList(aExtensions[i], aFindExtension)) {
aMatchingType = aMimeTypes[i];
return true;
}
}
return false;
}
static nsCString
MakeNiceFileName(const nsCString & aFileName)
{
nsCString niceName = aFileName;
int32_t niceNameLength = aFileName.RFind(".");
NS_ASSERTION(niceNameLength != kNotFound, "aFileName doesn't have a '.'?");
while (niceNameLength > 0) {
char chr = aFileName[niceNameLength - 1];
if (!std::isalpha(chr))
niceNameLength--;
else
break;
}
// If it turns out that niceNameLength <= 0, we'll fall back and use the
// entire aFileName (which we've already taken care of, a few lines back).
if (niceNameLength > 0) {
niceName.Truncate(niceNameLength);
}
ToLowerCase(niceName);
return niceName;
}
static nsCString
@ -58,6 +109,27 @@ MakePrefNameForPlugin(const char* const subname, nsPluginTag* aTag)
return pref;
}
static nsresult
CStringArrayToXPCArray(nsTArray<nsCString> & aArray,
uint32_t* aCount,
char16_t*** aResults)
{
uint32_t count = aArray.Length();
if (!count) {
return NS_ERROR_NOT_AVAILABLE;
}
*aResults =
static_cast<char16_t**>(nsMemory::Alloc(count * sizeof(**aResults)));
*aCount = count;
for (uint32_t i = 0; i < count; i++) {
(*aResults)[i] = ToNewUnicode(NS_ConvertUTF8toUTF16(aArray[i]));
}
return NS_OK;
}
static nsCString
GetStatePrefNameForPlugin(nsPluginTag* aTag)
{
@ -82,7 +154,6 @@ nsPluginTag::nsPluginTag(nsPluginInfo* aPluginInfo,
mFullPath(aPluginInfo->fFullPath),
mVersion(aPluginInfo->fVersion),
mLastModifiedTime(aLastModifiedTime),
mNiceFileName(),
mCachedBlocklistState(nsIBlocklistService::STATE_NOT_BLOCKED),
mCachedBlocklistStateValid(false),
mIsFromExtension(fromExtension)
@ -118,7 +189,6 @@ nsPluginTag::nsPluginTag(const char* aName,
mFullPath(aFullPath),
mVersion(aVersion),
mLastModifiedTime(aLastModifiedTime),
mNiceFileName(),
mCachedBlocklistState(nsIBlocklistService::STATE_NOT_BLOCKED),
mCachedBlocklistStateValid(false),
mIsFromExtension(fromExtension)
@ -266,7 +336,7 @@ static nsresult ConvertToUTF8(nsIUnicodeDecoder *aUnicodeDecoder,
NS_ENSURE_SUCCESS(rv, rv);
buffer.SetLength(outUnicodeLen);
CopyUTF16toUTF8(buffer, aString);
return NS_OK;
}
#endif
@ -277,7 +347,7 @@ nsresult nsPluginTag::EnsureMembersAreUTF8()
return NS_OK;
#else
nsresult rv;
nsCOMPtr<nsIPlatformCharset> pcs =
do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
@ -359,6 +429,13 @@ nsPluginTag::IsActive()
return IsEnabled() && !IsBlocklisted();
}
NS_IMETHODIMP
nsPluginTag::GetActive(bool *aResult)
{
*aResult = IsActive();
return NS_OK;
}
bool
nsPluginTag::IsEnabled()
{
@ -376,7 +453,9 @@ nsPluginTag::GetDisabled(bool* aDisabled)
bool
nsPluginTag::IsBlocklisted()
{
return GetBlocklistState() == nsIBlocklistService::STATE_BLOCKED;
uint32_t blocklistState;
nsresult rv = GetBlocklistState(&blocklistState);
return NS_FAILED(rv) || blocklistState == nsIBlocklistService::STATE_BLOCKED;
}
NS_IMETHODIMP
@ -476,52 +555,19 @@ nsPluginTag::SetPluginState(PluginState state)
NS_IMETHODIMP
nsPluginTag::GetMimeTypes(uint32_t* aCount, char16_t*** aResults)
{
uint32_t count = mMimeTypes.Length();
*aResults = static_cast<char16_t**>
(nsMemory::Alloc(count * sizeof(**aResults)));
if (!*aResults)
return NS_ERROR_OUT_OF_MEMORY;
*aCount = count;
for (uint32_t i = 0; i < count; i++) {
(*aResults)[i] = ToNewUnicode(NS_ConvertUTF8toUTF16(mMimeTypes[i]));
}
return NS_OK;
return CStringArrayToXPCArray(mMimeTypes, aCount, aResults);
}
NS_IMETHODIMP
nsPluginTag::GetMimeDescriptions(uint32_t* aCount, char16_t*** aResults)
{
uint32_t count = mMimeDescriptions.Length();
*aResults = static_cast<char16_t**>
(nsMemory::Alloc(count * sizeof(**aResults)));
if (!*aResults)
return NS_ERROR_OUT_OF_MEMORY;
*aCount = count;
for (uint32_t i = 0; i < count; i++) {
(*aResults)[i] = ToNewUnicode(NS_ConvertUTF8toUTF16(mMimeDescriptions[i]));
}
return NS_OK;
return CStringArrayToXPCArray(mMimeDescriptions, aCount, aResults);
}
NS_IMETHODIMP
nsPluginTag::GetExtensions(uint32_t* aCount, char16_t*** aResults)
{
uint32_t count = mExtensions.Length();
*aResults = static_cast<char16_t**>
(nsMemory::Alloc(count * sizeof(**aResults)));
if (!*aResults)
return NS_ERROR_OUT_OF_MEMORY;
*aCount = count;
for (uint32_t i = 0; i < count; i++) {
(*aResults)[i] = ToNewUnicode(NS_ConvertUTF8toUTF16(mExtensions[i]));
}
return NS_OK;
return CStringArrayToXPCArray(mExtensions, aCount, aResults);
}
bool
@ -571,27 +617,17 @@ nsCString nsPluginTag::GetNiceFileName() {
return mNiceFileName;
}
mNiceFileName.Assign(mFileName);
int32_t niceNameLength = mFileName.RFind(".");
NS_ASSERTION(niceNameLength != kNotFound, "mFileName doesn't have a '.'?");
while (niceNameLength > 0) {
char chr = mFileName[niceNameLength - 1];
if (!std::isalpha(chr))
niceNameLength--;
else
break;
}
// If it turns out that niceNameLength <= 0, we'll fall back and use the
// entire mFileName (which we've already taken care of, a few lines back)
if (niceNameLength > 0) {
mNiceFileName.Truncate(niceNameLength);
}
ToLowerCase(mNiceFileName);
mNiceFileName = MakeNiceFileName(mFileName);
return mNiceFileName;
}
NS_IMETHODIMP
nsPluginTag::GetNiceName(nsACString & aResult)
{
aResult = GetNiceFileName();
return NS_OK;
}
void nsPluginTag::ImportFlagsToPrefs(uint32_t flags)
{
if (!(flags & NS_PLUGIN_FLAG_ENABLED)) {
@ -599,16 +635,20 @@ void nsPluginTag::ImportFlagsToPrefs(uint32_t flags)
}
}
uint32_t
nsPluginTag::GetBlocklistState()
NS_IMETHODIMP
nsPluginTag::GetBlocklistState(uint32_t *aResult)
{
if (mCachedBlocklistStateValid) {
return mCachedBlocklistState;
*aResult = mCachedBlocklistState;
return NS_OK;
}
nsCOMPtr<nsIBlocklistService> blocklist = do_GetService("@mozilla.org/extensions/blocklist;1");
nsCOMPtr<nsIBlocklistService> blocklist =
do_GetService("@mozilla.org/extensions/blocklist;1");
if (!blocklist) {
return nsIBlocklistService::STATE_NOT_BLOCKED;
*aResult = nsIBlocklistService::STATE_NOT_BLOCKED;
return NS_OK;
}
// The EmptyString()s are so we use the currently running application
@ -616,13 +656,29 @@ nsPluginTag::GetBlocklistState()
uint32_t state;
if (NS_FAILED(blocklist->GetPluginBlocklistState(this, EmptyString(),
EmptyString(), &state))) {
return nsIBlocklistService::STATE_NOT_BLOCKED;
*aResult = nsIBlocklistService::STATE_NOT_BLOCKED;
return NS_OK;
}
MOZ_ASSERT(state <= UINT16_MAX);
mCachedBlocklistState = (uint16_t) state;
mCachedBlocklistStateValid = true;
return state;
*aResult = state;
return NS_OK;
}
bool
nsPluginTag::HasMimeType(const nsACString & aMimeType) const
{
return mMimeTypes.Contains(aMimeType,
nsCaseInsensitiveCStringArrayComparator());
}
bool
nsPluginTag::HasExtension(const nsACString & aExtension,
nsACString & aMatchingType) const
{
return SearchExtensions(mExtensions, mMimeTypes, aExtension, aMatchingType);
}
void

Просмотреть файл

@ -106,9 +106,17 @@ public:
int64_t mLastModifiedTime;
nsCOMPtr<nsITimer> mUnloadTimer;
uint32_t GetBlocklistState();
void InvalidateBlocklistState();
// Returns true if this plugin claims it supports this MIME type. The
// comparison is done ASCII-case-insensitively.
bool HasMimeType(const nsACString & aMimeType) const;
// Returns true if this plugin claims it supports the given extension. In hat
// case, aMatchingType is set to the MIME type the plugin claims corresponds
// to this extension. Again, the extension is done ASCII-case-insensitively.
bool HasExtension(const nsACString & aExtension,
/* out */ nsACString & aMatchingType) const;
private:
virtual ~nsPluginTag();

Просмотреть файл

@ -417,7 +417,9 @@ PluginModuleChromeParent::LoadModule(const char* aFilePath, uint32_t aPluginId,
return nullptr;
}
parent->mIsFlashPlugin = aPluginTag->mIsFlashPlugin;
parent->mIsBlocklisted = aPluginTag->GetBlocklistState() != 0;
uint32_t blocklistState;
nsresult rv = aPluginTag->GetBlocklistState(&blocklistState);
parent->mIsBlocklisted = NS_FAILED(rv) || blocklistState != 0;
if (!parent->mIsStartingAsync) {
int32_t launchTimeoutSecs = Preferences::GetInt(kLaunchTimeoutPref, 0);
if (!parent->mSubprocess->WaitUntilConnected(launchTimeoutSecs * 1000)) {

Просмотреть файл

@ -133,7 +133,7 @@ NS_IMETHODIMP
nsContentDLF::CreateInstance(const char* aCommand,
nsIChannel* aChannel,
nsILoadGroup* aLoadGroup,
const nsACString& aContentType,
const nsACString& aContentType,
nsIDocShell* aContainer,
nsISupports* aExtraInfo,
nsIStreamListener** aDocListener,
@ -241,24 +241,25 @@ nsContentDLF::CreateInstance(const char* aCommand,
}
if (mozilla::DecoderTraits::ShouldHandleMediaType(contentType.get())) {
return CreateDocument(aCommand,
return CreateDocument(aCommand,
aChannel, aLoadGroup,
aContainer, kVideoDocumentCID,
aDocListener, aDocViewer);
}
}
// Try image types
if (IsImageContentType(contentType.get())) {
return CreateDocument(aCommand,
return CreateDocument(aCommand,
aChannel, aLoadGroup,
aContainer, kImageDocumentCID,
aDocListener, aDocViewer);
}
nsCOMPtr<nsIPluginHost> pluginHostCOM(do_GetService(MOZ_PLUGIN_HOST_CONTRACTID));
nsPluginHost *pluginHost = static_cast<nsPluginHost*>(pluginHostCOM.get());
if(pluginHost &&
pluginHost->PluginExistsForType(contentType.get())) {
nsRefPtr<nsPluginHost> pluginHost = nsPluginHost::GetInst();
// Don't exclude disabled plugins, which will still trigger the "this plugin
// is disabled" placeholder.
if (pluginHost && pluginHost->HavePluginForType(contentType,
nsPluginHost::eExcludeNone)) {
return CreateDocument(aCommand,
aChannel, aLoadGroup,
aContainer, kPluginDocumentCID,

Просмотреть файл

@ -2702,18 +2702,13 @@ NS_IMETHODIMP nsExternalHelperAppService::GetTypeFromExtension(const nsACString&
if (found)
return NS_OK;
const nsCString& flatExt = PromiseFlatCString(aFileExt);
// Try the plugins
const char* mimeType;
nsCOMPtr<nsIPluginHost> pluginHostCOM(do_GetService(MOZ_PLUGIN_HOST_CONTRACTID, &rv));
nsPluginHost* pluginHost = static_cast<nsPluginHost*>(pluginHostCOM.get());
if (NS_SUCCEEDED(rv)) {
if (NS_SUCCEEDED(pluginHost->IsPluginEnabledForExtension(flatExt.get(), mimeType))) {
aContentType = mimeType;
return NS_OK;
}
nsRefPtr<nsPluginHost> pluginHost = nsPluginHost::GetInst();
if (pluginHost &&
pluginHost->HavePluginForExtension(aFileExt, aContentType)) {
return NS_OK;
}
rv = NS_OK;
// Let's see if an extension added something
nsCOMPtr<nsICategoryManager> catMan(do_GetService("@mozilla.org/categorymanager;1"));
@ -2730,7 +2725,7 @@ NS_IMETHODIMP nsExternalHelperAppService::GetTypeFromExtension(const nsACString&
else {
rv = NS_ERROR_NOT_AVAILABLE;
}
return rv;
}