Bug 1292093 Import PlacesUtils.jsm in ext-history r=kmag
authorAndrew Swan <aswan@mozilla.com>
Thu, 04 Aug 2016 11:26:55 -0700
changeset 308167 d6ee6a38aa43bae545a100d60296508878fde95c
parent 308166 5f657b0bdfed17d392887b5dc566a75c2dd05e2f
child 308168 384ff6b4b109bba115a73e1024d9e6d18226a424
push id31073
push useraswan@mozilla.com
push dateThu, 04 Aug 2016 18:59:48 +0000
treeherderautoland@d6ee6a38aa43 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs1292093
milestone51.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 1292093 Import PlacesUtils.jsm in ext-history r=kmag MozReview-Commit-ID: ICxJbWfVYdb
browser/components/extensions/ext-history.js
--- a/browser/components/extensions/ext-history.js
+++ b/browser/components/extensions/ext-history.js
@@ -1,25 +1,22 @@
 /* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set sts=2 sw=2 et tw=80: */
 "use strict";
 
 const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
 
 Cu.import("resource://gre/modules/ExtensionUtils.jsm");
 
-XPCOMUtils.defineLazyGetter(this, "History", () => {
-  Cu.import("resource://gre/modules/PlacesUtils.jsm");
-  return PlacesUtils.history;
-});
-
 XPCOMUtils.defineLazyModuleGetter(this, "EventEmitter",
                                   "resource://devtools/shared/event-emitter.js");
 XPCOMUtils.defineLazyModuleGetter(this, "NetUtil",
                                   "resource://gre/modules/NetUtil.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
+                                  "resource://gre/modules/PlacesUtils.jsm");
 
 const {
   normalizeTime,
   SingletonEventManager,
 } = ExtensionUtils;
 
 let nsINavHistoryService = Ci.nsINavHistoryService;
 const TRANSITION_TO_TRANSITION_TYPES_MAP = new Map([
@@ -123,17 +120,17 @@ function getObserver() {
       onPageChanged: function() {},
       onFrecencyChanged: function() {},
       onManyFrecenciesChanged: function() {},
       onDeleteVisits: function(uri, time, guid, reason) {
         this.emit("visitRemoved", {allHistory: false, urls: [uri.spec]});
       },
     };
     EventEmitter.decorate(_observer);
-    History.addObserver(_observer, false);
+    PlacesUtils.history.addObserver(_observer, false);
   }
   return _observer;
 }
 
 extensions.registerSchemaAPI("history", (extension, context) => {
   return {
     history: {
       addUrl: function(details) {
@@ -152,78 +149,78 @@ extensions.registerSchemaAPI("history", 
           visits: [
             {
               transition,
               date,
             },
           ],
         };
         try {
-          return History.insert(pageInfo).then(() => undefined);
+          return PlacesUtils.history.insert(pageInfo).then(() => undefined);
         } catch (error) {
           return Promise.reject({message: error.message});
         }
       },
 
       deleteAll: function() {
-        return History.clear();
+        return PlacesUtils.history.clear();
       },
 
       deleteRange: function(filter) {
         let newFilter = {
           beginDate: normalizeTime(filter.startTime),
           endDate: normalizeTime(filter.endTime),
         };
         // History.removeVisitsByFilter returns a boolean, but our API should return nothing
-        return History.removeVisitsByFilter(newFilter).then(() => undefined);
+        return PlacesUtils.history.removeVisitsByFilter(newFilter).then(() => undefined);
       },
 
       deleteUrl: function(details) {
         let url = details.url;
         // History.remove returns a boolean, but our API should return nothing
-        return History.remove(url).then(() => undefined);
+        return PlacesUtils.history.remove(url).then(() => undefined);
       },
 
       search: function(query) {
         let beginTime = (query.startTime == null) ?
                           PlacesUtils.toPRTime(Date.now() - 24 * 60 * 60 * 1000) :
                           PlacesUtils.toPRTime(normalizeTime(query.startTime));
         let endTime = (query.endTime == null) ?
                         Number.MAX_VALUE :
                         PlacesUtils.toPRTime(normalizeTime(query.endTime));
         if (beginTime > endTime) {
           return Promise.reject({message: "The startTime cannot be after the endTime"});
         }
 
-        let options = History.getNewQueryOptions();
+        let options = PlacesUtils.history.getNewQueryOptions();
         options.sortingMode = options.SORT_BY_DATE_DESCENDING;
         options.maxResults = query.maxResults || 100;
 
-        let historyQuery = History.getNewQuery();
+        let historyQuery = PlacesUtils.history.getNewQuery();
         historyQuery.searchTerms = query.text;
         historyQuery.beginTime = beginTime;
         historyQuery.endTime = endTime;
-        let queryResult = History.executeQuery(historyQuery, options).root;
+        let queryResult = PlacesUtils.history.executeQuery(historyQuery, options).root;
         let results = convertNavHistoryContainerResultNode(queryResult, convertNodeToHistoryItem);
         return Promise.resolve(results);
       },
 
       getVisits: function(details) {
         let url = details.url;
         if (!url) {
           return Promise.reject({message: "A URL must be provided for getVisits"});
         }
 
-        let options = History.getNewQueryOptions();
+        let options = PlacesUtils.history.getNewQueryOptions();
         options.sortingMode = options.SORT_BY_DATE_DESCENDING;
         options.resultType = options.RESULTS_AS_VISIT;
 
-        let historyQuery = History.getNewQuery();
+        let historyQuery = PlacesUtils.history.getNewQuery();
         historyQuery.uri = NetUtil.newURI(url);
-        let queryResult = History.executeQuery(historyQuery, options).root;
+        let queryResult = PlacesUtils.history.executeQuery(historyQuery, options).root;
         let results = convertNavHistoryContainerResultNode(queryResult, convertNodeToVisitItem);
         return Promise.resolve(results);
       },
 
       onVisited: new SingletonEventManager(context, "history.onVisited", fire => {
         let listener = (event, data) => {
           context.runSafe(fire, data);
         };