xpInstallHat.js
Go to the documentation of this file.
1 /*
2 //
3 // BEGIN SONGBIRD GPL
4 //
5 // This file is part of the Songbird web player.
6 //
7 // Copyright(c) 2005-2008 POTI, Inc.
8 // http://songbirdnest.com
9 //
10 // This file may be licensed under the terms of of the
11 // GNU General Public License Version 2 (the "GPL").
12 //
13 // Software distributed under the License is distributed
14 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
15 // express or implied. See the GPL for the specific language
16 // governing rights and limitations.
17 //
18 // You should have received a copy of the GPL along with this
19 // program. If not, go to http://www.gnu.org/licenses/gpl.html
20 // or write to the Free Software Foundation, Inc.,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 //
23 // END SONGBIRD GPL
24 //
25  */
26 
27 //
28 // Callback for XPInstall denied notification
29 //
30 
31 (function(){
32  const Cc = Components.classes;
33  const Ci = Components.interfaces;
34 
35  var bundleSvc = Cc["@mozilla.org/intl/stringbundle;1"]
36  .getService(Ci.nsIStringBundleService);
37  var brandBundle = bundleSvc.createBundle("chrome://branding/locale/brand.properties");
38  var browserBundle = bundleSvc.createBundle("chrome://browser/locale/browser.properties");
39 
40  var prefSvc = Cc["@mozilla.org/preferences-service;1"]
41  .getService(Ci.nsIPrefBranch);
42 
44  observe: function(aSubject, aTopic, aData) {
45  switch(aTopic) {
46  case "xpinstall-install-blocked":
47  // see browser.js gXPInstallObserver
48  var installInfo = aSubject.QueryInterface(Ci.nsIXPIInstallInfo);
49  var win = installInfo.originatingWindow;
50  var shell = win.QueryInterface(Ci.nsIInterfaceRequestor)
51  .getInterface(Ci.nsIWebNavigation)
52  .QueryInterface(Ci.nsIDocShell);
53  var host = installInfo.originatingURI.host;
54  var brandShortName = brandBundle.GetStringFromName("brandShortName");
55  var notificationName, messageString, buttons;
56  if (!prefSvc.getBoolPref("xpinstall.enabled")) {
57  notificationName = "xpinstall-disabled"
58  if (prefSvc.prefIsLocked("xpinstall.enabled")) {
59  messageString = browserBundle.GetStringFromName("xpinstallDisabledMessageLocked");
60  buttons = [];
61  }
62  else {
63  messageString = browserBundle.formatStringFromName("xpinstallDisabledMessage",
64  [brandShortName, host], 2);
65 
66  buttons = [{
67  label: browserBundle.GetStringFromName("xpinstallDisabledButton"),
68  accessKey: browserBundle.GetStringFromName("xpinstallDisabledButton.accesskey"),
69  popup: null,
70  callback: function editPrefs() {
71  prefSvc.setBoolPref("xpinstall.enabled", true);
72  return false;
73  }
74  }];
75  }
76  }
77  else {
78  notificationName = "xpinstall"
79  messageString = browserBundle.formatStringFromName("xpinstallPromptWarning",
80  [brandShortName, host], 2);
81 
82  buttons = [{
83  label: browserBundle.GetStringFromName("xpinstallPromptAllowButton"),
84  accessKey: browserBundle.GetStringFromName("xpinstallPromptAllowButton.accesskey"),
85  popup: null,
86  callback: function() {
87  var mgr = Components.classes["@mozilla.org/xpinstall/install-manager;1"]
88  .createInstance(Components.interfaces.nsIXPInstallManager);
89  mgr.initManagerWithInstallInfo(installInfo);
90  return false;
91  }
92  }];
93  }
94 
95  const iconURL = "chrome://songbird/skin/base-elements/icon-generic-addon.png";
96  // this is just a random notification box so we can get a priority
97  var notificationBox = gBrowser.getNotificationBox(gBrowser.getBrowserAtIndex(0));
98  const priority = notificationBox.PRIORITY_WARNING_MEDIUM;
99  gBrowser.showNotification(shell, notificationName, messageString,
100  iconURL, priority, buttons);
101  break;
102  }
103  },
104  handleEvent: function() {
105  os.removeObserver(xpinstallObserver, "xpinstall-install-blocked");
106  removeEventListener("unload", xpinstallObserver, false);
107  }
108  }
109 
110  addEventListener("unload", xpinstallObserver, false);
111  var os = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
112  os.addObserver(xpinstallObserver, "xpinstall-install-blocked", false);
113 })();
var os
const Cc
var prefSvc
Definition: xpInstallHat.js:40
var xpinstallObserver
Definition: xpInstallHat.js:43
handlersMenuPopup addEventListener("command", this, false)
var browserBundle
Definition: xpInstallHat.js:38
function const Ci
Definition: xpInstallHat.js:33
this _contentSandbox label
Definition: FeedWriter.js:814
var bundleSvc
Definition: xpInstallHat.js:35
grep callback
return null
Definition: FeedWriter.js:1143
this removeEventListener("load", this.__SS_restore, true)
var brandBundle
Definition: xpInstallHat.js:37
_updateTextAndScrollDataForFrame aData
sbDeviceFirmwareAutoCheckForUpdate prototype observe