Bug 454558 Null check missing in nsGNOMEShellService::GetShouldCheckDefaultBrowser...
[wine-gecko.git] / embedding / browser / photon / src / EmbedDownload.cpp
blob77c83daebfca9962d425b4ff4c3ac438b092fd41
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Adrian Mardare <amardare@qnx.com>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #include "EmbedDownload.h"
41 EmbedDownload::EmbedDownload( PtMozillaWidget_t *aMoz, int aDownloadTicket, const char * aURL )
43 mMozillaWidget = aMoz;
44 mDownloadTicket = aDownloadTicket;
45 mURL = strdup( aURL );
46 mDone = PR_FALSE;
47 mLauncher = nsnull;
48 mPersist = nsnull;
50 /* insert d into aMoz->fDownload */
51 aMoz->fDownload = ( EmbedDownload ** ) realloc( aMoz->fDownload, ( aMoz->fDownloadCount + 1 ) * sizeof( EmbedDownload * ) );
52 if( aMoz->fDownload ) {
53 aMoz->fDownload[ aMoz->fDownloadCount ] = this;
54 aMoz->fDownloadCount++;
58 EmbedDownload::~EmbedDownload()
60 int i;
62 ///* ATENTIE */ printf( "EmbedDownload destructor this=%p\n", this );
64 /* remove d from the mMoz->fDownload */
65 for( i=0; i<mMozillaWidget->fDownloadCount; i++ ) {
66 if( mMozillaWidget->fDownload[i] == this ) break;
69 if( i<mMozillaWidget->fDownloadCount ) {
70 int j;
72 for( j=i; j<mMozillaWidget->fDownloadCount-1; j++ )
73 mMozillaWidget->fDownload[j] = mMozillaWidget->fDownload[j+1];
75 mMozillaWidget->fDownloadCount--;
76 if( !mMozillaWidget->fDownloadCount ) {
77 free( mMozillaWidget->fDownload );
78 mMozillaWidget->fDownload = NULL;
81 if( mDone == PR_FALSE ) ReportDownload( Pt_WEB_DOWNLOAD_CANCEL, 0, 0, "" );
84 ///* ATENTIE */ printf( "after remove fDownloadCount=%d\n", mMozillaWidget->fDownloadCount );
86 free( mURL );
89 EmbedDownload *FindDownload( PtMozillaWidget_t *moz, int download_ticket )
91 int i;
92 for( i=0; i<moz->fDownloadCount; i++ ) {
93 if( moz->fDownload[i]->mDownloadTicket == download_ticket ) return moz->fDownload[i];
95 return NULL;
99 void EmbedDownload::ReportDownload( int type, int current, int total, char *message )
101 PtCallbackInfo_t cbinfo;
102 PtWebDownloadCallback_t cb;
104 memset( &cbinfo, 0, sizeof( cbinfo ) );
105 cbinfo.reason = Pt_CB_MOZ_DOWNLOAD;
106 cbinfo.cbdata = &cb;
108 cb.download_ticket = mDownloadTicket;
109 cb.type = type;
110 cb.url = mURL;
111 cb.current = current;
112 cb.total = total;
113 cb.message = message;
115 if( type == Pt_WEB_DOWNLOAD_DONE ) mDone = PR_TRUE;
117 ///* ATENTIE */ printf( "In EmbedDownload::ReportDownload type=%s\n",
118 //type==Pt_WEB_DOWNLOAD_CANCEL? "Pt_WEB_DOWNLOAD_CANCEL":
119 //type==Pt_WEB_DOWNLOAD_DONE? "Pt_WEB_DOWNLOAD_DONE":
120 //type==Pt_WEB_DOWNLOAD_PROGRESS? "Pt_WEB_DOWNLOAD_PROGRESS":"unknown");
122 PtInvokeCallbackList( mMozillaWidget->web_download_cb, (PtWidget_t *)mMozillaWidget, &cbinfo );
126 /* nsIWebProgressListener interface */
127 NS_IMPL_ISUPPORTS2(EmbedDownload, nsIWebProgressListener, nsIWebProgressListener2)
129 NS_IMETHODIMP EmbedDownload::OnProgressChange(nsIWebProgress *aProgress, nsIRequest *aRequest, PRInt32 curSelfProgress, PRInt32 maxSelfProgress, PRInt32 curTotalProgress, PRInt32 maxTotalProgress) {
131 ///* ATENTIE */ printf("this=%p OnProgressChange curSelfProgress=%d maxSelfProgress=%d curTotalProgress=%d maxTotalProgress=%d\n",
132 //this, curSelfProgress, maxSelfProgress, curTotalProgress, maxTotalProgress );
134 ReportDownload( Pt_WEB_DOWNLOAD_PROGRESS, curSelfProgress, maxSelfProgress, "" );
136 return NS_OK;
139 NS_IMETHODIMP EmbedDownload::OnProgressChange64(nsIWebProgress *aProgress, nsIRequest *aRequest, PRInt64 curSelfProgress, PRInt64 maxSelfProgress, PRInt64 curTotalProgress, PRInt64 maxTotalProgress) {
140 // XXX truncates 64-bit to 32-bit
141 return OnProgressChange(aProgress, aRequest,
142 PRInt32(curSelfProgress), PRInt32(maxSelfProgress),
143 PRInt32(curTotalProgress), PRInt32(maxTotalProgress));
146 NS_IMETHODIMP EmbedDownload::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 aStateFlags, nsresult aStatus) {
147 if( aStateFlags & STATE_STOP ) {
148 ReportDownload( Pt_WEB_DOWNLOAD_DONE, 0, 0, "" );
150 return NS_OK;
153 NS_IMETHODIMP EmbedDownload::OnLocationChange(nsIWebProgress* aWebProgress, nsIRequest* aRequest, nsIURI *location) {
154 return NS_OK;
156 NS_IMETHODIMP EmbedDownload::OnStatusChange(nsIWebProgress* aWebProgress, nsIRequest* aRequest, nsresult aStatus, const PRUnichar* aMessage) {
157 return NS_OK;
159 NS_IMETHODIMP EmbedDownload::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 state) {
160 return NS_OK;
162 NS_IMETHODIMP EmbedDownload::OnRefreshAttempted(nsIWebProgress *aWebProgress, nsIURI *aUri, PRInt32 aDelay, PRBool aSameUri, PRBool *allowRefresh)
164 *allowRefresh = PR_TRUE;
165 return NS_OK;