Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef __nsWindowWatcher_h__ |
michael@0 | 7 | #define __nsWindowWatcher_h__ |
michael@0 | 8 | |
michael@0 | 9 | // {a21bfa01-f349-4394-a84c-8de5cf0737d0} |
michael@0 | 10 | #define NS_WINDOWWATCHER_CID \ |
michael@0 | 11 | {0xa21bfa01, 0xf349, 0x4394, {0xa8, 0x4c, 0x8d, 0xe5, 0xcf, 0x7, 0x37, 0xd0}} |
michael@0 | 12 | |
michael@0 | 13 | #include "nsCOMPtr.h" |
michael@0 | 14 | #include "mozilla/Mutex.h" |
michael@0 | 15 | #include "nsIWindowCreator.h" // for stupid compilers |
michael@0 | 16 | #include "nsIWindowWatcher.h" |
michael@0 | 17 | #include "nsIPromptFactory.h" |
michael@0 | 18 | #include "nsPIWindowWatcher.h" |
michael@0 | 19 | #include "nsTArray.h" |
michael@0 | 20 | #include "js/TypeDecls.h" |
michael@0 | 21 | |
michael@0 | 22 | class nsIURI; |
michael@0 | 23 | class nsIDocShellTreeItem; |
michael@0 | 24 | class nsIDocShellTreeOwner; |
michael@0 | 25 | class nsIWebBrowserChrome; |
michael@0 | 26 | class nsString; |
michael@0 | 27 | class nsWatcherWindowEnumerator; |
michael@0 | 28 | class nsIScriptContext; |
michael@0 | 29 | class nsPromptService; |
michael@0 | 30 | struct nsWatcherWindowEntry; |
michael@0 | 31 | struct SizeSpec; |
michael@0 | 32 | |
michael@0 | 33 | class nsWindowWatcher : |
michael@0 | 34 | public nsIWindowWatcher, |
michael@0 | 35 | public nsPIWindowWatcher, |
michael@0 | 36 | public nsIPromptFactory |
michael@0 | 37 | { |
michael@0 | 38 | friend class nsWatcherWindowEnumerator; |
michael@0 | 39 | |
michael@0 | 40 | public: |
michael@0 | 41 | nsWindowWatcher(); |
michael@0 | 42 | virtual ~nsWindowWatcher(); |
michael@0 | 43 | |
michael@0 | 44 | nsresult Init(); |
michael@0 | 45 | |
michael@0 | 46 | NS_DECL_ISUPPORTS |
michael@0 | 47 | |
michael@0 | 48 | NS_DECL_NSIWINDOWWATCHER |
michael@0 | 49 | NS_DECL_NSPIWINDOWWATCHER |
michael@0 | 50 | NS_DECL_NSIPROMPTFACTORY |
michael@0 | 51 | |
michael@0 | 52 | protected: |
michael@0 | 53 | friend class nsPromptService; |
michael@0 | 54 | bool AddEnumerator(nsWatcherWindowEnumerator* inEnumerator); |
michael@0 | 55 | bool RemoveEnumerator(nsWatcherWindowEnumerator* inEnumerator); |
michael@0 | 56 | |
michael@0 | 57 | nsWatcherWindowEntry *FindWindowEntry(nsIDOMWindow *aWindow); |
michael@0 | 58 | nsresult RemoveWindow(nsWatcherWindowEntry *inInfo); |
michael@0 | 59 | |
michael@0 | 60 | // Get the caller tree item. Look on the JS stack, then fall back |
michael@0 | 61 | // to the parent if there's nothing there. |
michael@0 | 62 | already_AddRefed<nsIDocShellTreeItem> |
michael@0 | 63 | GetCallerTreeItem(nsIDocShellTreeItem* aParentItem); |
michael@0 | 64 | |
michael@0 | 65 | // Unlike GetWindowByName this will look for a caller on the JS |
michael@0 | 66 | // stack, and then fall back on aCurrentWindow if it can't find one. |
michael@0 | 67 | already_AddRefed<nsIDOMWindow> |
michael@0 | 68 | SafeGetWindowByName(const nsAString& aName, nsIDOMWindow* aCurrentWindow); |
michael@0 | 69 | |
michael@0 | 70 | // Just like OpenWindowJS, but knows whether it got called via OpenWindowJS |
michael@0 | 71 | // (which means called from script) or called via OpenWindow. |
michael@0 | 72 | nsresult OpenWindowInternal(nsIDOMWindow *aParent, |
michael@0 | 73 | const char *aUrl, |
michael@0 | 74 | const char *aName, |
michael@0 | 75 | const char *aFeatures, |
michael@0 | 76 | bool aCalledFromJS, |
michael@0 | 77 | bool aDialog, |
michael@0 | 78 | bool aNavigate, |
michael@0 | 79 | nsIArray *argv, |
michael@0 | 80 | nsIDOMWindow **_retval); |
michael@0 | 81 | |
michael@0 | 82 | static JSContext *GetJSContextFromWindow(nsIDOMWindow *aWindow); |
michael@0 | 83 | static nsresult URIfromURL(const char *aURL, |
michael@0 | 84 | nsIDOMWindow *aParent, |
michael@0 | 85 | nsIURI **aURI); |
michael@0 | 86 | |
michael@0 | 87 | static uint32_t CalculateChromeFlags(nsIDOMWindow *aParent, |
michael@0 | 88 | const char *aFeatures, |
michael@0 | 89 | bool aFeaturesSpecified, |
michael@0 | 90 | bool aDialog, |
michael@0 | 91 | bool aChromeURL, |
michael@0 | 92 | bool aHasChromeParent); |
michael@0 | 93 | static int32_t WinHasOption(const char *aOptions, const char *aName, |
michael@0 | 94 | int32_t aDefault, bool *aPresenceFlag); |
michael@0 | 95 | /* Compute the right SizeSpec based on aFeatures */ |
michael@0 | 96 | static void CalcSizeSpec(const char* aFeatures, SizeSpec& aResult); |
michael@0 | 97 | static nsresult ReadyOpenedDocShellItem(nsIDocShellTreeItem *aOpenedItem, |
michael@0 | 98 | nsIDOMWindow *aParent, |
michael@0 | 99 | bool aWindowIsNew, |
michael@0 | 100 | nsIDOMWindow **aOpenedWindow); |
michael@0 | 101 | static void SizeOpenedDocShellItem(nsIDocShellTreeItem *aDocShellItem, |
michael@0 | 102 | nsIDOMWindow *aParent, |
michael@0 | 103 | const SizeSpec & aSizeSpec); |
michael@0 | 104 | static void GetWindowTreeItem(nsIDOMWindow *inWindow, |
michael@0 | 105 | nsIDocShellTreeItem **outTreeItem); |
michael@0 | 106 | static void GetWindowTreeOwner(nsIDOMWindow *inWindow, |
michael@0 | 107 | nsIDocShellTreeOwner **outTreeOwner); |
michael@0 | 108 | |
michael@0 | 109 | nsTArray<nsWatcherWindowEnumerator*> mEnumeratorList; |
michael@0 | 110 | nsWatcherWindowEntry *mOldestWindow; |
michael@0 | 111 | mozilla::Mutex mListLock; |
michael@0 | 112 | |
michael@0 | 113 | nsCOMPtr<nsIWindowCreator> mWindowCreator; |
michael@0 | 114 | }; |
michael@0 | 115 | |
michael@0 | 116 | #endif |
michael@0 | 117 |