2007-03-22 10:30:00 -07:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
2007-12-18 09:42:44 -08:00
|
|
|
* Christopher Blizzard.
|
2007-03-22 10:30:00 -07:00
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2001
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Christopher Blizzard <blizzard@mozilla.org>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include "EmbedProgress.h"
|
|
|
|
|
2008-01-29 20:28:26 -08:00
|
|
|
#include "nsIChannel.h"
|
|
|
|
#include "nsIWebProgress.h"
|
|
|
|
#include "nsIDOMWindow.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsIURI.h"
|
|
|
|
|
|
|
|
EmbedProgress::EmbedProgress(void)
|
|
|
|
{
|
|
|
|
mOwner = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
EmbedProgress::~EmbedProgress()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS2(EmbedProgress,
|
2007-12-17 16:33:03 -08:00
|
|
|
nsIWebProgressListener,
|
|
|
|
nsISupportsWeakReference)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
EmbedProgress::Init(EmbedPrivate *aOwner)
|
|
|
|
{
|
|
|
|
mOwner = aOwner;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
EmbedProgress::OnStateChange(nsIWebProgress *aWebProgress,
|
2007-12-17 16:33:03 -08:00
|
|
|
nsIRequest *aRequest,
|
|
|
|
PRUint32 aStateFlags,
|
|
|
|
nsresult aStatus)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// give the widget a chance to attach any listeners
|
|
|
|
mOwner->ContentStateChange();
|
|
|
|
// if we've got the start flag, emit the signal
|
2007-12-17 16:33:03 -08:00
|
|
|
if ((aStateFlags & GTK_MOZ_EMBED_FLAG_IS_NETWORK) &&
|
|
|
|
(aStateFlags & GTK_MOZ_EMBED_FLAG_START))
|
|
|
|
{
|
2008-01-11 14:16:15 -08:00
|
|
|
g_signal_emit(G_OBJECT(mOwner->mOwningWidget),
|
|
|
|
moz_embed_signals[NET_START], 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-12-17 16:33:03 -08:00
|
|
|
// get the uri for this request
|
2008-01-10 01:01:11 -08:00
|
|
|
nsCAutoString uriString;
|
|
|
|
RequestToURIString(aRequest, uriString);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// is it the same as the current URI?
|
2008-01-10 01:01:11 -08:00
|
|
|
if (mOwner->mURI.Equals(uriString))
|
2007-12-17 16:33:03 -08:00
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
// for people who know what they are doing
|
2008-01-11 14:16:15 -08:00
|
|
|
g_signal_emit(G_OBJECT(mOwner->mOwningWidget),
|
|
|
|
moz_embed_signals[NET_STATE], 0,
|
|
|
|
aStateFlags, aStatus);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-01-11 14:16:15 -08:00
|
|
|
g_signal_emit(G_OBJECT(mOwner->mOwningWidget),
|
|
|
|
moz_embed_signals[NET_STATE_ALL], 0,
|
|
|
|
uriString.get(),
|
|
|
|
(gint)aStateFlags, (gint)aStatus);
|
2007-03-22 10:30:00 -07:00
|
|
|
// and for stop, too
|
2008-01-11 14:16:15 -08:00
|
|
|
if ((aStateFlags & GTK_MOZ_EMBED_FLAG_IS_NETWORK) &&
|
2007-12-17 16:33:03 -08:00
|
|
|
(aStateFlags & GTK_MOZ_EMBED_FLAG_STOP))
|
|
|
|
{
|
2008-01-11 14:16:15 -08:00
|
|
|
g_signal_emit(G_OBJECT(mOwner->mOwningWidget),
|
|
|
|
moz_embed_signals[NET_STOP], 0);
|
2007-12-17 16:33:03 -08:00
|
|
|
// let our owner know that the load finished
|
|
|
|
mOwner->ContentFinishedLoading();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
EmbedProgress::OnProgressChange(nsIWebProgress *aWebProgress,
|
2007-12-17 16:33:03 -08:00
|
|
|
nsIRequest *aRequest,
|
|
|
|
PRInt32 aCurSelfProgress,
|
|
|
|
PRInt32 aMaxSelfProgress,
|
|
|
|
PRInt32 aCurTotalProgress,
|
|
|
|
PRInt32 aMaxTotalProgress)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-12-17 16:33:03 -08:00
|
|
|
|
2008-01-10 01:01:11 -08:00
|
|
|
nsCAutoString uriString;
|
|
|
|
RequestToURIString(aRequest, uriString);
|
2008-01-11 14:16:15 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// is it the same as the current uri?
|
2008-01-10 01:01:11 -08:00
|
|
|
if (mOwner->mURI.Equals(uriString)) {
|
2008-01-11 14:16:15 -08:00
|
|
|
g_signal_emit(G_OBJECT(mOwner->mOwningWidget),
|
|
|
|
moz_embed_signals[PROGRESS], 0,
|
|
|
|
aCurTotalProgress, aMaxTotalProgress);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-01-11 14:16:15 -08:00
|
|
|
g_signal_emit(G_OBJECT(mOwner->mOwningWidget),
|
|
|
|
moz_embed_signals[PROGRESS_ALL], 0,
|
|
|
|
uriString.get(),
|
|
|
|
aCurTotalProgress, aMaxTotalProgress);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
EmbedProgress::OnLocationChange(nsIWebProgress *aWebProgress,
|
2007-12-17 16:33:03 -08:00
|
|
|
nsIRequest *aRequest,
|
|
|
|
nsIURI *aLocation)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsCAutoString newURI;
|
|
|
|
NS_ENSURE_ARG_POINTER(aLocation);
|
|
|
|
aLocation->GetSpec(newURI);
|
|
|
|
|
|
|
|
// Make sure that this is the primary frame change and not
|
|
|
|
// just a subframe.
|
|
|
|
PRBool isSubFrameLoad = PR_FALSE;
|
|
|
|
if (aWebProgress) {
|
|
|
|
nsCOMPtr<nsIDOMWindow> domWindow;
|
|
|
|
nsCOMPtr<nsIDOMWindow> topDomWindow;
|
|
|
|
|
|
|
|
aWebProgress->GetDOMWindow(getter_AddRefs(domWindow));
|
|
|
|
|
|
|
|
// get the root dom window
|
|
|
|
if (domWindow)
|
|
|
|
domWindow->GetTop(getter_AddRefs(topDomWindow));
|
|
|
|
|
|
|
|
if (domWindow != topDomWindow)
|
|
|
|
isSubFrameLoad = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isSubFrameLoad) {
|
|
|
|
mOwner->SetURI(newURI.get());
|
2008-01-11 14:16:15 -08:00
|
|
|
g_signal_emit(G_OBJECT(mOwner->mOwningWidget),
|
|
|
|
moz_embed_signals[LOCATION], 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
EmbedProgress::OnStatusChange(nsIWebProgress *aWebProgress,
|
2007-12-17 16:33:03 -08:00
|
|
|
nsIRequest *aRequest,
|
|
|
|
nsresult aStatus,
|
|
|
|
const PRUnichar *aMessage)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-01-11 14:16:15 -08:00
|
|
|
g_signal_emit(G_OBJECT(mOwner->mOwningWidget),
|
|
|
|
moz_embed_signals[STATUS_CHANGE], 0,
|
|
|
|
static_cast<void *>(aRequest),
|
|
|
|
static_cast<int>(aStatus),
|
|
|
|
static_cast<const void *>(aMessage));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
EmbedProgress::OnSecurityChange(nsIWebProgress *aWebProgress,
|
2007-12-17 16:33:03 -08:00
|
|
|
nsIRequest *aRequest,
|
|
|
|
PRUint32 aState)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-01-11 14:16:15 -08:00
|
|
|
g_signal_emit(G_OBJECT(mOwner->mOwningWidget),
|
|
|
|
moz_embed_signals[SECURITY_CHANGE], 0,
|
|
|
|
static_cast<void *>(aRequest),
|
|
|
|
aState);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
void
|
2008-01-10 01:01:11 -08:00
|
|
|
EmbedProgress::RequestToURIString(nsIRequest *aRequest, nsACString &aString)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// is it a channel
|
|
|
|
nsCOMPtr<nsIChannel> channel;
|
|
|
|
channel = do_QueryInterface(aRequest);
|
|
|
|
if (!channel)
|
|
|
|
return;
|
2007-12-17 16:33:03 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
channel->GetURI(getter_AddRefs(uri));
|
|
|
|
if (!uri)
|
|
|
|
return;
|
2007-12-17 16:33:03 -08:00
|
|
|
|
2008-01-10 01:01:11 -08:00
|
|
|
uri->GetSpec(aString);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|