1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3
* The contents of this file are subject to the Netscape Public
4
* License Version 1.1 (the "License"); you may not use this file
5
* except in compliance with the License. You may obtain a copy of
6
* the License at http://www.mozilla.org/NPL/
8
* Software distributed under the License is distributed on an "AS
9
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
10
* implied. See the License for the specific language governing
11
* rights and limitations under the License.
13
* The Original Code is Mozilla Communicator client code.
15
* The Initial Developer of the Original Code is Netscape Communications
16
* Corporation. Portions created by Netscape are
17
* Copyright (C) 1998 Netscape Communications Corporation. All
21
* Alec Flett <alecf@netscape.com>
26
#include "nsHistoryLoadListener.h"
27
#include "nsIGlobalHistory.h"
29
#include "nsIServiceManager.h"
30
#include "nsICategoryManager.h"
32
#include "nsXPIDLString.h"
34
#include "nsIDocumentLoader.h"
35
#include "nsIWebProgress.h"
36
#include "nsIRequestObserver.h"
37
#include "nsCURILoader.h"
40
#include "nsIDOMWindow.h"
41
#include "nsIDOMHTMLDocument.h"
42
#include "nsIDocument.h"
45
static NS_DEFINE_IID(kDocLoaderServiceCID, NS_DOCUMENTLOADER_SERVICE_CID);
47
nsHistoryLoadListener::nsHistoryLoadListener(nsIBrowserHistory *aHistory)
50
printf("Creating nsHistoryLoadListener\n");
53
nsHistoryLoadListener::~nsHistoryLoadListener()
59
nsHistoryLoadListener::Init()
63
// the global docloader
64
nsCOMPtr<nsIDocumentLoader> docLoaderService =
65
do_GetService(kDocLoaderServiceCID, &rv);
66
if (NS_FAILED(rv)) return rv;
68
printf("Have docloader\n");
70
nsCOMPtr<nsIWebProgress> progress =
71
do_QueryInterface(docLoaderService, &rv);
72
if (NS_FAILED(rv)) return rv;
74
printf("have web progress\n");
77
rv = progress->AddProgressListener(NS_STATIC_CAST(nsIWebProgressListener*,
79
nsIWebProgress::NOTIFY_STATE_DOCUMENT);
80
printf("\tSuccess: %8.8X\n", rv);
85
NS_IMPL_ISUPPORTS2(nsHistoryLoadListener,
86
nsIWebProgressListener,
87
nsISupportsWeakReference)
89
/* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aStateFlags, in nsresult aStatus); */
91
nsHistoryLoadListener::OnStateChange(nsIWebProgress *aWebProgress,
93
PRUint32 aStateFlags, nsresult aStatus)
95
// we only care about finishing up documents
96
if (! (aStateFlags & nsIWebProgressListener::STATE_STOP))
101
nsCOMPtr<nsIDOMWindow> window;
102
rv = aWebProgress->GetDOMWindow(getter_AddRefs(window));
103
if (NS_FAILED(rv)) return rv;
105
nsCOMPtr<nsIDOMDocument> domDoc;
107
rv = window->GetDocument(getter_AddRefs(domDoc));
108
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
109
if (!doc) return NS_OK;
111
nsCOMPtr<nsIURI> uri;
112
rv = doc->GetDocumentURI(getter_AddRefs(uri));
113
if (NS_FAILED(rv)) return rv;
115
nsXPIDLCString urlString;
116
uri->GetSpec(getter_Copies(urlString));
118
if (aStatus == NS_BINDING_REDIRECTED) {
120
mHistory->HidePage(urlString);
123
nsCOMPtr<nsIDOMHTMLDocument> htmlDoc = do_QueryInterface(doc);
125
// there should be a better way to handle non-html docs
126
if (!htmlDoc) return NS_OK;
127
// somehow get the title, and store it in history
129
htmlDoc->GetTitle(title);
131
mHistory->SetPageTitle(urlString, title.get());
134
nsAutoString referrer;
135
htmlDoc->GetReferrer(referrer);
136
mHistory->SetReferrer(urlString, referrer.get());
139
printf("nsHistoryLoadListener::OnStateChange(w,r, %8.8X, %d)\n", aStateFlags, aStatus);
143
/* void onProgressChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aCurSelfProgress, in long aMaxSelfProgress, in long aCurTotalProgress, in long aMaxTotalProgress); */
145
nsHistoryLoadListener::OnProgressChange(nsIWebProgress *aWebProgress,
146
nsIRequest *aRequest,
147
PRInt32 aCurSelfProgress,
148
PRInt32 aMaxSelfProgress,
149
PRInt32 aCurTotalProgress,
150
PRInt32 aMaxTotalProgress)
152
NS_NOTREACHED("notification excluded in AddProgressListener(...)");
156
/* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location); */
157
NS_IMETHODIMP nsHistoryLoadListener::OnLocationChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsIURI *location)
159
NS_NOTREACHED("notification excluded in AddProgressListener(...)");
163
/* void onStatusChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage); */
164
NS_IMETHODIMP nsHistoryLoadListener::OnStatusChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsresult aStatus, const PRUnichar *aMessage)
166
NS_NOTREACHED("notification excluded in AddProgressListener(...)");
170
/* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long state); */
171
NS_IMETHODIMP nsHistoryLoadListener::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 state)
173
NS_NOTREACHED("notification excluded in AddProgressListener(...)");