Skip to content

Commit

Permalink
Backed out changeset b2d0e28fe539 (bug 1185639) test_plugin_focus.htm…
Browse files Browse the repository at this point in the history
…l timeouts.
  • Loading branch information
rvandermeulen committed Jul 27, 2015
1 parent c78e298 commit 555a316
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 172 deletions.
9 changes: 0 additions & 9 deletions ipc/glue/MessageChannel.cpp
Expand Up @@ -853,7 +853,6 @@ MessageChannel::Send(Message* aMsg, Message* aReply)

#ifdef OS_WIN
SyncStackFrame frame(this, false);
NeuteredWindowRegion neuteredRgn(mFlags & REQUIRE_DEFERRED_MESSAGE_PROTECTION);
#endif

CxxStackFrame f(*this, OUT_MESSAGE, msg);
Expand Down Expand Up @@ -995,7 +994,6 @@ MessageChannel::Call(Message* aMsg, Message* aReply)

#ifdef OS_WIN
SyncStackFrame frame(this, true);
NeuteredWindowRegion neuteredRgn(mFlags & REQUIRE_DEFERRED_MESSAGE_PROTECTION);
#endif

// This must come before MonitorAutoLock, as its destructor acquires the
Expand Down Expand Up @@ -1034,12 +1032,6 @@ MessageChannel::Call(Message* aMsg, Message* aReply)
return false;
}

#ifdef OS_WIN
/* We should pump messages at this point to ensure that the IPC peer
does not become deadlocked on a pending inter-thread SendMessage() */
neuteredRgn.PumpOnce();
#endif

// Now might be the time to process a message deferred because of race
// resolution.
MaybeUndeferIncall();
Expand Down Expand Up @@ -1156,7 +1148,6 @@ MessageChannel::WaitForIncomingMessage()
{
#ifdef OS_WIN
SyncStackFrame frame(this, true);
NeuteredWindowRegion neuteredRgn(mFlags & REQUIRE_DEFERRED_MESSAGE_PROTECTION);
#endif

{ // Scope for lock
Expand Down
3 changes: 0 additions & 3 deletions ipc/glue/MessageChannel.h
Expand Up @@ -15,9 +15,6 @@
#include "mozilla/Monitor.h"
#include "mozilla/Vector.h"
#include "mozilla/WeakPtr.h"
#if defined(OS_WIN)
#include "mozilla/ipc/Neutering.h"
#endif // defined(OS_WIN)
#include "mozilla/ipc/Transport.h"
#include "MessageLink.h"
#include "nsAutoPtr.h"
Expand Down
64 changes: 0 additions & 64 deletions ipc/glue/Neutering.h

This file was deleted.

177 changes: 82 additions & 95 deletions ipc/glue/WindowsMessageLoop.cpp
Expand Up @@ -8,7 +8,6 @@
#include "mozilla/DebugOnly.h"

#include "WindowsMessageLoop.h"
#include "Neutering.h"
#include "MessageChannel.h"

#include "nsAutoPtr.h"
Expand Down Expand Up @@ -863,85 +862,6 @@ IsTimeoutExpired(PRIntervalTime aStart, PRIntervalTime aTimeout)
(aTimeout <= (PR_IntervalNow() - aStart));
}

static HHOOK gWindowHook;

static inline void
StartNeutering()
{
MOZ_ASSERT(gUIThreadId);
MOZ_ASSERT(!gWindowHook);
NS_ASSERTION(!MessageChannel::IsPumpingMessages(),
"Shouldn't be pumping already!");
MessageChannel::SetIsPumpingMessages(true);
gWindowHook = ::SetWindowsHookEx(WH_CALLWNDPROC, CallWindowProcedureHook,
nullptr, gUIThreadId);
NS_ASSERTION(gWindowHook, "Failed to set hook!");
}

static void
StopNeutering()
{
MOZ_ASSERT(MessageChannel::IsPumpingMessages());
::UnhookWindowsHookEx(gWindowHook);
gWindowHook = NULL;
::UnhookNeuteredWindows();
// Before returning we need to set a hook to run any deferred messages that
// we received during the IPC call. The hook will unset itself as soon as
// someone else calls GetMessage, PeekMessage, or runs code that generates
// a "nonqueued" message.
::ScheduleDeferredMessageRun();
MessageChannel::SetIsPumpingMessages(false);
}

NeuteredWindowRegion::NeuteredWindowRegion(bool aDoNeuter MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL)
: mNeuteredByThis(!gWindowHook)
{
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
if (aDoNeuter && mNeuteredByThis) {
StartNeutering();
}
}

NeuteredWindowRegion::~NeuteredWindowRegion()
{
if (gWindowHook && mNeuteredByThis) {
StopNeutering();
}
}

void
NeuteredWindowRegion::PumpOnce()
{
MSG msg = {0};
if (gCOMWindow) {
// Pump any COM messages so that we don't hang due to STA marshaling.
// This call will also expunge any nonqueued messages on the current thread
if (::PeekMessageW(&msg, gCOMWindow, 0, 0, PM_REMOVE)) {
::TranslateMessage(&msg);
::DispatchMessageW(&msg);
}
} else {
// Expunge any nonqueued messages on the current thread
::PeekMessageW(&msg, nullptr, 0, 0, PM_NOREMOVE);
}
}

DeneuteredWindowRegion::DeneuteredWindowRegion(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_IN_IMPL)
: mReneuter(gWindowHook != NULL)
{
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
if (mReneuter) {
StopNeutering();
}
}

DeneuteredWindowRegion::~DeneuteredWindowRegion()
{
if (mReneuter) {
StartNeutering();
}
}

bool
MessageChannel::WaitForSyncNotify()
{
Expand Down Expand Up @@ -996,6 +916,15 @@ MessageChannel::WaitForSyncNotify()
NS_ASSERTION(timerId, "SetTimer failed!");
}

// Setup deferred processing of native events while we wait for a response.
NS_ASSERTION(!MessageChannel::IsPumpingMessages(),
"Shouldn't be pumping already!");

MessageChannel::SetIsPumpingMessages(true);
HHOOK windowHook = SetWindowsHookEx(WH_CALLWNDPROC, CallWindowProcedureHook,
nullptr, gUIThreadId);
NS_ASSERTION(windowHook, "Failed to set hook!");

{
while (1) {
MSG msg = { 0 };
Expand Down Expand Up @@ -1069,11 +998,25 @@ MessageChannel::WaitForSyncNotify()
}
}

// Unhook the neutered window procedure hook.
UnhookWindowsHookEx(windowHook);

// Unhook any neutered windows procedures so messages can be delivered
// normally.
UnhookNeuteredWindows();

// Before returning we need to set a hook to run any deferred messages that
// we received during the IPC call. The hook will unset itself as soon as
// someone else calls GetMessage, PeekMessage, or runs code that generates
// a "nonqueued" message.
ScheduleDeferredMessageRun();

if (timerId) {
KillTimer(nullptr, timerId);
timerId = 0;
}

MessageChannel::SetIsPumpingMessages(false);

return WaitResponse(timedout);
}

