1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
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.
23 * Chak Nanga <chak@netscape.com>
24 * David Epstein <depstein@netscape.com>
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
43 #include "BrowserImpl.h"
44 #include "IBrowserFrameGlue.h"
46 #include "TestEmbed.h"
47 #include "BrowserView.h"
48 #include "BrowserFrm.h"
53 //*****************************************************************************
54 // CBrowserImpl::nsIWebProgressListener Implementation
55 //*****************************************************************************
57 // - Implements browser progress update functionality
58 // while loading a page into the embedded browser
60 // - Calls methods via the IBrowserFrameGlue interace
61 // (available thru' the m_pBrowserFrameGlue member var)
62 // to do the actual statusbar/progress bar updates.
67 NS_IMETHODIMP
CBrowserImpl::OnProgressChange(nsIWebProgress
*progress
, nsIRequest
*request
,
68 PRInt32 curSelfProgress
, PRInt32 maxSelfProgress
,
69 PRInt32 curTotalProgress
, PRInt32 maxTotalProgress
)
74 if(! m_pBrowserFrameGlue
)
75 return NS_ERROR_FAILURE
;
77 QAOutput("Entering nsIWebProgLstnr::OnProgressChange().");
79 PRInt32 nProgress
= curTotalProgress
;
80 PRInt32 nProgressMax
= maxTotalProgress
;
82 RequestName(request
, stringMsg
);
84 if (nProgressMax
== 0)
85 nProgressMax
= LONG_MAX
;
87 FormatAndPrintOutput("OnProgressChange(): curSelfProgress value = ", curSelfProgress
, 1);
88 FormatAndPrintOutput("OnProgressChange(): maxSelfProgress value = ", maxSelfProgress
, 1);
89 FormatAndPrintOutput("OnProgressChange(): curTotalProgress value = ", nProgress
, 1);
90 FormatAndPrintOutput("OnProgressChange(): maxTotalProgress value = ", nProgressMax
, 1);
92 if (curSelfProgress
== maxSelfProgress
&& maxSelfProgress
!= -1)
94 QAOutput("nsIWebProgLstnr::OnProgressChange(): Self progress complete!", 1);
96 // web progress DOMWindow test
97 WebProgDOMWindowTest(progress
, "OnProgressChange()", 1);
100 if (nProgress
> nProgressMax
&& nProgressMax
!= -1)
102 nProgress
= nProgressMax
; // Progress complete
104 QAOutput("nsIWebProgLstnr::OnProgressChange(): Progress Update complete!", 1);
106 WebProgIsDocLoadingTest(progress
, "OnProgressChange()", 1);
107 m_pBrowserFrameGlue
->UpdateProgress(nProgress
, nProgressMax
);
109 QAOutput("Exiting nsIWebProgLstnr::OnProgressChange().\r\n");
114 NS_IMETHODIMP
CBrowserImpl::OnStateChange(nsIWebProgress
*progress
, nsIRequest
*request
,
115 PRUint32 progressStateFlags
, nsresult status
)
117 char theDocType
[100];
118 char theStateType
[100];
122 if(! m_pBrowserFrameGlue
)
123 return NS_ERROR_FAILURE
;
125 QAOutput("Entering nsIWebProgLstnr::OnStateChange().");
127 RequestName(request
, stringMsg
); // nsIRequest::GetName() test
129 if (progressStateFlags
& STATE_IS_DOCUMENT
) // DOCUMENT
132 strcpy(theDocType
, "DOCUMENT");
133 if (progressStateFlags
& STATE_START
)
135 // Navigation has begun
136 strcpy(theStateType
, "STATE_START");
139 if(m_pBrowserFrameGlue
)
140 m_pBrowserFrameGlue
->UpdateBusyState(PR_TRUE
);
143 else if (progressStateFlags
& STATE_REDIRECTING
)
144 strcpy(theStateType
, "STATE_REDIRECTING");
146 else if (progressStateFlags
& STATE_TRANSFERRING
) {
147 strcpy(theStateType
, "STATE_TRANSFERRING");
150 else if (progressStateFlags
& STATE_NEGOTIATING
)
151 strcpy(theStateType
, "STATE_NEGOTIATING");
153 else if (progressStateFlags
& STATE_STOP
)
155 // We've completed the navigation
157 strcpy(theStateType
, "STATE_STOP");
160 m_pBrowserFrameGlue
->UpdateBusyState(PR_FALSE
);
161 m_pBrowserFrameGlue
->UpdateProgress(0, 100); // Clear the prog bar
162 m_pBrowserFrameGlue
->UpdateStatusBarText(nsnull
); // Clear the status bar
164 // web progress DOMWindow test
165 WebProgDOMWindowTest(progress
, "OnStateChange()", 1);
168 onStateChangeString(theStateType
, theDocType
, stringMsg
, status
, displayMode
);
170 } // end STATE_IS_DOCUMENT
172 if (progressStateFlags
& STATE_IS_REQUEST
) // REQUEST
175 strcpy(theDocType
, "REQUEST");
176 if (progressStateFlags
& STATE_START
)
177 strcpy(theStateType
, "STATE_START");
178 else if (progressStateFlags
& STATE_REDIRECTING
)
179 strcpy(theStateType
, "STATE_REDIRECTING");
181 else if (progressStateFlags
& STATE_TRANSFERRING
)
182 strcpy(theStateType
, "STATE_TRANSFERRING");
184 else if (progressStateFlags
& STATE_NEGOTIATING
)
185 strcpy(theStateType
, "STATE_NEGOTIATING");
187 else if (progressStateFlags
& STATE_STOP
)
188 strcpy(theStateType
, "STATE_STOP");
190 onStateChangeString(theStateType
, theDocType
, stringMsg
, status
, displayMode
);
193 if (progressStateFlags
& STATE_IS_NETWORK
) // NETWORK
196 strcpy(theDocType
, "NETWORK");
197 if (progressStateFlags
& STATE_START
)
198 strcpy(theStateType
, "STATE_START");
199 else if (progressStateFlags
& STATE_REDIRECTING
)
200 strcpy(theStateType
, "STATE_REDIRECTING");
202 else if (progressStateFlags
& STATE_TRANSFERRING
)
203 strcpy(theStateType
, "STATE_TRANSFERRING");
205 else if (progressStateFlags
& STATE_NEGOTIATING
)
206 strcpy(theStateType
, "STATE_NEGOTIATING");
208 else if (progressStateFlags
& STATE_STOP
)
209 strcpy(theStateType
, "STATE_STOP");
211 onStateChangeString(theStateType
, theDocType
, stringMsg
, status
, displayMode
);
214 if (progressStateFlags
& STATE_IS_WINDOW
) // WINDOW
217 strcpy(theDocType
, "WINDOW");
218 if (progressStateFlags
& STATE_START
)
219 strcpy(theStateType
, "STATE_START");
220 else if (progressStateFlags
& STATE_REDIRECTING
)
221 strcpy(theStateType
, "STATE_REDIRECTING");
223 else if (progressStateFlags
& STATE_TRANSFERRING
)
224 strcpy(theStateType
, "STATE_TRANSFERRING");
226 else if (progressStateFlags
& STATE_NEGOTIATING
)
227 strcpy(theStateType
, "STATE_NEGOTIATING");
229 else if (progressStateFlags
& STATE_STOP
)
230 strcpy(theStateType
, "STATE_STOP");
232 onStateChangeString(theStateType
, theDocType
, stringMsg
, status
, displayMode
);
235 // web progress isDocumentLoading test
236 WebProgIsDocLoadingTest(progress
, "OnStateChange()", 1);
238 QAOutput("Exiting nsIWebProgLstnr::OnStateChange().\r\n");
244 NS_IMETHODIMP
CBrowserImpl::OnLocationChange(nsIWebProgress
* aWebProgress
,
245 nsIRequest
* aRequest
,
250 if(! m_pBrowserFrameGlue
)
251 return NS_ERROR_FAILURE
;
253 QAOutput("Entering nsIWebProgLstnr::OnLocationChange().");
255 // test nsIURI parameter
256 GetTheURI(location
, 1);
258 RequestName(aRequest
, stringMsg
);
260 PRBool isSubFrameLoad
= PR_FALSE
; // Is this a subframe load
262 nsCOMPtr
<nsIDOMWindow
> domWindow
;
263 nsCOMPtr
<nsIDOMWindow
> topDomWindow
;
264 aWebProgress
->GetDOMWindow(getter_AddRefs(domWindow
));
265 if (domWindow
) { // Get root domWindow
266 domWindow
->GetTop(getter_AddRefs(topDomWindow
));
268 if (domWindow
!= topDomWindow
)
269 isSubFrameLoad
= PR_TRUE
;
270 WebProgIsDocLoadingTest(aWebProgress
, "OnLocationChange()", 1);
273 if (!isSubFrameLoad
) // Update urlbar only if it is not a subframe load
274 m_pBrowserFrameGlue
->UpdateCurrentURI(location
);
276 QAOutput("Exiting nsIWebProgLstnr::OnLocationChange().\r\n");
281 CBrowserImpl::OnStatusChange(nsIWebProgress
* aWebProgress
,
282 nsIRequest
* aRequest
,
284 const PRUnichar
* aMessage
)
288 if(! m_pBrowserFrameGlue
)
289 return NS_ERROR_FAILURE
;
291 QAOutput("Entering nsIWebProgLstnr::OnStatusChange().");
293 RequestName(aRequest
, stringMsg
);
295 // status result test (id number)
296 FormatAndPrintOutput("OnStatusChange(): Status id = ", aStatus
, 1);
298 // web progress DOMWindow test (typically the host name)
299 WebProgDOMWindowTest(aWebProgress
, "OnStatusChange(): web prog DOM window test", 1);
300 // web progress isDocumentLoading test
301 WebProgIsDocLoadingTest(aWebProgress
, "OnStatusChange()", 1);
303 m_pBrowserFrameGlue
->UpdateStatusBarText(aMessage
);
305 QAOutput("Exiting nsIWebProgLstnr::OnStatusChange().\r\n");
312 CBrowserImpl::OnSecurityChange(nsIWebProgress
*aWebProgress
,
313 nsIRequest
*aRequest
,
318 QAOutput("Entering nsIWebProgLstnr::OnSecurityChange().");
320 RequestName(aRequest
, stringMsg
);
322 if (state
& STATE_IS_SECURE
)
324 QAOutput("OnSecurityChange():STATE_IS_SECURE. All docs & subdocs are https.");
325 if ((state
& 0xFFFF0000) == STATE_SECURE_HIGH
)
326 QAOutput("OnSecurityChange(): STATE_SECURE_HIGH state");
327 else if (state
& STATE_SECURE_MED
)
328 QAOutput("OnSecurityChange(): STATE_SECURE_MED state");
329 else if (state
& STATE_SECURE_LOW
)
330 QAOutput("OnSecurityChange(): STATE_SECURE_LOW state");
332 else if (state
& STATE_IS_BROKEN
)
333 QAOutput("OnSecurityChange():STATE_IS_BROKEN. Mixed: some docs are https.");
334 else if ((state
& 0xFFFF) == STATE_IS_INSECURE
)
335 QAOutput("OnSecurityChange():STATE_IS_INSECURE. Nothing is https.");
337 // web progress DOMWindow test
338 WebProgDOMWindowTest(aWebProgress
, "OnSecurityChange()", 1);
339 // web progress isDocumentLoading test
340 WebProgIsDocLoadingTest(aWebProgress
, "OnSecurityChange()", 1);
342 QAOutput("Exiting nsIWebProgLstnr::OnSecurityChange().\r\n");