5
5
// ************************************************************************************************
8
const nsIWebNavigation = CI("nsIWebNavigation");
9
const nsIWebProgressListener = CI("nsIWebProgressListener");
10
const nsIWebProgress = CI("nsIWebProgress");
11
const nsISupportsWeakReference = CI("nsISupportsWeakReference");
12
const nsISupports = CI("nsISupports");
13
const nsIURI = CI("nsIURI");
8
const Cc = Components.classes;
9
const Ci = Components.interfaces;
10
const nsIWebNavigation = Ci.nsIWebNavigation;
11
const nsIWebProgressListener = Ci.nsIWebProgressListener;
12
const nsIWebProgress = Ci.nsIWebProgress;
13
const nsISupportsWeakReference = Ci.nsISupportsWeakReference;
14
const nsISupports = Ci.nsISupports;
15
const nsIURI = Ci.nsIURI;
15
17
const NOTIFY_STATE_DOCUMENT = nsIWebProgress.NOTIFY_STATE_DOCUMENT;
106
108
watchTopWindow: function(win, uri)
110
if (FBTrace.DBG_WINDOWS) /*@explore*/
111
FBTrace.sysout("tabWatcher.watchTopWindow uri="+(typeof(uri) == nsIURI?uri.spec:uri)+"\n"); /*@explore*/
108
112
if (tabBrowser.selectedBrowser.cancelNextLoad)
110
114
// We need to cancel this load and try again after a delay... this is used
141
145
context = this.owner.createTabContext(win, browser, browser.chrome, persistedState);
142
146
contexts.push(context);
148
if (FBTrace.DBG_WINDOWS) { /*@explore*/
149
context.uid = FBL.getUniqueId(); /*@explore*/
150
FBTrace.sysout("tabWatcher created context ++++++++++++++ with id="+context.uid+" for uri="+uri+" and win.location.href="+win.location.href+"\n"); /*@explore*/
144
153
this.dispatch("initContext", [context]);
146
win.addEventListener("pagehide", onUnloadTopWindow, true);
155
win.addEventListener("pagehide", onPageHideTopWindow, true);
147
156
win.addEventListener("pageshow", onLoadWindowContent, true);
148
157
win.addEventListener("DOMContentLoaded", onLoadWindowContent, true);
158
if (FBTrace.DBG_INITIALIZE) /*@explore*/
159
FBTrace.sysout("tabWatcher.watchTopWindow pagehide, pageshow, DomContentLoaded addEventListener\n"); /*@explore*/
150
161
// XXXjjb at this point we either have context or we just pushed null into contexts and sent it to init...
154
165
context.loaded = !context.browser.webProgress.isLoadingDocument;
167
if (FBTrace.DBG_WINDOWS && context.loaded) /*@explore*/
168
FBTrace.sysout("***************> Context loaded in tabWatcher.watchTopWindow\n"); /*@explore*/
156
169
this.watchContext(win, context);
166
179
var context = this.getContextByWindow(win);
167
180
if ((context && !context.window) || (isSystem && !Firebug.allowSystemPages))
182
if (FBTrace.DBG_WINDOWS) /*@explore*/
183
FBTrace.sysout("tabWatcher.watchLoadedTopWindow bailing, context.window:"+context.window+" isSystem:"+isSystem+"\n"); /*@explore*/
169
184
this.unwatchTopWindow(win);
170
185
this.watchContext(win, null, isSystem);
189
if (FBTrace.DBG_WINDOWS) /*@explore*/
190
FBTrace.sysout("watchLoadedTopWindow context="+(context?(context.uid+" loaded="+context.loaded):'undefined')+"\n"); /*@explore*/
174
192
if (context && !context.loaded)
176
194
context.loaded = true;
195
if (FBTrace.DBG_WINDOWS) /*@explore*/
196
FBTrace.sysout("***************> Context loaded in tabWatcher.watchLoadedTopWindow\n"); /*@explore*/
177
197
this.dispatch("loadedContext", [context]);
190
210
// are called several times, so we have to avoid dispatching watchWindow
191
211
// more than once
192
212
var href = win.location.href;
214
if (FBTrace.DBG_WINDOWS) { /*@explore*/
215
FBTrace.sysout("watchWindow for href="+href+" context="+context+"\n"); /*@explore*/
216
if (context) /*@explore*/
217
for (var i = 0; i < context.windows.length; i++) /*@explore*/
218
FBTrace.sysout("watchWindow context("+context.uid+").windows["+i+"]= (" /*@explore*/
219
+context.windows[i].__firebug__uid+") "+context.windows[i].location.href+"\n"); /*@explore*/
193
222
if (context && context.windows.indexOf(win) == -1 && href != aboutBlank)
195
224
context.windows.push(win);
226
if (FBTrace.DBG_WINDOWS) /*@explore*/
227
FBTrace.sysout("watchWindow sets context for href="+href+"\n"); /*@explore*/
197
229
var eventType = (win.parent == win) ? "pagehide" : "unload";
198
230
win.addEventListener(eventType, onUnloadWindow, false);
231
if (FBTrace.DBG_INITIALIZE) FBTrace.sysout("tabWatcher.watchWindow "+eventType+" addEventListener\n"); /*@explore*/
199
232
this.dispatch("watchWindow", [context, win]);
206
239
unwatchTopWindow: function(win)
208
241
var context = this.getContextByWindow(win);
242
if (FBTrace.DBG_WINDOWS) FBTrace.dumpStack("tabWatcher.unwatchTopWindow context="+context+"\n"); /*@explore*/
209
243
this.unwatchContext(win, context);
217
251
var context = this.getContextByWindow(win);
219
253
var index = context ? context.windows.indexOf(win) : -1;
254
if (FBTrace.DBG_WINDOWS) /*@explore*/
255
FBTrace.sysout("tabWatcher.unwatchWindow context="+context+" index of win="+index+"\n"); /*@explore*/
222
258
context.windows.splice(index, 1);
223
this.dispatch("unwatchWindow", [context, win]); // XXXjjb Joe check
259
this.dispatch("unwatchWindow", [context, win]);
253
290
var browser = this.getBrowserByWindow(win);
254
this.owner.destroyTabContext(browser, null);
292
this.owner.destroyTabContext(browser, null);
293
// else we are probably exiting anyway.
258
297
var persistedState = {location: context.window.location.href};
259
context.browser.persistedState = persistedState;
298
context.browser.persistedState = persistedState; // store our state on FF browser elt
261
300
iterateWindows(context.window, function(win)
271
311
context.browser.cancelNextLoad = true;
276
context.window.removeEventListener("pagehide", onUnloadTopWindow, true);
282
314
fbs.countContext(false);
284
316
this.owner.destroyTabContext(context.browser, context);
292
324
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
294
getContextByWindow: function(win)
296
while (win && win.parent != win)
299
if (!win) // eg search bar, and sometimes win.parent is null??
326
getContextByWindow: function(winIn)
328
var rootWindow = getRootWindow(winIn);
332
for (var i = 0; i < contexts.length; ++i)
334
var context = contexts[i];
335
if (context.window == rootWindow)
340
// eg search bar, maybe a global sandbox or other non-window global
341
if (FBTrace.DBG_WINDOWS) FBTrace.sysout("TabWatcher.getContextByWindow rootWindow:"+rootWindow," trying sandboxes\n"); /*@explore*/
343
return this.getContextBySandbox(winIn);
346
getContextBySandbox: function(sandbox)
302
348
for (var i = 0; i < contexts.length; ++i)
304
350
var context = contexts[i];
305
if (context.window == win)
351
if (context.sandboxes)
353
for (var iframe = 0; iframe < context.sandboxes.length; iframe++)
355
if (context.sandboxes[iframe] == sandbox)
310
364
getBrowserByWindow: function(win)
312
366
for (var i = 0; i < tabBrowser.browsers.length; ++i)
347
401
dispatch: function(name, args)
403
if (FBTrace.DBG_WINDOWS) /*@explore*/
404
FBTrace.sysout("TabWatcher.dispatch "+name+" to "+listeners.length+" listeners\n"); /*@explore*/
349
406
for (var i = 0; i < listeners.length; ++i)
351
408
var listener = listeners[i];
352
if (name in listener)
409
if ( listener.hasOwnProperty(name) )
398
457
// Only watch windows that are their own parent - e.g. not frames
399
458
if (progress.DOMWindow.parent == progress.DOMWindow)
460
if (FBTrace.DBG_WINDOWS) /*@explore*/
461
FBTrace.sysout("TabProgressListener.onLocationChange to uri=\'" /*@explore*/
462
+(uri?uri.spec:"null location")+"\'\n"); /*@explore*/
401
464
TabWatcher.watchTopWindow(progress.DOMWindow, uri);
420
483
onStateChange: function(progress, request, flag, status)
485
if (FBTrace.DBG_WINDOWS) /*@explore*/
486
FBTrace.sysout("FrameProgressListener "+getStateDescription(flag)+" uid=" /*@explore*/
487
+progress.DOMWindow.__firebug__uid+" request.name="+safeGetName(request)+"\n"); /*@explore*/
422
488
if (flag & STATE_IS_REQUEST && flag & STATE_START)
424
490
// We need to get the hook in as soon as the new DOMWindow is created, but before
529
function onPageHideTopWindow(event)
531
var win = event.currentTarget;
532
win.removeEventListener("pagehide", onPageHideTopWindow, true);
533
// http://developer.mozilla.org/en/docs/Using_Firefox_1.5_caching#pagehide_event
534
if (event.persisted) // then the page is cached and there cannot be an unload handler
536
TabWatcher.unwatchTopWindow(win);
540
// Page is not cached, there may be an unload
541
win.addEventListener("unload", onUnloadTopWindow, true);
542
if (FBTrace.DBG_WINDOWS) /*@explore*/
543
FBTrace.sysout("tabWatcher onPageHideTopWindow set unload handler "+win.location+"\n"); /*@explore*/
461
547
function onUnloadTopWindow(event)
463
TabWatcher.unwatchTopWindow(event.currentTarget);
549
var win = event.currentTarget;
550
win.removeEventListener("unload", onUnloadTopWindow, true);
551
if (FBTrace.DBG_WINDOWS) /*@explore*/
552
FBTrace.sysout("tabWatcher onUnloadTopWindow "+win.location+"\n"); /*@explore*/
553
TabWatcher.unwatchTopWindow(win);
466
556
function onLoadWindowContent(event)
558
if (FBTrace.DBG_WINDOWS) /*@explore*/
559
FBTrace.sysout("tabWatcher.onLoadWindowContent event.type="+event.type+"\n"); /*@explore*/
468
561
var win = event.currentTarget;
471
564
win.removeEventListener("pageshow", onLoadWindowContent, true);
565
if (FBTrace.DBG_INITIALIZE) FBTrace.sysout("tabWatcher.onLoadWindowContent pageshow removeEventListener\n"); /*@explore*/
477
571
win.removeEventListener("DOMContentLoaded", onLoadWindowContent, true);
572
if (FBTrace.DBG_INITIALIZE) FBTrace.sysout("tabWatcher.onLoadWindowContent DOMContentLoaded removeEventListener\n"); /*@explore*/
504
599
var win = event.currentTarget;
505
600
var eventType = (win.parent == win) ? "pagehide" : "unload";
506
601
win.removeEventListener(eventType, onUnloadWindow, false);
602
if (FBTrace.DBG_INITIALIZE) /*@explore*/
603
FBTrace.sysout("tabWatcher.onUnloadWindow "+win.location.href +" removeEventListener: "+ eventType+"\n"); /*@explore*/
507
604
TabWatcher.unwatchWindow(win);
539
function getStateDescription(flag) {
541
if (flag & nsIWebProgressListener.STATE_START) state += "STATE_START ";
542
else if (flag & nsIWebProgressListener.STATE_REDIRECTING) state += "STATE_REDIRECTING ";
543
else if (flag & nsIWebProgressListener.STATE_TRANSFERRING) state += "STATE_TRANSFERRING ";
544
else if (flag & nsIWebProgressListener.STATE_NEGOTIATING) state += "STATE_NEGOTIATING ";
545
else if (flag & nsIWebProgressListener.STATE_STOP) state += "STATE_STOP ";
547
if (flag & nsIWebProgressListener.STATE_IS_REQUEST) state += "STATE_IS_REQUEST ";
548
if (flag & nsIWebProgressListener.STATE_IS_DOCUMENT) state += "STATE_IS_DOCUMENT ";
549
if (flag & nsIWebProgressListener.STATE_IS_NETWORK) state += "STATE_IS_NETWORK ";
550
if (flag & nsIWebProgressListener.STATE_IS_WINDOW) state += "STATE_IS_WINDOW ";
551
if (flag & nsIWebProgressListener.STATE_RESTORING) state += "STATE_RESTORING ";
552
if (flag & nsIWebProgressListener.STATE_IS_INSECURE) state += "STATE_IS_INSECURE ";
553
if (flag & nsIWebProgressListener.STATE_IS_BROKEN) state += "STATE_IS_BROKEN ";
554
if (flag & nsIWebProgressListener.STATE_IS_SECURE) state += "STATE_IS_SECURE ";
555
if (flag & nsIWebProgressListener.STATE_SECURE_HIGH) state += "STATE_SECURE_HIGH ";
556
if (flag & nsIWebProgressListener.STATE_SECURE_MED) state += "STATE_SECURE_MED ";
557
if (flag & nsIWebProgressListener.STATE_SECURE_LOW) state += "STATE_SECURE_LOW ";
562
636
// ************************************************************************************************