Back to index

lightning-sunbird  0.9+nobinonly
UDownload.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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) 2002
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *  Conrad Carlen <ccarlen@netscape.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #ifndef UDownload_h__
00040 #define UDownload_h__
00041 #pragma once
00042 
00043 #include "nsIDownload.h"
00044 #include "nsIWebProgressListener.h"
00045 #include "nsIHelperAppLauncherDialog.h"
00046 #include "nsIExternalHelperAppService.h"
00047 
00048 #include "nsIURI.h"
00049 #include "nsILocalFile.h"
00050 #include "nsIWebBrowserPersist.h"
00051 
00052 class ADownloadProgressView;
00053 
00054 //*****************************************************************************
00055 // CDownload
00056 //
00057 // Holds information used to display a single download in the UI. This object is
00058 // created in one of two ways:
00059 // (1) By nsExternalHelperAppHandler when Gecko encounters a  MIME type which
00060 //     it doesn't itself handle. In this case, the notifications sent to
00061 //     nsIDownload are controlled by nsExternalHelperAppHandler.
00062 // (2) By the embedding app's file saving code when saving a web page or a link
00063 //     target. See CHeaderSniffer.cpp. In this case, the notifications sent to
00064 //     nsIDownload are controlled by the implementation of nsIWebBrowserPersist.
00065 //*****************************************************************************   
00066 
00067 class CDownload : public nsIDownload,
00068                   public nsIWebProgressListener,
00069                   public LBroadcaster
00070 {
00071 public:
00072     
00073     // Messages we broadcast to listeners.
00074     enum {
00075         msg_OnDLStart           = 57723,    // param is CDownload*
00076         msg_OnDLComplete,                   // param is CDownload*
00077         msg_OnDLProgressChange              // param is MsgOnDLProgressChangeInfo*
00078     };
00079        
00080     struct MsgOnDLProgressChangeInfo
00081     {
00082         MsgOnDLProgressChangeInfo(CDownload* broadcaster, PRInt32 curProgress, PRInt32 maxProgress) :
00083             mBroadcaster(broadcaster), mCurProgress(curProgress), mMaxProgress(maxProgress)
00084             { }
00085         
00086         CDownload *mBroadcaster;      
00087         PRInt32 mCurProgress, mMaxProgress;
00088     };
00089 
00090                             CDownload();
00091     virtual                 ~CDownload();
00092     
00093     NS_DECL_ISUPPORTS
00094     NS_DECL_NSIDOWNLOAD
00095     NS_DECL_NSIWEBPROGRESSLISTENER
00096     
00097     virtual void            Cancel();
00098     virtual void            GetStatus(nsresult& aStatus)
00099                             { aStatus = mStatus; }
00100 
00101 protected:
00102     void                    EnsureProgressView()
00103                             {
00104                                 if (!sProgressView)
00105                                     CreateProgressView();
00106                             }
00107     virtual void            CreateProgressView();
00108     // sProgressView is a singleton. This will only be called once.
00109     
00110 protected:
00111     nsCOMPtr<nsIURI>        mSource;
00112     nsCOMPtr<nsILocalFile>  mDestination;
00113     PRInt64                 mStartTime;
00114     PRInt32                 mPercentComplete;
00115     
00116     bool                    mGotFirstStateChange, mIsNetworkTransfer;
00117     bool                    mUserCanceled;
00118     nsresult                mStatus;
00119     
00120     nsCOMPtr<nsICancelable> mCancelable;
00121     
00122     static ADownloadProgressView *sProgressView;
00123 };
00124 
00125 //*****************************************************************************
00126 // CHelperAppLauncherDialog
00127 //
00128 // The implementation of nsIExternalHelperAppService in Gecko creates one of
00129 // these at the beginning of the download and calls its Show() method. Typically,
00130 // this will create a non-modal dialog in which the user can decide whether to
00131 // save the file to disk or open it with an application. This implementation
00132 // just saves the file to disk unconditionally. The user can decide what they
00133 // wish to do with the download from the progress dialog.
00134 //*****************************************************************************   
00135 
00136 class CHelperAppLauncherDialog : public nsIHelperAppLauncherDialog
00137 {
00138 public:
00139                             CHelperAppLauncherDialog();
00140     virtual                 ~CHelperAppLauncherDialog();
00141     
00142     NS_DECL_ISUPPORTS
00143     NS_DECL_NSIHELPERAPPLAUNCHERDIALOG
00144 
00145 protected:
00146 
00147 };
00148 
00149 
00150 //*****************************************************************************
00151 // ADownloadProgressView
00152 //
00153 // An abstract class which handles the display and interaction with a download.
00154 // Typically, it presents a progress dialog.
00155 //*****************************************************************************
00156 
00157 class ADownloadProgressView
00158 {
00159     friend class CDownload;
00160     
00161     virtual void AddDownloadItem(CDownload *aDownloadItem) = 0;
00162     // A download is beginning. Initialize the UI for this download.
00163     // Throughout the download process, the CDownload will broadcast
00164     // status messages. The UI needs to call LBroadcaster::AddListener()
00165     // on the CDownload at this point in order to get the messages.
00166     
00167 };
00168 
00169 
00170 #endif // UDownload_h__