Bug 1131416 - Desktop syncing module for reading list service (fixes to prepatory changes). rs=jaws a=readinglist
authorDrew Willcoxon <adw@mozilla.com>
Fri, 20 Mar 2015 14:26:54 -0700
changeset 259729 e52d11853e98
parent 259728 54e9be44f35c
child 259730 7b9c0e41f86a
push id721
push userjlund@mozilla.com
push date2015-04-21 23:03 +0000
treeherdermozilla-release@d27c9211ebb3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws, readinglist
bugs1131416
milestone38.0a2
Bug 1131416 - Desktop syncing module for reading list service (fixes to prepatory changes). rs=jaws a=readinglist rs=jaws IRL
browser/base/content/browser-readinglist.js
browser/components/readinglist/ReadingList.jsm
--- a/browser/base/content/browser-readinglist.js
+++ b/browser/base/content/browser-readinglist.js
@@ -287,17 +287,17 @@ let ReadingListUI = {
    */
   togglePageByBrowser: Task.async(function* (browser) {
     let uri = browser.currentURI;
     if (uri.spec.startsWith("about:reader?"))
       uri = ReaderParent.parseReaderUrl(uri.spec);
     if (!uri)
       return;
 
-    let item = yield ReadingList.getItemForURL(uri);
+    let item = yield ReadingList.itemForURL(uri);
     if (item) {
       yield item.delete();
     } else {
       yield ReadingList.addItemFromBrowser(browser, uri);
     }
   }),
 
   /**
--- a/browser/components/readinglist/ReadingList.jsm
+++ b/browser/components/readinglist/ReadingList.jsm
@@ -315,17 +315,17 @@ ReadingListImpl.prototype = {
     let record = {
       url: url,
       title: metadata.title,
       resolvedURL: metadata.url,
       excerpt: metadata.description,
     };
 
     if (metadata.previews.length > 0) {
-      itemData.preview = metadata.previews[0];
+      record.preview = metadata.previews[0];
     }
 
     return (yield this.addItem(record));
   }),
 
   /**
    * Adds a listener that will be notified when the list changes.  Listeners
    * are objects with the following optional methods:
@@ -846,28 +846,32 @@ ReadingListItemIterator.prototype = {
  * Normalizes the properties of a record object, which represents a
  * ReadingListItem.  Throws an error if the record contains properties that
  * aren't in ITEM_RECORD_PROPERTIES.
  *
  * @param record A non-normalized record object.
  * @return The new normalized record.
  */
 function normalizeRecord(nonNormalizedRecord) {
+  let record = {};
   for (let prop in nonNormalizedRecord) {
     if (!ITEM_RECORD_PROPERTIES.includes(prop)) {
       throw new Error("Unrecognized item property: " + prop);
     }
-  }
-
-  let record = clone(nonNormalizedRecord);
-  if (record.url) {
-    record.url = normalizeURI(record.url).spec;
-  }
-  if (record.resolvedURL) {
-    record.resolvedURL = normalizeURI(record.resolvedURL).spec;
+    switch (prop) {
+    case "url":
+    case "resolvedURL":
+      if (nonNormalizedRecord[prop]) {
+        record[prop] = normalizeURI(nonNormalizedRecord[prop]).spec;
+      }
+      break;
+    default:
+      record[prop] = nonNormalizedRecord[prop];
+      break;
+    }
   }
   return record;
 }
 
 /**
  * Normalize a URI, stripping away extraneous parts we don't want to store
  * or compare against.
  *