~ubuntu-branches/ubuntu/raring/ubufox/raring-security

« back to all changes in this revision

Viewing changes to content/overlay.js

  • Committer: Bazaar Package Importer
  • Author(s): Chris Coulson
  • Date: 2011-07-29 08:14:18 UTC
  • mfrom: (1.1.24 upstream)
  • Revision ID: james.westby@ubuntu.com-20110729081418-jp47q22u7kfr6y01
Tags: 1.0~b1-0ubuntu1
* New upstream release
  - Refactor the update restart notify functionality. The scheduling for
    checking if an update has occurred has been moved in to a JS module shared
    between windows, rather than having every window set up its own timer
    and doing its own checking. Each window registers as a listener on the
    new module
  - Drop all of the ubuntuAltPlugins overlay stuff. We still retain the
    dialog for configuring plugins, but the listeners that fired everytime
    a document was loaded or tab was switched have gone. Instead, the
    information required by the dialog is created when it is launched, rather
    than maintaining a bunch of state on each content document.
  - Clean up the variables that are added to the main window global scope.
    The only variables added now are functions called by menuitem oncommand
    handlers, and these are all namespaced org.ubuntu.Ubufox
  - Hide the translate menuitem in the help menu. It makes no sense to show
    this whilst we aren't using Launchpad for translations
  - Bump maxVersion to 8.0a1

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
 * ***** END LICENSE BLOCK ***** */
36
36
 
37
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) {
46
 
  }
47
 
 
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
 
}
 
38
//Components.utils.import("resource://ubufox/uAddonInstaller.jsm");
 
39
Components.utils.import("resource://ubufox/UpdateRestartNotifier.jsm");
 
40
 
 
41
(function() {
 
42
  var UpdateRestartListener = {
 
43
    updated: false,
 
44
    restartNotificationLabel: null,
 
45
    restartNotificationButton: null,
 
46
    restartNotificationKey: null,
 
47
    buttons: null,
 
48
 
 
49
    init: function URL_init() {
 
50
      let bundle = document.getElementById("ubufox-restart-strings");
 
51
      this.restartNotificationLabel = bundle.getString("restartNotificationLabel");
 
52
      this.restartNotificationButton = bundle.getString("restartNotificationButton");
 
53
      this.restartNotificationKey = bundle.getString("restartNotificationKey");
 
54
      this.buttons = [{ label: this.restartNotificationButton,
 
55
                        accessKey: this.restartNotificationKey,
 
56
                        callback: UpdateRestartNotifier.restart }];
 
57
    },
 
58
 
 
59
    addNotificationToBrowser: function URL_addNotificationToBrowser(browser) {
 
60
      let notificationBox = gBrowser.getNotificationBox(browser);
 
61
      let notification = notificationBox
 
62
                         .getNotificationWithValue("notification-restart");
 
63
      if (!notification) {
 
64
        notificationBox.appendNotification(this.restartNotificationLabel,
 
65
                                           "notification-restart", "",
 
66
                                           notificationBox.PRIORITY_WARNING_LOW,
 
67
                                           this.buttons);
 
68
      }
 
69
    },
 
70
 
 
71
    onUpdatedNotify: function URL_onUpdatedNotify() {
 
72
      if (this.updated)
 
73
        throw "onUpdatedNotify called more than once";
 
74
 
 
75
      this.updated = true;
 
76
      this.init();
 
77
 
 
78
      gBrowser.browsers.forEach(function(browser) {
 
79
        UpdateRestartListener.addNotificationToBrowser(browser);
 
80
      });
 
81
 
 
82
      gBrowser.tabContainer.addEventListener("TabOpen", function(aEvent) {
 
83
        UpdateRestartListener.addNotificationToBrowser(gBrowser
 
84
                                                       .getBrowserForTab(aEvent.target));
 
85
      }, false);
 
86
    },
 
87
 
 
88
    onUpdatedReminder: function URL_onUpdatedReminder() {
 
89
      gBrowser.browsers.forEach(function(browser) {
 
90
        UpdateRestartListener.addNotificationToBrowser(browser);
 
91
      });
 
92
    }
 
93
  };
 
94
 
 
95
  addEventListener("load", function() {
 
96
    removeEventListener("load", arguments.callee, false);
 
97
    UpdateRestartNotifier.addListener(UpdateRestartListener);
 
98
  }, false);
 
99
 
 
100
  addEventListener("unload", function() {
 
101
    removeEventListener("unload", arguments.callee, false);
 
102
    // Don't remove this call, ever. Without this we will leak the
 
103
    // document as it is in the scope of the callback, which
 
104
    // UpdateRestartNotifier is holding on to
 
105
    UpdateRestartNotifier.removeListener(UpdateRestartListener);
 
106
  }, false);
 
107
})();
 
