Back to index

lightning-sunbird  0.9+nobinonly
nsQABrowserView.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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  *   Radha Kulkarni (radha@netscape.com)
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #include <stdio.h>
00040 
00041 //locals
00042 #include "nsQABrowserView.h"
00043 #include "nsIQABrowserView.h"
00044 #include "nsIInterfaceRequestor.h"
00045 
00046 //essentials
00047 #include "nsIComponentManager.h"
00048 
00049 
00050 //Interfaces Needed
00051 #include "nsCWebBrowser.h"
00052 #include "nsIDocShellTreeItem.h"
00053 #include "nsIWebProgressListener.h"
00054 #include "nsIWebBrowserChrome.h"
00055 #include "nsWeakPtr.h"
00056 #include "nsWeakReference.h"
00057 
00058 nsQABrowserView::nsQABrowserView():mWebBrowser(nsnull)
00059 {
00060   mWebBrowser = nsnull;
00061   mWebNav = nsnull;
00062   mBaseWindow = nsnull;
00063 }
00064 
00065 nsQABrowserView::~nsQABrowserView()
00066 {
00067 }
00068 
00069 //*****************************************************************************
00070 // nsQABrowserView::nsISupports
00071 //*****************************************************************************   
00072 
00073 NS_IMPL_ISUPPORTS2(nsQABrowserView, nsIQABrowserView, nsIInterfaceRequestor)
00074 
00075 //*****************************************************************************
00076 // nsQABrowserView::nsIInterfacerequestor
00077 //*****************************************************************************
00078 
00079 NS_IMETHODIMP
00080 nsQABrowserView::GetInterface(const nsIID& aIID, void ** aSink)
00081 {
00082   NS_ENSURE_ARG_POINTER(aSink);  
00083   printf("In nsQABrowserView::GetInterface\n");
00084   if (NS_SUCCEEDED(QueryInterface(aIID, aSink)))
00085     return NS_OK;
00086 
00087   if (mWebBrowser) {
00088     printf("nsQABrowserView::GetInterface, Got mWebBrowser\n");
00089     nsCOMPtr<nsIInterfaceRequestor>  ifcReq(do_QueryInterface(mWebBrowser));
00090     if (ifcReq)
00091       return ifcReq->GetInterface(aIID, aSink);
00092   }
00093 
00094   return NS_NOINTERFACE;
00095 
00096 }
00097 
00098 
00099 NS_IMETHODIMP
00100 nsQABrowserView::CreateBrowser(nativeWindow aNativeWnd, nsIWebBrowserChrome * aChrome)
00101 {
00102 
00103   nsresult rv;
00104   mWebBrowser = do_CreateInstance(NS_WEBBROWSER_CONTRACTID, &rv);
00105   if (NS_FAILED(rv) || !mWebBrowser)
00106     return NS_ERROR_FAILURE; 
00107 
00108   mWebNav = do_QueryInterface(mWebBrowser, &rv);
00109        if(NS_FAILED(rv))
00110               return rv;
00111   
00112   // Set the chrome object the container window. 
00113   mWebBrowser->SetContainerWindow(aChrome);
00114   if(NS_FAILED(rv))
00115               return rv;
00116 
00117   rv = NS_OK;
00118   nsCOMPtr<nsIDocShellTreeItem> dsti = do_QueryInterface(mWebBrowser, &rv);
00119        if(NS_FAILED(rv))
00120               return rv;
00121 
00122   // If the browser window hosting chrome or content?
00123   dsti->SetItemType(nsIDocShellTreeItem::typeContentWrapper);
00124 
00125   // Create the real webbrowser window
00126        mBaseWindow = do_QueryInterface(mWebBrowser, &rv);
00127        if(NS_FAILED(rv))
00128               return rv;
00129 
00130   // Create the actual window
00131        rv = mBaseWindow->InitWindow(aNativeWnd, nsnull, 0, 0, -1, -1);
00132        rv = mBaseWindow->Create();
00133 
00134   // set a handle to nsIWebBrowser in nsQAWebBrowserChrome
00135   aChrome->SetWebBrowser(mWebBrowser);
00136 
00137   // Register the QABrowserChrome object to receive progress messages
00138        // These callbacks will be used to update the status/progress bars
00139   nsWeakPtr weakling(do_GetWeakReference(aChrome));
00140   (void)mWebBrowser->AddWebBrowserListener(weakling, NS_GET_IID(nsIWebProgressListener));
00141 
00142        // Finally, show the web browser window
00143        mBaseWindow->SetVisibility(PR_TRUE);
00144 
00145        return NS_OK;
00146 }
00147 
00148 // XXX Not needed
00149 NS_IMETHODIMP
00150 nsQABrowserView::DestroyBrowser()
00151 {
00152   // destroy the actual window.
00153   mBaseWindow->Destroy();
00154   mWebBrowser = nsnull;
00155   mWebNav = nsnull;
00156   return NS_OK;
00157 }
00158 
00159 
00160 
00161 // Get a handle to the nsIWebBrowser object. 
00162 NS_IMETHODIMP
00163 nsQABrowserView::GetWebBrowser(nsIWebBrowser ** aWebBrowser)
00164 {
00165   if (!mWebBrowser || !(aWebBrowser))
00166     return NS_ERROR_FAILURE;
00167   
00168   *aWebBrowser = mWebBrowser;
00169   NS_ADDREF(*aWebBrowser);
00170   return NS_OK;
00171 }
00172