mirror of
https://github.com/gorhill/uBlock.git
synced 2024-10-06 09:37:12 +02:00
code review re. lagacy toolbar button
This commit is contained in:
parent
13f42051b2
commit
756887a6cf
@ -2623,7 +2623,6 @@ vAPI.toolbarButton = {
|
|||||||
tbb.id = 'uBlock0-legacy-button'; // NOTE: must match legacy-toolbar-button.css
|
tbb.id = 'uBlock0-legacy-button'; // NOTE: must match legacy-toolbar-button.css
|
||||||
tbb.viewId = tbb.id + '-panel';
|
tbb.viewId = tbb.id + '-panel';
|
||||||
|
|
||||||
var sss = null;
|
|
||||||
var styleSheetUri = null;
|
var styleSheetUri = null;
|
||||||
|
|
||||||
var createToolbarButton = function(window) {
|
var createToolbarButton = function(window) {
|
||||||
@ -2651,6 +2650,18 @@ vAPI.toolbarButton = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var addLegacyToolbarButton = function(window) {
|
var addLegacyToolbarButton = function(window) {
|
||||||
|
// uBO's stylesheet lazily added.
|
||||||
|
if ( styleSheetUri === null ) {
|
||||||
|
var sss = Cc['@mozilla.org/content/style-sheet-service;1']
|
||||||
|
.getService(Ci.nsIStyleSheetService);
|
||||||
|
styleSheetUri = Services.io.newURI(vAPI.getURL('css/legacy-toolbar-button.css'), null, null);
|
||||||
|
|
||||||
|
// Register global so it works in all windows, including palette
|
||||||
|
if ( !sss.sheetRegistered(styleSheetUri, sss.AUTHOR_SHEET) ) {
|
||||||
|
sss.loadAndRegisterSheet(styleSheetUri, sss.AUTHOR_SHEET);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var document = window.document;
|
var document = window.document;
|
||||||
|
|
||||||
// https://github.com/gorhill/uMatrix/issues/357
|
// https://github.com/gorhill/uMatrix/issues/357
|
||||||
@ -2723,9 +2734,16 @@ vAPI.toolbarButton = {
|
|||||||
|
|
||||||
var canAddLegacyToolbarButton = function(window) {
|
var canAddLegacyToolbarButton = function(window) {
|
||||||
var document = window.document;
|
var document = window.document;
|
||||||
|
if (
|
||||||
|
!document ||
|
||||||
|
document.readyState !== 'complete' ||
|
||||||
|
document.getElementById('nav-bar') === null
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
var toolbox = document.getElementById('navigator-toolbox') ||
|
var toolbox = document.getElementById('navigator-toolbox') ||
|
||||||
document.getElementById('mail-toolbox');
|
document.getElementById('mail-toolbox');
|
||||||
return toolbox !== null && !!toolbox.palette && document.getElementById('nav-bar') !== null;
|
return toolbox !== null && !!toolbox.palette;
|
||||||
};
|
};
|
||||||
|
|
||||||
var onPopupCloseRequested = function({target}) {
|
var onPopupCloseRequested = function({target}) {
|
||||||
@ -2752,19 +2770,20 @@ vAPI.toolbarButton = {
|
|||||||
toolbarButton.parentNode.removeChild(toolbarButton);
|
toolbarButton.parentNode.removeChild(toolbarButton);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( sss === null ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if ( sss.sheetRegistered(styleSheetUri, sss.AUTHOR_SHEET) ) {
|
|
||||||
sss.unregisterSheet(styleSheetUri, sss.AUTHOR_SHEET);
|
|
||||||
}
|
|
||||||
sss = null;
|
|
||||||
styleSheetUri = null;
|
|
||||||
|
|
||||||
vAPI.messaging.globalMessageManager.removeMessageListener(
|
vAPI.messaging.globalMessageManager.removeMessageListener(
|
||||||
location.host + ':closePopup',
|
location.host + ':closePopup',
|
||||||
onPopupCloseRequested
|
onPopupCloseRequested
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ( styleSheetUri !== null ) {
|
||||||
|
var sss = Cc['@mozilla.org/content/style-sheet-service;1']
|
||||||
|
.getService(Ci.nsIStyleSheetService);
|
||||||
|
if ( sss.sheetRegistered(styleSheetUri, sss.AUTHOR_SHEET) ) {
|
||||||
|
sss.unregisterSheet(styleSheetUri, sss.AUTHOR_SHEET);
|
||||||
|
}
|
||||||
|
styleSheetUri = null;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
tbb.attachToNewWindow = function(win) {
|
tbb.attachToNewWindow = function(win) {
|
||||||
@ -2780,14 +2799,6 @@ vAPI.toolbarButton = {
|
|||||||
onPopupCloseRequested
|
onPopupCloseRequested
|
||||||
);
|
);
|
||||||
|
|
||||||
sss = Cc["@mozilla.org/content/style-sheet-service;1"].getService(Ci.nsIStyleSheetService);
|
|
||||||
styleSheetUri = Services.io.newURI(vAPI.getURL("css/legacy-toolbar-button.css"), null, null);
|
|
||||||
|
|
||||||
// Register global so it works in all windows, including palette
|
|
||||||
if ( !sss.sheetRegistered(styleSheetUri, sss.AUTHOR_SHEET) ) {
|
|
||||||
sss.loadAndRegisterSheet(styleSheetUri, sss.AUTHOR_SHEET);
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanupTasks.push(shutdown);
|
cleanupTasks.push(shutdown);
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
Loading…
Reference in New Issue
Block a user