Bug 838874 - Stop implementing nsIGlobalHistory2.

r=Mano sr=gavin
This commit is contained in:
Marco Bonardo
2013-03-20 18:09:41 +01:00
parent bf30c03573
commit 04b4837fa1
11 changed files with 93 additions and 503 deletions

View File

@@ -3,6 +3,10 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this # 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/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
"resource://gre/modules/PlacesUtils.jsm");
function Sanitizer() {} function Sanitizer() {}
Sanitizer.prototype = { Sanitizer.prototype = {
// warning to the caller: this one may raise an exception (e.g. bug #265028) // warning to the caller: this one may raise an exception (e.g. bug #265028)
@@ -181,12 +185,10 @@ Sanitizer.prototype = {
history: { history: {
clear: function () clear: function ()
{ {
var globalHistory = Components.classes["@mozilla.org/browser/global-history;2"]
.getService(Components.interfaces.nsIBrowserHistory);
if (this.range) if (this.range)
globalHistory.removeVisitsByTimeframe(this.range[0], this.range[1]); PlacesUtils.history.removeVisitsByTimeframe(this.range[0], this.range[1]);
else else
globalHistory.removeAllPages(); PlacesUtils.history.removeAllPages();
try { try {
var os = Components.classes["@mozilla.org/observer-service;1"] var os = Components.classes["@mozilla.org/observer-service;1"]

View File

@@ -3,6 +3,10 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
"resource://gre/modules/PlacesUtils.jsm");
function Sanitizer() {} function Sanitizer() {}
Sanitizer.prototype = { Sanitizer.prototype = {
// warning to the caller: this one may raise an exception (e.g. bug #265028) // warning to the caller: this one may raise an exception (e.g. bug #265028)
@@ -165,8 +169,7 @@ Sanitizer.prototype = {
history: { history: {
clear: function () clear: function ()
{ {
var globalHistory = Cc["@mozilla.org/browser/global-history;2"].getService(Ci.nsIBrowserHistory); PlacesUtils.history.removeAllPages();
globalHistory.removeAllPages();
try { try {
Services.obs.notifyObservers(null, "browser:purge-session-history", ""); Services.obs.notifyObservers(null, "browser:purge-session-history", "");

View File

@@ -1995,7 +1995,7 @@ this.PlacesUtils = {
asyncGetBookmarkIds: function PU_asyncGetBookmarkIds(aURI, aCallback, aScope) asyncGetBookmarkIds: function PU_asyncGetBookmarkIds(aURI, aCallback, aScope)
{ {
if (!this._asyncGetBookmarksStmt) { if (!this._asyncGetBookmarksStmt) {
let db = this.history.QueryInterface(Ci.nsPIPlacesDatabase).DBConnection; let db = this.history.DBConnection;
this._asyncGetBookmarksStmt = db.createAsyncStatement( this._asyncGetBookmarksStmt = db.createAsyncStatement(
"SELECT b.id " "SELECT b.id "
+ "FROM moz_bookmarks b " + "FROM moz_bookmarks b "
@@ -2114,20 +2114,19 @@ AsyncStatementCancelWrapper.prototype = {
} }
} }
XPCOMUtils.defineLazyServiceGetter(PlacesUtils, "history", XPCOMUtils.defineLazyGetter(PlacesUtils, "history", function() {
"@mozilla.org/browser/nav-history-service;1", return Cc["@mozilla.org/browser/nav-history-service;1"]
"nsINavHistoryService"); .getService(Ci.nsINavHistoryService)
.QueryInterface(Ci.nsIBrowserHistory)
.QueryInterface(Ci.nsPIPlacesDatabase);
});
XPCOMUtils.defineLazyServiceGetter(PlacesUtils, "asyncHistory", XPCOMUtils.defineLazyServiceGetter(PlacesUtils, "asyncHistory",
"@mozilla.org/browser/history;1", "@mozilla.org/browser/history;1",
"mozIAsyncHistory"); "mozIAsyncHistory");
XPCOMUtils.defineLazyGetter(PlacesUtils, "bhistory", function() { XPCOMUtils.defineLazyGetter(PlacesUtils, "bhistory", function() {
return PlacesUtils.history.QueryInterface(Ci.nsIBrowserHistory); return PlacesUtils.history;
});
XPCOMUtils.defineLazyGetter(PlacesUtils, "ghistory2", function() {
return PlacesUtils.history.QueryInterface(Ci.nsIGlobalHistory2);
}); });
XPCOMUtils.defineLazyServiceGetter(PlacesUtils, "favicons", XPCOMUtils.defineLazyServiceGetter(PlacesUtils, "favicons",

View File

@@ -10,8 +10,8 @@
#include "nsISupports.idl" #include "nsISupports.idl"
#include "nsIGlobalHistory2.idl" #include "nsIGlobalHistory2.idl"
[scriptable, uuid(837ea2db-c4c7-4f4c-8982-6c8c73e8f5d3)] [scriptable, uuid(20d31479-38de-49f4-9300-566d6e834c66)]
interface nsIBrowserHistory : nsIGlobalHistory2 interface nsIBrowserHistory : nsISupports
{ {
/** /**
* Removes a page from global history. * Removes a page from global history.

View File

@@ -166,7 +166,6 @@ NS_IMPL_CLASSINFO(nsNavHistory, NULL, nsIClassInfo::SINGLETON,
NS_NAVHISTORYSERVICE_CID) NS_NAVHISTORYSERVICE_CID)
NS_INTERFACE_MAP_BEGIN(nsNavHistory) NS_INTERFACE_MAP_BEGIN(nsNavHistory)
NS_INTERFACE_MAP_ENTRY(nsINavHistoryService) NS_INTERFACE_MAP_ENTRY(nsINavHistoryService)
NS_INTERFACE_MAP_ENTRY(nsIGlobalHistory2)
NS_INTERFACE_MAP_ENTRY(nsIBrowserHistory) NS_INTERFACE_MAP_ENTRY(nsIBrowserHistory)
NS_INTERFACE_MAP_ENTRY(nsIObserver) NS_INTERFACE_MAP_ENTRY(nsIObserver)
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
@@ -178,10 +177,9 @@ NS_INTERFACE_MAP_BEGIN(nsNavHistory)
NS_INTERFACE_MAP_END NS_INTERFACE_MAP_END
// We don't care about flattening everything // We don't care about flattening everything
NS_IMPL_CI_INTERFACE_GETTER3( NS_IMPL_CI_INTERFACE_GETTER2(
nsNavHistory nsNavHistory
, nsINavHistoryService , nsINavHistoryService
, nsIGlobalHistory2
, nsIBrowserHistory , nsIBrowserHistory
) )
@@ -620,33 +618,6 @@ nsNavHistory::FindLastVisit(nsIURI* aURI,
} }
// nsNavHistory::IsURIStringVisited
//
// Takes a URL as a string and returns true if we've visited it.
//
// Be careful to always reset the statement since it will be reused.
bool nsNavHistory::IsURIStringVisited(const nsACString& aURIString)
{
nsCOMPtr<mozIStorageStatement> stmt = mDB->GetStatement(
"SELECT 1 "
"FROM moz_places h "
"WHERE url = ?1 "
"AND last_visit_date NOTNULL "
);
NS_ENSURE_TRUE(stmt, false);
mozStorageStatementScoper scoper(stmt);
nsresult rv = URIBinder::Bind(stmt, 0, aURIString);
NS_ENSURE_SUCCESS(rv, false);
bool hasMore = false;
rv = stmt->ExecuteStep(&hasMore);
NS_ENSURE_SUCCESS(rv, false);
return hasMore;
}
void void
nsNavHistory::LoadPrefs() nsNavHistory::LoadPrefs()
{ {
@@ -1187,8 +1158,6 @@ nsNavHistory::invalidateFrecencies(const nsCString& aPlaceIdsQueryString)
// Call this method before visiting a URL in order to help determine the // Call this method before visiting a URL in order to help determine the
// transition type of the visit. // transition type of the visit.
// Later, in AddVisitChain() the next visit to this page will be associated to
// TRANSITION_BOOKMARK.
// //
// @see MarkPageAsTyped // @see MarkPageAsTyped
@@ -3113,8 +3082,6 @@ nsNavHistory::RemoveAllPages()
// Call this method before visiting a URL in order to help determine the // Call this method before visiting a URL in order to help determine the
// transition type of the visit. // transition type of the visit.
// Later, in AddVisitChain() the next visit to this page will be associated to
// TRANSITION_TYPED.
// //
// @see MarkPageAsFollowedBookmark // @see MarkPageAsFollowedBookmark
@@ -3147,8 +3114,6 @@ nsNavHistory::MarkPageAsTyped(nsIURI *aURI)
// Call this method before visiting a URL in order to help determine the // Call this method before visiting a URL in order to help determine the
// transition type of the visit. // transition type of the visit.
// Later, in AddVisitChain() the next visit to this page will be associated to
// TRANSITION_FRAMED_LINK or TRANSITION_LINK.
// //
// @see MarkPageAsTyped // @see MarkPageAsTyped
@@ -3240,232 +3205,6 @@ nsNavHistory::GetCharsetForURI(nsIURI* aURI,
} }
// nsGlobalHistory2 ************************************************************
// nsNavHistory::AddURI
//
// This is the main method of adding history entries.
NS_IMETHODIMP
nsNavHistory::AddURI(nsIURI *aURI, bool aRedirect,
bool aToplevel, nsIURI *aReferrer)
{
PLACES_WARN_DEPRECATED();
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
NS_ENSURE_ARG(aURI);
// filter out any unwanted URIs
bool canAdd = false;
nsresult rv = CanAddURI(aURI, &canAdd);
NS_ENSURE_SUCCESS(rv, rv);
if (!canAdd)
return NS_OK;
PRTime now = PR_Now();
rv = AddURIInternal(aURI, now, aRedirect, aToplevel, aReferrer);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
// nsNavHistory::AddURIInternal
//
// This does the work of AddURI so it can be done lazily.
nsresult
nsNavHistory::AddURIInternal(nsIURI* aURI, PRTime aTime, bool aRedirect,
bool aToplevel, nsIURI* aReferrer)
{
mozStorageTransaction transaction(mDB->MainConn(), false);
int64_t visitID = 0;
int64_t sessionID = 0;
nsresult rv = AddVisitChain(aURI, aTime, aToplevel, aRedirect, aReferrer,
&visitID, &sessionID);
NS_ENSURE_SUCCESS(rv, rv);
return transaction.Commit();
}
// nsNavHistory::AddVisitChain
//
// This function is sits between AddURI (which is called when a page is
// visited) and AddVisit (which creates the DB entries) to figure out what
// we should add and what are the detailed parameters that should be used
// (like referring visit ID and typed/bookmarked state).
//
// This function walks up the referring chain and recursively calls itself,
// each time calling InternalAdd to create a new history entry.
nsresult
nsNavHistory::AddVisitChain(nsIURI* aURI,
PRTime aTime,
bool aToplevel,
bool aIsRedirect,
nsIURI* aReferrerURI,
int64_t* aVisitID,
int64_t* aSessionID)
{
// This is the address that will be saved to from_visit column, will be
// overwritten later if needed.
nsCOMPtr<nsIURI> fromVisitURI = aReferrerURI;
nsAutoCString spec;
nsresult rv = aURI->GetSpec(spec);
NS_ENSURE_SUCCESS(rv, rv);
// A visit is considered EMBED if it's in a frame and the page visit does not
// come from a user's action (like clicking a link), otherwise is FRAMED_LINK.
// An embed visit should not appear in history views.
// See bug 381453 for details.
bool isEmbedVisit = !aToplevel &&
!CheckIsRecentEvent(&mRecentLink, spec);
uint32_t transitionType = 0;
if (aReferrerURI) {
// This page had a referrer.
// Check if the referrer has a previous visit.
PRTime lastVisitTime;
int64_t referringVisitId;
bool referrerHasPreviousVisit =
FindLastVisit(aReferrerURI, &referringVisitId, &lastVisitTime, aSessionID);
// Don't add a new visit if the referring site is the same as
// the new site. This happens when a page refreshes itself.
// Otherwise, if the page has never been added, the visit should be
// registered regardless.
bool referrerIsSame;
if (NS_SUCCEEDED(aURI->Equals(aReferrerURI, &referrerIsSame)) &&
referrerIsSame && referrerHasPreviousVisit) {
// Ensure a valid session id to the chain.
if (aIsRedirect)
*aSessionID = GetNewSessionID();
return NS_OK;
}
if (!referrerHasPreviousVisit ||
aTime - lastVisitTime > RECENT_EVENT_THRESHOLD) {
// Either the referrer has no visits or the last visit is too
// old to be part of this session. Thus start a new session.
*aSessionID = GetNewSessionID();
}
// Since referrer is set, this visit comes from an originating page.
// For top-level windows, visit is considered user-initiated and it should
// appear in history views.
// Visits to pages in frames are distinguished between user-initiated ones
// and automatic ones.
if (isEmbedVisit)
transitionType = nsINavHistoryService::TRANSITION_EMBED;
else if (!aToplevel)
transitionType = nsINavHistoryService::TRANSITION_FRAMED_LINK;
else
transitionType = nsINavHistoryService::TRANSITION_LINK;
}
else {
// When there is no referrer:
// - Check recent events for a typed-in uri.
// - Check recent events for a bookmark selection.
// - Otherwise mark as TRANSITION_LINK or TRANSITION_EMBED depending on
// whether it happens in a frame (see above for reasoning about this).
// Drag and drop operations are not handled, so they will most likely
// be marked as links.
if (CheckIsRecentEvent(&mRecentTyped, spec))
transitionType = nsINavHistoryService::TRANSITION_TYPED;
else if (CheckIsRecentEvent(&mRecentBookmark, spec))
transitionType = nsINavHistoryService::TRANSITION_BOOKMARK;
else if (isEmbedVisit)
transitionType = nsINavHistoryService::TRANSITION_EMBED;
else if (!aToplevel)
transitionType = nsINavHistoryService::TRANSITION_FRAMED_LINK;
else
transitionType = nsINavHistoryService::TRANSITION_LINK;
// Since there is no referrer, there is no way to continue am existing
// session.
*aSessionID = GetNewSessionID();
}
NS_WARN_IF_FALSE(transitionType > 0, "Visit must have a transition type");
// Create the visit and update the page entry.
return AddVisit(aURI, aTime, fromVisitURI, transitionType,
aIsRedirect, *aSessionID, aVisitID);
}
// nsNavHistory::IsVisited
//
// Note that this ignores the "hidden" flag. This function just checks if the
// given page is in the DB for link coloring. The "hidden" flag affects
// the history list view and autocomplete.
NS_IMETHODIMP
nsNavHistory::IsVisited(nsIURI *aURI, bool *_retval)
{
PLACES_WARN_DEPRECATED();
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
NS_ENSURE_ARG(aURI);
NS_ENSURE_ARG_POINTER(_retval);
// if history is disabled, we can optimize
if (IsHistoryDisabled()) {
*_retval = false;
return NS_OK;
}
nsAutoCString utf8URISpec;
nsresult rv = aURI->GetSpec(utf8URISpec);
NS_ENSURE_SUCCESS(rv, rv);
*_retval = hasEmbedVisit(aURI) ? true : IsURIStringVisited(utf8URISpec);
return NS_OK;
}
// nsNavHistory::SetPageTitle
//
// This sets the page title.
//
// Note that we do not allow empty real titles and will silently ignore such
// requests. When a URL is added we give it a default title based on the
// URL. Most pages provide a title and it gets replaced to something better.
// Some pages don't: some say <title></title>, and some don't have any title
// element. In BOTH cases, we get SetPageTitle(URI, ""), but in both cases,
// our default title is more useful to the user than "(no title)".
NS_IMETHODIMP
nsNavHistory::SetPageTitle(nsIURI* aURI,
const nsAString& aTitle)
{
PLACES_WARN_DEPRECATED();
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
NS_ENSURE_ARG(aURI);
// if aTitle is empty we want to clear the previous title.
// We don't want to set it to an empty string, but to a NULL value,
// so we use SetIsVoid and SetPageTitleInternal will take care of that
nsresult rv;
if (aTitle.IsEmpty()) {
// Using a void string to bind a NULL in the database.
nsString voidString;
voidString.SetIsVoid(true);
rv = SetPageTitleInternal(aURI, voidString);
}
else {
rv = SetPageTitleInternal(aURI, aTitle);
}
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
NS_IMETHODIMP NS_IMETHODIMP
nsNavHistory::GetPageTitle(nsIURI* aURI, nsAString& aTitle) nsNavHistory::GetPageTitle(nsIURI* aURI, nsAString& aTitle)
{ {
@@ -4836,87 +4575,6 @@ nsNavHistory::GetMonthYear(int32_t aMonth, int32_t aYear, nsACString& aResult)
aResult.AppendLiteral("finduri-MonthYear"); aResult.AppendLiteral("finduri-MonthYear");
} }
// nsNavHistory::SetPageTitleInternal
//
// Called to set the title for the given URI. Used as a
// backend for SetTitle.
//
// Will fail for pages that are not in the DB. To clear the corresponding
// title, use aTitle.SetIsVoid(). Sending an empty string will save an
// empty string instead of clearing it.
nsresult
nsNavHistory::SetPageTitleInternal(nsIURI* aURI, const nsAString& aTitle)
{
nsresult rv;
// Make sure the page exists by fetching its GUID and the old title.
nsAutoString title;
nsAutoCString guid;
{
nsCOMPtr<mozIStorageStatement> stmt = mDB->GetStatement(
"SELECT id, url, title, rev_host, visit_count, guid "
"FROM moz_places "
"WHERE url = :page_url "
);
NS_ENSURE_STATE(stmt);
mozStorageStatementScoper scoper(stmt);
rv = URIBinder::Bind(stmt, NS_LITERAL_CSTRING("page_url"), aURI);
NS_ENSURE_SUCCESS(rv, rv);
bool hasURL = false;
rv = stmt->ExecuteStep(&hasURL);
NS_ENSURE_SUCCESS(rv, rv);
if (!hasURL) {
// If the url is unknown, either the page had an embed visit, or we have
// never seen it. While the former is fine, the latter is an error.
if (hasEmbedVisit(aURI)) {
return NS_OK;
}
return NS_ERROR_NOT_AVAILABLE;
}
rv = stmt->GetString(2, title);
NS_ENSURE_SUCCESS(rv, rv);
rv = stmt->GetUTF8String(5, guid);
NS_ENSURE_SUCCESS(rv, rv);
}
// It is actually common to set the title to be the same thing it used to
// be. For example, going to any web page will always cause a title to be set,
// even though it will often be unchanged since the last visit. In these
// cases, we can avoid DB writing and (most significantly) observer overhead.
if ((aTitle.IsVoid() && title.IsVoid()) || aTitle == title)
return NS_OK;
nsCOMPtr<mozIStorageStatement> stmt = mDB->GetStatement(
"UPDATE moz_places "
"SET title = :page_title "
"WHERE url = :page_url "
);
NS_ENSURE_STATE(stmt);
mozStorageStatementScoper scoper(stmt);
if (aTitle.IsVoid())
rv = stmt->BindNullByName(NS_LITERAL_CSTRING("page_title"));
else {
rv = stmt->BindStringByName(NS_LITERAL_CSTRING("page_title"),
StringHead(aTitle, TITLE_LENGTH_MAX));
}
NS_ENSURE_SUCCESS(rv, rv);
rv = URIBinder::Bind(stmt, NS_LITERAL_CSTRING("page_url"), aURI);
NS_ENSURE_SUCCESS(rv, rv);
rv = stmt->Execute();
NS_ENSURE_SUCCESS(rv, rv);
MOZ_ASSERT(!guid.IsEmpty());
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
nsINavHistoryObserver, OnTitleChanged(aURI, aTitle, guid));
return NS_OK;
}
namespace { namespace {

View File

@@ -78,7 +78,6 @@ public:
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
NS_DECL_NSINAVHISTORYSERVICE NS_DECL_NSINAVHISTORYSERVICE
NS_DECL_NSIGLOBALHISTORY2
NS_DECL_NSIBROWSERHISTORY NS_DECL_NSIBROWSERHISTORY
NS_DECL_NSIOBSERVER NS_DECL_NSIOBSERVER
NS_DECL_NSPIPLACESDATABASE NS_DECL_NSPIPLACESDATABASE
@@ -448,13 +447,6 @@ protected:
nsresult RemovePagesInternal(const nsCString& aPlaceIdsQueryString); nsresult RemovePagesInternal(const nsCString& aPlaceIdsQueryString);
nsresult CleanupPlacesOnVisitsDelete(const nsCString& aPlaceIdsQueryString); nsresult CleanupPlacesOnVisitsDelete(const nsCString& aPlaceIdsQueryString);
nsresult AddURIInternal(nsIURI* aURI, PRTime aTime, bool aRedirect,
bool aToplevel, nsIURI* aReferrer);
nsresult AddVisitChain(nsIURI* aURI, PRTime aTime,
bool aToplevel, bool aRedirect,
nsIURI* aReferrer, int64_t* aVisitID,
int64_t* aSessionID);
nsresult InternalAddNewPage(nsIURI* aURI, const nsAString& aTitle, nsresult InternalAddNewPage(nsIURI* aURI, const nsAString& aTitle,
bool aHidden, bool aTyped, bool aHidden, bool aTyped,
int32_t aVisitCount, bool aCalculateFrecency, int32_t aVisitCount, bool aCalculateFrecency,
@@ -466,7 +458,6 @@ protected:
int64_t* aVisitID, int64_t* aVisitID,
PRTime* aTime, PRTime* aTime,
int64_t* aSessionID); int64_t* aSessionID);
bool IsURIStringVisited(const nsACString& url);
/** /**
* Loads all of the preferences that we use into member variables. * Loads all of the preferences that we use into member variables.
@@ -510,8 +501,6 @@ protected:
void TitleForDomain(const nsCString& domain, nsACString& aTitle); void TitleForDomain(const nsCString& domain, nsACString& aTitle);
nsresult SetPageTitleInternal(nsIURI* aURI, const nsAString& aTitle);
nsresult FilterResultSet(nsNavHistoryQueryResultNode *aParentNode, nsresult FilterResultSet(nsNavHistoryQueryResultNode *aParentNode,
const nsCOMArray<nsNavHistoryResultNode>& aSet, const nsCOMArray<nsNavHistoryResultNode>& aSet,
nsCOMArray<nsNavHistoryResultNode>* aFiltered, nsCOMArray<nsNavHistoryResultNode>* aFiltered,

View File

@@ -10,6 +10,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
"resource://gre/modules/PlacesUtils.jsm"); "resource://gre/modules/PlacesUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "TelemetryStopwatch", XPCOMUtils.defineLazyModuleGetter(this, "TelemetryStopwatch",
"resource://gre/modules/TelemetryStopwatch.jsm"); "resource://gre/modules/TelemetryStopwatch.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "NetUtil",
"resource://gre/modules/NetUtil.jsm");
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//// Constants //// Constants
@@ -304,10 +306,7 @@ function nsPlacesAutoComplete()
// to our own in-memory temp table, and having a cloned copy means we do not // to our own in-memory temp table, and having a cloned copy means we do not
// run the risk of our queries taking longer due to the main database // run the risk of our queries taking longer due to the main database
// connection performing a long-running task. // connection performing a long-running task.
let db = Cc["@mozilla.org/browser/nav-history-service;1"]. let db = PlacesUtils.history.DBConnection.clone(true);
getService(Ci.nsPIPlacesDatabase).
DBConnection.
clone(true);
// Autocomplete often fallbacks to a table scan due to lack of text indices. // Autocomplete often fallbacks to a table scan due to lack of text indices.
// In such cases a larger cache helps reducing IO. The default Storage // In such cases a larger cache helps reducing IO. The default Storage
@@ -339,22 +338,6 @@ function nsPlacesAutoComplete()
return db; return db;
}); });
XPCOMUtils.defineLazyServiceGetter(this, "_bh",
"@mozilla.org/browser/global-history;2",
"nsIBrowserHistory");
XPCOMUtils.defineLazyServiceGetter(this, "_bs",
"@mozilla.org/browser/nav-bookmarks-service;1",
"nsINavBookmarksService");
XPCOMUtils.defineLazyServiceGetter(this, "_ioService",
"@mozilla.org/network/io-service;1",
"nsIIOService");
XPCOMUtils.defineLazyServiceGetter(this, "_faviconService",
"@mozilla.org/browser/favicon-service;1",
"nsIFaviconService");
XPCOMUtils.defineLazyGetter(this, "_defaultQuery", function() { XPCOMUtils.defineLazyGetter(this, "_defaultQuery", function() {
let replacementText = ""; let replacementText = "";
return this._db.createAsyncStatement( return this._db.createAsyncStatement(
@@ -581,7 +564,7 @@ nsPlacesAutoComplete.prototype = {
onValueRemoved: function PAC_onValueRemoved(aResult, aURISpec, aRemoveFromDB) onValueRemoved: function PAC_onValueRemoved(aResult, aURISpec, aRemoveFromDB)
{ {
if (aRemoveFromDB) { if (aRemoveFromDB) {
this._bh.removePage(this._ioService.newURI(aURISpec, null, null)); PlacesUtils.history.removePage(NetUtil.newURI(aURISpec));
} }
}, },
@@ -961,7 +944,7 @@ nsPlacesAutoComplete.prototype = {
// Bind the needed parameters to the query so consumers can use it. // Bind the needed parameters to the query so consumers can use it.
let (params = query.params) { let (params = query.params) {
params.parent = this._bs.tagsFolder; params.parent = PlacesUtils.tagsFolderId;
params.query_type = kQueryTypeFiltered; params.query_type = kQueryTypeFiltered;
params.matchBehavior = aMatchBehavior; params.matchBehavior = aMatchBehavior;
params.searchBehavior = this._behavior; params.searchBehavior = this._behavior;
@@ -1043,7 +1026,7 @@ nsPlacesAutoComplete.prototype = {
let query = this._adaptiveQuery; let query = this._adaptiveQuery;
let (params = query.params) { let (params = query.params) {
params.parent = this._bs.tagsFolder; params.parent = PlacesUtils.tagsFolderId;
params.search_string = this._currentSearchString; params.search_string = this._currentSearchString;
params.query_type = kQueryTypeFiltered; params.query_type = kQueryTypeFiltered;
params.matchBehavior = aMatchBehavior; params.matchBehavior = aMatchBehavior;
@@ -1194,10 +1177,10 @@ nsPlacesAutoComplete.prototype = {
// Obtain the favicon for this URI. // Obtain the favicon for this URI.
let favicon; let favicon;
if (aFaviconSpec) { if (aFaviconSpec) {
let uri = this._ioService.newURI(aFaviconSpec, null, null); let uri = NetUtil.newURI(aFaviconSpec);
favicon = this._faviconService.getFaviconLinkForIcon(uri).spec; favicon = PlacesUtils.favicons.getFaviconLinkForIcon(uri).spec;
} }
favicon = favicon || this._faviconService.defaultFavicon.spec; favicon = favicon || PlacesUtils.favicons.defaultFavicon.spec;
this._result.appendMatch(aURISpec, aTitle, favicon, aStyle); this._result.appendMatch(aURISpec, aTitle, favicon, aStyle);
}, },
@@ -1289,8 +1272,7 @@ urlInlineComplete.prototype = {
get _db() get _db()
{ {
if (!this.__db && this._autofillEnabled) { if (!this.__db && this._autofillEnabled) {
this.__db = PlacesUtils.history.QueryInterface(Ci.nsPIPlacesDatabase). this.__db = PlacesUtils.history.DBConnection.clone(true);
DBConnection.clone(true);
} }
return this.__db; return this.__db;
}, },

View File

@@ -45,7 +45,6 @@ const mozilla::Module::CIDEntry kPlacesCIDs[] = {
const mozilla::Module::ContractIDEntry kPlacesContracts[] = { const mozilla::Module::ContractIDEntry kPlacesContracts[] = {
{ NS_NAVHISTORYSERVICE_CONTRACTID, &kNS_NAVHISTORYSERVICE_CID }, { NS_NAVHISTORYSERVICE_CONTRACTID, &kNS_NAVHISTORYSERVICE_CID },
{ NS_GLOBALHISTORY2_CONTRACTID, &kNS_NAVHISTORYSERVICE_CID },
{ NS_ANNOTATIONSERVICE_CONTRACTID, &kNS_ANNOTATIONSERVICE_CID }, { NS_ANNOTATIONSERVICE_CONTRACTID, &kNS_ANNOTATIONSERVICE_CID },
{ NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "moz-anno", &kNS_ANNOPROTOCOLHANDLER_CID }, { NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "moz-anno", &kNS_ANNOPROTOCOLHANDLER_CID },
{ NS_NAVBOOKMARKSSERVICE_CONTRACTID, &kNS_NAVBOOKMARKSSERVICE_CID }, { NS_NAVBOOKMARKSSERVICE_CONTRACTID, &kNS_NAVBOOKMARKSSERVICE_CID },

View File

@@ -4,36 +4,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Get bookmark service
try {
var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].getService(Ci.nsINavBookmarksService);
} catch(ex) {
do_throw("Could not get nav-bookmarks-service\n");
}
// Get history service
try {
var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].getService(Ci.nsINavHistoryService);
} catch(ex) {
do_throw("Could not get history service\n");
}
// Get annotation service
try {
var annosvc= Cc["@mozilla.org/browser/annotation-service;1"].getService(Ci.nsIAnnotationService);
} catch(ex) {
do_throw("Could not get annotation service\n");
}
// Get global history service
try {
var bhist = Cc["@mozilla.org/browser/global-history;2"].getService(Ci.nsIBrowserHistory);
} catch(ex) {
do_throw("Could not get history service\n");
}
// get bookmarks root id // get bookmarks root id
var root = bmsvc.bookmarksMenuFolder; var root = PlacesUtils.bookmarksMenuFolderId;
// a search term that matches a default bookmark // a search term that matches a default bookmark
const searchTerm = "about"; const searchTerm = "about";
@@ -45,28 +17,31 @@ function run_test() {
// create a folder to hold all the tests // create a folder to hold all the tests
// this makes the tests more tolerant of changes to the default bookmarks set // this makes the tests more tolerant of changes to the default bookmarks set
// also, name it using the search term, for testing that containers that match don't show up in query results // also, name it using the search term, for testing that containers that match don't show up in query results
testRoot = bmsvc.createFolder(root, searchTerm, bmsvc.DEFAULT_INDEX); testRoot = PlacesUtils.bookmarks.createFolder(
root, searchTerm, PlacesUtils.bookmarks.DEFAULT_INDEX);
run_next_test(); run_next_test();
} }
add_test(function test_savedsearches_bookmarks() { add_test(function test_savedsearches_bookmarks() {
// add a bookmark that matches the search term // add a bookmark that matches the search term
var bookmarkId = bmsvc.insertBookmark(root, uri("http://foo.com"), bmsvc.DEFAULT_INDEX, searchTerm); var bookmarkId = PlacesUtils.bookmarks.insertBookmark(
root, uri("http://foo.com"), PlacesUtils.bookmarks.DEFAULT_INDEX,
searchTerm);
// create a saved-search that matches a default bookmark // create a saved-search that matches a default bookmark
var searchId = bmsvc.insertBookmark(testRoot, var searchId = PlacesUtils.bookmarks.insertBookmark(
uri("place:terms=" + searchTerm + "&excludeQueries=1&expandQueries=1&queryType=1"), testRoot, uri("place:terms=" + searchTerm + "&excludeQueries=1&expandQueries=1&queryType=1"),
bmsvc.DEFAULT_INDEX, searchTerm); PlacesUtils.bookmarks.DEFAULT_INDEX, searchTerm);
// query for the test root, expandQueries=0 // query for the test root, expandQueries=0
// the query should show up as a regular bookmark // the query should show up as a regular bookmark
try { try {
var options = histsvc.getNewQueryOptions(); var options = PlacesUtils.history.getNewQueryOptions();
options.expandQueries = 0; options.expandQueries = 0;
var query = histsvc.getNewQuery(); var query = PlacesUtils.history.getNewQuery();
query.setFolders([testRoot], 1); query.setFolders([testRoot], 1);
var result = histsvc.executeQuery(query, options); var result = PlacesUtils.history.executeQuery(query, options);
var rootNode = result.root; var rootNode = result.root;
rootNode.containerOpen = true; rootNode.containerOpen = true;
var cc = rootNode.childCount; var cc = rootNode.childCount;
@@ -89,11 +64,11 @@ add_test(function test_savedsearches_bookmarks() {
// query for the test root, expandQueries=1 // query for the test root, expandQueries=1
// the query should show up as a query container, with 1 child // the query should show up as a query container, with 1 child
try { try {
var options = histsvc.getNewQueryOptions(); var options = PlacesUtils.history.getNewQueryOptions();
options.expandQueries = 1; options.expandQueries = 1;
var query = histsvc.getNewQuery(); var query = PlacesUtils.history.getNewQuery();
query.setFolders([testRoot], 1); query.setFolders([testRoot], 1);
var result = histsvc.executeQuery(query, options); var result = PlacesUtils.history.executeQuery(query, options);
var rootNode = result.root; var rootNode = result.root;
rootNode.containerOpen = true; rootNode.containerOpen = true;
var cc = rootNode.childCount; var cc = rootNode.childCount;
@@ -117,19 +92,23 @@ add_test(function test_savedsearches_bookmarks() {
do_check_eq(item.itemId, bookmarkId); do_check_eq(item.itemId, bookmarkId);
// XXX - FAILING - test live-update of query results - add a bookmark that matches the query // XXX - FAILING - test live-update of query results - add a bookmark that matches the query
//var tmpBmId = bmsvc.insertBookmark(root, uri("http://" + searchTerm + ".com"), bmsvc.DEFAULT_INDEX, searchTerm + "blah"); //var tmpBmId = PlacesUtils.bookmarks.insertBookmark(
// root, uri("http://" + searchTerm + ".com"),
// PlacesUtils.bookmarks.DEFAULT_INDEX, searchTerm + "blah");
//do_check_eq(query.childCount, 2); //do_check_eq(query.childCount, 2);
// XXX - test live-update of query results - delete a bookmark that matches the query // XXX - test live-update of query results - delete a bookmark that matches the query
//bmsvc.removeItem(tmpBMId); //PlacesUtils.bookmarks.removeItem(tmpBMId);
//do_check_eq(query.childCount, 1); //do_check_eq(query.childCount, 1);
// test live-update of query results - add a folder that matches the query // test live-update of query results - add a folder that matches the query
bmsvc.createFolder(root, searchTerm + "zaa", bmsvc.DEFAULT_INDEX); PlacesUtils.bookmarks.createFolder(
root, searchTerm + "zaa", PlacesUtils.bookmarks.DEFAULT_INDEX);
do_check_eq(node.childCount, 1); do_check_eq(node.childCount, 1);
// test live-update of query results - add a query that matches the query // test live-update of query results - add a query that matches the query
bmsvc.insertBookmark(root, uri("place:terms=foo&excludeQueries=1&expandQueries=1&queryType=1"), PlacesUtils.bookmarks.insertBookmark(
bmsvc.DEFAULT_INDEX, searchTerm + "blah"); root, uri("place:terms=foo&excludeQueries=1&expandQueries=1&queryType=1"),
PlacesUtils.bookmarks.DEFAULT_INDEX, searchTerm + "blah");
do_check_eq(node.childCount, 1); do_check_eq(node.childCount, 1);
} }
rootNode.containerOpen = false; rootNode.containerOpen = false;
@@ -139,7 +118,7 @@ add_test(function test_savedsearches_bookmarks() {
} }
// delete the bookmark search // delete the bookmark search
bmsvc.removeItem(searchId); PlacesUtils.bookmarks.removeItem(searchId);
run_next_test(); run_next_test();
}); });
@@ -150,18 +129,18 @@ add_task(function test_savedsearches_history() {
yield promiseAddVisits({ uri: testURI, title: searchTerm }); yield promiseAddVisits({ uri: testURI, title: searchTerm });
// create a saved-search that matches the visit we added // create a saved-search that matches the visit we added
var searchId = bmsvc.insertBookmark(testRoot, var searchId = PlacesUtils.bookmarks.insertBookmark(testRoot,
uri("place:terms=" + searchTerm + "&excludeQueries=1&expandQueries=1&queryType=0"), uri("place:terms=" + searchTerm + "&excludeQueries=1&expandQueries=1&queryType=0"),
bmsvc.DEFAULT_INDEX, searchTerm); PlacesUtils.bookmarks.DEFAULT_INDEX, searchTerm);
// query for the test root, expandQueries=1 // query for the test root, expandQueries=1
// the query should show up as a query container, with 1 child // the query should show up as a query container, with 1 child
try { try {
var options = histsvc.getNewQueryOptions(); var options = PlacesUtils.history.getNewQueryOptions();
options.expandQueries = 1; options.expandQueries = 1;
var query = histsvc.getNewQuery(); var query = PlacesUtils.history.getNewQuery();
query.setFolders([testRoot], 1); query.setFolders([testRoot], 1);
var result = histsvc.executeQuery(query, options); var result = PlacesUtils.history.executeQuery(query, options);
var rootNode = result.root; var rootNode = result.root;
rootNode.containerOpen = true; rootNode.containerOpen = true;
var cc = rootNode.childCount; var cc = rootNode.childCount;
@@ -194,14 +173,16 @@ add_task(function test_savedsearches_history() {
do_check_eq(node.childCount, 2); do_check_eq(node.childCount, 2);
// test live-update of query results - delete a history visit that matches the query // test live-update of query results - delete a history visit that matches the query
bhist.removePage(uri("http://foo.com")); PlacesUtils.history.removePage(uri("http://foo.com"));
do_check_eq(node.childCount, 1); do_check_eq(node.childCount, 1);
node.containerOpen = false; node.containerOpen = false;
} }
// test live-update of moved queries // test live-update of moved queries
var tmpFolderId = bmsvc.createFolder(testRoot, "foo", bmsvc.DEFAULT_INDEX); var tmpFolderId = PlacesUtils.bookmarks.createFolder(
bmsvc.moveItem(searchId, tmpFolderId, bmsvc.DEFAULT_INDEX); testRoot, "foo", PlacesUtils.bookmarks.DEFAULT_INDEX);
PlacesUtils.bookmarks.moveItem(
searchId, tmpFolderId, PlacesUtils.bookmarks.DEFAULT_INDEX);
var tmpFolderNode = rootNode.getChild(0); var tmpFolderNode = rootNode.getChild(0);
do_check_eq(tmpFolderNode.itemId, tmpFolderId); do_check_eq(tmpFolderNode.itemId, tmpFolderId);
tmpFolderNode.QueryInterface(Ci.nsINavHistoryContainerResultNode); tmpFolderNode.QueryInterface(Ci.nsINavHistoryContainerResultNode);
@@ -209,11 +190,11 @@ add_task(function test_savedsearches_history() {
do_check_eq(tmpFolderNode.childCount, 1); do_check_eq(tmpFolderNode.childCount, 1);
// test live-update of renamed queries // test live-update of renamed queries
bmsvc.setItemTitle(searchId, "foo"); PlacesUtils.bookmarks.setItemTitle(searchId, "foo");
do_check_eq(tmpFolderNode.title, "foo"); do_check_eq(tmpFolderNode.title, "foo");
// test live-update of deleted queries // test live-update of deleted queries
bmsvc.removeItem(searchId); PlacesUtils.bookmarks.removeItem(searchId);
try { try {
var tmpFolderNode = root.getChild(1); var tmpFolderNode = root.getChild(1);
do_throw("query was not removed"); do_throw("query was not removed");

View File

@@ -4,30 +4,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Get global history service
try {
var bhist = Cc["@mozilla.org/browser/global-history;2"]
.getService(Ci.nsIBrowserHistory);
} catch(ex) {
do_throw("Could not get history service\n");
}
// Get history service
try {
var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"]
.getService(Ci.nsINavHistoryService);
} catch(ex) {
do_throw("Could not get history service\n");
}
// Get annotation service
try {
var annosvc = Cc["@mozilla.org/browser/annotation-service;1"]
.getService(Ci.nsIAnnotationService);
} catch(ex) {
do_throw("Could not get annotation service\n");
}
/** /**
* Checks to see that a URI is in the database. * Checks to see that a URI is in the database.
* *
@@ -36,12 +12,12 @@ try {
* @returns true if the URI is in the DB, false otherwise. * @returns true if the URI is in the DB, false otherwise.
*/ */
function uri_in_db(aURI) { function uri_in_db(aURI) {
var options = histsvc.getNewQueryOptions(); var options = PlacesUtils.history.getNewQueryOptions();
options.maxResults = 1; options.maxResults = 1;
options.resultType = options.RESULTS_AS_URI options.resultType = options.RESULTS_AS_URI
var query = histsvc.getNewQuery(); var query = PlacesUtils.history.getNewQuery();
query.uri = aURI; query.uri = aURI;
var result = histsvc.executeQuery(query, options); var result = PlacesUtils.history.executeQuery(query, options);
var root = result.root; var root = result.root;
root.containerOpen = true; root.containerOpen = true;
var cc = root.childCount; var cc = root.childCount;
@@ -77,20 +53,22 @@ add_task(function test_execute()
var testAnnoDeletedURI = uri("http://www.test.com/1/"); var testAnnoDeletedURI = uri("http://www.test.com/1/");
var testAnnoDeletedName = "foo"; var testAnnoDeletedName = "foo";
var testAnnoDeletedValue = "bar"; var testAnnoDeletedValue = "bar";
annosvc.setPageAnnotation(testAnnoDeletedURI, testAnnoDeletedName, PlacesUtils.annotations.setPageAnnotation(testAnnoDeletedURI,
testAnnoDeletedName,
testAnnoDeletedValue, 0, testAnnoDeletedValue, 0,
annosvc.EXPIRE_WITH_HISTORY); PlacesUtils.annotations.EXPIRE_WITH_HISTORY);
// set a page annotation on one of the urls that will NOT be removed // set a page annotation on one of the urls that will NOT be removed
var testAnnoRetainedURI = uri("http://www.test-1.com/"); var testAnnoRetainedURI = uri("http://www.test-1.com/");
var testAnnoRetainedName = "foo"; var testAnnoRetainedName = "foo";
var testAnnoRetainedValue = "bar"; var testAnnoRetainedValue = "bar";
annosvc.setPageAnnotation(testAnnoRetainedURI, testAnnoRetainedName, PlacesUtils.annotations.setPageAnnotation(testAnnoRetainedURI,
testAnnoRetainedName,
testAnnoRetainedValue, 0, testAnnoRetainedValue, 0,
annosvc.EXPIRE_WITH_HISTORY); PlacesUtils.annotations.EXPIRE_WITH_HISTORY);
// remove pages from www.test.com // remove pages from www.test.com
bhist.removePagesFromHost("www.test.com", false); PlacesUtils.history.removePagesFromHost("www.test.com", false);
// check that all pages in www.test.com have been removed // check that all pages in www.test.com have been removed
for (var i = 0; i < TOTAL_SITES; i++) { for (var i = 0; i < TOTAL_SITES; i++) {
@@ -108,13 +86,13 @@ add_task(function test_execute()
// check that annotation on the removed item does not exists // check that annotation on the removed item does not exists
try { try {
annosvc.getPageAnnotation(testAnnoDeletedURI, testAnnoName); PlacesUtils.annotations.getPageAnnotation(testAnnoDeletedURI, testAnnoName);
do_throw("fetching page-annotation that doesn't exist, should've thrown"); do_throw("fetching page-annotation that doesn't exist, should've thrown");
} catch(ex) {} } catch(ex) {}
// check that annotation on the NOT removed item still exists // check that annotation on the NOT removed item still exists
try { try {
var annoVal = annosvc.getPageAnnotation(testAnnoRetainedURI, var annoVal = PlacesUtils.annotations.getPageAnnotation(testAnnoRetainedURI,
testAnnoRetainedName); testAnnoRetainedName);
} catch(ex) { } catch(ex) {
do_throw("The annotation has been removed erroneously"); do_throw("The annotation has been removed erroneously");

View File

@@ -3,6 +3,9 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
Components.utils.import("resource://gre/modules/Services.jsm"); Components.utils.import("resource://gre/modules/Services.jsm");
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
"resource://gre/modules/PlacesUtils.jsm");
this.EXPORTED_SYMBOLS = ["ForgetAboutSite"]; this.EXPORTED_SYMBOLS = ["ForgetAboutSite"];
@@ -43,11 +46,7 @@ this.ForgetAboutSite = {
Services.prefs.deleteBranch("geo.wifi.access_token."); Services.prefs.deleteBranch("geo.wifi.access_token.");
} catch (e) {} } catch (e) {}
// History PlacesUtils.history.removePagesFromHost(aDomain, true);
let (bh = Cc["@mozilla.org/browser/global-history;2"].
getService(Ci.nsIBrowserHistory)) {
bh.removePagesFromHost(aDomain, true);
}
// Cache // Cache
let (cs = Cc["@mozilla.org/network/cache-service;1"]. let (cs = Cc["@mozilla.org/network/cache-service;1"].