Skip to content

Commit

Permalink
Bug 449129 - abort a plugin process if a plugin attempts to spin an e…
Browse files Browse the repository at this point in the history
…vent loop while painting, r=jmathies
  • Loading branch information
bsmedberg committed Jun 23, 2010
1 parent 0624a7a commit 1af2f35
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 0 deletions.
4 changes: 4 additions & 0 deletions dom/plugins/PluginInstanceChild.cpp
Expand Up @@ -615,6 +615,8 @@ PluginInstanceChild::AnswerNPP_HandleEvent_Shmem(const NPRemoteEvent& event,
PLUGIN_LOG_DEBUG_FUNCTION;
AssertPluginThread();

PaintTracker pt;

NPCocoaEvent evcopy = event.event;

if (evcopy.type == NPCocoaEventDrawRect) {
Expand Down Expand Up @@ -686,6 +688,8 @@ PluginInstanceChild::AnswerNPP_HandleEvent_IOSurface(const NPRemoteEvent& event,
PLUGIN_LOG_DEBUG_FUNCTION;
AssertPluginThread();

PaintTracker pt;

NPCocoaEvent evcopy = event.event;
nsIOSurface* surf = nsIOSurface::LookupSurface(surfaceid);
if (!surf) {
Expand Down
2 changes: 2 additions & 0 deletions dom/plugins/PluginInstanceChild.h
Expand Up @@ -56,6 +56,7 @@
#include "ChildTimer.h"
#include "nsRect.h"
#include "nsTHashtable.h"
#include "mozilla/PaintTracker.h"

namespace mozilla {
namespace plugins {
Expand Down Expand Up @@ -100,6 +101,7 @@ class PluginInstanceChild : public PPluginInstanceChild
virtual bool
AnswerPaint(const NPRemoteEvent& event, int16_t* handled)
{
PaintTracker pt;
return AnswerNPP_HandleEvent(event, handled);
}

Expand Down
5 changes: 5 additions & 0 deletions ipc/glue/WindowsMessageLoop.cpp
Expand Up @@ -47,6 +47,7 @@
#include "nsIXULAppInfo.h"

#include "mozilla/Mutex.h"
#include "mozilla/PaintTracker.h"

using mozilla::ipc::SyncChannel;
using mozilla::ipc::RPCChannel;
Expand Down Expand Up @@ -623,6 +624,10 @@ RPCChannel::ProcessNativeEventsInRPCCall()
void
RPCChannel::SpinInternalEventLoop()
{
if (mozilla::PaintTracker::IsPainting()) {
NS_RUNTIMEABORT("Don't spin an event loop while painting.");
}

NS_ASSERTION(mTopFrame && mTopFrame->mSpinNestedEvents,
"Spinning incorrectly");

Expand Down
7 changes: 7 additions & 0 deletions layout/base/Makefile.in
Expand Up @@ -58,6 +58,8 @@ XPIDLSRCS = \
nsIStyleSheetService.idl \
$(NULL)

EXPORTS_NAMESPACES = mozilla

EXPORTS = \
FrameLayerBuilder.h \
FramePropertyTable.h \
Expand Down Expand Up @@ -88,6 +90,10 @@ EXPORTS = \
nsStyleConsts.h \
$(NULL)

EXPORTS_mozilla = \
PaintTracker.h \
$(NULL)

CPPSRCS = \
FrameLayerBuilder.cpp \
FramePropertyTable.cpp \
Expand Down Expand Up @@ -115,6 +121,7 @@ CPPSRCS = \
nsRefreshDriver.cpp \
nsStyleChangeList.cpp \
nsStyleSheetService.cpp \
PaintTracker.cpp \
$(NULL)

ifndef MOZ_XUL
Expand Down
7 changes: 7 additions & 0 deletions layout/base/PaintTracker.cpp
@@ -0,0 +1,7 @@
#include "mozilla/PaintTracker.h"

namespace mozilla {

int PaintTracker::gPaintTracker;

} // namespace mozilla
29 changes: 29 additions & 0 deletions layout/base/PaintTracker.h
@@ -0,0 +1,29 @@
#ifndef mozilla_PaintTracker_h
#define mozilla_PaintTracker_h

#include "nscore.h"
#include "nsDebug.h"

namespace mozilla {

class NS_STACK_CLASS PaintTracker
{
public:
PaintTracker() {
++gPaintTracker;
}
~PaintTracker() {
NS_ASSERTION(gPaintTracker > 0, "Mismatched constructor/destructor");
}

static bool IsPainting() {
return !!gPaintTracker;
}

private:
static int gPaintTracker;
};

} // namespace mozilla

#endif // mozilla_PaintTracker_h

0 comments on commit 1af2f35

Please sign in to comment.