Bug 838874 - Stop implementing nsIGlobalHistory2.
authorMarco Bonardo <mbonardo@mozilla.com>
Wed, 20 Mar 2013 18:09:41 +0100
changeset 125666 4d5bd5014ce6
parent 125665 bea32c1185e7
child 125667 61555788d72f
push id24461
push useremorley@mozilla.com
push dateThu, 21 Mar 2013 11:51:51 +0000
treeherdermozilla-central@a73a2b5c423b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs838874
milestone22.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 838874 - Stop implementing nsIGlobalHistory2. r=Mano sr=gavin
browser/base/content/sanitize.js
browser/metro/base/content/sanitize.js
toolkit/components/places/PlacesUtils.jsm
toolkit/components/places/nsIBrowserHistory.idl
toolkit/components/places/nsNavHistory.cpp
toolkit/components/places/nsNavHistory.h
toolkit/components/places/nsPlacesAutoComplete.js
toolkit/components/places/nsPlacesModule.cpp
toolkit/components/places/tests/bookmarks/test_savedsearches.js
toolkit/components/places/tests/unit/test_415757.js
toolkit/forgetaboutsite/ForgetAboutSite.jsm
--- a/browser/base/content/sanitize.js
+++ b/browser/base/content/sanitize.js
@@ -1,13 +1,17 @@
 # -*- Mode: Java; 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/.
 
+Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
+                                  "resource://gre/modules/PlacesUtils.jsm");
+
 function Sanitizer() {}
 Sanitizer.prototype = {
   // warning to the caller: this one may raise an exception (e.g. bug #265028)
   clearItem: function (aItemName)
   {
     if (this.items[aItemName].canClear)
       this.items[aItemName].clear();
   },
@@ -176,22 +180,20 @@ Sanitizer.prototype = {
       {
         return true;
       }
     },
 
     history: {
       clear: function ()
       {
-        var globalHistory = Components.classes["@mozilla.org/browser/global-history;2"]
-                                      .getService(Components.interfaces.nsIBrowserHistory);
         if (this.range)
-          globalHistory.removeVisitsByTimeframe(this.range[0], this.range[1]);
+          PlacesUtils.history.removeVisitsByTimeframe(this.range[0], this.range[1]);
         else
-          globalHistory.removeAllPages();
+          PlacesUtils.history.removeAllPages();
         
         try {
           var os = Components.classes["@mozilla.org/observer-service;1"]
                              .getService(Components.interfaces.nsIObserverService);
           os.notifyObservers(null, "browser:purge-session-history", "");
         }
         catch (e) { }
         
--- a/browser/metro/base/content/sanitize.js
+++ b/browser/metro/base/content/sanitize.js
@@ -1,13 +1,17 @@
 // -*- Mode: Java; 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/. */
 
+Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
+                                  "resource://gre/modules/PlacesUtils.jsm");
+
 function Sanitizer() {}
 Sanitizer.prototype = {
   // warning to the caller: this one may raise an exception (e.g. bug #265028)
   clearItem: function (aItemName)
   {
     if (this.items[aItemName].canClear)
       this.items[aItemName].clear();
   },
@@ -160,39 +164,38 @@ Sanitizer.prototype = {
       {
           return true;
       }
     },
 
     history: {
       clear: function ()
       {
-        var globalHistory = Cc["@mozilla.org/browser/global-history;2"].getService(Ci.nsIBrowserHistory);
-        globalHistory.removeAllPages();
-        
+        PlacesUtils.history.removeAllPages();
+
         try {
           Services.obs.notifyObservers(null, "browser:purge-session-history", "");
         }
         catch (e) { }
-        
+
         // Clear last URL of the Open Web Location dialog
         try {
           Services.prefs.clearUserPref("general.open_location.last_url");
         }
         catch (e) { }
       },
-      
+
       get canClear()
       {
         // bug 347231: Always allow clearing history due to dependencies on
         // the browser:purge-session-history notification. (like error console)
         return true;
       }
     },
-    
+
     formdata: {
       clear: function ()
       {
         //Clear undo history of all searchBars
         var windows = Services.wm.getEnumerator("navigator:browser");
         while (windows.hasMoreElements()) {
           var searchBar = windows.getNext().document.getElementById("searchbar");
           if (searchBar) {
--- a/toolkit/components/places/PlacesUtils.jsm
+++ b/toolkit/components/places/PlacesUtils.jsm
@@ -1990,17 +1990,17 @@ this.PlacesUtils = {
    * @return A object with a .cancel() method allowing to cancel the request.
    *
    * @note Children of live bookmarks folders are excluded. The callback function is
    *       not invoked if the request is cancelled or hits an error.
    */
   asyncGetBookmarkIds: function PU_asyncGetBookmarkIds(aURI, aCallback, aScope)
   {
     if (!this._asyncGetBookmarksStmt) {
-      let db = this.history.QueryInterface(Ci.nsPIPlacesDatabase).DBConnection;
+      let db = this.history.DBConnection;
       this._asyncGetBookmarksStmt = db.createAsyncStatement(
         "SELECT b.id "
       + "FROM moz_bookmarks b "
       + "JOIN moz_places h on h.id = b.fk "
       + "WHERE h.url = :url "
       );
       this.registerShutdownFunction(function () {
         this._asyncGetBookmarksStmt.finalize();
@@ -2109,30 +2109,29 @@ AsyncStatementCancelWrapper.prototype = 
   executeAsync: function(aCallback) {
     this._pendingStmt = this._stmt.executeAsync(this);
     this._callback = aCallback;
     let self = this;
     return { cancel: function () { self._cancel(); } }
   }
 }
 
-XPCOMUtils.defineLazyServiceGetter(PlacesUtils, "history",
-                                   "@mozilla.org/browser/nav-history-service;1",
-                                   "nsINavHistoryService");
+XPCOMUtils.defineLazyGetter(PlacesUtils, "history", function() {
+  return Cc["@mozilla.org/browser/nav-history-service;1"]
+           .getService(Ci.nsINavHistoryService)
+           .QueryInterface(Ci.nsIBrowserHistory)
+           .QueryInterface(Ci.nsPIPlacesDatabase);
+});
 
 XPCOMUtils.defineLazyServiceGetter(PlacesUtils, "asyncHistory",
                                    "@mozilla.org/browser/history;1",
                                    "mozIAsyncHistory");
 
 XPCOMUtils.defineLazyGetter(PlacesUtils, "bhistory", function() {
-  return PlacesUtils.history.QueryInterface(Ci.nsIBrowserHistory);
-});
-
-XPCOMUtils.defineLazyGetter(PlacesUtils, "ghistory2", function() {
-  return PlacesUtils.history.QueryInterface(Ci.nsIGlobalHistory2);
+  return PlacesUtils.history;
 });
 
 XPCOMUtils.defineLazyServiceGetter(PlacesUtils, "favicons",
                                    "@mozilla.org/browser/favicon-service;1",
                                    "mozIAsyncFavicons");
 
 XPCOMUtils.defineLazyServiceGetter(PlacesUtils, "bookmarks",
                                    "@mozilla.org/browser/nav-bookmarks-service;1",
--- a/toolkit/components/places/nsIBrowserHistory.idl
+++ b/toolkit/components/places/nsIBrowserHistory.idl
@@ -5,18 +5,18 @@
 
 /*
  * browser-specific interface to global history
  */
 
 #include "nsISupports.idl"
 #include "nsIGlobalHistory2.idl"
 
-[scriptable, uuid(837ea2db-c4c7-4f4c-8982-6c8c73e8f5d3)]
-interface nsIBrowserHistory : nsIGlobalHistory2
+[scriptable, uuid(20d31479-38de-49f4-9300-566d6e834c66)]
+interface nsIBrowserHistory : nsISupports
 {
     /**
      * Removes a page from global history.
      *
      * @note It is preferrable to use this one rather then RemovePages when
      *       removing less than 10 pages, since it won't start a full batch
      *       operation.
      */
--- a/toolkit/components/places/nsNavHistory.cpp
+++ b/toolkit/components/places/nsNavHistory.cpp
@@ -161,32 +161,30 @@ static const char* kObservedPrefs[] = {
 
 NS_IMPL_THREADSAFE_ADDREF(nsNavHistory)
 NS_IMPL_THREADSAFE_RELEASE(nsNavHistory)
 
 NS_IMPL_CLASSINFO(nsNavHistory, NULL, nsIClassInfo::SINGLETON,
                   NS_NAVHISTORYSERVICE_CID)
 NS_INTERFACE_MAP_BEGIN(nsNavHistory)
   NS_INTERFACE_MAP_ENTRY(nsINavHistoryService)
-  NS_INTERFACE_MAP_ENTRY(nsIGlobalHistory2)
   NS_INTERFACE_MAP_ENTRY(nsIBrowserHistory)
   NS_INTERFACE_MAP_ENTRY(nsIObserver)
   NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
   NS_INTERFACE_MAP_ENTRY(nsPIPlacesDatabase)
   NS_INTERFACE_MAP_ENTRY(nsPIPlacesHistoryListenersNotifier)
   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_GETTER3(
+NS_IMPL_CI_INTERFACE_GETTER2(
   nsNavHistory
 , nsINavHistoryService
-, nsIGlobalHistory2
 , nsIBrowserHistory
 )
 
 namespace {
 
 static int64_t GetSimpleBookmarksQueryFolder(
     const nsCOMArray<nsNavHistoryQuery>& aQueries,
     nsNavHistoryQueryOptions* aOptions);
@@ -615,43 +613,16 @@ nsNavHistory::FindLastVisit(nsIURI* aURI
     rv = stmt->GetInt64(2, reinterpret_cast<int64_t*>(aTime));
     NS_ENSURE_SUCCESS(rv, false);
     return true;
   }
   return false;
 }
 
 
-// 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
 nsNavHistory::LoadPrefs()
 {
   // History preferences.
   // Check the old preference and migrate disabled state.
   int32_t oldDaysPref = Preferences::GetInt("browser.history_expire_days", -1);
   if (oldDaysPref >= 0) {
     if (oldDaysPref == 0) {
@@ -1182,18 +1153,16 @@ nsNavHistory::invalidateFrecencies(const
   NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
 }
 
 
 // Call this method before visiting a URL in order to help determine the
 // transition type of the visit.
-// Later, in AddVisitChain() the next visit to this page will be associated to
-// TRANSITION_BOOKMARK.
 //
 // @see MarkPageAsTyped
 
 NS_IMETHODIMP
 nsNavHistory::MarkPageAsFollowedBookmark(nsIURI* aURI)
 {
   NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
   NS_ENSURE_ARG(aURI);
@@ -3108,18 +3077,16 @@ nsNavHistory::RemoveAllPages()
   NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "failed to fix invalid frecencies");
 
   return NS_OK;
 }
 
 
 // Call this method before visiting a URL in order to help determine the
 // transition type of the visit.
-// Later, in AddVisitChain() the next visit to this page will be associated to
-// TRANSITION_TYPED.
 //
 // @see MarkPageAsFollowedBookmark
 
 NS_IMETHODIMP
 nsNavHistory::MarkPageAsTyped(nsIURI *aURI)
 {
   NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
   NS_ENSURE_ARG(aURI);
@@ -3142,18 +3109,16 @@ nsNavHistory::MarkPageAsTyped(nsIURI *aU
 
   mRecentTyped.Put(uriString, GetNow());
   return NS_OK;
 }
 
 
 // Call this method before visiting a URL in order to help determine the
 // 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
 
 NS_IMETHODIMP
 nsNavHistory::MarkPageAsFollowedLink(nsIURI *aURI)
 {
   NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
   NS_ENSURE_ARG(aURI);
@@ -3235,242 +3200,16 @@ nsNavHistory::GetCharsetForURI(nsIURI* a
   if (NS_FAILED(rv)) {
     // be sure to return an empty string if character-set is not found
     aCharset.Truncate();
   }
   return NS_OK;
 }
 
 
-// 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
 nsNavHistory::GetPageTitle(nsIURI* aURI, nsAString& aTitle)
 {
   NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
   NS_ENSURE_ARG(aURI);
 
   aTitle.Truncate(0);
 
@@ -4831,97 +4570,16 @@ nsNavHistory::GetMonthYear(int32_t aMont
         ))) {
       CopyUTF16toUTF8(value, aResult);
       return;
     }
   }
   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 {
 
 // GetSimpleBookmarksQueryFolder
 //
 //    Determines if this set of queries is a simple bookmarks query for a
 //    folder with no other constraints. In these common cases, we can more
 //    efficiently compute the results.
--- a/toolkit/components/places/nsNavHistory.h
+++ b/toolkit/components/places/nsNavHistory.h
@@ -73,17 +73,16 @@ class nsNavHistory MOZ_FINAL : public ns
 {
   friend class PlacesSQLQueryBuilder;
 
 public:
   nsNavHistory();
 
   NS_DECL_ISUPPORTS
   NS_DECL_NSINAVHISTORYSERVICE
-  NS_DECL_NSIGLOBALHISTORY2
   NS_DECL_NSIBROWSERHISTORY
   NS_DECL_NSIOBSERVER
   NS_DECL_NSPIPLACESDATABASE
   NS_DECL_NSPIPLACESHISTORYLISTENERSNOTIFIER
   NS_DECL_MOZISTORAGEVACUUMPARTICIPANT
 
   /**
    * Obtains the nsNavHistory object.
@@ -443,35 +442,27 @@ protected:
   nsresult DecayFrecency();
 
   nsresult CalculateFrecency(int64_t aPageID, int32_t aTyped, int32_t aVisitCount, nsAutoCString &aURL, int32_t *aFrecency);
   nsresult CalculateFrecencyInternal(int64_t aPageID, int32_t aTyped, int32_t aVisitCount, bool aIsBookmarked, int32_t *aFrecency);
 
   nsresult RemovePagesInternal(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,
                               bool aHidden, bool aTyped,
                               int32_t aVisitCount, bool aCalculateFrecency,
                               int64_t* aPageID, nsACString& guid);
   nsresult InternalAddVisit(int64_t aPageID, int64_t aReferringVisit,
                             int64_t aSessionID, PRTime aTime,
                             int32_t aTransitionType, int64_t* aVisitID);
   bool FindLastVisit(nsIURI* aURI,
                        int64_t* aVisitID,
                        PRTime* aTime,
                        int64_t* aSessionID);
-  bool IsURIStringVisited(const nsACString& url);
 
   /**
    * Loads all of the preferences that we use into member variables.
    *
    * @note If mPrefBranch is NULL, this does nothing.
    */
   void LoadPrefs();
 
@@ -505,18 +496,16 @@ protected:
                                      nsNavHistoryQueryOptions* aOptions);
 
   nsresult ResultsAsList(mozIStorageStatement* statement,
                          nsNavHistoryQueryOptions* aOptions,
                          nsCOMArray<nsNavHistoryResultNode>* aResults);
 
   void TitleForDomain(const nsCString& domain, nsACString& aTitle);
 
-  nsresult SetPageTitleInternal(nsIURI* aURI, const nsAString& aTitle);
-
   nsresult FilterResultSet(nsNavHistoryQueryResultNode *aParentNode,
                            const nsCOMArray<nsNavHistoryResultNode>& aSet,
                            nsCOMArray<nsNavHistoryResultNode>* aFiltered,
                            const nsCOMArray<nsNavHistoryQuery>& aQueries,
                            nsNavHistoryQueryOptions* aOptions);
 
   // observers
   nsMaybeWeakPtrArray<nsINavHistoryObserver> mObservers;
--- a/toolkit/components/places/nsPlacesAutoComplete.js
+++ b/toolkit/components/places/nsPlacesAutoComplete.js
@@ -5,16 +5,18 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 Components.utils.import("resource://gre/modules/Services.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
                                   "resource://gre/modules/PlacesUtils.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "TelemetryStopwatch",
                                   "resource://gre/modules/TelemetryStopwatch.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "NetUtil",
+                                  "resource://gre/modules/NetUtil.jsm");
 
 ////////////////////////////////////////////////////////////////////////////////
 //// Constants
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cr = Components.results;
 
@@ -299,20 +301,17 @@ function nsPlacesAutoComplete()
   //////////////////////////////////////////////////////////////////////////////
   //// Smart Getters
 
   XPCOMUtils.defineLazyGetter(this, "_db", function() {
     // Get a cloned, read-only version of the database.  We'll only ever write
     // 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
     // connection performing a long-running task.
-    let db = Cc["@mozilla.org/browser/nav-history-service;1"].
-             getService(Ci.nsPIPlacesDatabase).
-             DBConnection.
-             clone(true);
+    let db = PlacesUtils.history.DBConnection.clone(true);
 
     // 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
     // value is MAX_CACHE_SIZE_BYTES in storage/src/mozStorageConnection.cpp.
     let stmt = db.createAsyncStatement("PRAGMA cache_size = -6144"); // 6MiB
     stmt.executeAsync();
     stmt.finalize();
 
@@ -334,32 +333,16 @@ function nsPlacesAutoComplete()
       stmt.executeAsync();
       stmt.finalize();
       delete this._openPagesCache;
     }
 
     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() {
     let replacementText = "";
     return this._db.createAsyncStatement(
       SQL_BASE.replace("{ADDITIONAL_CONDITIONS}", replacementText, "g")
     );
   });
 
   XPCOMUtils.defineLazyGetter(this, "_historyQuery", function() {
@@ -576,17 +559,17 @@ nsPlacesAutoComplete.prototype = {
   },
 
   //////////////////////////////////////////////////////////////////////////////
   //// nsIAutoCompleteSimpleResultListener
 
   onValueRemoved: function PAC_onValueRemoved(aResult, aURISpec, aRemoveFromDB)
   {
     if (aRemoveFromDB) {
-      this._bh.removePage(this._ioService.newURI(aURISpec, null, null));
+      PlacesUtils.history.removePage(NetUtil.newURI(aURISpec));
     }
   },
 
   //////////////////////////////////////////////////////////////////////////////
   //// mozIPlacesAutoComplete
 
   // If the connection has not yet been started, use this local cache.  This
   // prevents autocomplete from initing the database till the first search.
@@ -956,17 +939,17 @@ nsPlacesAutoComplete.prototype = {
     let query = this._hasBehavior("tag") ? this._tagsQuery :
                 this._hasBehavior("bookmark") ? this._bookmarkQuery :
                 this._hasBehavior("typed") ? this._typedQuery :
                 this._hasBehavior("history") ? this._historyQuery :
                 this._defaultQuery;
 
     // Bind the needed parameters to the query so consumers can use it.
     let (params = query.params) {
-      params.parent = this._bs.tagsFolder;
+      params.parent = PlacesUtils.tagsFolderId;
       params.query_type = kQueryTypeFiltered;
       params.matchBehavior = aMatchBehavior;
       params.searchBehavior = this._behavior;
 
       // We only want to search the tokens that we are left with - not the
       // original search string.
       params.searchString = aTokens.join(" ");
 
@@ -1038,17 +1021,17 @@ nsPlacesAutoComplete.prototype = {
   {
     // If we were not given a match behavior, use the stored match behavior.
     if (arguments.length == 0) {
       aMatchBehavior = this._matchBehavior;
     }
 
     let query = this._adaptiveQuery;
     let (params = query.params) {
-      params.parent = this._bs.tagsFolder;
+      params.parent = PlacesUtils.tagsFolderId;
       params.search_string = this._currentSearchString;
       params.query_type = kQueryTypeFiltered;
       params.matchBehavior = aMatchBehavior;
       params.searchBehavior = this._behavior;
     }
 
     return query;
   },
@@ -1189,20 +1172,20 @@ nsPlacesAutoComplete.prototype = {
     // We cannot use only the url since keywords entries are modified to
     // include the search string, and would be returned multiple times.  Ids
     // are faster too.
     this._usedPlaces[aPlaceId || aURISpec] = true;
 
     // Obtain the favicon for this URI.
     let favicon;
     if (aFaviconSpec) {
-      let uri = this._ioService.newURI(aFaviconSpec, null, null);
-      favicon = this._faviconService.getFaviconLinkForIcon(uri).spec;
+      let uri = NetUtil.newURI(aFaviconSpec);
+      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);
   },
 
   /**
    * Determines if the specified AutoComplete behavior is set.
    *
    * @param aType
@@ -1284,18 +1267,17 @@ urlInlineComplete.prototype = {
 /////////////////////////////////////////////////////////////////////////////////
 //// Database and query getters
 
   __db: null,
 
   get _db()
   {
     if (!this.__db && this._autofillEnabled) {
-      this.__db = PlacesUtils.history.QueryInterface(Ci.nsPIPlacesDatabase).
-                  DBConnection.clone(true);
+      this.__db = PlacesUtils.history.DBConnection.clone(true);
     }
     return this.__db;
   },
 
   __syncQuery: null,
 
   get _syncQuery()
   {
--- a/toolkit/components/places/nsPlacesModule.cpp
+++ b/toolkit/components/places/nsPlacesModule.cpp
@@ -40,17 +40,16 @@ const mozilla::Module::CIDEntry kPlacesC
   { &kNS_NAVBOOKMARKSSERVICE_CID, false, NULL, nsNavBookmarksConstructor },
   { &kNS_FAVICONSERVICE_CID, false, NULL, nsFaviconServiceConstructor },
   { &kNS_HISTORYSERVICE_CID, false, NULL, HistoryConstructor },
   { NULL }
 };
 
 const mozilla::Module::ContractIDEntry kPlacesContracts[] = {
   { NS_NAVHISTORYSERVICE_CONTRACTID, &kNS_NAVHISTORYSERVICE_CID },
-  { NS_GLOBALHISTORY2_CONTRACTID, &kNS_NAVHISTORYSERVICE_CID },
   { NS_ANNOTATIONSERVICE_CONTRACTID, &kNS_ANNOTATIONSERVICE_CID },
   { NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "moz-anno", &kNS_ANNOPROTOCOLHANDLER_CID },
   { NS_NAVBOOKMARKSSERVICE_CONTRACTID, &kNS_NAVBOOKMARKSSERVICE_CID },
   { NS_FAVICONSERVICE_CONTRACTID, &kNS_FAVICONSERVICE_CID },
   { "@mozilla.org/embeddor.implemented/bookmark-charset-resolver;1", &kNS_NAVHISTORYSERVICE_CID },
   { NS_IHISTORY_CONTRACTID, &kNS_HISTORYSERVICE_CID },
   { NS_DOWNLOADHISTORY_CONTRACTID, &kNS_HISTORYSERVICE_CID },
   { NULL }
--- a/toolkit/components/places/tests/bookmarks/test_savedsearches.js
+++ b/toolkit/components/places/tests/bookmarks/test_savedsearches.js
@@ -1,77 +1,52 @@
 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:set ts=2 sw=2 sts=2 et: */
 /* 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/. */
 
-// 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
-var root = bmsvc.bookmarksMenuFolder;
+var root = PlacesUtils.bookmarksMenuFolderId;
 
 // a search term that matches a default bookmark
 const searchTerm = "about";
 
 var testRoot;
 
 // main
 function run_test() {
   // create a folder to hold all the tests
   // 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
-  testRoot = bmsvc.createFolder(root, searchTerm, bmsvc.DEFAULT_INDEX);
+  testRoot = PlacesUtils.bookmarks.createFolder(
+    root, searchTerm, PlacesUtils.bookmarks.DEFAULT_INDEX);
 
   run_next_test();
 }
 
 add_test(function test_savedsearches_bookmarks() {
   // 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
-  var searchId = bmsvc.insertBookmark(testRoot,
-                                      uri("place:terms=" + searchTerm + "&excludeQueries=1&expandQueries=1&queryType=1"),
-                                      bmsvc.DEFAULT_INDEX, searchTerm);
+  var searchId = PlacesUtils.bookmarks.insertBookmark(
+    testRoot, uri("place:terms=" + searchTerm + "&excludeQueries=1&expandQueries=1&queryType=1"),
+    PlacesUtils.bookmarks.DEFAULT_INDEX, searchTerm);
 
   // query for the test root, expandQueries=0
   // the query should show up as a regular bookmark
   try {
-    var options = histsvc.getNewQueryOptions();
+    var options = PlacesUtils.history.getNewQueryOptions();
     options.expandQueries = 0;
-    var query = histsvc.getNewQuery();
+    var query = PlacesUtils.history.getNewQuery();
     query.setFolders([testRoot], 1);
-    var result = histsvc.executeQuery(query, options);
+    var result = PlacesUtils.history.executeQuery(query, options);
     var rootNode = result.root;
     rootNode.containerOpen = true;
     var cc = rootNode.childCount;
     do_check_eq(cc, 1);
     for (var i = 0; i < cc; i++) {
       var node = rootNode.getChild(i);
       // test that queries have valid itemId
       do_check_true(node.itemId > 0);
@@ -84,21 +59,21 @@ add_test(function test_savedsearches_boo
   catch(ex) {
     do_throw("expandQueries=0 query error: " + ex);
   }
 
   // bookmark saved search
   // query for the test root, expandQueries=1
   // the query should show up as a query container, with 1 child
   try {
-    var options = histsvc.getNewQueryOptions();
+    var options = PlacesUtils.history.getNewQueryOptions();
     options.expandQueries = 1;
-    var query = histsvc.getNewQuery();
+    var query = PlacesUtils.history.getNewQuery();
     query.setFolders([testRoot], 1);
-    var result = histsvc.executeQuery(query, options);
+    var result = PlacesUtils.history.executeQuery(query, options);
     var rootNode = result.root;
     rootNode.containerOpen = true;
     var cc = rootNode.childCount;
     do_check_eq(cc, 1);
     for (var i = 0; i < cc; i++) {
       var node = rootNode.getChild(i);
       // test that query node type is container when expandQueries=1
       do_check_eq(node.type, node.RESULT_TYPE_QUERY);
@@ -112,61 +87,65 @@ add_test(function test_savedsearches_boo
       // test that queries don't show themselves in query results (shouldn't have our saved search)
       do_check_eq(node.childCount, 1);
 
       // test that bookmark shows in query results
       var item = node.getChild(0);
       do_check_eq(item.itemId, bookmarkId);
 
       // 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);
 
       // 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);
 
       // 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);
       // 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"),
-                           bmsvc.DEFAULT_INDEX, searchTerm + "blah");
+      PlacesUtils.bookmarks.insertBookmark(
+        root, uri("place:terms=foo&excludeQueries=1&expandQueries=1&queryType=1"),
+        PlacesUtils.bookmarks.DEFAULT_INDEX, searchTerm + "blah");
       do_check_eq(node.childCount, 1);
     }
     rootNode.containerOpen = false;
   }
   catch(ex) {
     do_throw("expandQueries=1 bookmarks query: " + ex);
   }
 
   // delete the bookmark search
-  bmsvc.removeItem(searchId);
+  PlacesUtils.bookmarks.removeItem(searchId);
 
   run_next_test();
 });
 
 add_task(function test_savedsearches_history() {
   // add a visit that matches the search term
   var testURI = uri("http://" + searchTerm + ".com");
   yield promiseAddVisits({ uri: testURI, title: searchTerm });
 
   // create a saved-search that matches the visit we added
-  var searchId = bmsvc.insertBookmark(testRoot,
-                                      uri("place:terms=" + searchTerm + "&excludeQueries=1&expandQueries=1&queryType=0"),
-                                      bmsvc.DEFAULT_INDEX, searchTerm);
+  var searchId = PlacesUtils.bookmarks.insertBookmark(testRoot,
+    uri("place:terms=" + searchTerm + "&excludeQueries=1&expandQueries=1&queryType=0"),
+    PlacesUtils.bookmarks.DEFAULT_INDEX, searchTerm);
 
   // query for the test root, expandQueries=1
   // the query should show up as a query container, with 1 child
   try {
-    var options = histsvc.getNewQueryOptions();
+    var options = PlacesUtils.history.getNewQueryOptions();
     options.expandQueries = 1;
-    var query = histsvc.getNewQuery();
+    var query = PlacesUtils.history.getNewQuery();
     query.setFolders([testRoot], 1);
-    var result = histsvc.executeQuery(query, options);
+    var result = PlacesUtils.history.executeQuery(query, options);
     var rootNode = result.root;
     rootNode.containerOpen = true;
     var cc = rootNode.childCount;
     do_check_eq(cc, 1);
     for (var i = 0; i < cc; i++) {
       var node = rootNode.getChild(i);
       // test that query node type is container when expandQueries=1
       do_check_eq(node.type, node.RESULT_TYPE_QUERY);
@@ -189,36 +168,38 @@ add_task(function test_savedsearches_his
       // test live-update of query results - add a history visit that matches the query
       yield promiseAddVisits({
         uri: uri("http://foo.com"),
         title: searchTerm + "blah"
       });
       do_check_eq(node.childCount, 2);
 
       // 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);
       node.containerOpen = false;
     }
 
     // test live-update of moved queries
-    var tmpFolderId = bmsvc.createFolder(testRoot, "foo", bmsvc.DEFAULT_INDEX);
-    bmsvc.moveItem(searchId, tmpFolderId, bmsvc.DEFAULT_INDEX);
+    var tmpFolderId = PlacesUtils.bookmarks.createFolder(
+      testRoot, "foo", PlacesUtils.bookmarks.DEFAULT_INDEX);
+    PlacesUtils.bookmarks.moveItem(
+      searchId, tmpFolderId, PlacesUtils.bookmarks.DEFAULT_INDEX);
     var tmpFolderNode = rootNode.getChild(0);
     do_check_eq(tmpFolderNode.itemId, tmpFolderId);
     tmpFolderNode.QueryInterface(Ci.nsINavHistoryContainerResultNode);
     tmpFolderNode.containerOpen = true;
     do_check_eq(tmpFolderNode.childCount, 1);
 
     // test live-update of renamed queries
-    bmsvc.setItemTitle(searchId, "foo");
+    PlacesUtils.bookmarks.setItemTitle(searchId, "foo");
     do_check_eq(tmpFolderNode.title, "foo");
 
     // test live-update of deleted queries
-    bmsvc.removeItem(searchId);
+    PlacesUtils.bookmarks.removeItem(searchId);
     try {
       var tmpFolderNode = root.getChild(1);
       do_throw("query was not removed");
     } catch(ex) {}
 
     tmpFolderNode.containerOpen = false;
     rootNode.containerOpen = false;
   }
--- a/toolkit/components/places/tests/unit/test_415757.js
+++ b/toolkit/components/places/tests/unit/test_415757.js
@@ -1,52 +1,28 @@
 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:set ts=2 sw=2 sts=2 et: */
 /* 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/. */
 
-// 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.
  *
  * @param aURI
  *        The URI to check.
  * @returns true if the URI is in the DB, false otherwise.
  */
 function uri_in_db(aURI) {
-  var options = histsvc.getNewQueryOptions();
+  var options = PlacesUtils.history.getNewQueryOptions();
   options.maxResults = 1;
   options.resultType = options.RESULTS_AS_URI
-  var query = histsvc.getNewQuery();
+  var query = PlacesUtils.history.getNewQuery();
   query.uri = aURI;
-  var result = histsvc.executeQuery(query, options);
+  var result = PlacesUtils.history.executeQuery(query, options);
   var root = result.root;
   root.containerOpen = true;
   var cc = root.childCount;
   root.containerOpen = false;
   return (cc == 1);
 }
 
 const TOTAL_SITES = 20;
@@ -72,30 +48,32 @@ add_task(function test_execute()
     let when = Date.now() * 1000 + (i * TOTAL_SITES);
     yield promiseAddVisits({ uri: testURI, visitDate: when });
   }
 
   // set a page annotation on one of the urls that will be removed
   var testAnnoDeletedURI = uri("http://www.test.com/1/");
   var testAnnoDeletedName = "foo";
   var testAnnoDeletedValue = "bar";
-  annosvc.setPageAnnotation(testAnnoDeletedURI, testAnnoDeletedName,
-                            testAnnoDeletedValue, 0,
-                            annosvc.EXPIRE_WITH_HISTORY);
+  PlacesUtils.annotations.setPageAnnotation(testAnnoDeletedURI,
+                                            testAnnoDeletedName,
+                                            testAnnoDeletedValue, 0,
+                                            PlacesUtils.annotations.EXPIRE_WITH_HISTORY);
 
   // set a page annotation on one of the urls that will NOT be removed
   var testAnnoRetainedURI = uri("http://www.test-1.com/");
   var testAnnoRetainedName = "foo";
   var testAnnoRetainedValue = "bar";
-  annosvc.setPageAnnotation(testAnnoRetainedURI, testAnnoRetainedName,
-                            testAnnoRetainedValue, 0,
-                            annosvc.EXPIRE_WITH_HISTORY);
+  PlacesUtils.annotations.setPageAnnotation(testAnnoRetainedURI,
+                                            testAnnoRetainedName,
+                                            testAnnoRetainedValue, 0,
+                                            PlacesUtils.annotations.EXPIRE_WITH_HISTORY);
 
   // 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
   for (var i = 0; i < TOTAL_SITES; i++) {
     let site = "http://www.test.com/" + i + "/";
     let testURI = uri(site);
     do_check_false(uri_in_db(testURI));
   }
 
@@ -103,22 +81,22 @@ add_task(function test_execute()
   for (var i = 0; i < TOTAL_SITES; i++) {
     let site = "http://www.test-" + i + ".com/";
     let testURI = uri(site);
     do_check_true(uri_in_db(testURI));
   }
 
   // check that annotation on the removed item does not exists
   try {
-    annosvc.getPageAnnotation(testAnnoDeletedURI, testAnnoName);
+    PlacesUtils.annotations.getPageAnnotation(testAnnoDeletedURI, testAnnoName);
     do_throw("fetching page-annotation that doesn't exist, should've thrown");
   } catch(ex) {}
 
   // check that annotation on the NOT removed item still exists
   try {
-    var annoVal = annosvc.getPageAnnotation(testAnnoRetainedURI,
-                                            testAnnoRetainedName);
+    var annoVal = PlacesUtils.annotations.getPageAnnotation(testAnnoRetainedURI,
+                                                            testAnnoRetainedName);
   } catch(ex) {
     do_throw("The annotation has been removed erroneously");
   }
   do_check_eq(annoVal, testAnnoRetainedValue);
 
 });
--- a/toolkit/forgetaboutsite/ForgetAboutSite.jsm
+++ b/toolkit/forgetaboutsite/ForgetAboutSite.jsm
@@ -1,13 +1,16 @@
 /* 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/. */
 
 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"];
 
 /**
  * Returns true if the string passed in is part of the root domain of the
  * current string.  For example, if this is "www.mozilla.org", and we pass in
  * "mozilla.org", this will return true.  It would return false the other way
  * around.
@@ -38,21 +41,17 @@ const Cu = Components.utils;
 this.ForgetAboutSite = {
   removeDataFromDomain: function CRH_removeDataFromDomain(aDomain)
   {
     // clear any and all network geolocation provider sessions
     try {
         Services.prefs.deleteBranch("geo.wifi.access_token.");
     } catch (e) {}
 
-    // History
-    let (bh = Cc["@mozilla.org/browser/global-history;2"].
-              getService(Ci.nsIBrowserHistory)) {
-      bh.removePagesFromHost(aDomain, true);
-    }
+    PlacesUtils.history.removePagesFromHost(aDomain, true);
 
     // Cache
     let (cs = Cc["@mozilla.org/network/cache-service;1"].
               getService(Ci.nsICacheService)) {
       // NOTE: there is no way to clear just that domain, so we clear out
       //       everything)
       try {
         cs.evictEntries(Ci.nsICache.STORE_ANYWHERE);