-
Notifications
You must be signed in to change notification settings - Fork 27
/
extensionOptionsPanel.uc.js
1214 lines (1131 loc) · 41 KB
/
extensionOptionsPanel.uc.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
// ==UserScript==
// @name Extension Options Panel
// @version 1.9.1
// @author aminomancer
// @homepageURL https://github.com/aminomancer/uc.css.js
// @description This script creates a toolbar button that opens a popup panel where extensions can be configured, disabled, uninstalled, etc. Each extension gets its own button in the panel. Clicking an extension's button leads to a subview where you can jump to the extension's options, disable or enable the extension, uninstall it, configure automatic updates, disable/enable it in private browsing, view its source code in whatever program is associated with `.xpi` files, open the extension's homepage, or copy the extension's ID. The panel can also be opened from the App Menu, using the built-in "Add-ons and themes" button. Since v1.8, themes will also be listed in the panel. Hovering a theme will show a tooltip with a preview/screenshot of the theme, and clicking the theme will toggle it on or off. There are several translation and configuration options directly below.
// @downloadURL https://cdn.jsdelivr.net/gh/aminomancer/uc.css.js@master/JS/extensionOptionsPanel.uc.js
// @updateURL https://cdn.jsdelivr.net/gh/aminomancer/uc.css.js@master/JS/extensionOptionsPanel.uc.js
// @license This Source Code Form is subject to the terms of the Creative Commons Attribution-NonCommercial-ShareAlike International License, v. 4.0. If a copy of the CC BY-NC-SA 4.0 was not distributed with this file, You can obtain one at http://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
// ==/UserScript==
class ExtensionOptionsWidget {
// user configuration. some of these are prefs that can be changed in
// about:config or user.js. as for the others, you can directly edit this file
// and change the value to the right of the colon.
static config = {
// this script replaces the "Add-ons & Themes" button in the app menu with
// an "Extensions" button that opens our new panel instead of opening
// about:addons. set to false if you want to leave this button alone
"Replace addons button": Services.prefs.getBoolPref(
"extensionOptionsPanel.replaceAddonsButton",
true
),
// set to false if you don't want the "Add-on options" title to be displayed
// at the top of the panel
"Show header": Services.prefs.getBoolPref(
"extensionOptionsPanel.showHeader",
true
),
// show the addon version next to its name in the list
"Show version": Services.prefs.getBoolPref(
"extensionOptionsPanel.showVersion",
false
),
// about:addons shows you when an addon has a warning or error, e.g. it's
// unsigned or blocked. if this is set to true, we'll show the same
// information in the panel
"Show addon messages": Services.prefs.getBoolPref(
"extensionOptionsPanel.showAddonMessages",
true
),
// when hovering a theme in the panel, a preview/screenshot of the theme
// will be displayed in a tooltip, if possible. this depends on the add-on
// author.
"Show theme preview tooltips": Services.prefs.getBoolPref(
"extensionOptionsPanel.showThemePreviewTooltips",
true
),
// show system extensions?
"Show hidden extensions": Services.prefs.getBoolPref(
"extensionOptionsPanel.showHiddenExtensions",
false
),
// show extensions that you've disabled?
"Show disabled extensions": Services.prefs.getBoolPref(
"extensionOptionsPanel.showDisabledExtensions",
true
),
// show enabled extensions at the top of the list and disabled extensions at
// the bottom?
"Show enabled extensions first": Services.prefs.getBoolPref(
"extensionOptionsPanel.showEnabledExtensionsFirst",
true
),
// put addon IDs in this list, separated by commas, to exclude them from the
// list, e.g. ["[email protected]", "[email protected]"]
"Addon ID blacklist": JSON.parse(
Services.prefs.getCharPref("extensionOptionsPanel.addonIDBlacklist", "[]")
),
// if you want to change the button's icon for some reason, you can replace
// this string with any URL or data URL that leads to an image.
"Icon URL": `chrome://mozapps/skin/extensions/extension.svg`,
// localization strings
l10n: {
// what should the button's label be when it's in the overflow panel or
// customization palette?
"Button label": "Add-ons and themes",
// what should the button's tooltip be? I use sentence case since that's
// the convention.
"Button tooltip": "Add-ons and themes",
// title shown at the top of the panel (when "Show header" is true)
"Panel title": "Add-ons and themes",
// label for the button that appears when you have no addons installed.
"Download addons label": "Download add-ons",
// label for the about:addons button at the bottom of the panel
"Addons page label": "Add-ons page",
// labels for the addon subview buttons
"Addon options label": "Extension options",
"Manage addon label": "Manage add-on",
"Enable addon label": "Enable",
"Disable addon label": "Disable",
"Uninstall addon label": "Uninstall",
"View source label": "View source",
"Manage shortcuts label": "Manage shortcuts",
"Open homepage label": "Open homepage",
"Copy ID label": "Copy ID",
"Automatic updates label": "Automatic updates:",
// labels for the automatic update radio buttons
autoUpdate: {
"Default label": "Default",
"On label": "On",
"Off label": "Off",
},
"Run in private windows label": "Run in private windows:",
// labels for the run in private windows radio buttons
runInPrivate: {
"Allow label": "Allow",
"Don't allow label": "Don't allow",
},
// labels for addon buttons that have a warning or error, e.g. addon
// automatically disabled because it's on a blocklist or unsigned
addonMessages: {
Blocked: "Blocked",
"Signature required": "Signature required",
Incompatible: "Incompatible",
Unverified: "Unverified",
Insecure: "Insecure",
},
},
};
/**
* create a DOM node with given parameters
* @param {object} aDoc (which doc to create the element in)
* @param {string} tag (an HTML tag name, like "button" or "p")
* @param {object} props (an object containing attribute name/value pairs,
* e.g. class: ".bookmark-item")
* @param {boolean} isHTML (if true, create an HTML element. if omitted or
* false, create a XUL element. generally avoid HTML
* when modding the UI, most UI elements are actually
* XUL elements.)
* @returns the created DOM node
*/
create(aDoc, tag, props, isHTML = false) {
let el = isHTML ? aDoc.createElement(tag) : aDoc.createXULElement(tag);
for (let prop in props) el.setAttribute(prop, props[prop]);
return el;
}
/**
* set or remove multiple attributes for a given node
* @param {object} el (a DOM node)
* @param {object} props (an object of attribute name/value pairs)
* @returns the DOM node
*/
setAttributes(el, props) {
for (let [name, value] of Object.entries(props)) {
if (value) el.setAttribute(name, value);
else el.removeAttribute(name);
}
}
/**
* make a valid ID for a DOM node based on an extension's ID.
* @param {string} id (an extension's ID)
* @returns an ID with crap removed so it can be used in a DOM node's ID.
*/
makeWidgetId(id) {
id = id.toLowerCase();
return id.replace(/[^a-z0-9_-]/g, "_");
}
/**
* for a given addon ID, get the Extension object from the addon policy
* @param {string} id (an addon's ID)
* @returns the Extension object
*/
extensionForAddonId(id) {
let policy = WebExtensionPolicy.getByID(id);
return policy && policy.extension;
}
/**
* find out if an addon has a valid signature
* @param {object} addon (an Addon object, retrieved by AddonManager.getAddonsByTypes)
* @returns true if signed, false if unsigned or invalid
*/
isCorrectlySigned(addon) {
// Add-ons without an "isCorrectlySigned" property are correctly signed as
// they aren't the correct type for signing.
return addon.isCorrectlySigned !== false;
}
/**
* find out if an addon has been automatically disabled from the xpi database
* because it lacked a valid signature and user had xpinstall.signatures.required = true
* @param {object} addon (an Addon object)
* @returns true if the addon was auto-disabled
*/
isDisabledUnsigned(addon) {
let signingRequired =
addon.type == "locale"
? this.LANGPACKS_REQUIRE_SIGNING
: this.REQUIRE_SIGNING;
return signingRequired && !this.isCorrectlySigned(addon);
}
/**
* find an addon's screenshot url. prefer 680x92.
* @param {object} addon (an Addon object)
* @returns {string} url
*/
getScreenshotUrlForAddon(addon) {
if (addon.id == "[email protected]") {
return "chrome://mozapps/content/extensions/default-theme/preview.svg";
}
const builtInThemePreview = this.BuiltInThemes.previewForBuiltInThemeId(
addon.id
);
if (builtInThemePreview) return builtInThemePreview;
let { screenshots } = addon;
if (!screenshots || !screenshots.length) return null;
let screenshot = screenshots.find(s => s.width === 680 && s.height === 92);
if (!screenshot) screenshot = screenshots[0];
return screenshot.url;
}
// where panelviews are hiding when we're not looking
viewCache(doc) {
return doc.getElementById("appMenu-viewCache");
}
constructor() {
XPCOMUtils.defineLazyModuleGetters(this, {
ExtensionPermissions: "resource://gre/modules/ExtensionPermissions.jsm",
BuiltInThemes: "resource:///modules/BuiltInThemes.jsm",
});
ChromeUtils.defineLazyGetter(this, "extBundle", function () {
return Services.strings.createBundle(
"chrome://global/locale/extensions.properties"
);
});
XPCOMUtils.defineLazyPreferenceGetter(
this,
"REQUIRE_SIGNING",
"xpinstall.signatures.required",
false
);
XPCOMUtils.defineLazyPreferenceGetter(
this,
"LANGPACKS_REQUIRE_SIGNING",
"extensions.langpacks.signatures.required",
false
);
this.viewId = "PanelUI-eom";
this.config = ExtensionOptionsWidget.config;
let { l10n } = this.config;
if (
/^chrome:\/\/browser\/content\/browser.(xul||xhtml)$/i.test(location) &&
!CustomizableUI.getPlacementOfWidget("eom-button", true)
) {
CustomizableUI.createWidget({
id: "eom-button",
viewId: this.viewId,
type: "view",
defaultArea: CustomizableUI.AREA_NAVBAR,
removable: true,
label: l10n["Button label"],
tooltiptext: l10n["Button tooltip"],
// if the button is middle-clicked, open the addons page instead of the panel
onClick: event => {
if (event.button == 1) {
event.target.ownerGlobal.BrowserOpenAddonsMgr(
"addons://list/extension"
);
}
},
// create the panelview before the toolbar button
onBeforeCreated: aDoc => {
let eop = aDoc.defaultView.extensionOptionsPanel;
if (!eop) return;
let view = eop.create(aDoc, "panelview", {
id: eop.viewId,
class: "PanelUI-subView cui-widget-panelview",
flex: "1",
style: "min-width:30em",
});
aDoc.getElementById("appMenu-viewCache").appendChild(view);
aDoc.defaultView.extensionOptionsPanel.panelview = view;
if (eop.config["Show header"]) {
let header = view.appendChild(
eop.create(aDoc, "vbox", { id: "eom-mainView-panel-header" })
);
let heading = header.appendChild(eop.create(aDoc, "label"));
let label = heading.appendChild(
eop.create(aDoc, "html:span", {
id: "eom-mainView-panel-header-span",
role: "heading",
"aria-level": "1",
})
);
label.textContent = l10n["Panel title"];
view.appendChild(aDoc.createXULElement("toolbarseparator"));
}
view.appendChild(
eop.create(aDoc, "vbox", {
id: `${view.id}-body`,
class: "panel-subview-body",
})
);
// create the theme preview tooltip
if (eop.config["Show theme preview tooltips"]) {
aDoc
.getElementById("mainPopupSet")
.appendChild(
aDoc.defaultView.MozXULElement.parseXULToFragment(
`<tooltip id="eom-theme-preview-tooltip" noautohide="true" orient="vertical" onpopupshowing="extensionOptionsPanel.onTooltipShowing(event);"><vbox id="eom-theme-preview-box"><html:img id="eom-theme-preview-canvas"></html:img></vbox></tooltip>`
)
);
}
eop.fluentSetup(aDoc).then(() => eop.swapAddonsButton(aDoc));
},
// populate the panel before it's shown
onViewShowing: event => {
if (
event.originalTarget ===
event.target.ownerGlobal.extensionOptionsPanel?.panelview
) {
event.target.ownerGlobal.extensionOptionsPanel.getAddonsAndPopulate(
event
);
}
},
// delete the panel if the widget node is destroyed
onDestroyed: aDoc => {
let view = aDoc.getElementById(
aDoc.defaultView.extensionOptionsPanel?.viewId
);
if (view) {
aDoc.defaultView.CustomizableUI.hidePanelForNode(view);
view.remove();
}
},
});
}
this.loadStylesheet(); // load the stylesheet
}
// grab localized strings for the extensions button and disabled/enabled extensions headings
async fluentSetup(aDoc) {
aDoc.ownerGlobal.MozXULElement.insertFTLIfNeeded(
"toolkit/about/aboutAddons.ftl"
);
let [extensions, themes, enabled, disabled, privateHelp] =
await aDoc.l10n.formatValues([
"addon-category-extension",
"addon-category-theme",
"extension-enabled-heading",
"extension-disabled-heading",
"addon-detail-private-browsing-help",
]);
privateHelp = privateHelp.replace(/\s*\<.*\>$/, "");
this.aboutAddonsStrings = {
extensions,
themes,
enabled,
disabled,
privateHelp,
};
}
/**
* this script changes the built-in "Add-ons & themes" button in the app menu
* to open our new panel instead of opening about:addons
* @param {object} aDoc (the document our widget has been created within)
*/
swapAddonsButton(aDoc) {
if (!this.config["Replace addons button"]) return;
let win = aDoc.defaultView;
win.PanelUI._initialized ||
win.PanelUI.init(shouldSuppressPopupNotifications);
this.setAttributes(
win.PanelUI.mainView.querySelector("#appMenu-extensions-themes-button") ||
win.PanelUI.mainView.querySelector("#appMenu-addons-button"),
{
command: 0,
key: 0,
shortcut: 0,
class: "subviewbutton subviewbutton-nav",
oncommand: "PanelUI.showSubView('PanelUI-eom', this);",
closemenu: "none",
}
);
}
/**
* grab all addons and populate the panel with them.
* @param {object} e (a ViewShowing event)
*/
async getAddonsAndPopulate(e) {
let extensions = await AddonManager.getAddonsByTypes(["extension"]);
let themes = await AddonManager.getAddonsByTypes(["theme"]);
this.populatePanelBody(e, { extensions, themes });
}
/**
* create everything inside the panel
* @param {object} e (a ViewShowing event - its target is the panelview node)
* @param {array} addons (an object containing arrays for different addon
* types e.g. extensions, themes)
*/
populatePanelBody(e, addons) {
let prevState;
let { extensions, themes } = addons;
let view = e?.target || this.panelview;
let win = view.ownerGlobal;
let doc = win.document;
let body = view.querySelector(".panel-subview-body");
let { l10n } = this.config;
let enabledFirst = this.config["Show enabled extensions first"];
let showVersion = this.config["Show version"];
let showDisabled = this.config["Show disabled extensions"];
let blackListArray = this.config["Addon ID blacklist"];
// clear all the panel items and subviews before rebuilding them.
while (body.hasChildNodes()) body.firstChild.remove();
[...this.viewCache(doc).children].forEach(panel => {
if (panel.id.includes("PanelUI-eom-addon-")) panel.remove();
});
let appMenuMultiView = win.PanelMultiView.forNode(PanelUI.multiView);
if (
win.PanelMultiView.forNode(view.closest("panelmultiview")) ===
appMenuMultiView
) {
[...appMenuMultiView._viewStack.children].forEach(panel => {
if (panel.id !== view.id && panel.id.includes("PanelUI-eom-addon-")) {
panel.remove();
}
});
}
// extensions...
let enabledSubheader = body.appendChild(
this.create(doc, "h2", { class: "subview-subheader" }, true)
);
enabledSubheader.textContent =
this.aboutAddonsStrings[showDisabled ? "enabled" : "extensions"];
extensions
.sort((a, b) => {
// get sorted by enabled state...
let ka =
(enabledFirst ? Number(!a.isActive) : "") + a.name.toLowerCase();
let kb =
(enabledFirst ? Number(!b.isActive) : "") + b.name.toLowerCase();
return ka < kb ? -1 : 1;
})
.forEach(addon => {
// then get excluded if config wills it...
if (
!blackListArray.includes(addon.id) &&
(!addon.hidden || this.config["Show hidden extensions"]) &&
(!addon.userDisabled || showDisabled)
) {
// then get built into subviewbuttons and corresponding subviews...
if (
showDisabled &&
enabledFirst &&
prevState &&
addon.isActive != prevState
) {
body.appendChild(doc.createXULElement("toolbarseparator"));
let disabledSubheader = body.appendChild(
this.create(doc, "h2", { class: "subview-subheader" }, true)
);
disabledSubheader.textContent = this.aboutAddonsStrings.disabled;
}
prevState = addon.isActive;
let subviewbutton = body.appendChild(
this.create(doc, "toolbarbutton", {
label: addon.name + (showVersion ? ` ${addon.version}` : ""),
class:
"subviewbutton subviewbutton-iconic subviewbutton-nav eom-addon-button",
oncommand: "extensionOptionsPanel.showSubView(event, this)",
closemenu: "none",
"addon-type": "extension",
"data-extensionid": addon.id,
})
);
if (!addon.isActive) subviewbutton.classList.add("disabled");
// set the icon using CSS variables and list-style-image so that user stylesheets can override the icon URL.
subviewbutton.style.setProperty(
"--extension-icon",
`url(${addon.iconURL || this.config["Icon URL"]})`
);
subviewbutton._Addon = addon;
if (this.config["Show addon messages"]) {
this.setAddonMessage(doc, subviewbutton, addon);
}
}
});
// themes...
let themesSeparator = body.appendChild(
doc.createXULElement("toolbarseparator")
);
let themesSubheader = body.appendChild(
this.create(doc, "h2", { class: "subview-subheader" }, true)
);
themesSubheader.textContent = this.aboutAddonsStrings.themes;
themes.forEach(addon => {
if (
!blackListArray.includes(addon.id) &&
(!addon.hidden || this.config["Show hidden extensions"]) &&
(!addon.userDisabled || showDisabled)
) {
let subviewbutton = body.appendChild(
this.create(doc, "toolbarbutton", {
label: addon.name + (showVersion ? ` ${addon.version}` : ""),
class: "subviewbutton subviewbutton-iconic eom-addon-button",
closemenu: "none",
"addon-type": "theme",
"data-extensionid": addon.id,
})
);
subviewbutton.addEventListener("command", async e => {
await addon[addon.userDisabled ? "enable" : "disable"]();
subviewbutton.parentElement
.querySelectorAll(`.eom-addon-button[addon-type="theme"]`)
.forEach(btn => {
btn.classList[btn._Addon?.isActive ? "remove" : "add"](
"disabled"
);
this.setAddonMessage(doc, btn, btn._Addon);
});
});
if (!addon.isActive) subviewbutton.classList.add("disabled");
subviewbutton.style.setProperty(
"--extension-icon",
`url(${addon.iconURL || this.config["Icon URL"]})`
);
subviewbutton._Addon = addon;
this.setAddonMessage(doc, subviewbutton, addon);
}
});
// if no addons are shown, display a "Download Addons" button that leads to AMO.
let getAddonsButton = body.appendChild(
this.create(doc, "toolbarbutton", {
id: "eom-get-addons-button",
class: "subviewbutton subviewbutton-iconic",
label: l10n["Download addons label"],
image: `data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 68 68" style="border-radius:3px"><path fill="context-fill" fill-opacity="context-fill-opacity" d="M0 0v68h68V0H0zm61.8 49H49.5V32.4c0-5.1-1.7-7-5-7-4 0-5.6 2.9-5.6 6.9v10.2h3.9v6.4H30.5V32.4c0-5.1-1.7-7-5-7-4 0-5.6 2.9-5.6 6.9v10.2h5.6v6.4h-18v-6.4h3.9V26H7.5v-6.4h12.3V24c1.8-3.1 4.8-5 8.9-5 4.2 0 8.1 2 9.5 6.3 1.6-3.9 4.9-6.3 9.5-6.3 5.3 0 10.1 3.2 10.1 10.1v13.5h4V49z"/></svg>`,
oncommand: `switchToTabHavingURI(Services.urlFormatter.formatURLPref("extensions.getAddons.link.url"), true, {
inBackground: false,
triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
});`,
})
);
let hasExtensions = !!body.querySelector(
`.eom-addon-button[addon-type="extension"]`
);
let hasThemes = !!body.querySelector(
`.eom-addon-button[addon-type="theme"]`
);
getAddonsButton.hidden = hasExtensions || hasThemes;
if (!hasExtensions) {
enabledSubheader.remove();
themesSeparator.remove();
}
if (!hasThemes) {
themesSubheader.remove();
themesSeparator.remove();
}
// make a footer button that leads to about:addons
if (view.querySelector("#eom-allAddonsButton")) return;
view.appendChild(doc.createXULElement("toolbarseparator"));
view.appendChild(
this.create(doc, "toolbarbutton", {
label: l10n["Addons page label"],
id: "eom-allAddonsButton",
class: "subviewbutton subviewbutton-iconic panel-subview-footer-button",
image: this.config["Icon URL"],
key: "key_openAddons",
shortcut: win.ShortcutUtils.prettifyShortcut(win.key_openAddons),
oncommand: `BrowserOpenAddonsMgr("addons://list/extension")`,
})
);
}
/**
* for a given button made for an addon, find out if it has a message
* (blocked, unverified, etc.) and if so, display it
* @param {object} doc (the document we're localizing)
* @param {object} subviewbutton (an addon button in the panel)
* @param {object} addon (an Addon object)
*/
async setAddonMessage(doc, subviewbutton, addon) {
const { l10n } = this.config;
const { name } = addon;
const { STATE_BLOCKED, STATE_SOFTBLOCKED } = Ci.nsIBlocklistService;
const formatString = (type, args) => {
return new Promise(resolve => {
doc.l10n
.formatMessages([{ id: `details-notification-${type}2`, args }])
.then(msg => resolve(msg[0].value));
});
};
let message = null;
if (addon.blocklistState === STATE_BLOCKED) {
message = {
label: l10n.addonMessages.Blocked,
detail: await formatString("blocked", { name }),
type: "error",
};
} else if (this.isDisabledUnsigned(addon)) {
message = {
label: l10n.addonMessages["Signature Required"],
detail: await formatString("unsigned-and-disabled", { name }),
type: "error",
};
} else if (
!addon.isCompatible &&
(AddonManager.checkCompatibility ||
addon.blocklistState !== STATE_SOFTBLOCKED)
) {
message = {
label: l10n.addonMessages.Incompatible,
detail: await formatString("incompatible", {
name,
version: Services.appinfo.version,
}),
type: "warning",
};
} else if (!this.isCorrectlySigned(addon)) {
message = {
label: l10n.addonMessages.Unverified,
detail: await formatString("unsigned", { name }),
type: "warning",
};
} else if (addon.blocklistState === STATE_SOFTBLOCKED) {
message = {
label: l10n.addonMessages.Insecure,
detail: await formatString("softblocked", { name }),
type: "warning",
};
}
if (
this.config["Show theme preview tooltips"] &&
addon.type === "theme" &&
(!message || message.type !== "error")
) {
message = message ?? {};
message.detail = "";
message.tooltip = "eom-theme-preview-tooltip";
message.preview = this.getScreenshotUrlForAddon(addon);
if (addon.isActive) {
message.label = null;
message.checked = true;
}
}
if (subviewbutton._addonMessage) {
subviewbutton.removeAttribute("message-type");
subviewbutton.removeAttribute("tooltiptext");
subviewbutton.removeAttribute("tooltip");
subviewbutton.removeAttribute("enable-checked");
subviewbutton.querySelector(".eom-message-label")?.remove();
delete subviewbutton._addonMessage;
}
if (message) {
subviewbutton.setAttribute("message-type", message?.type);
subviewbutton.setAttribute("tooltiptext", message?.detail);
if (message.tooltip) {
subviewbutton.setAttribute("tooltip", message.tooltip);
}
if (message.checked) subviewbutton.setAttribute("enable-checked", true);
if (message.label) {
subviewbutton.appendChild(
this.create(document, "h", {
class: "toolbarbutton-text eom-message-label",
})
).textContent = `(${message.label})`;
}
}
subviewbutton._addonMessage = message;
}
/**
* show the subview for a given extension
* @param {object} event (a triggering command/click event)
* @param {object} anchor (the subviewbutton that was clicked —
* dictates the title of the subview)
*/
showSubView(event, anchor) {
if (!("_Addon" in anchor)) return;
this.buildSubView(anchor, anchor._Addon);
event.target.ownerGlobal.PanelUI?.showSubView(
`PanelUI-eom-addon-${this.makeWidgetId(anchor._Addon.id)}`,
anchor,
event
);
}
/**
* for a given addon, build a panel subview
* @param {object} subviewbutton (the button you click to enter the subview,
* corresponding to the addon)
* @param {object} addon (an addon object provided by the AddonManager,
* with all the data we need)
*/
buildSubView(subviewbutton, addon) {
let { l10n } = this.config;
let win = subviewbutton.ownerGlobal;
let doc = win.document;
let view = this.viewCache(doc).appendChild(
this.create(doc, "panelview", {
id: `PanelUI-eom-addon-${this.makeWidgetId(addon.id)}`, // turn the extension ID into a DOM node ID
flex: "1",
class: "PanelUI-subView cui-widget-panelview",
})
);
// create options button
let optionsButton = view.appendChild(
this.create(doc, "toolbarbutton", {
label: l10n["Addon options label"],
class: "subviewbutton",
})
);
optionsButton.addEventListener("command", e =>
this.openAddonOptions(addon, win)
);
// manage button, when no options page exists
let manageButton = view.appendChild(
this.create(doc, "toolbarbutton", {
label: l10n["Manage addon label"],
class: "subviewbutton",
})
);
manageButton.addEventListener("command", e =>
win.BrowserOpenAddonsMgr(
`addons://detail/${encodeURIComponent(addon.id)}`
)
);
// disable button
let disableButton = view.appendChild(
this.create(doc, "toolbarbutton", {
label: addon.userDisabled
? l10n["Enable addon label"]
: l10n["Disable addon label"],
class: "subviewbutton",
closemenu: "none",
})
);
disableButton.addEventListener("command", async e => {
if (addon.userDisabled) {
await addon.enable();
disableButton.setAttribute("label", l10n["Disable addon label"]);
} else {
await addon.disable();
disableButton.setAttribute("label", l10n["Enable addon label"]);
}
this.getAddonsAndPopulate();
});
// uninstall button, and so on...
let uninstallButton = view.appendChild(
this.create(doc, "toolbarbutton", {
label: l10n["Uninstall addon label"],
class: "subviewbutton",
})
);
uninstallButton.addEventListener("command", e => {
if (
win.Services.prompt.confirm(
null,
null,
`Delete ${addon.name} permanently?`
)
) {
addon.pendingOperations & win.AddonManager.PENDING_UNINSTALL
? addon.cancelUninstall()
: addon.uninstall();
}
});
// allow automatic updates radio group
let updates = view.appendChild(
this.create(doc, "hbox", {
id: "eom-allow-auto-updates",
class: "subviewbutton eom-radio-hbox",
align: "center",
})
);
let updatesLabel = updates.appendChild(
this.create(doc, "label", {
id: "eom-allow-auto-updates-label",
class: "toolbarbutton-text eom-radio-label",
flex: 1,
wrap: true,
})
);
updatesLabel.textContent = l10n["Automatic updates label"];
let updatesGroup = updates.appendChild(
this.create(doc, "radiogroup", {
id: "eom-allow-auto-updates-group",
class: "eom-radio-group",
value: addon.applyBackgroundUpdates,
closemenu: "none",
orient: "horizontal",
"aria-labelledby": "eom-allow-auto-updates-label",
})
);
updatesGroup.addEventListener(
"command",
e => (addon.applyBackgroundUpdates = e.target.value)
);
updatesGroup.appendChild(
this.create(doc, "radio", {
label: l10n.autoUpdate["Default label"],
class: "subviewradio",
value: 1,
})
);
updatesGroup.appendChild(
this.create(doc, "radio", {
label: l10n.autoUpdate["On label"],
class: "subviewradio",
value: 2,
})
);
updatesGroup.appendChild(
this.create(doc, "radio", {
label: l10n.autoUpdate["Off label"],
class: "subviewradio",
value: 0,
})
);
// run in private windows radio group
let setPrivateState = async (addon, node) => {
let perms = await this.ExtensionPermissions.get(addon.id);
let isAllowed = perms.permissions.includes(
"internal:privateBrowsingAllowed"
);
node.permState = isAllowed;
node.value = isAllowed ? 1 : 0;
};
let privateWindows = view.appendChild(
this.create(doc, "hbox", {
id: "eom-run-in-private",
class: "subviewbutton eom-radio-hbox",
align: "center",
})
);
let privateLabel = privateWindows.appendChild(
this.create(doc, "label", {
id: "eom-run-in-private-label",
class: "toolbarbutton-text eom-radio-label",
flex: 1,
wrap: true,
tooltiptext: this.aboutAddonsStrings.privateHelp,
})
);
privateLabel.textContent = l10n["Run in private windows label"];
let privateGroup = privateWindows.appendChild(
this.create(doc, "radiogroup", {
id: "eom-run-in-private-group",
class: "eom-radio-group",
closemenu: "none",
orient: "horizontal",
"aria-labelledby": "eom-run-in-private-label",
})
);
privateGroup.addEventListener("command", async () => {
let extension = this.extensionForAddonId(addon.id);
await this.ExtensionPermissions[
privateGroup.permState ? "remove" : "add"
](
addon.id,
{
permissions: ["internal:privateBrowsingAllowed"],
origins: [],
},
extension
);
setPrivateState(addon, privateGroup);
});
privateGroup.appendChild(
this.create(doc, "radio", {
label: l10n.runInPrivate["Allow label"],
class: "subviewradio",
value: 1,
})
);
privateGroup.appendChild(
this.create(doc, "radio", {
label: l10n.runInPrivate["Don't allow label"],
class: "subviewradio",
value: 0,
})
);
setPrivateState(addon, privateGroup);
// manage shortcuts
let shortcutsButton = view.appendChild(
this.create(doc, "toolbarbutton", {
label: l10n["Manage shortcuts label"],
class: "subviewbutton",
})
);
shortcutsButton.addEventListener("command", () =>
win.BrowserOpenAddonsMgr("addons://shortcuts/shortcuts")
);
let viewSrcButton = view.appendChild(
this.create(doc, "toolbarbutton", {
label: l10n["View source label"],
class: "subviewbutton",
})
);
viewSrcButton.addEventListener("command", () => this.openArchive(addon));
let homePageButton = view.appendChild(
this.create(doc, "toolbarbutton", {
label: l10n["Open homepage label"],
class: "subviewbutton",
})
);
homePageButton.addEventListener("command", () => {
win.switchToTabHavingURI(addon.homepageURL || addon.supportURL, true, {
inBackground: false,
triggeringPrincipal:
win.Services.scriptSecurityManager.getSystemPrincipal(),
});
});
let copyIdButton = view.appendChild(
this.create(doc, "toolbarbutton", {
label: l10n["Copy ID label"],
class: "subviewbutton panel-subview-footer-button",
})
);
copyIdButton.addEventListener("command", () => {
win.Cc["@mozilla.org/widget/clipboardhelper;1"]
.getService(win.Ci.nsIClipboardHelper)
.copyString(addon.id);
let PMV =
view.panelMultiView && win.PanelMultiView.forNode(view.panelMultiView);
if (PMV) {
let panel = PMV._panel;
if (panel && PMV._getBoundsWithoutFlushing(panel.anchorNode)?.width) {
win.CustomHint?.show(panel.anchorNode, "Copied");
}
}
});
view.addEventListener("ViewShowing", () => {
optionsButton.hidden = !addon.optionsURL;
manageButton.hidden = !!addon.optionsURL;
updates.hidden = !(addon.permissions & win.AddonManager.PERM_CAN_UPGRADE);
updatesGroup.setAttribute("value", addon.applyBackgroundUpdates);
privateWindows.hidden = !(
addon.incognito != "not_allowed" &&