Backed out changesets b7d9158b53e7 and 820a0cabcb92 (bug 1131375) for Windows bustage.

CLOSED TREE

--HG--
extra : rebase_source : be0f4ecf8aa06e10e503dbff675feeddd8442bf9
This commit is contained in:
Ryan VanderMeulen 2015-02-18 14:47:27 -05:00
Родитель 35dc26890e
Коммит 31b517eaf7
9 изменённых файлов: 55 добавлений и 238 удалений

Просмотреть файл

@ -1,72 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* 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 "SameProcessMessageQueue.h"
using namespace mozilla;
using namespace mozilla::dom;
SameProcessMessageQueue* SameProcessMessageQueue::sSingleton;
SameProcessMessageQueue::SameProcessMessageQueue()
{
}
SameProcessMessageQueue::~SameProcessMessageQueue()
{
// This code should run during shutdown, and we should already have pumped the
// event loop. So we should only see messages here if someone is sending
// messages pretty late in shutdown.
NS_WARN_IF_FALSE(mQueue.IsEmpty(), "Shouldn't send messages during shutdown");
sSingleton = nullptr;
}
void
SameProcessMessageQueue::Push(Runnable* aRunnable)
{
mQueue.AppendElement(aRunnable);
NS_DispatchToCurrentThread(aRunnable);
}
void
SameProcessMessageQueue::Flush()
{
nsTArray<nsRefPtr<Runnable>> queue;
mQueue.SwapElements(queue);
for (size_t i = 0; i < queue.Length(); i++) {
queue[i]->Run();
}
}
/* static */ SameProcessMessageQueue*
SameProcessMessageQueue::Get()
{
if (!sSingleton) {
sSingleton = new SameProcessMessageQueue();
}
return sSingleton;
}
SameProcessMessageQueue::Runnable::Runnable()
: mDispatched(false)
{
}
NS_IMPL_ISUPPORTS(SameProcessMessageQueue::Runnable, nsIRunnable)
nsresult
SameProcessMessageQueue::Runnable::Run()
{
if (mDispatched) {
return NS_OK;
}
SameProcessMessageQueue* queue = SameProcessMessageQueue::Get();
queue->mQueue.RemoveElement(this);
mDispatched = true;
return HandleMessage();
}

Просмотреть файл

