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