This commit is contained in:
gorhill 2015-11-08 00:31:49 -05:00
parent 35474f0146
commit 1c6d969ccb
2 changed files with 46 additions and 38 deletions

View File

@ -72,8 +72,7 @@ function startup(data/*, reason*/) {
// Do not test against `loading`: it does appear `readyState` could be // Do not test against `loading`: it does appear `readyState` could be
// undefined if looked up too early. // undefined if looked up too early.
if ( !hiddenDoc || if ( !hiddenDoc || hiddenDoc.readyState !== 'complete' ) {
hiddenDoc.readyState !== 'interactive' && hiddenDoc.readyState !== 'complete' ) {
return false; return false;
} }

View File

@ -1233,10 +1233,7 @@ var tabWatcher = (function() {
// https://github.com/gorhill/uBlock/issues/906 // https://github.com/gorhill/uBlock/issues/906
// This might have been the cause. Will see. // This might have been the cause. Will see.
if ( if ( document.readyState !== 'complete' ) {
document.readyState !== 'interactive' &&
document.readyState !== 'complete'
) {
attachToTabBrowserLater({ window: window, tryCount: tryCount }); attachToTabBrowserLater({ window: window, tryCount: tryCount });
return; return;
} }
@ -3111,43 +3108,55 @@ vAPI.contextMenu.displayMenuItem = function({target}) {
/******************************************************************************/ /******************************************************************************/
vAPI.contextMenu.register = function(doc) { vAPI.contextMenu.register = (function() {
if ( !this.menuItemId ) { var register = function(doc) {
return; if ( !this.menuItemId ) {
} return;
}
if ( vAPI.fennec ) { if ( vAPI.fennec ) {
// TODO https://developer.mozilla.org/en-US/Add-ons/Firefox_for_Android/API/NativeWindow/contextmenus/add // TODO https://developer.mozilla.org/en-US/Add-ons/Firefox_for_Android/API/NativeWindow/contextmenus/add
/*var nativeWindow = doc.defaultView.NativeWindow; /*var nativeWindow = doc.defaultView.NativeWindow;
contextId = nativeWindow.contextmenus.add( contextId = nativeWindow.contextmenus.add(
this.menuLabel, this.menuLabel,
nativeWindow.contextmenus.linkOpenableContext, nativeWindow.contextmenus.linkOpenableContext,
this.onCommand this.onCommand
);*/ );*/
return; return;
} }
// Already installed? // Already installed?
if ( doc.getElementById(this.menuItemId) !== null ) { if ( doc.getElementById(this.menuItemId) !== null ) {
return; return;
} }
var contextMenu = doc.getElementById('contentAreaContextMenu'); var contextMenu = doc.getElementById('contentAreaContextMenu');
// This can happen (Thunderbird). // This can happen (Thunderbird).
if ( contextMenu === null ) { if ( contextMenu === null ) {
return; return;
} }
var menuitem = doc.createElement('menuitem'); var menuitem = doc.createElement('menuitem');
menuitem.setAttribute('id', this.menuItemId); menuitem.setAttribute('id', this.menuItemId);
menuitem.setAttribute('label', this.menuLabel); menuitem.setAttribute('label', this.menuLabel);
menuitem.setAttribute('image', vAPI.getURL('img/browsericons/icon16.svg')); menuitem.setAttribute('image', vAPI.getURL('img/browsericons/icon16.svg'));
menuitem.setAttribute('class', 'menuitem-iconic'); menuitem.setAttribute('class', 'menuitem-iconic');
menuitem.addEventListener('command', this.onCommand); menuitem.addEventListener('command', this.onCommand);
contextMenu.addEventListener('popupshowing', this.displayMenuItem); contextMenu.addEventListener('popupshowing', this.displayMenuItem);
contextMenu.insertBefore(menuitem, doc.getElementById('inspect-separator')); contextMenu.insertBefore(menuitem, doc.getElementById('inspect-separator'));
}; };
var registerSafely = function(doc) {
if ( doc.readyState !== 'complete' ) {
vAPI.setTimeout(registerSafely.bind(this, doc), 200);
} else {
register.call(this, doc);
}
};
return registerSafely;
})();
/******************************************************************************/ /******************************************************************************/