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: Mozilla-sample-code 1.0
00004  *
00005  * Copyright (c) 2002 Netscape Communications Corporation and
00006  * other contributors
00007  *
00008  * Permission is hereby granted, free of charge, to any person obtaining a
00009  * copy of this Mozilla sample software and associated documentation files
00010  * (the "Software"), to deal in the Software without restriction, including
00011  * without limitation the rights to use, copy, modify, merge, publish,
00012  * distribute, sublicense, and/or sell copies of the Software, and to permit
00013  * persons to whom the Software is furnished to do so, subject to the
00014  * following conditions:
00015  *
00016  * The above copyright notice and this permission notice shall be included
00017  * in all copies or substantial portions of the Software.
00018  *
00019  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00020  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00021  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
00022  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00023  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00024  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00025  * DEALINGS IN THE SOFTWARE.
00026  *
00027  * Contributor(s):
00028  *   Chak Nanga <chak@netscape.com>
00029  *
00030  * ***** END LICENSE BLOCK ***** */
00031 
00032 #ifdef _WINDOWS
00033   #include "stdafx.h"
00034 #endif
00035 #include "BrowserImpl.h"
00036 #include "IBrowserFrameGlue.h"
00037 
00038 //*****************************************************************************
00039 // CBrowserImpl::nsIWebProgressListener Implementation
00040 //*****************************************************************************   
00041 //
00042 // - Implements browser progress update functionality 
00043 //   while loading a page into the embedded browser
00044 //
00045 // - Calls methods via the IBrowserFrameGlue interace 
00046 //    (available thru' the m_pBrowserFrameGlue member var)
00047 //    to do the actual statusbar/progress bar updates. 
00048 //
00049 
00050 NS_IMETHODIMP CBrowserImpl::OnProgressChange(nsIWebProgress *progress,
00051                                              nsIRequest *request,
00052                                              PRInt32 curSelfProgress,
00053                                              PRInt32 maxSelfProgress,
00054                                              PRInt32 curTotalProgress,
00055                                              PRInt32 maxTotalProgress)
00056 {
00057   if(! m_pBrowserFrameGlue) {
00058     // always return NS_OK
00059     return NS_OK;
00060   }
00061 
00062   PRInt32 nProgress = curTotalProgress;
00063   PRInt32 nProgressMax = maxTotalProgress;
00064 
00065   if (nProgressMax == 0)
00066     nProgressMax = LONG_MAX;
00067 
00068   if (nProgress > nProgressMax)
00069     nProgress = nProgressMax; // Progress complete
00070 
00071   m_pBrowserFrameGlue->UpdateProgress(nProgress, nProgressMax);
00072 
00073   return NS_OK;
00074 }
00075 
00076 NS_IMETHODIMP CBrowserImpl::OnStateChange(nsIWebProgress *progress,
00077                                           nsIRequest *request,
00078                                           PRUint32 progressStateFlags,
00079                                           nsresult status)
00080 {
00081   if(! m_pBrowserFrameGlue) {
00082     // always return NS_OK
00083     return NS_OK;
00084   }
00085 
00086   if ((progressStateFlags & STATE_START) && (progressStateFlags & STATE_IS_DOCUMENT))
00087   {
00088     // Navigation has begun
00089     m_pBrowserFrameGlue->UpdateBusyState(PR_TRUE);
00090   }
00091 
00092   if ((progressStateFlags & STATE_STOP) && (progressStateFlags & STATE_IS_DOCUMENT))
00093   {
00094     // We've completed the navigation
00095 
00096     m_pBrowserFrameGlue->UpdateBusyState(PR_FALSE);
00097     m_pBrowserFrameGlue->UpdateProgress(0, 100);       // Clear the prog bar
00098     m_pBrowserFrameGlue->UpdateStatusBarText(nsnull);  // Clear the status bar
00099   }
00100 
00101   return NS_OK;
00102 }
00103 
00104 
00105 NS_IMETHODIMP CBrowserImpl::OnLocationChange(nsIWebProgress* aWebProgress,
00106                                                  nsIRequest* aRequest,
00107                                                  nsIURI *location)
00108 {
00109   if(! m_pBrowserFrameGlue) {
00110     // always return NS_OK
00111     return NS_OK;
00112   }
00113 
00114   PRBool isSubFrameLoad = PR_FALSE; // Is this a subframe load
00115   if (aWebProgress) {
00116     nsCOMPtr<nsIDOMWindow>  domWindow;
00117     nsCOMPtr<nsIDOMWindow>  topDomWindow;
00118     aWebProgress->GetDOMWindow(getter_AddRefs(domWindow));
00119     if (domWindow) { // Get root domWindow
00120       domWindow->GetTop(getter_AddRefs(topDomWindow));
00121     }
00122     if (domWindow != topDomWindow)
00123       isSubFrameLoad = PR_TRUE;
00124 
00125   }
00126 
00127   if (!isSubFrameLoad) // Update urlbar only if it is not a subframe load
00128     m_pBrowserFrameGlue->UpdateCurrentURI(location);
00129 
00130     return NS_OK;
00131 }
00132 
00133 NS_IMETHODIMP 
00134 CBrowserImpl::OnStatusChange(nsIWebProgress* aWebProgress,
00135                                  nsIRequest* aRequest,
00136                                  nsresult aStatus,
00137                                  const PRUnichar* aMessage)
00138 {
00139   if(m_pBrowserFrameGlue)
00140     m_pBrowserFrameGlue->UpdateStatusBarText(aMessage);
00141 
00142   return NS_OK;
00143 }
00144 
00145 
00146 
00147 NS_IMETHODIMP 
00148 CBrowserImpl::OnSecurityChange(nsIWebProgress *aWebProgress, 
00149                                     nsIRequest *aRequest, 
00150                                     PRUint32 state)
00151 {
00152   m_pBrowserFrameGlue->UpdateSecurityStatus(state);
00153 
00154   return NS_OK;
00155 }