From d436ad454ddabc23d7ec28577db148c110641d64 Mon Sep 17 00:00:00 2001 From: "bsmedberg%covad.net" Date: Wed, 11 Feb 2004 02:10:04 +0000 Subject: [PATCH] Bug 224829 - docshell should not require non-gecko interface nsIBrowserHistory. This was fixed by introducing a new interface nsIGlobalHistory2 to replace the current nsIGlobalHistory. There are two-way adapters so that the frozen interface still works. r=biesi sr=bz a=mscott for toolkit/ changes. git-svn-id: svn://10.0.0.236/trunk@152632 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/Makefile.in | 12 +- mozilla/browser/base/content/browser.js | 15 +- .../browser/base/content/contentAreaUtils.js | 34 +-- .../prefwindow/content/pref-privacy.js | 4 +- mozilla/docshell/base/Makefile.in | 7 + mozilla/docshell/base/nsDocShell.cpp | 158 ++-------- mozilla/docshell/base/nsDocShell.h | 7 +- .../docshell/base/nsGlobalHistory2Adapter.cpp | 176 ++++++++++++ .../docshell/base/nsGlobalHistory2Adapter.h | 76 +++++ .../docshell/base/nsGlobalHistoryAdapter.cpp | 199 +++++++++++++ .../docshell/base/nsGlobalHistoryAdapter.h | 77 +++++ mozilla/docshell/base/nsIDocShellHistory.idl | 16 +- mozilla/docshell/base/nsIGlobalHistory.idl | 10 +- mozilla/docshell/base/nsIGlobalHistory2.idl | 82 ++++++ mozilla/docshell/base/nsWebShell.cpp | 5 +- mozilla/docshell/build/Makefile.in | 4 + mozilla/docshell/build/nsDocShellCID.h | 44 +++ mozilla/docshell/build/nsDocShellModule.cpp | 14 +- .../browser/webBrowser/nsWebBrowser.cpp | 10 +- mozilla/embedding/lite/Makefile.in | 2 +- mozilla/rdf/Makefile.in | 7 - mozilla/toolkit/components/build/nsModule.cpp | 3 +- .../components/build/nsToolkitCompsCID.h | 7 + .../components/history/public/Makefile.in | 1 - .../history/public/nsIBrowserHistory.idl | 52 +--- .../history/public/nsIGlobalHistory.idl | 81 ------ .../components/history/src/Makefile.in | 1 + .../history/src/nsGlobalHistory.cpp | 269 +++++++++++------- .../components/history/src/nsGlobalHistory.h | 7 +- mozilla/toolkit/content/widgets/browser.xml | 6 +- mozilla/uriloader/exthandler/Makefile.in | 2 +- .../browser/resources/content/navigator.js | 10 +- .../resources/content/sessionHistoryUI.js | 2 +- .../xpfe/browser/src/nsBrowserInstance.cpp | 5 +- mozilla/xpfe/components/build/nsModule.cpp | 10 +- .../components/history/public/Makefile.in | 3 - .../history/public/nsIBrowserHistory.idl | 42 ++- .../history/public/nsIGlobalHistory.idl | 81 ------ .../xpfe/components/history/src/Makefile.in | 1 + .../history/src/nsGlobalHistory.cpp | 220 ++++++++------ .../components/history/src/nsGlobalHistory.h | 6 +- .../resources/content/pref-history.xul | 4 +- .../resources/content/bindings/browser.xml | 6 +- 43 files changed, 1120 insertions(+), 658 deletions(-) create mode 100644 mozilla/docshell/base/nsGlobalHistory2Adapter.cpp create mode 100644 mozilla/docshell/base/nsGlobalHistory2Adapter.h create mode 100644 mozilla/docshell/base/nsGlobalHistoryAdapter.cpp create mode 100644 mozilla/docshell/base/nsGlobalHistoryAdapter.h create mode 100644 mozilla/docshell/base/nsIGlobalHistory2.idl create mode 100644 mozilla/docshell/build/nsDocShellCID.h delete mode 100644 mozilla/toolkit/components/history/public/nsIGlobalHistory.idl delete mode 100644 mozilla/xpfe/components/history/public/nsIGlobalHistory.idl diff --git a/mozilla/Makefile.in b/mozilla/Makefile.in index 196ac911cf0..efa64a1c6a6 100644 --- a/mozilla/Makefile.in +++ b/mozilla/Makefile.in @@ -205,10 +205,12 @@ tier_9_dirs += \ xpfe/components/xremote/public \ $(NULL) +ifdef MOZ_XUL ifdef MOZ_XUL_APP -tier_9_dirs += toolkit/components/history/public chrome +tier_9_dirs += chrome else -tier_9_dirs += xpfe/components/history/public +tier_9_dirs += rdf/chrome +endif endif ifdef ACCESSIBILITY @@ -239,6 +241,12 @@ ifdef MOZ_JPROF tier_50_dirs += tools/jprof endif +ifdef MOZ_XUL_APP +tier_50_dirs += toolkit/components/history/public +else +tier_50_dirs += xpfe/components/history/public +endif + tier_50_dirs += xpfe themes ifdef MOZ_LEAKY diff --git a/mozilla/browser/base/content/browser.js b/mozilla/browser/base/content/browser.js index 34c5fdccb73..f09e47fd264 100644 --- a/mozilla/browser/base/content/browser.js +++ b/mozilla/browser/base/content/browser.js @@ -336,10 +336,8 @@ function prepareForStartup() webNavigation.sessionHistory = Components.classes["@mozilla.org/browser/shistory;1"] .createInstance(Components.interfaces.nsISHistory); - // wire up global history. the same applies here. - var globalHistory = Components.classes["@mozilla.org/browser/global-history;1"] - .getService(Components.interfaces.nsIGlobalHistory); - gBrowser.docShell.QueryInterface(Components.interfaces.nsIDocShellHistory).globalHistory = globalHistory; + // enable global history + gBrowser.docShell.QueryInterface(Components.interfaces.nsIDocShellHistory).useGlobalHistory = true; const selectedBrowser = gBrowser.selectedBrowser; if (selectedBrowser.securityUI) @@ -750,10 +748,9 @@ function updateGoMenu(goMenu) if (history.hidden) { history.hidden = false; - var globalHistory = Components.classes["@mozilla.org/browser/global-history;1"] - .getService(Components.interfaces.nsIGlobalHistory); - var dataSource = globalHistory.QueryInterface(Components.interfaces.nsIRDFDataSource); - history.database.AddDataSource(dataSource); + var globalHistory = Components.classes["@mozilla.org/browser/global-history;2"] + .getService(Components.interfaces.nsIRDFDataSource); + history.database.AddDataSource(globalHistory); } if (!history.ref) @@ -1783,7 +1780,7 @@ function addToUrlbarHistory() return; if (!gGlobalHistory) - gGlobalHistory = Components.classes["@mozilla.org/browser/global-history;1"] + gGlobalHistory = Components.classes["@mozilla.org/browser/global-history;2"] .getService(Components.interfaces.nsIBrowserHistory); if (!gURIFixup) diff --git a/mozilla/browser/base/content/contentAreaUtils.js b/mozilla/browser/base/content/contentAreaUtils.js index 34ff7af2a8a..36d9e767d55 100644 --- a/mozilla/browser/base/content/contentAreaUtils.js +++ b/mozilla/browser/base/content/contentAreaUtils.js @@ -63,22 +63,24 @@ function openNewWindowWith(href, linkNode, securityCheck) function markLinkVisited(href, linkNode) { - var globalHistory = Components.classes["@mozilla.org/browser/global-history;1"] - .getService(Components.interfaces.nsIGlobalHistory); - if (!globalHistory.isVisited(href)) { - globalHistory.addPage(href); - var oldHref = linkNode.getAttribute("href"); - if (typeof oldHref == "string") { - // Use setAttribute instead of direct assignment. - // (bug 217195, bug 187195) - linkNode.setAttribute("href", ""); - linkNode.setAttribute("href", oldHref); - } - else { - // Converting to string implicitly would be a - // minor security hole (similar to bug 202994). - } - } + var globalHistory = Components.classes["@mozilla.org/browser/global-history;2"] + .getService(Components.interfaces.nsIGlobalHistory2); + + var uri = makeURL(href); + if (!globalHistory.isVisited(uri)) { + globalHistory.addPage(uri, false, false); + var oldHref = linkNode.getAttribute("href"); + if (typeof oldHref == "string") { + // Use setAttribute instead of direct assignment. + // (bug 217195, bug 187195) + linkNode.setAttribute("href", ""); + linkNode.setAttribute("href", oldHref); + } + else { + // Converting to string implicitly would be a + // minor security hole (similar to bug 202994). + } + } } function urlSecurityCheck(url, doc) diff --git a/mozilla/browser/components/prefwindow/content/pref-privacy.js b/mozilla/browser/components/prefwindow/content/pref-privacy.js index 69df1ac825b..20102abcf9d 100644 --- a/mozilla/browser/components/prefwindow/content/pref-privacy.js +++ b/mozilla/browser/components/prefwindow/content/pref-privacy.js @@ -47,7 +47,7 @@ var _elementIDs = ["histDay", "browserCacheDiskCache", "cookieBehavior", "enable function Startup() { // Initially disable the clear buttons when needed - var globalHistory = Components.classes["@mozilla.org/browser/global-history;1"].getService(Components.interfaces.nsIBrowserHistory); + var globalHistory = Components.classes["@mozilla.org/browser/global-history;2"].getService(Components.interfaces.nsIBrowserHistory); document.getElementById("history").setAttribute("cleardisabled", globalHistory.count == 0); var cookieMgr = Components.classes["@mozilla.org/cookiemanager;1"].getService(); @@ -183,7 +183,7 @@ var PrivacyPanel = { // to them. history: function () { - var globalHistory = Components.classes["@mozilla.org/browser/global-history;1"] + var globalHistory = Components.classes["@mozilla.org/browser/global-history;2"] .getService(Components.interfaces.nsIBrowserHistory); globalHistory.removeAllPages(); diff --git a/mozilla/docshell/base/Makefile.in b/mozilla/docshell/base/Makefile.in index 36483a75a38..a38e711e239 100644 --- a/mozilla/docshell/base/Makefile.in +++ b/mozilla/docshell/base/Makefile.in @@ -65,6 +65,10 @@ REQUIRES = xpcom \ history \ $(NULL) +SDK_XPIDLSRCS = \ + nsIGlobalHistory.idl \ + $(NULL) + XPIDLSRCS = \ nsCDocShell.idl \ nsCDefaultURIFixup.idl \ @@ -74,6 +78,7 @@ XPIDLSRCS = \ nsIDocShellTreeNode.idl \ nsIDocShellTreeOwner.idl \ nsIDocShellHistory.idl \ + nsIGlobalHistory2.idl \ nsIMarkupDocumentViewer.idl \ nsIScrollable.idl \ nsITextScroll.idl \ @@ -95,6 +100,8 @@ CPPSRCS = \ nsDocShellEnumerator.cpp \ nsDSURIContentListener.cpp \ nsDefaultURIFixup.cpp \ + nsGlobalHistoryAdapter.cpp \ + nsGlobalHistory2Adapter.cpp \ $(NULL) # we don't want the shared lib, but we want to force the creation of a diff --git a/mozilla/docshell/base/nsDocShell.cpp b/mozilla/docshell/base/nsDocShell.cpp index ffbfa3f0b3b..0ec6f935fb4 100644 --- a/mozilla/docshell/base/nsDocShell.cpp +++ b/mozilla/docshell/base/nsDocShell.cpp @@ -33,6 +33,7 @@ #include "nsIDocumentLoaderFactory.h" #include "nsIPluginHost.h" #include "nsCURILoader.h" +#include "nsDocShellCID.h" #include "nsLayoutCID.h" #include "nsDOMCID.h" #include "nsIDOMScriptObjectFactory.h" @@ -126,9 +127,7 @@ #include "nsISelectionDisplay.h" -// this is going away - see -// -#include "nsIBrowserHistory.h" +#include "nsIGlobalHistory2.h" #ifdef DEBUG_DOCSHELL_FOCUS #include "nsIEventStateManager.h" @@ -2033,7 +2032,7 @@ nsDocShell::AddChild(nsIDocShellTreeItem * aChild) nsCOMPtr dsHistoryChild(do_QueryInterface(aChild)); if (dsHistoryChild) - dsHistoryChild->SetGlobalHistory(mGlobalHistory); + dsHistoryChild->SetUseGlobalHistory(PR_TRUE); } @@ -2311,19 +2310,27 @@ nsDocShell::AddChildSHEntry(nsISHEntry * aCloneRef, nsISHEntry * aNewEntry, } NS_IMETHODIMP -nsDocShell::SetGlobalHistory(nsIGlobalHistory * aGlobalHistory) +nsDocShell::SetUseGlobalHistory(PRBool aUseGlobalHistory) { - mGlobalHistory = aGlobalHistory; - return NS_OK; + nsresult rv; + + if (!aUseGlobalHistory) { + mGlobalHistory = nsnull; + return NS_OK; + } + + if (mGlobalHistory) { + return NS_OK; + } + + mGlobalHistory = do_GetService(NS_GLOBALHISTORY2_CONTRACTID, &rv); + return rv; } NS_IMETHODIMP -nsDocShell::GetGlobalHistory(nsIGlobalHistory ** aGlobalHistory) +nsDocShell::GetUseGlobalHistory(PRBool *aUseGlobalHistory) { - NS_ENSURE_ARG_POINTER(aGlobalHistory); - - *aGlobalHistory = mGlobalHistory; - NS_IF_ADDREF(*aGlobalHistory); + *aUseGlobalHistory = (mGlobalHistory != nsnull); return NS_OK; } @@ -2988,8 +2995,6 @@ nsDocShell::Create() nsresult rv = NS_ERROR_FAILURE; mPrefs = do_GetService(NS_PREF_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); - //GlobalHistory is now set in SetGlobalHistory - // mGlobalHistory = do_GetService(NS_GLOBALHISTORY_CONTRACTID); // i don't want to read this pref in every time we load a url // so read it in once here and be done with it... @@ -3370,12 +3375,7 @@ nsDocShell::SetTitle(const PRUnichar * aTitle) } if (mGlobalHistory && mCurrentURI) { - nsCAutoString url; - mCurrentURI->GetSpec(url); - nsCOMPtr browserHistory = - do_QueryInterface(mGlobalHistory); - if (browserHistory) - browserHistory->SetPageTitle(url.get(), aTitle); + mGlobalHistory->SetPageTitle(mCurrentURI, nsDependentString(aTitle)); } @@ -5143,7 +5143,7 @@ nsDocShell::InternalLoad(nsIURI * aURI, /* This is a anchor traversal with in the same page. * call OnNewURI() so that, this traversal will be * recorded in session and global history. - */ + */ OnNewURI(aURI, nsnull, mLoadType); nsCOMPtr postData; @@ -5979,7 +5979,7 @@ nsDocShell::OnNewURI(nsIURI * aURI, nsIChannel * aChannel, } // Update Global history - AddToGlobalHistory(aURI, IsFrame()); + AddToGlobalHistory(aURI, PR_FALSE); } // If this was a history load, update the index in @@ -6423,58 +6423,6 @@ nsDocShell::ShouldDiscardLayoutState(nsIHttpChannel * aChannel) return (noStore || (noCache && securityInfo)); } -//***************************************************************************** -// nsDocShell: Global History -//***************************************************************************** - -nsresult -nsDocShell::ShouldAddToGlobalHistory(nsIURI * aURI, PRBool * aShouldAdd) -{ - *aShouldAdd = PR_FALSE; - if (!mGlobalHistory || !aURI || (typeContent != mItemType)) - return NS_OK; - - // The model is really if we don't know differently then add which basically - // means we are suppose to try all the things we know not to allow in and - // then if we don't bail go on and allow it in. But here lets compare - // against the most common case we know to allow in and go on and say yes - // to it. - PRBool isHTTP = PR_FALSE; - PRBool isHTTPS = PR_FALSE; - NS_ENSURE_SUCCESS(aURI->SchemeIs("http", &isHTTP), NS_ERROR_FAILURE); - NS_ENSURE_SUCCESS(aURI->SchemeIs("https", &isHTTPS), NS_ERROR_FAILURE); - - if (isHTTP || isHTTPS) { - *aShouldAdd = PR_TRUE; - return NS_OK; - } - - PRBool isAbout = PR_FALSE; - PRBool isImap = PR_FALSE; - PRBool isNews = PR_FALSE; - PRBool isMailbox = PR_FALSE; - PRBool isViewSource = PR_FALSE; - PRBool isChrome = PR_FALSE; - PRBool isData = PR_FALSE; - - NS_ENSURE_SUCCESS(aURI->SchemeIs("about", &isAbout), NS_ERROR_FAILURE); - NS_ENSURE_SUCCESS(aURI->SchemeIs("imap", &isImap), NS_ERROR_FAILURE); - NS_ENSURE_SUCCESS(aURI->SchemeIs("news", &isNews), NS_ERROR_FAILURE); - NS_ENSURE_SUCCESS(aURI->SchemeIs("mailbox", &isMailbox), NS_ERROR_FAILURE); - NS_ENSURE_SUCCESS(aURI->SchemeIs("view-source", &isViewSource), - NS_ERROR_FAILURE); - NS_ENSURE_SUCCESS(aURI->SchemeIs("chrome", &isChrome), NS_ERROR_FAILURE); - NS_ENSURE_SUCCESS(aURI->SchemeIs("data", &isData), NS_ERROR_FAILURE); - - if (isAbout || isImap || isNews || isMailbox || isViewSource || isChrome || isData) - return NS_OK; - - *aShouldAdd = PR_TRUE; - return NS_OK; -} - - - //***************************************************************************** // nsDocShell: nsIEditorDocShell //***************************************************************************** @@ -6532,68 +6480,20 @@ NS_IMETHODIMP nsDocShell::MakeEditable(PRBool inWaitForUriLoad) } nsresult -nsDocShell::AddToGlobalHistory(nsIURI * aURI, PRBool aHidden) +nsDocShell::AddToGlobalHistory(nsIURI * aURI, PRBool aRedirect) { - // first check if we should be adding it - PRBool updateHistory; - ShouldAddToGlobalHistory(aURI, &updateHistory); - if (!updateHistory) return NS_OK; - - NS_ENSURE_STATE(mGlobalHistory); + if (mItemType != typeContent) + return NS_OK; - nsCAutoString spec; - NS_ENSURE_SUCCESS(aURI->GetSpec(spec), NS_ERROR_FAILURE); + if (!mGlobalHistory) + return NS_OK; - PRBool isJavascript; - NS_ENSURE_SUCCESS(aURI->SchemeIs("javascript", &isJavascript), NS_ERROR_FAILURE); - - nsCOMPtr browserHistory; - if (isJavascript || aHidden) { - browserHistory = do_QueryInterface(mGlobalHistory); - } - - // If this is a JS url, hide it in global history so that - // it doesn't show up in the autocomplete dropdown. AddPage() - // contains logic to unhide urls if they are typed, so this call - // to HidePage() needs to be before the AddPage() call. - // See bug 197127 and bug 161531 for more details. - if (isJavascript && browserHistory) { - browserHistory->HidePage(spec.get()); - } - - NS_ENSURE_SUCCESS(mGlobalHistory->AddPage(spec.get()), NS_ERROR_FAILURE); - - // Only save last page visited if it is not a frame and one of the - // startup, new window or new tab prefs is set to last page visited. - // See bug 58613 for more details. - if (mPrefs && !IsFrame()) { - PRInt32 choice = 0; - if (NS_SUCCEEDED(mPrefs->GetIntPref("browser.startup.page", &choice))) { - if (choice != 2) { - if (NS_SUCCEEDED(mPrefs->GetIntPref("browser.windows.loadOnNewWindow", &choice))) { - if (choice != 2) - mPrefs->GetIntPref("browser.tabs.loadOnNewTab", &choice); - } - } - } - if (choice == 2) { - browserHistory = do_QueryInterface(mGlobalHistory); - if (browserHistory) - browserHistory->SetLastPageVisited(spec.get()); - } - } - - // this is a redirect, hide the page from - // being enumerated in history - if (aHidden && browserHistory) { - browserHistory->HidePage(spec.get()); - } - return NS_OK; + return mGlobalHistory->AddURI(aURI, aRedirect, !IsFrame()); } //***************************************************************************** // nsDocShell: Helper Routines -//***************************************************************************** +//***************************************************************************** nsresult nsDocShell::SetLoadCookie(nsISupports * aCookie) diff --git a/mozilla/docshell/base/nsDocShell.h b/mozilla/docshell/base/nsDocShell.h index eac49d0b48a..bfc74735f8f 100644 --- a/mozilla/docshell/base/nsDocShell.h +++ b/mozilla/docshell/base/nsDocShell.h @@ -60,7 +60,7 @@ // Interfaces Needed #include "nsIDocumentCharsetInfo.h" #include "nsIDocCharset.h" -#include "nsIGlobalHistory.h" +#include "nsIGlobalHistory2.h" #include "nsIInterfaceRequestor.h" #include "nsIInterfaceRequestorUtils.h" #include "nsIPrompt.h" @@ -262,8 +262,7 @@ protected: PRBool ShouldDiscardLayoutState(nsIHttpChannel * aChannel); // Global History - nsresult ShouldAddToGlobalHistory(nsIURI * aURI, PRBool * aShouldAdd); - nsresult AddToGlobalHistory(nsIURI * aURI, PRBool ); + nsresult AddToGlobalHistory(nsIURI * aURI, PRBool aRedirect); // Helper Routines NS_IMETHOD GetPromptAndStringBundle(nsIPrompt ** aPrompt, @@ -327,7 +326,7 @@ protected: nsCOMPtr mScriptGlobal; nsCOMPtr mScriptContext; nsCOMPtr mSessionHistory; - nsCOMPtr mGlobalHistory; + nsCOMPtr mGlobalHistory; nsCOMPtr mLoadCookie; // the load cookie associated with the window context. nsCOMPtr mURIFixup; nsCOMPtr mFind; diff --git a/mozilla/docshell/base/nsGlobalHistory2Adapter.cpp b/mozilla/docshell/base/nsGlobalHistory2Adapter.cpp new file mode 100644 index 00000000000..d5159b4e47c --- /dev/null +++ b/mozilla/docshell/base/nsGlobalHistory2Adapter.cpp @@ -0,0 +1,176 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** 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 gecko code. + * + * The Initial Developer of the Original Code is + * Benjamin Smedberg + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * 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 "nsGlobalHistory2Adapter.h" + +#include "nsDocShellCID.h" +#include "nsIServiceManagerUtils.h" +#include "nsIComponentRegistrar.h" +#include "nsGlobalHistoryAdapter.h" +#include "nsIURI.h" +#include "nsString.h" +#include "nsNetUtil.h" + +// we should really have a nsIGenericFactory macro to make this a static +// member function + +nsresult +nsGlobalHistory2Adapter::Create(nsISupports *aOuter, + REFNSIID aIID, + void **aResult) +{ + nsresult rv; + + if (aOuter) { + rv = NS_ERROR_NO_AGGREGATION; + return rv; + } + + nsGlobalHistory2Adapter* adapter = new nsGlobalHistory2Adapter(); + if (!adapter) { + rv = NS_ERROR_OUT_OF_MEMORY; + return rv; + } + + NS_ADDREF(adapter); + rv = adapter->Init(); + if (NS_SUCCEEDED(rv)) { + rv = adapter->QueryInterface(aIID, aResult); + } + NS_RELEASE(adapter); + + return rv; +} + +nsresult +nsGlobalHistory2Adapter::RegisterSelf(nsIComponentManager* aCompMgr, + nsIFile* aPath, + const char* aLoaderStr, + const char* aType, + const nsModuleComponentInfo *aInfo) +{ + nsresult rv; + PRBool registered; + nsCOMPtr compReg( do_QueryInterface(aCompMgr) ); + if (!compReg) { + rv = NS_ERROR_UNEXPECTED; + return rv; + } + + rv = compReg->IsContractIDRegistered(NS_GLOBALHISTORY_CONTRACTID, ®istered); + if (NS_FAILED(rv)) return rv; + + // If the embedder has already registered the contractID, we don't want to + // register ourself. Ideally the component manager would handle this for us. + if (registered) { + rv = NS_OK; + return rv; + } + + return compReg->RegisterFactoryLocation(GetCID(), + "nsGlobalHistory2Adapter", + NS_GLOBALHISTORY_CONTRACTID, + aPath, aLoaderStr, aType); +} + +nsGlobalHistory2Adapter::nsGlobalHistory2Adapter() +{ } + +nsGlobalHistory2Adapter::~nsGlobalHistory2Adapter() +{ } + +nsresult +nsGlobalHistory2Adapter::Init() +{ + nsresult rv; + + nsCOMPtr compReg; + rv = NS_GetComponentRegistrar(getter_AddRefs(compReg)); + NS_ENSURE_SUCCESS(rv, rv); + + nsCID *cid; + rv = compReg->ContractIDToCID(NS_GLOBALHISTORY2_CONTRACTID, &cid); + if (NS_FAILED(rv)) { + rv = NS_ERROR_FACTORY_NOT_REGISTERED; + return rv; + } + + if (cid->Equals(nsGlobalHistoryAdapter::GetCID())) { + rv = NS_ERROR_FACTORY_NOT_REGISTERED; + return rv; + } + + NS_WARNING("Using nsIGlobalHistory->nsIGlobalHistory2 adapter."); + mHistory = do_GetService(NS_GLOBALHISTORY2_CONTRACTID, &rv); + return rv; +} + +NS_IMPL_ISUPPORTS1(nsGlobalHistory2Adapter, nsIGlobalHistory) + +NS_IMETHODIMP +nsGlobalHistory2Adapter::AddPage(const char* aURI) +{ + NS_ENSURE_ARG_POINTER(aURI); + NS_ENSURE_TRUE(*aURI, NS_ERROR_ILLEGAL_VALUE); + + nsresult rv; + + nsCOMPtr uri; + rv = NS_NewURI(getter_AddRefs(uri), nsDependentCString(aURI)); + + if (NS_SUCCEEDED(rv)) { + rv = mHistory->AddURI(uri, PR_FALSE, PR_FALSE); + } + + return rv; +} + +NS_IMETHODIMP +nsGlobalHistory2Adapter::IsVisited(const char* aURI, PRBool* aRetval) +{ + NS_ENSURE_ARG_POINTER(aURI); + nsresult rv; + + nsCOMPtr uri; + rv = NS_NewURI(getter_AddRefs(uri), nsDependentCString(aURI)); + + if (NS_SUCCEEDED(rv)) { + rv = mHistory->IsVisited(uri, aRetval); + } + + return rv; +} diff --git a/mozilla/docshell/base/nsGlobalHistory2Adapter.h b/mozilla/docshell/base/nsGlobalHistory2Adapter.h new file mode 100644 index 00000000000..5c93356d36e --- /dev/null +++ b/mozilla/docshell/base/nsGlobalHistory2Adapter.h @@ -0,0 +1,76 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** 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 gecko code. + * + * The Initial Developer of the Original Code is + * Benjamin Smedberg + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * 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 "nsIGlobalHistory2.h" +#include "nsIGlobalHistory.h" +#include "nsIGenericFactory.h" +#include "nsCOMPtr.h" + +/** + * A compatibility wrapper for the nsIGlobalHistory2 interface. It provides + * the old nsIGlobalHistory interface for extensions which still use it. + */ + +// {a772eee4-0464-40d5-a329-a29dfda3791a} +#define NS_GLOBALHISTORY2ADAPTER_CID \ + { 0xa772eee4, 0x0464, 0x405d, { 0xa3, 0x29, 0xa2, 0x9d, 0xfd, 0xa3, 0x79, 0x1a } } + +class nsGlobalHistory2Adapter : public nsIGlobalHistory +{ +public: + NS_DECL_ISUPPORTS + NS_DECL_NSIGLOBALHISTORY + + static nsresult Create(nsISupports *aOuter, + REFNSIID aIID, + void **aResult); + + static nsresult RegisterSelf(nsIComponentManager* aCompMgr, + nsIFile* aPath, + const char* aLoaderStr, + const char* aType, + const nsModuleComponentInfo *aInfo); + + NS_DEFINE_STATIC_CID_ACCESSOR(NS_GLOBALHISTORY2ADAPTER_CID); + +private: + nsGlobalHistory2Adapter(); + ~nsGlobalHistory2Adapter(); + + nsresult Init(); + nsCOMPtr mHistory; +}; diff --git a/mozilla/docshell/base/nsGlobalHistoryAdapter.cpp b/mozilla/docshell/base/nsGlobalHistoryAdapter.cpp new file mode 100644 index 00000000000..b0c704bf76f --- /dev/null +++ b/mozilla/docshell/base/nsGlobalHistoryAdapter.cpp @@ -0,0 +1,199 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** 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 gecko code. + * + * The Initial Developer of the Original Code is + * Benjamin Smedberg + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * 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 "nsGlobalHistoryAdapter.h" + +#include "nsDocShellCID.h" +#include "nsIServiceManagerUtils.h" +#include "nsIComponentRegistrar.h" +#include "nsGlobalHistory2Adapter.h" +#include "nsIURI.h" +#include "nsString.h" + +nsresult +nsGlobalHistoryAdapter::Create(nsISupports *aOuter, + REFNSIID aIID, + void **aResult) +{ + nsresult rv; + + if (aOuter) { + rv = NS_ERROR_NO_AGGREGATION; + return rv; + } + + nsGlobalHistoryAdapter* adapter = new nsGlobalHistoryAdapter(); + if (!adapter) { + rv = NS_ERROR_OUT_OF_MEMORY; + return rv; + } + + NS_ADDREF(adapter); + rv = adapter->Init(); + if (NS_SUCCEEDED(rv)) { + rv = adapter->QueryInterface(aIID, aResult); + } + NS_RELEASE(adapter); + + return rv; +} + +nsresult +nsGlobalHistoryAdapter::RegisterSelf(nsIComponentManager* aCompMgr, + nsIFile* aPath, + const char* aLoaderStr, + const char* aType, + const nsModuleComponentInfo *aInfo) +{ + nsresult rv; + PRBool registered; + nsCOMPtr compReg( do_QueryInterface(aCompMgr) ); + if (!compReg) { + rv = NS_ERROR_UNEXPECTED; + return rv; + } + + rv = compReg->IsContractIDRegistered(NS_GLOBALHISTORY2_CONTRACTID, ®istered); + if (NS_FAILED(rv)) return rv; + + // If the embedder has already registered the contractID, we don't want to + // register ourself. Ideally the component manager would handle this for us. + if (registered) { + rv = NS_OK; + return rv; + } + + return compReg->RegisterFactoryLocation(GetCID(), + "nsGlobalHistoryAdapter", + NS_GLOBALHISTORY2_CONTRACTID, + aPath, aLoaderStr, aType); +} + +nsGlobalHistoryAdapter::nsGlobalHistoryAdapter() +{ } + +nsGlobalHistoryAdapter::~nsGlobalHistoryAdapter() +{ } + +nsresult +nsGlobalHistoryAdapter::Init() +{ + nsresult rv; + + nsCOMPtr compReg; + rv = NS_GetComponentRegistrar(getter_AddRefs(compReg)); + NS_ENSURE_SUCCESS(rv, rv); + + nsCID *cid; + rv = compReg->ContractIDToCID(NS_GLOBALHISTORY_CONTRACTID, &cid); + if (NS_FAILED(rv)) { + rv = NS_ERROR_FACTORY_NOT_REGISTERED; + return rv; + } + + if (cid->Equals(nsGlobalHistory2Adapter::GetCID())) { + rv = NS_ERROR_FACTORY_NOT_REGISTERED; + return rv; + } + + NS_WARNING("Using nsIGlobalHistory2->nsIGlobalHistory adapter."); + mHistory = do_GetService(NS_GLOBALHISTORY_CONTRACTID, &rv); + return rv; +} + +NS_IMPL_ISUPPORTS1(nsGlobalHistoryAdapter, nsIGlobalHistory2) + +NS_IMETHODIMP +nsGlobalHistoryAdapter::AddURI(nsIURI* aURI, PRBool aRedirect, + PRBool aToplevel) +{ + NS_ENSURE_ARG_POINTER(aURI); + nsresult rv; + + // The model is really if we don't know differently then add which basically + // means we are supposed to try all the things we know not to allow in and + // then if we don't bail go on and allow it in. But here lets compare + // against the most common case we know to allow in and go on and say yes + // to it. + + PRBool isHTTP = PR_FALSE; + PRBool isHTTPS = PR_FALSE; + + NS_ENSURE_SUCCESS(rv = aURI->SchemeIs("http", &isHTTP), rv); + NS_ENSURE_SUCCESS(rv = aURI->SchemeIs("https", &isHTTPS), rv); + + if (!isHTTP && !isHTTPS) { + PRBool isAbout, isImap, isNews, isMailbox, isViewSource, isChrome, isData; + + rv = aURI->SchemeIs("about", &isAbout); + rv |= aURI->SchemeIs("imap", &isImap); + rv |= aURI->SchemeIs("news", &isNews); + rv |= aURI->SchemeIs("mailbox", &isMailbox); + rv |= aURI->SchemeIs("view-source", &isViewSource); + rv |= aURI->SchemeIs("chrome", &isChrome); + rv |= aURI->SchemeIs("data", &isData); + NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE); + + if (isAbout || isImap || isNews || isMailbox || isViewSource || isChrome || isData) { + return NS_OK; + } + } + + nsCAutoString spec; + rv = aURI->GetSpec(spec); + NS_ENSURE_SUCCESS(rv, rv); + + return mHistory->AddPage(spec.get()); +} + +NS_IMETHODIMP +nsGlobalHistoryAdapter::IsVisited(nsIURI* aURI, PRBool* aRetval) +{ + NS_ENSURE_ARG_POINTER(aURI); + + nsCAutoString spec; + nsresult rv = aURI->GetSpec(spec); + NS_ENSURE_SUCCESS(rv, rv); + + return mHistory->IsVisited(spec.get(), aRetval); +} + +NS_IMETHODIMP +nsGlobalHistoryAdapter::SetPageTitle(nsIURI* aURI, const nsAString& aTitle) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} diff --git a/mozilla/docshell/base/nsGlobalHistoryAdapter.h b/mozilla/docshell/base/nsGlobalHistoryAdapter.h new file mode 100644 index 00000000000..57bdd811ed1 --- /dev/null +++ b/mozilla/docshell/base/nsGlobalHistoryAdapter.h @@ -0,0 +1,77 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** 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 gecko code. + * + * The Initial Developer of the Original Code is + * Benjamin Smedberg + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * 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 "nsIGlobalHistory2.h" +#include "nsIGlobalHistory.h" +#include "nsIGenericFactory.h" +#include "nsCOMPtr.h" + +/** + * A compatibility wrapper for the old nsIGlobalHistory interface. It provides + * the new nsIGlobalHistory2 interface for embedders who haven't implemented it + * themselves. + */ + +// {2e9b69dd-9087-438c-8b5d-f77b553abefb} +#define NS_GLOBALHISTORYADAPTER_CID \ + { 0x2e9b69dd, 0x9087, 0x438c, { 0x8b, 0x5d, 0xf7, 0x7b, 0x55, 0x3a, 0xbe, 0xfb } } + +class nsGlobalHistoryAdapter : public nsIGlobalHistory2 +{ +public: + NS_DECL_ISUPPORTS + NS_DECL_NSIGLOBALHISTORY2 + + static nsresult Create(nsISupports *aOuter, + REFNSIID aIID, + void **aResult); + + static nsresult RegisterSelf(nsIComponentManager* aCompMgr, + nsIFile* aPath, + const char* aLoaderStr, + const char* aType, + const nsModuleComponentInfo *aInfo); + + NS_DEFINE_STATIC_CID_ACCESSOR(NS_GLOBALHISTORYADAPTER_CID); + +private: + nsGlobalHistoryAdapter(); + ~nsGlobalHistoryAdapter(); + + nsresult Init(); + nsCOMPtr mHistory; +}; diff --git a/mozilla/docshell/base/nsIDocShellHistory.idl b/mozilla/docshell/base/nsIDocShellHistory.idl index 80004012394..249bff51e9b 100644 --- a/mozilla/docshell/base/nsIDocShellHistory.idl +++ b/mozilla/docshell/base/nsIDocShellHistory.idl @@ -21,11 +21,8 @@ #include "nsISupports.idl" interface nsISHEntry; -interface nsIGlobalHistory; - - -[scriptable, uuid(bd0a9ac0-4d3d-11d4-9bb1-00e09872a416)] +[scriptable, uuid(89caa9f0-8b1c-47fb-b0d3-f0aef0bff749)] interface nsIDocShellHistory : nsISupports { /** @@ -40,12 +37,9 @@ interface nsIDocShellHistory : nsISupports in nsISHEntry aHistoryEntry, in long aChildOffset); - /* - * The global history object used to store - * the global history for the session. - */ - attribute nsIGlobalHistory globalHistory; - - + /* + * Whether this docshell should save entries in global history. + */ + attribute boolean useGlobalHistory; }; diff --git a/mozilla/docshell/base/nsIGlobalHistory.idl b/mozilla/docshell/base/nsIGlobalHistory.idl index 04dbd2081e7..5a289b52c1a 100644 --- a/mozilla/docshell/base/nsIGlobalHistory.idl +++ b/mozilla/docshell/base/nsIGlobalHistory.idl @@ -39,7 +39,8 @@ * * The interface to global history. * - * @status FROZEN + * @status FROZEN & DEPRECATED. This interface is still accepted, but new + * implementations should use nsIGlobalHistory2. * @version 1.0 */ @@ -68,14 +69,7 @@ interface nsIGlobalHistory : nsISupports }; %{ C++ -// {9491C382-E3C4-11D2-BDBE-0050040A9B44} -#define NS_GLOBALHISTORY_CID \ -{ 0x9491c382, 0xe3c4, 0x11d2, { 0xbd, 0xbe, 0x0, 0x50, 0x4, 0xa, 0x9b, 0x44} } - #define NS_GLOBALHISTORY_CONTRACTID \ "@mozilla.org/browser/global-history;1" - -#define NS_GLOBALHISTORY_DATASOURCE_CONTRACTID \ - "@mozilla.org/rdf/datasource;1?name=history" %} diff --git a/mozilla/docshell/base/nsIGlobalHistory2.idl b/mozilla/docshell/base/nsIGlobalHistory2.idl new file mode 100644 index 00000000000..541b09ae2a5 --- /dev/null +++ b/mozilla/docshell/base/nsIGlobalHistory2.idl @@ -0,0 +1,82 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** 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 the Mozilla gecko engine. + * + * The Initial Developer of the Original Code is + * Benjamin Smedberg . + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * 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 ***** */ + +/** + * Provides information about global history to gecko. + * + * @note This interface replaces and deprecates nsIGlobalHistory. + * @status UNDER_REVIEW + */ + +#include "nsISupports.idl" +interface nsIURI; + +[scriptable, uuid(c4d143b7-22d7-4760-b9a0-ac942016f189)] +interface nsIGlobalHistory2 : nsISupports +{ + /** + * Add a URI to global history + * + * @param aURI the URI of the page + * @param aRedirect whether the URI was redirected to another location; + * this is 'true' for the original URI which is + * redirected. + * @param aToplevel whether the URI is loaded in a top-level window + * + * @note Docshell will not filter out URI schemes like chrome: data: + * about: and view-source:. Embedders should consider filtering out + * these schemes and others, e.g. mailbox: + */ + void addURI(in nsIURI aURI, in boolean aRedirect, in boolean aToplevel); + + /** + * Checks to see whether the given URI is in history. + * + * @param aURI the uri to the page + * @return true if a URI has been visited + */ + boolean isVisited(in nsIURI aURI); + + /** + * Set the page title for the given uri. URIs that are not already in + * global history will not be added. + * + * @param aURI the URI for which to set to the title + * @param aTitle the page title + */ + void setPageTitle(in nsIURI aURI, in AString aTitle); +}; diff --git a/mozilla/docshell/base/nsWebShell.cpp b/mozilla/docshell/base/nsWebShell.cpp index 3cee85c9357..d1d5fe9b584 100644 --- a/mozilla/docshell/base/nsWebShell.cpp +++ b/mozilla/docshell/base/nsWebShell.cpp @@ -711,11 +711,8 @@ nsWebShell::GetLinkState(nsIURI* aLinkURI, nsLinkState& aState) if (!mGlobalHistory) return NS_OK; - nsCAutoString spec; - aLinkURI->GetSpec(spec); - PRBool isVisited; - NS_ENSURE_SUCCESS(mGlobalHistory->IsVisited(spec.get(), &isVisited), + NS_ENSURE_SUCCESS(mGlobalHistory->IsVisited(aLinkURI, &isVisited), NS_ERROR_FAILURE); if (isVisited) aState = eLinkState_Visited; diff --git a/mozilla/docshell/build/Makefile.in b/mozilla/docshell/build/Makefile.in index 320b574a297..feea8849c51 100644 --- a/mozilla/docshell/build/Makefile.in +++ b/mozilla/docshell/build/Makefile.in @@ -63,6 +63,10 @@ REQUIRES = xpcom \ prefetch \ $(NULL) +EXPORTS = \ + nsDocShellCID.h \ + $(NULL) + ifeq ($(OS_ARCH),WINNT) EXTRA_DSO_LIBS = gkgfx endif diff --git a/mozilla/docshell/build/nsDocShellCID.h b/mozilla/docshell/build/nsDocShellCID.h new file mode 100644 index 00000000000..fa7cffeefe3 --- /dev/null +++ b/mozilla/docshell/build/nsDocShellCID.h @@ -0,0 +1,44 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** 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 the Mozilla gecko engine. + * + * The Initial Developer of the Original Code is + * Benjamin Smedberg . + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * 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 ***** */ + +#ifndef nsDocShellCID_h__ +#define nsDocShellCID_h__ + +#define NS_GLOBALHISTORY2_CONTRACTID \ + "@mozilla.org/browser/global-history;2" + +#endif // nsDocShellCID_h__ diff --git a/mozilla/docshell/build/nsDocShellModule.cpp b/mozilla/docshell/build/nsDocShellModule.cpp index bdc4fa320c1..497f2cef13f 100644 --- a/mozilla/docshell/build/nsDocShellModule.cpp +++ b/mozilla/docshell/build/nsDocShellModule.cpp @@ -37,6 +37,10 @@ #include "nsSHistory.h" #include "nsSHTransaction.h" +// global history +#include "nsGlobalHistoryAdapter.h" +#include "nsGlobalHistory2Adapter.h" + // docshell NS_GENERIC_FACTORY_CONSTRUCTOR(nsWebShell) NS_GENERIC_FACTORY_CONSTRUCTOR(nsDefaultURIFixup) @@ -108,7 +112,15 @@ static const nsModuleComponentInfo gDocShellModuleInfo[] = { { "nsSHistory", NS_SHISTORY_CID, NS_SHISTORY_CONTRACTID, nsSHistoryConstructor }, { "nsSHistory", NS_SHISTORY_INTERNAL_CID, - NS_SHISTORY_INTERNAL_CONTRACTID, nsSHistoryConstructor } + NS_SHISTORY_INTERNAL_CONTRACTID, nsSHistoryConstructor }, + + // global history adapters + { "nsGlobalHistoryAdapter", NS_GLOBALHISTORYADAPTER_CID, + nsnull, nsGlobalHistoryAdapter::Create, + nsGlobalHistoryAdapter::RegisterSelf }, + { "nsGlobalHistory2Adapter", NS_GLOBALHISTORY2ADAPTER_CID, + nsnull, nsGlobalHistory2Adapter::Create, + nsGlobalHistory2Adapter::RegisterSelf } }; // "docshell provider" to illustrate that this thing really *should* diff --git a/mozilla/embedding/browser/webBrowser/nsWebBrowser.cpp b/mozilla/embedding/browser/webBrowser/nsWebBrowser.cpp index e4415de7ca0..3e53bcb87f9 100644 --- a/mozilla/embedding/browser/webBrowser/nsWebBrowser.cpp +++ b/mozilla/embedding/browser/webBrowser/nsWebBrowser.cpp @@ -335,13 +335,11 @@ NS_IMETHODIMP nsWebBrowser::EnableGlobalHistory(PRBool aEnable) if (NS_FAILED(rv)) return rv; if (aEnable) { - nsCOMPtr history = - do_GetService(NS_GLOBALHISTORY_CONTRACTID, &rv); - if (NS_FAILED(rv)) return rv; - rv = dsHistory->SetGlobalHistory(history); + rv = dsHistory->SetUseGlobalHistory(PR_TRUE); + } + else { + rv = dsHistory->SetUseGlobalHistory(PR_FALSE); } - else - rv = dsHistory->SetGlobalHistory(nsnull); return rv; } diff --git a/mozilla/embedding/lite/Makefile.in b/mozilla/embedding/lite/Makefile.in index 283271d4dc1..cdc1d9161ac 100644 --- a/mozilla/embedding/lite/Makefile.in +++ b/mozilla/embedding/lite/Makefile.in @@ -36,7 +36,7 @@ REQUIRES = xpcom \ content \ necko \ pref \ - history \ + docshell \ $(NULL) CPPSRCS = \ diff --git a/mozilla/rdf/Makefile.in b/mozilla/rdf/Makefile.in index 378c40bb925..af494d4b6bb 100644 --- a/mozilla/rdf/Makefile.in +++ b/mozilla/rdf/Makefile.in @@ -29,15 +29,8 @@ include $(DEPTH)/config/autoconf.mk MODULE = rdf DIRS = base util datasource resources build -ifdef MOZ_XUL -ifndef MOZ_XUL_APP -DIRS += chrome -endif -endif - ifdef ENABLE_TESTS DIRS += tests endif include $(topsrcdir)/config/rules.mk - diff --git a/mozilla/toolkit/components/build/nsModule.cpp b/mozilla/toolkit/components/build/nsModule.cpp index 9efdba0ad9f..e6cc81b4188 100644 --- a/mozilla/toolkit/components/build/nsModule.cpp +++ b/mozilla/toolkit/components/build/nsModule.cpp @@ -41,6 +41,7 @@ #include "nsAlertsService.h" #endif #include "nsToolkitCompsCID.h" +#include "nsDocShellCID.h" #include "nsAutoCompleteController.h" #include "nsAutoCompleteMdbResult.h" #include "nsDownloadManager.h" @@ -122,7 +123,7 @@ static const nsModuleComponentInfo components[] = { "Global History", NS_GLOBALHISTORY_CID, - NS_GLOBALHISTORY_CONTRACTID, + NS_GLOBALHISTORY2_CONTRACTID, nsGlobalHistoryConstructor }, { "Global History", diff --git a/mozilla/toolkit/components/build/nsToolkitCompsCID.h b/mozilla/toolkit/components/build/nsToolkitCompsCID.h index 0fecbf15f09..2635d16cabe 100644 --- a/mozilla/toolkit/components/build/nsToolkitCompsCID.h +++ b/mozilla/toolkit/components/build/nsToolkitCompsCID.h @@ -59,6 +59,9 @@ #define NS_FORMHISTORYAUTOCOMPLETE_CONTRACTID \ "@mozilla.org/autocomplete/search;1?name=form-history" +#define NS_GLOBALHISTORY_DATASOURCE_CONTRACTID \ + "@mozilla.org/rdf/datasource;1?name=history" + #define NS_GLOBALHISTORY_AUTOCOMPLETE_CONTRACTID \ "@mozilla.org/autocomplete/search;1?name=history" @@ -86,3 +89,7 @@ // {A2059C0E-5A58-4c55-AB7C-26F0557546EF} #define NS_FORMHISTORY_CID \ { 0xa2059c0e, 0x5a58, 0x4c55, { 0xab, 0x7c, 0x26, 0xf0, 0x55, 0x75, 0x46, 0xef } } + +// {59648a91-5a60-4122-8ff2-54b839c84aed} +#define NS_GLOBALHISTORY_CID \ +{ 0x59648a91, 0x5a60, 0x4122, { 0x8f, 0xf2, 0x54, 0xb8, 0x39, 0xc8, 0x4a, 0xed} } diff --git a/mozilla/toolkit/components/history/public/Makefile.in b/mozilla/toolkit/components/history/public/Makefile.in index 7a64dbb1309..233d6d62ba5 100644 --- a/mozilla/toolkit/components/history/public/Makefile.in +++ b/mozilla/toolkit/components/history/public/Makefile.in @@ -31,7 +31,6 @@ MODULE = history XPIDL_MODULE = history XPIDLSRCS = \ - nsIGlobalHistory.idl \ nsIBrowserHistory.idl \ $(NULL) diff --git a/mozilla/toolkit/components/history/public/nsIBrowserHistory.idl b/mozilla/toolkit/components/history/public/nsIBrowserHistory.idl index 10d486d7b11..b18979bb0f0 100644 --- a/mozilla/toolkit/components/history/public/nsIBrowserHistory.idl +++ b/mozilla/toolkit/components/history/public/nsIBrowserHistory.idl @@ -40,29 +40,23 @@ */ #include "nsISupports.idl" +#include "nsIGlobalHistory2.idl" -[scriptable, uuid(1a9129f7-2490-49d1-ba54-196ddb848ddb)] -interface nsIBrowserHistory : nsISupports +[scriptable, uuid(68c59967-d043-4659-a973-f8f11b1d2aca)] +interface nsIBrowserHistory : nsIGlobalHistory2 { + /** + * lastPageVisited + * The last page that was visited in a top-level window. + */ + readonly attribute string lastPageVisited; + /** * count * The number of entries in global history */ readonly attribute PRUint32 count; - /** - * setPageTitle - * set the page title for the given url. Ignores urls that are not - * already in the history - */ - void setPageTitle(in string aURL, in wstring aTitle); - - /** - * removePage - * Remove the specified page from the global history - */ - void removePage(in string aURL); - /** * removePagesFromHost * Remove all pages from the given host. @@ -77,13 +71,6 @@ interface nsIBrowserHistory : nsISupports */ void removeAllPages(); - /** - * lastPageVisited - * the most recently visited page - */ - attribute string lastPageVisited; - - /** * hidePage * Hide the specified URL from being enumerated (and thus @@ -92,31 +79,12 @@ interface nsIBrowserHistory : nsISupports * if the page hasn't been visited yet, then it will be added * as if it was visited, and then marked as hidden */ - - void hidePage(in string url); + void hidePage(in nsIURI aURI); /** * markPageAsTyped * Designate the url as having been explicitly typed in by * the user, so it's okay to be an autocomplete result. */ - void markPageAsTyped(in string url); - - /** - * outputReferrerURL - * Prints out referrer information for a url to a - * data file if browser.history.url.datacapture.mode is set - * to 1 or 2 (see the comment in nsGlobalHistory.cpp for - * more details). - * - * This method is a big hack and only temporary. Please do NOT use - * it in your code. It will be removed after the data - * collection phase of the project described in bug 182366 is - * over. - * - * @param aURL a url in global history - * @param aReferrer the referrer url to aURL - */ - void outputReferrerURL(in string aURL, in string aReferrer); }; diff --git a/mozilla/toolkit/components/history/public/nsIGlobalHistory.idl b/mozilla/toolkit/components/history/public/nsIGlobalHistory.idl deleted file mode 100644 index 04dbd2081e7..00000000000 --- a/mozilla/toolkit/components/history/public/nsIGlobalHistory.idl +++ /dev/null @@ -1,81 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -/** - * - * The interface to global history. - * - * @status FROZEN - * @version 1.0 - */ - -#include "nsISupports.idl" - -[scriptable, uuid(9491C383-E3C4-11d2-BDBE-0050040A9B44)] -interface nsIGlobalHistory : nsISupports -{ - /** - * addPage - * Add a page to the history - * - * @param aURL the url to the page - */ - - void addPage(in string aURL); - - /** - * isVisited - * Checks to see if the given page is in history - * - * @return true if a page has been passed into addPage(). - * @param aURL the url to the page - */ - boolean isVisited(in string aURL); -}; - -%{ C++ -// {9491C382-E3C4-11D2-BDBE-0050040A9B44} -#define NS_GLOBALHISTORY_CID \ -{ 0x9491c382, 0xe3c4, 0x11d2, { 0xbd, 0xbe, 0x0, 0x50, 0x4, 0xa, 0x9b, 0x44} } - -#define NS_GLOBALHISTORY_CONTRACTID \ - "@mozilla.org/browser/global-history;1" - -#define NS_GLOBALHISTORY_DATASOURCE_CONTRACTID \ - "@mozilla.org/rdf/datasource;1?name=history" -%} - diff --git a/mozilla/toolkit/components/history/src/Makefile.in b/mozilla/toolkit/components/history/src/Makefile.in index cd95b274324..4afb6bceea3 100644 --- a/mozilla/toolkit/components/history/src/Makefile.in +++ b/mozilla/toolkit/components/history/src/Makefile.in @@ -33,6 +33,7 @@ FORCE_STATIC_LIB = 1 REQUIRES = xpcom \ string \ + docshell \ rdf \ mork \ pref \ diff --git a/mozilla/toolkit/components/history/src/nsGlobalHistory.cpp b/mozilla/toolkit/components/history/src/nsGlobalHistory.cpp index df9ca5953e1..ec04b4b4c10 100644 --- a/mozilla/toolkit/components/history/src/nsGlobalHistory.cpp +++ b/mozilla/toolkit/components/history/src/nsGlobalHistory.cpp @@ -585,7 +585,7 @@ nsGlobalHistory::~nsGlobalHistory() // nsISupports methods NS_IMPL_ISUPPORTS7(nsGlobalHistory, - nsIGlobalHistory, + nsIGlobalHistory2, nsIBrowserHistory, nsIObserver, nsISupportsWeakReference, @@ -597,58 +597,89 @@ NS_IMPL_ISUPPORTS7(nsGlobalHistory, // // nsGlobalHistory // -// nsIGlobalHistory methods +// nsIGlobalHistory2 methods // - NS_IMETHODIMP -nsGlobalHistory::AddPage(const char *aURL) +nsGlobalHistory::AddURI(nsIURI *aURI, PRBool aRedirect, PRBool aTopLevel) { + nsresult rv; + NS_ENSURE_ARG_POINTER(aURI); + // If history is set to expire after 0 days, // then it's technically disabled. Don't even // bother adding the page - if (mExpireDays == 0) + if (mExpireDays == 0) { + NS_WARNING("mExpireDays == 0"); return NS_OK; + } - NS_ENSURE_ARG_POINTER(aURL); - NS_ENSURE_SUCCESS(OpenDB(), NS_ERROR_FAILURE); + // filter out unwanted URIs such as chrome: mailbox: etc + // The model is really if we don't know differently then add which basically + // means we are suppose to try all the things we know not to allow in and + // then if we don't bail go on and allow it in. But here lets compare + // against the most common case we know to allow in and go on and say yes + // to it. - nsresult rv = AddPageToDatabase(aURL, GetNow()); + PRBool isHTTP = PR_FALSE; + PRBool isHTTPS = PR_FALSE; + + NS_ENSURE_SUCCESS(rv = aURI->SchemeIs("http", &isHTTP), rv); + NS_ENSURE_SUCCESS(rv = aURI->SchemeIs("https", &isHTTPS), rv); + + if (!isHTTP && !isHTTPS) { + PRBool isAbout, isImap, isNews, isMailbox, isViewSource, isChrome, isData; + + rv = aURI->SchemeIs("about", &isAbout); + rv |= aURI->SchemeIs("imap", &isImap); + rv |= aURI->SchemeIs("news", &isNews); + rv |= aURI->SchemeIs("mailbox", &isMailbox); + rv |= aURI->SchemeIs("view-source", &isViewSource); + rv |= aURI->SchemeIs("chrome", &isChrome); + rv |= aURI->SchemeIs("data", &isData); + NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE); + + if (isAbout || isImap || isNews || isMailbox || isViewSource || isChrome || isData) { +#ifdef DEBUG_bsmedberg + printf("Filtering out unwanted scheme.\n"); +#endif + return NS_OK; + } + } + + rv = OpenDB(); NS_ENSURE_SUCCESS(rv, rv); - return NS_OK; -} + nsCAutoString URISpec; + rv = aURI->GetSpec(URISpec); + NS_ENSURE_SUCCESS(rv, rv); + +#ifdef DEBUG_bsmedberg + printf("AddURI: %s%s%s", + URISpec.get(), + aRedirect ? ", redirect" : "", + aTopLevel ? ", toplevel" : ""); +#endif + + PRInt64 now = GetNow(); -nsresult -nsGlobalHistory::AddPageToDatabase(const char *aURL, - PRInt64 aDate) -{ - nsresult rv; - - // Sanity check the URL - PRInt32 len = PL_strlen(aURL); - NS_ASSERTION(len != 0, "no URL"); - if (! len) - return NS_ERROR_INVALID_ARG; - // For notifying observers, later... nsCOMPtr url; - rv = gRDFService->GetResource(nsDependentCString(aURL, len), getter_AddRefs(url)); - if (NS_FAILED(rv)) return rv; + rv = gRDFService->GetResource(URISpec, getter_AddRefs(url)); + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr date; - rv = gRDFService->GetDateLiteral(aDate, getter_AddRefs(date)); - if (NS_FAILED(rv)) return rv; + rv = gRDFService->GetDateLiteral(now, getter_AddRefs(date)); + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr row; - rv = FindRow(kToken_URLColumn, aURL, getter_AddRefs(row)); + rv = FindRow(kToken_URLColumn, URISpec.get(), getter_AddRefs(row)); if (NS_SUCCEEDED(rv)) { - // update the database, and get the old info back PRInt64 oldDate; PRInt32 oldCount; - rv = AddExistingPageToDatabase(row, aDate, &oldDate, &oldCount); + rv = AddExistingPageToDatabase(row, now, &oldDate, &oldCount); NS_ASSERTION(NS_SUCCEEDED(rv), "AddExistingPageToDatabase failed; see bug 88961"); if (NS_FAILED(rv)) return rv; @@ -657,43 +688,84 @@ nsGlobalHistory::AddPageToDatabase(const char *aURL, // visit date nsCOMPtr oldDateLiteral; rv = gRDFService->GetDateLiteral(oldDate, getter_AddRefs(oldDateLiteral)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); rv = NotifyChange(url, kNC_Date, oldDateLiteral, date); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); // visit count nsCOMPtr oldCountLiteral; rv = gRDFService->GetIntLiteral(oldCount, getter_AddRefs(oldCountLiteral)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr newCountLiteral; rv = gRDFService->GetIntLiteral(oldCount+1, getter_AddRefs(newCountLiteral)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); rv = NotifyChange(url, kNC_VisitCount, oldCountLiteral, newCountLiteral); - if (NS_FAILED(rv)) return rv; - + NS_ENSURE_SUCCESS(rv, rv); + +#ifdef DEBUG_bsmedberg + printf("Existing page succeeded.\n"); +#endif } else { - rv = AddNewPageToDatabase(aURL, aDate, getter_AddRefs(row)); + rv = AddNewPageToDatabase(URISpec.get(), now, getter_AddRefs(row)); NS_ASSERTION(NS_SUCCEEDED(rv), "AddNewPageToDatabase failed; see bug 88961"); if (NS_FAILED(rv)) return rv; - // Notify observers - rv = NotifyAssert(url, kNC_Date, date); - if (NS_FAILED(rv)) return rv; + PRBool isJavascript; + rv = aURI->SchemeIs("javascript", &isJavascript); + NS_ENSURE_SUCCESS(rv, rv); + + if (isJavascript || aRedirect || !aTopLevel) { + // if this is a JS url, or a redirected URI or in a frame, hide it in + // global history so that it doesn't show up in the autocomplete + // dropdown. AddExistingPageToDatabase has logic to override this + // behavior for URIs which were typed. See bug 197127 and bug 161531 + // for details. + rv = SetRowValue(row, kToken_HiddenColumn, 1); + NS_ENSURE_SUCCESS(rv, rv); + } + else { + // Notify observers + rv = NotifyAssert(url, kNC_Date, date); + if (NS_FAILED(rv)) return rv; + + rv = NotifyAssert(kNC_HistoryRoot, kNC_child, url); + if (NS_FAILED(rv)) return rv; - rv = NotifyAssert(kNC_HistoryRoot, kNC_child, url); - if (NS_FAILED(rv)) return rv; - - NotifyFindAssertions(url, row); + NotifyFindAssertions(url, row); + } + +#ifdef DEBUG_bsmedberg + printf("New page succeeded.\n"); +#endif + } + + // Store last visited page if we have the pref set accordingly + if (aTopLevel) { + PRInt32 choice = 0; + if (NS_SUCCEEDED(gPrefBranch->GetIntPref("startup.page", &choice))) { + if (choice != 2) { + if (NS_SUCCEEDED(gPrefBranch->GetIntPref("windows.loadOnNewWindow", &choice))) { + if (choice != 2) { + gPrefBranch->GetIntPref("tabs.loadOnNewTab", &choice); + } + } + } + } + if (choice == 2) { + NS_ENSURE_STATE(mMetaRow); + + SetRowValue(mMetaRow, kToken_LastPageVisited, URISpec.get()); + } } SetDirty(); - return rv; + return NS_OK; } nsresult @@ -702,7 +774,6 @@ nsGlobalHistory::AddExistingPageToDatabase(nsIMdbRow *row, PRInt64 *aOldDate, PRInt32 *aOldCount) { - nsresult rv; // if the page was typed, unhide it now because it's @@ -937,30 +1008,31 @@ nsGlobalHistory::GetCount(PRUint32* aCount) } NS_IMETHODIMP -nsGlobalHistory::SetPageTitle(const char *aURL, const PRUnichar *aTitle) +nsGlobalHistory::SetPageTitle(nsIURI *aURI, const nsAString& aTitle) { - NS_PRECONDITION(aURL != nsnull, "null ptr"); - if (! aURL) - return NS_ERROR_NULL_POINTER; + nsresult rv; + NS_ENSURE_ARG_POINTER(aURI); + + const nsAFlatString& titleString = PromiseFlatString(aTitle); + + // skip about: URIs to avoid reading in the db (about:blank, especially) + PRBool isAbout; + rv = aURI->SchemeIs("about", &isAbout); + NS_ENSURE_SUCCESS(rv, rv); + if (isAbout) return NS_OK; - // avoid this one well-known url since we can avoid - // reading in the db - if (PL_strcmp(aURL, "about:blank")==0) - return NS_OK; - NS_ENSURE_SUCCESS(OpenDB(), NS_ERROR_FAILURE); - nsresult rv; - - // Be defensive if somebody sends us a null title. - static PRUnichar kEmptyString[] = { 0 }; - if (! aTitle) - aTitle = kEmptyString; + nsCAutoString URISpec; + rv = aURI->GetSpec(URISpec); + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr row; - rv = FindRow(kToken_URLColumn, aURL, getter_AddRefs(row)); - if (NS_FAILED(rv)) - return rv; + rv = FindRow(kToken_URLColumn, URISpec.get(), getter_AddRefs(row)); + + // if the row doesn't exist, we silently succeed + if (rv == NS_ERROR_NOT_AVAILABLE) return NS_OK; + NS_ENSURE_SUCCESS(rv, rv); // Get the old title so we can notify observers nsAutoString oldtitle; @@ -973,15 +1045,15 @@ nsGlobalHistory::SetPageTitle(const char *aURL, const PRUnichar *aTitle) if (NS_FAILED(rv)) return rv; } - SetRowValue(row, kToken_NameColumn, aTitle); + SetRowValue(row, kToken_NameColumn, titleString.get()); // ...and update observers nsCOMPtr url; - rv = gRDFService->GetResource(nsDependentCString(aURL), getter_AddRefs(url)); + rv = gRDFService->GetResource(URISpec, getter_AddRefs(url)); if (NS_FAILED(rv)) return rv; nsCOMPtr name; - rv = gRDFService->GetLiteral(aTitle, getter_AddRefs(name)); + rv = gRDFService->GetLiteral(titleString.get(), getter_AddRefs(name)); if (NS_FAILED(rv)) return rv; if (oldname) { @@ -1169,35 +1241,25 @@ nsGlobalHistory::RemoveMatchingRows(rowMatchCallback aMatchFunc, } NS_IMETHODIMP -nsGlobalHistory::IsVisited(const char *aURL, PRBool *_retval) +nsGlobalHistory::IsVisited(nsIURI* aURI, PRBool *_retval) { - NS_PRECONDITION(aURL != nsnull, "null ptr"); - if (! aURL) - return NS_ERROR_NULL_POINTER; + NS_ENSURE_ARG_POINTER(aURI); nsresult rv; NS_ENSURE_SUCCESS(OpenDB(), NS_ERROR_NOT_INITIALIZED); + nsCAutoString URISpec; + rv = aURI->GetSpec(URISpec); + NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr row; - rv = FindRow(kToken_URLColumn, aURL, getter_AddRefs(row)); + rv = FindRow(kToken_URLColumn, URISpec.get(), getter_AddRefs(row)); *_retval = NS_SUCCEEDED(rv); return NS_OK; } -NS_IMETHODIMP -nsGlobalHistory::SetLastPageVisited(const char *aURL) -{ - NS_ENSURE_TRUE(aURL, NS_ERROR_FAILURE); - NS_ENSURE_STATE(mMetaRow); - - mdb_err err = SetRowValue(mMetaRow, kToken_LastPageVisited, aURL); - NS_ENSURE_TRUE(err == 0, NS_ERROR_FAILURE); - - return NS_OK; -} - NS_IMETHODIMP nsGlobalHistory::GetLastPageVisited(char **_retval) { @@ -1218,21 +1280,30 @@ nsGlobalHistory::GetLastPageVisited(char **_retval) } NS_IMETHODIMP -nsGlobalHistory::HidePage(const char *aURL) +nsGlobalHistory::HidePage(nsIURI *aURI) { nsresult rv; + NS_ENSURE_ARG_POINTER(aURI); + + nsCAutoString URISpec; + rv = aURI->GetSpec(URISpec); + NS_ENSURE_SUCCESS(rv, rv); + +#ifdef DEBUG_bsmedberg + printf("nsGlobalHistory::HidePage: %s\n", URISpec.get()); +#endif nsCOMPtr row; - rv = FindRow(kToken_URLColumn, aURL, getter_AddRefs(row)); + rv = FindRow(kToken_URLColumn, URISpec.get(), getter_AddRefs(row)); if (NS_FAILED(rv)) { // it hasn't been visited yet, but if one ever comes in, we need // to hide it when it is visited - rv = AddPage(aURL); + rv = AddURI(aURI, PR_FALSE, PR_FALSE); if (NS_FAILED(rv)) return rv; - rv = FindRow(kToken_URLColumn, aURL, getter_AddRefs(row)); + rv = FindRow(kToken_URLColumn, URISpec.get(), getter_AddRefs(row)); if (NS_FAILED(rv)) return rv; } @@ -1243,7 +1314,7 @@ nsGlobalHistory::HidePage(const char *aURL) // HasAssertion() correctly checks the Hidden column to show that // the row is hidden nsCOMPtr urlResource; - rv = gRDFService->GetResource(nsDependentCString(aURL), getter_AddRefs(urlResource)); + rv = gRDFService->GetResource(URISpec, getter_AddRefs(urlResource)); if (NS_FAILED(rv)) return rv; return NotifyFindUnassertions(urlResource, row); } @@ -1254,27 +1325,17 @@ nsGlobalHistory::MarkPageAsTyped(const char* aURL) nsCOMPtr row; nsresult rv = FindRow(kToken_URLColumn, aURL, getter_AddRefs(row)); if (NS_FAILED(rv)) { - rv = AddPage(aURL); - if (NS_FAILED(rv)) return rv; - - rv = FindRow(kToken_URLColumn, aURL, getter_AddRefs(row)); - if (NS_FAILED(rv)) return rv; + rv = AddNewPageToDatabase(aURL, GetNow(), getter_AddRefs(row)); + NS_ENSURE_SUCCESS(rv, rv); + + // We don't know if this is a valid URI yet. Hide it until it finishes + // loading. + SetRowValue(row, kToken_HiddenColumn, 1); } - // hide the page for now in case the url turns out to be invalid - // we'll unhide it in AddExistingPageToDatabase - rv = SetRowValue(row, kToken_HiddenColumn, 1); - if (NS_FAILED(rv)) return rv; - return SetRowValue(row, kToken_TypedColumn, 1); } -NS_IMETHODIMP -nsGlobalHistory::OutputReferrerURL(const char* aURL, const char* aReferrer) -{ - return NS_OK; -} - //---------------------------------------------------------------------- // // nsGlobalHistory diff --git a/mozilla/toolkit/components/history/src/nsGlobalHistory.h b/mozilla/toolkit/components/history/src/nsGlobalHistory.h index 8c6c73d8a7c..4a0744135d9 100644 --- a/mozilla/toolkit/components/history/src/nsGlobalHistory.h +++ b/mozilla/toolkit/components/history/src/nsGlobalHistory.h @@ -41,7 +41,6 @@ #ifndef nsglobalhistory__h____ #define nsglobalhistory__h____ -#include "nsIGlobalHistory.h" #include "nsIBrowserHistory.h" #include "mdb.h" @@ -129,7 +128,6 @@ struct AutocompleteExclude { }; class nsGlobalHistory : nsSupportsWeakReference, - public nsIGlobalHistory, public nsIBrowserHistory, public nsIObserver, public nsIRDFDataSource, @@ -140,7 +138,7 @@ public: // nsISupports methods NS_DECL_ISUPPORTS - NS_DECL_NSIGLOBALHISTORY + NS_DECL_NSIGLOBALHISTORY2 NS_DECL_NSIBROWSERHISTORY NS_DECL_NSIOBSERVER NS_DECL_NSIRDFDATASOURCE @@ -181,6 +179,7 @@ protected: // // expiration/removal stuff // + nsresult RemovePage(const char *aURL); PRInt32 mExpireDays; nsresult ExpireEntries(PRBool notify); nsresult RemoveMatchingRows(rowMatchCallback aMatchFunc, @@ -304,8 +303,6 @@ protected: // // AddPage-oriented stuff // - nsresult AddPageToDatabase(const char *aURL, - PRInt64 aDate); nsresult AddExistingPageToDatabase(nsIMdbRow *row, PRInt64 aDate, PRInt64 *aOldDate, diff --git a/mozilla/toolkit/content/widgets/browser.xml b/mozilla/toolkit/content/widgets/browser.xml index f87e9332da3..3990e22449b 100644 --- a/mozilla/toolkit/content/widgets/browser.xml +++ b/mozilla/toolkit/content/widgets/browser.xml @@ -437,10 +437,8 @@ // wire up session history this.webNavigation.sessionHistory = Components.classes["@mozilla.org/browser/shistory;1"].createInstance(Components.interfaces.nsISHistory); - // wire up global history - var globalHistory = Components.classes["@mozilla.org/browser/global-history;1"].getService(Components.interfaces.nsIGlobalHistory); - - this.docShell.QueryInterface(Components.interfaces.nsIDocShellHistory).globalHistory = globalHistory; + // enable global history + this.docShell.QueryInterface(Components.interfaces.nsIDocShellHistory).useGlobalHistory = true; } } catch (e) { diff --git a/mozilla/uriloader/exthandler/Makefile.in b/mozilla/uriloader/exthandler/Makefile.in index 9e46e218712..bb4a8f76d42 100644 --- a/mozilla/uriloader/exthandler/Makefile.in +++ b/mozilla/uriloader/exthandler/Makefile.in @@ -62,7 +62,7 @@ REQUIRES = xpcom \ intl \ uconv \ windowwatcher \ - history \ + docshell \ $(NULL) ifdef MOZ_PHOENIX diff --git a/mozilla/xpfe/browser/resources/content/navigator.js b/mozilla/xpfe/browser/resources/content/navigator.js index d79af806f49..5c8c717dd6f 100644 --- a/mozilla/xpfe/browser/resources/content/navigator.js +++ b/mozilla/xpfe/browser/resources/content/navigator.js @@ -520,10 +520,8 @@ function Startup() webNavigation.sessionHistory = Components.classes["@mozilla.org/browser/shistory;1"] .createInstance(Components.interfaces.nsISHistory); - // wire up global history. the same applies here. - var globalHistory = Components.classes["@mozilla.org/browser/global-history;1"] - .getService(Components.interfaces.nsIGlobalHistory); - getBrowser().docShell.QueryInterface(Components.interfaces.nsIDocShellHistory).globalHistory = globalHistory; + // enable global history + getBrowser().docShell.QueryInterface(Components.interfaces.nsIDocShellHistory).useGlobalHistory = true; } catch (e) {} const selectedBrowser = getBrowser().selectedBrowser; @@ -568,7 +566,7 @@ function Startup() uriArray = getHomePage(); break; case 2: - var history = Components.classes["@mozilla.org/browser/global-history;1"] + var history = Components.classes["@mozilla.org/browser/global-history;2"] .getService(Components.interfaces.nsIBrowserHistory); uriArray = [history.lastPageVisited]; break; @@ -690,7 +688,7 @@ function BrowserFlushBookmarksAndHistory() bmks.Flush(); // give history a chance at flushing to disk also - var history = Components.classes["@mozilla.org/browser/global-history;1"] + var history = Components.classes["@mozilla.org/browser/global-history;2"] .getService(Components.interfaces.nsIRDFRemoteDataSource); history.Flush(); } catch(ex) { diff --git a/mozilla/xpfe/browser/resources/content/sessionHistoryUI.js b/mozilla/xpfe/browser/resources/content/sessionHistoryUI.js index f25b71bd199..8b386c4781a 100644 --- a/mozilla/xpfe/browser/resources/content/sessionHistoryUI.js +++ b/mozilla/xpfe/browser/resources/content/sessionHistoryUI.js @@ -170,7 +170,7 @@ function addToUrlbarHistory() .getService(Components.interfaces.nsIRDFService); if (!gGlobalHistory) - gGlobalHistory = Components.classes["@mozilla.org/browser/global-history;1"] + gGlobalHistory = Components.classes["@mozilla.org/browser/global-history;2"] .getService(Components.interfaces.nsIBrowserHistory); if (!gURIFixup) diff --git a/mozilla/xpfe/browser/src/nsBrowserInstance.cpp b/mozilla/xpfe/browser/src/nsBrowserInstance.cpp index af336a3ec16..605d7316546 100644 --- a/mozilla/xpfe/browser/src/nsBrowserInstance.cpp +++ b/mozilla/xpfe/browser/src/nsBrowserInstance.cpp @@ -89,8 +89,8 @@ #include "nsAppShellCIDs.h" #include "nsIDocumentViewer.h" -#include "nsIGlobalHistory.h" #include "nsIBrowserHistory.h" +#include "nsDocShellCID.h" #include "nsIObserverService.h" @@ -118,7 +118,6 @@ static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID); static NS_DEFINE_CID(kProxyObjectManagerCID, NS_PROXYEVENT_MANAGER_CID); static NS_DEFINE_CID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID); static NS_DEFINE_CID(kCmdLineServiceCID, NS_COMMANDLINE_SERVICE_CID); -static NS_DEFINE_CID(kCGlobalHistoryCID, NS_GLOBALHISTORY_CID); #ifdef DEBUG static int APP_DEBUG = 0; // Set to 1 in debugger to turn on debugging. @@ -772,7 +771,7 @@ NS_IMETHODIMP nsBrowserContentHandler::GetDefaultArgs(PRUnichar **aDefaultArgs) return GetHomePageGroup(prefs, aDefaultArgs); } case 2: { - nsCOMPtr history(do_GetService(kCGlobalHistoryCID)); + nsCOMPtr history(do_GetService(NS_GLOBALHISTORY2_CONTRACTID)); if (history) { nsXPIDLCString curl; rv = history->GetLastPageVisited(getter_Copies(curl)); diff --git a/mozilla/xpfe/components/build/nsModule.cpp b/mozilla/xpfe/components/build/nsModule.cpp index 765eee6ca66..9e965dfb82a 100644 --- a/mozilla/xpfe/components/build/nsModule.cpp +++ b/mozilla/xpfe/components/build/nsModule.cpp @@ -50,6 +50,7 @@ #include "nsAutoComplete.h" #include "nsBookmarksService.h" #include "nsGlobalHistory.h" +#include "nsDocShellCID.h" #include "nsUrlbarHistory.h" #include "nsDownloadManager.h" #include "nsDownloadProxy.h" @@ -69,6 +70,13 @@ #include "nsBrowserInstance.h" #include "nsCURILoader.h" +// {9491C382-E3C4-11D2-BDBE-0050040A9B44} +#define NS_GLOBALHISTORY_CID \ +{ 0x9491c382, 0xe3c4, 0x11d2, { 0xbd, 0xbe, 0x0, 0x50, 0x4, 0xa, 0x9b, 0x44} } + +#define NS_GLOBALHISTORY_DATASOURCE_CONTRACTID \ + "@mozilla.org/rdf/datasource;1?name=history" + // Factory constructors NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsHTTPIndex, Init) NS_GENERIC_FACTORY_CONSTRUCTOR(nsDirectoryViewerFactory) @@ -159,7 +167,7 @@ static const nsModuleComponentInfo components[] = { nsAutoCompleteItemConstructor}, { "nsUrlbarHistory", NS_URLBARHISTORY_CID, NS_URLBARHISTORY_CONTRACTID, nsUrlbarHistoryConstructor }, - { "Global History", NS_GLOBALHISTORY_CID, NS_GLOBALHISTORY_CONTRACTID, + { "Global History", NS_GLOBALHISTORY_CID, NS_GLOBALHISTORY2_CONTRACTID, nsGlobalHistoryConstructor }, { "Global History", NS_GLOBALHISTORY_CID, NS_GLOBALHISTORY_DATASOURCE_CONTRACTID, nsGlobalHistoryConstructor }, diff --git a/mozilla/xpfe/components/history/public/Makefile.in b/mozilla/xpfe/components/history/public/Makefile.in index d01ebf322fb..45f0d4675ec 100644 --- a/mozilla/xpfe/components/history/public/Makefile.in +++ b/mozilla/xpfe/components/history/public/Makefile.in @@ -30,9 +30,6 @@ MODULE = history XPIDL_MODULE = history GRE_MODULE = 1 -SDK_XPIDLSRCS = nsIGlobalHistory.idl \ - $(NULL) - XPIDLSRCS = nsIBrowserHistory.idl \ $(NULL) diff --git a/mozilla/xpfe/components/history/public/nsIBrowserHistory.idl b/mozilla/xpfe/components/history/public/nsIBrowserHistory.idl index 48a416484a2..5d36b3cbc64 100644 --- a/mozilla/xpfe/components/history/public/nsIBrowserHistory.idl +++ b/mozilla/xpfe/components/history/public/nsIBrowserHistory.idl @@ -40,28 +40,27 @@ */ #include "nsISupports.idl" +#include "nsIGlobalHistory2.idl" -[scriptable, uuid(1a9129f7-2490-49d1-ba54-196ddb848ddb)] -interface nsIBrowserHistory : nsISupports +[scriptable, uuid(460947aa-7636-43b5-949a-415a7c59da97)] +interface nsIBrowserHistory : nsIGlobalHistory2 { + /** + * lastPageVisited + * The last page that was visited in a top-level window. + */ + readonly attribute string lastPageVisited; + + /** + * remove a page from history + */ + void removePage(in string aURI); + /** * count * The number of entries in global history */ - readonly attribute PRUint32 count; - - /** - * setPageTitle - * set the page title for the given url. Ignores urls that are not - * already in the history - */ - void setPageTitle(in string aURL, in wstring aTitle); - - /** - * removePage - * Remove the specified page from the global history - */ - void removePage(in string aURL); + readonly attribute unsigned long count; /** * removePagesFromHost @@ -77,13 +76,6 @@ interface nsIBrowserHistory : nsISupports */ void removeAllPages(); - /** - * lastPageVisited - * the most recently visited page - */ - attribute string lastPageVisited; - - /** * hidePage * Hide the specified URL from being enumerated (and thus @@ -92,15 +84,13 @@ interface nsIBrowserHistory : nsISupports * if the page hasn't been visited yet, then it will be added * as if it was visited, and then marked as hidden */ - - void hidePage(in string url); + void hidePage(in nsIURI url); /** * markPageAsTyped * Designate the url as having been explicitly typed in by * the user, so it's okay to be an autocomplete result. */ - void markPageAsTyped(in string url); }; diff --git a/mozilla/xpfe/components/history/public/nsIGlobalHistory.idl b/mozilla/xpfe/components/history/public/nsIGlobalHistory.idl deleted file mode 100644 index 04dbd2081e7..00000000000 --- a/mozilla/xpfe/components/history/public/nsIGlobalHistory.idl +++ /dev/null @@ -1,81 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -/** - * - * The interface to global history. - * - * @status FROZEN - * @version 1.0 - */ - -#include "nsISupports.idl" - -[scriptable, uuid(9491C383-E3C4-11d2-BDBE-0050040A9B44)] -interface nsIGlobalHistory : nsISupports -{ - /** - * addPage - * Add a page to the history - * - * @param aURL the url to the page - */ - - void addPage(in string aURL); - - /** - * isVisited - * Checks to see if the given page is in history - * - * @return true if a page has been passed into addPage(). - * @param aURL the url to the page - */ - boolean isVisited(in string aURL); -}; - -%{ C++ -// {9491C382-E3C4-11D2-BDBE-0050040A9B44} -#define NS_GLOBALHISTORY_CID \ -{ 0x9491c382, 0xe3c4, 0x11d2, { 0xbd, 0xbe, 0x0, 0x50, 0x4, 0xa, 0x9b, 0x44} } - -#define NS_GLOBALHISTORY_CONTRACTID \ - "@mozilla.org/browser/global-history;1" - -#define NS_GLOBALHISTORY_DATASOURCE_CONTRACTID \ - "@mozilla.org/rdf/datasource;1?name=history" -%} - diff --git a/mozilla/xpfe/components/history/src/Makefile.in b/mozilla/xpfe/components/history/src/Makefile.in index aa2b302dd58..5be29b3b187 100644 --- a/mozilla/xpfe/components/history/src/Makefile.in +++ b/mozilla/xpfe/components/history/src/Makefile.in @@ -30,6 +30,7 @@ MODULE = history LIBRARY_NAME = history_s REQUIRES = xpcom \ string \ + docshell \ rdf \ mork \ pref \ diff --git a/mozilla/xpfe/components/history/src/nsGlobalHistory.cpp b/mozilla/xpfe/components/history/src/nsGlobalHistory.cpp index e89e0046bf5..00f22854471 100644 --- a/mozilla/xpfe/components/history/src/nsGlobalHistory.cpp +++ b/mozilla/xpfe/components/history/src/nsGlobalHistory.cpp @@ -570,7 +570,7 @@ nsGlobalHistory::~nsGlobalHistory() // nsISupports methods NS_IMPL_ISUPPORTS7(nsGlobalHistory, - nsIGlobalHistory, + nsIGlobalHistory2, nsIBrowserHistory, nsIObserver, nsISupportsWeakReference, @@ -582,58 +582,79 @@ NS_IMPL_ISUPPORTS7(nsGlobalHistory, // // nsGlobalHistory // -// nsIGlobalHistory methods +// nsIGlobalHistory2 methods // NS_IMETHODIMP -nsGlobalHistory::AddPage(const char *aURL) +nsGlobalHistory::AddURI(nsIURI *aURI, PRBool aRedirect, PRBool aTopLevel) { + nsresult rv; + NS_ENSURE_ARG_POINTER(aURI); + // If history is set to expire after 0 days, // then it's technically disabled. Don't even // bother adding the page if (mExpireDays == 0) return NS_OK; - NS_ENSURE_ARG_POINTER(aURL); - NS_ENSURE_SUCCESS(OpenDB(), NS_ERROR_FAILURE); + // filter out unwanted URIs such as chrome: mailbox: etc + // The model is really if we don't know differently then add which basically + // means we are suppose to try all the things we know not to allow in and + // then if we don't bail go on and allow it in. But here lets compare + // against the most common case we know to allow in and go on and say yes + // to it. - nsresult rv = AddPageToDatabase(aURL, GetNow()); + PRBool isHTTP = PR_FALSE; + PRBool isHTTPS = PR_FALSE; + + NS_ENSURE_SUCCESS(rv = aURI->SchemeIs("http", &isHTTP), rv); + NS_ENSURE_SUCCESS(rv = aURI->SchemeIs("https", &isHTTPS), rv); + + if (!isHTTP && !isHTTPS) { + PRBool isAbout, isImap, isNews, isMailbox, isViewSource, isChrome, isData; + + rv = aURI->SchemeIs("about", &isAbout); + rv |= aURI->SchemeIs("imap", &isImap); + rv |= aURI->SchemeIs("news", &isNews); + rv |= aURI->SchemeIs("mailbox", &isMailbox); + rv |= aURI->SchemeIs("view-source", &isViewSource); + rv |= aURI->SchemeIs("chrome", &isChrome); + rv |= aURI->SchemeIs("data", &isData); + NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE); + + if (isAbout || isImap || isNews || isMailbox || isViewSource || isChrome || isData) { + return NS_OK; + } + } + + rv = OpenDB(); NS_ENSURE_SUCCESS(rv, rv); - return NS_OK; -} + nsCAutoString URISpec; + rv = aURI->GetSpec(URISpec); + NS_ENSURE_SUCCESS(rv, rv); + + PRInt64 now = GetNow(); -nsresult -nsGlobalHistory::AddPageToDatabase(const char *aURL, - PRInt64 aDate) -{ - nsresult rv; - - // Sanity check the URL - PRInt32 len = PL_strlen(aURL); - NS_ASSERTION(len != 0, "no URL"); - if (! len) - return NS_ERROR_INVALID_ARG; - // For notifying observers, later... nsCOMPtr url; - rv = gRDFService->GetResource(nsDependentCString(aURL, len), getter_AddRefs(url)); + rv = gRDFService->GetResource(URISpec, getter_AddRefs(url)); if (NS_FAILED(rv)) return rv; nsCOMPtr date; - rv = gRDFService->GetDateLiteral(aDate, getter_AddRefs(date)); + rv = gRDFService->GetDateLiteral(now, getter_AddRefs(date)); if (NS_FAILED(rv)) return rv; nsCOMPtr row; - rv = FindRow(kToken_URLColumn, aURL, getter_AddRefs(row)); + rv = FindRow(kToken_URLColumn, URISpec.get(), getter_AddRefs(row)); if (NS_SUCCEEDED(rv)) { // update the database, and get the old info back PRInt64 oldDate; PRInt32 oldCount; - rv = AddExistingPageToDatabase(row, aDate, &oldDate, &oldCount); + rv = AddExistingPageToDatabase(row, now, &oldDate, &oldCount); NS_ASSERTION(NS_SUCCEEDED(rv), "AddExistingPageToDatabase failed; see bug 88961"); if (NS_FAILED(rv)) return rv; @@ -662,23 +683,57 @@ nsGlobalHistory::AddPageToDatabase(const char *aURL, } else { - rv = AddNewPageToDatabase(aURL, aDate, getter_AddRefs(row)); + rv = AddNewPageToDatabase(URISpec.get(), now, getter_AddRefs(row)); NS_ASSERTION(NS_SUCCEEDED(rv), "AddNewPageToDatabase failed; see bug 88961"); if (NS_FAILED(rv)) return rv; - // Notify observers - rv = NotifyAssert(url, kNC_Date, date); - if (NS_FAILED(rv)) return rv; + PRBool isJavascript; + rv = aURI->SchemeIs("javascript", &isJavascript); + NS_ENSURE_SUCCESS(rv, rv); + + if (isJavascript || aRedirect || !aTopLevel) { + // if this is a JS url, or a redirected URI or in a frame, hide it in + // global history so that it doesn't show up in the autocomplete + // dropdown. AddExistingPageToDatabase has logic to override this + // behavior for URIs which were typed. See bug 197127 and bug 161531 + // for details. + rv = SetRowValue(row, kToken_HiddenColumn, 1); + NS_ENSURE_SUCCESS(rv, rv); + } + else { + // Notify observers + rv = NotifyAssert(url, kNC_Date, date); + if (NS_FAILED(rv)) return rv; + + rv = NotifyAssert(kNC_HistoryRoot, kNC_child, url); + if (NS_FAILED(rv)) return rv; - rv = NotifyAssert(kNC_HistoryRoot, kNC_child, url); - if (NS_FAILED(rv)) return rv; - - NotifyFindAssertions(url, row); + NotifyFindAssertions(url, row); + } + } + + // Store last visited page if we have the pref set accordingly + if (aTopLevel) { + PRInt32 choice = 0; + if (NS_SUCCEEDED(gPrefBranch->GetIntPref("startup.page", &choice))) { + if (choice != 2) { + if (NS_SUCCEEDED(gPrefBranch->GetIntPref("windows.loadOnNewWindow", &choice))) { + if (choice != 2) { + gPrefBranch->GetIntPref("tabs.loadOnNewTab", &choice); + } + } + } + } + if (choice == 2) { + NS_ENSURE_STATE(mMetaRow); + + SetRowValue(mMetaRow, kToken_LastPageVisited, URISpec.get()); + } } SetDirty(); - return rv; + return NS_OK; } nsresult @@ -687,7 +742,6 @@ nsGlobalHistory::AddExistingPageToDatabase(nsIMdbRow *row, PRInt64 *aOldDate, PRInt32 *aOldCount) { - nsresult rv; // if the page was typed, unhide it now because it's @@ -960,30 +1014,31 @@ nsGlobalHistory::GetCount(PRUint32* aCount) } NS_IMETHODIMP -nsGlobalHistory::SetPageTitle(const char *aURL, const PRUnichar *aTitle) +nsGlobalHistory::SetPageTitle(nsIURI *aURI, const nsAString& aTitle) { - NS_PRECONDITION(aURL != nsnull, "null ptr"); - if (! aURL) - return NS_ERROR_NULL_POINTER; + nsresult rv; + NS_ENSURE_ARG_POINTER(aURI); + + const nsAFlatString& titleString = PromiseFlatString(aTitle); + + // skip about: URIs to avoid reading in the db (about:blank, especially) + PRBool isAbout; + rv = aURI->SchemeIs("about", &isAbout); + NS_ENSURE_SUCCESS(rv, rv); + if (isAbout) return NS_OK; - // avoid this one well-known url since we can avoid - // reading in the db - if (PL_strcmp(aURL, "about:blank")==0) - return NS_OK; - NS_ENSURE_SUCCESS(OpenDB(), NS_ERROR_FAILURE); - nsresult rv; - - // Be defensive if somebody sends us a null title. - static PRUnichar kEmptyString[] = { 0 }; - if (! aTitle) - aTitle = kEmptyString; + nsCAutoString URISpec; + rv = aURI->GetSpec(URISpec); + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr row; - rv = FindRow(kToken_URLColumn, aURL, getter_AddRefs(row)); - if (NS_FAILED(rv)) - return rv; + rv = FindRow(kToken_URLColumn, URISpec.get(), getter_AddRefs(row)); + + // if the row doesn't exist, we silently succeed + if (rv == NS_ERROR_NOT_AVAILABLE) return NS_OK; + NS_ENSURE_SUCCESS(rv, rv); // Get the old title so we can notify observers nsAutoString oldtitle; @@ -996,15 +1051,15 @@ nsGlobalHistory::SetPageTitle(const char *aURL, const PRUnichar *aTitle) if (NS_FAILED(rv)) return rv; } - SetRowValue(row, kToken_NameColumn, aTitle); + SetRowValue(row, kToken_NameColumn, titleString.get()); // ...and update observers nsCOMPtr url; - rv = gRDFService->GetResource(nsDependentCString(aURL), getter_AddRefs(url)); + rv = gRDFService->GetResource(URISpec, getter_AddRefs(url)); if (NS_FAILED(rv)) return rv; nsCOMPtr name; - rv = gRDFService->GetLiteral(aTitle, getter_AddRefs(name)); + rv = gRDFService->GetLiteral(titleString.get(), getter_AddRefs(name)); if (NS_FAILED(rv)) return rv; if (oldname) { @@ -1196,35 +1251,25 @@ nsGlobalHistory::RemoveMatchingRows(rowMatchCallback aMatchFunc, } NS_IMETHODIMP -nsGlobalHistory::IsVisited(const char *aURL, PRBool *_retval) +nsGlobalHistory::IsVisited(nsIURI* aURI, PRBool *_retval) { - NS_PRECONDITION(aURL != nsnull, "null ptr"); - if (! aURL) - return NS_ERROR_NULL_POINTER; + NS_ENSURE_ARG_POINTER(aURI); nsresult rv; NS_ENSURE_SUCCESS(OpenDB(), NS_ERROR_NOT_INITIALIZED); + nsCAutoString URISpec; + rv = aURI->GetSpec(URISpec); + NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr row; - rv = FindRow(kToken_URLColumn, aURL, getter_AddRefs(row)); + rv = FindRow(kToken_URLColumn, URISpec.get(), getter_AddRefs(row)); *_retval = NS_SUCCEEDED(rv); return NS_OK; } -NS_IMETHODIMP -nsGlobalHistory::SetLastPageVisited(const char *aURL) -{ - NS_ENSURE_TRUE(aURL, NS_ERROR_FAILURE); - NS_ENSURE_STATE(mMetaRow); - - mdb_err err = SetRowValue(mMetaRow, kToken_LastPageVisited, aURL); - NS_ENSURE_TRUE(err == 0, NS_ERROR_FAILURE); - - return NS_OK; -} - NS_IMETHODIMP nsGlobalHistory::GetLastPageVisited(char **_retval) { @@ -1281,21 +1326,26 @@ nsGlobalHistory::GetByteOrder(char **_retval) } NS_IMETHODIMP -nsGlobalHistory::HidePage(const char *aURL) +nsGlobalHistory::HidePage(nsIURI *aURI) { nsresult rv; + NS_ENSURE_ARG_POINTER(aURI); + + nsCAutoString URISpec; + rv = aURI->GetSpec(URISpec); + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr row; - rv = FindRow(kToken_URLColumn, aURL, getter_AddRefs(row)); + rv = FindRow(kToken_URLColumn, URISpec.get(), getter_AddRefs(row)); if (NS_FAILED(rv)) { // it hasn't been visited yet, but if one ever comes in, we need // to hide it when it is visited - rv = AddPage(aURL); + rv = AddURI(aURI, PR_FALSE, PR_FALSE); if (NS_FAILED(rv)) return rv; - rv = FindRow(kToken_URLColumn, aURL, getter_AddRefs(row)); + rv = FindRow(kToken_URLColumn, URISpec.get(), getter_AddRefs(row)); if (NS_FAILED(rv)) return rv; } @@ -1306,7 +1356,7 @@ nsGlobalHistory::HidePage(const char *aURL) // HasAssertion() correctly checks the Hidden column to show that // the row is hidden nsCOMPtr urlResource; - rv = gRDFService->GetResource(nsDependentCString(aURL), getter_AddRefs(urlResource)); + rv = gRDFService->GetResource(URISpec, getter_AddRefs(urlResource)); if (NS_FAILED(rv)) return rv; return NotifyFindUnassertions(urlResource, row); } @@ -1317,18 +1367,14 @@ nsGlobalHistory::MarkPageAsTyped(const char* aURL) nsCOMPtr row; nsresult rv = FindRow(kToken_URLColumn, aURL, getter_AddRefs(row)); if (NS_FAILED(rv)) { - rv = AddPage(aURL); - if (NS_FAILED(rv)) return rv; - - rv = FindRow(kToken_URLColumn, aURL, getter_AddRefs(row)); - if (NS_FAILED(rv)) return rv; + rv = AddNewPageToDatabase(aURL, GetNow(), getter_AddRefs(row)); + NS_ENSURE_SUCCESS(rv, rv); + + // We don't know if this is a valid URI yet. Hide it until it finishes + // loading. + SetRowValue(row, kToken_HiddenColumn, 1); } - // hide the page for now in case the url turns out to be invalid - // we'll unhide it in AddExistingPageToDatabase - rv = SetRowValue(row, kToken_HiddenColumn, 1); - if (NS_FAILED(rv)) return rv; - return SetRowValue(row, kToken_TypedColumn, 1); } diff --git a/mozilla/xpfe/components/history/src/nsGlobalHistory.h b/mozilla/xpfe/components/history/src/nsGlobalHistory.h index b786607016c..8f4efbd67e5 100644 --- a/mozilla/xpfe/components/history/src/nsGlobalHistory.h +++ b/mozilla/xpfe/components/history/src/nsGlobalHistory.h @@ -41,7 +41,6 @@ #define nsglobalhistory__h____ #include "mdb.h" -#include "nsIGlobalHistory.h" #include "nsIBrowserHistory.h" #include "nsIObserver.h" #include "nsIPrefBranch.h" @@ -125,7 +124,6 @@ struct AutocompleteExclude { }; class nsGlobalHistory : nsSupportsWeakReference, - public nsIGlobalHistory, public nsIBrowserHistory, public nsIObserver, public nsIRDFDataSource, @@ -136,7 +134,7 @@ public: // nsISupports methods NS_DECL_ISUPPORTS - NS_DECL_NSIGLOBALHISTORY + NS_DECL_NSIGLOBALHISTORY2 NS_DECL_NSIBROWSERHISTORY NS_DECL_NSIOBSERVER NS_DECL_NSIRDFDATASOURCE @@ -305,8 +303,6 @@ protected: // // AddPage-oriented stuff // - nsresult AddPageToDatabase(const char *aURL, - PRInt64 aDate); nsresult AddExistingPageToDatabase(nsIMdbRow *row, PRInt64 aDate, PRInt64 *aOldDate, diff --git a/mozilla/xpfe/components/prefwindow/resources/content/pref-history.xul b/mozilla/xpfe/components/prefwindow/resources/content/pref-history.xul index 6abdd32a38e..faac66d3f93 100644 --- a/mozilla/xpfe/components/prefwindow/resources/content/pref-history.xul +++ b/mozilla/xpfe/components/prefwindow/resources/content/pref-history.xul @@ -52,7 +52,7 @@ } var globalHistButton = document.getElementById("browserClearHistory"); - var globalHistory = Components.classes["@mozilla.org/browser/global-history;1"] + var globalHistory = Components.classes["@mozilla.org/browser/global-history;2"] .getService(Components.interfaces.nsIBrowserHistory); if (globalHistory.count == 0) globalHistButton.disabled = true; @@ -61,7 +61,7 @@ function prefClearGlobalHistory() { - var globalHistory = Components.classes["@mozilla.org/browser/global-history;1"] + var globalHistory = Components.classes["@mozilla.org/browser/global-history;2"] .getService(Components.interfaces.nsIBrowserHistory); globalHistory.removeAllPages(); } diff --git a/mozilla/xpfe/global/resources/content/bindings/browser.xml b/mozilla/xpfe/global/resources/content/bindings/browser.xml index 2cf8bc3e973..1f10b392a51 100644 --- a/mozilla/xpfe/global/resources/content/bindings/browser.xml +++ b/mozilla/xpfe/global/resources/content/bindings/browser.xml @@ -333,10 +333,8 @@ // wire up session history this.webNavigation.sessionHistory = Components.classes["@mozilla.org/browser/shistory;1"].createInstance(Components.interfaces.nsISHistory); - // wire up global history - var globalHistory = Components.classes["@mozilla.org/browser/global-history;1"].getService(Components.interfaces.nsIGlobalHistory); - - this.docShell.QueryInterface(Components.interfaces.nsIDocShellHistory).globalHistory = globalHistory; + // enable global history + this.docShell.QueryInterface(Components.interfaces.nsIDocShellHistory).useGlobalHistory = true; } } catch (e) {