108
 
 
109
if (!com) var com = {};
 
110
if (!com.ubuntu) com.ubuntu = {};
 
111
 
 
112
(function() {
 
113
  const Ci = Components.interfaces;
 
114
  const Cc = Components.classes;
 
115
 
 
116
  this.Ubufox = {
 
117
    openPluginFinder: function() {
 
118
      let contentMimeArray = {};
 
119
      let pluginsOnTab = false;
 
120
      let elements = gBrowser.selectedBrowser.contentDocument
 
121
                                             .getElementsByTagName("embed");
 
122
      for (let a = 0; a < elements.length; a++) {
 
123
        let element = elements[a];
 
124
        let pluginInfo = getPluginInfo(element);
 
125
        contentMimeArray[pluginInfo.mimetype] = pluginInfo;
 
126
        pluginsOnTab = true;
 
127
      }
 
128
      window.openDialog("chrome://ubufox/content/pluginAlternativeOverlay.xul",
 
129
                       "PFSWindow", "chrome,centerscreen,resizable=yes",
 
130
                       {plugins: contentMimeArray,
 
131
                        browser: gBrowser.selectedBrowser,
 
132
                        pluginsOnTab: pluginsOnTab});
 
133
    },
 
134
 
 
135
    reportBug: function() {
 
136
      let executable = Cc["@mozilla.org/file/local;1"]
 
137
                          .createInstance(Ci.nsILocalFile);
 
138
 
 
139
      executable.initWithPath("/usr/bin/ubuntu-bug");
 
140
 
 
141
      if(!executable.exists () || !executable.isExecutable())
 
142
        alert('Unexpected error!');
 
143
 
 
144
      let procUtil = Cc["@mozilla.org/process/util;1"]
 
145
                        .createInstance(Ci.nsIProcess);
 
146
 
 
147
      procUtil.init(executable);
 
148
 
 
149
      let args = null;
 
150
      args = new Array("-p", firefox);
 
151
 
 
152
      procUtil.run(false, args, args.length);
 
153
    },
 
154
 
 
155
    help: function() {
 
156
      let codename = Services.prefs.getCharPref("extensions.ubufox@ubuntu.com.codename");
 
157
      let url = "https://launchpad.net/distros/ubuntu/" + codename + "/+sources/firefox/+gethelp";
 
158
      openUILinkIn(url, "tab");
 
159
    },
 
160
 
 
161
    translate: function() {
 
162
      let codename = Services.prefs.getCharPref("extensions.ubufox@ubuntu.com.codename");
 
163
      let url = "https://launchpad.net/distros/ubuntu/" +
 
164
                codename + "/+sources/firefox/+translate";
 
165
      openUILinkIn(url, "tab");
 
166
    },
 
167
  };
 
168
 
 
169
  window.addEventListener("load", function() {
 
170
    window.removeEventListener("load", arguments.callee, false);
 
171
    let item = document.getElementById("ubufox-helptranslate");
 
172
    item.hidden = true;
 
173
  }, false);
 
174
}).call(com.ubuntu);