diff options
author | Ruben Rodriguez <ruben@gnu.org> | 2017-09-01 16:35:50 -0400 |
---|---|---|
committer | Ruben Rodriguez <ruben@gnu.org> | 2017-09-01 16:35:50 -0400 |
commit | e8730f68798f173bd4d1c2f9b7ce02985e3fd771 (patch) | |
tree | 711132ed84ef8ae9e0621de5436a6818a5fa1e12 /data/extensions/spyblock@gnu.org/chrome/content/ui/common.js | |
parent | edde38bbb0e0afb9b8a78c002996c758fb6023b6 (diff) |
SpyBlock updated to 2.9.1
Diffstat (limited to 'data/extensions/spyblock@gnu.org/chrome/content/ui/common.js')
-rw-r--r-- | data/extensions/spyblock@gnu.org/chrome/content/ui/common.js | 154 |
1 files changed, 154 insertions, 0 deletions
diff --git a/data/extensions/spyblock@gnu.org/chrome/content/ui/common.js b/data/extensions/spyblock@gnu.org/chrome/content/ui/common.js new file mode 100644 index 0000000..ec20ede --- /dev/null +++ b/data/extensions/spyblock@gnu.org/chrome/content/ui/common.js @@ -0,0 +1,154 @@ +/* + * This file is part of Adblock Plus <https://adblockplus.org/>, + * Copyright (C) 2006-2017 eyeo GmbH + * + * Adblock Plus is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * Adblock Plus is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. + */ + +/* globals Components */ + +"use strict"; + +function E(id) +{ + return document.getElementById(id); +} + +function getDocLink(link, callback) +{ + ext.backgroundPage.sendMessage({ + type: "app.get", + what: "doclink", + link + }, callback); +} + +function checkShareResource(url, callback) +{ + ext.backgroundPage.sendMessage({ + type: "filters.blocked", + url, + requestType: "SCRIPT", + docDomain: "adblockplus.org", + thirdParty: true + }, callback); +} + +function openSharePopup(url) +{ + let glassPane = E("glass-pane"); + if (!glassPane) + { + glassPane = document.createElement("div"); + glassPane.setAttribute("id", "glass-pane"); + document.body.appendChild(glassPane); + } + + let iframe = E("share-popup"); + if (!iframe) + { + iframe = document.createElement("iframe"); + iframe.setAttribute("id", "share-popup"); + iframe.setAttribute("scrolling", "no"); + glassPane.appendChild(iframe); + } + + // Firefox 38+ no longer allows messaging using postMessage so we need + // to have a fake top level frame to avoid problems with scripts that try to + // communicate with the first-run page + let isGecko = ("Components" in window); + if (isGecko) + { + try + { + let Ci = Components.interfaces; + let docShell = iframe.contentWindow + .QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIDocShell); + + if (typeof docShell.frameType != "undefined") + { + // Gecko 47+ + docShell.frameType = docShell.FRAME_TYPE_BROWSER; + } + else + { + // Legacy branch + docShell.setIsBrowserInsideApp( + Ci.nsIScriptSecurityManager.UNKNOWN_APP_ID + ); + } + } + catch (ex) + { + console.error(ex); + } + } + + let popupMessageReceived = false; + function resizePopup(width, height) + { + iframe.width = width; + iframe.height = height; + iframe.style.marginTop = -height / 2 + "px"; + iframe.style.marginLeft = -width / 2 + "px"; + popupMessageReceived = true; + window.removeEventListener("message", popupMessageListener); + } + + let popupMessageListener = function(event) + { + if (!/[./]adblockplus\.org$/.test(event.origin) || + !("width" in event.data) || !("height" in event.data)) + return; + + resizePopup(event.data.width, event.data.height); + }; + // Firefox requires last parameter to be true to be triggered by + // unprivileged pages + window.addEventListener("message", popupMessageListener, false, true); + + let popupLoadListener = function() + { + if (!popupMessageReceived && isGecko) + { + let rootElement = iframe.contentDocument.documentElement; + let {width, height} = rootElement.dataset; + if (width && height) + resizePopup(width, height); + } + + if (popupMessageReceived) + { + iframe.className = "visible"; + + let popupCloseListener = function() + { + iframe.className = glassPane.className = ""; + document.removeEventListener("click", popupCloseListener); + }; + document.addEventListener("click", popupCloseListener, false); + } + else + { + glassPane.className = ""; + window.removeEventListener("message", popupMessageListener); + } + + iframe.removeEventListener("load", popupLoadListener); + }; + iframe.addEventListener("load", popupLoadListener, false); + + iframe.src = url; + glassPane.className = "visible"; +} |