Bug 1133351: Backed out 0cc8abe4e2bb for assertion failures; r=bustage

This commit is contained in:
Aaron Klotz 2015-03-28 06:08:26 -07:00
parent e44e211365
commit 9f5bba30cd
6 changed files with 152 additions and 62 deletions

View File

@ -0,0 +1,84 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "base/basictypes.h"
#include "COMMessageFilter.h"
#include "base/message_loop.h"
#include "mozilla/plugins/PluginModuleChild.h"
#include <stdio.h>
namespace mozilla {
namespace plugins {
HRESULT
COMMessageFilter::QueryInterface(REFIID riid, void** ppv)
{
if (riid == IID_IUnknown || riid == IID_IMessageFilter) {
*ppv = static_cast<IMessageFilter*>(this);
AddRef();
return S_OK;
}
return E_NOINTERFACE;
}
DWORD COMMessageFilter::AddRef()
{
++mRefCnt;
return mRefCnt;
}
DWORD COMMessageFilter::Release()
{
DWORD r = --mRefCnt;
if (0 == r)
delete this;
return r;
}
DWORD
COMMessageFilter::HandleInComingCall(DWORD dwCallType,
HTASK htaskCaller,
DWORD dwTickCount,
LPINTERFACEINFO lpInterfaceInfo)
{
if (mPreviousFilter)
return mPreviousFilter->HandleInComingCall(dwCallType, htaskCaller,
dwTickCount, lpInterfaceInfo);
return SERVERCALL_ISHANDLED;
}
DWORD
COMMessageFilter::RetryRejectedCall(HTASK htaskCallee,
DWORD dwTickCount,
DWORD dwRejectType)
{
if (mPreviousFilter)
return mPreviousFilter->RetryRejectedCall(htaskCallee, dwTickCount,
dwRejectType);
return -1;
}
DWORD
COMMessageFilter::MessagePending(HTASK htaskCallee,
DWORD dwTickCount,
DWORD dwPendingType)
{
mPlugin->FlushPendingInterruptQueue();
if (mPreviousFilter)
return mPreviousFilter->MessagePending(htaskCallee, dwTickCount,
dwPendingType);
return PENDINGMSG_WAITNOPROCESS;
}
void
COMMessageFilter::Initialize(PluginModuleChild* module)
{
nsRefPtr<COMMessageFilter> f = new COMMessageFilter(module);
::CoRegisterMessageFilter(f, getter_AddRefs(f->mPreviousFilter));
}
} // namespace plugins
} // namespace mozilla

View File

@ -0,0 +1,50 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_plugins_COMMessageFilter_h
#define mozilla_plugins_COMMessageFilter_h
#include <objidl.h>
#include "nsISupportsImpl.h"
#include "nsAutoPtr.h"
namespace mozilla {
namespace plugins {
class PluginModuleChild;
class COMMessageFilter final : public IMessageFilter
{
public:
static void Initialize(PluginModuleChild* plugin);
COMMessageFilter(PluginModuleChild* plugin)
: mPlugin(plugin)
{ }
HRESULT WINAPI QueryInterface(REFIID riid, void** ppv);
DWORD WINAPI AddRef();
DWORD WINAPI Release();
DWORD WINAPI HandleInComingCall(DWORD dwCallType,
HTASK htaskCaller,
DWORD dwTickCount,
LPINTERFACEINFO lpInterfaceInfo);
DWORD WINAPI RetryRejectedCall(HTASK htaskCallee,
DWORD dwTickCount,
DWORD dwRejectType);
DWORD WINAPI MessagePending(HTASK htaskCallee,
DWORD dwTickCount,
DWORD dwPendingType);
private:
nsAutoRefCnt mRefCnt;
PluginModuleChild* mPlugin;
nsRefPtr<IMessageFilter> mPreviousFilter;
};
} // namespace plugins
} // namespace mozilla
#endif // COMMessageFilter_h

View File

@ -42,6 +42,7 @@
#include "nsNPAPIPlugin.h"
#ifdef XP_WIN
#include "COMMessageFilter.h"
#include "nsWindowsDllInterceptor.h"
#include "mozilla/widget/AudioSession.h"
#endif
@ -263,6 +264,10 @@ PluginModuleChild::InitForChrome(const std::string& aPluginFilename,
MessageLoop* aIOLoop,
IPC::Channel* aChannel)
{
#ifdef XP_WIN
COMMessageFilter::Initialize(this);
#endif
NS_ASSERTION(aChannel, "need a channel");
if (!InitGraphics())

View File

@ -50,6 +50,7 @@ if CONFIG['OS_ARCH'] == 'WINNT':
'PluginSurfaceParent.h',
]
UNIFIED_SOURCES += [
'COMMessageFilter.cpp',
'PluginHangUIParent.cpp',
'PluginSurfaceParent.cpp',
]

View File

