~ubuntu-branches/ubuntu/lucid/ubufox/lucid-security

« back to all changes in this revision

Viewing changes to content/overlay.js

  • Committer: Package Import Robot
  • Author(s): Chris Coulson
  • Date: 2012-06-27 20:31:34 UTC
  • mfrom: (1.1.26)
  • Revision ID: package-import@ubuntu.com-20120627203134-jwppqfwlv3xzc5ei
Tags: 2.1.1-0ubuntu0.10.04.1
* New upstream release v2.1.1
  - Drop the alternative plugin selector, as it depends on a patch that
    we no longer carry in Firefox

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
 * 
35
35
 * ***** END LICENSE BLOCK ***** */
36
36
 
37
 
Components.utils.import("resource://gre/modules/Services.jsm");
38
 
Components.utils.import("resource://ubufox/uAddonInstaller.jsm");
39
 
 
40
 
function getAppVersion ()
41
 
{
42
 
  var versionString = null;
43
 
  try {
44
 
    versionString = Components.classes["@mozilla.org/fuel/application;1"].getService(Components.interfaces.extIApplication).version;
45
 
  } catch (e) {
 
37
if (!com) var com = {};
 
38
if (!com.ubuntu) com.ubuntu = {};
 
39
 
 
40
(function() {
 
41
  const { classes: Cc, utils: Cu } = Components;
 
42
 
 
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");
 
47
 
 
48
  var UpdateRestartListener = {
 
49
    updated: false,
 
50
 
 
51
    addNotificationToBrowser: function URL_addNotificationToBrowser(browser) {
 
52
      let notificationBox = gBrowser.getNotificationBox(browser);
 
53
      let notification = notificationBox
 
54
                         .getNotificationWithValue("notification-restart");
 
55
      if (!notification) {
 
56
        notificationBox.appendNotification(this.restartNotificationLabel,
 
57
                                           "notification-restart", "",
 
58
                                           notificationBox.PRIORITY_WARNING_LOW,
 
59
                                           this.buttons);
 
60
      }
 
61
    },
 
62
 
 
63
    onUpdatedNotify: function URL_onUpdatedNotify() {
 
64
      if (!this.updated) {
 
65
        this.updated = true;
 
66
 
 
67
        gBrowser.tabContainer.addEventListener("TabOpen", function(aEvent) {
 
68
          UpdateRestartListener.addNotificationToBrowser(gBrowser
 
69
                                                         .getBrowserForTab(aEvent.target));
 
70
        }, false);
 
71
      }
 
72
 
 
73
      gBrowser.browsers.forEach(function(browser) {
 
74
        UpdateRestartListener.addNotificationToBrowser(browser);
 
75
      });
 
76
    }
 
77
  };
 
78
 
 
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;
 
82
 
 
83
    return [{ label: bundle.getString("restartNotificationButton"),
 
84
              accessKey: bundle.getString("restartNotificationKey"),
 
85
              callback: svc.restart }];
 
86
  });
 
87
 
 
88
  XPCOMUtils.defineLazyGetter(UpdateRestartListener,
 
89
                              "restartNotificationLabel",
 
90
                              function() {
 
91
    let bundle = document.getElementById("ubufox-restart-strings");
 
92
    return bundle.getString("restartNotificationLabel");
 
93
  });
 
94
 
 
95
  this.Ubufox = {
 
96
    reportBug: function() {
 
97
      distro.reportBug();
 
98
    },
 
99
 
 
100
    help: function() {
 
101
      openUILinkIn(distro.helpURL, "tab");
 
102
    }
 
103
  };
 
104
 
 
105
  // Override an existing function with a new function, chaining up to
 
106
  // the old function
 
107
  function overrideExistingFunction(aObject, aName, aReplacement) {
 
108
    var old = aObject[aName];
 
109
    aObject[aName] = function() {
 
110
      try {
 
111
        aReplacement.apply(aObject, arguments);
 
112
      } catch(e) {
 
113
        Cu.reportError(e);
 
114
      }
 
115
      old.apply(aObject, arguments);
 
116
    }
46
117
  }
47
118
 
48
 
  if (versionString == null)
49
 
    return null;
50
 
 
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
56
 
    versionString = null;
57
 
 
58
 
  return versionString;
59
 
}
60
 
 
61
 
function getSourcePackageName ()
62
 
{
63
 
  var sourcePackageName = "firefox";
64
 
  var versionString = getAppVersion();
65
 
  if (versionString)
66
 
    sourcePackageName = sourcePackageName + "-" + versionString;
67
 
 
68
 
  return sourcePackageName;
69
 
}
70
 
 
71
 
function ubufoxReportBug(event) {
72
 
 
73
 
  var executable =
74
 
      Components.classes['@mozilla.org/file/local;1']
75
 
      .createInstance(Components.interfaces.nsILocalFile);
76
 
 
77
 
  executable.initWithPath("/usr/bin/ubuntu-bug");
78
 
 
79
 
  if(!executable.exists () || !executable.isExecutable())
80
 
         alert('Unexpected error!');
81
 
 
82
 
  var procUtil =
83
 
      Components.classes['@mozilla.org/process/util;1']
84
 
      .createInstance(Components.interfaces.nsIProcess);
85
 
 
86
 
  var nsFile = executable.QueryInterface(Components.interfaces.nsIFile);
87
 
 
88
 
  procUtil.init(executable);
89
 
 
90
 
  var args = null;
91
 
  args = new Array("-p", getSourcePackageName());
92
 
 
93
 
  var res = procUtil.run(false, args, args.length);
94
 
}
95
 
 
96
 
 
97
 
function ubufoxGetHelpOnline(event)
98
 
{
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);
102
 
}
103
 
 
104
 
function ubufoxHelpTranslateLaunchpad(event)
105
 
{
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);
109
 
}
 
119
  overrideExistingFunction(window, "buildHelpMenu", function() {
 
120
    let helpURL = null;
 
121
    try {
 
122
      helpURL = distro.helpURL;
 
123
    } catch(e) { };
 
124
 
 
125
    document.getElementById("ubufox-reportbug").setAttribute("hidden",
 
126
                                                             !distro.canReportBug);
 
127
    document.getElementById("ubufox-gethelp").setAttribute("hidden", helpURL == null);
 
128
  });
 
129
 
 
130
  addEventListener("load", function() {
 
131
    try {
 
132
      removeEventListener("load", arguments.callee, false);
 
133
      Cc["@ubuntu.com/update-restart-notifier;1"].getService()
 
134
                                                 .wrappedJSObject
 
135
                                                 .addListener(UpdateRestartListener);
 
136
    } catch(e) {
 
137
      Cu.reportError(e);
 
138
    }
 
139
  }, false);
 
140
 
 
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()
 
147
                                               .wrappedJSObject
 
148
                                               .removeListener(UpdateRestartListener);
 
149
  }, false);
 
150
 
 
151
}).call(com.ubuntu);