Bug 739219 - Remove nsIBrowserHistory. r=standard8
MozReview-Commit-ID: G1n44eSFWr1
--- a/toolkit/components/places/PlacesUtils.jsm
+++ b/toolkit/components/places/PlacesUtils.jsm
@@ -1848,17 +1848,16 @@ var PlacesUtils = {
return rootItem;
}
};
XPCOMUtils.defineLazyGetter(PlacesUtils, "history", function() {
let hs = Cc["@mozilla.org/browser/nav-history-service;1"]
.getService(Ci.nsINavHistoryService)
- .QueryInterface(Ci.nsIBrowserHistory)
.QueryInterface(Ci.nsPIPlacesDatabase);
return Object.freeze(new Proxy(hs, {
get(target, name) {
let property, object;
if (name in target) {
property = target[name];
object = target;
} else {
--- a/toolkit/components/places/moz.build
+++ b/toolkit/components/places/moz.build
@@ -17,17 +17,16 @@ if CONFIG['MOZ_PLACES']:
XPIDL_SOURCES += [
'mozIAsyncFavicons.idl',
'mozIAsyncHistory.idl',
'mozIAsyncLivemarks.idl',
'mozIColorAnalyzer.idl',
'mozIPlacesAutoComplete.idl',
'mozIPlacesPendingOperation.idl',
'nsIAnnotationService.idl',
- 'nsIBrowserHistory.idl',
'nsIFaviconService.idl',
'nsINavBookmarksService.idl',
'nsITaggingService.idl',
'nsPIPlacesDatabase.idl',
]
EXPORTS.mozilla.places = [
'Database.h',
deleted file mode 100644
--- a/toolkit/components/places/nsIBrowserHistory.idl
+++ /dev/null
@@ -1,48 +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/. */
-
-/*
- * browser-specific interface to global history
- */
-
-#include "nsISupports.idl"
-#include "nsIGlobalHistory2.idl"
-
-[scriptable, uuid(20d31479-38de-49f4-9300-566d6e834c66)]
-interface nsIBrowserHistory : nsISupports
-{
- /**
- * Removes all global history information about pages for a given host.
- *
- * @param aHost
- * Hostname to be removed.
- * An empty host name means local files and anything else with no
- * hostname. You can also pass in the localized "(local files)"
- * title given to you from a history query to remove all
- * history information from local files.
- * @param aEntireDomain
- * If true, will also delete pages from sub hosts (so if
- * passed in "microsoft.com" will delete "www.microsoft.com",
- * "msdn.microsoft.com", etc.).
- *
- * @note The removal happens in a batch.
- */
- void removePagesFromHost(in AUTF8String aHost,
- in boolean aEntireDomain);
-
- /**
- * Removes all pages for a given timeframe.
- * Limits are included: aBeginTime <= timeframe <= aEndTime
- *
- * @param aBeginTime
- * Microseconds from epoch, representing the initial time.
- * @param aEndTime
- * Microseconds from epoch, representing the final time.
- *
- * @note The removal happens in a batch.
- */
- void removePagesByTimeframe(in PRTime aBeginTime,
- in PRTime aEndTime);
-};
--- a/toolkit/components/places/nsNavHistory.cpp
+++ b/toolkit/components/places/nsNavHistory.cpp
@@ -172,29 +172,27 @@ static const char* kObservedPrefs[] = {
NS_IMPL_ADDREF(nsNavHistory)
NS_IMPL_RELEASE(nsNavHistory)
NS_IMPL_CLASSINFO(nsNavHistory, nullptr, nsIClassInfo::SINGLETON,
NS_NAVHISTORYSERVICE_CID)
NS_INTERFACE_MAP_BEGIN(nsNavHistory)
NS_INTERFACE_MAP_ENTRY(nsINavHistoryService)
- NS_INTERFACE_MAP_ENTRY(nsIBrowserHistory)
NS_INTERFACE_MAP_ENTRY(nsIObserver)
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
NS_INTERFACE_MAP_ENTRY(nsPIPlacesDatabase)
NS_INTERFACE_MAP_ENTRY(mozIStorageVacuumParticipant)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsINavHistoryService)
NS_IMPL_QUERY_CLASSINFO(nsNavHistory)
NS_INTERFACE_MAP_END
// We don't care about flattening everything
NS_IMPL_CI_INTERFACE_GETTER(nsNavHistory,
- nsINavHistoryService,
- nsIBrowserHistory)
+ nsINavHistoryService)
namespace {
static int64_t GetSimpleBookmarksQueryFolder(const RefPtr<nsNavHistoryQuery>& aQuery,
const RefPtr<nsNavHistoryQueryOptions>& aOptions);
static void ParseSearchTermsFromQuery(const RefPtr<nsNavHistoryQuery>& aQuery,
nsTArray<nsString>* aTerms);
@@ -2176,316 +2174,16 @@ nsNavHistory::GetHistoryDisabled(bool *_
{
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
NS_ENSURE_ARG_POINTER(_retval);
*_retval = IsHistoryDisabled();
return NS_OK;
}
-// Browser history *************************************************************
-
-
-// nsNavHistory::RemovePagesInternal
-//
-// Deletes a list of placeIds from history.
-// This is an internal method used by RemovePages, RemovePagesFromHost and
-// RemovePagesByTimeframe.
-// Takes a comma separated list of place ids.
-// This method does not do any observer notification.
-
-nsresult
-nsNavHistory::RemovePagesInternal(const nsCString& aPlaceIdsQueryString)
-{
- // Return early if there is nothing to delete.
- if (aPlaceIdsQueryString.IsEmpty())
- return NS_OK;
-
- nsCOMPtr<mozIStorageConnection> conn = mDB->MainConn();
- if (!conn) {
- return NS_ERROR_UNEXPECTED;
- }
- mozStorageTransaction transaction(conn, false,
- mozIStorageConnection::TRANSACTION_DEFAULT,
- true);
-
- // Delete all visits for the specified place ids.
- nsresult rv = conn->ExecuteSimpleSQL(
- NS_LITERAL_CSTRING(
- "DELETE FROM moz_historyvisits WHERE place_id IN (") +
- aPlaceIdsQueryString +
- NS_LITERAL_CSTRING(")")
- );
- NS_ENSURE_SUCCESS(rv, rv);
-
- rv = CleanupPlacesOnVisitsDelete(aPlaceIdsQueryString);
- NS_ENSURE_SUCCESS(rv, rv);
-
- // Invalidate the cached value for whether there's history or not.
- mDaysOfHistory = -1;
-
- return transaction.Commit();
-}
-
-
-/**
- * Performs cleanup on places that just had all their visits removed, including
- * deletion of those places. This is an internal method used by
- * RemovePagesInternal. This method does not execute in a transaction, so
- * callers should make sure they begin one if needed.
- *
- * @param aPlaceIdsQueryString
- * A comma-separated list of place IDs, each of which just had all its
- * visits removed
- */
-nsresult
-nsNavHistory::CleanupPlacesOnVisitsDelete(const nsCString& aPlaceIdsQueryString)
-{
- // Return early if there is nothing to delete.
- if (aPlaceIdsQueryString.IsEmpty())
- return NS_OK;
-
- // Collect about-to-be-deleted URIs to notify onDeleteURI.
- nsCOMPtr<mozIStorageStatement> stmt = mDB->GetStatement(NS_LITERAL_CSTRING(
- "SELECT h.id, h.url, h.guid, "
- "(SUBSTR(h.url, 1, 6) <> 'place:' "
- " AND NOT EXISTS (SELECT b.id FROM moz_bookmarks b "
- "WHERE b.fk = h.id LIMIT 1)) as whole_entry "
- "FROM moz_places h "
- "WHERE h.id IN ( ") + aPlaceIdsQueryString + NS_LITERAL_CSTRING(")")
- );
- NS_ENSURE_STATE(stmt);
- mozStorageStatementScoper scoper(stmt);
-
- nsCString filteredPlaceIds;
- nsCOMArray<nsIURI> URIs;
- nsTArray<nsCString> GUIDs;
- bool hasMore;
- while (NS_SUCCEEDED(stmt->ExecuteStep(&hasMore)) && hasMore) {
- int64_t placeId;
- nsresult rv = stmt->GetInt64(0, &placeId);
- NS_ENSURE_SUCCESS(rv, rv);
- nsAutoCString URLString;
- rv = stmt->GetUTF8String(1, URLString);
- nsCString guid;
- rv = stmt->GetUTF8String(2, guid);
- int32_t wholeEntry;
- rv = stmt->GetInt32(3, &wholeEntry);
- nsCOMPtr<nsIURI> uri;
- rv = NS_NewURI(getter_AddRefs(uri), URLString);
- NS_ENSURE_SUCCESS(rv, rv);
- if (wholeEntry) {
- if (!filteredPlaceIds.IsEmpty()) {
- filteredPlaceIds.Append(',');
- }
- filteredPlaceIds.AppendInt(placeId);
- URIs.AppendElement(uri.forget());
- GUIDs.AppendElement(guid);
- }
- else {
- // Notify that we will delete all visits for this page, but not the page
- // itself, since it's bookmarked or a place: query.
- NOTIFY_OBSERVERS(mCanNotify, mObservers, nsINavHistoryObserver,
- OnDeleteVisits(uri, 0, guid, nsINavHistoryObserver::REASON_DELETED, 0));
- }
- }
-
- // if the entry is not bookmarked and is not a place: uri
- // then we can remove it from moz_places.
- // Note that we do NOT delete favicons. Any unreferenced favicons will be
- // deleted next time the browser is shut down.
- nsCOMPtr<mozIStorageConnection> conn = mDB->MainConn();
- if (!conn) {
- return NS_ERROR_UNEXPECTED;
- }
- nsresult rv = conn->ExecuteSimpleSQL(
- NS_LITERAL_CSTRING(
- "DELETE FROM moz_places WHERE id IN ( "
- ) + filteredPlaceIds + NS_LITERAL_CSTRING(
- ") "
- )
- );
- NS_ENSURE_SUCCESS(rv, rv);
-
- // Expire orphan icons.
- rv = conn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
- "DELETE FROM moz_pages_w_icons "
- "WHERE page_url_hash NOT IN (SELECT url_hash FROM moz_places) "
- ));
- NS_ENSURE_SUCCESS(rv, rv);
- rv = conn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
- "DELETE FROM moz_icons "
- "WHERE root = 0 AND id NOT IN (SELECT icon_id FROM moz_icons_to_pages) "
- ));
- NS_ENSURE_SUCCESS(rv, rv);
-
- // Hosts accumulated during the places delete are updated through a trigger
- // (see nsPlacesTriggers.h).
- rv = conn->ExecuteSimpleSQL(
- NS_LITERAL_CSTRING("DELETE FROM moz_updatehostsdelete_temp")
- );
- NS_ENSURE_SUCCESS(rv, rv);
-
- // Invalidate frecencies of touched places, since they need recalculation.
- rv = invalidateFrecencies(aPlaceIdsQueryString);
- NS_ENSURE_SUCCESS(rv, rv);
-
- // Finally notify about the removed URIs.
- for (int32_t i = 0; i < URIs.Count(); ++i) {
- NOTIFY_OBSERVERS(mCanNotify, mObservers, nsINavHistoryObserver,
- OnDeleteURI(URIs[i], GUIDs[i], nsINavHistoryObserver::REASON_DELETED));
- }
-
- return NS_OK;
-}
-
-
-// nsNavHistory::RemovePagesFromHost
-//
-// This function will delete all history information about pages from a
-// given host. If aEntireDomain is set, we will also delete pages from
-// sub hosts (so if we are passed in "microsoft.com" we delete
-// "www.microsoft.com", "msdn.microsoft.com", etc.). An empty host name
-// means local files and anything else with no host name. You can also pass
-// in the localized "(local files)" title given to you from a history query.
-//
-// Silently fails if we have no knowledge of the host.
-//
-// This sends onBeginUpdateBatch/onEndUpdateBatch to observers
-
-NS_IMETHODIMP
-nsNavHistory::RemovePagesFromHost(const nsACString& aHost, bool aEntireDomain)
-{
- NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
-
- nsresult rv;
- // Local files don't have any host name. We don't want to delete all files in
- // history when we get passed an empty string, so force to exact match
- if (aHost.IsEmpty())
- aEntireDomain = false;
-
- // translate "(local files)" to an empty host name
- // be sure to use the TitleForDomain to get the localized name
- nsCString localFiles;
- TitleForDomain(EmptyCString(), localFiles);
- nsAutoString host16;
- if (!aHost.Equals(localFiles))
- CopyUTF8toUTF16(aHost, host16);
-
- // see BindQueryClauseParameters for how this host selection works
- nsAutoString revHostDot;
- GetReversedHostname(host16, revHostDot);
- NS_ASSERTION(revHostDot[revHostDot.Length() - 1] == '.', "Invalid rev. host");
- nsAutoString revHostSlash(revHostDot);
- revHostSlash.Truncate(revHostSlash.Length() - 1);
- revHostSlash.Append('/');
-
- // build condition string based on host selection type
- nsAutoCString conditionString;
- if (aEntireDomain)
- conditionString.AssignLiteral("rev_host >= ?1 AND rev_host < ?2 ");
- else
- conditionString.AssignLiteral("rev_host = ?1 ");
-
- // create statement depending on delete type
- nsCOMPtr<mozIStorageStatement> statement = mDB->GetStatement(
- NS_LITERAL_CSTRING("SELECT id FROM moz_places WHERE ") + conditionString
- );
- NS_ENSURE_STATE(statement);
- mozStorageStatementScoper scoper(statement);
-
- rv = statement->BindStringByIndex(0, revHostDot);
- NS_ENSURE_SUCCESS(rv, rv);
- if (aEntireDomain) {
- rv = statement->BindStringByIndex(1, revHostSlash);
- NS_ENSURE_SUCCESS(rv, rv);
- }
-
- nsCString hostPlaceIds;
- bool hasMore = false;
- while (NS_SUCCEEDED(statement->ExecuteStep(&hasMore)) && hasMore) {
- if (!hostPlaceIds.IsEmpty())
- hostPlaceIds.Append(',');
- int64_t placeId;
- rv = statement->GetInt64(0, &placeId);
- NS_ENSURE_SUCCESS(rv, rv);
- hostPlaceIds.AppendInt(placeId);
- }
-
- // force a full refresh calling onEndUpdateBatch (will call Refresh())
- UpdateBatchScoper batch(*this); // sends Begin/EndUpdateBatch to observers
-
- rv = RemovePagesInternal(hostPlaceIds);
- NS_ENSURE_SUCCESS(rv, rv);
-
- // Clear the registered embed visits.
- clearEmbedVisits();
-
- return NS_OK;
-}
-
-
-// nsNavHistory::RemovePagesByTimeframe
-//
-// This function will delete all history information about
-// pages for a given timeframe.
-// Limits are included: aBeginTime <= timeframe <= aEndTime
-//
-// This method sends onBeginUpdateBatch/onEndUpdateBatch to observers
-
-NS_IMETHODIMP
-nsNavHistory::RemovePagesByTimeframe(PRTime aBeginTime, PRTime aEndTime)
-{
- NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
-
- nsresult rv;
- // build a list of place ids to delete
- nsCString deletePlaceIdsQueryString;
-
- // we only need to know if a place has a visit into the given timeframe
- // this query is faster than actually selecting in moz_historyvisits
- nsCOMPtr<mozIStorageStatement> selectByTime = mDB->GetStatement(
- "SELECT h.id FROM moz_places h WHERE "
- "EXISTS "
- "(SELECT id FROM moz_historyvisits v WHERE v.place_id = h.id "
- "AND v.visit_date >= :from_date AND v.visit_date <= :to_date LIMIT 1)"
- );
- NS_ENSURE_STATE(selectByTime);
- mozStorageStatementScoper selectByTimeScoper(selectByTime);
-
- rv = selectByTime->BindInt64ByName(NS_LITERAL_CSTRING("from_date"), aBeginTime);
- NS_ENSURE_SUCCESS(rv, rv);
- rv = selectByTime->BindInt64ByName(NS_LITERAL_CSTRING("to_date"), aEndTime);
- NS_ENSURE_SUCCESS(rv, rv);
-
- bool hasMore = false;
- while (NS_SUCCEEDED(selectByTime->ExecuteStep(&hasMore)) && hasMore) {
- int64_t placeId;
- rv = selectByTime->GetInt64(0, &placeId);
- NS_ENSURE_SUCCESS(rv, rv);
- if (placeId != 0) {
- if (!deletePlaceIdsQueryString.IsEmpty())
- deletePlaceIdsQueryString.Append(',');
- deletePlaceIdsQueryString.AppendInt(placeId);
- }
- }
-
- // force a full refresh calling onEndUpdateBatch (will call Refresh())
- UpdateBatchScoper batch(*this); // sends Begin/EndUpdateBatch to observers
-
- rv = RemovePagesInternal(deletePlaceIdsQueryString);
- NS_ENSURE_SUCCESS(rv, rv);
-
- // Clear the registered embed visits.
- clearEmbedVisits();
-
- return NS_OK;
-}
-
-
// Call this method before visiting a URL in order to help determine the
// transition type of the visit.
//
// @see MarkPageAsFollowedBookmark
NS_IMETHODIMP
nsNavHistory::MarkPageAsTyped(nsIURI *aURI)
{
@@ -3351,26 +3049,19 @@ nsNavHistory::registerEmbedVisit(nsIURI*
bool
nsNavHistory::hasEmbedVisit(nsIURI* aURI) {
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
return !!mEmbedVisits.GetEntry(aURI);
}
-void
-nsNavHistory::clearEmbedVisits() {
- NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
-
- mEmbedVisits.Clear();
-}
-
NS_IMETHODIMP
nsNavHistory::ClearEmbedVisits() {
- clearEmbedVisits();
+ mEmbedVisits.Clear();
return NS_OK;
}
NS_IMETHODIMP
nsNavHistory::MakeGuid(nsACString& aGuid) {
if (NS_FAILED(GenerateGUID(aGuid))) {
MOZ_ASSERT(false, "Shouldn't fail to create a guid!");
aGuid.SetIsVoid(true);
@@ -3827,34 +3518,16 @@ nsNavHistory::SendPageChangedNotificatio
const nsAString& aNewValue,
const nsACString& aGUID)
{
MOZ_ASSERT(!aGUID.IsEmpty());
NOTIFY_OBSERVERS(mCanNotify, mObservers, nsINavHistoryObserver,
OnPageChanged(aURI, aChangedAttribute, aNewValue, aGUID));
}
-// nsNavHistory::TitleForDomain
-//
-// This computes the title for a given domain. Normally, this is just the
-// domain name, but we specially handle empty cases to give you a nice
-// localized string.
-
-void
-nsNavHistory::TitleForDomain(const nsCString& domain, nsACString& aTitle)
-{
- if (! domain.IsEmpty()) {
- aTitle = domain;
- return;
- }
-
- // use the localized one instead
- GetStringFromName("localhost", aTitle);
-}
-
void
nsNavHistory::GetAgeInDaysString(int32_t aInt, const char* aName,
nsACString& aResult)
{
nsIStringBundle *bundle = GetBundle();
if (bundle) {
nsAutoString intString;
intString.AppendInt(aInt);
--- a/toolkit/components/places/nsNavHistory.h
+++ b/toolkit/components/places/nsNavHistory.h
@@ -3,19 +3,19 @@
* 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 nsNavHistory_h_
#define nsNavHistory_h_
#include "nsINavHistoryService.h"
#include "nsPIPlacesDatabase.h"
-#include "nsIBrowserHistory.h"
#include "nsINavBookmarksService.h"
#include "nsIFaviconService.h"
+#include "nsIGlobalHistory2.h"
#include "nsIObserverService.h"
#include "nsICollation.h"
#include "nsIStringBundle.h"
#include "nsITimer.h"
#include "nsMaybeWeakPtr.h"
#include "nsCategoryCache.h"
#include "nsNetCID.h"
@@ -73,28 +73,26 @@ class nsIIDNService;
class PlacesSQLQueryBuilder;
class nsIAutoCompleteController;
// nsNavHistory
class nsNavHistory final : public nsSupportsWeakReference
, public nsINavHistoryService
, public nsIObserver
- , public nsIBrowserHistory
, public nsPIPlacesDatabase
, public mozIStorageVacuumParticipant
{
friend class PlacesSQLQueryBuilder;
public:
nsNavHistory();
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSINAVHISTORYSERVICE
- NS_DECL_NSIBROWSERHISTORY
NS_DECL_NSIOBSERVER
NS_DECL_NSPIPLACESDATABASE
NS_DECL_MOZISTORAGEVACUUMPARTICIPANT
/**
* Obtains the nsNavHistory object.
*/
static already_AddRefed<nsNavHistory> GetSingleton();
@@ -347,21 +345,16 @@ public:
* Returns whether the specified url has a embed visit.
*
* @param aURI
* URI of the page.
* @return whether the page has a embed visit.
*/
bool hasEmbedVisit(nsIURI* aURI);
- /**
- * Clears all registered embed visits.
- */
- void clearEmbedVisits();
-
int32_t GetFrecencyAgedWeight(int32_t aAgeInDays) const
{
if (aAgeInDays <= mFirstBucketCutoffInDays) {
return mFirstBucketWeight;
}
if (aAgeInDays <= mSecondBucketCutoffInDays) {
return mSecondBucketWeight;
}
@@ -507,19 +500,16 @@ protected:
// Database handle.
RefPtr<mozilla::places::Database> mDB;
/**
* Decays frecency and inputhistory values. Runs on idle-daily.
*/
nsresult DecayFrecency();
- nsresult RemovePagesInternal(const nsCString& aPlaceIdsQueryString);
- nsresult CleanupPlacesOnVisitsDelete(const nsCString& aPlaceIdsQueryString);
-
/**
* Loads all of the preferences that we use into member variables.
*
* @note If mPrefBranch is nullptr, this does nothing.
*/
void LoadPrefs();
/**
@@ -548,18 +538,16 @@ protected:
nsresult BindQueryClauseParameters(mozIStorageBaseStatement* statement,
const RefPtr<nsNavHistoryQuery>& aQuery,
const RefPtr<nsNavHistoryQueryOptions>& aOptions);
nsresult ResultsAsList(mozIStorageStatement* statement,
nsNavHistoryQueryOptions* aOptions,
nsCOMArray<nsNavHistoryResultNode>* aResults);
- void TitleForDomain(const nsCString& domain, nsACString& aTitle);
-
// observers
nsMaybeWeakPtrArray<nsINavHistoryObserver> mObservers;
// effective tld service
nsCOMPtr<nsIEffectiveTLDService> mTLDService;
nsCOMPtr<nsIIDNService> mIDNService;
// localization