1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/embedding/components/windowwatcher/src/nsWindowWatcher.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,117 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef __nsWindowWatcher_h__ 1.10 +#define __nsWindowWatcher_h__ 1.11 + 1.12 +// {a21bfa01-f349-4394-a84c-8de5cf0737d0} 1.13 +#define NS_WINDOWWATCHER_CID \ 1.14 + {0xa21bfa01, 0xf349, 0x4394, {0xa8, 0x4c, 0x8d, 0xe5, 0xcf, 0x7, 0x37, 0xd0}} 1.15 + 1.16 +#include "nsCOMPtr.h" 1.17 +#include "mozilla/Mutex.h" 1.18 +#include "nsIWindowCreator.h" // for stupid compilers 1.19 +#include "nsIWindowWatcher.h" 1.20 +#include "nsIPromptFactory.h" 1.21 +#include "nsPIWindowWatcher.h" 1.22 +#include "nsTArray.h" 1.23 +#include "js/TypeDecls.h" 1.24 + 1.25 +class nsIURI; 1.26 +class nsIDocShellTreeItem; 1.27 +class nsIDocShellTreeOwner; 1.28 +class nsIWebBrowserChrome; 1.29 +class nsString; 1.30 +class nsWatcherWindowEnumerator; 1.31 +class nsIScriptContext; 1.32 +class nsPromptService; 1.33 +struct nsWatcherWindowEntry; 1.34 +struct SizeSpec; 1.35 + 1.36 +class nsWindowWatcher : 1.37 + public nsIWindowWatcher, 1.38 + public nsPIWindowWatcher, 1.39 + public nsIPromptFactory 1.40 +{ 1.41 +friend class nsWatcherWindowEnumerator; 1.42 + 1.43 +public: 1.44 + nsWindowWatcher(); 1.45 + virtual ~nsWindowWatcher(); 1.46 + 1.47 + nsresult Init(); 1.48 + 1.49 + NS_DECL_ISUPPORTS 1.50 + 1.51 + NS_DECL_NSIWINDOWWATCHER 1.52 + NS_DECL_NSPIWINDOWWATCHER 1.53 + NS_DECL_NSIPROMPTFACTORY 1.54 + 1.55 +protected: 1.56 + friend class nsPromptService; 1.57 + bool AddEnumerator(nsWatcherWindowEnumerator* inEnumerator); 1.58 + bool RemoveEnumerator(nsWatcherWindowEnumerator* inEnumerator); 1.59 + 1.60 + nsWatcherWindowEntry *FindWindowEntry(nsIDOMWindow *aWindow); 1.61 + nsresult RemoveWindow(nsWatcherWindowEntry *inInfo); 1.62 + 1.63 + // Get the caller tree item. Look on the JS stack, then fall back 1.64 + // to the parent if there's nothing there. 1.65 + already_AddRefed<nsIDocShellTreeItem> 1.66 + GetCallerTreeItem(nsIDocShellTreeItem* aParentItem); 1.67 + 1.68 + // Unlike GetWindowByName this will look for a caller on the JS 1.69 + // stack, and then fall back on aCurrentWindow if it can't find one. 1.70 + already_AddRefed<nsIDOMWindow> 1.71 + SafeGetWindowByName(const nsAString& aName, nsIDOMWindow* aCurrentWindow); 1.72 + 1.73 + // Just like OpenWindowJS, but knows whether it got called via OpenWindowJS 1.74 + // (which means called from script) or called via OpenWindow. 1.75 + nsresult OpenWindowInternal(nsIDOMWindow *aParent, 1.76 + const char *aUrl, 1.77 + const char *aName, 1.78 + const char *aFeatures, 1.79 + bool aCalledFromJS, 1.80 + bool aDialog, 1.81 + bool aNavigate, 1.82 + nsIArray *argv, 1.83 + nsIDOMWindow **_retval); 1.84 + 1.85 + static JSContext *GetJSContextFromWindow(nsIDOMWindow *aWindow); 1.86 + static nsresult URIfromURL(const char *aURL, 1.87 + nsIDOMWindow *aParent, 1.88 + nsIURI **aURI); 1.89 + 1.90 + static uint32_t CalculateChromeFlags(nsIDOMWindow *aParent, 1.91 + const char *aFeatures, 1.92 + bool aFeaturesSpecified, 1.93 + bool aDialog, 1.94 + bool aChromeURL, 1.95 + bool aHasChromeParent); 1.96 + static int32_t WinHasOption(const char *aOptions, const char *aName, 1.97 + int32_t aDefault, bool *aPresenceFlag); 1.98 + /* Compute the right SizeSpec based on aFeatures */ 1.99 + static void CalcSizeSpec(const char* aFeatures, SizeSpec& aResult); 1.100 + static nsresult ReadyOpenedDocShellItem(nsIDocShellTreeItem *aOpenedItem, 1.101 + nsIDOMWindow *aParent, 1.102 + bool aWindowIsNew, 1.103 + nsIDOMWindow **aOpenedWindow); 1.104 + static void SizeOpenedDocShellItem(nsIDocShellTreeItem *aDocShellItem, 1.105 + nsIDOMWindow *aParent, 1.106 + const SizeSpec & aSizeSpec); 1.107 + static void GetWindowTreeItem(nsIDOMWindow *inWindow, 1.108 + nsIDocShellTreeItem **outTreeItem); 1.109 + static void GetWindowTreeOwner(nsIDOMWindow *inWindow, 1.110 + nsIDocShellTreeOwner **outTreeOwner); 1.111 + 1.112 + nsTArray<nsWatcherWindowEnumerator*> mEnumeratorList; 1.113 + nsWatcherWindowEntry *mOldestWindow; 1.114 + mozilla::Mutex mListLock; 1.115 + 1.116 + nsCOMPtr<nsIWindowCreator> mWindowCreator; 1.117 +}; 1.118 + 1.119 +#endif 1.120 +