Bug 1475670: Optimizing the code inside ContentBlocking. r=johannh

This commit is contained in:
Abdelrhman Ahmed 2018-12-18 11:18:13 +02:00
Родитель fd7e92a35e
Коммит 3823488bec
2 изменённых файлов: 62 добавлений и 23 удалений

Просмотреть файл

@ -524,15 +524,57 @@ var ContentBlocking = {
PREF_CB_CATEGORY: "browser.contentblocking.category",
PREF_SHOW_ALLOWED_LABELS: "browser.contentblocking.control-center.ui.showAllowedLabels",
PREF_SHOW_BLOCKED_LABELS: "browser.contentblocking.control-center.ui.showBlockedLabels",
content: null,
icon: null,
activeTooltipText: null,
disabledTooltipText: null,
get prefIntroCount() {
return this.PREF_INTRO_COUNT_CB;
},
get content() {
delete this.content;
return this.content =
document.getElementById("identity-popup-content-blocking-content");
},
get icon() {
delete this.icon;
return this.icon = document.getElementById("tracking-protection-icon");
},
get iconBox() {
delete this.iconBox;
return this.iconBox = document.getElementById("tracking-protection-icon-box");
},
get animatedIcon() {
delete this.animatedIcon;
return this.animatedIcon =
document.getElementById("tracking-protection-icon-animatable-image");
},
get identityPopupMultiView() {
delete this.identityPopupMultiView;
return this.identityPopupMultiView =
document.getElementById("identity-popup-multiView");
},
get reportBreakageButton() {
delete this.reportBreakageButton;
return this.reportBreakageButton =
document.getElementById("identity-popup-content-blocking-report-breakage");
},
get reportBreakageURL() {
delete this.reportBreakageURL;
return this.reportBreakageURL =
document.getElementById("identity-popup-breakageReportView-collection-url");
},
get reportBreakageLearnMore() {
delete this.reportBreakageLearnMore;
return this.reportBreakageLearnMore =
document.getElementById("identity-popup-breakageReportView-learn-more");
},
get appMenuLabel() {
delete this.appMenuLabel;
return this.appMenuLabel = document.getElementById("appMenu-tp-label");
@ -555,6 +597,18 @@ var ContentBlocking = {
return this.appMenuTooltip =
gNavigatorBundle.getString("contentBlocking.tooltip");
},
get activeTooltipText() {
delete this.activeTooltipText;
return this.activeTooltipText =
gNavigatorBundle.getString("trackingProtection.icon.activeTooltip");
},
get disabledTooltipText() {
delete this.disabledTooltipText;
return this.disabledTooltipText =
gNavigatorBundle.getString("trackingProtection.icon.disabledTooltip");
},
},
// A list of blockers that will be displayed in the categories list
@ -581,18 +635,8 @@ var ContentBlocking = {
},
init() {
let $ = id => document.getElementById(id);
this.content = $("identity-popup-content-blocking-content");
this.icon = $("tracking-protection-icon");
this.iconBox = $("tracking-protection-icon-box");
this.animatedIcon = $("tracking-protection-icon-animatable-image");
this.animatedIcon.addEventListener("animationend", () => this.iconBox.removeAttribute("animate"));
this.identityPopupMultiView = $("identity-popup-multiView");
this.reportBreakageButton = $("identity-popup-content-blocking-report-breakage");
this.reportBreakageURL = $("identity-popup-breakageReportView-collection-url");
this.reportBreakageLearnMore = $("identity-popup-breakageReportView-learn-more");
let baseURL = Services.urlFormatter.formatURLPref("app.support.baseURL");
this.reportBreakageLearnMore.href = baseURL + "blocking-breakage";
@ -629,10 +673,6 @@ var ContentBlocking = {
this.appMenuLabel.setAttribute("value", this.strings.appMenuTitle);
this.appMenuLabel.setAttribute("tooltiptext", this.strings.appMenuTooltip);
this.activeTooltipText =
gNavigatorBundle.getString("trackingProtection.icon.activeTooltip");
this.disabledTooltipText =
gNavigatorBundle.getString("trackingProtection.icon.disabledTooltip");
this.updateCBCategoryLabel = this.updateCBCategoryLabel.bind(this);
this.updateCBCategoryLabel();
Services.prefs.addObserver(this.PREF_CB_CATEGORY, this.updateCBCategoryLabel);
@ -844,10 +884,10 @@ var ContentBlocking = {
}
if (hasException) {
this.iconBox.setAttribute("tooltiptext", this.disabledTooltipText);
this.iconBox.setAttribute("tooltiptext", this.strings.disabledTooltipText);
this.shieldHistogramAdd(1);
} else if (anyBlocking) {
this.iconBox.setAttribute("tooltiptext", this.activeTooltipText);
this.iconBox.setAttribute("tooltiptext", this.strings.activeTooltipText);
this.shieldHistogramAdd(2);
} else {
this.iconBox.removeAttribute("tooltiptext");

Просмотреть файл

@ -1331,7 +1331,6 @@ var gBrowserInit = {
gPageStyleMenu.init();
LanguageDetectionListener.init();
BrowserOnClick.init();
ContentBlocking.init();
CaptivePortalWatcher.init();
ZoomUI.init(window);
@ -1477,6 +1476,7 @@ var gBrowserInit = {
BookmarkingUI.init();
BrowserSearch.delayedStartupInit();
AutoShowBookmarksToolbar.init();
ContentBlocking.init();
let safeMode = document.getElementById("helpSafeMode");
if (Services.appinfo.inSafeMode) {
@ -1914,8 +1914,6 @@ var gBrowserInit = {
BrowserOnClick.uninit();
ContentBlocking.uninit();
CaptivePortalWatcher.uninit();
SidebarUI.uninit();
@ -1941,6 +1939,7 @@ var gBrowserInit = {
Services.prefs.removeObserver(ctrlTab.prefName, ctrlTab);
ctrlTab.uninit();
gBrowserThumbnails.uninit();
ContentBlocking.uninit();
FullZoom.destroy();
Services.obs.removeObserver(gIdentityHandler, "perm-changed");