Expand Down Expand Up @@ -1107,28 +1050,56 @@ MessageChannel::WaitForInterruptNotify()
UINT_PTR timerId = 0;
TimeoutData timeoutData = { 0 };

// gWindowHook is used as a flag variable for the loop below: if it is set
// windowHook is used as a flag variable for the loop below: if it is set
// and we start to spin a nested event loop, we need to clear the hook and
// process deferred/pending messages.
// If windowHook is nullptr, MessageChannel::IsPumpingMessages should be false.
HHOOK windowHook = nullptr;

while (1) {
NS_ASSERTION((!!gWindowHook) == MessageChannel::IsPumpingMessages(),
"gWindowHook out of sync with reality");
NS_ASSERTION((!!windowHook) == MessageChannel::IsPumpingMessages(),
"windowHook out of sync with reality");

if (mTopFrame->mSpinNestedEvents) {
if (gWindowHook && timerId) {
KillTimer(nullptr, timerId);
timerId = 0;
if (windowHook) {
UnhookWindowsHookEx(windowHook);
windowHook = nullptr;

if (timerId) {
KillTimer(nullptr, timerId);
timerId = 0;
}

// Used by widget to assert on incoming native events
MessageChannel::SetIsPumpingMessages(false);

// Unhook any neutered windows procedures so messages can be delievered
// normally.
UnhookNeuteredWindows();

// Send all deferred "nonqueued" message to the intended receiver.
// We're dropping into SpinInternalEventLoop so we should be fairly
// certain these will get delivered soohn.
ScheduleDeferredMessageRun();
}
DeneuteredWindowRegion deneuteredRgn;
SpinInternalEventLoop();
ResetEvent(mEvent);
return true;
}

if (mTimeoutMs != kNoTimeout && !timerId) {
InitTimeoutData(&timeoutData, mTimeoutMs);
timerId = SetTimer(nullptr, 0, mTimeoutMs, nullptr);
NS_ASSERTION(timerId, "SetTimer failed!");
if (!windowHook) {
MessageChannel::SetIsPumpingMessages(true);
windowHook = SetWindowsHookEx(WH_CALLWNDPROC, CallWindowProcedureHook,
nullptr, gUIThreadId);
NS_ASSERTION(windowHook, "Failed to set hook!");

NS_ASSERTION(!timerId, "Timer already initialized?");

if (mTimeoutMs != kNoTimeout) {
InitTimeoutData(&timeoutData, mTimeoutMs);
timerId = SetTimer(nullptr, 0, mTimeoutMs, nullptr);
NS_ASSERTION(timerId, "SetTimer failed!");
}
}

MSG msg = { 0 };
Expand Down Expand Up @@ -1180,11 +1151,27 @@ MessageChannel::WaitForInterruptNotify()
}
}

if (timerId) {
KillTimer(nullptr, timerId);
timerId = 0;
if (windowHook) {
// Unhook the neutered window procedure hook.
UnhookWindowsHookEx(windowHook);

// Unhook any neutered windows procedures so messages can be delivered
// normally.
UnhookNeuteredWindows();

// Before returning we need to set a hook to run any deferred messages that
// we received during the IPC call. The hook will unset itself as soon as
// someone else calls GetMessage, PeekMessage, or runs code that generates
// a "nonqueued" message.
ScheduleDeferredMessageRun();

if (timerId) {
KillTimer(nullptr, timerId);
}
}

MessageChannel::SetIsPumpingMessages(false);

return WaitResponse(timedout);
}

Expand Down
1 change: 0 additions & 1 deletion ipc/glue/moz.build
Expand Up @@ -25,7 +25,6 @@ EXPORTS.mozilla.ipc += [
'IOThreadChild.h',
'MessageChannel.h',
'MessageLink.h',
'Neutering.h',
'ProcessChild.h',
'ProtocolUtils.h',
'ScopedXREEmbed.h',
Expand Down

0 comments on commit 555a316

Please sign in to comment.