Back to index

lightning-sunbird  0.9+nobinonly
BrowserImplWebPrgrsLstnr.cpp
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) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Chak Nanga <chak@netscape.com>
00024  *   David Epstein <depstein@netscape.com>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either the GNU General Public License Version 2 or later (the "GPL"), or
00028  * 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 #ifdef _WINDOWS
00041   #include "stdafx.h"
00042 #endif
00043 #include "BrowserImpl.h"
00044 #include "IBrowserFrameGlue.h"
00045 
00046 #include "TestEmbed.h"
00047 #include "BrowserView.h"
00048 #include "BrowserFrm.h"
00049 
00050 #include "QaUtils.h"
00051 #include "Tests.h"
00052 
00053 //*****************************************************************************
00054 // CBrowserImpl::nsIWebProgressListener Implementation
00055 //*****************************************************************************   
00056 //
00057 // - Implements browser progress update functionality 
00058 //   while loading a page into the embedded browser
00059 //
00060 //     - Calls methods via the IBrowserFrameGlue interace 
00061 //       (available thru' the m_pBrowserFrameGlue member var)
00062 //       to do the actual statusbar/progress bar updates. 
00063 //
00064 
00065 class CBrowserView;
00066 
00067 NS_IMETHODIMP CBrowserImpl::OnProgressChange(nsIWebProgress *progress, nsIRequest *request,
00068                                                   PRInt32 curSelfProgress, PRInt32 maxSelfProgress,
00069                                                   PRInt32 curTotalProgress, PRInt32 maxTotalProgress)
00070 {
00071        // nsCString
00072        nsCString stringMsg;
00073 
00074        if(! m_pBrowserFrameGlue)
00075               return NS_ERROR_FAILURE;
00076 
00077        QAOutput("Entering nsIWebProgLstnr::OnProgressChange().");
00078 
00079        PRInt32 nProgress = curTotalProgress;
00080        PRInt32 nProgressMax = maxTotalProgress;
00081 
00082        RequestName(request, stringMsg);
00083 
00084        if (nProgressMax == 0)
00085               nProgressMax = LONG_MAX;
00086 
00087        FormatAndPrintOutput("OnProgressChange(): curSelfProgress value = ", curSelfProgress, 1); 
00088        FormatAndPrintOutput("OnProgressChange(): maxSelfProgress value = ", maxSelfProgress, 1);
00089        FormatAndPrintOutput("OnProgressChange(): curTotalProgress value = ", nProgress, 1); 
00090        FormatAndPrintOutput("OnProgressChange(): maxTotalProgress value = ", nProgressMax, 1);
00091 
00092        if (curSelfProgress == maxSelfProgress && maxSelfProgress != -1)
00093        {
00094               QAOutput("nsIWebProgLstnr::OnProgressChange(): Self progress complete!", 1);
00095 
00096               // web progress DOMWindow test
00097               WebProgDOMWindowTest(progress, "OnProgressChange()", 1);
00098        }
00099 
00100        if (nProgress > nProgressMax && nProgressMax != -1)
00101        {
00102               nProgress = nProgressMax; // Progress complete
00103 
00104               QAOutput("nsIWebProgLstnr::OnProgressChange(): Progress Update complete!", 1);
00105        }
00106        WebProgIsDocLoadingTest(progress, "OnProgressChange()", 1);
00107        m_pBrowserFrameGlue->UpdateProgress(nProgress, nProgressMax);
00108 
00109        QAOutput("Exiting nsIWebProgLstnr::OnProgressChange().\r\n");
00110   
00111        return NS_OK;
00112 }
00113 
00114 NS_IMETHODIMP CBrowserImpl::OnStateChange(nsIWebProgress *progress, nsIRequest *request,
00115                                           PRUint32 progressStateFlags, nsresult status)
00116 {
00117        char theDocType[100];
00118        char theStateType[100];
00119        int displayMode = 1;
00120        nsCString stringMsg;
00121 
00122        if(! m_pBrowserFrameGlue)
00123               return NS_ERROR_FAILURE;
00124 
00125        QAOutput("Entering nsIWebProgLstnr::OnStateChange().");
00126 
00127        RequestName(request, stringMsg);   // nsIRequest::GetName() test
00128 
00129        if (progressStateFlags & STATE_IS_DOCUMENT)             // DOCUMENT
00130        {
00131               displayMode = 1;
00132               strcpy(theDocType, "DOCUMENT");
00133               if (progressStateFlags & STATE_START)
00134               { 
00135                      // Navigation has begun
00136                      strcpy(theStateType, "STATE_START");
00137                      displayMode = 2;
00138 
00139                      if(m_pBrowserFrameGlue)
00140                             m_pBrowserFrameGlue->UpdateBusyState(PR_TRUE);
00141               }
00142 
00143               else if (progressStateFlags & STATE_REDIRECTING)
00144                      strcpy(theStateType, "STATE_REDIRECTING");
00145 
00146               else if (progressStateFlags & STATE_TRANSFERRING) {
00147                      strcpy(theStateType, "STATE_TRANSFERRING");      
00148               }
00149 
00150               else if (progressStateFlags & STATE_NEGOTIATING)
00151                      strcpy(theStateType, "STATE_NEGOTIATING");                            
00152 
00153               else if (progressStateFlags & STATE_STOP)
00154               {
00155                      // We've completed the navigation
00156 
00157                      strcpy(theStateType, "STATE_STOP");
00158                      displayMode = 2;
00159 
00160                      m_pBrowserFrameGlue->UpdateBusyState(PR_FALSE);
00161                      m_pBrowserFrameGlue->UpdateProgress(0, 100);       // Clear the prog bar
00162                      m_pBrowserFrameGlue->UpdateStatusBarText(nsnull);  // Clear the status bar
00163 
00164               // web progress DOMWindow test
00165                      WebProgDOMWindowTest(progress, "OnStateChange()", 1);
00166               }
00167 
00168               onStateChangeString(theStateType, theDocType, stringMsg, status, displayMode);
00169 
00170        }             // end STATE_IS_DOCUMENT
00171 
00172        if (progressStateFlags & STATE_IS_REQUEST)              // REQUEST
00173        {
00174               displayMode = 1;
00175               strcpy(theDocType, "REQUEST");
00176               if (progressStateFlags & STATE_START)
00177                      strcpy(theStateType, "STATE_START");
00178               else if (progressStateFlags & STATE_REDIRECTING)
00179                      strcpy(theStateType, "STATE_REDIRECTING");
00180 
00181               else if (progressStateFlags & STATE_TRANSFERRING)
00182                      strcpy(theStateType, "STATE_TRANSFERRING");             
00183 
00184               else if (progressStateFlags & STATE_NEGOTIATING)
00185                      strcpy(theStateType, "STATE_NEGOTIATING");                            
00186 
00187               else if (progressStateFlags & STATE_STOP)
00188                      strcpy(theStateType, "STATE_STOP");
00189               
00190               onStateChangeString(theStateType, theDocType, stringMsg, status, displayMode);
00191        }
00192 
00193        if (progressStateFlags & STATE_IS_NETWORK)              // NETWORK
00194        {
00195               displayMode = 1;
00196               strcpy(theDocType, "NETWORK");
00197               if (progressStateFlags & STATE_START)
00198                      strcpy(theStateType, "STATE_START");
00199               else if (progressStateFlags & STATE_REDIRECTING)
00200                      strcpy(theStateType, "STATE_REDIRECTING");
00201 
00202               else if (progressStateFlags & STATE_TRANSFERRING)
00203                      strcpy(theStateType, "STATE_TRANSFERRING");             
00204 
00205               else if (progressStateFlags & STATE_NEGOTIATING)
00206                      strcpy(theStateType, "STATE_NEGOTIATING");                            
00207 
00208               else if (progressStateFlags & STATE_STOP)
00209                      strcpy(theStateType, "STATE_STOP");
00210               
00211               onStateChangeString(theStateType, theDocType, stringMsg, status, displayMode);
00212 
00213        }
00214        if (progressStateFlags & STATE_IS_WINDOW)        // WINDOW
00215        {
00216               displayMode = 1;
00217               strcpy(theDocType, "WINDOW");
00218               if (progressStateFlags & STATE_START)
00219                      strcpy(theStateType, "STATE_START");
00220               else if (progressStateFlags & STATE_REDIRECTING)
00221                      strcpy(theStateType, "STATE_REDIRECTING");
00222 
00223               else if (progressStateFlags & STATE_TRANSFERRING)
00224                      strcpy(theStateType, "STATE_TRANSFERRING");             
00225 
00226               else if (progressStateFlags & STATE_NEGOTIATING)
00227                      strcpy(theStateType, "STATE_NEGOTIATING");                            
00228 
00229               else if (progressStateFlags & STATE_STOP)
00230                      strcpy(theStateType, "STATE_STOP");
00231               
00232               onStateChangeString(theStateType, theDocType, stringMsg, status, displayMode);
00233 
00234        }
00235        // web progress isDocumentLoading test
00236        WebProgIsDocLoadingTest(progress, "OnStateChange()", 1);
00237 
00238        QAOutput("Exiting nsIWebProgLstnr::OnStateChange().\r\n");
00239 
00240     return NS_OK;
00241 }
00242 
00243 
00244 NS_IMETHODIMP CBrowserImpl::OnLocationChange(nsIWebProgress* aWebProgress,
00245                                                  nsIRequest* aRequest,
00246                                                  nsIURI *location)
00247 {
00248        nsCString stringMsg;
00249 
00250        if(! m_pBrowserFrameGlue)
00251               return NS_ERROR_FAILURE;
00252 
00253        QAOutput("Entering nsIWebProgLstnr::OnLocationChange().");
00254 
00255        // test nsIURI parameter
00256        GetTheURI(location, 1);
00257  
00258        RequestName(aRequest, stringMsg);  
00259 
00260        PRBool isSubFrameLoad = PR_FALSE; // Is this a subframe load
00261        if (aWebProgress) {
00262               nsCOMPtr<nsIDOMWindow>  domWindow;
00263               nsCOMPtr<nsIDOMWindow>  topDomWindow;
00264               aWebProgress->GetDOMWindow(getter_AddRefs(domWindow));
00265               if (domWindow) { // Get root domWindow
00266                      domWindow->GetTop(getter_AddRefs(topDomWindow));
00267               }
00268               if (domWindow != topDomWindow)
00269                      isSubFrameLoad = PR_TRUE;
00270               WebProgIsDocLoadingTest(aWebProgress, "OnLocationChange()", 1);
00271        }
00272 
00273        if (!isSubFrameLoad) // Update urlbar only if it is not a subframe load
00274          m_pBrowserFrameGlue->UpdateCurrentURI(location);
00275 
00276        QAOutput("Exiting nsIWebProgLstnr::OnLocationChange().\r\n");
00277     return NS_OK;
00278 }
00279 
00280 NS_IMETHODIMP 
00281 CBrowserImpl::OnStatusChange(nsIWebProgress* aWebProgress,
00282                                  nsIRequest* aRequest,
00283                                  nsresult aStatus,
00284                                  const PRUnichar* aMessage)
00285 {
00286        nsCString stringMsg;
00287 
00288        if(! m_pBrowserFrameGlue)
00289               return NS_ERROR_FAILURE;
00290 
00291        QAOutput("Entering nsIWebProgLstnr::OnStatusChange().");
00292 
00293        RequestName(aRequest, stringMsg);
00294 
00295                      // status result test (id number)
00296        FormatAndPrintOutput("OnStatusChange(): Status id = ", aStatus, 1);
00297 
00298                      // web progress DOMWindow test (typically the host name)
00299        WebProgDOMWindowTest(aWebProgress, "OnStatusChange(): web prog DOM window test", 1);
00300                      // web progress isDocumentLoading test
00301        WebProgIsDocLoadingTest(aWebProgress, "OnStatusChange()", 1);
00302 
00303        m_pBrowserFrameGlue->UpdateStatusBarText(aMessage);
00304 
00305        QAOutput("Exiting nsIWebProgLstnr::OnStatusChange().\r\n");
00306 
00307     return NS_OK;
00308 }
00309 
00310 
00311 NS_IMETHODIMP 
00312 CBrowserImpl::OnSecurityChange(nsIWebProgress *aWebProgress, 
00313                                     nsIRequest *aRequest, 
00314                                     PRUint32 state)
00315 {
00316        nsCString stringMsg;
00317 
00318        QAOutput("Entering nsIWebProgLstnr::OnSecurityChange().");
00319 
00320        RequestName(aRequest, stringMsg);
00321 
00322        if (state & STATE_IS_SECURE)
00323        {
00324               QAOutput("OnSecurityChange():STATE_IS_SECURE. All docs & subdocs are https.");
00325               if ((state & 0xFFFF0000) == STATE_SECURE_HIGH)
00326                      QAOutput("OnSecurityChange(): STATE_SECURE_HIGH state");
00327               else if (state & STATE_SECURE_MED)
00328                      QAOutput("OnSecurityChange(): STATE_SECURE_MED state");
00329               else if (state & STATE_SECURE_LOW)
00330                      QAOutput("OnSecurityChange(): STATE_SECURE_LOW state");
00331        }
00332        else if (state & STATE_IS_BROKEN)
00333               QAOutput("OnSecurityChange():STATE_IS_BROKEN. Mixed: some docs are https.");
00334        else if ((state & 0xFFFF) ==  STATE_IS_INSECURE)
00335               QAOutput("OnSecurityChange():STATE_IS_INSECURE. Nothing is https.");
00336 
00337                             // web progress DOMWindow test
00338        WebProgDOMWindowTest(aWebProgress, "OnSecurityChange()", 1);
00339                             // web progress isDocumentLoading test
00340        WebProgIsDocLoadingTest(aWebProgress, "OnSecurityChange()", 1);
00341 
00342        QAOutput("Exiting nsIWebProgLstnr::OnSecurityChange().\r\n");
00343 
00344     return NS_OK;
00345 }