overlayLoader.js
Go to the documentation of this file.
1 // JScript source code
2 /*
3 //
4 // BEGIN SONGBIRD GPL
5 //
6 // This file is part of the Songbird web player.
7 //
8 // Copyright(c) 2005-2008 POTI, Inc.
9 // http://songbirdnest.com
10 //
11 // This file may be licensed under the terms of of the
12 // GNU General Public License Version 2 (the "GPL").
13 //
14 // Software distributed under the License is distributed
15 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
16 // express or implied. See the GPL for the specific language
17 // governing rights and limitations.
18 //
19 // You should have received a copy of the GPL along with this
20 // program. If not, go to http://www.gnu.org/licenses/gpl.html
21 // or write to the Free Software Foundation, Inc.,
22 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 //
24 // END SONGBIRD GPL
25 //
26  */
27 
28 
29 
36 
37  // Flag to indicate that loadOverlayList has been called
38  // and has not yet observed the last overlay finish loading
39  loadInProgress: false,
40 
41  // Flag to indicate that the whole overlay loading is already done
42  loadCompleted: false,
43 
52  loadRuntimeOverlays: function loadRuntimeOverlays() {
53  // Get overlays that are intended for all windows
54  var overlays = this.getOverlaysForTarget("windowtype:*");
55 
56  // If this window has a windowtype attribute, then also get all overlays
57  // specifically targeting this window type
58  var windowType = document.documentElement.getAttribute("windowtype");
59  if (windowType != null && windowType != "") {
60  overlays = overlays.concat(this.getOverlaysForTarget("windowtype:" + windowType));
61  }
62 
63  // If there are overlays to load, get started
64  if (overlays.length > 0) {
65  this.loadOverlayList(overlays);
66  } else {
67  // Or send the event because there was nothing to do
68  this.sendOverlayEvent();
69  }
70  },
71 
72 
76  sendOverlayEvent: function sendOverlayEvent() {
77  var e = document.createEvent("Events");
78  e.initEvent("sb-overlay-load", false, true);
79  document.dispatchEvent(e);
80  this.loadCompleted = true;
81  },
82 
86  loadOverlayList: function loadOverlayList(overlays) {
87 
88  dump("\n\nOverlayLoader.loadOverlayList()\n\t+");
89  dump(overlays.join("\n\t+") + "\n\n");
90 
91  // Check simultaneous load flag
92  if (this.loadInProgress) {
93  dump("\n\nOverlayLoader.loadOverlayList() already in progress!");
94  return;
95  }
96  this.loadInProgress = true;
97 
98  // Disable the normal loadOverlay function while we are loading
99  // in order to avoid BMO 330458
100  document._loadOverlayInUse = document.loadOverlay;
101  document.loadOverlay = function() {
102  var caller = "unknown";
103  try {
104  caller = document.loadOverlay.caller.name;
105  } catch (e) {};
106  dump("\n\n\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
107  dump("WARNING: Someone is attempting to use document.loadOverlay while\n");
108  dump(" loadPlayerOverlays() is in progress. This cannot be allowed\n");
109  dump(" as simultaneous loadOverlay calls will clobber each other.\n");
110  dump(" For more information see Mozilla Bug 330458.\n\n");
111  dump(" Possible culprit: " + caller + "()\n");
112  dump("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n\n\n\n\n");
113  }
114 
115 
116  // Create an observer that will notice xul-overlay-merged events
117  // and load the next overlay in the list
118  var observer = {
119  observe: function ()
120  {
121  // If there are overlays in our list, load the next one
122  if (overlays.length > 0) {
123  var overlay = overlays.pop();
124  dump("\nOverlayLoader.loadPlayerOverlays() loading overlay " + overlay + "\n");
125  // Pass ourselves in as the observer, so that we will know
126  // when it is safe to load the next overlay
127  document._loadOverlayInUse(overlay, observer);
128  }
129  // Otherwise, we're finished, so restore the normal loadOverlay
130  else {
131  dump("\nOverlayLoader.loadPlayerOverlays() finished loading overlays\n");
132  document.loadOverlay = document._loadOverlayInUse;
133  OverlayLoader.loadInProgress = false;
134 
135  // Send out an event to let people know it's safe to go modal.
136  setTimeout( OverlayLoader.sendOverlayEvent, 0 );
137  }
138  }
139  }
140 
141  // If we haven't finished loading in 3 seconds, something has
142  // then gone terribly wrong. Set a timeout that will warn
143  // the user if the load does not happen. *sigh*
144  var checkCompleted = function() {
145  if (OverlayLoader.loadInProgress) {
146  Components.utils.reportError(
147  "An extension overlay has failed to load.\n\n" +
148  "Known causes include: \n" +
149  " - a malformed overlay file\n" +
150  " - an overlay which is itself the target of an overlay.\n\n" +
151  "Open the Add-Ons window and disable extensions one by one until " +
152  "you have isolated which extension is causing the problem.\n\n"+
153  "Please report this error to the extension author, or " +
154  "http://bugzilla.songbirdnest.com.");
155 
156  // Then send the event that we're done
157  OverlayLoader.sendOverlayEvent();
158  }
159  }
160  setTimeout(checkCompleted, 3000);
161 
162  // Start loading the overlays
163  observer.observe();
164  },
165 
166 
171  getOverlaysForTarget: function getOverlaysForTarget(targetURL) {
172 
173  var targetURI = Components.classes["@mozilla.org/network/io-service;1"]
174  .getService(Components.interfaces.nsIIOService)
175  .newURI(targetURL, null, null);
176 
177  var uriList = [];
178 
179  // Helper to add string URIs to our array using a given
180  // nsISimpleEnumerator of nsIURIs
181  var addURIs = function(enumerator) {
182  while (enumerator.hasMoreElements()) {
183  uriList.push( enumerator.getNext()
184  .QueryInterface(Components.interfaces.nsIURI)
185  .spec );
186  }
187  }
188 
189  // Ask the chrome registry for all overlays that should be applied to this identifier
190  var chromeRegistry = Components.classes["@mozilla.org/chrome/chrome-registry;1"]
191  .getService(Components.interfaces.nsIXULOverlayProvider);
192  addURIs(chromeRegistry.getXULOverlays(targetURI));
193  addURIs(chromeRegistry.getStyleOverlays(targetURI));
194 
195  return uriList;
196  }
197 } // End of OverlayLoader
198 
199 
200 
201 // Start pulling in the dynamic overlays as soon as the window loads
202 window.addEventListener("load", function() { OverlayLoader.loadRuntimeOverlays();}, false);
203 
204 
let window
aWindow setTimeout(function(){_this.restoreHistory(aWindow, aTabs, aTabData, aIdMap);}, 0)
return null
Definition: FeedWriter.js:1143
let observer
sbDeviceFirmwareAutoCheckForUpdate prototype observe
var OverlayLoader