Back to index

lightning-sunbird  0.9+nobinonly
EmbedProgress.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is mozilla.org code.
00017  *
00018  * The Initial Developer of the Original Code is
00019  *  Zack Rusin <zack@kde.org>.
00020  * Portions created by the Initial Developer are Copyright (C) 2004
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   Lars Knoll <knoll@kde.org>
00025  *   Zack Rusin <zack@kde.org>
00026  *
00027  * Alternatively, the contents of this file may be used under the terms of
00028  * either the GNU General Public License Version 2 or later (the "GPL"), or
00029  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00030  * in which case the provisions of the GPL or the LGPL are applicable instead
00031  * of those above. If you wish to allow use of your version of this file only
00032  * under the terms of either the GPL or the LGPL, and not to allow others to
00033  * use your version of this file under the terms of the MPL, indicate your
00034  * decision by deleting the provisions above and replace them with the notice
00035  * and other provisions required by the GPL or the LGPL. If you do not delete
00036  * the provisions above, a recipient may use your version of this file under
00037  * the terms of any one of the MPL, the GPL or the LGPL.
00038  *
00039  * ***** END LICENSE BLOCK ***** */
00040 #include "EmbedProgress.h"
00041 
00042 #include "qgeckoembed.h"
00043 
00044 #include <nsXPIDLString.h>
00045 #include <nsIChannel.h>
00046 #include <nsIWebProgress.h>
00047 #include <nsIDOMWindow.h>
00048 
00049 #include "nsIURI.h"
00050 #include "nsCRT.h"
00051 #include "nsString.h"
00052 
00053 EmbedProgress::EmbedProgress(QGeckoEmbed *aOwner)
00054 {
00055     qDebug("XXX EMBEDPROGRSS");
00056     mOwner = aOwner;
00057 }
00058 
00059 EmbedProgress::~EmbedProgress()
00060 {
00061     qDebug("#########################################################################################");
00062 }
00063 
00064 NS_IMPL_ISUPPORTS2(EmbedProgress,
00065                    nsIWebProgressListener,
00066                    nsISupportsWeakReference)
00067 
00068 NS_IMETHODIMP
00069 EmbedProgress::OnStateChange(nsIWebProgress *aWebProgress,
00070                              nsIRequest     *aRequest,
00071                              PRUint32        aStateFlags,
00072                              nsresult        aStatus)
00073 {
00074     // give the widget a chance to attach any listeners
00075     mOwner->contentStateChanged();
00076     // if we've got the start flag, emit the signal
00077     if ((aStateFlags & STATE_IS_NETWORK) &&
00078         (aStateFlags & STATE_START))
00079     {
00080         qDebug("net start");
00081         emit mOwner->netStart();
00082     }
00083 
00084     //XXX: emit state all here
00085 
00086     if ((aStateFlags & STATE_IS_NETWORK) &&
00087              (aStateFlags & STATE_STOP)) {
00088         //qDebug("progress: --stop");
00089         emit mOwner->netStop();
00090         mOwner->contentFinishedLoading();
00091     }
00092 
00093     return NS_OK;
00094 }
00095 
00096 NS_IMETHODIMP
00097 EmbedProgress::OnProgressChange(nsIWebProgress *aWebProgress,
00098                                 nsIRequest     *aRequest,
00099                                 PRInt32         aCurSelfProgress,
00100                                 PRInt32         aMaxSelfProgress,
00101                                 PRInt32         aCurTotalProgress,
00102                                 PRInt32         aMaxTotalProgress)
00103 {
00104 #if 0
00105     nsString tmpString;
00106     RequestToURIString(aRequest, tmpString);
00107     // is it the same as the current uri?
00108     if (mOwner->mURI.Equals(tmpString))
00109         mOwner->progressAll(QString(tmpString.get()), aCurTotalProgress, aMaxTotalProgress);
00110 #endif
00111     //qDebug("progress self: %d %d", aCurSelfProgress, aMaxSelfProgress);
00112 
00113     mOwner->progress(aCurTotalProgress, aMaxTotalProgress);
00114     return NS_OK;
00115 }
00116 
00117 NS_IMETHODIMP
00118 EmbedProgress::OnLocationChange(nsIWebProgress *aWebProgress,
00119                                 nsIRequest     *aRequest,
00120                                 nsIURI         *aLocation)
00121 {
00122     nsCAutoString newURI;
00123     NS_ENSURE_ARG_POINTER(aLocation);
00124     aLocation->GetSpec(newURI);
00125 
00126     // Make sure that this is the primary frame change and not
00127     // just a subframe.
00128     PRBool isSubFrameLoad = PR_FALSE;
00129     if (aWebProgress) {
00130         nsCOMPtr<nsIDOMWindow> domWindow;
00131         nsCOMPtr<nsIDOMWindow> topDomWindow;
00132 
00133         aWebProgress->GetDOMWindow(getter_AddRefs(domWindow));
00134 
00135         // get the root dom window
00136         if (domWindow)
00137             domWindow->GetTop(getter_AddRefs(topDomWindow));
00138 
00139         if (domWindow != topDomWindow)
00140             isSubFrameLoad = PR_TRUE;
00141     }
00142 
00143     if (!isSubFrameLoad)
00144         emit mOwner->locationChanged(newURI.get());
00145 
00146     return NS_OK;
00147 }
00148 
00149 NS_IMETHODIMP
00150 EmbedProgress::OnStatusChange(nsIWebProgress  *aWebProgress,
00151                               nsIRequest      *aRequest,
00152                               nsresult         aStatus,
00153                               const PRUnichar *aMessage)
00154 {
00155     QString message = QString::fromUcs2(aMessage);
00156     emit mOwner->linkMessage(message);
00157 
00158     return NS_OK;
00159 }
00160 
00161 NS_IMETHODIMP
00162 EmbedProgress::OnSecurityChange(nsIWebProgress *aWebProgress,
00163                                 nsIRequest     *aRequest,
00164                                 PRUint32         aState)
00165 {
00166     //FIXME:
00167     //emit mOwner->securityChange(aRequest, aState);
00168 
00169     return NS_OK;
00170 }
00171 
00172 /* static */
00173 void
00174 EmbedProgress::RequestToURIString(nsIRequest *aRequest, nsString &aString)
00175 {
00176     // is it a channel
00177     nsCOMPtr<nsIChannel> channel;
00178     channel = do_QueryInterface(aRequest);
00179     if (!channel)
00180         return;
00181 
00182     nsCOMPtr<nsIURI> uri;
00183     channel->GetURI(getter_AddRefs(uri));
00184     if (!uri)
00185         return;
00186 
00187     nsCAutoString uriString;
00188     uri->GetSpec(uriString);
00189 
00190     CopyUTF8toUTF16(uriString, aString);
00191 }