1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
14 * The Original Code is mozilla.org code.
16 * The Initial Developer of the Original Code is
17 * Christopher Blizzard.
18 * Portions created by the Initial Developer are Copyright (C) 2001
19 * the Initial Developer. All Rights Reserved.
22 * Christopher Blizzard <blizzard@mozilla.org>
23 * Brian Edmond <briane@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 "EmbedProgress.h"
41 #include <nsXPIDLString.h>
42 #include <nsIChannel.h>
44 #include <nsCWebBrowser.h>
45 #include <nsIComponentManager.h>
46 #include <nsIDocShellTreeItem.h>
47 #include "nsIWidget.h"
50 #include "nsReadableUtils.h"
51 #include <nsILocalFile.h>
52 #include <nsIRequestObserver.h>
53 #include <nsISocketTransportService.h>
55 #include "nsGfxCIID.h"
57 #include "nsIDOMWindow.h"
59 #include "EmbedWindow.h"
60 #include "EmbedPrivate.h"
63 #include "PtMozilla.h"
65 EmbedProgress::EmbedProgress(void)
69 mSkipOnState
= mDownloadDocument
= 0;
72 EmbedProgress::~EmbedProgress()
76 NS_IMPL_ISUPPORTS2(EmbedProgress
,
77 nsIWebProgressListener
,
78 nsISupportsWeakReference
)
81 EmbedProgress::Init(EmbedPrivate
*aOwner
)
88 EmbedProgress::OnStateChange(nsIWebProgress
*aWebProgress
,
93 PtMozillaWidget_t
*moz
= (PtMozillaWidget_t
*) mOwner
->mOwningWidget
;
94 PtCallbackList_t
*cb
= NULL
;
95 PtCallbackInfo_t cbinfo
;
96 PtMozillaNetStateCb_t state
;
98 // get the uri for this request
99 nsXPIDLCString uriString
;
100 RequestToURIString(aRequest
, getter_Copies(uriString
));
102 tmpString
.AssignWithConversion(uriString
);
104 if( ( aStateFlags
& STATE_IS_REQUEST
) && NS_FAILED( aStatus
) )
106 PtWebErrorCallback_t cbw
;
108 /* invoke the Pt_CB_WEB_ERROR in the client */
109 cb
= moz
->web_error_cb
;
110 memset(&cbinfo
, 0, sizeof(cbinfo
));
111 cbinfo
.reason
= Pt_CB_MOZ_ERROR
;
112 cbinfo
.cbdata
= &cbw
;
114 memset( &cbw
, 0, sizeof( PtWebErrorCallback_t
) );
115 cbw
.url
= (char*)((const char *)uriString
);
116 cbw
.description
= "";
118 cbw
.type
= Pt_WEB_ERROR_TOPVIEW
;
121 case NS_ERROR_UNKNOWN_HOST
:
124 case NS_ERROR_NET_TIMEOUT
:
127 case NS_ERROR_NO_CONTENT
:
130 case NS_ERROR_FILE_NOT_FOUND
:
133 case NS_ERROR_CONNECTION_REFUSED
:
140 if( cbw
.reason
!= -1)
141 PtInvokeCallbackList(cb
, (PtWidget_t
*)moz
, &cbinfo
);
142 /* let it check for STATE_STOP */
145 memset(&cbinfo
, 0, sizeof(cbinfo
));
147 if( aStateFlags
& STATE_IS_NETWORK
/* STATE_IS_REQUEST STATE_IS_DOCUMENT */ )
149 if( aStateFlags
& STATE_START
)
151 cbinfo
.reason
= Pt_CB_MOZ_START
;
152 if( ( cb
= moz
->start_cb
) )
153 PtInvokeCallbackList(cb
, (PtWidget_t
*) moz
, &cbinfo
);
155 else if( aStateFlags
& STATE_STOP
)
157 PtWebCompleteCallback_t cbcomplete
;
159 cbinfo
.reason
= Pt_CB_MOZ_COMPLETE
;
160 cbinfo
.cbdata
= &cbcomplete
;
161 memset( &cbcomplete
, 0, sizeof( PtWebCompleteCallback_t
) );
162 cbcomplete
.url
= strdup( uriString
);
164 if( ( cb
= moz
->complete_cb
) )
165 PtInvokeCallbackList(cb
, (PtWidget_t
*) moz
, &cbinfo
);
167 free( cbcomplete
.url
);
169 if( moz
->text_zoom
!= moz
->actual_text_zoom
) {
170 nsCOMPtr
<nsIDOMWindow
> domWindow
;
171 moz
->EmbedRef
->mWindow
->mWebBrowser
->GetContentDOMWindow(getter_AddRefs(domWindow
));
173 domWindow
->SetTextZoom( moz
->text_zoom
/100. );
175 domWindow
->GetTextZoom( &vv
);
176 moz
->actual_text_zoom
= (int) ( vv
* 100 );
182 // invoke the raw status callbacks for page load status
183 cbinfo
.reason
= Pt_CB_MOZ_NET_STATE
;
184 cbinfo
.cbdata
= &state
;
185 state
.flags
= aStateFlags
;
186 state
.status
= aStatus
;
187 //state.url = (const char *)uriString;
189 char *statusMessage
= "";
190 PRInt32 flags
= aStateFlags
;
192 if (flags
& STATE_IS_REQUEST
)
194 if (flags
& STATE_REDIRECTING
)
195 statusMessage
= "Redirecting to site:";
196 else if (flags
& STATE_TRANSFERRING
)
197 statusMessage
= "Receiving Data:";
198 else if (flags
& STATE_NEGOTIATING
)
199 statusMessage
= "Waiting for authorization:";
202 if (flags
& STATE_IS_DOCUMENT
)
204 if (flags
& STATE_START
)
205 statusMessage
= "Loading site:";
206 else if (flags
& STATE_STOP
)
207 statusMessage
= "Finishing:";
209 state
.message
= statusMessage
;
210 if( ( cb
= moz
->net_state_cb
) && statusMessage
[0])
211 PtInvokeCallbackList(cb
, (PtWidget_t
*) moz
, &cbinfo
);
216 EmbedProgress::OnProgressChange(nsIWebProgress
*aWebProgress
,
217 nsIRequest
*aRequest
,
218 PRInt32 aCurSelfProgress
,
219 PRInt32 aMaxSelfProgress
,
220 PRInt32 aCurTotalProgress
,
221 PRInt32 aMaxTotalProgress
)
223 PtMozillaWidget_t
*moz
= (PtMozillaWidget_t
*) mOwner
->mOwningWidget
;
224 PtCallbackList_t
*cb
;
225 PtCallbackInfo_t cbinfo
;
226 PtMozillaProgressCb_t prog
;
228 nsXPIDLCString uriString
;
229 if (!moz
->progress_cb
)
232 cur
= aCurTotalProgress
;
233 max
= aMaxTotalProgress
;
235 if (cur
> max
&& max
!= -1 && max
!= 0)
236 cur
= max
; // Progress complete
238 cb
= moz
->progress_cb
;
239 memset(&cbinfo
, 0, sizeof(cbinfo
));
240 cbinfo
.reason
= Pt_CB_MOZ_PROGRESS
;
241 cbinfo
.cbdata
= &prog
;
245 PtInvokeCallbackList(cb
, (PtWidget_t
*)moz
, &cbinfo
);
251 EmbedProgress::OnLocationChange(nsIWebProgress
*aWebProgress
,
252 nsIRequest
*aRequest
,
255 NS_ENSURE_ARG_POINTER(aLocation
);
257 PtMozillaWidget_t
*moz
= (PtMozillaWidget_t
*) mOwner
->mOwningWidget
;
258 PtCallbackList_t
*cb
= NULL
;
259 PtCallbackInfo_t cbinfo
;
260 PtMozillaUrlCb_t url
;
261 nsCAutoString newURI
;
263 aLocation
->GetSpec(newURI
);
264 mOwner
->SetURI(newURI
.get());
269 memset(&cbinfo
, 0, sizeof(cbinfo
));
270 cbinfo
.cbdata
= &url
;
271 cbinfo
.reason
= Pt_CB_MOZ_URL
;
272 url
.url
= (char *) newURI
.get();
273 // aLocation->GetSpec(&(url.url));
275 PtInvokeCallbackList(cb
, (PtWidget_t
*) moz
, &cbinfo
);
281 EmbedProgress::OnStatusChange(nsIWebProgress
*aWebProgress
,
282 nsIRequest
*aRequest
,
284 const PRUnichar
*aMessage
)
286 PtMozillaWidget_t
*moz
= (PtMozillaWidget_t
*) mOwner
->mOwningWidget
;
287 PtCallbackList_t
*cb
;
288 PtCallbackInfo_t cbinfo
;
289 PtMozillaInfoCb_t info
;
290 nsAutoString
Text ( aMessage
);
295 memset(&cbinfo
, 0, sizeof(cbinfo
));
296 cbinfo
.cbdata
= &info
;
297 cbinfo
.reason
= Pt_CB_MOZ_INFO
;
300 const char* msg
= ToNewCString(Text
);
301 info
.type
= Pt_MOZ_INFO_CONNECT
;
303 info
.data
= (char *)msg
;
304 PtInvokeCallbackList(cb
, (PtWidget_t
*) moz
, &cbinfo
);
306 nsMemory::Free( (void*)msg
);
311 EmbedProgress::OnSecurityChange(nsIWebProgress
*aWebProgress
,
312 nsIRequest
*aRequest
,
320 EmbedProgress::RequestToURIString(nsIRequest
*aRequest
, char **aString
)
323 nsCOMPtr
<nsIChannel
> channel
;
324 channel
= do_QueryInterface(aRequest
);
328 nsCOMPtr
<nsIURI
> uri
;
329 channel
->GetURI(getter_AddRefs(uri
));
333 nsCAutoString uriString
;
334 uri
->GetSpec(uriString
);
336 *aString
= strdup(uriString
.get());