@ -1,57 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* 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_dom_SameProcessMessageQueue_h
#define mozilla_dom_SameProcessMessageQueue_h
#include "nsIRunnable.h"
#include "nsRefPtr.h"
#include "nsTArray.h"
namespace mozilla {
namespace dom {
class CancelableRunnable;
class SameProcessMessageQueue
{
public:
SameProcessMessageQueue();
virtual ~SameProcessMessageQueue();
class Runnable : public nsIRunnable
{
public:
explicit Runnable();
NS_DECL_ISUPPORTS
NS_DECL_NSIRUNNABLE
virtual nsresult HandleMessage() = 0;
protected:
virtual ~Runnable() {}
private:
bool mDispatched;
};
void Push(Runnable* aRunnable);
void Flush();
static SameProcessMessageQueue* Get();
private:
friend class CancelableRunnable;
nsTArray<nsRefPtr<Runnable>> mQueue;
static SameProcessMessageQueue* sSingleton;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_SameProcessMessageQueue_h

Просмотреть файл

@ -184,7 +184,6 @@ EXPORTS.mozilla.dom += [
'PerformanceMeasure.h',
'PerformanceResourceTiming.h',
'ResponsiveImageSelector.h',
'SameProcessMessageQueue.h',
'ScreenOrientation.h',
'ScriptSettings.h',
'ShadowRoot.h',
@ -320,7 +319,6 @@ UNIFIED_SOURCES += [
'PerformanceMeasure.cpp',
'PerformanceResourceTiming.cpp',
'ResponsiveImageSelector.cpp',
'SameProcessMessageQueue.cpp',
'ScriptSettings.cpp',
'ShadowRoot.cpp',
'StyleSheetList.cpp',

Просмотреть файл

@ -33,7 +33,6 @@
#include "mozilla/dom/File.h"
#include "mozilla/dom/nsIContentParent.h"
#include "mozilla/dom/PermissionMessageUtils.h"
#include "mozilla/dom/SameProcessMessageQueue.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/dom/StructuredCloneUtils.h"
#include "mozilla/dom/ipc/BlobChild.h"
@ -1631,6 +1630,7 @@ NS_IMPL_ISUPPORTS(nsScriptCacheCleaner, nsIObserver)
nsFrameMessageManager* nsFrameMessageManager::sChildProcessManager = nullptr;
nsFrameMessageManager* nsFrameMessageManager::sParentProcessManager = nullptr;
nsFrameMessageManager* nsFrameMessageManager::sSameProcessParentManager = nullptr;
nsTArray<nsCOMPtr<nsIRunnable> >* nsFrameMessageManager::sPendingSameProcessAsyncMessages = nullptr;
class nsAsyncMessageToSameProcessChild : public nsSameProcessAsyncMessageBase,
public nsRunnable
@ -1779,7 +1779,7 @@ public:
class nsAsyncMessageToSameProcessParent : public nsSameProcessAsyncMessageBase,
public SameProcessMessageQueue::Runnable
public nsRunnable
{
public:
nsAsyncMessageToSameProcessParent(JSContext* aCx,
@ -1788,15 +1788,25 @@ public:
JS::Handle<JSObject *> aCpows,
nsIPrincipal* aPrincipal)
: nsSameProcessAsyncMessageBase(aCx, aMessage, aData, aCpows, aPrincipal)
, mDelivered(false)
{
}
NS_IMETHOD HandleMessage()
NS_IMETHOD Run()
{
if (nsFrameMessageManager::sPendingSameProcessAsyncMessages) {
nsFrameMessageManager::sPendingSameProcessAsyncMessages->RemoveElement(this);
}
if (!mDelivered) {
mDelivered = true;
nsFrameMessageManager* ppm = nsFrameMessageManager::sSameProcessParentManager;
ReceiveMessage(static_cast<nsIContentFrameMessageManager*>(ppm), ppm);
}
return NS_OK;
}
private:
bool mDelivered;
};
/**
@ -1822,9 +1832,15 @@ public:
InfallibleTArray<nsString>* aJSONRetVal,
bool aIsSync) MOZ_OVERRIDE
{
SameProcessMessageQueue* queue = SameProcessMessageQueue::Get();
queue->Flush();
nsTArray<nsCOMPtr<nsIRunnable> > asyncMessages;
if (nsFrameMessageManager::sPendingSameProcessAsyncMessages) {
asyncMessages.SwapElements(*nsFrameMessageManager::sPendingSameProcessAsyncMessages);
uint32_t len = asyncMessages.Length();
for (uint32_t i = 0; i < len; ++i) {
nsCOMPtr<nsIRunnable> async = asyncMessages[i];
async->Run();
}
}
if (nsFrameMessageManager::sSameProcessParentManager) {
SameProcessCpowHolder cpows(js::GetRuntime(aCx), aCpows);
nsRefPtr<nsFrameMessageManager> ppm = nsFrameMessageManager::sSameProcessParentManager;
@ -1840,10 +1856,13 @@ public:
JS::Handle<JSObject *> aCpows,
nsIPrincipal* aPrincipal) MOZ_OVERRIDE
{
SameProcessMessageQueue* queue = SameProcessMessageQueue::Get();
nsRefPtr<nsAsyncMessageToSameProcessParent> ev =
if (!nsFrameMessageManager::sPendingSameProcessAsyncMessages) {
nsFrameMessageManager::sPendingSameProcessAsyncMessages = new nsTArray<nsCOMPtr<nsIRunnable> >;
}
nsCOMPtr<nsIRunnable> ev =
new nsAsyncMessageToSameProcessParent(aCx, aMessage, aData, aCpows, aPrincipal);
queue->Push(ev);
nsFrameMessageManager::sPendingSameProcessAsyncMessages->AppendElement(ev);
NS_DispatchToCurrentThread(ev);
return true;
}

Просмотреть файл

@ -27,7 +27,6 @@
#include "mozilla/Attributes.h"
#include "js/RootingAPI.h"
#include "nsTObserverArray.h"
#include "mozilla/dom/SameProcessMessageQueue.h"
#include "mozilla/dom/StructuredCloneUtils.h"
#include "mozilla/jsipc/CpowHolder.h"
@ -201,7 +200,8 @@ private:
}
if (this == sChildProcessManager) {
sChildProcessManager = nullptr;
delete mozilla::dom::SameProcessMessageQueue::Get();
delete sPendingSameProcessAsyncMessages;
sPendingSameProcessAsyncMessages = nullptr;
}
if (this == sSameProcessParentManager) {
sSameProcessParentManager = nullptr;

Просмотреть файл

@ -19,7 +19,6 @@
#include "nsIMozBrowserFrame.h"
#include "nsDOMClassInfoID.h"
#include "mozilla/EventDispatcher.h"
#include "mozilla/dom/SameProcessMessageQueue.h"
#include "mozilla/dom/StructuredCloneUtils.h"
#include "js/StructuredClone.h"
@ -36,9 +35,13 @@ nsInProcessTabChildGlobal::DoSendBlockingMessage(JSContext* aCx,
InfallibleTArray<nsString>* aJSONRetVal,
bool aIsSync)
{
SameProcessMessageQueue* queue = SameProcessMessageQueue::Get();
queue->Flush();
nsTArray<nsCOMPtr<nsIRunnable> > asyncMessages;
asyncMessages.SwapElements(mASyncMessages);
uint32_t len = asyncMessages.Length();
for (uint32_t i = 0; i < len; ++i) {
nsCOMPtr<nsIRunnable> async = asyncMessages[i];
async->Run();
}
if (mChromeMessageManager) {
SameProcessCpowHolder cpows(js::GetRuntime(aCx), aCpows);
nsRefPtr<nsFrameMessageManager> mm = mChromeMessageManager;
@ -49,7 +52,7 @@ nsInProcessTabChildGlobal::DoSendBlockingMessage(JSContext* aCx,
}
class nsAsyncMessageToParent : public nsSameProcessAsyncMessageBase,
public SameProcessMessageQueue::Runnable
public nsRunnable
{
public:
nsAsyncMessageToParent(JSContext* aCx,
@ -59,16 +62,25 @@ public:
JS::Handle<JSObject *> aCpows,
nsIPrincipal* aPrincipal)
: nsSameProcessAsyncMessageBase(aCx, aMessage, aData, aCpows, aPrincipal),
mTabChild(aTabChild)
mTabChild(aTabChild), mRun(false)
{
}
NS_IMETHOD HandleMessage()
NS_IMETHOD Run()
{
if (mRun) {
return NS_OK;
}
mRun = true;
mTabChild->mASyncMessages.RemoveElement(this);
ReceiveMessage(mTabChild->mOwner, mTabChild->mChromeMessageManager);
return NS_OK;
}
nsRefPtr<nsInProcessTabChildGlobal> mTabChild;
// True if this runnable has already been called. This can happen if DoSendSyncMessage
// is called while waiting for an asynchronous message send.
bool mRun;
};
bool
@ -78,10 +90,10 @@ nsInProcessTabChildGlobal::DoSendAsyncMessage(JSContext* aCx,
JS::Handle<JSObject *> aCpows,
nsIPrincipal* aPrincipal)
{
SameProcessMessageQueue* queue = SameProcessMessageQueue::Get();
nsRefPtr<nsAsyncMessageToParent> ev =
nsCOMPtr<nsIRunnable> ev =
new nsAsyncMessageToParent(aCx, this, aMessage, aData, aCpows, aPrincipal);
queue->Push(ev);
mASyncMessages.AppendElement(ev);
NS_DispatchToCurrentThread(ev);
return true;
}

Просмотреть файл

@ -175,6 +175,7 @@ protected:
public:
nsIContent* mOwner;
nsFrameMessageManager* mChromeMessageManager;
nsTArray<nsCOMPtr<nsIRunnable> > mASyncMessages;
};
#endif

Просмотреть файл

@ -9,4 +9,3 @@ skip-if = e10s # Bug ?????? - test e10s utils don't support load events from ifr
skip-if = true # Intermittent failures - bug 987493. Restore the skip-if above once fixed
[browser_bug1058164.js]
skip-if = e10s # We need bug 918634 to land before this can be tested with e10s.
[browser_ipc_order.js]

Просмотреть файл

@ -1,83 +0,0 @@
add_task(function*() {
let frame_script = () => {
const { classes: Cc, interfaces: Ci } = Components;
let cpmm = Cc["@mozilla.org/childprocessmessagemanager;1"].
getService(Ci.nsISyncMessageSender);
sendAsyncMessage("Test:Frame:Async");
cpmm.sendAsyncMessage("Test:Process:Async");
cpmm.sendSyncMessage("Test:Process:Sync");
};
// This must be a page that opens in the main process
let tab = gBrowser.addTab("about:robots");
let browser = tab.linkedBrowser;
let mm = browser.messageManager;
let ppmm = Cc["@mozilla.org/parentprocessmessagemanager;1"].
getService(Ci.nsIMessageBroadcaster);
yield new Promise(resolve => browser.addEventListener("load", resolve, true));
let messages = [];
let promise = new Promise(resolve => {
let listener = message => {
messages.push(message.name)
if (messages.length == 3)
resolve();
};
mm.addMessageListener("Test:Frame:Async", listener);
ppmm.addMessageListener("Test:Process:Async", listener);
ppmm.addMessageListener("Test:Process:Sync", listener);
});
mm.loadFrameScript("data:,(" + frame_script.toString() + ")();", false);
yield promise;
gBrowser.removeTab(tab);
is(messages[0], "Test:Frame:Async", "Expected async frame message");
is(messages[1], "Test:Process:Async", "Expected async process message");
is(messages[2], "Test:Process:Sync", "Expected sync process message");
});
add_task(function*() {
let frame_script = () => {
const { classes: Cc, interfaces: Ci } = Components;
let cpmm = Cc["@mozilla.org/childprocessmessagemanager;1"].
getService(Ci.nsISyncMessageSender);
cpmm.sendAsyncMessage("Test:Process:Async");
sendAsyncMessage("Test:Frame:Async");
sendSyncMessage("Test:Frame:Sync");
};
// This must be a page that opens in the main process
let tab = gBrowser.addTab("about:robots");
let browser = tab.linkedBrowser;
let mm = browser.messageManager;
let ppmm = Cc["@mozilla.org/parentprocessmessagemanager;1"].
getService(Ci.nsIMessageBroadcaster);
yield new Promise(resolve => browser.addEventListener("load", resolve, true));
let messages = [];
let promise = new Promise(resolve => {
let listener = message => {
messages.push(message.name)
if (messages.length == 3)
resolve();
};
ppmm.addMessageListener("Test:Process:Async", listener);
mm.addMessageListener("Test:Frame:Async", listener);
mm.addMessageListener("Test:Frame:Sync", listener);
});
mm.loadFrameScript("data:,(" + frame_script.toString() + ")();", false);
yield promise;
gBrowser.removeTab(tab);
is(messages[0], "Test:Process:Async", "Expected async process message");
is(messages[1], "Test:Frame:Async", "Expected async frame message");
is(messages[2], "Test:Frame:Sync", "Expected sync frame message");
});