Bug 990872 - Eliminate Places dependency in Sync utils. r=gps

This commit is contained in:
Richard Newman 2014-04-01 21:33:42 -07:00
Родитель a2a0ca216f
Коммит 77caf5094f
14 изменённых файлов: 43 добавлений и 38 удалений

Просмотреть файл

@ -2,11 +2,11 @@
* 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/. */
const Cu = Components.utils;
Cu.import("resource://services-sync/main.js");
Cu.import("resource:///modules/PlacesUIUtils.jsm");
Cu.import("resource://gre/modules/PlacesUtils.jsm", this);
Cu.import("resource://gre/modules/Services.jsm");
let RemoteTabViewer = {
@ -129,6 +129,18 @@ let RemoteTabViewer = {
}
},
getIcon: function (iconUri, defaultIcon) {
try {
let iconURI = Weave.Utils.makeURI(iconUri);
return PlacesUtils.favicons.getFaviconLinkForIcon(iconURI).spec;
} catch(ex) {
// Do nothing.
}
// Just give the provided default icon or the system's default.
return defaultIcon || PlacesUtils.favicons.defaultFavicon.spec;
},
_generateTabList: function() {
let engine = Weave.Service.engineManager.get("tabs");
let list = this._tabsList;
@ -169,7 +181,7 @@ let RemoteTabViewer = {
type: "tab",
title: title || url,
url: url,
icon: Weave.Utils.getIcon(icon)
icon: this.getIcon(icon),
}
let tab = this.createItem(attrs);
list.appendChild(tab);

Просмотреть файл

@ -3,8 +3,12 @@
* 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';
Components.utils.import("resource://services-sync/main.js");
"use strict";
const Cu = Components.utils;
Cu.import("resource://services-sync/main.js");
Cu.import("resource://gre/modules/PlacesUtils.jsm", this);
/**
* Wraps a list/grid control implementing nsIDOMXULSelectControlElement and
@ -63,6 +67,18 @@ RemoteTabsView.prototype = Util.extend(Object.create(View.prototype), {
}
},
getIcon: function (iconUri, defaultIcon) {
try {
let iconURI = Weave.Utils.makeURI(iconUri);
return PlacesUtils.favicons.getFaviconLinkForIcon(iconURI).spec;
} catch(ex) {
// Do nothing.
}
// Just give the provided default icon or the system's default.
return defaultIcon || PlacesUtils.favicons.defaultFavicon.spec;
},
populateGrid: function populateGrid() {
let tabsEngine = Weave.Service.engineManager.get("tabs");
@ -88,7 +104,7 @@ RemoteTabsView.prototype = Util.extend(Object.create(View.prototype), {
// need to readd logic to reset seenURLs for each client.
let item = this._set.appendItem((title || url), url);
item.setAttribute("iconURI", Weave.Utils.getIcon(icon));
item.setAttribute("iconURI", this.getIcon(icon));
}, this);
}

Просмотреть файл

@ -11,6 +11,7 @@ const Cr = Components.results;
const HISTORY_TTL = 5184000; // 60 days
Cu.import("resource://gre/modules/PlacesUtils.jsm", this);
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://services-common/async.js");
Cu.import("resource://gre/modules/Log.jsm");

Просмотреть файл

@ -2,7 +2,7 @@
* 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/. */
this.EXPORTED_SYMBOLS = ["XPCOMUtils", "Services", "NetUtil", "PlacesUtils",
this.EXPORTED_SYMBOLS = ["XPCOMUtils", "Services", "NetUtil",
"FileUtils", "Utils", "Async", "Svc", "Str"];
const {classes: Cc, interfaces: Ci, results: Cr, utils: Cu} = Components;
@ -16,7 +16,6 @@ Cu.import("resource://services-crypto/utils.js");
Cu.import("resource://services-sync/constants.js");
Cu.import("resource://gre/modules/FileUtils.jsm", this);
Cu.import("resource://gre/modules/NetUtil.jsm", this);
Cu.import("resource://gre/modules/PlacesUtils.jsm", this);
Cu.import("resource://gre/modules/Preferences.jsm");
Cu.import("resource://gre/modules/Services.jsm", this);
Cu.import("resource://gre/modules/XPCOMUtils.jsm", this);
@ -410,17 +409,6 @@ this.Utils = {
});
},
getIcon: function(iconUri, defaultIcon) {
try {
let iconURI = Utils.makeURI(iconUri);
return PlacesUtils.favicons.getFaviconLinkForIcon(iconURI).spec;
}
catch(ex) {}
// Just give the provided default icon or the system's default
return defaultIcon || PlacesUtils.favicons.defaultFavicon.spec;
},
getErrorString: function Utils_getErrorString(error, args) {
try {
return Str.errors.get(error, args || null);

Просмотреть файл

@ -2,6 +2,7 @@
http://creativecommons.org/publicdomain/zero/1.0/ */
_("Making sure after processing incoming bookmarks, they show up in the right order");
Cu.import("resource://gre/modules/PlacesUtils.jsm", this);
Cu.import("resource://services-sync/engines/bookmarks.js");
Cu.import("resource://services-sync/service.js");
Cu.import("resource://services-sync/util.js");

Просмотреть файл

@ -2,6 +2,7 @@
http://creativecommons.org/publicdomain/zero/1.0/ */
_("Rewrite place: URIs.");
Cu.import("resource://gre/modules/PlacesUtils.jsm");
Cu.import("resource://services-sync/engines/bookmarks.js");
Cu.import("resource://services-sync/service.js");
Cu.import("resource://services-sync/util.js");

Просмотреть файл

@ -1,6 +1,7 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
Cu.import("resource://gre/modules/PlacesUtils.jsm");
Cu.import("resource://services-sync/engines.js");
Cu.import("resource://services-sync/engines/bookmarks.js");
Cu.import("resource://services-sync/service.js");

Просмотреть файл

@ -1,6 +1,7 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
Cu.import("resource://gre/modules/PlacesUtils.jsm");
Cu.import("resource://gre/modules/Log.jsm");
Cu.import("resource://services-sync/constants.js");
Cu.import("resource://services-sync/engines.js");

Просмотреть файл

@ -1,6 +1,7 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
Cu.import("resource://gre/modules/PlacesUtils.jsm");
Cu.import("resource://services-sync/constants.js");
Cu.import("resource://services-sync/engines/history.js");
Cu.import("resource://services-sync/engines.js");

Просмотреть файл

@ -1,6 +1,7 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
Cu.import("resource://gre/modules/PlacesUtils.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://services-common/async.js");
Cu.import("resource://services-sync/engines/history.js");

Просмотреть файл

@ -1,8 +1,8 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/PlacesUtils.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://services-sync/engines.js");
Cu.import("resource://services-sync/constants.js");
Cu.import("resource://services-sync/engines/history.js");

Просмотреть файл

@ -1,6 +1,7 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
Cu.import("resource://gre/modules/PlacesUtils.jsm");
Cu.import("resource://services-common/async.js");
Cu.import("resource://services-sync/util.js");
Cu.import("resource://services-sync/engines.js");

Просмотреть файл

@ -1,18 +0,0 @@
Cu.import("resource://services-sync/util.js");
function run_test() {
_("Test with a valid icon URI");
let iconUri = "http://foo.bar/favicon.png";
let icon1 = Utils.getIcon(iconUri);
do_check_true(icon1.indexOf(iconUri) > 0);
_("Test with an invalid icon URI and default icon");
let icon2 = Utils.getIcon("foo", "bar");
do_check_eq(icon2, "bar");
_("Test with an invalid icon URI and no default icon");
let icon3 = Utils.getIcon("foo");
var defaultFavicon = Cc["@mozilla.org/browser/favicon-service;1"]
.getService(Ci.nsIFaviconService).defaultFavicon.spec;
do_check_eq(icon3, defaultFavicon);
}

Просмотреть файл

@ -25,7 +25,6 @@ support-files =
[test_utils_deriveKey.js]
[test_utils_keyEncoding.js]
[test_utils_getErrorString.js]
[test_utils_getIcon.js]
[test_utils_json.js]
[test_utils_lazyStrings.js]
[test_utils_lock.js]