~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/xpfe/components/history/src/nsHistoryLoadListener.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 
2
 *
 
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/
 
7
 *
 
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.
 
12
 *
 
13
 * The Original Code is Mozilla Communicator client code.
 
14
 *
 
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
 
18
 * Rights Reserved.
 
19
 *
 
20
 * Original Author(s):
 
21
 *   Alec Flett <alecf@netscape.com>
 
22
 *
 
23
 * Contributor(s): 
 
24
 */
 
25
 
 
26
#include "nsHistoryLoadListener.h"
 
27
#include "nsIGlobalHistory.h"
 
28
 
 
29
#include "nsIServiceManager.h"
 
30
#include "nsICategoryManager.h"
 
31
#include "nsString.h"
 
32
#include "nsXPIDLString.h"
 
33
 
 
34
#include "nsIDocumentLoader.h"
 
35
#include "nsIWebProgress.h"
 
36
#include "nsIRequestObserver.h"
 
37
#include "nsCURILoader.h"
 
38
 
 
39
 
 
40
#include "nsIDOMWindow.h"
 
41
#include "nsIDOMHTMLDocument.h"
 
42
#include "nsIDocument.h"
 
43
#include "nsIURI.h"
 
44
 
 
45
static NS_DEFINE_IID(kDocLoaderServiceCID, NS_DOCUMENTLOADER_SERVICE_CID);
 
46
 
 
47
nsHistoryLoadListener::nsHistoryLoadListener(nsIBrowserHistory *aHistory)
 
48
{
 
49
    mHistory = aHistory;
 
50
    printf("Creating nsHistoryLoadListener\n");
 
51
}
 
52
 
 
53
nsHistoryLoadListener::~nsHistoryLoadListener()
 
54
{
 
55
 
 
56
}
 
57
 
 
58
nsresult
 
59
nsHistoryLoadListener::Init()
 
60
{
 
61
    nsresult rv;
 
62
 
 
63
    // the global docloader
 
64
    nsCOMPtr<nsIDocumentLoader> docLoaderService =
 
65
        do_GetService(kDocLoaderServiceCID, &rv);
 
66
    if (NS_FAILED(rv)) return rv;
 
67
 
 
68
    printf("Have docloader\n");
 
69
    
 
70
    nsCOMPtr<nsIWebProgress> progress =
 
71
        do_QueryInterface(docLoaderService, &rv);
 
72
    if (NS_FAILED(rv)) return rv;
 
73
 
 
74
    printf("have web progress\n");
 
75
 
 
76
    NS_ADDREF_THIS();
 
77
    rv = progress->AddProgressListener(NS_STATIC_CAST(nsIWebProgressListener*,
 
78
                                                      this),
 
79
                                       nsIWebProgress::NOTIFY_STATE_DOCUMENT);
 
80
    printf("\tSuccess: %8.8X\n", rv);
 
81
    
 
82
    return NS_OK;
 
83
}
 
84
 
 
85
NS_IMPL_ISUPPORTS2(nsHistoryLoadListener,
 
86
                   nsIWebProgressListener,
 
87
                   nsISupportsWeakReference)
 
88
 
 
89
/* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aStateFlags, in nsresult aStatus); */
 
90
NS_IMETHODIMP
 
91
nsHistoryLoadListener::OnStateChange(nsIWebProgress *aWebProgress,
 
92
                                     nsIRequest *aRequest,
 
93
                                     PRUint32 aStateFlags, nsresult aStatus)
 
94
{
 
95
    // we only care about finishing up documents
 
96
    if (! (aStateFlags & nsIWebProgressListener::STATE_STOP))
 
97
        return NS_OK;
 
98
 
 
99
    nsresult rv;
 
100
    
 
101
    nsCOMPtr<nsIDOMWindow> window;
 
102
    rv = aWebProgress->GetDOMWindow(getter_AddRefs(window));
 
103
    if (NS_FAILED(rv)) return rv;
 
104
 
 
105
    nsCOMPtr<nsIDOMDocument> domDoc;
 
106
 
 
107
    rv = window->GetDocument(getter_AddRefs(domDoc));
 
108
    nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
 
109
    if (!doc) return NS_OK;
 
110
 
 
111
    nsCOMPtr<nsIURI> uri;
 
112
    rv = doc->GetDocumentURI(getter_AddRefs(uri));
 
113
    if (NS_FAILED(rv)) return rv;
 
114
        
 
115
    nsXPIDLCString urlString;
 
116
    uri->GetSpec(getter_Copies(urlString));
 
117
    
 
118
    if (aStatus == NS_BINDING_REDIRECTED) {
 
119
        
 
120
        mHistory->HidePage(urlString);
 
121
        
 
122
    } else {
 
123
        nsCOMPtr<nsIDOMHTMLDocument> htmlDoc = do_QueryInterface(doc);
 
124
 
 
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
 
128
        nsAutoString title;
 
129
        htmlDoc->GetTitle(title);
 
130
 
 
131
        mHistory->SetPageTitle(urlString, title.get());
 
132
 
 
133
#if 0
 
134
        nsAutoString referrer;
 
135
        htmlDoc->GetReferrer(referrer);
 
136
        mHistory->SetReferrer(urlString, referrer.get());
 
137
#endif
 
138
    }
 
139
    printf("nsHistoryLoadListener::OnStateChange(w,r, %8.8X, %d)\n", aStateFlags, aStatus);
 
140
    return NS_OK;
 
141
}
 
142
 
 
143
/* void onProgressChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aCurSelfProgress, in long aMaxSelfProgress, in long aCurTotalProgress, in long aMaxTotalProgress); */
 
144
NS_IMETHODIMP
 
145
nsHistoryLoadListener::OnProgressChange(nsIWebProgress *aWebProgress,
 
146
                                        nsIRequest *aRequest,
 
147
                                        PRInt32 aCurSelfProgress,
 
148
                                        PRInt32 aMaxSelfProgress,
 
149
                                        PRInt32 aCurTotalProgress,
 
150
                                        PRInt32 aMaxTotalProgress)
 
151
{
 
152
    NS_NOTREACHED("notification excluded in AddProgressListener(...)");
 
153
    return NS_OK;
 
154
}
 
155
 
 
156
/* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location); */
 
157
NS_IMETHODIMP nsHistoryLoadListener::OnLocationChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsIURI *location)
 
158
{
 
159
    NS_NOTREACHED("notification excluded in AddProgressListener(...)");
 
160
    return NS_OK;
 
161
}
 
162
 
 
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)
 
165
{
 
166
    NS_NOTREACHED("notification excluded in AddProgressListener(...)");
 
167
    return NS_OK;
 
168
}
 
169
 
 
170
/* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long state); */
 
171
NS_IMETHODIMP nsHistoryLoadListener::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 state)
 
172
{
 
173
    NS_NOTREACHED("notification excluded in AddProgressListener(...)");
 
174
    return NS_OK;
 
175
}
 
176