2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License
|
|
|
|
* Version 1.1 (the "License"); you may not use this file except in
|
|
|
|
* compliance with the License. You may obtain a copy of the License
|
|
|
|
* at http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS"
|
|
|
|
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
|
|
|
* the License for the specific language governing rights and
|
|
|
|
* limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code is the Places JS Livemark Service.
|
|
|
|
*
|
2009-12-21 13:50:30 -08:00
|
|
|
* The Initial Developer of the Original Code is Mozilla Foundation.
|
2007-03-22 10:30:00 -07:00
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2006
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Annie Sullivan <annie.sullivan@gmail.com> (C++ author)
|
|
|
|
* Joe Hughes <joe@retrovirus.com>
|
|
|
|
* Vladimir Vukicevic <vladimir@pobox.com>
|
|
|
|
* Masayuki Nakano <masayuki@d-toybox.com>
|
|
|
|
* Robert Sayre <sayrer@gmail.com> (JS port)
|
2008-01-05 20:45:01 -08:00
|
|
|
* Phil Ringnalda <philringnalda@gmail.com>
|
2008-09-25 03:30:33 -07:00
|
|
|
* Marco Bonardo <mak77@bonardo.net>
|
2008-09-27 04:05:28 -07:00
|
|
|
* Takeshi Ichimaru <ayakawa.m@gmail.com>
|
2007-03-22 10:30:00 -07:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the
|
|
|
|
* terms of either the GNU General Public License Version 2 or later
|
|
|
|
* (the "GPL"), or the GNU Lesser General Public License Version 2.1
|
|
|
|
* or later (the "LGPL"), in which case the provisions of the GPL or
|
|
|
|
* the LGPL are applicable instead of those above. If you wish to
|
|
|
|
* allow use of your version of this file only under the terms of
|
|
|
|
* either the GPL or the LGPL, and not to allow others to use your
|
|
|
|
* version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the
|
|
|
|
* notice and other provisions required by the GPL or the LGPL. If you
|
|
|
|
* do not delete the provisions above, a recipient may use your
|
|
|
|
* version of this file under the terms of any one of the MPL, the GPL
|
|
|
|
* or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2011-06-14 16:54:33 -07:00
|
|
|
|
|
|
|
/* Update Behavior:
|
|
|
|
*
|
|
|
|
* The update timer is started via nsILivemarkService.start(). it fires
|
|
|
|
* immediately and by default every 15 minutes (is dynamically calculated as
|
|
|
|
* gExpiration/4), with a maximum limit of 1 hour.
|
|
|
|
*
|
|
|
|
* When the update timer fires, it iterates over the list of livemarks, and will
|
|
|
|
* refresh a livemark *only* if it's expired. The update is done in chunks and
|
|
|
|
* each chunk is separated by a delay.
|
|
|
|
*
|
|
|
|
* The expiration time for a livemark is determined by using information
|
|
|
|
* provided by the server when the feed was requested, specifically
|
|
|
|
* nsICacheEntryInfo.expirationTime. If no information was provided by the
|
|
|
|
* server, the default expiration time is 1 hour.
|
|
|
|
*
|
|
|
|
* Users can modify the default expiration time via the following preferences:
|
|
|
|
* browser.bookmarks.livemark_refresh_seconds: seconds between updates.
|
|
|
|
* browser.bookmarks.livemark_refresh_limit_count: number of livemarks in a chunk.
|
|
|
|
* browser.bookmarks.livemark_refresh_delay_time: seconds between each chunk.
|
|
|
|
*/
|
2009-09-03 15:19:29 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cr = Components.results;
|
|
|
|
|
2011-06-14 16:54:33 -07:00
|
|
|
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, "NetUtil",
|
|
|
|
"resource://gre/modules/NetUtil.jsm");
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "idle",
|
|
|
|
"@mozilla.org/widget/idleservice;1",
|
|
|
|
"nsIIdleService");
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "secMan",
|
|
|
|
"@mozilla.org/scriptsecuritymanager;1",
|
|
|
|
"nsIScriptSecurityManager");
|
2009-11-06 07:27:51 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
const SEC_FLAGS = Ci.nsIScriptSecurityManager.DISALLOW_INHERIT_PRINCIPAL;
|
|
|
|
|
2009-11-06 07:27:51 -08:00
|
|
|
const PREF_REFRESH_SECONDS = "browser.bookmarks.livemark_refresh_seconds";
|
|
|
|
const PREF_REFRESH_LIMIT_COUNT = "browser.bookmarks.livemark_refresh_limit_count";
|
|
|
|
const PREF_REFRESH_DELAY_TIME = "browser.bookmarks.livemark_refresh_delay_time";
|
|
|
|
|
|
|
|
// Expire livemarks after 1 hour by default (milliseconds).
|
2011-06-14 16:54:33 -07:00
|
|
|
let gExpiration = 3600000;
|
2007-06-12 08:56:36 -07:00
|
|
|
|
2009-11-06 07:27:51 -08:00
|
|
|
// Number of livemarks that are read at once.
|
2011-06-14 16:54:33 -07:00
|
|
|
let gLimitCount = 1;
|
2008-09-27 04:05:28 -07:00
|
|
|
|
2009-11-06 07:27:51 -08:00
|
|
|
// Interval in seconds between refreshes of each group of livemarks.
|
2011-06-14 16:54:33 -07:00
|
|
|
let gDelayTime = 3;
|
2008-09-27 04:05:28 -07:00
|
|
|
|
2009-11-06 07:27:51 -08:00
|
|
|
// Expire livemarks after this time on error (milliseconds).
|
2007-03-22 10:30:00 -07:00
|
|
|
const ERROR_EXPIRATION = 600000;
|
|
|
|
|
2009-11-06 07:27:51 -08:00
|
|
|
// Time after which we will stop checking for livemarks updates (milliseconds).
|
2007-08-31 13:33:54 -07:00
|
|
|
const IDLE_TIMELIMIT = 1800000;
|
|
|
|
|
2009-11-06 07:27:51 -08:00
|
|
|
// Maximum time between update checks (milliseconds).
|
2008-03-07 10:35:29 -08:00
|
|
|
// This cap is used only if the user sets a very high expiration time (>4h)
|
|
|
|
const MAX_REFRESH_TIME = 3600000;
|
2009-11-06 07:27:51 -08:00
|
|
|
// Minimum time between update checks, used to avoid flooding servers.
|
|
|
|
const MIN_REFRESH_TIME = 600000;
|
2008-03-07 10:35:29 -08:00
|
|
|
|
2011-06-14 16:54:33 -07:00
|
|
|
// Tracks the loading status
|
|
|
|
const STATUS = {
|
|
|
|
IDLE: 0,
|
|
|
|
LOADING: 1,
|
|
|
|
FAILED: 2,
|
2007-12-13 22:04:49 -08:00
|
|
|
}
|
2007-12-04 21:02:06 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
function LivemarkService() {
|
2009-11-06 07:27:51 -08:00
|
|
|
this._loadPrefs();
|
2008-09-27 04:05:28 -07:00
|
|
|
|
2011-06-14 16:54:33 -07:00
|
|
|
// Cache of Livemark objects, hashed by folderId.
|
|
|
|
XPCOMUtils.defineLazyGetter(this, "_livemarks", function () {
|
|
|
|
let livemarks = {};
|
|
|
|
PlacesUtils.annotations
|
|
|
|
.getItemsWithAnnotation(PlacesUtils.LMANNO_FEEDURI)
|
|
|
|
.forEach(function (aFolderId) {
|
|
|
|
livemarks[aFolderId] = new Livemark(aFolderId);
|
|
|
|
});
|
|
|
|
return livemarks;
|
|
|
|
});
|
2007-08-02 13:19:44 -07:00
|
|
|
|
2009-11-06 07:27:51 -08:00
|
|
|
// Cleanup on shutdown.
|
2011-06-14 16:54:33 -07:00
|
|
|
Services.obs.addObserver(this, PlacesUtils.TOPIC_SHUTDOWN, false);
|
2009-11-06 07:27:51 -08:00
|
|
|
|
|
|
|
// Observe bookmarks changes.
|
2011-06-14 16:54:33 -07:00
|
|
|
PlacesUtils.bookmarks.addObserver(this, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
LivemarkService.prototype = {
|
2008-01-17 22:58:52 -08:00
|
|
|
_updateTimer: null,
|
|
|
|
start: function LS_start() {
|
2011-06-14 16:54:33 -07:00
|
|
|
if (this._updateTimer) {
|
2008-01-17 22:58:52 -08:00
|
|
|
return;
|
2011-06-14 16:54:33 -07:00
|
|
|
}
|
|
|
|
|
2008-03-07 10:35:29 -08:00
|
|
|
// start is called in delayed startup, 5s after browser startup
|
|
|
|
// we do a first check of the livemarks here, next checks will be on timer
|
|
|
|
// browser start => 5s => this.start() => check => refresh_time => check
|
|
|
|
this._checkAllLivemarks();
|
2008-09-27 04:05:28 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
stopUpdateLivemarks: function LS_stopUpdateLivemarks() {
|
2011-06-14 16:54:33 -07:00
|
|
|
for each (let livemark in this._livemarks) {
|
|
|
|
livemark.abort();
|
2008-09-27 04:05:28 -07:00
|
|
|
}
|
2011-06-14 16:54:33 -07:00
|
|
|
// Stop the update timer.
|
2008-09-27 04:05:28 -07:00
|
|
|
if (this._updateTimer) {
|
|
|
|
this._updateTimer.cancel();
|
|
|
|
this._updateTimer = null;
|
|
|
|
}
|
2008-01-17 22:58:52 -08:00
|
|
|
},
|
|
|
|
|
2009-11-06 07:27:51 -08:00
|
|
|
_loadPrefs: function LS__loadPrefs() {
|
|
|
|
try {
|
2011-06-14 16:54:33 -07:00
|
|
|
let livemarkRefresh = Services.prefs.getIntPref(PREF_REFRESH_SECONDS);
|
2009-11-06 07:27:51 -08:00
|
|
|
// Don't allow setting a too small timeout.
|
|
|
|
gExpiration = Math.max(livemarkRefresh * 1000, MIN_REFRESH_TIME);
|
|
|
|
}
|
|
|
|
catch (ex) { /* no pref, use default */ }
|
|
|
|
|
|
|
|
try {
|
2011-06-14 16:54:33 -07:00
|
|
|
let limitCount = Services.prefs.getIntPref(PREF_REFRESH_LIMIT_COUNT);
|
2009-11-06 07:27:51 -08:00
|
|
|
// Don't allow 0 or negative values.
|
|
|
|
gLimitCount = Math.max(limitCount, gLimitCount);
|
|
|
|
}
|
|
|
|
catch (ex) { /* no pref, use default */ }
|
|
|
|
|
|
|
|
try {
|
2011-06-14 16:54:33 -07:00
|
|
|
let delayTime = Services.prefs.getIntPref(PREF_REFRESH_DELAY_TIME);
|
2009-11-06 07:27:51 -08:00
|
|
|
// Don't allow too small delays.
|
|
|
|
gDelayTime = Math.max(delayTime, gDelayTime);
|
|
|
|
}
|
|
|
|
catch (ex) { /* no pref, use default */ }
|
|
|
|
},
|
|
|
|
|
|
|
|
// nsIObserver
|
|
|
|
observe: function LS_observe(aSubject, aTopic, aData) {
|
2011-06-14 16:54:33 -07:00
|
|
|
if (aTopic == PlacesUtils.TOPIC_SHUTDOWN) {
|
|
|
|
Services.obs.removeObserver(this, aTopic);
|
2009-11-06 07:27:51 -08:00
|
|
|
// Remove bookmarks observer.
|
2011-06-14 16:54:33 -07:00
|
|
|
PlacesUtils.bookmarks.removeObserver(this);
|
2009-11-06 07:27:51 -08:00
|
|
|
// Stop updating livemarks.
|
|
|
|
this.stopUpdateLivemarks();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2008-09-27 04:05:28 -07:00
|
|
|
// We try to distribute the load of the livemark update.
|
|
|
|
// load gLimitCount Livemarks per gDelayTime sec.
|
2011-06-14 16:54:33 -07:00
|
|
|
_updatedLivemarks: [],
|
2011-06-17 08:05:46 -07:00
|
|
|
_forceUpdate: false,
|
|
|
|
_checkAllLivemarks: function LS__checkAllLivemarks(aForceUpdate) {
|
|
|
|
if (aForceUpdate && !this._forceUpdate)
|
|
|
|
this._forceUpdate = true;
|
2011-06-14 16:54:33 -07:00
|
|
|
let updateCount = 0;
|
|
|
|
for each (let livemark in this._livemarks) {
|
|
|
|
if (this._updatedLivemarks.indexOf(livemark.folderId) == -1) {
|
|
|
|
this._updatedLivemarks.push(livemark.folderId);
|
|
|
|
// Check if livemarks are expired, update if needed.
|
2011-06-17 08:05:46 -07:00
|
|
|
if (livemark.updateChildren(this._forceUpdate)) {
|
2011-06-14 16:54:33 -07:00
|
|
|
if (++updateCount == gLimitCount) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-09-27 04:05:28 -07:00
|
|
|
}
|
|
|
|
}
|
2009-11-06 07:27:51 -08:00
|
|
|
|
|
|
|
let refresh_time = gDelayTime * 1000;
|
2011-06-14 16:54:33 -07:00
|
|
|
if (this._updatedLivemarks.length >= Object.keys(this._livemarks).length) {
|
|
|
|
// All livemarks are up-to-date, sleep until next period.
|
|
|
|
this._updatedLivemarks.length = 0;
|
2011-06-17 08:05:46 -07:00
|
|
|
this._forceUpdate = false;
|
2009-11-06 07:27:51 -08:00
|
|
|
refresh_time = Math.min(Math.floor(gExpiration / 4), MAX_REFRESH_TIME);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-11-06 07:27:51 -08:00
|
|
|
this._newTimer(refresh_time);
|
|
|
|
},
|
|
|
|
|
|
|
|
_newTimer: function LS__newTimer(aTime) {
|
2011-06-14 16:54:33 -07:00
|
|
|
if (this._updateTimer) {
|
2009-11-06 07:27:51 -08:00
|
|
|
this._updateTimer.cancel();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-06-14 16:54:33 -07:00
|
|
|
this._updateTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
|
|
|
this._updateTimer.initWithCallback(this._checkAllLivemarks.bind(this),
|
|
|
|
aTime, Ci.nsITimer.TYPE_ONE_SHOT);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2008-03-07 10:35:29 -08:00
|
|
|
createLivemark: function LS_createLivemark(aParentId, aName, aSiteURI,
|
|
|
|
aFeedURI, aIndex) {
|
2011-06-14 16:54:33 -07:00
|
|
|
let folderId = this.createLivemarkFolderOnly(aParentId, aName, aSiteURI,
|
|
|
|
aFeedURI, aIndex);
|
|
|
|
this._livemarks[folderId].updateChildren();
|
2008-03-07 10:35:29 -08:00
|
|
|
return folderId;
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
createLivemarkFolderOnly:
|
2008-03-07 10:35:29 -08:00
|
|
|
function LS_createLivemarkFolderOnly(aParentId, aName, aSiteURI,
|
|
|
|
aFeedURI, aIndex) {
|
2011-06-14 16:54:33 -07:00
|
|
|
if (!aParentId || aParentId < 1 || !aFeedURI ||
|
|
|
|
this.isLivemark(aParentId)) {
|
2009-06-12 00:34:35 -07:00
|
|
|
throw Cr.NS_ERROR_INVALID_ARG;
|
2011-06-14 16:54:33 -07:00
|
|
|
}
|
2009-06-12 00:34:35 -07:00
|
|
|
|
2011-06-14 16:54:33 -07:00
|
|
|
let livemark = new Livemark({ parentId: aParentId,
|
|
|
|
index: aIndex,
|
|
|
|
title: aName });
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-06-14 16:54:33 -07:00
|
|
|
// Add to the cache before setting the feedURI, otherwise isLivemark may
|
|
|
|
// fail identifying it, when invoked by an annotation observer.
|
|
|
|
this._livemarks[livemark.folderId] = livemark;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-06-14 16:54:33 -07:00
|
|
|
livemark.feedURI = aFeedURI;
|
2008-03-07 10:35:29 -08:00
|
|
|
if (aSiteURI) {
|
2011-06-14 16:54:33 -07:00
|
|
|
livemark.siteURI = aSiteURI;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-06-14 16:54:33 -07:00
|
|
|
return livemark.folderId;
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2008-03-07 10:35:29 -08:00
|
|
|
isLivemark: function LS_isLivemark(aFolderId) {
|
2011-06-14 16:54:33 -07:00
|
|
|
if (aFolderId < 1) {
|
2009-06-12 00:34:35 -07:00
|
|
|
throw Cr.NS_ERROR_INVALID_ARG;
|
2009-06-12 15:39:42 -07:00
|
|
|
}
|
2011-06-14 16:54:33 -07:00
|
|
|
|
|
|
|
return aFolderId in this._livemarks;
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2009-06-22 16:00:51 -07:00
|
|
|
getLivemarkIdForFeedURI: function LS_getLivemarkIdForFeedURI(aFeedURI) {
|
2011-06-14 16:54:33 -07:00
|
|
|
if (!(aFeedURI instanceof Ci.nsIURI)) {
|
2009-06-22 16:00:51 -07:00
|
|
|
throw Cr.NS_ERROR_INVALID_ARG;
|
2011-06-14 16:54:33 -07:00
|
|
|
}
|
2009-06-22 16:00:51 -07:00
|
|
|
|
2011-06-14 16:54:33 -07:00
|
|
|
for each (livemark in this._livemarks) {
|
|
|
|
if (livemark.feedURI.equals(aFeedURI)) {
|
|
|
|
return livemark.folderId;
|
|
|
|
}
|
2009-06-22 16:00:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
},
|
|
|
|
|
2008-03-07 10:35:29 -08:00
|
|
|
_ensureLivemark: function LS__ensureLivemark(aFolderId) {
|
2011-06-14 16:54:33 -07:00
|
|
|
if (!this.isLivemark(aFolderId)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
throw Cr.NS_ERROR_INVALID_ARG;
|
2011-06-14 16:54:33 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2008-03-07 10:35:29 -08:00
|
|
|
getSiteURI: function LS_getSiteURI(aFolderId) {
|
|
|
|
this._ensureLivemark(aFolderId);
|
2007-10-13 13:50:57 -07:00
|
|
|
|
2011-06-14 16:54:33 -07:00
|
|
|
return this._livemarks[aFolderId].siteURI;
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2008-03-07 10:35:29 -08:00
|
|
|
setSiteURI: function LS_setSiteURI(aFolderId, aSiteURI) {
|
2011-06-14 16:54:33 -07:00
|
|
|
if (aSiteURI && !(aSiteURI instanceof Ci.nsIURI)) {
|
|
|
|
throw Cr.NS_ERROR_INVALID_ARG;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-06-14 16:54:33 -07:00
|
|
|
this._ensureLivemark(aFolderId);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-06-14 16:54:33 -07:00
|
|
|
this._livemarks[aFolderId].siteURI = aSiteURI;
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2008-03-07 10:35:29 -08:00
|
|
|
getFeedURI: function LS_getFeedURI(aFolderId) {
|
2011-06-14 16:54:33 -07:00
|
|
|
this._ensureLivemark(aFolderId);
|
|
|
|
|
|
|
|
return this._livemarks[aFolderId].feedURI;
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2008-03-07 10:35:29 -08:00
|
|
|
setFeedURI: function LS_setFeedURI(aFolderId, aFeedURI) {
|
2011-06-14 16:54:33 -07:00
|
|
|
if (!aFeedURI || !(aFeedURI instanceof Ci.nsIURI)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
throw Cr.NS_ERROR_INVALID_ARG;
|
2011-06-14 16:54:33 -07:00
|
|
|
}
|
|
|
|
this._ensureLivemark(aFolderId);
|
2007-05-10 01:05:19 -07:00
|
|
|
|
2011-06-14 16:54:33 -07:00
|
|
|
this._livemarks[aFolderId].feedURI = aFeedURI;
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
reloadAllLivemarks: function LS_reloadAllLivemarks() {
|
2011-06-17 08:05:46 -07:00
|
|
|
this._checkAllLivemarks(true);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2008-03-07 10:35:29 -08:00
|
|
|
reloadLivemarkFolder: function LS_reloadLivemarkFolder(aFolderId) {
|
2011-06-14 16:54:33 -07:00
|
|
|
this._ensureLivemark(aFolderId);
|
|
|
|
|
|
|
|
this._livemarks[aFolderId].updateChildren(true);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2007-08-02 13:19:44 -07:00
|
|
|
// nsINavBookmarkObserver
|
|
|
|
onBeginUpdateBatch: function() { },
|
|
|
|
onEndUpdateBatch: function() { },
|
|
|
|
onItemAdded: function() { },
|
|
|
|
onItemChanged: function() { },
|
|
|
|
onItemVisited: function() { },
|
|
|
|
onItemMoved: function() { },
|
2009-03-19 12:56:51 -07:00
|
|
|
onBeforeItemRemoved: function() { },
|
2007-08-02 13:19:44 -07:00
|
|
|
|
2009-10-01 09:53:26 -07:00
|
|
|
onItemRemoved: function(aItemId, aParentId, aIndex, aItemType) {
|
2008-03-07 10:35:29 -08:00
|
|
|
// we don't need to remove annotations since itemAnnotations
|
|
|
|
// are already removed with the bookmark
|
2011-06-14 16:54:33 -07:00
|
|
|
if (!this.isLivemark(aItemId)) {
|
2007-08-02 13:19:44 -07:00
|
|
|
return;
|
|
|
|
}
|
2008-02-23 01:38:39 -08:00
|
|
|
|
2011-06-14 16:54:33 -07:00
|
|
|
this._livemarks[aItemId].terminate();
|
|
|
|
delete this._livemarks[aItemId];
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2009-11-06 07:27:51 -08:00
|
|
|
// nsISupports
|
|
|
|
classID: Components.ID("{dca61eb5-c7cd-4df1-b0fb-d0722baba251}"),
|
|
|
|
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([
|
|
|
|
Ci.nsILivemarkService
|
|
|
|
, Ci.nsINavBookmarkObserver
|
|
|
|
, Ci.nsIObserver
|
|
|
|
])
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2011-06-14 16:54:33 -07:00
|
|
|
/**
|
|
|
|
* Object used internally to represent a livemark.
|
|
|
|
*
|
|
|
|
* @param aFolderIdOrCreationInfo
|
|
|
|
* Item id of the bookmarks folder representing an existing livemark, or
|
|
|
|
* object containing information (parentId, title, index) to create a
|
|
|
|
* new livemark.
|
|
|
|
*
|
|
|
|
* @note terminate() must be invoked before getting rid of this object.
|
|
|
|
*/
|
|
|
|
function Livemark(aFolderIdOrCreationInfo)
|
|
|
|
{
|
|
|
|
if (typeof(aFolderIdOrCreationInfo) == "number") {
|
|
|
|
this.folderId = aFolderIdOrCreationInfo;
|
|
|
|
}
|
|
|
|
else if (typeof(aFolderIdOrCreationInfo) == "object"){
|
|
|
|
this.folderId =
|
|
|
|
PlacesUtils.bookmarks.createFolder(aFolderIdOrCreationInfo.parentId,
|
|
|
|
aFolderIdOrCreationInfo.title,
|
|
|
|
aFolderIdOrCreationInfo.index);
|
|
|
|
PlacesUtils.bookmarks.setFolderReadonly(this.folderId, true);
|
|
|
|
|
|
|
|
// Setup the status to avoid some useless lazy getter work.
|
|
|
|
this._loadStatus = STATUS.IDLE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
throw Cr.NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-06-14 16:54:33 -07:00
|
|
|
Livemark.prototype = {
|
|
|
|
loadGroup: null,
|
|
|
|
locked: null,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether this Livemark is valid or has been terminate()d.
|
|
|
|
*/
|
|
|
|
get alive() !!this.folderId,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets an item annotation on the folderId representing this livemark.
|
|
|
|
*
|
|
|
|
* @param aName
|
|
|
|
* Name of the annotation.
|
|
|
|
* @param aValue
|
|
|
|
* Value of the annotation.
|
|
|
|
* @return The annotation value.
|
|
|
|
* @throws If the folder is invalid.
|
|
|
|
*/
|
|
|
|
_setAnno: function LM__setAnno(aName, aValue)
|
|
|
|
{
|
|
|
|
if (this.alive) {
|
|
|
|
PlacesUtils.annotations
|
|
|
|
.setItemAnnotation(this.folderId, aName, aValue, 0,
|
|
|
|
PlacesUtils.annotations.EXPIRE_NEVER);
|
|
|
|
}
|
|
|
|
return aValue;
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2011-06-14 16:54:33 -07:00
|
|
|
/**
|
|
|
|
* Gets a item annotation from the folderId representing this livemark.
|
|
|
|
*
|
|
|
|
* @param aName
|
|
|
|
* Name of the annotation.
|
|
|
|
* @return The annotation value.
|
|
|
|
* @throws If the folder is invalid or the annotation does not exist.
|
|
|
|
*/
|
|
|
|
_getAnno: function LM__getAnno(aName)
|
|
|
|
{
|
|
|
|
if (this.alive) {
|
|
|
|
return PlacesUtils.annotations.getItemAnnotation(this.folderId, aName);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
2007-05-31 17:44:43 -07:00
|
|
|
|
2011-06-14 16:54:33 -07:00
|
|
|
/**
|
|
|
|
* Removes a item annotation from the folderId representing this livemark.
|
|
|
|
*
|
|
|
|
* @param aName
|
|
|
|
* Name of the annotation.
|
|
|
|
* @throws If the folder is invalid or the annotation does not exist.
|
|
|
|
*/
|
|
|
|
_removeAnno: function LM__removeAnno(aName)
|
|
|
|
{
|
|
|
|
if (this.alive) {
|
|
|
|
return PlacesUtils.annotations.removeItemAnnotation(this.folderId, aName);
|
|
|
|
}
|
|
|
|
},
|
2007-12-13 20:01:05 -08:00
|
|
|
|
2011-06-14 16:54:33 -07:00
|
|
|
set feedURI(aFeedURI)
|
|
|
|
{
|
|
|
|
this._setAnno(PlacesUtils.LMANNO_FEEDURI, aFeedURI.spec);
|
|
|
|
this._feedURI = aFeedURI;
|
|
|
|
},
|
|
|
|
get feedURI()
|
|
|
|
{
|
|
|
|
if (this._feedURI === undefined) {
|
|
|
|
this._feedURI = NetUtil.newURI(this._getAnno(PlacesUtils.LMANNO_FEEDURI));
|
|
|
|
}
|
|
|
|
return this._feedURI;
|
|
|
|
},
|
2007-05-31 17:44:43 -07:00
|
|
|
|
2011-06-14 16:54:33 -07:00
|
|
|
set siteURI(aSiteURI)
|
|
|
|
{
|
|
|
|
if (!aSiteURI) {
|
|
|
|
this._removeAnno(PlacesUtils.LMANNO_SITEURI);
|
|
|
|
this._siteURI = null;
|
|
|
|
return;
|
2007-05-31 17:44:43 -07:00
|
|
|
}
|
|
|
|
|
2011-06-14 16:54:33 -07:00
|
|
|
// Security check the site URI against the feed URI principal.
|
|
|
|
let feedPrincipal = secMan.getCodebasePrincipal(this.feedURI);
|
|
|
|
try {
|
|
|
|
secMan.checkLoadURIWithPrincipal(feedPrincipal, aSiteURI, SEC_FLAGS);
|
|
|
|
}
|
|
|
|
catch (ex) {
|
|
|
|
return;
|
2008-01-05 20:45:01 -08:00
|
|
|
}
|
2007-09-16 18:46:27 -07:00
|
|
|
|
2011-06-14 16:54:33 -07:00
|
|
|
this._setAnno(PlacesUtils.LMANNO_SITEURI, aSiteURI.spec)
|
|
|
|
this._siteURI = aSiteURI;
|
|
|
|
},
|
|
|
|
get siteURI()
|
|
|
|
{
|
|
|
|
if (this._siteURI === undefined) {
|
|
|
|
try {
|
|
|
|
this._siteURI = NetUtil.newURI(this._getAnno(PlacesUtils.LMANNO_SITEURI));
|
|
|
|
} catch (ex if ex.result == Cr.NS_ERROR_NOT_AVAILABLE) {
|
|
|
|
// siteURI is optional.
|
|
|
|
return this._siteURI = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return this._siteURI;
|
|
|
|
},
|
2007-09-16 18:46:27 -07:00
|
|
|
|
2011-06-14 16:54:33 -07:00
|
|
|
set expireTime(aExpireTime)
|
|
|
|
{
|
|
|
|
this._expireTime = this._setAnno(PlacesUtils.LMANNO_EXPIRATION,
|
|
|
|
aExpireTime);
|
|
|
|
},
|
|
|
|
get expireTime()
|
|
|
|
{
|
|
|
|
if (this._expireTime === undefined) {
|
2007-09-16 18:46:27 -07:00
|
|
|
try {
|
2011-06-14 16:54:33 -07:00
|
|
|
this._expireTime = this._getAnno(PlacesUtils.LMANNO_EXPIRATION);
|
|
|
|
} catch (ex if ex.result == Cr.NS_ERROR_NOT_AVAILABLE) {
|
|
|
|
// Expiration time may not be set yet.
|
|
|
|
return this._expireTime = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return this._expireTime;
|
|
|
|
},
|
|
|
|
|
|
|
|
set loadStatus(aStatus)
|
|
|
|
{
|
|
|
|
// Avoid setting the same status multiple times.
|
|
|
|
if (this.loadStatus == aStatus) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (aStatus) {
|
|
|
|
case STATUS.FAILED:
|
|
|
|
if (this.loadStatus == STATUS.LOADING) {
|
|
|
|
this._removeAnno(PlacesUtils.LMANNO_LOADING);
|
|
|
|
}
|
|
|
|
this._setAnno(PlacesUtils.LMANNO_LOADFAILED, true);
|
|
|
|
break;
|
|
|
|
case STATUS.LOADING:
|
|
|
|
if (this.loadStatus == STATUS.FAILED) {
|
|
|
|
this._removeAnno(PlacesUtils.LMANNO_LOADFAILED);
|
|
|
|
}
|
|
|
|
this._setAnno(PlacesUtils.LMANNO_LOADING, true);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (this.loadStatus == STATUS.LOADING) {
|
|
|
|
this._removeAnno(PlacesUtils.LMANNO_LOADING);
|
|
|
|
}
|
|
|
|
else if (this.loadStatus == STATUS.FAILED) {
|
|
|
|
this._removeAnno(PlacesUtils.LMANNO_LOADFAILED);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._loadStatus = aStatus;
|
|
|
|
},
|
|
|
|
get loadStatus()
|
|
|
|
{
|
|
|
|
if (this._loadStatus === undefined) {
|
|
|
|
if (PlacesUtils.annotations.itemHasAnnotation(this.folderId,
|
|
|
|
PlacesUtils.LMANNO_LOADFAILED)) {
|
|
|
|
this._loadStatus = STATUS.FAILED;
|
|
|
|
}
|
|
|
|
else if (PlacesUtils.annotations.itemHasAnnotation(this.folderId,
|
|
|
|
PlacesUtils.LMANNO_LOADING)) {
|
|
|
|
this._loadStatus = STATUS.LOADING;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this._loadStatus = STATUS.IDLE;
|
2007-09-16 18:46:27 -07:00
|
|
|
}
|
2011-06-14 16:54:33 -07:00
|
|
|
}
|
|
|
|
return this._loadStatus;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tries to updates the livemark if needed.
|
|
|
|
* The update process is asynchronous.
|
|
|
|
*
|
|
|
|
* @param [optional] aForceUpdate
|
|
|
|
* If true will try to update the livemark even if its contents have
|
|
|
|
* not yet expired.
|
|
|
|
* @return true if the livemarks will be updated, false otherwise.
|
|
|
|
*/
|
|
|
|
updateChildren: function LM_updateChildren(aForceUpdate)
|
|
|
|
{
|
|
|
|
if (this.locked) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.locked = true;
|
|
|
|
|
|
|
|
// Check the TTL/expiration on this. If there isn't one,
|
|
|
|
// then we assume it's never been loaded. We perform this
|
|
|
|
// check even when the update is being forced, in case the
|
|
|
|
// livemark has somehow never been loaded.
|
|
|
|
if (!aForceUpdate && this.expireTime > Date.now()) {
|
|
|
|
// No need to refresh this livemark.
|
|
|
|
this.locked = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check the user idle time.
|
|
|
|
// If the user is away from the computer, don't bother updating,
|
|
|
|
// so we save some bandwidth.
|
|
|
|
// If we can't get the idle time, assume the user is not idle.
|
|
|
|
try {
|
|
|
|
let idleTime = idle.idleTime;
|
2011-06-17 08:05:46 -07:00
|
|
|
if (idleTime > IDLE_TIMELIMIT && !aForceUpdate) {
|
2011-06-14 16:54:33 -07:00
|
|
|
this.locked = false;
|
|
|
|
return false;
|
2007-05-31 17:44:43 -07:00
|
|
|
}
|
2011-06-14 16:54:33 -07:00
|
|
|
}
|
|
|
|
catch (ex) {}
|
2007-05-31 17:44:43 -07:00
|
|
|
|
2011-06-14 16:54:33 -07:00
|
|
|
let loadgroup;
|
|
|
|
try {
|
|
|
|
// Create a load group for the request. This will allow us to
|
|
|
|
// automatically keep track of redirects, so we can always
|
|
|
|
// cancel the channel.
|
|
|
|
loadgroup = Cc["@mozilla.org/network/load-group;1"].
|
|
|
|
createInstance(Ci.nsILoadGroup);
|
|
|
|
let channel = NetUtil.newChannel(this.feedURI.spec).
|
|
|
|
QueryInterface(Ci.nsIHttpChannel);
|
|
|
|
channel.loadGroup = loadgroup;
|
|
|
|
channel.loadFlags |= Ci.nsIRequest.LOAD_BACKGROUND |
|
|
|
|
Ci.nsIRequest.VALIDATE_ALWAYS;
|
|
|
|
channel.requestMethod = "GET";
|
|
|
|
channel.setRequestHeader("X-Moz", "livebookmarks", false);
|
|
|
|
|
|
|
|
// Stream the result to the feed parser with this listener
|
|
|
|
let listener = new LivemarkLoadListener(this);
|
|
|
|
channel.notificationCallbacks = listener;
|
|
|
|
|
|
|
|
this.loadStatus = STATUS.LOADING;
|
|
|
|
channel.asyncOpen(listener, null);
|
|
|
|
}
|
|
|
|
catch (ex) {
|
|
|
|
this.loadStatus = STATUS.FAILED;
|
|
|
|
this.locked = false;
|
|
|
|
return false;
|
2007-05-31 17:44:43 -07:00
|
|
|
}
|
2011-06-14 16:54:33 -07:00
|
|
|
this.loadGroup = loadgroup;
|
|
|
|
return true;
|
2007-05-31 17:44:43 -07:00
|
|
|
},
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
2011-06-14 16:54:33 -07:00
|
|
|
* Replaces all children of the livemark.
|
|
|
|
*
|
|
|
|
* @param aChildren
|
|
|
|
* Array of new children in the form of { uri, title } objects.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2011-06-14 16:54:33 -07:00
|
|
|
replaceChildren: function LM_replaceChildren(aChildren) {
|
|
|
|
let self = this;
|
|
|
|
PlacesUtils.bookmarks.runInBatchMode({
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([
|
|
|
|
Ci.nsINavHistoryBatchCallback
|
|
|
|
]),
|
|
|
|
runBatched: function LM_runBatched(aUserData) {
|
|
|
|
PlacesUtils.bookmarks.removeFolderChildren(self.folderId);
|
|
|
|
aChildren.forEach(function (aChild) {
|
|
|
|
PlacesUtils.bookmarks.insertBookmark(self.folderId,
|
|
|
|
aChild.uri,
|
|
|
|
PlacesUtils.bookmarks.DEFAULT_INDEX,
|
|
|
|
aChild.title);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, null);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Terminates the livemark entry, cancelling any ongoing load.
|
|
|
|
* Must be invoked before destroying the entry.
|
|
|
|
*/
|
|
|
|
terminate: function LM_terminate()
|
|
|
|
{
|
|
|
|
this.folderId = null;
|
|
|
|
this.abort();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Aborts the livemark loading if needed.
|
|
|
|
*/
|
|
|
|
abort: function LM_abort() {
|
|
|
|
this.locked = false;
|
|
|
|
if (this.loadGroup) {
|
|
|
|
this.loadStatus = STATUS.FAILED;
|
|
|
|
this.loadGroup.cancel(Cr.NS_BINDING_ABORTED);
|
|
|
|
this.loadGroup = null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Object used internally to handle loading a livemark's contents.
|
|
|
|
*
|
|
|
|
* @param aLivemark
|
|
|
|
* The Livemark that is loading.
|
|
|
|
*/
|
|
|
|
function LivemarkLoadListener(aLivemark) {
|
|
|
|
this._livemark = aLivemark;
|
|
|
|
this._processor = null;
|
|
|
|
this._isAborted = false;
|
|
|
|
this._ttl = gExpiration;
|
|
|
|
}
|
|
|
|
|
|
|
|
LivemarkLoadListener.prototype = {
|
|
|
|
abort: function LLL_abort() {
|
|
|
|
this._isAborted = true;
|
|
|
|
this._livemark.abort();
|
|
|
|
},
|
|
|
|
|
|
|
|
// nsIFeedResultListener
|
2008-03-07 10:35:29 -08:00
|
|
|
handleResult: function LLL_handleResult(aResult) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (this._isAborted) {
|
|
|
|
return;
|
|
|
|
}
|
2011-06-14 16:54:33 -07:00
|
|
|
|
2007-05-31 17:44:43 -07:00
|
|
|
try {
|
2011-06-14 16:54:33 -07:00
|
|
|
// We need this to make sure the item links are safe
|
|
|
|
let feedPrincipal = secMan.getCodebasePrincipal(this._livemark.feedURI);
|
|
|
|
|
|
|
|
// Enforce well-formedness because the existing code does
|
|
|
|
if (!aResult || !aResult.doc || aResult.bozo) {
|
|
|
|
this.abort();
|
|
|
|
this._ttl = gExpiration;
|
|
|
|
throw Cr.NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
let feed = aResult.doc.QueryInterface(Ci.nsIFeed);
|
2011-06-14 16:54:35 -07:00
|
|
|
let siteURI = this._livemark.siteURI;
|
|
|
|
if (feed.link && (!siteURI || !feed.link.equals(siteURI))) {
|
|
|
|
this._livemark.siteURI = siteURI = feed.link;
|
2011-06-14 16:54:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Insert feed items.
|
|
|
|
let livemarkChildren = [];
|
|
|
|
for (let i = 0; i < feed.items.length; ++i) {
|
|
|
|
let entry = feed.items.queryElementAt(i, Ci.nsIFeedEntry);
|
2011-06-14 16:54:35 -07:00
|
|
|
let href = entry.link || siteURI;
|
2011-06-14 16:54:33 -07:00
|
|
|
if (!href) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
secMan.checkLoadURIWithPrincipal(feedPrincipal, href, SEC_FLAGS);
|
|
|
|
}
|
|
|
|
catch(ex) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
let title = entry.title ? entry.title.plainText() : "";
|
|
|
|
livemarkChildren.push({ uri: href, title: title });
|
|
|
|
}
|
|
|
|
|
|
|
|
this._livemark.replaceChildren(livemarkChildren);
|
|
|
|
}
|
|
|
|
catch (ex) {
|
|
|
|
this.abort();
|
2007-05-31 17:44:43 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
finally {
|
|
|
|
this._processor.listener = null;
|
|
|
|
this._processor = null;
|
|
|
|
}
|
|
|
|
},
|
2007-12-13 22:04:49 -08:00
|
|
|
|
2008-03-07 10:35:29 -08:00
|
|
|
onDataAvailable: function LLL_onDataAvailable(aRequest, aContext, aInputStream,
|
|
|
|
aSourceOffset, aCount) {
|
2011-06-14 16:54:33 -07:00
|
|
|
if (this._processor) {
|
2009-05-01 22:17:07 -07:00
|
|
|
this._processor.onDataAvailable(aRequest, aContext, aInputStream,
|
|
|
|
aSourceOffset, aCount);
|
2011-06-14 16:54:33 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
2007-12-13 22:04:49 -08:00
|
|
|
|
2008-03-07 10:35:29 -08:00
|
|
|
onStartRequest: function LLL_onStartRequest(aRequest, aContext) {
|
2011-06-14 16:54:33 -07:00
|
|
|
if (this._isAborted) {
|
2007-03-22 10:30:00 -07:00
|
|
|
throw Cr.NS_ERROR_UNEXPECTED;
|
2011-06-14 16:54:33 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-06-14 16:54:33 -07:00
|
|
|
this._livemark.loadStatus = STATUS.LOADING;
|
|
|
|
|
|
|
|
let channel = aRequest.QueryInterface(Ci.nsIChannel);
|
2007-12-13 22:04:49 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Parse feed data as it comes in
|
2011-06-14 16:54:33 -07:00
|
|
|
this._processor = Cc["@mozilla.org/feed-processor;1"].
|
|
|
|
createInstance(Ci.nsIFeedProcessor);
|
2007-03-22 10:30:00 -07:00
|
|
|
this._processor.listener = this;
|
|
|
|
this._processor.parseAsync(null, channel.URI);
|
2007-12-13 22:04:49 -08:00
|
|
|
|
2009-07-07 03:41:23 -07:00
|
|
|
try {
|
|
|
|
this._processor.onStartRequest(aRequest, aContext);
|
|
|
|
}
|
|
|
|
catch (ex) {
|
|
|
|
Components.utils.reportError("Livemark Service: feed processor received an invalid channel for " + channel.URI.spec);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
2007-12-13 22:04:49 -08:00
|
|
|
|
2008-03-07 10:35:29 -08:00
|
|
|
onStopRequest: function LLL_onStopRequest(aRequest, aContext, aStatus) {
|
|
|
|
if (!Components.isSuccessCode(aStatus)) {
|
2011-06-14 16:54:33 -07:00
|
|
|
this.abort();
|
|
|
|
this._setResourceTTL(ERROR_EXPIRATION);
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
}
|
2011-06-14 16:54:33 -07:00
|
|
|
|
|
|
|
if (this._livemark.loadStatus == STATUS.LOADING) {
|
|
|
|
this._livemark.loadStatus = STATUS.IDLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set an expiration on the livemark, to reloading the data in future.
|
2007-12-13 22:04:49 -08:00
|
|
|
try {
|
2011-06-14 16:54:33 -07:00
|
|
|
if (this._processor) {
|
2009-05-01 22:17:07 -07:00
|
|
|
this._processor.onStopRequest(aRequest, aContext, aStatus);
|
2011-06-14 16:54:33 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Calculate a new ttl
|
2011-06-14 16:54:33 -07:00
|
|
|
let channel = aRequest.QueryInterface(Ci.nsICachingChannel);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (channel) {
|
2011-06-14 16:54:33 -07:00
|
|
|
let entryInfo = channel.cacheToken.QueryInterface(Ci.nsICacheEntryInfo);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (entryInfo) {
|
2007-12-13 22:04:49 -08:00
|
|
|
// nsICacheEntryInfo returns value as seconds,
|
2008-03-07 10:35:29 -08:00
|
|
|
// expireTime stores as milliseconds
|
2011-06-14 16:54:33 -07:00
|
|
|
let expireTime = entryInfo.expirationTime * 1000;
|
|
|
|
let nowTime = Date.now();
|
2007-12-13 22:04:49 -08:00
|
|
|
|
2008-03-07 10:35:29 -08:00
|
|
|
// note, expireTime can be 0, see bug 383538
|
|
|
|
if (expireTime > nowTime) {
|
2011-06-14 16:54:33 -07:00
|
|
|
this._setResourceTTL(Math.max((expireTime - nowTime), gExpiration));
|
2007-06-12 08:56:36 -07:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-06-14 16:54:33 -07:00
|
|
|
catch (ex) {
|
|
|
|
this.abort();
|
|
|
|
}
|
|
|
|
finally {
|
|
|
|
this._livemark.locked = false;
|
|
|
|
this._livemark.loadGroup = null;
|
|
|
|
}
|
2007-06-12 08:56:36 -07:00
|
|
|
this._setResourceTTL(this._ttl);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2008-03-07 10:35:29 -08:00
|
|
|
_setResourceTTL: function LLL__setResourceTTL(aMilliseconds) {
|
2011-06-14 16:54:33 -07:00
|
|
|
this._livemark.expireTime = Date.now() + aMilliseconds;
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
2007-12-13 22:04:49 -08:00
|
|
|
|
2009-11-06 07:27:51 -08:00
|
|
|
// nsIBadCertListener2
|
|
|
|
notifyCertProblem:
|
|
|
|
function LLL_certProblem(aSocketInfo, aStatus, aTargetSite) {
|
2008-01-15 07:06:34 -08:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2009-11-06 07:27:51 -08:00
|
|
|
// nsISSLErrorListener
|
2008-03-07 10:35:29 -08:00
|
|
|
notifySSLError: function LLL_SSLError(aSocketInfo, aError, aTargetSite) {
|
2008-01-15 07:06:34 -08:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2009-11-06 07:27:51 -08:00
|
|
|
// nsIInterfaceRequestor
|
2008-03-07 10:35:29 -08:00
|
|
|
getInterface: function LLL_getInterface(aIID) {
|
|
|
|
return this.QueryInterface(aIID);
|
2008-01-15 07:06:34 -08:00
|
|
|
},
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// nsISupports
|
2009-11-06 07:27:51 -08:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([
|
|
|
|
Ci.nsIFeedResultListener
|
|
|
|
, Ci.nsIStreamListener
|
|
|
|
, Ci.nsIRequestObserver
|
|
|
|
, Ci.nsIBadCertListener2
|
|
|
|
, Ci.nsISSLErrorListener
|
|
|
|
, Ci.nsIInterfaceRequestor
|
|
|
|
])
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-06-14 16:54:33 -07:00
|
|
|
const NSGetFactory = XPCOMUtils.generateNSGetFactory([LivemarkService]);
|