/
firebug.js
2556 lines (2133 loc) · 74.5 KB
/
firebug.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* See license.txt for terms of usage */
/**
* Firebug module can depend only on modules that don't use the 'Firebug' namespace.
* So, be careful before you create a new dependency.
*/
define([
"firebug/lib/lib",
"firebug/lib/object",
"firebug/firefox/firefox",
"firebug/chrome/chrome",
"firebug/lib/domplate",
"firebug/lib/options",
"firebug/lib/locale",
"firebug/lib/events",
"firebug/lib/wrapper",
"firebug/lib/url",
"firebug/lib/css",
"firebug/firefox/window",
"firebug/lib/string",
"firebug/lib/array",
"firebug/lib/dom",
"firebug/net/httpLib",
],
function(FBL, Obj, Firefox, ChromeFactory, Domplate, Options, Locale, Events,
Wrapper, Url, Css, Win, Str, Arr, Dom, Http) {
// ********************************************************************************************* //
// Constants
const Cc = Components.classes;
const Ci = Components.interfaces;
const nsISupports = Ci.nsISupports;
const observerService = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
const categoryManager = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager);
const promptService = Cc["@mozilla.org/embedcomp/prompt-service;1"].getService(Ci.nsIPromptService);
const versionURL = "chrome://firebug/content/branch.properties";
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
const firebugURLs = // TODO chrome.js
{
main: "http://www.getfirebug.com",
FAQ: "http://getfirebug.com/wiki/index.php/FAQ",
docs: "http://www.getfirebug.com/docs.html",
keyboard: "http://getfirebug.com/wiki/index.php/Keyboard_and_Mouse_Shortcuts",
discuss: "http://groups.google.com/group/firebug",
issues: "http://code.google.com/p/fbug/issues/list",
donate: "http://getfirebug.com/getinvolved",
issue5110: "http://code.google.com/p/fbug/issues/detail?id=5110"
};
const scriptBlockSize = 20;
const PLACEMENT_NONE = 0;
const PLACEMENT_INBROWSER = 1;
const PLACEMENT_DETACHED = 2;
const PLACEMENT_MINIMIZED = 3;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
var modules = [];
var activeContexts = [];
var activableModules = [];
var panelTypes = [];
var earlyRegPanelTypes = []; // See Firebug.registerPanelType for more info
var reps = [];
var defaultRep = null;
var defaultFuncRep = null;
var menuItemControllers = [];
var panelTypeMap = {};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
try
{
// Register default Firebug string bundle (yet before domplate templates).
Locale.registerStringBundle("chrome://firebug/locale/firebug.properties");
}
catch (exc)
{
dump("Register default string bundle FAILS: "+exc+"\n");
}
// ********************************************************************************************* //
if (window.Firebug)
{
// Stow the pre-load properties, add them back at the end
var PreFirebug = {};
var preFirebugKeys = Object.keys(Firebug);
preFirebugKeys.forEach(function copyProps(key)
{
PreFirebug[key] = Firebug[key];
});
}
/**
* @class Represents the main Firebug application object. An instance of this object is
* created for each browser window (browser.xul).
*/
window.Firebug =
{
version: "1.10",
dispatchName: "Firebug",
modules: modules,
panelTypes: panelTypes,
earlyRegPanelTypes: earlyRegPanelTypes,
uiListeners: [],
reps: reps,
stringCropLength: 50,
isInitialized: false,
migrations: {},
// Custom stylesheets registered by extensions.
stylesheets: [],
// xxxHonza: hack, all "Firebug.Options" occurences should be replaced by "Options"
Options: Options,
viewChrome: null,
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Initialization
initialize: function(chrome)
{
// This says how much time was necessary to load Firebug overlay (+ all script tags).
FBTrace.timeEnd("SCRIPTTAG_TIME");
// Measure the entire Firebug initialiation time.
FBTrace.time("INITIALIZATION_TIME");
Firebug.chrome = chrome;
Firebug.originalChrome = Firebug.chrome;
if (FBTrace.sysout && (!FBL || !FBL.initialize))
{
FBTrace.sysout("Firebug is broken, FBL incomplete, if the last function is QI, " +
"check lib.js:", FBL);
}
else if (FBTrace.DBG_INITIALIZE)
{
FBTrace.sysout("firebug.initialize FBL: " + FBL);
}
if (window.FBL.legacyApiPatch)
window.FBL.legacyApiPatch(FBL, this, Firefox);
// Till now all registered panels have been inserted into earlyRegPanelTypes.
var tempPanelTypes = earlyRegPanelTypes;
earlyRegPanelTypes = null;
Firebug.completeInitialize(tempPanelTypes);
},
completeInitialize: function(tempPanelTypes)
{
if (FBL)
FBL.initialize(); // non require.js modules
// Append early registered panels at the end.
panelTypes.push.apply(panelTypes, tempPanelTypes);
Firebug.Options.addListener(this);
this.isInitialized = true;
Events.dispatch(modules, "initialize", []);
// This is the final of Firebug initialization.
FBTrace.timeEnd("INITIALIZATION_TIME");
},
sendLoadEvent: function()
{
var event = document.createEvent("Events");
event.initEvent("FirebugLoaded", true, false);
// Send to the current window/scope (firebugFrame.xul)
window.document.dispatchEvent(event);
// Send to the top window/scope (browser.xul)
if (top != window)
top.document.dispatchEvent(event);
},
getVersion: function()
{
if (!this.fullVersion)
this.fullVersion = this.loadVersion(versionURL);
return this.fullVersion;
},
loadVersion: function(versionURL)
{
var content = Http.getResource(versionURL);
if (!content)
return "no content at "+versionURL;
var m = /RELEASE=(.*)/.exec(content);
if (m)
var release = m[1];
else
return "no RELEASE in "+versionURL;
m = /VERSION=(.*)/.exec(content);
if (m)
var version = m[1];
else
return "no VERSION in "+versionURL;
return version+""+release;
},
/**
* Substitute strings in the UI, with fall back to en-US
*/
internationalizeUI: function(doc) // TODO chrome.js
{
if (!doc)
return;
if (FBTrace.DBG_INITIALIZE)
FBTrace.sysout("Firebug.internationalizeUI");
var elements = doc.getElementsByClassName("fbInternational");
elements = Arr.cloneArray(elements);
var attributes = ["label", "tooltiptext", "aria-label"];
for (var i=0; i<elements.length; i++)
{
var element = elements[i];
Css.removeClass(elements[i], "fbInternational");
for (var j=0; j<attributes.length; j++)
{
if (element.hasAttribute(attributes[j]))
Locale.internationalize(element, attributes[j]);
}
}
// Allow other modules to internationalize UI labels (called also for
// detached Firebug window).
Events.dispatch(modules, "internationalizeUI", [doc]);
},
/**
* Called when the UI is ready to be initialized, once the panel browsers are loaded,
* but before any contexts are created.
*/
initializeUI: function(detachArgs)
{
if (FBTrace.DBG_INITIALIZE)
FBTrace.sysout("firebug.initializeUI detachArgs:", detachArgs);
Events.dispatch(menuItemControllers, "initialize", []); // TODO chrome.js
// In the case that the user opens firebug in a new window but then closes Firefox
// window, we don't get the quitApplicationGranted event (platform is still running)
// and we call shutdown (Firebug isDetached).
window.addEventListener('unload', shutdownFirebug, false);
// Initial activation of registered panel types. All panel -> module dependencies
// should be defined now (in onActivationChange). Must be called after
// Firebug.TabWatcher is ready.
if (Firebug.PanelActivation)
Firebug.PanelActivation.activatePanelTypes(panelTypes);
// Tell the modules the UI is up.
Events.dispatch(modules, "initializeUI", [detachArgs]);
},
/**
* called in browser when Firefox closes and in externalMode when fbs gets
* quitApplicationGranted.
*/
shutdown: function()
{
if (this.isShutdown)
return;
this.shutdownUI();
Events.dispatch(modules, "shutdown");
this.Options.shutdown();
this.Options.removeListener(this);
this.connection.disconnect();
this.PanelActivation.deactivatePanelTypes(panelTypes);
// Shutdown all registered extensions.
this.unregisterExtensions();
if (FBTrace.DBG_OBSERVERS)
{
// import fbObserverService
Components.utils.import("resource://firebug/observer-service.js");
fbObserverService.traceStacksForTrack();
}
this.isShutdown = true;
if (FBTrace.DBG_INITIALIZE)
FBTrace.sysout("firebug.shutdown exited ");
},
shutdownUI: function() // TODO chrome.js
{
window.removeEventListener('unload', shutdownFirebug, false);
Events.dispatch(modules, "disable", [Firebug.chrome]);
},
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// TODO this entire section to XULWindow
// TODO XULWindow
getSuspended: function()
{
return Firebug.StartButton.getSuspended();
},
// TODO XULWindow
setSuspended: function(value)
{
Firebug.StartButton.setSuspended(value);
},
// TODO XULWindow IN detached "Activate Firebug for the current website"
toggleSuspend: function()
{
// getSuspended returns non-null value if Firebug is suspended.
if (this.getSuspended() || this.isDetached())
{
// Firebug is suspended now. Two possible actions have been executed:
// 1) Firebug UI is closed and the user clicked on the status bar icon in order to
// show the UI and resume Firebug.
// 2) Firebug is detached, but suspended for the current page. The user clicked
// either on the status bar icon or on an activation button that is displayed
// within detached Firebug window.
this.toggleBar(true);
}
else
{
// The users wants to suspend Firebug, let's do it and pull down the visible UI.
// xxxHonza: the Firebug isn't suspended if detached and the user clicks on the
// status bar icon (the detached window should becoma blank displaying only
// the activation button).
this.suspend();
// Close detached Firebug or
// show/hide Firebug UI according to the browser.showFirebug flag.
if (Firebug.isDetached())
this.toggleDetachBar(false);
else
this.syncBar();
}
},
// dispatch suspendFirebug to all windows
suspend: function()
{
if(Firebug.rerun)
return;
Firebug.suspendFirebug();
},
// dispatch onSuspendFirebug to all modules
suspendFirebug: function()
{
var cancelSuspend = Events.dispatch2(activableModules, "onSuspendingFirebug", []);
if (cancelSuspend)
return;
this.setSuspended("suspending");
// TODO no context arg
var cancelSuspend = Events.dispatch2(activableModules, "onSuspendFirebug",
[Firebug.currentContext]);
if (cancelSuspend)
Firebug.resume();
else
this.setSuspended("suspended");
},
resume: function()
{
Firebug.resumeFirebug();
},
resumeFirebug: function() // dispatch onResumeFirebug to all modules
{
this.setSuspended("resuming");
// TODO no context arg
Events.dispatch(activableModules, 'onResumeFirebug', [Firebug.currentContext]);
this.setSuspended(null);
},
getURLsForAllActiveContexts: function()
{
var contextURLSet = [];
// create a list of all unique activeContexts
Firebug.connection.eachContext( function createActiveContextList(context)
{
if (FBTrace.DBG_WINDOWS)
FBTrace.sysout("context "+context.getName());
try
{
var cw = context.window;
if (cw)
{
if (cw.closed)
url = "about:closed";
else
if ('location' in cw)
var url = cw.location.toString();
else
var url = context.getName();
if (url)
{
if (contextURLSet.indexOf(url) == -1)
contextURLSet.push(url);
}
}
}
catch(e)
{
if (FBTrace.DBG_ERRORS)
FBTrace.sysout("firebug.getURLsForAllActiveContexts could not get " +
"window.location for a context", e);
}
});
if (FBTrace.DBG_ACTIVATION)
FBTrace.sysout("active contexts urls " + contextURLSet.length);
return contextURLSet;
},
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Registration
/**
* Set a default value for a preference into the firebug preferences list.
*
* @param name preference name, possibly dot segmented, will be stored under
* extensions.firebug.<name>
* @param value default value of preference
* @return true if default set, else false
*/
registerPreference: function(name, value)
{
Firebug.Options.register(name, value);
},
registerModule: function()
{
modules.push.apply(modules, arguments);
if (FBTrace.DBG_REGISTRATION)
{
for (var i = 0; i < arguments.length; ++i)
FBTrace.sysout("registerModule "+arguments[i].dispatchName);
}
},
unregisterModule: function()
{
for (var i = 0; i < arguments.length; ++i)
Arr.remove(modules, arguments[i]);
},
registerActivableModule: function()
{
activableModules.push.apply(activableModules, arguments);
this.registerModule.apply(this, arguments);
},
registerUIListener: function()
{
for (var j = 0; j < arguments.length; j++)
Firebug.uiListeners.push(arguments[j]);
},
unregisterUIListener: function()
{
for (var i = 0; i < arguments.length; ++i)
Arr.remove(Firebug.uiListeners, arguments[i]);
},
registerPanel: function()
{
// In order to keep built in panels (like Console, Script...) be the first one
// and insert all panels coming from extension at the end, catch any early registered
// panel (i.e. before FBL.initialize is called, such as YSlow) in a temp array
// that is appended at the end as soon as FBL.initialize is called.
if (earlyRegPanelTypes)
earlyRegPanelTypes.push.apply(earlyRegPanelTypes, arguments);
else
panelTypes.push.apply(panelTypes, arguments);
for (var i = 0; i < arguments.length; ++i)
panelTypeMap[arguments[i].prototype.name] = arguments[i];
if (FBTrace.DBG_REGISTRATION)
for (var i = 0; i < arguments.length; ++i)
FBTrace.sysout("registerPanel "+arguments[i].prototype.name+"\n");
},
unregisterPanel: function(panelType)
{
for (var i = 0; i < panelTypes.length; ++i)
{
if (panelTypes[i] == panelType)
{
panelTypes.splice(i, 1);
break;
}
}
delete panelTypeMap[panelType.prototype.name];
},
registerRep: function()
{
reps.push.apply(reps, arguments);
},
unregisterRep: function()
{
for (var i = 0; i < arguments.length; ++i)
Arr.remove(reps, arguments[i]);
},
setDefaultReps: function(funcRep, rep)
{
defaultRep = rep;
defaultFuncRep = funcRep;
},
registerStringBundle: function(bundleURI)
{
Locale.registerStringBundle(bundleURI);
},
/**
* Allows registering of custom stylesheet coming from extension. The stylesheet is then
* used automatially thorough Firebug UI.
* @param {Object} styleURI URI of the stylesheet.
*/
registerStylesheet: function(styleURI)
{
this.stylesheets.push(styleURI);
if (FBTrace.DBG_REGISTRATION)
FBTrace.sysout("registerStylesheet " + styleURI);
},
registerMenuItem: function(menuItemController)
{
FBTrace.sysout("Firebug.registerMenuItem");
menuItemControllers.push(menuItemController);
},
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Options
getPref: function()
{
// TODO deprecated
return Options.getPref.apply(Firebug.Options, arguments);
},
setPref: function()
{
// TODO deprecated
return Options.setPref.apply(Firebug.Options, arguments);
},
clearPref: function()
{
// TODO deprecated
return Options.clearPref.apply(Options, arguments);
},
prefDomain: "extensions.firebug",
updateOption: function(name, value)
{
// fbtest changes options which change prefs which trigger updates in fbtrace
if (!Firebug.chrome)
return;
// Distribute to the current chrome.
Firebug.chrome.updateOption(name, value);
// If Firebug is detached distribute also into the in-browser chrome.
if (Firebug.chrome != Firebug.originalChrome)
Firebug.originalChrome.updateOption(name, value);
Events.dispatch(Firebug.modules, "updateOption", [name, value]);
},
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
shouldIgnore: function(objectChromeView)
{
if (objectChromeView)
{
var contentView = Wrapper.unwrapObject(objectChromeView);
return (contentView && contentView.firebugIgnore);
}
// else don't ignore things we don't understand
},
setIgnored: function(objectChromeView)
{
if (objectChromeView)
{
var contentView = Wrapper.unwrapObject(objectChromeView);
if (contentView)
contentView.firebugIgnore = true;
}
},
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Browser Bottom Bar
// TODO XULWindow
showBar: function(show)
{
var browser = Firefox.getCurrentBrowser();
if (FBTrace.DBG_WINDOWS || FBTrace.DBG_ACTIVATION)
FBTrace.sysout("showBar("+show+") for browser "+browser.currentURI.spec+
" Firebug.currentContext "+Firebug.currentContext);
Firebug.chrome.toggleOpen(show);
if(!show)
Firebug.Inspector.inspectNode(null);
//xxxHonza: should be removed.
Events.dispatch(Firebug.uiListeners, show ? "showUI" : "hideUI",
[browser, Firebug.currentContext]);
// Sync panel state after the showUI event is dispatched. syncPanel method calls
// Panel.show method, which expects the active context to be already registered.
if (show)
Firebug.chrome.syncPanel();
else
Firebug.chrome.selectPanel(); // select null causes hide() on selected
Firebug.StartButton.resetTooltip();
},
closeFirebug: function(userCommands) // this is really deactivate
{
if (!Firebug.currentContext)
return;
// It looks like FBTest is calling Firebug.Activation.clearAnnotations()
// when there is no current context.
//throw new Error("closeFirebug ERROR: no Firebug.currentContext ");
Firebug.connection.closeContext(Firebug.currentContext, userCommands);
Firebug.StartButton.resetTooltip();
},
/**
* Primary function to activate or minimize firebug. Used by
* <ol>
* <li>the status bar icon click action</li>
* <li>the activation button (within Firebug.xul) click action</li>
* </ol>
* @param forceOpen: don't minimize, stay open if open.
* @param panelName: eg 'script', to select a specific panel.
*/
toggleBar: function(forceOpen, panelName)
{
if (panelName)
Firebug.chrome.selectPanel(panelName);
var webApp = Firebug.connection.getCurrentSelectedWebApp();
var context = Firebug.connection.getContextByWebApp(webApp);
if (!context) // then we are not debugging the selected tab
{
context = Firebug.connection.getOrCreateContextByWebApp(webApp);
forceOpen = true; // Be sure the UI is open for a newly created context
}
else // we were debugging
{
}
if (Firebug.isDetached()) // if we are out of the browser focus the window
Firebug.chrome.focus();
else if (Firebug.framePosition == "detached")
this.detachBar();
else if (Firebug.isMinimized()) // toggle minimize
Firebug.unMinimize();
else if (!forceOpen) // else isInBrowser
Firebug.minimizeBar();
return true;
},
/**
* Primary function to re-show firebug due to visiting active site.
* Unlike toggleBar, we are trying to obey the current placement, not change it.
*/
showContext: function(browser, context)
{
// user wants detached but we are not yet
if (Firebug.framePosition == "detached" && !Firebug.isDetached())
{
if (context && !Firebug.isMinimized()) // don't detach if it's minimized 2067
this.detachBar(); // the placement will be set once the external window opens
else // just make sure we are not showing
this.showBar(false);
}
else if (Firebug.openMinimized() && !Firebug.isMinimized())
this.minimizeBar();
else if (Firebug.isMinimized())
this.showBar(false); // don't show, we are minimized
else if (Firebug.isDetached())
Firebug.chrome.syncResumeBox(context);
else // inBrowser
this.showBar(context?true:false);
},
minimizeBar: function() // just pull down the UI, but don't deactivate the context
{
if (Firebug.isDetached()) // TODO disable minimize on externalMode
{
// TODO reattach
Firebug.toggleDetachBar(false, false);
Firebug.chrome.focus();
}
else // inBrowser -> minimized
{
Firebug.setPlacement("minimized");
this.showBar(false);
}
},
unMinimize: function()
{
Firebug.setPlacement("inBrowser");
Firebug.showBar(true);
},
onShowDetachTooltip: function(tooltip)
{
tooltip.label = Firebug.isDetached() ? Locale.$STR("firebug.AttachFirebug") :
Locale.$STR("firebug.DetachFirebug");
return true;
},
// detached -> closed; inBrowser -> detached TODO reattach
toggleDetachBar: function(forceOpen, reopenInBrowser)
{
if (!forceOpen && Firebug.isDetached()) // detached -> minimized
{
var topWin = Firebug.chrome.window.top;
topWin.exportFirebug();
topWin.close();
if (reopenInBrowser)
Firebug.unMinimize();
else
Firebug.minimizeBar();
Firebug.chrome.syncPositionPref();
}
else
{
this.detachBar();
}
},
closeDetachedWindow: function(userCommands)
{
Firebug.showBar(false);
if (Firebug.currentContext)
ToolInterface.browser.closeContext(Firebug.currentContext, userCommands);
// else the user closed Firebug external window while not looking at
// a debugged web page.
Firebug.StartButton.resetTooltip();
},
detachBar: function()
{
if (Firebug.isDetached()) // can be set true attachBrowser
{
Firebug.chrome.focus();
return null;
}
if(Firebug.chrome.waitingForDetach)
return null;
Firebug.chrome.waitingForDetach = true;
Firebug.chrome.toggleOpen(false); // don't show in browser.xul now
if (FBTrace.DBG_ACTIVATION)
{
FBTrace.sysout("Firebug.detachBar opening firebug.xul for context " +
Firebug.currentContext.getName() );
}
Firebug.chrome.syncPositionPref("detached");
return Firefox.openWindow("Firebug",
"chrome://firebug/content/firefox/firebug.xul",
"", {});
},
// show firebug if we should
syncBar: function()
{
var browser = Firefox.getCurrentBrowser();
// implicitly this is operating in the chrome of browser.xul
this.showBar(browser && browser.showFirebug);
},
toggleCommandLine: function(showCommandEditor)
{
Options.set("commandEditor", showCommandEditor);
},
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// deprecated
resetAllOptions: function(confirm)
{
if (confirm)
{
var promptService = Cc["@mozilla.org/embedcomp/prompt-service;1"].
getService(Ci.nsIPromptService);
// Do not reset options if the user changed its mind.
if (!promptService.confirm(null, Locale.$STR("Firebug"),
Locale.$STR("confirmation.Reset_All_Firebug_Options")))
{
return;
}
}
// Dispatch to non-module objects.
Options.resetAllOptions(confirm);
// Dispatch to all modules so, additional settings can be reset.
Events.dispatch(modules, "resetAllOptions", []);
},
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Panels
getPanelType: function(panelName)
{
if (panelTypeMap.hasOwnProperty(panelName))
return panelTypeMap[panelName];
else
return null;
},
getPanelTitle: function(panelType)
{
return panelType.prototype.title ? panelType.prototype.title
: Locale.$STR("Panel-"+panelType.prototype.name);
},
getPanelTooltip: function(panelType)
{
return panelType.prototype.tooltip ? panelType.prototype.tooltip
: this.getPanelTitle(panelType);
},
getMainPanelTypes: function(context)
{
var resultTypes = [];
for (var i = 0; i < panelTypes.length; ++i)
{
var panelType = panelTypes[i];
if (!panelType.prototype.parentPanel)
resultTypes.push(panelType);
}
if (context.panelTypes)
{
for (var i = 0; i < context.panelTypes.length; ++i)
{
var panelType = context.panelTypes[i];
if (!panelType.prototype.parentPanel)
resultTypes.push(panelType);
}
}
resultTypes.sort(function(a, b)
{
return a.prototype.order < b.prototype.order ? -1 : 1;
});
return resultTypes;
},
getSidePanelTypes: function(context, mainPanel)
{
if (!mainPanel)
return [];
var resultTypes = [];
for (var i = 0; i < panelTypes.length; ++i)
{
var panelType = panelTypes[i];
if (panelType.prototype.parentPanel &&
(panelType.prototype.parentPanel == mainPanel.name))
{
resultTypes.push(panelType);
}
}
if (context.panelTypes)
{
for (var i = 0; i < context.panelTypes.length; ++i)
{
var panelType = context.panelTypes[i];
if (panelType.prototype.parentPanel == mainPanel.name)
resultTypes.push(panelType);
}
}
resultTypes.sort(function(a, b)
{
return a.prototype.order < b.prototype.order ? -1 : 1;
});
return resultTypes;
},
/**
* Gets an object containing the state of the panel from the last time
* it was displayed before one or more page reloads.
* The 'null' return here is a too-subtle signal to the panel code in bindings.xml.
* Note that panel.context may not have a persistedState, but in addition the persisted
* state for panel.name may be null.
*/
getPanelState: function(panel)
{
var persistedState = panel.context.persistedState;
if (!persistedState || !persistedState.panelState)
return null;
return persistedState.panelState[panel.name];
},
showPanel: function(browser, panel)
{
// The panel may be null
Events.dispatch(modules, "showPanel", [browser, panel]);
},
showSidePanel: function(browser, sidePanel)
{
Events.dispatch(modules, "showSidePanel", [browser, sidePanel]);
},
eachPanel: function(callback)
{
Firebug.connection.eachContext(function iteratePanels(context)
{
var rc = context.eachPanelInContext(callback);
if (rc)
return rc;
});
},
dispatchToPanels: function(fName, args)
{
Firebug.eachPanel( function dispatchToPanel(panel)
{