Back to index

lightning-sunbird  0.9+nobinonly
nsXPITriggerInfo.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 Communicator client code, released
00016  * March 31, 1998.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 1998-1999
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   Daniel Veditz <dveditz@netscape.com>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either of the GNU General Public License Version 2 or later (the "GPL"),
00028  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #ifndef nsXPITriggerInfo_h
00041 #define nsXPITriggerInfo_h
00042 
00043 #include "nsString.h"
00044 #include "nsVoidArray.h"
00045 #include "nsCOMPtr.h"
00046 #include "nsISupportsUtils.h"
00047 #include "nsIFileSpec.h"
00048 #include "nsILocalFile.h"
00049 #include "nsIOutputStream.h"
00050 #include "jsapi.h"
00051 #include "prthread.h"
00052 #include "plevent.h"
00053 #include "nsIXPConnect.h"
00054 #include "nsICryptoHash.h"
00055 #include "nsIPrincipal.h"
00056 
00057 typedef struct XPITriggerEvent {
00058     PLEvent     e;
00059     nsString    URL;
00060     PRInt32     status;
00061     JSContext*  cx;
00062     jsval       global;
00063     jsval       cbval;
00064     nsCOMPtr<nsISupports> ref;
00065     nsCOMPtr<nsIPrincipal> princ;
00066 } XPITriggerEvent;
00067 
00068 
00069 
00070 class nsXPITriggerItem
00071 {
00072   public:
00073     nsXPITriggerItem( const PRUnichar* name,
00074                       const PRUnichar* URL,
00075                       const PRUnichar* iconURL,
00076                       const char* hash = nsnull,
00077                       PRInt32 flags = 0);
00078     ~nsXPITriggerItem();
00079 
00080     nsString    mName;
00081     nsString    mURL;
00082     nsString    mIconURL;
00083     nsString    mArguments;
00084     nsString    mCertName;
00085 
00086     PRBool      mHashFound; // this flag indicates that we found _some_ hash info in the trigger
00087     nsCString   mHash;
00088     nsCOMPtr<nsICryptoHash> mHasher;
00089     PRInt32     mFlags;
00090 
00091     nsCOMPtr<nsILocalFile>      mFile;
00092     nsCOMPtr<nsIOutputStream>   mOutStream;
00093     nsCOMPtr<nsIPrincipal>      mPrincipal;
00094 
00095     void    SetPrincipal(nsIPrincipal* aPrincipal);
00096 
00097     PRBool  IsFileURL() { return StringBeginsWith(mURL, NS_LITERAL_STRING("file:/")); }
00098     PRBool  IsRelativeURL();
00099 
00100     const PRUnichar* GetSafeURLString();
00101 
00102   private:
00103     //-- prevent inadvertent copies and assignments
00104     nsXPITriggerItem& operator=(const nsXPITriggerItem& rhs);
00105     nsXPITriggerItem(const nsXPITriggerItem& rhs);
00106 
00107     nsString    mSafeURL;
00108 };
00109 
00110 
00111 
00112 class nsXPITriggerInfo
00113 {
00114   public:
00115     nsXPITriggerInfo();
00116     ~nsXPITriggerInfo();
00117 
00118     void                Add( nsXPITriggerItem *aItem ) 
00119                         { if ( aItem ) mItems.AppendElement( (void*)aItem ); }
00120 
00121     nsXPITriggerItem*   Get( PRUint32 aIndex )
00122                         { return (nsXPITriggerItem*)mItems.ElementAt(aIndex);}
00123 
00124     void                SaveCallback( JSContext *aCx, jsval aVal );
00125 
00126     PRUint32            Size() { return mItems.Count(); }
00127 
00128     void                SendStatus(const PRUnichar* URL, PRInt32 status);
00129 
00130     void                SetPrincipal(nsIPrincipal* aPrinc) { mPrincipal = aPrinc; }
00131 
00132 
00133   private:
00134     nsVoidArray mItems;
00135     JSContext   *mCx;
00136     nsCOMPtr<nsIXPConnectJSObjectHolder> mGlobalWrapper;
00137     jsval       mCbval;
00138     PRThread*   mThread;
00139 
00140     nsCOMPtr<nsIPrincipal>      mPrincipal;
00141 
00142     //-- prevent inadvertent copies and assignments
00143     nsXPITriggerInfo& operator=(const nsXPITriggerInfo& rhs);
00144     nsXPITriggerInfo(const nsXPITriggerInfo& rhs);
00145 };
00146 
00147 #endif /* nsXPITriggerInfo_h */