AlexVallat 10 years ago committed by gorhill
parent 651fa9c16a
commit c9a8c8d6df

@ -269,17 +269,20 @@ var windowWatcher = {
return; return;
} }
if ( tabBrowser.tabContainer ) { if ( tabBrowser.deck ) {
// Fennec
tabContainer = tabBrowser.deck;
} else if ( tabBrowser.tabContainer ) {
// desktop Firefox // desktop Firefox
tabContainer = tabBrowser.tabContainer; tabContainer = tabBrowser.tabContainer;
tabBrowser.addTabsProgressListener(tabWatcher); tabBrowser.addTabsProgressListener(tabWatcher);
vAPI.contextMenu.register(this.document);
} else { } else {
return; return;
} }
tabContainer.addEventListener('TabClose', tabWatcher.onTabClose); tabContainer.addEventListener('TabClose', tabWatcher.onTabClose);
tabContainer.addEventListener('TabSelect', tabWatcher.onTabSelect); tabContainer.addEventListener('TabSelect', tabWatcher.onTabSelect);
vAPI.contextMenu.register(this.document);
// when new window is opened TabSelect doesn't run on the selected tab? // when new window is opened TabSelect doesn't run on the selected tab?
}, },
@ -417,7 +420,10 @@ vAPI.tabs.registerListeners = function() {
continue; continue;
} }
if ( tabBrowser.tabContainer ) { if ( tabBrowser.deck ) {
// Fennec
tabContainer = tabBrowser.deck;
} else if ( tabBrowser.tabContainer ) {
tabContainer = tabBrowser.tabContainer; tabContainer = tabBrowser.tabContainer;
tabBrowser.removeTabsProgressListener(tabWatcher); tabBrowser.removeTabsProgressListener(tabWatcher);
} }
@ -543,7 +549,7 @@ vAPI.tabs.get = function(tabId, callback) {
} }
} }
// for internal use // For internal use
if ( typeof callback !== 'function' ) { if ( typeof callback !== 'function' ) {
return tab; return tab;
} }
@ -559,12 +565,14 @@ vAPI.tabs.get = function(tabId, callback) {
var browser = getBrowserForTab(tab); var browser = getBrowserForTab(tab);
var tabBrowser = getTabBrowser(win); var tabBrowser = getTabBrowser(win);
var tabIndex = vAPI.fennec var tabIndex, tabTitle;
? tabBrowser.tabs.indexOf(tab) if ( vAPI.fennec ) {
: tabBrowser.browsers.indexOf(browser); tabIndex = tabBrowser.tabs.indexOf(tab);
var tabTitle = vAPI.fennec tabTitle = browser.contentTitle;
? browser.contentTitle } else {
: tab.label; tabIndex = tabBrowser.browsers.indexOf(browser);
tabTitle = tab.label;
}
callback({ callback({
id: tabId, id: tabId,
@ -735,6 +743,24 @@ vAPI.tabs.reload = function(tabId) {
/******************************************************************************/ /******************************************************************************/
vAPI.tabs.select = function(tabId) {
var tab = this.get(tabId);
if ( !tab ) {
return;
}
var tabBrowser = getTabBrowser(getOwnerWindow(tab));
if (vAPI.fennec) {
tabBrowser.selectTab(tab);
} else {
tabBrowser.selectedTab = tab;
}
};
/******************************************************************************/
vAPI.tabs.injectScript = function(tabId, details, callback) { vAPI.tabs.injectScript = function(tabId, details, callback) {
var tab = this.get(tabId); var tab = this.get(tabId);
@ -747,7 +773,7 @@ vAPI.tabs.injectScript = function(tabId, details, callback) {
} }
details.file = vAPI.getURL(details.file); details.file = vAPI.getURL(details.file);
tab.linkedBrowser.messageManager.sendAsyncMessage( getBrowserForTab(tab).messageManager.sendAsyncMessage(
location.host + ':broadcast', location.host + ':broadcast',
JSON.stringify({ JSON.stringify({
broadcast: true, broadcast: true,
@ -785,23 +811,7 @@ vAPI.setIcon = function(tabId, iconStatus, badge) {
return; return;
} }
var button = win.document.getElementById(tb.id); tb.updateState(win, tabId);
if ( !button ) {
return;
}
var icon = tb.tabs[tabId];
button.setAttribute('badge', icon && icon.badge || '');
if ( !icon || !icon.img ) {
icon = '';
}
else {
icon = 'url(' + vAPI.getURL('img/browsericons/icon16.svg') + ')';
}
button.style.listStyleImage = icon;
}; };
/******************************************************************************/ /******************************************************************************/
@ -990,6 +1000,7 @@ var httpObserver = {
classDescription: 'net-channel-event-sinks for ' + location.host, classDescription: 'net-channel-event-sinks for ' + location.host,
classID: Components.ID('{dc8d6319-5f6e-4438-999e-53722db99e84}'), classID: Components.ID('{dc8d6319-5f6e-4438-999e-53722db99e84}'),
contractID: '@' + location.host + '/net-channel-event-sinks;1', contractID: '@' + location.host + '/net-channel-event-sinks;1',
REQDATAKEY: location.host + 'reqdata',
ABORT: Components.results.NS_BINDING_ABORTED, ABORT: Components.results.NS_BINDING_ABORTED,
ACCEPT: Components.results.NS_SUCCEEDED, ACCEPT: Components.results.NS_SUCCEEDED,
// Request types: https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIContentPolicy#Constants // Request types: https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIContentPolicy#Constants
@ -1008,14 +1019,7 @@ var httpObserver = {
12: 'object', 12: 'object',
14: 'font' 14: 'font'
}, },
lastRequest: { lastRequest: [{}, {}],
url: null,
type: null,
tabId: null,
frameId: null,
parentFrameId: null,
openerURL: null
},
get componentRegistrar() { get componentRegistrar() {
return Components.manager.QueryInterface(Ci.nsIComponentRegistrar); return Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
@ -1086,9 +1090,9 @@ var httpObserver = {
} }
var result = vAPI.tabs.onPopup({ var result = vAPI.tabs.onPopup({
targetTabId: tabId, tabId: tabId,
openerTabId: sourceTabId, sourceTabId: sourceTabId,
targetURL: URI.asciiSpec url: URI.asciiSpec
}); });
return result === true; return result === true;
@ -1120,13 +1124,13 @@ var httpObserver = {
return true; return true;
} }
if ( result.redirectUrl ) { /*if ( result.redirectUrl ) {
channel.redirectionLimit = 1; channel.redirectionLimit = 1;
channel.redirectTo( channel.redirectTo(
Services.io.newURI(result.redirectUrl, null, null) Services.io.newURI(result.redirectUrl, null, null)
); );
return true; return true;
} }*/
return false; return false;
}, },
@ -1136,9 +1140,6 @@ var httpObserver = {
return; return;
} }
var reqDataKey = location.host + 'reqdata';
var URI = channel.URI; var URI = channel.URI;
var channelData, result; var channelData, result;
@ -1148,14 +1149,7 @@ var httpObserver = {
} }
try { try {
/*[ channelData = channel.getProperty(this.REQDATAKEY);
type,
tabId,
sourceTabId - given if it was a popup,
frameId,
parentFrameId
]*/
channelData = channel.getProperty(reqDataKey);
} catch (ex) { } catch (ex) {
return; return;
} }
@ -1164,7 +1158,7 @@ var httpObserver = {
return; return;
} }
if ( (1 << channelData[0] & this.VALID_CSP_TARGETS) === 0 ) { if ( (1 << channelData[4] & this.VALID_CSP_TARGETS) === 0 ) {
return; return;
} }
@ -1178,9 +1172,9 @@ var httpObserver = {
result = vAPI.net.onHeadersReceived.callback({ result = vAPI.net.onHeadersReceived.callback({
hostname: URI.asciiHost, hostname: URI.asciiHost,
parentFrameId: channelData[4], parentFrameId: channelData[1],
responseHeaders: result ? [{name: topic, value: result}] : [], responseHeaders: result ? [{name: topic, value: result}] : [],
tabId: channelData[1], tabId: channelData[3],
url: URI.asciiSpec url: URI.asciiSpec
}); });
@ -1197,71 +1191,64 @@ var httpObserver = {
// http-on-opening-request // http-on-opening-request
var lastRequest = this.lastRequest; var lastRequest = this.lastRequest[0];
if ( lastRequest.url !== URI.spec ) {
if ( this.lastRequest[1].url === URI.spec ) {
lastRequest = this.lastRequest[1];
} else {
lastRequest.url = null;
}
}
if ( lastRequest.url === null ) { if ( lastRequest.url === null ) {
this.handleRequest(channel, URI, { lastRequest.type = channel.loadInfo && channel.loadInfo.contentPolicyType || 1;
result = this.handleRequest(channel, URI, {
tabId: vAPI.noTabId, tabId: vAPI.noTabId,
type: channel.loadInfo && channel.loadInfo.contentPolicyType || 1 type: lastRequest.type
}); });
return;
}
// Important! When loading file via XHR for mirroring, if ( result === true ) {
// the URL will be the same, so it could fall into an infinite loop return;
lastRequest.url = null;
var sourceTabId = null;
// Popup candidate (only for main_frame type)
if ( lastRequest.openerURL ) {
for ( var tab of vAPI.tabs.getAll() ) {
var tabURI = tab.linkedBrowser.currentURI;
// Probably isn't the best method to identify the source tab
if ( tabURI.spec !== lastRequest.openerURL ) {
continue;
}
sourceTabId = vAPI.tabs.getTabId(tab);
if ( sourceTabId !== lastRequest.tabId ) {
break;
}
sourceTabId = null;
} }
if ( this.handlePopup(channel.URI, lastRequest.tabId, sourceTabId) ) { if ( channel instanceof Ci.nsIWritablePropertyBag === false ) {
channel.cancel(this.ABORT);
return; return;
} }
// Carry data for behind-the-scene redirects
channel.setProperty(
this.REQDATAKEY,
[lastRequest.type, vAPI.noTabId, null, 0, -1]
);
return;
} }
if ( lastRequest.type === this.MAIN_FRAME && lastRequest.frameId === 0 ) { // Important! When loading file via XHR for mirroring,
vAPI.tabs.onNavigation({ // the URL will be the same, so it could fall into an infinite loop
frameId: 0, lastRequest.url = null;
tabId: lastRequest.tabId,
url: URI.asciiSpec
});
}
if ( this.handleRequest(channel, URI, lastRequest) ) { if ( this.handleRequest(channel, URI, lastRequest) ) {
return; return;
} }
if ( vAPI.fennec && lastRequest.type === this.MAIN_FRAME && lastRequest.frameId === 0 ) {
vAPI.tabs.onNavigation({
frameId: 0,
tabId: lastRequest.tabId,
url: URI.asciiSpec
});
}
// If request is not handled we may use the data in on-modify-request // If request is not handled we may use the data in on-modify-request
if ( channel instanceof Ci.nsIWritablePropertyBag ) { if ( channel instanceof Ci.nsIWritablePropertyBag ) {
channel.setProperty( channel.setProperty(this.REQDATAKEY, [
reqDataKey, lastRequest.frameId,
[ lastRequest.parentFrameId,
lastRequest.type, lastRequest.sourceTabId,
lastRequest.tabId, lastRequest.tabId,
sourceTabId, lastRequest.type
lastRequest.frameId, ]);
lastRequest.parentFrameId
]
);
} }
}, },
@ -1271,12 +1258,6 @@ var httpObserver = {
// If error thrown, the redirect will fail // If error thrown, the redirect will fail
try { try {
// skip internal redirects?
/*if ( flags & 4 ) {
console.log('internal redirect skipped');
return;
}*/
var URI = newChannel.URI; var URI = newChannel.URI;
if ( !URI.schemeIs('http') && !URI.schemeIs('https') ) { if ( !URI.schemeIs('http') && !URI.schemeIs('https') ) {
@ -1287,21 +1268,18 @@ var httpObserver = {
return; return;
} }
// TODO: what if a behind-the-scene request is being redirected? var channelData = oldChannel.getProperty(this.REQDATAKEY);
// This data is present only for tabbed requests, so if this throws,
// the redirection won't be evaluated and canceled (if necessary)
var channelData = oldChannel.getProperty(location.host + 'reqdata');
if ( this.handlePopup(URI, channelData[1], channelData[2]) ) { if ( this.handlePopup(URI, channelData[3], channelData[2]) ) {
result = this.ABORT; result = this.ABORT;
return; return;
} }
var details = { var details = {
type: channelData[0], frameId: channelData[0],
tabId: channelData[1], parentFrameId: channelData[1],
frameId: channelData[3], tabId: channelData[3],
parentFrameId: channelData[4] type: channelData[4]
}; };
if ( this.handleRequest(newChannel, URI, details) ) { if ( this.handleRequest(newChannel, URI, details) ) {
@ -1311,7 +1289,7 @@ var httpObserver = {
// Carry the data on in case of multiple redirects // Carry the data on in case of multiple redirects
if ( newChannel instanceof Ci.nsIWritablePropertyBag ) { if ( newChannel instanceof Ci.nsIWritablePropertyBag ) {
newChannel.setProperty(location.host + 'reqdata', channelData); newChannel.setProperty(this.REQDATAKEY, channelData);
} }
} catch (ex) { } catch (ex) {
// console.error(ex); // console.error(ex);
@ -1336,13 +1314,46 @@ vAPI.net.registerListeners = function() {
var shouldLoadListenerMessageName = location.host + ':shouldLoad'; var shouldLoadListenerMessageName = location.host + ':shouldLoad';
var shouldLoadListener = function(e) { var shouldLoadListener = function(e) {
var details = e.data; var details = e.data;
var tabId = vAPI.tabs.getTabId(e.target);
var sourceTabId = null;
// Popup candidate
if ( details.openerURL ) {
for ( var tab of vAPI.tabs.getAll() ) {
var URI = tab.linkedBrowser.currentURI;
// Probably isn't the best method to identify the source tab
if ( URI.spec !== details.openerURL ) {
continue;
}
sourceTabId = vAPI.tabs.getTabId(tab);
if ( sourceTabId === tabId ) {
sourceTabId = null;
continue;
}
URI = Services.io.newURI(details.url, null, null);
if ( httpObserver.handlePopup(URI, tabId, sourceTabId) ) {
return;
}
break;
}
}
var lastRequest = httpObserver.lastRequest; var lastRequest = httpObserver.lastRequest;
lastRequest.url = details.url; lastRequest[1] = lastRequest[0];
lastRequest.type = details.type; lastRequest[0] = {
lastRequest.tabId = vAPI.tabs.getTabId(e.target); frameId: details.frameId,
lastRequest.frameId = details.frameId; parentFrameId: details.parentFrameId,
lastRequest.parentFrameId = details.parentFrameId; sourceTabId: sourceTabId,
lastRequest.openerURL = details.openerURL; tabId: tabId,
type: details.type,
url: details.url
};
}; };
vAPI.messaging.globalMessageManager.addMessageListener( vAPI.messaging.globalMessageManager.addMessageListener(
@ -1373,215 +1384,301 @@ vAPI.toolbarButton = {
tabs: {/*tabId: {badge: 0, img: boolean}*/} tabs: {/*tabId: {badge: 0, img: boolean}*/}
}; };
/******************************************************************************/ if (vAPI.fennec) {
// Menu UI
vAPI.toolbarButton.menuItemIds = new WeakMap();
vAPI.toolbarButton.getMenuItemLabel = function(tabId) {
var label = this.label;
if (tabId !== undefined) {
var tabDetails = this.tabs[tabId];
if (tabDetails) {
if (tabDetails.img) {
if (tabDetails.badge) {
label = label + " (" + tabDetails.badge + ")";
}
} else {
label = label + " (" + vAPI.i18n("fennecMenuItemBlockingOff") + ")";
}
}
}
return label;
}
vAPI.toolbarButton.init = function() { vAPI.toolbarButton.init = function() {
var CustomizableUI; // Only actually expecting one window under Fennec (note, not tabs, windows)
try { for (var win of vAPI.tabs.getWindows()) {
CustomizableUI = Cu.import('resource:///modules/CustomizableUI.jsm', null).CustomizableUI; this.addToWindow(win, this.getMenuItemLabel());
} catch (ex) { }
return;
cleanupTasks.push(this.cleanUp);
} }
this.defaultArea = CustomizableUI.AREA_NAVBAR; vAPI.toolbarButton.addToWindow = function(win, label) {
this.styleURI = [ var id = win.NativeWindow.menu.add({
'#' + this.id + ' {', name: label,
'list-style-image: url(', callback: this.onClick
vAPI.getURL('img/browsericons/icon16-off.svg'), });
');', this.menuItemIds.set(win, id);
'}', }
'#' + this.viewId + ', #' + this.viewId + ' > iframe {',
'width: 160px;',
'height: 290px;',
'overflow: hidden !important;',
'}'
];
var platformVersion = Services.appinfo.platformVersion;
if ( Services.vc.compare(platformVersion, '36.0') < 0 ) {
this.styleURI.push(
'#' + this.id + '[badge]:not([badge=""])::after {',
'position: absolute;',
'margin-left: -16px;',
'margin-top: 3px;',
'padding: 1px 2px;',
'font-size: 9px;',
'font-weight: bold;',
'color: #fff;',
'background: #666;',
'content: attr(badge);',
'}'
);
} else {
this.CUIEvents = {};
var updateBadge = function() { vAPI.toolbarButton.cleanUp = function() {
var wId = vAPI.toolbarButton.id; for (var win of vAPI.tabs.getWindows()) {
var buttonInPanel = CustomizableUI.getWidget(wId).areaType === CustomizableUI.TYPE_MENU_PANEL; vAPI.toolbarButton.removeFromWindow(win);
}
}
for ( var win of vAPI.tabs.getWindows() ) { vAPI.toolbarButton.removeFromWindow = function(win) {
var button = win.document.getElementById(wId); var id = this.menuItemIds.get(win);
if ( buttonInPanel ) { if (id) {
button.classList.remove('badged-button'); win.NativeWindow.menu.remove(id);
continue; this.menuItemIds.delete(win);
} }
if ( button === null ) { }
continue;
}
button.classList.add('badged-button');
}
if ( buttonInPanel ) { vAPI.toolbarButton.updateState = function (win, tabId) {
return; var id = this.menuItemIds.get(win);
} if (!id) {
return;
}
win.NativeWindow.menu.update(id, { name: this.getMenuItemLabel(tabId) });
}
// Anonymous elements need some time to be reachable vAPI.toolbarButton.onClick = function() {
setTimeout(this.updateBadgeStyle, 50); var win = Services.wm.getMostRecentWindow('navigator:browser');
}.bind(this.CUIEvents); var curTabId = vAPI.tabs.getTabId(getTabBrowser(win).selectedTab);
vAPI.tabs.open({ url: vAPI.getURL("popup.html?tabId=" + curTabId), index: -1, select: true });
}
} else {
// Toolbar button UI
this.CUIEvents.onCustomizeEnd = updateBadge; /******************************************************************************/
this.CUIEvents.onWidgetUnderflow = updateBadge;
this.CUIEvents.updateBadgeStyle = function() { vAPI.toolbarButton.init = function() {
var css = [ var CustomizableUI;
'background: #666', try {
'color: #fff' CustomizableUI = Cu.import('resource:///modules/CustomizableUI.jsm', null).CustomizableUI;
].join(';'); } catch (ex) {
return;
}
for ( var win of vAPI.tabs.getWindows() ) { this.defaultArea = CustomizableUI.AREA_NAVBAR;
var button = win.document.getElementById(vAPI.toolbarButton.id); this.styleURI = [
if ( button === null ) { '#' + this.id + ' {',
continue; 'list-style-image: url(',
vAPI.getURL('img/browsericons/icon16-off.svg'),
');',
'}',
'#' + this.viewId + ', #' + this.viewId + ' > iframe {',
'width: 160px;',
'height: 290px;',
'overflow: hidden !important;',
'}'
];
var platformVersion = Services.appinfo.platformVersion;
if ( Services.vc.compare(platformVersion, '36.0') < 0 ) {
this.styleURI.push(
'#' + this.id + '[badge]:not([badge=""])::after {',
'position: absolute;',
'margin-left: -16px;',
'margin-top: 3px;',
'padding: 1px 2px;',
'font-size: 9px;',
'font-weight: bold;',
'color: #fff;',
'background: #666;',
'content: attr(badge);',
'}'
);
} else {
this.CUIEvents = {};
this.CUIEvents.onCustomizeEnd = function() {
var wId = vAPI.toolbarButton.id;
var buttonInPanel = CustomizableUI.getWidget(wId).areaType === CustomizableUI.TYPE_MENU_PANEL;
for ( var win of vAPI.tabs.getWindows() ) {
var button = win.document.getElementById(wId);
if ( buttonInPanel ) {
button.classList.remove('badged-button');
continue;
}
if ( button === null ) {
continue;
}
button.classList.add('badged-button');
} }
var badge = button.ownerDocument.getAnonymousElementByAttribute(
button, if ( buttonInPanel ) {
'class',
'toolbarbutton-badge'
);
if ( !badge ) {
return; return;
} }
badge.style.cssText = css; // Anonymous elements need some time to be reachable
} setTimeout(this.updateBadgeStyle, 250);
}; }.bind(this.CUIEvents);
this.onCreated = function(button) { this.CUIEvents.updateBadgeStyle = function() {
button.setAttribute('badge', ''); var css = [
setTimeout(this.CUIEvents.onCustomizeEnd, 50); 'background: #666',
}; 'color: #fff'
].join(';');
CustomizableUI.addListener(this.CUIEvents); for ( var win of vAPI.tabs.getWindows() ) {
} var button = win.document.getElementById(vAPI.toolbarButton.id);
if ( button === null ) {
this.styleURI = Services.io.newURI( continue;
'data:text/css,' + encodeURIComponent(this.styleURI.join('')), }
null, var badge = button.ownerDocument.getAnonymousElementByAttribute(
null button,
); 'class',
'toolbarbutton-badge'
);
if ( !badge ) {
return;
}
this.closePopup = function({target}) { badge.style.cssText = css;
CustomizableUI.hidePanelForNode( }
target.ownerDocument.getElementById(vAPI.toolbarButton.viewId) };
);
};
CustomizableUI.createWidget(this); this.onCreated = function(button) {
vAPI.messaging.globalMessageManager.addMessageListener( button.setAttribute('badge', '');
location.host + ':closePopup', setTimeout(this.CUIEvents.onCustomizeEnd, 250);
this.closePopup };
);
cleanupTasks.push(function() { CustomizableUI.addListener(this.CUIEvents);
if ( this.CUIEvents ) {
CustomizableUI.removeListener(this.CUIEvents);
} }
CustomizableUI.destroyWidget(this.id); this.styleURI = Services.io.newURI(
vAPI.messaging.globalMessageManager.removeMessageListener( 'data:text/css,' + encodeURIComponent(this.styleURI.join('')),
null,
null
);
this.closePopup = function({target}) {
CustomizableUI.hidePanelForNode(
target.ownerDocument.getElementById(vAPI.toolbarButton.viewId)
);
};
CustomizableUI.createWidget(this);
vAPI.messaging.globalMessageManager.addMessageListener(
location.host + ':closePopup', location.host + ':closePopup',
this.closePopup this.closePopup
); );
for ( var win of vAPI.tabs.getWindows() ) { cleanupTasks.push(function() {
var panel = win.document.getElementById(this.viewId); if ( this.CUIEvents ) {
panel.parentNode.removeChild(panel); CustomizableUI.removeListener(this.CUIEvents);
win.QueryInterface(Ci.nsIInterfaceRequestor) }
.getInterface(Ci.nsIDOMWindowUtils)
.removeSheet(this.styleURI, 1);
}
}.bind(this));
};
/******************************************************************************/ CustomizableUI.destroyWidget(this.id);
vAPI.messaging.globalMessageManager.removeMessageListener(
location.host + ':closePopup',
this.closePopup
);
vAPI.toolbarButton.onBeforeCreated = function(doc) { for ( var win of vAPI.tabs.getWindows() ) {
var panel = doc.createElement('panelview'); var panel = win.document.getElementById(this.viewId);
panel.setAttribute('id', this.viewId); panel.parentNode.removeChild(panel);
win.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils)
.removeSheet(this.styleURI, 1);
}
}.bind(this));
};
/******************************************************************************/
vAPI.toolbarButton.onBeforeCreated = function(doc) {
var panel = doc.createElement('panelview');
panel.setAttribute('id', this.viewId);
var iframe = doc.createElement('iframe'); var iframe = doc.createElement('iframe');
iframe.setAttribute('type', 'content'); iframe.setAttribute('type', 'content');
doc.getElementById('PanelUI-multiView') doc.getElementById('PanelUI-multiView')
.appendChild(panel) .appendChild(panel)
.appendChild(iframe); .appendChild(iframe);
var updateTimer = null; var updateTimer = null;
var delayedResize = function() { var delayedResize = function() {
if ( updateTimer ) { if ( updateTimer ) {
return; return;
} }
updateTimer = setTimeout(resizePopup, 10); updateTimer = setTimeout(resizePopup, 10);
}; };
var resizePopup = function() { var resizePopup = function() {
updateTimer = null; updateTimer = null;
var body = iframe.contentDocument.body; var body = iframe.contentDocument.body;
panel.parentNode.style.maxWidth = 'none'; panel.parentNode.style.maxWidth = 'none';
// https://github.com/gorhill/uBlock/issues/730 // https://github.com/gorhill/uBlock/issues/730
// Voodoo programming: this recipe works // Voodoo programming: this recipe works
panel.style.height = iframe.style.height = body.clientHeight.toString() + 'px'; panel.style.height = iframe.style.height = body.clientHeight.toString() + 'px';
panel.style.width = iframe.style.width = body.clientWidth.toString() + 'px'; panel.style.width = iframe.style.width = body.clientWidth.toString() + 'px';
if ( iframe.clientHeight !== body.clientHeight || iframe.clientWidth !== body.clientWidth ) { if ( iframe.clientHeight !== body.clientHeight || iframe.clientWidth !== body.clientWidth ) {
delayedResize(); delayedResize();
} }
}; };
var onPopupReady = function() { var onPopupReady = function() {
var win = this.contentWindow; var win = this.contentWindow;
if ( !win || win.location.host !== location.host ) { if ( !win || win.location.host !== location.host ) {
return; return;
} }
new win.MutationObserver(delayedResize).observe(win.document.body, { new win.MutationObserver(delayedResize).observe(win.document.body, {
attributes: true, attributes: true,
characterData: true, characterData: true,
subtree: true subtree: true
}); });
delayedResize();
};
delayedResize(); iframe.addEventListener('load', onPopupReady, true);
doc.defaultView.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils)
.loadSheet(this.styleURI, 1);
}; };
iframe.addEventListener('load', onPopupReady, true); /******************************************************************************/
doc.defaultView.QueryInterface(Ci.nsIInterfaceRequestor) vAPI.toolbarButton.onViewShowing = function({target}) {
.getInterface(Ci.nsIDOMWindowUtils) target.firstChild.setAttribute('src', vAPI.getURL('popup.html'));
.loadSheet(this.styleURI, 1); };
};
/******************************************************************************/ /******************************************************************************/
vAPI.toolbarButton.onViewShowing = function({target}) { vAPI.toolbarButton.onViewHiding = function({target}) {
target.firstChild.setAttribute('src', vAPI.getURL('popup.html')); target.parentNode.style.maxWidth = '';
}; target.firstChild.setAttribute('src', 'about:blank');
};
/******************************************************************************/ vAPI.toolbarButton.updateState = function(win, tabId) {
var button = win.document.getElementById(this.id);
vAPI.toolbarButton.onViewHiding = function({target}) { if ( !button ) {
target.parentNode.style.maxWidth = ''; return;
target.firstChild.setAttribute('src', 'about:blank'); }
};
var icon = this.tabs[tabId];
button.setAttribute('badge', icon && icon.badge || '');
if ( !icon || !icon.img ) {
icon = '';
}
else {
icon = 'url(' + vAPI.getURL('img/browsericons/icon16.svg') + ')';
}
button.style.listStyleImage = icon;
}
}
/******************************************************************************/ /******************************************************************************/
@ -1716,7 +1813,7 @@ vAPI.contextMenu.create = function(details, callback) {
if ( gContextMenu.inFrame ) { if ( gContextMenu.inFrame ) {
details.tagName = 'iframe'; details.tagName = 'iframe';
// Probably won't work with e01s // Probably won't work with e10s
details.frameUrl = gContextMenu.focusedWindow.location.href; details.frameUrl = gContextMenu.focusedWindow.location.href;
} else if ( gContextMenu.onImage ) { } else if ( gContextMenu.onImage ) {
details.tagName = 'img'; details.tagName = 'img';

Loading…
Cancel
Save