Bug 789363 - Work - Live update the history used for Firefox Start.r=mbrubeck
authorAllison Naaktgeboren <ally@mozilla.com>
Fri, 26 Apr 2013 14:21:36 -0700
changeset 141068 384746174d6d344b233a5294110cbb5b99e9ee14
parent 141067 171ed33b6622804e6eedb356da3d822ace7b6912
child 141069 98ce2f8962536e1febd90f4c3c8ccd336bfe2f84
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmbrubeck
bugs789363
milestone23.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 789363 - Work - Live update the history used for Firefox Start.r=mbrubeck
browser/metro/base/content/history.js
--- a/browser/metro/base/content/history.js
+++ b/browser/metro/base/content/history.js
@@ -1,19 +1,19 @@
 // -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*-
 /* 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/. */
 'use strict';
 
 
-// TODO <jwilde>: Observe changes in history with nsINavHistoryObserver
 function HistoryView(aSet) {
   this._set = aSet;
   this._set.controller = this;
+  this._inBatch = false;
 
   let history = Cc["@mozilla.org/browser/nav-history-service;1"].
                 getService(Ci.nsINavHistoryService);
   history.addObserver(this, false);
 }
 
 HistoryView.prototype = {
   _set:null,
@@ -37,52 +37,88 @@ HistoryView.prototype = {
     rootNode.containerOpen = true;
     let childCount = rootNode.childCount;
 
     for (let i = 0; i < childCount; i++) {
       let node = rootNode.getChild(i);
       let uri = node.uri;
       let title = node.title || uri;
 
-      let item = this._set.appendItem(title, uri);
-      item.setAttribute("iconURI", node.icon);
+      this.addItemToSet(uri, title, node.icon);
     }
 
     rootNode.containerOpen = false;
   },
 
   destruct: function destruct() {
   },
 
-  // nsINavHistoryObserver
+  // nsINavHistoryObserver & helpers
+
+  addItemToSet: function addItemToSet(uri, title, icon) {
+    let item = this._set.appendItem(title, uri, this._inBatch);
+    item.setAttribute("iconURI", icon);
+  },
+
+  // TODO rebase/merge Alert: bug 831916 's patch merges in,
+  // this can be replaced with the updated calls to populateGrid()
+  refreshAndRepopulate: function() {
+    this._set.clearAll();
+    this.populateGrid();
+  },
 
   onBeginUpdateBatch: function() {
+    // Avoid heavy grid redraws while a batch is in process
+    this._inBatch = true;
   },
 
   onEndUpdateBatch: function() {
+    this._inBatch = false;
+    this.refreshAndRepopulate();
   },
 
   onVisit: function(aURI, aVisitID, aTime, aSessionID,
                     aReferringID, aTransitionType) {
+    this.refreshAndRepopulate();
   },
 
   onTitleChanged: function(aURI, aPageTitle) {
+    let changedItems = this._set.getItemsByUrl(aURI.spec);
+    for (let item of changedItems) {
+      item.setAttribute("label", aPageTitle);
+    }
   },
 
   onDeleteURI: function(aURI) {
+    for (let item of this._set.getItemsByUrl(aURI.spec)) {
+      this._set.removeItem(item, this._inBatch);
+    }
   },
 
   onClearHistory: function() {
     this._set.clearAll();
   },
 
   onPageChanged: function(aURI, aWhat, aValue) {
+    if (aWhat ==  Ci.nsINavHistoryObserver.ATTRIBUTE_FAVICON) {
+      let changedItems = this._set.getItemsByUrl(aURI.spec);
+      for (let item of changedItems) {
+        let currIcon = item.getAttribute("iconURI");
+        if (currIcon != aValue) {
+          item.setAttribute("iconURI", aValue);
+        }
+      }
+    }
   },
 
-  onPageExpired: function(aURI, aVisitTime, aWholeEntry) {
+  onDeleteVisits: function (aURI, aVisitTime, aGUID, aReason, aTransitionType) {
+    if (aReason ==  Ci.nsINavHistoryObserver.REASON_DELETED) {
+      Cu.reportError("got REASON_DELETED");
+      this.refreshAndRepopulate();
+    }
   },
 
   QueryInterface: function(iid) {
     if (iid.equals(Components.interfaces.nsINavHistoryObserver) ||
         iid.equals(Components.interfaces.nsISupports)) {
       return this;
     }
     throw Cr.NS_ERROR_NO_INTERFACE;
@@ -120,9 +156,8 @@ let HistoryPanelView = {
     this._view = new HistoryView(this._grid);
     this._view.populateGrid();
   },
 
   uninit: function uninit() {
     this._view.destruct();
   }
 };
-