Bug 990812 - Add nsIDOMChromeWindow.getGroupMessageManager() API r=smaug

This commit is contained in:
Tim Taubert 2014-05-23 14:51:56 +02:00
parent ab4d658e1d
commit a1ba283cde
4 changed files with 74 additions and 2 deletions

View File

@ -13115,6 +13115,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsGlobalChromeWindow,
nsGlobalWindow) nsGlobalWindow)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mBrowserDOMWindow) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mBrowserDOMWindow)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMessageManager) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMessageManager)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGroupMessageManagers)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
@ -13126,6 +13127,10 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsGlobalChromeWindow,
tmp->mMessageManager.get())->Disconnect(); tmp->mMessageManager.get())->Disconnect();
NS_IMPL_CYCLE_COLLECTION_UNLINK(mMessageManager) NS_IMPL_CYCLE_COLLECTION_UNLINK(mMessageManager)
} }
tmp->mGroupMessageManagers.EnumerateRead(DisconnectGroupMessageManager, nullptr);
tmp->mGroupMessageManagers.Clear();
NS_IMPL_CYCLE_COLLECTION_UNLINK(mGroupMessageManagers)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END NS_IMPL_CYCLE_COLLECTION_UNLINK_END
DOMCI_DATA(ChromeWindow, nsGlobalChromeWindow) DOMCI_DATA(ChromeWindow, nsGlobalChromeWindow)
@ -13494,6 +13499,39 @@ nsGlobalWindow::GetMessageManager(ErrorResult& aError)
return myself->mMessageManager; return myself->mMessageManager;
} }
NS_IMETHODIMP
nsGlobalChromeWindow::GetGroupMessageManager(const nsAString& aGroup,
nsIMessageBroadcaster** aManager)
{
ErrorResult rv;
NS_IF_ADDREF(*aManager = GetGroupMessageManager(aGroup, rv));
return rv.ErrorCode();
}
nsIMessageBroadcaster*
nsGlobalWindow::GetGroupMessageManager(const nsAString& aGroup,
ErrorResult& aError)
{
FORWARD_TO_INNER_OR_THROW(GetGroupMessageManager, (aGroup, aError), aError, nullptr);
MOZ_ASSERT(IsChromeWindow());
nsGlobalChromeWindow* myself = static_cast<nsGlobalChromeWindow*>(this);
nsCOMPtr<nsIMessageBroadcaster> messageManager =
myself->mGroupMessageManagers.Get(aGroup);
if (!messageManager) {
nsFrameMessageManager* parent =
static_cast<nsFrameMessageManager*>(GetMessageManager(aError));
messageManager = new nsFrameMessageManager(nullptr,
parent,
MM_CHROME | MM_BROADCASTER);
myself->mGroupMessageManagers.Put(aGroup, messageManager);
}
return messageManager;
}
// nsGlobalModalWindow implementation // nsGlobalModalWindow implementation
// QueryInterface implementation for nsGlobalModalWindow // QueryInterface implementation for nsGlobalModalWindow

View File

