michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef __nsWindowWatcher_h__ michael@0: #define __nsWindowWatcher_h__ michael@0: michael@0: // {a21bfa01-f349-4394-a84c-8de5cf0737d0} michael@0: #define NS_WINDOWWATCHER_CID \ michael@0: {0xa21bfa01, 0xf349, 0x4394, {0xa8, 0x4c, 0x8d, 0xe5, 0xcf, 0x7, 0x37, 0xd0}} michael@0: michael@0: #include "nsCOMPtr.h" michael@0: #include "mozilla/Mutex.h" michael@0: #include "nsIWindowCreator.h" // for stupid compilers michael@0: #include "nsIWindowWatcher.h" michael@0: #include "nsIPromptFactory.h" michael@0: #include "nsPIWindowWatcher.h" michael@0: #include "nsTArray.h" michael@0: #include "js/TypeDecls.h" michael@0: michael@0: class nsIURI; michael@0: class nsIDocShellTreeItem; michael@0: class nsIDocShellTreeOwner; michael@0: class nsIWebBrowserChrome; michael@0: class nsString; michael@0: class nsWatcherWindowEnumerator; michael@0: class nsIScriptContext; michael@0: class nsPromptService; michael@0: struct nsWatcherWindowEntry; michael@0: struct SizeSpec; michael@0: michael@0: class nsWindowWatcher : michael@0: public nsIWindowWatcher, michael@0: public nsPIWindowWatcher, michael@0: public nsIPromptFactory michael@0: { michael@0: friend class nsWatcherWindowEnumerator; michael@0: michael@0: public: michael@0: nsWindowWatcher(); michael@0: virtual ~nsWindowWatcher(); michael@0: michael@0: nsresult Init(); michael@0: michael@0: NS_DECL_ISUPPORTS michael@0: michael@0: NS_DECL_NSIWINDOWWATCHER michael@0: NS_DECL_NSPIWINDOWWATCHER michael@0: NS_DECL_NSIPROMPTFACTORY michael@0: michael@0: protected: michael@0: friend class nsPromptService; michael@0: bool AddEnumerator(nsWatcherWindowEnumerator* inEnumerator); michael@0: bool RemoveEnumerator(nsWatcherWindowEnumerator* inEnumerator); michael@0: michael@0: nsWatcherWindowEntry *FindWindowEntry(nsIDOMWindow *aWindow); michael@0: nsresult RemoveWindow(nsWatcherWindowEntry *inInfo); michael@0: michael@0: // Get the caller tree item. Look on the JS stack, then fall back michael@0: // to the parent if there's nothing there. michael@0: already_AddRefed michael@0: GetCallerTreeItem(nsIDocShellTreeItem* aParentItem); michael@0: michael@0: // Unlike GetWindowByName this will look for a caller on the JS michael@0: // stack, and then fall back on aCurrentWindow if it can't find one. michael@0: already_AddRefed michael@0: SafeGetWindowByName(const nsAString& aName, nsIDOMWindow* aCurrentWindow); michael@0: michael@0: // Just like OpenWindowJS, but knows whether it got called via OpenWindowJS michael@0: // (which means called from script) or called via OpenWindow. michael@0: nsresult OpenWindowInternal(nsIDOMWindow *aParent, michael@0: const char *aUrl, michael@0: const char *aName, michael@0: const char *aFeatures, michael@0: bool aCalledFromJS, michael@0: bool aDialog, michael@0: bool aNavigate, michael@0: nsIArray *argv, michael@0: nsIDOMWindow **_retval); michael@0: michael@0: static JSContext *GetJSContextFromWindow(nsIDOMWindow *aWindow); michael@0: static nsresult URIfromURL(const char *aURL, michael@0: nsIDOMWindow *aParent, michael@0: nsIURI **aURI); michael@0: michael@0: static uint32_t CalculateChromeFlags(nsIDOMWindow *aParent, michael@0: const char *aFeatures, michael@0: bool aFeaturesSpecified, michael@0: bool aDialog, michael@0: bool aChromeURL, michael@0: bool aHasChromeParent); michael@0: static int32_t WinHasOption(const char *aOptions, const char *aName, michael@0: int32_t aDefault, bool *aPresenceFlag); michael@0: /* Compute the right SizeSpec based on aFeatures */ michael@0: static void CalcSizeSpec(const char* aFeatures, SizeSpec& aResult); michael@0: static nsresult ReadyOpenedDocShellItem(nsIDocShellTreeItem *aOpenedItem, michael@0: nsIDOMWindow *aParent, michael@0: bool aWindowIsNew, michael@0: nsIDOMWindow **aOpenedWindow); michael@0: static void SizeOpenedDocShellItem(nsIDocShellTreeItem *aDocShellItem, michael@0: nsIDOMWindow *aParent, michael@0: const SizeSpec & aSizeSpec); michael@0: static void GetWindowTreeItem(nsIDOMWindow *inWindow, michael@0: nsIDocShellTreeItem **outTreeItem); michael@0: static void GetWindowTreeOwner(nsIDOMWindow *inWindow, michael@0: nsIDocShellTreeOwner **outTreeOwner); michael@0: michael@0: nsTArray mEnumeratorList; michael@0: nsWatcherWindowEntry *mOldestWindow; michael@0: mozilla::Mutex mListLock; michael@0: michael@0: nsCOMPtr mWindowCreator; michael@0: }; michael@0: michael@0: #endif michael@0: