Back to index

lightning-sunbird  0.9+nobinonly
nsQABrowserChrome.cpp
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is mozilla.org Code.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Netscape Communications Corporation.
00018  * Portions created by the Initial Developer are Copyright (C) 2001
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *   Radha Kulkarni (radha@netscape.com)
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 // Mozilla Includes
00039 #include "nsIGenericFactory.h"
00040 #include "nsIComponentManager.h"
00041 #include "nsString.h"
00042 #include "nsXPIDLString.h"
00043 #include "nsIURI.h"
00044 #include "nsIWebProgress.h"
00045 #include "nsIDocShellTreeItem.h"
00046 #include "nsIDOMWindow.h"
00047 #include "nsIDOMWindowInternal.h"
00048 #include "nsIInterfaceRequestor.h"
00049 #include "nsIInterfaceRequestorUtils.h"
00050 #include "nsIRequest.h"
00051 #include "nsIChannel.h"
00052 #include "nsCWebBrowser.h"
00053 #include "nsWidgetsCID.h"
00054 #include "nsIProfileChangeStatus.h"
00055 #include "nsCRT.h"
00056 #include "nsWeakReference.h"
00057 
00058 // Local includes
00059 #include "resource.h"
00060 #include "mozEmbed.h"
00061 #include "nsQABrowserChrome.h"
00062 
00063 
00064 nsQABrowserChrome::nsQABrowserChrome()
00065 {
00066     mNativeWindow = nsnull;
00067     mSizeSet = PR_FALSE;
00068 }
00069 
00070 nsQABrowserChrome::~nsQABrowserChrome()
00071 {
00072   if (mBrowserUIGlue)
00073     mBrowserUIGlue->Destroyed(this);
00074 }
00075 
00076 
00077 //*****************************************************************************
00078 // nsQABrowserChrome::nsISupports
00079 //*****************************************************************************   
00080 
00081 
00082 NS_IMPL_ISUPPORTS7(nsQABrowserChrome, 
00083                    nsIQABrowserChrome, 
00084                    nsIWebBrowserChrome,
00085                    nsIInterfaceRequestor,
00086                    nsIEmbeddingSiteWindow,
00087                    nsIWebProgressListener,
00088                    nsIWebBrowserChromeFocus,
00089                    nsISupportsWeakReference);
00090 
00091 
00092 
00093 //*****************************************************************************
00094 // nsQABrowserChrome::nsIInterfaceRequestor
00095 //*****************************************************************************   
00096 
00097 NS_IMETHODIMP nsQABrowserChrome::GetInterface(const nsIID &aIID, void** aInstancePtr)
00098 {
00099     NS_ENSURE_ARG_POINTER(aInstancePtr);
00100 
00101     *aInstancePtr = 0;
00102     if (aIID.Equals(NS_GET_IID(nsIDOMWindow)))
00103     {
00104         if (mWebBrowser)
00105         {
00106             return mWebBrowser->GetContentDOMWindow((nsIDOMWindow **) aInstancePtr);
00107         }
00108         return NS_ERROR_NOT_INITIALIZED;
00109     }
00110     return QueryInterface(aIID, aInstancePtr);
00111 }
00112 
00113 //*****************************************************************************
00114 // nsQABrowserChrome::nsIQABrowserChrome
00115 //*****************************************************************************   
00116 
00117 NS_IMETHODIMP
00118 nsQABrowserChrome::InitQAChrome(nsIQABrowserUIGlue * aUIGlue,  nativeWindow aNativeWnd)
00119 {
00120   mBrowserUIGlue = aUIGlue;
00121   mNativeWindow = aNativeWnd;
00122   
00123   return NS_OK;
00124 }
00125 
00126 //*****************************************************************************
00127 // nsQABrowserChrome::nsIQABrowserChrome
00128 //*****************************************************************************   
00129 
00130 NS_IMETHODIMP nsQABrowserChrome::SetStatus(PRUint32 aType, const PRUnichar* aStatus)
00131 {
00132   if (mBrowserUIGlue)
00133     return mBrowserUIGlue->UpdateStatusBarText(this, aStatus);
00134   return NS_ERROR_FAILURE;
00135 }
00136 
00137 NS_IMETHODIMP nsQABrowserChrome::GetWebBrowser(nsIWebBrowser** aWebBrowser)
00138 {
00139     NS_ENSURE_ARG_POINTER(aWebBrowser);
00140     *aWebBrowser = mWebBrowser;
00141     NS_IF_ADDREF(*aWebBrowser);
00142     return NS_OK;
00143 }
00144 
00145 NS_IMETHODIMP nsQABrowserChrome::SetWebBrowser(nsIWebBrowser* aWebBrowser)
00146 {
00147     mWebBrowser = aWebBrowser;
00148     return NS_OK;
00149 }
00150 
00151 NS_IMETHODIMP nsQABrowserChrome::GetChromeFlags(PRUint32* aChromeMask)
00152 {
00153   if (aChromeMask)
00154     *aChromeMask = mChromeFlags;
00155   return NS_OK;
00156 }
00157 
00158 NS_IMETHODIMP nsQABrowserChrome::SetChromeFlags(PRUint32 aChromeMask)
00159 {
00160     mChromeFlags = aChromeMask;
00161     return NS_OK;
00162 }
00163 
00164 NS_IMETHODIMP nsQABrowserChrome::DestroyBrowserWindow(void)
00165 {
00166   if (mBrowserUIGlue)
00167     return mBrowserUIGlue->Destroy(this);
00168   return NS_ERROR_FAILURE;
00169 }
00170 
00171 
00172 NS_IMETHODIMP nsQABrowserChrome::SizeBrowserTo(PRInt32 aCX, PRInt32 aCY)
00173 {
00174   /* This isn't exactly correct: we're setting the whole window to
00175      the size requested for the browser. At time of writing, though,
00176      it's fine and useful for mozEmbed's purposes. 
00177   */
00178   mSizeSet = PR_TRUE;
00179   if (mBrowserUIGlue)
00180     return mBrowserUIGlue->SizeTo(this, aCX, aCY);
00181   return NS_ERROR_FAILURE;
00182 }
00183 
00184 
00185 NS_IMETHODIMP nsQABrowserChrome::ShowAsModal(void)
00186 {
00187 /*
00188   if (mDependentParent)
00189     AppCallbacks::EnableChromeWindow(mDependentParent, PR_FALSE);
00190 
00191   mContinueModalLoop = PR_TRUE;
00192   AppCallbacks::RunEventLoop(mContinueModalLoop);
00193 
00194   if (mDependentParent)
00195     AppCallbacks::EnableChromeWindow(mDependentParent, PR_TRUE);
00196 */
00197   return NS_OK;
00198 }
00199 
00200 NS_IMETHODIMP nsQABrowserChrome::IsWindowModal(PRBool *aReturn)
00201 {
00202   if (aReturn)
00203     *aReturn = PR_FALSE;
00204   return NS_OK;
00205 }
00206 
00207 NS_IMETHODIMP nsQABrowserChrome::ExitModalEventLoop(nsresult aStatus)
00208 {
00209   mContinueModalLoop = PR_FALSE;
00210   return NS_OK;
00211 }
00212 
00213 //*****************************************************************************
00214 // nsQABrowserChrome::nsIEmbeddingSiteWindow
00215 //*****************************************************************************   
00216 
00217 NS_IMETHODIMP nsQABrowserChrome::SetDimensions(PRUint32 aFlags, PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy)
00218 {
00219     return NS_ERROR_NOT_IMPLEMENTED;
00220 }
00221 
00222 NS_IMETHODIMP nsQABrowserChrome::GetDimensions(PRUint32 aFlags, PRInt32 *x, PRInt32 *y, PRInt32 *cx, PRInt32 *cy)
00223 {
00224     if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION)
00225     {
00226         *x = 0;
00227         *y = 0;
00228     }
00229     if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER ||
00230         aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER)
00231     {
00232         *cx = 0;
00233         *cy = 0;
00234     }
00235     return NS_ERROR_NOT_IMPLEMENTED;
00236 }
00237 
00238 /* void setFocus (); */
00239 NS_IMETHODIMP nsQABrowserChrome::SetFocus()
00240 {
00241   if (mBrowserUIGlue)
00242     return mBrowserUIGlue->SetFocus(this);
00243   return NS_ERROR_FAILURE;
00244 }
00245 
00246 /* attribute wstring title; */
00247 NS_IMETHODIMP nsQABrowserChrome::GetTitle(PRUnichar * *aTitle)
00248 {
00249    NS_ENSURE_ARG_POINTER(aTitle);
00250    *aTitle = nsnull;   
00251    return NS_ERROR_NOT_IMPLEMENTED;
00252 }
00253 
00254 NS_IMETHODIMP nsQABrowserChrome::SetTitle(const PRUnichar * aTitle)
00255 {
00256     return NS_ERROR_NOT_IMPLEMENTED;
00257 }
00258 
00259 /* attribute boolean visibility; */
00260 NS_IMETHODIMP nsQABrowserChrome::GetVisibility(PRBool * aVisibility)
00261 {
00262     NS_ENSURE_ARG_POINTER(aVisibility);
00263     *aVisibility = PR_TRUE;
00264     return NS_OK;
00265 }
00266 NS_IMETHODIMP nsQABrowserChrome::SetVisibility(PRBool aVisibility)
00267 {
00268     return NS_OK;
00269 }
00270 
00271 /* attribute nativeSiteWindow siteWindow */
00272 NS_IMETHODIMP nsQABrowserChrome::GetSiteWindow(void * *aSiteWindow)
00273 {
00274    NS_ENSURE_ARG_POINTER(aSiteWindow);
00275    *aSiteWindow = mNativeWindow;
00276    return NS_OK;
00277 }
00278 
00279 
00280 //*****************************************************************************
00281 // nsQABrowserChrome::nsIWebProgressListener
00282 //*****************************************************************************   
00283 NS_IMETHODIMP
00284 nsQABrowserChrome::OnProgressChange(nsIWebProgress *progress, nsIRequest *request,
00285                                     PRInt32 curSelfProgress, PRInt32 maxSelfProgress,
00286                                     PRInt32 curTotalProgress, PRInt32 maxTotalProgress)
00287 {
00288   if (mBrowserUIGlue)
00289     return mBrowserUIGlue->UpdateProgress(this, curTotalProgress, maxTotalProgress);
00290   return NS_OK;
00291 }
00292 
00293 NS_IMETHODIMP
00294 nsQABrowserChrome::OnStateChange(nsIWebProgress *progress, nsIRequest *request,
00295                                                PRUint32 progressStateFlags, nsresult status)
00296 {
00297   if (!mBrowserUIGlue)
00298     return NS_ERROR_FAILURE;
00299 
00300   if ((progressStateFlags & STATE_START) && (progressStateFlags & STATE_IS_DOCUMENT))
00301   {
00302     mBrowserUIGlue->UpdateBusyState(this, PR_TRUE);
00303   }
00304 
00305   if ((progressStateFlags & STATE_STOP) && (progressStateFlags & STATE_IS_DOCUMENT))
00306   {
00307     mBrowserUIGlue->UpdateBusyState(this, PR_FALSE);
00308     mBrowserUIGlue->UpdateProgress(this, 0, 100);
00309     mBrowserUIGlue->UpdateStatusBarText(this, nsnull);
00310     ContentFinishedLoading();
00311   }
00312 
00313   return NS_OK;
00314 }
00315 
00316 
00317 NS_IMETHODIMP
00318 nsQABrowserChrome::OnLocationChange(nsIWebProgress* aWebProgress,
00319                                     nsIRequest* aRequest,
00320                                     nsIURI *location)
00321 {
00322   if (!mBrowserUIGlue)
00323     return NS_ERROR_FAILURE;
00324 
00325   PRBool isSubFrameLoad = PR_FALSE; // Is this a subframe load
00326   if (aWebProgress) {
00327     nsCOMPtr<nsIDOMWindow>  domWindow;
00328     nsCOMPtr<nsIDOMWindow>  topDomWindow;
00329     aWebProgress->GetDOMWindow(getter_AddRefs(domWindow));
00330     if (domWindow) { // Get root domWindow
00331       domWindow->GetTop(getter_AddRefs(topDomWindow));
00332     }
00333     if (domWindow != topDomWindow)
00334       isSubFrameLoad = PR_TRUE;
00335   }
00336   if (!isSubFrameLoad)
00337     mBrowserUIGlue->UpdateCurrentURI(this);
00338   return NS_OK;
00339 }
00340 
00341 NS_IMETHODIMP 
00342 nsQABrowserChrome::OnStatusChange(nsIWebProgress* aWebProgress,
00343                                  nsIRequest* aRequest,
00344                                  nsresult aStatus,
00345                                  const PRUnichar* aMessage)
00346 {
00347   if (mBrowserUIGlue)
00348     return mBrowserUIGlue->UpdateStatusBarText(this, aMessage);
00349   return NS_OK;
00350 }
00351 
00352 
00353 
00354 NS_IMETHODIMP 
00355 nsQABrowserChrome::OnSecurityChange(nsIWebProgress *aWebProgress, 
00356                                     nsIRequest *aRequest, 
00357                                     PRUint32 state)
00358 {
00359     return NS_OK;
00360 }
00361 //*****************************************************************************
00362 // nsQABrowserChrome::nsInsQABrowserChromeFocus
00363 //*****************************************************************************   
00364 
00365 NS_IMETHODIMP
00366 nsQABrowserChrome::FocusNextElement()
00367 {
00368     return NS_OK;
00369 }
00370 
00371 NS_IMETHODIMP
00372 nsQABrowserChrome::FocusPrevElement()
00373 {
00374     return NS_OK;
00375 }
00376 
00377 
00378 
00379 void
00380 nsQABrowserChrome::ContentFinishedLoading()
00381 {
00382   // if it was a chrome window and no one has already specified a size,
00383   // size to content
00384   if (mWebBrowser && !mSizeSet && mBrowserUIGlue &&
00385      (mChromeFlags & nsIWebBrowserChrome::CHROME_OPENAS_CHROME)) {
00386     nsCOMPtr<nsIDOMWindow> contentWin;
00387     mWebBrowser->GetContentDOMWindow(getter_AddRefs(contentWin));
00388     if (contentWin)
00389         contentWin->SizeToContent();
00390     mBrowserUIGlue->ShowWindow(this, PR_TRUE);
00391   }
00392 }
00393 
00394 
00395 
00396 
00397 
00398 
00399 
00400 
00401 
00402 
00403 
00404 
00405