extensionManagerOverlay.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 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
29  const Ci = Components.interfaces;
30  const Cc = Components.classes;
31 
32  window.removeEventListener("load", songbird_extensionManager_overlay, false);
33  window.addEventListener("unload",
34  function songbird_extensionManager_unload() {
35  gExtensionsView.builder.removeListener(TemplateBuilderListener);
36  }, false);
37 
38  function fixResizers() {
39  // Resizers are broken in release mode for some reason... Worthy of further
40  // investigation. Do this for now, but remove once bug 2324 is resolved.
41  var resizersList = document.getElementsByTagName("resizer");
42  var resizerCount = resizersList.length;
43  for (var index = 0; index < resizerCount; index++) {
44  var resizer = resizersList.item(index);
45  if (resizer)
46  resizer.dir = resizer.dir;
47  }
48  }
49 
50  // RDF rebuild listener to listen for the richlistbox of addon items being
51  // built, and look through the install.rdfs and set hidden on elements as
52  // appropriate.
53  var TemplateBuilderListener = {
54  willRebuild: function(){},
55  didRebuild: function SBEMDidRebuild(aBuilder) {
56  const RDF_INSTALL_MANIFEST =
57  gRDF.GetResource("urn:mozilla:install-manifest");
58  const RDF_EM_HIDDEN =
59  gRDF.GetResource("http://www.mozilla.org/2004/em-rdf#hidden");
60  const RDF_TRUE = gRDF.GetLiteral("true");
61  var ios = Cc["@mozilla.org/network/io-service;1"]
62  .getService(Ci.nsIIOService);
63 
64  // step through the generated richlistitems (for each addon) and look at
65  // which ones should be hidden, by looking into each install.rdf
66  Array.forEach(gExtensionsView.children, function(itemElem) {
67  if (!(itemElem.hasAttribute("addonID")) ||
68  itemElem.hasAttribute("songbird_checked"))
69  {
70  // not a richlistitem about an addon, or an item we've already checked
71  return;
72  }
73  // mark this item as checked so we don't read install.rdf again (until
74  // we reload this window...)
75  itemElem.setAttribute("songbird_checked", true);
76 
77  // look for the addon install location, and check that it's in a
78  // restricted location (app-global, app-system-share)
79  var addonID = itemElem.getAttribute("addonID");
80  var installLocation = gExtensionManager.getInstallLocation(addonID);
81  if (!installLocation.restricted) {
82  // install location is not restricted, don't allow hidden addons
83  itemElem.setAttribute("restricted", false);
84  return;
85  }
86 
87  // RDF load observer in which to actually do the work, because it's
88  // likely that we never had to load install.rdf at all in this run
89  var RDFLoadObserver = {
90  onBeginLoad: function(){},
91  onInterrupt: function(){},
92  onResume: function(){},
93  onError: function(){/* nothing we can do here, ignore */},
94  onEndLoad: function(aSink) {
95  aSink.removeXMLSinkObserver(this);
96  if (rdfDS.HasAssertion(RDF_INSTALL_MANIFEST,
97  RDF_EM_HIDDEN,
98  RDF_TRUE,
99  true))
100  {
101  // we have a <em:hidden>true</em:hidden> in the <Description
102  // about="urn:mozilla:install-manifest">; hide the richlistitem
103  itemElem.setAttribute("hidden", true);
104  }
105  },
106  QueryInterface: XPCOMUtils.generateQI([Ci.nsIRDFXMLSinkObserver])
107  };
108 
109  // find the install.rdf in the installed extension, and read the
110  // datasource
111  var installRDF = installLocation.getItemFile(addonID, "install.rdf");
112  var rdfDS = gRDF.GetDataSource(ios.newFileURI(installRDF).spec)
113  .QueryInterface(Ci.nsIRDFRemoteDataSource)
114  .QueryInterface(Ci.nsIRDFXMLSink);
115  rdfDS.addXMLSinkObserver(RDFLoadObserver);
116  if (rdfDS.loaded) {
117  // the datasource has already loaded; we won't get an onEndLoad, so
118  // fire it manually to trigger the hiding
119  RDFLoadObserver.onEndLoad(rdfDS);
120  }
121  });
122  },
123  QueryInterface: XPCOMUtils.generateQI([Ci.nsIXULBuilderListener])
124  };
125 
126  fixResizers();
127 
128  // add a rebuild listener so that when the RDF-generated richlistitems get
129  // created we go and mark things hidden
130  gExtensionsView.builder.addListener(TemplateBuilderListener);
131  // force a call in case this was hooked up after the initial build
132  TemplateBuilderListener.didRebuild(gExtensionsView.builder);
133 }
134 
135 function openURL(url) {
136  var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
137  .getService(Components.interfaces.nsIWindowMediator);
138  var mainWin = wm.getMostRecentWindow("Songbird:Main");
139  if (mainWin && mainWin.window && mainWin.window.gBrowser) {
140  mainWin.window.gBrowser.loadURI(url, null, null, null, "_blank");
141  mainWin.focus();
142  return;
143  }
144 
146 }
147 
148 function openURLExternal(url) {
149  var externalLoader = (Components
150  .classes["@mozilla.org/uriloader/external-protocol-service;1"]
151  .getService(Components.interfaces.nsIExternalProtocolService));
152  var nsURI = (Components
153  .classes["@mozilla.org/network/io-service;1"]
154  .getService(Components.interfaces.nsIIOService)
155  .newURI(url, null, null));
156  externalLoader.loadURI(nsURI, null);
157 }
158 
159 window.addEventListener("load", songbird_extensionManager_overlay, false);
var gRDF
const Cc
function songbird_extensionManager_overlay()
sbOSDControlService prototype QueryInterface
let window
function openURLExternal(url)
return null
Definition: FeedWriter.js:1143
function url(spec)
if(DEBUG_DATAREMOTES)
const Ci
var ios
Definition: head_feeds.js:5
function openURL(url)