35
35
* ***** END LICENSE BLOCK ***** */
37
Components.utils.import("resource://gre/modules/Services.jsm");
38
Components.utils.import("resource://ubufox/uAddonInstaller.jsm");
40
function getAppVersion ()
42
var versionString = null;
44
versionString = Components.classes["@mozilla.org/fuel/application;1"].getService(Components.interfaces.extIApplication).version;
37
if (!com) var com = {};
38
if (!com.ubuntu) com.ubuntu = {};
41
const { classes: Cc, utils: Cu } = Components;
43
Cu.import("resource://gre/modules/Services.jsm");
44
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
45
Cu.import("resource://ubufox/Distro.jsm");
46
Cu.import("resource://ubufox/uAddonInstaller.jsm");
48
var UpdateRestartListener = {
51
addNotificationToBrowser: function URL_addNotificationToBrowser(browser) {
52
let notificationBox = gBrowser.getNotificationBox(browser);
53
let notification = notificationBox
54
.getNotificationWithValue("notification-restart");
56
notificationBox.appendNotification(this.restartNotificationLabel,
57
"notification-restart", "",
58
notificationBox.PRIORITY_WARNING_LOW,
63
onUpdatedNotify: function URL_onUpdatedNotify() {
67
gBrowser.tabContainer.addEventListener("TabOpen", function(aEvent) {
68
UpdateRestartListener.addNotificationToBrowser(gBrowser
69
.getBrowserForTab(aEvent.target));
73
gBrowser.browsers.forEach(function(browser) {
74
UpdateRestartListener.addNotificationToBrowser(browser);
79
XPCOMUtils.defineLazyGetter(UpdateRestartListener, "buttons", function() {
80
let bundle = document.getElementById("ubufox-restart-strings");
81
let svc = Cc["@ubuntu.com/update-restart-notifier;1"].getService().wrappedJSObject;
83
return [{ label: bundle.getString("restartNotificationButton"),
84
accessKey: bundle.getString("restartNotificationKey"),
85
callback: svc.restart }];
88
XPCOMUtils.defineLazyGetter(UpdateRestartListener,
89
"restartNotificationLabel",
91
let bundle = document.getElementById("ubufox-restart-strings");
92
return bundle.getString("restartNotificationLabel");
96
reportBug: function() {
101
openUILinkIn(distro.helpURL, "tab");
105
// Override an existing function with a new function, chaining up to
107
function overrideExistingFunction(aObject, aName, aReplacement) {
108
var old = aObject[aName];
109
aObject[aName] = function() {
111
aReplacement.apply(aObject, arguments);
115
old.apply(aObject, arguments);
48
if (versionString == null)
51
if (String_startsWith (versionString, "3.0"))
52
versionString = "3.0";
53
else if (String_startsWith (versionString, "3.5"))
54
versionString = "3.5";
55
else // Return null for > 3.6 as firefox is unversioned now
61
function getSourcePackageName ()
63
var sourcePackageName = "firefox";
64
var versionString = getAppVersion();
66
sourcePackageName = sourcePackageName + "-" + versionString;
68
return sourcePackageName;
71
function ubufoxReportBug(event) {
74
Components.classes['@mozilla.org/file/local;1']
75
.createInstance(Components.interfaces.nsILocalFile);
77
executable.initWithPath("/usr/bin/ubuntu-bug");
79
if(!executable.exists () || !executable.isExecutable())
80
alert('Unexpected error!');
83
Components.classes['@mozilla.org/process/util;1']
84
.createInstance(Components.interfaces.nsIProcess);
86
var nsFile = executable.QueryInterface(Components.interfaces.nsIFile);
88
procUtil.init(executable);
91
args = new Array("-p", getSourcePackageName());
93
var res = procUtil.run(false, args, args.length);
97
function ubufoxGetHelpOnline(event)
99
var codename = Services.prefs.getCharPref("extensions.ubufox@ubuntu.com.codename");
100
var getHelpUrl = "https://launchpad.net/distros/ubuntu/" + codename + "/+sources/" + getSourcePackageName() + "/+gethelp";
101
openUILink(getHelpUrl, event, false, true);
104
function ubufoxHelpTranslateLaunchpad(event)
106
var codename = Services.prefs.getCharPref("extensions.ubufox@ubuntu.com.codename");
107
var translateUrl = "https://launchpad.net/distros/ubuntu/" + codename + "/+sources/" + getSourcePackageName() + "/+translate";
108
openUILink(translateUrl, event, false, true);
119
overrideExistingFunction(window, "buildHelpMenu", function() {
122
helpURL = distro.helpURL;
125
document.getElementById("ubufox-reportbug").setAttribute("hidden",
126
!distro.canReportBug);
127
document.getElementById("ubufox-gethelp").setAttribute("hidden", helpURL == null);
130
addEventListener("load", function() {
132
removeEventListener("load", arguments.callee, false);
133
Cc["@ubuntu.com/update-restart-notifier;1"].getService()
135
.addListener(UpdateRestartListener);
141
addEventListener("unload", function() {
142
removeEventListener("unload", arguments.callee, false);
143
// Don't remove this call, ever. Without this we will leak the
144
// document as it is in the scope of the callback, which
145
// UpdateRestartNotifier is holding on to
146
Cc["@ubuntu.com/update-restart-notifier;1"].getService()
148
.removeListener(UpdateRestartListener);