Bug 578694 - Extend `removeVisitsByFilter` to delete Places by GUID. draft
authorKit Cambridge <kit@yakshaving.ninja>
Thu, 23 Nov 2017 16:11:13 -0800
changeset 702922 3d73d64a8f7e3f481cb12ce1346936ce66721d59
parent 702148 571fa7413320e0b7ed2cbc2ff1e7d81a1924bd3c
child 702923 f3caba567e2f504701d1937028c8528c9c6465a6
child 702930 bd0c837491691646ed1eaf2c3e3485d9e25e4e07
push id90630
push userbmo:kit@mozilla.com
push dateFri, 24 Nov 2017 00:14:28 +0000
bugs578694
milestone59.0a1
Bug 578694 - Extend `removeVisitsByFilter` to delete Places by GUID. MozReview-Commit-ID: J1Hf6hJ8OYi
toolkit/components/places/History.jsm
--- a/toolkit/components/places/History.jsm
+++ b/toolkit/components/places/History.jsm
@@ -396,34 +396,39 @@ this.History = Object.freeze({
     if (!filter || typeof filter != "object") {
       throw new TypeError("Expected a filter");
     }
 
     let hasBeginDate = "beginDate" in filter;
     let hasEndDate = "endDate" in filter;
     let hasURL = "url" in filter;
     let hasLimit = "limit" in filter;
+    let hasGUID = "guid" in filter;
     if (hasBeginDate) {
       this.ensureDate(filter.beginDate);
     }
     if (hasEndDate) {
       this.ensureDate(filter.endDate);
     }
     if (hasBeginDate && hasEndDate && filter.beginDate > filter.endDate) {
       throw new TypeError("`beginDate` should be at least as old as `endDate`");
     }
-    if (!hasBeginDate && !hasEndDate && !hasURL && !hasLimit) {
+    if (!hasBeginDate && !hasEndDate && !hasURL && !hasLimit && !hasGUID) {
       throw new TypeError("Expected a non-empty filter");
     }
 
     if (hasURL && !(filter.url instanceof URL) && typeof filter.url != "string" &&
         !(filter.url instanceof Ci.nsIURI)) {
       throw new TypeError("Expected a valid URL for `url`");
     }
 
+    if (hasGUID && !PlacesUtils.isValidGuid(filter.guid)) {
+      throw new TypeError("Expected a valid GUID for `guid`");
+    }
+
     if (hasLimit &&
         (typeof filter.limit != "number" ||
          filter.limit <= 0 ||
          !Number.isInteger(filter.limit))) {
       throw new TypeError("Expected a non-zero positive integer as a limit");
     }
 
     if (onResult && typeof onResult != "function") {
@@ -1035,26 +1040,34 @@ var removeVisitsByFilter = async functio
     conditions.push("v.visit_date <= :end * 1000");
     args.end = Number(filter.endDate);
   }
   if ("limit" in filter) {
     args.limit = Number(filter.limit);
   }
 
   let optionalJoin = "";
-  if ("url" in filter) {
-    let url = filter.url;
-    if (url instanceof Ci.nsIURI) {
-      url = filter.url.spec;
-    } else {
-      url = new URL(url).href;
+  let hasURL = "url" in filter;
+  let hasGUID = "guid" in filter;
+  if (hasURL || hasGUID) {
+    optionalJoin = `JOIN moz_places h ON h.id = v.place_id`;
+    if (hasURL) {
+      let url = filter.url;
+      if (url instanceof Ci.nsIURI) {
+        url = filter.url.spec;
+      } else {
+        url = new URL(url).href;
+      }
+      conditions.push("h.url_hash = hash(:url)", "h.url = :url");
+      args.url = url;
     }
-    optionalJoin = `JOIN moz_places h ON h.id = v.place_id`;
-    conditions.push("h.url_hash = hash(:url)", "h.url = :url");
-    args.url = url;
+    if (hasGUID) {
+      conditions.push("h.guid = :guid");
+      args.guid = filter.guid;
+    }
   }
 
 
   let visitsToRemove = [];
   let pagesToInspect = new Set();
   let onResultData = onResult ? [] : null;
 
   await db.executeCached(