From 9bb360e6454ce4fd70daba0cd49d017f32276f0a Mon Sep 17 00:00:00 2001 From: John Foerch Date: Tue, 4 Dec 2012 19:59:11 -0500 Subject: [PATCH] favicon_set: fix for xulrunner 18 The call form of favicon_service.setAndLoadFaviconForPage changed in xulrunner 18. get_mozilla_version, version_compare: new utils --- modules/env.js | 11 +++++++++++ modules/favicon.js | 21 +++++++++++++++++---- modules/string.js | 11 +++++++++++ 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/modules/env.js b/modules/env.js index 073ca7c..9a39c06 100644 --- a/modules/env.js +++ b/modules/env.js @@ -23,6 +23,17 @@ const POSIX = !WINDOWS; /** + * get_xulrunner_version returns the version string of the running + * platform. + */ +function get_mozilla_version () { + return Cc['@mozilla.org/xre/app-info;1'] + .getService(Ci.nsIXULAppInfo) + .platformVersion; +} + + +/** * getenv returns the value of a named environment variable or null if * the environment variable does not exist. */ diff --git a/modules/favicon.js b/modules/favicon.js index 83b281b..abbe60b 100644 --- a/modules/favicon.js +++ b/modules/favicon.js @@ -17,10 +17,23 @@ define_variable("favicon_image_max_size", 1024, "is considered for use as a favicon."); -function favicon_set (buffer, icon_url) { - favicon_service.setAndLoadFaviconForPage(buffer.current_uri, - icon_url, false); - buffer.icon = icon_url.spec; +let (favicon_set_internal) { + if (version_compare(get_mozilla_version(), "18.0") >= 0) { + favicon_set_internal = function (buffer, icon_url) { + favicon_service.setAndLoadFaviconForPage( + buffer.current_uri, icon_url, false, + favicon_service.FAVICON_LOAD_NON_PRIVATE); + }; + } else { + favicon_set_internal = function (buffer, icon_url) { + favicon_service.setAndLoadFaviconForPage( + buffer.current_uri, icon_url, false); + }; + } + function favicon_set (buffer, icon_url) { + favicon_set_internal(buffer, icon_url); + buffer.icon = icon_url.spec; + } } diff --git a/modules/string.js b/modules/string.js index 4331c5a..87d0f59 100644 --- a/modules/string.js +++ b/modules/string.js @@ -196,4 +196,15 @@ function position_in_strings (strings, pos) { } +/** + * version_compare: compare two version strings with nsIVersionComparator. + * If a == b, returns 0; if a < b, returns <0; if a > b, returns >0. + */ +function version_compare (a, b) { + var vc = Cc["@mozilla.org/xpcom/version-comparator;1"] + .getService(Ci.nsIVersionComparator); + return vc.compare(a, b); +} + + provide("string"); -- 2.11.4.GIT