mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 05:11:16 +00:00
Back out bug 1191145 - Stop blocking scripts in CPOW IPCs
This commit is contained in:
parent
4abd7ee5d1
commit
47202f14e8
@ -648,6 +648,10 @@ ContentChild::Init(MessageLoop* aIOLoop,
|
||||
}
|
||||
sSingleton = this;
|
||||
|
||||
// Make sure there's an nsAutoScriptBlocker on the stack when dispatching
|
||||
// urgent messages.
|
||||
GetIPCChannel()->BlockScripts();
|
||||
|
||||
// If communications with the parent have broken down, take the process
|
||||
// down so it's not hanging around.
|
||||
bool abortOnError = true;
|
||||
|
@ -275,6 +275,31 @@ private:
|
||||
CxxStackFrame& operator=(const CxxStackFrame&) = delete;
|
||||
};
|
||||
|
||||
namespace {
|
||||
|
||||
class MOZ_RAII MaybeScriptBlocker {
|
||||
public:
|
||||
explicit MaybeScriptBlocker(MessageChannel *aChannel, bool aBlock
|
||||
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
||||
: mBlocked(aChannel->ShouldBlockScripts() && aBlock)
|
||||
{
|
||||
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
||||
if (mBlocked) {
|
||||
nsContentUtils::AddScriptBlocker();
|
||||
}
|
||||
}
|
||||
~MaybeScriptBlocker() {
|
||||
if (mBlocked) {
|
||||
nsContentUtils::RemoveScriptBlocker();
|
||||
}
|
||||
}
|
||||
private:
|
||||
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
||||
bool mBlocked;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
MessageChannel::MessageChannel(MessageListener *aListener)
|
||||
: mListener(aListener),
|
||||
mChannelState(ChannelClosed),
|
||||
@ -300,6 +325,7 @@ MessageChannel::MessageChannel(MessageListener *aListener)
|
||||
mSawInterruptOutMsg(false),
|
||||
mIsWaitingForIncoming(false),
|
||||
mAbortOnError(false),
|
||||
mBlockScripts(false),
|
||||
mFlags(REQUIRE_DEFAULT),
|
||||
mPeerPidSet(false),
|
||||
mPeerPid(-1)
|
||||
@ -815,6 +841,9 @@ MessageChannel::Send(Message* aMsg, Message* aReply)
|
||||
{
|
||||
nsAutoPtr<Message> msg(aMsg);
|
||||
|
||||
// See comment in DispatchSyncMessage.
|
||||
MaybeScriptBlocker scriptBlocker(this, true);
|
||||
|
||||
// Sanity checks.
|
||||
AssertWorkerThread();
|
||||
mMonitor->AssertNotCurrentThreadOwns();
|
||||
@ -1296,7 +1325,13 @@ MessageChannel::DispatchSyncMessage(const Message& aMsg, Message*& aReply)
|
||||
AssertWorkerThread();
|
||||
|
||||
int prio = aMsg.priority();
|
||||
|
||||
// We don't want to run any code that might run a nested event loop here, so
|
||||
// we avoid running event handlers. Once we've sent the response to the
|
||||
// urgent message, it's okay to run event handlers again since the parent is
|
||||
// no longer blocked.
|
||||
MOZ_ASSERT_IF(prio > IPC::Message::PRIORITY_NORMAL, NS_IsMainThread());
|
||||
MaybeScriptBlocker scriptBlocker(this, prio > IPC::Message::PRIORITY_NORMAL);
|
||||
|
||||
MessageChannel* dummy;
|
||||
MessageChannel*& blockingVar = NS_IsMainThread() ? gMainThreadBlocker : dummy;
|
||||
@ -1854,6 +1889,13 @@ MessageChannel::CloseWithTimeout()
|
||||
mChannelState = ChannelTimeout;
|
||||
}
|
||||
|
||||
void
|
||||
MessageChannel::BlockScripts()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
mBlockScripts = true;
|
||||
}
|
||||
|
||||
void
|
||||
MessageChannel::Close()
|
||||
{
|
||||
|
@ -107,6 +107,13 @@ class MessageChannel : HasResultCodes
|
||||
void SetChannelFlags(ChannelFlags aFlags) { mFlags = aFlags; }
|
||||
ChannelFlags GetChannelFlags() { return mFlags; }
|
||||
|
||||
void BlockScripts();
|
||||
|
||||
bool ShouldBlockScripts() const
|
||||
{
|
||||
return mBlockScripts;
|
||||
}
|
||||
|
||||
// Asynchronously send a message to the other side of the channel
|
||||
bool Send(Message* aMsg);
|
||||
|
||||
@ -729,6 +736,9 @@ class MessageChannel : HasResultCodes
|
||||
// a channel error occurs?
|
||||
bool mAbortOnError;
|
||||
|
||||
// Should we prevent scripts from running while dispatching urgent messages?
|
||||
bool mBlockScripts;
|
||||
|
||||
// See SetChannelFlags
|
||||
ChannelFlags mFlags;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user