@ -12,6 +12,7 @@
#include "nsTHashtable.h" #include "nsTHashtable.h"
#include "nsHashKeys.h" #include "nsHashKeys.h"
#include "nsRefPtrHashtable.h" #include "nsRefPtrHashtable.h"
#include "nsInterfaceHashtable.h"
// Local Includes // Local Includes
// Helper Classes // Helper Classes
@ -1006,6 +1007,8 @@ public:
void NotifyDefaultButtonLoaded(mozilla::dom::Element& aDefaultButton, void NotifyDefaultButtonLoaded(mozilla::dom::Element& aDefaultButton,
mozilla::ErrorResult& aError); mozilla::ErrorResult& aError);
nsIMessageBroadcaster* GetMessageManager(mozilla::ErrorResult& aError); nsIMessageBroadcaster* GetMessageManager(mozilla::ErrorResult& aError);
nsIMessageBroadcaster* GetGroupMessageManager(const nsAString& aGroup,
mozilla::ErrorResult& aError);
void BeginWindowMove(mozilla::dom::Event& aMouseDownEvent, void BeginWindowMove(mozilla::dom::Event& aMouseDownEvent,
mozilla::dom::Element* aPanel, mozilla::dom::Element* aPanel,
mozilla::ErrorResult& aError); mozilla::ErrorResult& aError);
@ -1621,16 +1624,32 @@ public:
NS_DECL_NSIDOMCHROMEWINDOW NS_DECL_NSIDOMCHROMEWINDOW
nsGlobalChromeWindow(nsGlobalWindow *aOuterWindow) nsGlobalChromeWindow(nsGlobalWindow *aOuterWindow)
: nsGlobalWindow(aOuterWindow) : nsGlobalWindow(aOuterWindow),
mGroupMessageManagers(1)
{ {
mIsChrome = true; mIsChrome = true;
mCleanMessageManager = true; mCleanMessageManager = true;
} }
static PLDHashOperator
DisconnectGroupMessageManager(const nsAString& aKey,
nsIMessageBroadcaster* aMM,
void* aUserArg)
{
if (aMM) {
static_cast<nsFrameMessageManager*>(aMM)->Disconnect();
}
return PL_DHASH_NEXT;
}
~nsGlobalChromeWindow() ~nsGlobalChromeWindow()
{ {
NS_ABORT_IF_FALSE(mCleanMessageManager, NS_ABORT_IF_FALSE(mCleanMessageManager,
"chrome windows may always disconnect the msg manager"); "chrome windows may always disconnect the msg manager");
mGroupMessageManagers.EnumerateRead(DisconnectGroupMessageManager, nullptr);
mGroupMessageManagers.Clear();
if (mMessageManager) { if (mMessageManager) {
static_cast<nsFrameMessageManager *>( static_cast<nsFrameMessageManager *>(
mMessageManager.get())->Disconnect(); mMessageManager.get())->Disconnect();
@ -1652,10 +1671,12 @@ public:
using nsGlobalWindow::Restore; using nsGlobalWindow::Restore;
using nsGlobalWindow::NotifyDefaultButtonLoaded; using nsGlobalWindow::NotifyDefaultButtonLoaded;
using nsGlobalWindow::GetMessageManager; using nsGlobalWindow::GetMessageManager;
using nsGlobalWindow::GetGroupMessageManager;
using nsGlobalWindow::BeginWindowMove; using nsGlobalWindow::BeginWindowMove;
nsCOMPtr<nsIBrowserDOMWindow> mBrowserDOMWindow; nsCOMPtr<nsIBrowserDOMWindow> mBrowserDOMWindow;
nsCOMPtr<nsIMessageBroadcaster> mMessageManager; nsCOMPtr<nsIMessageBroadcaster> mMessageManager;
nsInterfaceHashtable<nsStringHashKey, nsIMessageBroadcaster> mGroupMessageManagers;
}; };
/* /*

View File

@ -10,7 +10,7 @@ interface nsIDOMElement;
interface nsIDOMEvent; interface nsIDOMEvent;
interface nsIMessageBroadcaster; interface nsIMessageBroadcaster;
[scriptable, uuid(0c10226f-8abb-4345-aa6b-2780a6f4687e)] [scriptable, uuid(78bdcb41-1efa-409f-aaba-70842213f80f)]
interface nsIDOMChromeWindow : nsISupports interface nsIDOMChromeWindow : nsISupports
{ {
const unsigned short STATE_MAXIMIZED = 1; const unsigned short STATE_MAXIMIZED = 1;
@ -45,6 +45,12 @@ interface nsIDOMChromeWindow : nsISupports
readonly attribute nsIMessageBroadcaster messageManager; readonly attribute nsIMessageBroadcaster messageManager;
/**
* Returns the message manager identified by the given group name that
* manages all frame loaders belonging to that group.
*/
nsIMessageBroadcaster getGroupMessageManager(in AString group);
/** /**
* On some operating systems, we must allow the window manager to * On some operating systems, we must allow the window manager to
* handle window dragging. This function tells the window manager to * handle window dragging. This function tells the window manager to

View File

@ -433,6 +433,13 @@ interface ChromeWindow {
[Throws, Func="nsGlobalWindow::IsChromeWindow"] [Throws, Func="nsGlobalWindow::IsChromeWindow"]
readonly attribute nsIMessageBroadcaster messageManager; readonly attribute nsIMessageBroadcaster messageManager;
/**
* Returns the message manager identified by the given group name that
* manages all frame loaders belonging to that group.
*/
[Throws, Func="nsGlobalWindow::IsChromeWindow"]
nsIMessageBroadcaster getGroupMessageManager(DOMString aGroup);
/** /**
* On some operating systems, we must allow the window manager to * On some operating systems, we must allow the window manager to
* handle window dragging. This function tells the window manager to * handle window dragging. This function tells the window manager to