1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright © 2001, 2004 Philip Langdale
4 * Copyright © 2004 Christian Persch
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #include "mozilla-config.h"
26 #include <nsStringAPI.h>
30 #include "ephy-embed-shell.h"
32 #include "GlobalHistory.h"
35 #define MAX_TITLE_LENGTH 2048
36 #define MAX_URL_LENGTH 16384
38 #ifdef HAVE_NSIGLOBALHISTORY3_H
39 NS_IMPL_ISUPPORTS2 (MozGlobalHistory, nsIGlobalHistory2, nsIGlobalHistory3)
41 NS_IMPL_ISUPPORTS1 (MozGlobalHistory, nsIGlobalHistory2)
42 #endif /* HAVE_NSIGLOBALHISTORY3_H */
44 MozGlobalHistory::MozGlobalHistory ()
46 mGlobalHistory = EPHY_HISTORY (ephy_embed_shell_get_global_history (embed_shell));
48 mHistoryListener = new EphyHistoryListener ();
49 mHistoryListener->Init (mGlobalHistory);
52 MozGlobalHistory::~MozGlobalHistory ()
56 /* void addURI (in nsIURI aURI, in boolean aRedirect, in boolean aToplevel, in nsIURI aReferrer); */
57 NS_IMETHODIMP MozGlobalHistory::AddURI(nsIURI *aURI,
66 // filter out unwanted URIs such as chrome: etc
67 // The model is really if we don't know differently then add which basically
68 // means we are suppose to try all the things we know not to allow in and
69 // then if we don't bail go on and allow it in. But here lets compare
70 // against the most common case we know to allow in and go on and say yes
73 PRBool isHTTP = PR_FALSE, isHTTPS = PR_FALSE;
74 rv = aURI->SchemeIs("http", &isHTTP);
75 rv |= aURI->SchemeIs("https", &isHTTPS);
76 NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE);
78 if (!isHTTP && !isHTTPS)
80 static const char *schemes[] = { "javascript",
87 for (PRUint32 i = 0; i < G_N_ELEMENTS (schemes); ++i)
89 PRBool result = PR_FALSE;
90 if (NS_SUCCEEDED (aURI->SchemeIs (schemes[i], &result)) && result)
98 rv = aURI->GetSpec(spec);
99 NS_ENSURE_TRUE (NS_SUCCEEDED(rv) && spec.Length(), rv);
101 if (spec.Length () > MAX_URL_LENGTH) return NS_OK;
103 ephy_history_add_page (mGlobalHistory, spec.get(), aRedirect, aToplevel);
108 /* boolean isVisited (in nsIURI aURI); */
109 NS_IMETHODIMP MozGlobalHistory::IsVisited(nsIURI *aURI,
112 NS_ENSURE_ARG (aURI);
119 if (spec.Length () > MAX_URL_LENGTH) return NS_OK;
121 *_retval = ephy_history_is_page_visited (mGlobalHistory, spec.get());
126 /* void setPageTitle (in nsIURI aURI, in AString aTitle); */
127 NS_IMETHODIMP MozGlobalHistory::SetPageTitle(nsIURI *aURI,
128 const nsAString & aTitle)
130 NS_ENSURE_ARG (aURI);
135 if (spec.Length () > MAX_URL_LENGTH) return NS_OK;
137 nsString uTitle (aTitle);
139 /* This depends on the assumption that
140 * typeof(PRUnichar) == typeof (gunichar2) == uint16,
141 * which should be pretty safe.
143 glong n_read = 0, n_written = 0;
144 char *converted = g_utf16_to_utf8 ((gunichar2*) uTitle.get(), MAX_TITLE_LENGTH,
145 &n_read, &n_written, NULL);
146 /* FIXME loop from the end while !g_unichar_isspace (char)? */
147 if (converted == NULL) return NS_OK;
149 ephy_history_set_page_title (mGlobalHistory, spec.get(), converted);
156 #ifdef HAVE_NSIGLOBALHISTORY3_H
158 #ifdef HAVE_GECKO_1_9
160 /* unsigned long getURIGeckoFlags(in nsIURI aURI); */
162 MozGlobalHistory::GetURIGeckoFlags(nsIURI *aURI,
170 if (spec.Length () > MAX_URL_LENGTH) return NS_OK;
172 EphyNode *page = ephy_history_get_page (mGlobalHistory, spec.get());
174 GValue value = { 0, };
176 ephy_node_get_property (page, EPHY_NODE_PAGE_PROP_GECKO_FLAGS, &value))
178 *aFlags = (PRUint32) (gulong) g_value_get_long (&value);
179 g_value_unset (&value);
184 return NS_ERROR_FAILURE;
187 /* void setURIGeckoFlags(in nsIURI aURI, in unsigned long aFlags); */
189 MozGlobalHistory::SetURIGeckoFlags(nsIURI *aURI,
195 if (spec.Length () > MAX_URL_LENGTH) return NS_OK;
197 EphyNode *page = ephy_history_get_page (mGlobalHistory, spec.get());
200 ephy_node_set_property_long (page,
201 EPHY_NODE_PAGE_PROP_GECKO_FLAGS,
206 return NS_ERROR_FAILURE;
209 #endif /* HAVE_GECKO_1_9 */
211 /* void addDocumentRedirect (in nsIChannel
213 in nsIChannel aNewChannel,
215 in boolean aTopLevel); */
217 MozGlobalHistory::AddDocumentRedirect(nsIChannel *aOldChannel,
218 nsIChannel *aNewChannel,
222 return NS_ERROR_NOT_IMPLEMENTED;
225 #endif /* HAVE_NSIGLOBALHISTORY3_H */