From eed98f7886e68bbe89fbf170f5f9f136cd8ac766 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Sun, 9 Jan 2022 02:41:39 -0600 Subject: Bug 1419704 - Remove nsIGlobalHistory2 and docshell's nsDownloadHistory as they are redundant(ly busted). * Since gecko/22 the actual impl for nsIGlobalHistory has been removed and without it nsDownloadHistory in docshell will not function. As well as, Mozilla only be sheer luck was able to rely on the places impl for nsIDownloadHistory overriding docshell's. Obviously this is fuckin moronic as hell and as demonstrated with moving things around it in its broken state became dominate. * The difference between our port and what Mozilla is doing is that we are not gonna remove the interface for nsIDownloadHistory nor the observer topic as there are consumers of them. --- components/places/moz.build | 1 + components/places/public/nsIBrowserHistory.idl | 2 +- components/places/public/nsIDownloadHistory.idl | 53 ++++++++++++++++++++++ components/places/src/History.cpp | 2 + system/docshell/base/moz.build | 3 -- system/docshell/base/nsDocShell.cpp | 28 +----------- system/docshell/base/nsDocShell.h | 5 +-- system/docshell/base/nsDownloadHistory.cpp | 51 --------------------- system/docshell/base/nsDownloadHistory.h | 27 ----------- system/docshell/base/nsIDownloadHistory.idl | 58 ------------------------ system/docshell/base/nsIGlobalHistory2.idl | 59 ------------------------- system/docshell/build/nsDocShellModule.cpp | 9 ---- 12 files changed, 59 insertions(+), 239 deletions(-) create mode 100644 components/places/public/nsIDownloadHistory.idl delete mode 100644 system/docshell/base/nsDownloadHistory.cpp delete mode 100644 system/docshell/base/nsDownloadHistory.h delete mode 100644 system/docshell/base/nsIDownloadHistory.idl delete mode 100644 system/docshell/base/nsIGlobalHistory2.idl diff --git a/components/places/moz.build b/components/places/moz.build index 540265537..2be099873 100644 --- a/components/places/moz.build +++ b/components/places/moz.build @@ -15,6 +15,7 @@ if CONFIG['MOZ_PLACES']: 'public/mozIPlacesPendingOperation.idl', 'public/nsIAnnotationService.idl', 'public/nsIBrowserHistory.idl', + 'public/nsIDownloadHistory.idl', 'public/nsIFaviconService.idl', 'public/nsINavBookmarksService.idl', 'public/nsITaggingService.idl', diff --git a/components/places/public/nsIBrowserHistory.idl b/components/places/public/nsIBrowserHistory.idl index 8f3265972..35a186293 100644 --- a/components/places/public/nsIBrowserHistory.idl +++ b/components/places/public/nsIBrowserHistory.idl @@ -8,7 +8,7 @@ */ #include "nsISupports.idl" -#include "nsIGlobalHistory2.idl" +interface nsIURI; [scriptable, uuid(20d31479-38de-49f4-9300-566d6e834c66)] interface nsIBrowserHistory : nsISupports diff --git a/components/places/public/nsIDownloadHistory.idl b/components/places/public/nsIDownloadHistory.idl new file mode 100644 index 000000000..ca0a06549 --- /dev/null +++ b/components/places/public/nsIDownloadHistory.idl @@ -0,0 +1,53 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * vim: sw=2 ts=2 sts=2 + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "nsISupports.idl" + +interface nsIURI; + +[scriptable, uuid(4dcd6a12-a091-4f38-8360-022929635746)] +interface nsIDownloadHistory : nsISupports { + /** + * Adds a download to history. This will also notify observers that the + * URI aSource is visited with the topic NS_LINK_VISITED_EVENT_TOPIC if + * aSource has not yet been visited. + * + * @param aSource + * The source of the download we are adding to history. This cannot be + * null. + * @param aReferrer + * [optional] The referrer of source URI. + * @param aStartTime + * [optional] The time the download was started. If the start time + * is not given, the current time is used. + * @param aDestination + * [optional] The target where the download is to be saved on the local + * filesystem. + * @throws NS_ERROR_NOT_AVAILABLE + * In a situation where a history implementation is not available, + * where 'history implementation' refers to something like + * nsIGlobalHistory and friends. + * @note This addition is not guaranteed to be synchronous, since it delegates + * the actual addition to the underlying history implementation. If you + * need to observe the completion of the addition, use the underlying + * history implementation's notifications system (e.g. nsINavHistoryObserver + * for toolkit's implementation of this interface). + */ + void addDownload(in nsIURI aSource, [optional] in nsIURI aReferrer, + [optional] in PRTime aStartTime, + [optional] in nsIURI aDestination); + + /** + * Remove all downloads from history. + * + * @note This removal is not guaranteed to be synchronous, since it delegates + * the actual removal to the underlying history implementation. If you + * need to observe the completion of the removal, use the underlying + * history implementation's notifications system (e.g. nsINavHistoryObserver + * for toolkit's implementation of this interface). + */ + void removeAllDownloads(); +}; diff --git a/components/places/src/History.cpp b/components/places/src/History.cpp index e9c27d1d6..fe74e230e 100644 --- a/components/places/src/History.cpp +++ b/components/places/src/History.cpp @@ -43,6 +43,8 @@ // Initial length for the visits removal hash. #define VISITS_REMOVAL_INITIAL_HASH_LENGTH 64 +#define NS_LINK_VISITED_EVENT_TOPIC "link-visited" + using namespace mozilla::dom; using namespace mozilla::ipc; using mozilla::Unused; diff --git a/system/docshell/base/moz.build b/system/docshell/base/moz.build index c60e0d882..308e29614 100644 --- a/system/docshell/base/moz.build +++ b/system/docshell/base/moz.build @@ -22,8 +22,6 @@ XPIDL_SOURCES += [ 'nsIDocShellTreeItem.idl', 'nsIDocShellTreeOwner.idl', 'nsIDocumentLoaderFactory.idl', - 'nsIDownloadHistory.idl', - 'nsIGlobalHistory2.idl', 'nsILoadContext.idl', 'nsIPrivacyTransitionObserver.idl', 'nsIReflowObserver.idl', @@ -65,7 +63,6 @@ SOURCES += [ 'nsDocShellLoadInfo.cpp', 'nsDocShellTransferableHooks.cpp', 'nsDocShellTreeOwner.cpp', - 'nsDownloadHistory.cpp', 'nsDSURIContentListener.cpp', 'nsWebNavigationInfo.cpp', 'SerializedLoadContext.cpp', diff --git a/system/docshell/base/nsDocShell.cpp b/system/docshell/base/nsDocShell.cpp index b07cb15ff..5df1b6775 100644 --- a/system/docshell/base/nsDocShell.cpp +++ b/system/docshell/base/nsDocShell.cpp @@ -174,8 +174,6 @@ #include "nsISelectionDisplay.h" -#include "nsIGlobalHistory2.h" - #include "nsIFrame.h" #include "nsSubDocumentFrame.h" @@ -4399,27 +4397,15 @@ nsDocShell::AddChildSHEntryToParent(nsISHEntry* aNewEntry, int32_t aChildOffset, NS_IMETHODIMP nsDocShell::SetUseGlobalHistory(bool aUseGlobalHistory) { - nsresult rv; - mUseGlobalHistory = aUseGlobalHistory; if (!aUseGlobalHistory) { - mGlobalHistory = nullptr; return NS_OK; } - // No need to initialize mGlobalHistory if IHistory is available. nsCOMPtr history = services::GetHistoryService(); - if (history) { - return NS_OK; - } - if (mGlobalHistory) { - return NS_OK; - } - - mGlobalHistory = do_GetService(NS_GLOBALHISTORY2_CONTRACTID, &rv); - return rv; + return history ? NS_OK : NS_ERROR_FAILURE; } NS_IMETHODIMP @@ -6490,8 +6476,6 @@ nsDocShell::SetTitle(const char16_t* aTitle) nsCOMPtr history = services::GetHistoryService(); if (history) { history->SetURITitle(mCurrentURI, mTitle); - } else if (mGlobalHistory) { - mGlobalHistory->SetPageTitle(mCurrentURI, nsString(mTitle)); } } @@ -10381,8 +10365,6 @@ nsDocShell::InternalLoad(nsIURI* aURI, nsCOMPtr history = services::GetHistoryService(); if (history) { history->SetURITitle(aURI, mTitle); - } else if (mGlobalHistory) { - mGlobalHistory->SetPageTitle(aURI, mTitle); } } @@ -12209,8 +12191,6 @@ nsDocShell::UpdateURLAndHistory(nsIDocument* aDocument, nsIURI* aNewURI, nsCOMPtr history = services::GetHistoryService(); if (history) { history->SetURITitle(aNewURI, mTitle); - } else if (mGlobalHistory) { - mGlobalHistory->SetPageTitle(aNewURI, mTitle); } } @@ -13185,12 +13165,6 @@ nsDocShell::AddURIVisit(nsIURI* aURI, } (void)history->VisitURI(aURI, aPreviousURI, visitURIFlags); - } else if (mGlobalHistory) { - // Falls back to sync global history interface. - (void)mGlobalHistory->AddURI(aURI, - !!aChannelRedirectFlags, - !IsFrame(), - aReferrerURI); } } diff --git a/system/docshell/base/nsDocShell.h b/system/docshell/base/nsDocShell.h index f8fead3ac..4d8f06302 100644 --- a/system/docshell/base/nsDocShell.h +++ b/system/docshell/base/nsDocShell.h @@ -81,7 +81,6 @@ class nsIContentViewer; class nsIDocument; class nsIDOMNode; class nsIDocShellTreeOwner; -class nsIGlobalHistory2; class nsIHttpChannel; class nsIMutableArray; class nsIPrompt; @@ -562,8 +561,7 @@ protected: uint32_t aChannelRedirectFlags); /** - * Helper function for adding a URI visit using IHistory. If IHistory is - * not available, the method tries nsIGlobalHistory2. + * Helper function for adding a URI visit using IHistory. * * The IHistory API maintains chains of visits, tracking both HTTP referrers * and redirects for a user session. VisitURI requires the current URI and @@ -828,7 +826,6 @@ protected: uint32_t mReferrerPolicy; RefPtr mScriptGlobal; nsCOMPtr mSessionHistory; - nsCOMPtr mGlobalHistory; nsCOMPtr mFind; nsCOMPtr mCommandManager; // Reference to the SHEntry for this docshell until the page is destroyed. diff --git a/system/docshell/base/nsDownloadHistory.cpp b/system/docshell/base/nsDownloadHistory.cpp deleted file mode 100644 index 5fa44d473..000000000 --- a/system/docshell/base/nsDownloadHistory.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "nsDownloadHistory.h" -#include "nsCOMPtr.h" -#include "nsServiceManagerUtils.h" -#include "nsIGlobalHistory2.h" -#include "nsIObserverService.h" -#include "nsIURI.h" -#include "mozilla/Services.h" - -NS_IMPL_ISUPPORTS(nsDownloadHistory, nsIDownloadHistory) - -NS_IMETHODIMP -nsDownloadHistory::AddDownload(nsIURI* aSource, - nsIURI* aReferrer, - PRTime aStartTime, - nsIURI* aDestination) -{ - NS_ENSURE_ARG_POINTER(aSource); - - nsCOMPtr history = - do_GetService("@mozilla.org/browser/global-history;2"); - if (!history) { - return NS_ERROR_NOT_AVAILABLE; - } - - bool visited; - nsresult rv = history->IsVisited(aSource, &visited); - NS_ENSURE_SUCCESS(rv, rv); - - rv = history->AddURI(aSource, false, true, aReferrer); - NS_ENSURE_SUCCESS(rv, rv); - - if (!visited) { - nsCOMPtr os = mozilla::services::GetObserverService(); - if (os) { - os->NotifyObservers(aSource, NS_LINK_VISITED_EVENT_TOPIC, nullptr); - } - } - - return NS_OK; -} - -NS_IMETHODIMP -nsDownloadHistory::RemoveAllDownloads() -{ - return NS_ERROR_NOT_IMPLEMENTED; -} diff --git a/system/docshell/base/nsDownloadHistory.h b/system/docshell/base/nsDownloadHistory.h deleted file mode 100644 index 297868c00..000000000 --- a/system/docshell/base/nsDownloadHistory.h +++ /dev/null @@ -1,27 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef __nsDownloadHistory_h__ -#define __nsDownloadHistory_h__ - -#include "nsIDownloadHistory.h" -#include "mozilla/Attributes.h" - -#define NS_DOWNLOADHISTORY_CID \ - {0x2ee83680, 0x2af0, 0x4bcb, {0xbf, 0xa0, 0xc9, 0x70, 0x5f, 0x65, 0x54, 0xf1}} - -class nsDownloadHistory final : public nsIDownloadHistory -{ -public: - NS_DECL_ISUPPORTS - NS_DECL_NSIDOWNLOADHISTORY - - NS_DEFINE_STATIC_CID_ACCESSOR(NS_DOWNLOADHISTORY_CID) - -private: - ~nsDownloadHistory() {} -}; - -#endif // __nsDownloadHistory_h__ diff --git a/system/docshell/base/nsIDownloadHistory.idl b/system/docshell/base/nsIDownloadHistory.idl deleted file mode 100644 index ed2a19deb..000000000 --- a/system/docshell/base/nsIDownloadHistory.idl +++ /dev/null @@ -1,58 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * vim: sw=2 ts=2 sts=2 - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "nsISupports.idl" - -interface nsIURI; - -/** - * This interface can be used to add a download to history. There is a separate - * interface specifically for downloads in case embedders choose to track - * downloads differently from other types of history. - */ -[scriptable, uuid(4dcd6a12-a091-4f38-8360-022929635746)] -interface nsIDownloadHistory : nsISupports { - /** - * Adds a download to history. This will also notify observers that the - * URI aSource is visited with the topic NS_LINK_VISITED_EVENT_TOPIC if - * aSource has not yet been visited. - * - * @param aSource - * The source of the download we are adding to history. This cannot be - * null. - * @param aReferrer - * [optional] The referrer of source URI. - * @param aStartTime - * [optional] The time the download was started. If the start time - * is not given, the current time is used. - * @param aDestination - * [optional] The target where the download is to be saved on the local - * filesystem. - * @throws NS_ERROR_NOT_AVAILABLE - * In a situation where a history implementation is not available, - * where 'history implementation' refers to something like - * nsIGlobalHistory and friends. - * @note This addition is not guaranteed to be synchronous, since it delegates - * the actual addition to the underlying history implementation. If you - * need to observe the completion of the addition, use the underlying - * history implementation's notifications system (e.g. nsINavHistoryObserver - * for toolkit's implementation of this interface). - */ - void addDownload(in nsIURI aSource, [optional] in nsIURI aReferrer, - [optional] in PRTime aStartTime, - [optional] in nsIURI aDestination); - - /** - * Remove all downloads from history. - * - * @note This removal is not guaranteed to be synchronous, since it delegates - * the actual removal to the underlying history implementation. If you - * need to observe the completion of the removal, use the underlying - * history implementation's notifications system (e.g. nsINavHistoryObserver - * for toolkit's implementation of this interface). - */ - void removeAllDownloads(); -}; diff --git a/system/docshell/base/nsIGlobalHistory2.idl b/system/docshell/base/nsIGlobalHistory2.idl deleted file mode 100644 index aa8b44620..000000000 --- a/system/docshell/base/nsIGlobalHistory2.idl +++ /dev/null @@ -1,59 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -/** - * Provides information about global history to gecko. - * - * @note This interface replaces and deprecates nsIGlobalHistory. - */ - -#include "nsISupports.idl" -interface nsIURI; - -%{ C++ - -// nsIObserver topic to fire when you add new visited URIs to the history; -// the nsIURI is the subject -#define NS_LINK_VISITED_EVENT_TOPIC "link-visited" - -%} - -[scriptable, uuid(cf777d42-1270-4b34-be7b-2931c93feda5)] -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 - * @param aReferrer the URI of the referring page - * - * @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: for the main URI and the - * referrer. - */ - void addURI(in nsIURI aURI, in boolean aRedirect, in boolean aToplevel, in nsIURI aReferrer); - - /** - * 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/system/docshell/build/nsDocShellModule.cpp b/system/docshell/build/nsDocShellModule.cpp index b36d70b56..59043abe4 100644 --- a/system/docshell/build/nsDocShellModule.cpp +++ b/system/docshell/build/nsDocShellModule.cpp @@ -31,9 +31,6 @@ #include "nsSHistory.h" #include "nsSHTransaction.h" -// download history -#include "nsDownloadHistory.h" - using mozilla::dom::ContentHandlerService; static bool gInitialized = false; @@ -87,9 +84,6 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsSHEntry) NS_GENERIC_FACTORY_CONSTRUCTOR(nsSHTransaction) NS_GENERIC_FACTORY_CONSTRUCTOR(nsSHistory) -// download history -NS_GENERIC_FACTORY_CONSTRUCTOR(nsDownloadHistory) - NS_DEFINE_NAMED_CID(NS_DOCSHELL_CID); NS_DEFINE_NAMED_CID(NS_DEFAULTURIFIXUP_CID); NS_DEFINE_NAMED_CID(NS_WEBNAVIGATION_INFO_CID); @@ -109,7 +103,6 @@ NS_DEFINE_NAMED_CID(NS_SHENTRY_CID); NS_DEFINE_NAMED_CID(NS_SHTRANSACTION_CID); NS_DEFINE_NAMED_CID(NS_SHISTORY_CID); NS_DEFINE_NAMED_CID(NS_SHISTORY_INTERNAL_CID); -NS_DEFINE_NAMED_CID(NS_DOWNLOADHISTORY_CID); NS_DEFINE_NAMED_CID(NS_CONTENTHANDLERSERVICE_CID); const mozilla::Module::CIDEntry kDocShellCIDs[] = { @@ -134,7 +127,6 @@ const mozilla::Module::CIDEntry kDocShellCIDs[] = { { &kNS_SHTRANSACTION_CID, false, nullptr, nsSHTransactionConstructor }, { &kNS_SHISTORY_CID, false, nullptr, nsSHistoryConstructor }, { &kNS_SHISTORY_INTERNAL_CID, false, nullptr, nsSHistoryConstructor }, - { &kNS_DOWNLOADHISTORY_CID, false, nullptr, nsDownloadHistoryConstructor }, { nullptr } }; @@ -188,7 +180,6 @@ const mozilla::Module::ContractIDEntry kDocShellContracts[] = { { NS_SHTRANSACTION_CONTRACTID, &kNS_SHTRANSACTION_CID }, { NS_SHISTORY_CONTRACTID, &kNS_SHISTORY_CID }, { NS_SHISTORY_INTERNAL_CONTRACTID, &kNS_SHISTORY_INTERNAL_CID }, - { NS_DOWNLOADHISTORY_CONTRACTID, &kNS_DOWNLOADHISTORY_CID }, { nullptr } }; -- cgit v1.2.3