Bug 768802: Prevent plugins from setting the foreground window during NP_Initialize; r=bsmedberg

--HG--
extra : rebase_source : 8628dba0eca82a12d2b9f999e55889c9a6c3ab18
This commit is contained in:
Aaron Klotz 2014-08-29 11:30:14 -06:00
parent 5662a359c6
commit 2b957f2ee3

View File

@ -34,6 +34,7 @@
#ifdef XP_WIN
#include "PluginHangUIParent.h"
#include "mozilla/GuardObjects.h"
#include "mozilla/widget/AudioSession.h"
#endif
@ -1217,6 +1218,26 @@ PluginModuleParent::NP_Initialize(NPNetscapeFuncs* bFuncs, NPPluginFuncs* pFuncs
return NS_OK;
}
#else
#if defined(XP_WIN)
class MOZ_STACK_CLASS SetForegroundLocker
{
public:
SetForegroundLocker(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM)
{
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
::LockSetForegroundWindow(LSFW_LOCK);
}
~SetForegroundLocker()
{
::LockSetForegroundWindow(LSFW_UNLOCK);
}
private:
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
};
#endif
nsresult
PluginModuleParent::NP_Initialize(NPNetscapeFuncs* bFuncs, NPError* error)
{
@ -1232,6 +1253,11 @@ PluginModuleParent::NP_Initialize(NPNetscapeFuncs* bFuncs, NPError* error)
uint32_t flags = 0;
#ifdef XP_WIN
flags |= kAllowAsyncDrawing;
// Bug 768802: We need to call LockSetForegroundWindow before calling
// NP_Initialize to prevent our window from losing focus when the
// plugin starts.
SetForegroundLocker fgLock;
#endif
if (!CallNP_Initialize(flags, error)) {