Back to index

lightning-sunbird  0.9+nobinonly
nsWindowWatcher.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 2001
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef __nsWindowWatcher_h__
00039 #define __nsWindowWatcher_h__
00040 
00041 // {a21bfa01-f349-4394-a84c-8de5cf0737d0}
00042 #define NS_WINDOWWATCHER_CID \
00043  {0xa21bfa01, 0xf349, 0x4394, {0xa8, 0x4c, 0x8d, 0xe5, 0xcf, 0x7, 0x37, 0xd0}}
00044 
00045 #include "nsCOMPtr.h"
00046 #include "jspubtd.h"
00047 #include "nsIWindowCreator.h" // for stupid compilers
00048 #include "nsIWindowWatcher.h"
00049 #include "nsPIWindowWatcher.h"
00050 #include "nsVoidArray.h"
00051 
00052 class  nsIURI;
00053 class  nsIDocShellTreeItem;
00054 class  nsIDocShellTreeOwner;
00055 class  nsIWebBrowserChrome;
00056 class  nsString;
00057 class  nsWatcherWindowEnumerator;
00058 class  nsIScriptContext;
00059 struct JSContext;
00060 struct JSObject;
00061 struct nsWatcherWindowEntry;
00062 struct PRLock;
00063 struct SizeSpec;
00064 
00065 class nsWindowWatcher :
00066       public nsIWindowWatcher,
00067       public nsPIWindowWatcher
00068 {
00069 friend class nsWatcherWindowEnumerator;
00070 
00071 public:
00072   nsWindowWatcher();
00073   virtual ~nsWindowWatcher();
00074 
00075   nsresult Init();
00076 
00077   NS_DECL_ISUPPORTS
00078 
00079   NS_DECL_NSIWINDOWWATCHER
00080   NS_DECL_NSPIWINDOWWATCHER
00081 
00082 private:
00083   PRBool AddEnumerator(nsWatcherWindowEnumerator* inEnumerator);
00084   PRBool RemoveEnumerator(nsWatcherWindowEnumerator* inEnumerator);
00085 
00086   nsWatcherWindowEntry *FindWindowEntry(nsIDOMWindow *aWindow);
00087   nsresult RemoveWindow(nsWatcherWindowEntry *inInfo);
00088 
00089   // Get the caller tree item.  Look on the JS stack, then fall back
00090   // to the parent if there's nothing there.
00091   already_AddRefed<nsIDocShellTreeItem>
00092     GetCallerTreeItem(nsIDocShellTreeItem* aParentItem);
00093   
00094   // Unlike GetWindowByName this will look for a caller on the JS
00095   // stack, and then fall back on aCurrentWindow if it can't find one.
00096   nsresult SafeGetWindowByName(const nsAString& aName,
00097                                nsIDOMWindow* aCurrentWindow,
00098                                nsIDOMWindow** aResult);
00099 
00100   // Just like OpenWindowJS, but knows whether it got called via OpenWindowJS
00101   // (which means called from script) or called via OpenWindow.
00102   nsresult OpenWindowJSInternal(nsIDOMWindow *aParent,
00103                                 const char *aUrl,
00104                                 const char *aName,
00105                                 const char *aFeatures,
00106                                 PRBool aDialog,
00107                                 PRUint32 argc,
00108                                 jsval *argv,
00109                                 PRBool aCalledFromJS,
00110                                 nsIDOMWindow **_retval);
00111 
00112   static JSContext *GetJSContextFromWindow(nsIDOMWindow *aWindow);
00113   static JSContext *GetJSContextFromCallStack();
00114   static nsresult   URIfromURL(const char *aURL,
00115                                nsIDOMWindow *aParent,
00116                                nsIURI **aURI);
00117 #ifdef DEBUG
00118   static void       CheckWindowName(nsString& aName);
00119 #endif
00120   
00121   static PRUint32   CalculateChromeFlags(const char *aFeatures,
00122                                          PRBool aFeaturesSpecified,
00123                                          PRBool aDialog,
00124                                          PRBool aChromeURL,
00125                                          PRBool aHasChromeParent);
00126   static PRInt32    WinHasOption(const char *aOptions, const char *aName,
00127                                  PRInt32 aDefault, PRBool *aPresenceFlag);
00128   /* Compute the right SizeSpec based on aFeatures */
00129   static void       CalcSizeSpec(const char* aFeatures, SizeSpec& aResult);
00130   static nsresult   ReadyOpenedDocShellItem(nsIDocShellTreeItem *aOpenedItem,
00131                                             nsIDOMWindow *aParent,
00132                                             PRBool aWindowIsNew,
00133                                             nsIDOMWindow **aOpenedWindow);
00134   static void       SizeOpenedDocShellItem(nsIDocShellTreeItem *aDocShellItem,
00135                                            nsIDOMWindow *aParent,
00136                                            const SizeSpec & aSizeSpec);
00137   static nsresult   AttachArguments(nsIDOMWindow *aWindow,
00138                                     PRUint32 argc, jsval *argv);
00139   static nsresult   ConvertSupportsTojsvals(nsIDOMWindow *aWindow,
00140                                             nsISupports *aArgs,
00141                                             PRUint32 *aArgc, jsval **aArgv,
00142                                             JSContext **aUsedContext,
00143                                             void **aMarkp,
00144                                             nsIScriptContext **aScriptContext);
00145   static nsresult   AddSupportsTojsvals(nsISupports *aArg,
00146                                         JSContext *cx, jsval *aArgv);
00147   static nsresult   AddInterfaceTojsvals(nsISupports *aArg,
00148                                       JSContext *cx, jsval *aArgv);
00149   static void       GetWindowTreeItem(nsIDOMWindow *inWindow,
00150                                       nsIDocShellTreeItem **outTreeItem);
00151   static void       GetWindowTreeOwner(nsIDOMWindow *inWindow,
00152                                        nsIDocShellTreeOwner **outTreeOwner);
00153 
00154   nsVoidArray           mEnumeratorList;
00155   nsWatcherWindowEntry *mOldestWindow;
00156   nsIDOMWindow         *mActiveWindow;
00157   PRLock               *mListLock;
00158 
00159   nsCOMPtr<nsIWindowCreator> mWindowCreator;
00160 };
00161 
00162 #endif
00163