From a66006818cd5596ad85c9f7678a4fca01c257fea Mon Sep 17 00:00:00 2001 From: "bzbarsky@mit.edu" Date: Fri, 3 Mar 2006 03:34:48 +0000 Subject: [PATCH] Revert nsIGlobalHistory2 to what it was on the 1.8 branch. Move the new stuff to nsIGlobalHistory3. Bug 328928, r=brettw and smfr, sr=darin --- .../components/places/src/nsNavHistory.cpp | 18 ++++---- docshell/base/nsDocShell.cpp | 16 ++++--- docshell/base/nsGlobalHistoryAdapter.cpp | 12 ----- docshell/base/nsIGlobalHistory2.idl | 18 +------- docshell/base/nsIGlobalHistory3.idl | 46 ++++++++++++++++--- layout/generic/nsGfxScrollFrame.cpp | 6 +-- .../history/src/nsGlobalHistory.cpp | 31 +++++++++---- .../components/history/src/nsGlobalHistory.h | 6 ++- .../history/src/nsGlobalHistory.cpp | 31 +++++++++---- xpfe/components/history/src/nsGlobalHistory.h | 5 +- 10 files changed, 117 insertions(+), 72 deletions(-) diff --git a/browser/components/places/src/nsNavHistory.cpp b/browser/components/places/src/nsNavHistory.cpp index c999ce48fe3b..ad3d2fe16605 100644 --- a/browser/components/places/src/nsNavHistory.cpp +++ b/browser/components/places/src/nsNavHistory.cpp @@ -2583,7 +2583,7 @@ nsNavHistory::SetURIGeckoFlags(nsIURI* aURI, PRUint32 aFlags) // nsIGlobalHistory3 *********************************************************** -// nsNavHistory::AddToplevelRedirect +// nsNavHistory::AddDocumentRedirect // // This adds a redirect mapping from the destination of the redirect to the // source, time, and type. This mapping is used by GetRedirectFor when we @@ -2600,8 +2600,10 @@ PLDHashOperator PR_CALLBACK nsNavHistory::ExpireNonrecentRedirects( return PL_DHASH_NEXT; } NS_IMETHODIMP -nsNavHistory::AddToplevelRedirect(nsIChannel *aOldChannel, - nsIChannel *aNewChannel, PRInt32 aFlags) +nsNavHistory::AddDocumentRedirect(nsIChannel *aOldChannel, + nsIChannel *aNewChannel, + PRInt32 aFlags, + PRBool aTopLevel) { nsresult rv; nsCOMPtr oldURI, newURI; @@ -3180,7 +3182,7 @@ nsNavHistory::ExpireNonrecentEvents(RecentEventHash* hashTable) // // HOW REDIRECT TRACKING WORKS // --------------------------- -// When we get an AddToplevelRedirect message, we store the redirect in +// When we get an AddDocumentRedirect message, we store the redirect in // our mRecentRedirects which maps the destination URI to a source,time pair. // When we get a new URI, we see if there were any redirects to this page // in the hash table. If found, we know that the page came through the given @@ -3188,8 +3190,8 @@ nsNavHistory::ExpireNonrecentEvents(RecentEventHash* hashTable) // // Example: Page S redirects throught R1, then R2, to give page D. Page S // will have been already added to history. -// - AddToplevelRedirect(R1, R2) -// - AddToplevelRedirect(R2, D) +// - AddDocumentRedirect(R1, R2) +// - AddDocumentRedirect(R2, D) // - AddURI(uri=D, referrer=S) // // When we get the AddURI(D), we see the hash table has a value for D from R2. @@ -3200,8 +3202,8 @@ nsNavHistory::ExpireNonrecentEvents(RecentEventHash* hashTable) // Alternatively, the user could have typed or followed a bookmark from S. // In this case, with two redirects we'll get: // - MarkPageAsTyped(S) -// - AddToplevelRedirect(S, R) -// - AddToplevelRedirect(R, D) +// - AddDocumentRedirect(S, R) +// - AddDocumentRedirect(R, D) // - AddURI(uri=D, referrer=null) // We need to be careful to add a visit to S in this case with an incoming // transition of typed and an outgoing transition of redirect. diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 858e2e72b7d5..87791bfe7b6b 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -4683,14 +4683,18 @@ nsDocShell::OnRedirectStateChange(nsIChannel* aOldChannel, return; // not a toplevel document nsCOMPtr history3(do_QueryInterface(mGlobalHistory)); + nsresult result = NS_ERROR_NOT_IMPLEMENTED; if (history3) { // notify global history of this redirect - history3->AddToplevelRedirect(aOldChannel, aNewChannel, - aRedirectFlags); - } else { - // when there is no GlobalHistory3, we fall back to GlobalHistory2. - // Just notify that the redirecting page was a redirect so it will - // be link colored but not visible. + result = history3->AddDocumentRedirect(aOldChannel, aNewChannel, + aRedirectFlags, !IsFrame()); + } + + if (result == NS_ERROR_NOT_IMPLEMENTED) { + // when there is no GlobalHistory3, or it doesn't implement + // AddToplevelRedirect, we fall back to GlobalHistory2. Just notify + // that the redirecting page was a redirect so it will be link colored + // but not visible. nsCOMPtr oldURI; aOldChannel->GetURI(getter_AddRefs(oldURI)); if (! oldURI) diff --git a/docshell/base/nsGlobalHistoryAdapter.cpp b/docshell/base/nsGlobalHistoryAdapter.cpp index 09b46dd085c7..de25ed57a8e8 100644 --- a/docshell/base/nsGlobalHistoryAdapter.cpp +++ b/docshell/base/nsGlobalHistoryAdapter.cpp @@ -197,15 +197,3 @@ nsGlobalHistoryAdapter::SetPageTitle(nsIURI* aURI, const nsAString& aTitle) { return NS_ERROR_NOT_IMPLEMENTED; } - -NS_IMETHODIMP -nsGlobalHistoryAdapter::SetURIGeckoFlags(nsIURI *aURI, PRUint32 aFlags) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -nsGlobalHistoryAdapter::GetURIGeckoFlags(nsIURI *aURI, PRUint32* aFlags) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} diff --git a/docshell/base/nsIGlobalHistory2.idl b/docshell/base/nsIGlobalHistory2.idl index 265605c3fe5a..c2cca33b4b5b 100644 --- a/docshell/base/nsIGlobalHistory2.idl +++ b/docshell/base/nsIGlobalHistory2.idl @@ -51,12 +51,9 @@ interface nsIURI; // the nsIURI is the subject #define NS_LINK_VISITED_EVENT_TOPIC "link-visited" -// This is NOT part of the interface! It could change. -#define NS_GECKO_FLAG_NEEDS_VERTICAL_SCROLLBAR (1 << 0) - %} -[scriptable, uuid(fbcfa5ca-5d05-4726-b325-d0e6563a1715)] +[scriptable, uuid(cf777d42-1270-4b34-be7b-2931c93feda5)] interface nsIGlobalHistory2 : nsISupports { /** @@ -92,17 +89,4 @@ interface nsIGlobalHistory2 : nsISupports * @param aTitle the page title */ void setPageTitle(in nsIURI aURI, in AString aTitle); - - /** - * Get the Gecko flags for this URI. These flags are used by Gecko as hints - * to optimize page loading. Not all histories have them; this need not be - * supported (just return NS_ERROR_NOT_IMPLEMENTED. These flags are opaque - * and should not be interpreted by the history engine. - */ - unsigned long getURIGeckoFlags(in nsIURI aURI); - /** - * Set the Gecko flags for this URI. May fail if the history entry - * doesn't have any flags or if there is no entry for the URI. - */ - void setURIGeckoFlags(in nsIURI aURI, in unsigned long aFlags); }; diff --git a/docshell/base/nsIGlobalHistory3.idl b/docshell/base/nsIGlobalHistory3.idl index 0b1e094364de..d54ee56cd82e 100644 --- a/docshell/base/nsIGlobalHistory3.idl +++ b/docshell/base/nsIGlobalHistory3.idl @@ -40,10 +40,17 @@ #include "nsIGlobalHistory2.idl" interface nsIChannel; +%{C++ + +// This is NOT part of the interface! It could change. +#define NS_GECKO_FLAG_NEEDS_VERTICAL_SCROLLBAR (1 << 0) + +%} + /** * Provides information about global history to gecko, extending GlobalHistory2 */ -[scriptable, uuid(40e9613e-1742-4b4d-a858-053e6237d04d)] +[scriptable, uuid(24306852-c60e-49c3-a455-90f6747118ba)] interface nsIGlobalHistory3 : nsIGlobalHistory2 { /** @@ -60,12 +67,37 @@ interface nsIGlobalHistory3 : nsIGlobalHistory2 * * For implementors of nsIGlobalHistory3: The history implementation is * responsible for sending NS_LINK_VISITED_EVENT_TOPIC to observers for - * redirect pages. This will be sent by the docshell for all non-redirect - * pages (see nsDocShell::AddToGlobalHistory). + * redirect pages. This notification must be sent for history consumers for + * all non-redirect pages. * - * This function takes the same arguments as - * nsIChannelEventSink::OnChannelRedirect + * @param aToplevel whether the URI is loaded in a top-level window. If + * false, the load is in a subframe. + * + * The other params to this function are the same as those for + * nsIChannelEventSink::OnChannelRedirect. + * + * Note: Implementors who wish to implement this interface but rely on + * nsIGlobalHistory2.addURI for redirect processing may throw + * NS_ERROR_NOT_IMPLEMENTED from this method. If they do so, then callers + * must call nsIGlobalHistory2.addURI upon getting the + * NS_ERROR_NOT_IMPLEMENTED result. */ - void addToplevelRedirect(in nsIChannel aOldChannel, in nsIChannel aNewChannel, - in PRInt32 aFlags); + void addDocumentRedirect(in nsIChannel aOldChannel, + in nsIChannel aNewChannel, + in PRInt32 aFlags, + in boolean aTopLevel); + + /** + * Get the Gecko flags for this URI. These flags are used by Gecko as hints + * to optimize page loading. Not all histories have them; this need not be + * supported (just return NS_ERROR_NOT_IMPLEMENTED. These flags are opaque + * and should not be interpreted by the history engine. + */ + unsigned long getURIGeckoFlags(in nsIURI aURI); + + /** + * Set the Gecko flags for this URI. May fail if the history entry + * doesn't have any flags or if there is no entry for the URI. + */ + void setURIGeckoFlags(in nsIURI aURI, in unsigned long aFlags); }; diff --git a/layout/generic/nsGfxScrollFrame.cpp b/layout/generic/nsGfxScrollFrame.cpp index a19f49f4530c..bd73c91088fd 100644 --- a/layout/generic/nsGfxScrollFrame.cpp +++ b/layout/generic/nsGfxScrollFrame.cpp @@ -75,7 +75,7 @@ #include "nsReflowPath.h" #include "nsAutoPtr.h" #include "nsPresState.h" -#include "nsIGlobalHistory2.h" +#include "nsIGlobalHistory3.h" #include "nsDocShellCID.h" #ifdef ACCESSIBILITY #include "nsIAccessibilityService.h" @@ -2623,7 +2623,7 @@ nsGfxScrollFrameInner::SaveVScrollbarStateToGlobalHistory() if (!uri) return; - nsCOMPtr history(do_GetService(NS_GLOBALHISTORY2_CONTRACTID)); + nsCOMPtr history(do_GetService(NS_GLOBALHISTORY2_CONTRACTID)); if (!history) return; @@ -2646,7 +2646,7 @@ nsGfxScrollFrameInner::GetVScrollbarHintFromGlobalHistory(PRBool* aVScrollbarNee if (!uri) return NS_ERROR_FAILURE; - nsCOMPtr history(do_GetService(NS_GLOBALHISTORY2_CONTRACTID)); + nsCOMPtr history(do_GetService(NS_GLOBALHISTORY2_CONTRACTID)); if (!history) return NS_ERROR_FAILURE; diff --git a/toolkit/components/history/src/nsGlobalHistory.cpp b/toolkit/components/history/src/nsGlobalHistory.cpp index 9371867af9db..262bb3c59b0a 100644 --- a/toolkit/components/history/src/nsGlobalHistory.cpp +++ b/toolkit/components/history/src/nsGlobalHistory.cpp @@ -548,14 +548,20 @@ nsGlobalHistory::~nsGlobalHistory() // // nsISupports methods -NS_IMPL_ISUPPORTS7(nsGlobalHistory, - nsIGlobalHistory2, - nsIBrowserHistory, - nsIObserver, - nsISupportsWeakReference, - nsIRDFDataSource, - nsIRDFRemoteDataSource, - nsIAutoCompleteSearch) +NS_IMPL_ADDREF(nsGlobalHistory) +NS_IMPL_RELEASE(nsGlobalHistory) + +NS_INTERFACE_MAP_BEGIN(nsGlobalHistory) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIGlobalHistory2, nsIGlobalHistory3) + NS_INTERFACE_MAP_ENTRY(nsIGlobalHistory3) + NS_INTERFACE_MAP_ENTRY(nsIBrowserHistory) + NS_INTERFACE_MAP_ENTRY(nsIObserver) + NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) + NS_INTERFACE_MAP_ENTRY(nsIRDFDataSource) + NS_INTERFACE_MAP_ENTRY(nsIRDFRemoteDataSource) + NS_INTERFACE_MAP_ENTRY(nsIAutoCompleteSearch) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIBrowserHistory) +NS_INTERFACE_MAP_END //---------------------------------------------------------------------- // @@ -1486,6 +1492,15 @@ nsGlobalHistory::MarkPageAsTyped(nsIURI *aURI) return SetRowValue(row, kToken_TypedColumn, 1); } +NS_IMETHODIMP +nsGlobalHistory::AddDocumentRedirect(nsIChannel *aOldChannel, + nsIChannel *aNewChannel, + PRInt32 aFlags, + PRBool aTopLevel) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + NS_IMETHODIMP nsGlobalHistory::SetURIGeckoFlags(nsIURI *aURI, PRUint32 aFlags) { diff --git a/toolkit/components/history/src/nsGlobalHistory.h b/toolkit/components/history/src/nsGlobalHistory.h index c4f08669a19a..661fa0d09f6f 100644 --- a/toolkit/components/history/src/nsGlobalHistory.h +++ b/toolkit/components/history/src/nsGlobalHistory.h @@ -42,7 +42,7 @@ #define nsglobalhistory__h____ #include "nsIBrowserHistory.h" - +#include "nsIGlobalHistory3.h" #include "mdb.h" #include "nsIObserver.h" #include "nsIPrefBranch.h" @@ -132,13 +132,15 @@ class nsGlobalHistory : nsSupportsWeakReference, public nsIObserver, public nsIRDFDataSource, public nsIRDFRemoteDataSource, - public nsIAutoCompleteSearch + public nsIAutoCompleteSearch, + public nsIGlobalHistory3 { public: // nsISupports methods NS_DECL_ISUPPORTS NS_DECL_NSIGLOBALHISTORY2 + NS_DECL_NSIGLOBALHISTORY3 NS_DECL_NSIBROWSERHISTORY NS_DECL_NSIOBSERVER NS_DECL_NSIRDFDATASOURCE diff --git a/xpfe/components/history/src/nsGlobalHistory.cpp b/xpfe/components/history/src/nsGlobalHistory.cpp index b93df770c56e..ccc4c9adfb9f 100644 --- a/xpfe/components/history/src/nsGlobalHistory.cpp +++ b/xpfe/components/history/src/nsGlobalHistory.cpp @@ -528,14 +528,20 @@ nsGlobalHistory::~nsGlobalHistory() // // nsISupports methods -NS_IMPL_ISUPPORTS7(nsGlobalHistory, - nsIGlobalHistory2, - nsIBrowserHistory, - nsIObserver, - nsISupportsWeakReference, - nsIRDFDataSource, - nsIRDFRemoteDataSource, - nsIAutoCompleteSession) +NS_IMPL_ADDREF(nsGlobalHistory) +NS_IMPL_RELEASE(nsGlobalHistory) + +NS_INTERFACE_MAP_BEGIN(nsGlobalHistory) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIGlobalHistory2, nsIGlobalHistory3) + NS_INTERFACE_MAP_ENTRY(nsIGlobalHistory3) + NS_INTERFACE_MAP_ENTRY(nsIBrowserHistory) + NS_INTERFACE_MAP_ENTRY(nsIObserver) + NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) + NS_INTERFACE_MAP_ENTRY(nsIRDFDataSource) + NS_INTERFACE_MAP_ENTRY(nsIRDFRemoteDataSource) + NS_INTERFACE_MAP_ENTRY(nsIAutoCompleteSession) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIBrowserHistory) +NS_INTERFACE_MAP_END //---------------------------------------------------------------------- // @@ -1398,6 +1404,15 @@ nsGlobalHistory::MarkPageAsTyped(nsIURI *aURI) return SetRowValue(row, kToken_TypedColumn, 1); } +NS_IMETHODIMP +nsGlobalHistory::AddDocumentRedirect(nsIChannel *aOldChannel, + nsIChannel *aNewChannel, + PRInt32 aFlags, + PRBool aTopLevel) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + NS_IMETHODIMP nsGlobalHistory::SetURIGeckoFlags(nsIURI *aURI, PRUint32 aFlags) { diff --git a/xpfe/components/history/src/nsGlobalHistory.h b/xpfe/components/history/src/nsGlobalHistory.h index 6f1b49c59a9e..a76ebdc94d25 100644 --- a/xpfe/components/history/src/nsGlobalHistory.h +++ b/xpfe/components/history/src/nsGlobalHistory.h @@ -42,6 +42,7 @@ #include "mdb.h" #include "nsIBrowserHistory.h" +#include "nsIGlobalHistory3.h" #include "nsIObserver.h" #include "nsIPrefBranch.h" #include "nsIRDFDataSource.h" @@ -129,13 +130,15 @@ class nsGlobalHistory : nsSupportsWeakReference, public nsIObserver, public nsIRDFDataSource, public nsIRDFRemoteDataSource, - public nsIAutoCompleteSession + public nsIAutoCompleteSession, + public nsIGlobalHistory3 { public: // nsISupports methods NS_DECL_ISUPPORTS NS_DECL_NSIGLOBALHISTORY2 + NS_DECL_NSIGLOBALHISTORY3 NS_DECL_NSIBROWSERHISTORY NS_DECL_NSIOBSERVER NS_DECL_NSIRDFDATASOURCE