@ -104,7 +104,6 @@ HHOOK gDeferredGetMsgHook = nullptr;
HHOOK gDeferredCallWndProcHook = nullptr;
DWORD gUIThreadId = 0;
HWND gCOMWindow = 0;
// WM_GETOBJECT id pulled from uia headers
#define MOZOBJID_UIAROOT -25
@ -341,15 +340,13 @@ ProcessOrDeferMessage(HWND hwnd,
case WM_GETOBJECT: {
if (!::GetPropW(hwnd, k3rdPartyWindowProp)) {
DWORD objId = static_cast<DWORD>(lParam);
if ((objId == OBJID_CLIENT || objId == MOZOBJID_UIAROOT)) {
WNDPROC oldWndProc = (WNDPROC)GetProp(hwnd, kOldWndProcProp);
if (oldWndProc) {
return CallWindowProcW(oldWndProc, hwnd, uMsg, wParam, lParam);
}
WNDPROC oldWndProc = (WNDPROC)GetProp(hwnd, kOldWndProcProp);
if ((objId == OBJID_CLIENT || objId == MOZOBJID_UIAROOT) && oldWndProc) {
return CallWindowProcW(oldWndProc, hwnd, uMsg, wParam, lParam);
}
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
break;
}
#endif // ACCESSIBILITY
default: {
@ -650,10 +647,7 @@ InitUIThread()
// on startup.
if (!gUIThreadId) {
gUIThreadId = GetCurrentThreadId();
CoInitialize(nullptr);
}
MOZ_ASSERT(gUIThreadId);
MOZ_ASSERT(gUIThreadId == GetCurrentThreadId(),
"Called InitUIThread multiple times on different threads!");
@ -810,21 +804,6 @@ IsTimeoutExpired(PRIntervalTime aStart, PRIntervalTime aTimeout)
(aTimeout <= (PR_IntervalNow() - aStart));
}
HWND
FindCOMWindow()
{
MOZ_ASSERT(gUIThreadId);
HWND last = 0;
while ((last = FindWindowExW(HWND_MESSAGE, last, L"OleMainThreadWndClass", NULL))) {
if (GetWindowThreadProcessId(last, NULL) == gUIThreadId) {
return last;
}
}
return (HWND)0;
}
bool
MessageChannel::WaitForSyncNotify()
{
@ -865,12 +844,6 @@ MessageChannel::WaitForSyncNotify()
MonitorAutoUnlock unlock(*mMonitor);
MOZ_ASSERT_IF(gCOMWindow, FindCOMWindow() == gCOMWindow);
if (!gCOMWindow) {
gCOMWindow = FindCOMWindow();
}
bool timedout = false;
UINT_PTR timerId = 0;
@ -939,20 +912,11 @@ MessageChannel::WaitForSyncNotify()
bool haveSentMessagesPending =
(HIWORD(GetQueueStatus(QS_SENDMESSAGE)) & QS_SENDMESSAGE) != 0;
// Either of the PeekMessage calls below will actually process all
// "nonqueued" messages that are pending before returning. If we have
// "nonqueued" messages pending then we should have switched out all the
// window procedures above. In that case this PeekMessage call won't
// actually cause any mozilla code (or plugin code) to run.
// We have to manually pump all COM messages *after* looking at the queue
// queue status but before yielding our thread below.
if (gCOMWindow) {
if (PeekMessageW(&msg, gCOMWindow, 0, 0, PM_REMOVE)) {
TranslateMessage(&msg);
::DispatchMessageW(&msg);
}
}
// This PeekMessage call will actually process all "nonqueued" messages
// that are pending before returning. If we have "nonqueued" messages
// pending then we should have switched out all the window procedures
// above. In that case this PeekMessage call won't actually cause any
// mozilla code (or plugin code) to run.
// If the following PeekMessage call fails to return a message for us (and
// returns false) and we didn't run any "nonqueued" messages then we must
@ -1014,12 +978,6 @@ MessageChannel::WaitForInterruptNotify()
MonitorAutoUnlock unlock(*mMonitor);
MOZ_ASSERT_IF(gCOMWindow, FindCOMWindow() == gCOMWindow);
if (!gCOMWindow) {
gCOMWindow = FindCOMWindow();
}
bool timedout = false;
UINT_PTR timerId = 0;
@ -1109,14 +1067,6 @@ MessageChannel::WaitForInterruptNotify()
bool haveSentMessagesPending =
(HIWORD(GetQueueStatus(QS_SENDMESSAGE)) & QS_SENDMESSAGE) != 0;
// Run all COM messages *after* looking at the queue status.
if (gCOMWindow) {
if (PeekMessageW(&msg, gCOMWindow, 0, 0, PM_REMOVE)) {
TranslateMessage(&msg);
::DispatchMessageW(&msg);
}
}
// PeekMessage markes the messages as "old" so that they don't wake up
// MsgWaitForMultipleObjects every time.
if (!PeekMessageW(&msg, nullptr, 0, 0, PM_NOREMOVE) &&

View File

@ -4144,8 +4144,8 @@ nsWindow::IsAsyncResponseEvent(UINT aMsg, LRESULT& aResult)
void
nsWindow::IPCWindowProcHandler(UINT& msg, WPARAM& wParam, LPARAM& lParam)
{
MOZ_ASSERT_IF(msg != WM_GETOBJECT,
!mozilla::ipc::MessageChannel::IsPumpingMessages());
NS_ASSERTION(!mozilla::ipc::MessageChannel::IsPumpingMessages(),
"Failed to prevent a nonqueued message from running!");
// Modal UI being displayed in windowless plugins.
if (mozilla::ipc::MessageChannel::IsSpinLoopActive() &&