Bug 1061967 part 1 - Move checking for special-cased plugin types to a central spot. r=bsmedberg

This commit is contained in:
John Schoenick 2015-01-30 10:54:19 -05:00
Родитель 99e95e2eff
Коммит 73b9b08920
8 изменённых файлов: 107 добавлений и 76 удалений

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

@ -112,6 +112,13 @@ GetObjectLog()
#define LOG(args) PR_LOG(GetObjectLog(), PR_LOG_DEBUG, args)
#define LOG_ENABLED() PR_LOG_TEST(GetObjectLog(), PR_LOG_DEBUG)
static bool
IsJavaMIME(const nsACString & aMIMEType)
{
return
nsPluginHost::GetSpecialType(aMIMEType) == nsPluginHost::eSpecialType_Java;
}
static bool
InActiveDocument(nsIContent *aContent)
{
@ -992,7 +999,7 @@ nsObjectLoadingContent::BuildParametersArray()
mCachedAttributes.AppendElement(param);
}
bool isJava = nsPluginHost::IsJavaMIMEType(mContentType.get());
bool isJava = IsJavaMIME(mContentType);
nsCString codebase;
if (isJava) {
@ -1584,8 +1591,8 @@ nsObjectLoadingContent::UpdateObjectParameters(bool aJavaURI)
if (aJavaURI || thisContent->NodeInfo()->Equals(nsGkAtoms::applet)) {
nsAdoptingCString javaMIME = Preferences::GetCString(kPrefJavaMIME);
newMime = javaMIME;
NS_ASSERTION(nsPluginHost::IsJavaMIMEType(newMime.get()),
"plugin.mime.java should be recognized by IsJavaMIMEType");
NS_ASSERTION(IsJavaMIME(newMime),
"plugin.mime.java should be recognized as java");
isJava = true;
} else {
nsAutoString rawTypeAttr;
@ -1593,7 +1600,7 @@ nsObjectLoadingContent::UpdateObjectParameters(bool aJavaURI)
if (!rawTypeAttr.IsEmpty()) {
typeAttr = rawTypeAttr;
CopyUTF16toUTF8(rawTypeAttr, newMime);
isJava = nsPluginHost::IsJavaMIMEType(newMime.get());
isJava = IsJavaMIME(newMime);
}
}
@ -1607,8 +1614,8 @@ nsObjectLoadingContent::UpdateObjectParameters(bool aJavaURI)
if (!classIDAttr.IsEmpty()) {
// Our classid support is limited to 'java:' ids
nsAdoptingCString javaMIME = Preferences::GetCString(kPrefJavaMIME);
NS_ASSERTION(nsPluginHost::IsJavaMIMEType(javaMIME.get()),
"plugin.mime.java should be recognized by IsJavaMIMEType");
NS_ASSERTION(IsJavaMIME(javaMIME),
"plugin.mime.java should be recognized as java");
if (StringBeginsWith(classIDAttr, NS_LITERAL_STRING("java:")) &&
PluginExistsForType(javaMIME)) {
newMime = javaMIME;
@ -1720,7 +1727,7 @@ nsObjectLoadingContent::UpdateObjectParameters(bool aJavaURI)
(caps & eAllowPluginSkipChannel) &&
IsPluginEnabledByExtension(newURI, newMime)) {
LOG(("OBJLC [%p]: Using extension as type hint (%s)", this, newMime.get()));
if (!isJava && nsPluginHost::IsJavaMIMEType(newMime.get())) {
if (!isJava && IsJavaMIME(newMime)) {
return UpdateObjectParameters(true);
}
}
@ -1836,7 +1843,7 @@ nsObjectLoadingContent::UpdateObjectParameters(bool aJavaURI)
}
} else {
newMime = channelType;
if (nsPluginHost::IsJavaMIMEType(newMime.get())) {
if (IsJavaMIME(newMime)) {
// Java does not load with a channel, and being java retroactively
// changes how we may have interpreted the codebase to construct this
// URI above. Because the behavior here is more or less undefined, play
@ -2107,7 +2114,7 @@ nsObjectLoadingContent::LoadObject(bool aNotify,
if (mType != eType_Null) {
bool allowLoad = true;
if (nsPluginHost::IsJavaMIMEType(mContentType.get())) {
if (IsJavaMIME(mContentType)) {
allowLoad = CheckJavaCodebase();
}
int16_t contentPolicy = nsIContentPolicy::ACCEPT;
@ -3017,7 +3024,8 @@ nsObjectLoadingContent::StopPluginInstance()
if (inst) {
const char* mime = nullptr;
if (NS_SUCCEEDED(inst->GetMIMEType(&mime)) && mime) {
if (strcmp(mime, "audio/x-pn-realaudio-plugin") == 0) {
if (nsPluginHost::GetSpecialType(nsDependentCString(mime)) ==
nsPluginHost::eSpecialType_RealPlayer) {
delayedStop = true;
}
}

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

@ -535,8 +535,10 @@ nsresult nsNPAPIPluginInstance::SetWindow(NPWindow* window)
#if MOZ_WIDGET_GTK
// bug 108347, flash plugin on linux doesn't like window->width <=
// 0, but Java needs wants this call.
if (!nsPluginHost::IsJavaMIMEType(mMIMEType) && window->type == NPWindowTypeWindow &&
(window->width <= 0 || window->height <= 0)) {
if (window && window->type == NPWindowTypeWindow &&
(window->width <= 0 || window->height <= 0) &&
(nsPluginHost::GetSpecialType(nsDependentCString(mMIMEType)) !=
nsPluginHost::eSpecialType_Java)) {
return NS_OK;
}
#endif
@ -749,8 +751,8 @@ NPError nsNPAPIPluginInstance::SetWindowless(bool aWindowless)
// property. (Last tested version: sl 4.0).
// Changes to this code should be matched with changes in
// PluginInstanceChild::InitQuirksMode.
NS_NAMED_LITERAL_CSTRING(silverlight, "application/x-silverlight");
if (!PL_strncasecmp(mMIMEType, silverlight.get(), silverlight.Length())) {
if (nsPluginHost::GetSpecialType(nsDependentCString(mMIMEType)) ==
nsPluginHost::eSpecialType_Silverlight) {
mTransparent = true;
}
}

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

@ -1652,19 +1652,43 @@ nsPluginHost::SiteHasData(nsIPluginTag* plugin, const nsACString& domain,
return NS_OK;
}
bool nsPluginHost::IsJavaMIMEType(const char* aType)
nsPluginHost::SpecialType
nsPluginHost::GetSpecialType(const nsACString & aMIMEType)
{
if (aMIMEType.LowerCaseEqualsASCII("application/x-shockwave-flash") ||
aMIMEType.LowerCaseEqualsASCII("application/futuresplash")) {
return eSpecialType_Flash;
}
if (aMIMEType.LowerCaseEqualsASCII("application/x-silverlight") ||
aMIMEType.LowerCaseEqualsASCII("application/x-silverlight-2")) {
return eSpecialType_Silverlight;
}
if (aMIMEType.LowerCaseEqualsASCII("audio/x-pn-realaudio-plugin")) {
NS_WARNING("You are loading RealPlayer");
return eSpecialType_RealPlayer;
}
if (aMIMEType.LowerCaseEqualsASCII("application/pdf")) {
return eSpecialType_PDF;
}
// Java registers variants of its MIME with parameters, e.g.
// application/x-java-vm;version=1.3
const nsACString &noParam = Substring(aMIMEType, 0, aMIMEType.FindChar(';'));
// The java mime pref may well not be one of these,
// e.g. application/x-java-test used in the test suite
nsAdoptingCString javaMIME = Preferences::GetCString(kPrefJavaMIME);
return aType &&
(javaMIME.EqualsIgnoreCase(aType) ||
(0 == PL_strncasecmp(aType, "application/x-java-vm",
sizeof("application/x-java-vm") - 1)) ||
(0 == PL_strncasecmp(aType, "application/x-java-applet",
sizeof("application/x-java-applet") - 1)) ||
(0 == PL_strncasecmp(aType, "application/x-java-bean",
sizeof("application/x-java-bean") - 1)));
if ((!javaMIME.IsEmpty() && noParam.LowerCaseEqualsASCII(javaMIME)) ||
noParam.LowerCaseEqualsASCII("application/x-java-vm") ||
noParam.LowerCaseEqualsASCII("application/x-java-applet") ||
noParam.LowerCaseEqualsASCII("application/x-java-bean")) {
return eSpecialType_Java;
}
return eSpecialType_None;
}
// Check whether or not a tag is a live, valid tag, and that it's loaded.

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

@ -171,9 +171,20 @@ public:
// Always returns true if plugin.allowed_types is not set
static bool IsTypeWhitelisted(const char *aType);
// checks whether aTag is a "java" plugin tag (a tag for a plugin
// that does Java)
static bool IsJavaMIMEType(const char *aType);
// checks whether aType is a type we recognize for potential special handling
enum SpecialType { eSpecialType_None,
// Informs some decisions about OOP and quirks
eSpecialType_Flash,
// Binds to the <applet> tag, has various special
// rules around opening channels, codebase, ...
eSpecialType_Java,
// Some IPC quirks
eSpecialType_Silverlight,
// Native widget quirks
eSpecialType_PDF,
// Native widget quirks
eSpecialType_RealPlayer };
static SpecialType GetSpecialType(const nsACString & aMIMEType);
static nsresult PostPluginUnloadEvent(PRLibrary* aLibrary);

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

@ -1096,10 +1096,10 @@ void nsPluginInstanceOwner::AddToCARefreshTimer() {
// Flash invokes InvalidateRect for us.
const char* mime = nullptr;
if (NS_SUCCEEDED(mInstance->GetMIMEType(&mime)) && mime) {
if (strcmp(mime, "application/x-shockwave-flash") == 0) {
return;
}
if (NS_SUCCEEDED(mInstance->GetMIMEType(&mime)) && mime &&
nsPluginHost::GetSpecialType(nsDependentCString(mime)) ==
nsPluginHost::eSpecialType_Flash) {
return;
}
if (!sCARefreshListeners) {

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

@ -97,14 +97,6 @@ void PluginWindowEvent::Init(const PluginWindowWeakRef &ref, HWND aWnd,
* nsPluginNativeWindow Windows specific class declaration
*/
typedef enum {
nsPluginType_Unknown = 0,
nsPluginType_Flash,
nsPluginType_Real,
nsPluginType_PDF,
nsPluginType_Other
} nsPluginType;
class nsPluginNativeWindowWin : public nsPluginNativeWindow {
public:
nsPluginNativeWindowWin();
@ -135,7 +127,7 @@ private:
HWND mParentWnd;
LONG_PTR mParentProc;
public:
nsPluginType mPluginType;
nsPluginHost::SpecialType mPluginType;
};
static bool sInMessageDispatch = false;
@ -213,7 +205,7 @@ static LRESULT CALLBACK PluginWndProcInternal(HWND hWnd, UINT msg, WPARAM wParam
// Real may go into a state where it recursivly dispatches the same event
// when subclassed. If this is Real, lets examine the event and drop it
// on the floor if we get into this recursive situation. See bug 192914.
if (win->mPluginType == nsPluginType_Real) {
if (win->mPluginType == nsPluginHost::eSpecialType_RealPlayer) {
if (sInMessageDispatch && msg == sLastMsg)
return true;
// Cache the last message sent
@ -291,7 +283,7 @@ static LRESULT CALLBACK PluginWndProcInternal(HWND hWnd, UINT msg, WPARAM wParam
case WM_KILLFOCUS: {
// RealPlayer can crash, don't process the message for those,
// see bug 328675.
if (win->mPluginType == nsPluginType_Real && msg == sLastMsg)
if (win->mPluginType == nsPluginHost::eSpecialType_RealPlayer && msg == sLastMsg)
return TRUE;
// Make sure setfocus and killfocus get through to the widget procedure
// even if they are eaten by the plugin. Also make sure we aren't calling
@ -309,7 +301,7 @@ static LRESULT CALLBACK PluginWndProcInternal(HWND hWnd, UINT msg, WPARAM wParam
// Macromedia Flash plugin may flood the message queue with some special messages
// (WM_USER+1) causing 100% CPU consumption and GUI freeze, see mozilla bug 132759;
// we can prevent this from happening by delaying the processing such messages;
if (win->mPluginType == nsPluginType_Flash) {
if (win->mPluginType == nsPluginHost::eSpecialType_Flash) {
if (ProcessFlashMessageDelayed(win, inst, hWnd, msg, wParam, lParam))
return TRUE;
}
@ -403,7 +395,7 @@ SetWindowLongHookCheck(HWND hWnd,
{
nsPluginNativeWindowWin * win =
(nsPluginNativeWindowWin *)GetProp(hWnd, NS_PLUGIN_WINDOW_PROPERTY_ASSOCIATION);
if (!win || (win && win->mPluginType != nsPluginType_Flash) ||
if (!win || (win && win->mPluginType != nsPluginHost::eSpecialType_Flash) ||
(nIndex == GWLP_WNDPROC &&
newLong == reinterpret_cast<LONG_PTR>(PluginWndProc)))
return true;
@ -507,7 +499,7 @@ nsPluginNativeWindowWin::nsPluginNativeWindowWin() : nsPluginNativeWindow()
mPrevWinProc = nullptr;
mPluginWinProc = nullptr;
mPluginType = nsPluginType_Unknown;
mPluginType = nsPluginHost::eSpecialType_None;
mParentWnd = nullptr;
mParentProc = 0;
@ -615,18 +607,10 @@ nsresult nsPluginNativeWindowWin::CallSetWindow(nsRefPtr<nsNPAPIPluginInstance>
}
// check plugin mime type and cache it if it will need special treatment later
if (mPluginType == nsPluginType_Unknown) {
if (mPluginType == nsPluginHost::eSpecialType_None) {
const char* mimetype = nullptr;
aPluginInstance->GetMIMEType(&mimetype);
if (mimetype) {
if (!strcmp(mimetype, "application/x-shockwave-flash"))
mPluginType = nsPluginType_Flash;
else if (!strcmp(mimetype, "audio/x-pn-realaudio-plugin"))
mPluginType = nsPluginType_Real;
else if (!strcmp(mimetype, "application/pdf"))
mPluginType = nsPluginType_PDF;
else
mPluginType = nsPluginType_Other;
if (NS_SUCCEEDED(aPluginInstance->GetMIMEType(&mimetype)) && mimetype) {
mPluginType = nsPluginHost::GetSpecialType(nsDependentCString(mimetype));
}
}
@ -649,7 +633,7 @@ nsresult nsPluginNativeWindowWin::CallSetWindow(nsRefPtr<nsNPAPIPluginInstance>
// PDF plugin v7.0.9, v8.1.3, and v9.0 subclass parent window, bug 531551
// V8.2.2 and V9.1 don't have such problem.
if (mPluginType == nsPluginType_PDF) {
if (mPluginType == nsPluginHost::eSpecialType_PDF) {
HWND parent = ::GetParent((HWND)window);
if (mParentWnd != parent) {
NS_ASSERTION(!mParentWnd, "Plugin's parent window changed");
@ -663,7 +647,7 @@ nsresult nsPluginNativeWindowWin::CallSetWindow(nsRefPtr<nsNPAPIPluginInstance>
SubclassAndAssociateWindow();
if (window && mPluginType == nsPluginType_Flash &&
if (window && mPluginType == nsPluginHost::eSpecialType_Flash &&
!GetPropW((HWND)window, L"PluginInstanceParentProperty")) {
HookSetWindowLongPtr();
}
@ -741,7 +725,7 @@ nsresult nsPluginNativeWindowWin::UndoSubclassAndAssociateWindow()
SetWindowLongPtr(hWnd, GWL_STYLE, style);
}
if (mPluginType == nsPluginType_PDF && mParentWnd) {
if (mPluginType == nsPluginHost::eSpecialType_Flash && mParentWnd) {
::SetWindowLongPtr(mParentWnd, GWLP_WNDPROC, mParentProc);
mParentWnd = nullptr;
mParentProc = 0;

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

@ -195,10 +195,16 @@ void nsPluginTag::InitMime(const char* const* aMimeTypes,
}
// Look for certain special plugins.
if (nsPluginHost::IsJavaMIMEType(mimeType.get())) {
mIsJavaPlugin = true;
} else if (mimeType.EqualsLiteral("application/x-shockwave-flash")) {
mIsFlashPlugin = true;
switch (nsPluginHost::GetSpecialType(mimeType)) {
case nsPluginHost::eSpecialType_Java:
mIsJavaPlugin = true;
break;
case nsPluginHost::eSpecialType_Flash:
mIsFlashPlugin = true;
break;
case nsPluginHost::eSpecialType_None:
default:
break;
}
// Fill in our MIME type array.

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

@ -2077,10 +2077,10 @@ PluginModuleChild::InitQuirksModes(const nsCString& aMimeType)
if (mQuirks != QUIRKS_NOT_INITIALIZED)
return;
mQuirks = 0;
// application/x-silverlight
// application/x-silverlight-2
NS_NAMED_LITERAL_CSTRING(silverlight, "application/x-silverlight");
if (FindInReadable(silverlight, aMimeType)) {
nsPluginHost::SpecialType specialType = nsPluginHost::GetSpecialType(aMimeType);
if (specialType == nsPluginHost::eSpecialType_Silverlight) {
mQuirks |= QUIRK_SILVERLIGHT_DEFAULT_TRANSPARENT;
#ifdef OS_WIN
mQuirks |= QUIRK_WINLESS_TRACKPOPUP_HOOK;
@ -2089,9 +2089,7 @@ PluginModuleChild::InitQuirksModes(const nsCString& aMimeType)
}
#ifdef OS_WIN
// application/x-shockwave-flash
NS_NAMED_LITERAL_CSTRING(flash, "application/x-shockwave-flash");
if (FindInReadable(flash, aMimeType)) {
if (specialType == nsPluginHost::eSpecialType_Flash) {
mQuirks |= QUIRK_WINLESS_TRACKPOPUP_HOOK;
mQuirks |= QUIRK_FLASH_THROTTLE_WMUSER_EVENTS;
mQuirks |= QUIRK_FLASH_HOOK_SETLONGPTR;
@ -2108,14 +2106,12 @@ PluginModuleChild::InitQuirksModes(const nsCString& aMimeType)
#ifdef XP_MACOSX
// Whitelist Flash and Quicktime to support offline renderer
NS_NAMED_LITERAL_CSTRING(flash, "application/x-shockwave-flash");
NS_NAMED_LITERAL_CSTRING(quicktime, "QuickTime Plugin.plugin");
if (FindInReadable(flash, aMimeType)) {
mQuirks |= QUIRK_FLASH_AVOID_CGMODE_CRASHES;
mQuirks |= QUIRK_FLASH_HIDE_HIDPI_SUPPORT;
}
if (FindInReadable(flash, aMimeType) ||
FindInReadable(quicktime, mPluginFilename)) {
if (specialType == nsPluginHost::eSpecialType_Flash) {
mQuirks |= QUIRK_FLASH_AVOID_CGMODE_CRASHES;
mQuirks |= QUIRK_ALLOW_OFFLINE_RENDERER;
mQuirks |= QUIRK_FLASH_HIDE_HIDPI_SUPPORT;
} else if (FindInReadable(quicktime, mPluginFilename)) {
mQuirks |= QUIRK_ALLOW_OFFLINE_RENDERER;
}
#endif