Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: common.js

Issue 29321336: Issue 2381 - Added share overlay to options page (Closed)
Left Patch Set: Rebased to 312559088567 Created July 16, 2015, 1:41 p.m.
Right Patch Set: Rebased to 4a68f2a456d6 and set strict mode in common.js Created Sept. 23, 2015, 1:54 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « background.js ('k') | firstRun.html » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17
18 "use strict";
17 19
18 (function(global) 20 (function(global)
19 { 21 {
20 global.E = function E(id) 22 global.E = function E(id)
21 { 23 {
22 return document.getElementById(id); 24 return document.getElementById(id);
23 } 25 }
24 26
25 global.getDocLink = function(link, callback) 27 global.getDocLink = function(link, callback)
26 { 28 {
(...skipping 18 matching lines...) Expand all
45 47
46 global.openSharePopup = function(url) 48 global.openSharePopup = function(url)
47 { 49 {
48 var glassPane = E("glass-pane"); 50 var glassPane = E("glass-pane");
49 if (!glassPane) 51 if (!glassPane)
50 { 52 {
51 glassPane = document.createElement("div"); 53 glassPane = document.createElement("div");
52 glassPane.setAttribute("id", "glass-pane"); 54 glassPane.setAttribute("id", "glass-pane");
53 document.body.appendChild(glassPane); 55 document.body.appendChild(glassPane);
54 } 56 }
57
55 var iframe = E("share-popup"); 58 var iframe = E("share-popup");
56 if (!iframe) 59 if (!iframe)
57 { 60 {
58 iframe = document.createElement("iframe"); 61 iframe = document.createElement("iframe");
59 iframe.setAttribute("id", "share-popup"); 62 iframe.setAttribute("id", "share-popup");
60 iframe.setAttribute("scrolling", "no"); 63 iframe.setAttribute("scrolling", "no");
61 glassPane.appendChild(iframe); 64 glassPane.appendChild(iframe);
62 } 65 }
66
67 // Firefox 38+ no longer allows messaging using postMessage so we need
68 // to have a fake top level frame to avoid problems with scripts that try to
69 // communicate with the first-run page
70 var isGecko = ("Components" in window);
71 if (isGecko)
72 {
73 try
74 {
75 var Ci = Components.interfaces;
76 iframe.contentWindow
77 .QueryInterface(Ci.nsIInterfaceRequestor)
78 .getInterface(Ci.nsIDocShell)
79 .setIsBrowserInsideApp(Ci.nsIScriptSecurityManager.UNKNOWN_APP_ID);
80 }
81 catch(ex)
82 {
83 console.error(ex);
84 }
85 }
86
63 var popupMessageReceived = false; 87 var popupMessageReceived = false;
88 function resizePopup(width, height)
89 {
90 iframe.width = width;
91 iframe.height = height;
92 iframe.style.marginTop = -height / 2 + "px";
93 iframe.style.marginLeft = -width / 2 + "px";
94 popupMessageReceived = true;
95 window.removeEventListener("message", popupMessageListener);
96 }
64 97
65 var popupMessageListener = function(event) 98 var popupMessageListener = function(event)
66 { 99 {
67 if (!/[.\/]adblockplus\.org$/.test(event.origin) 100 if (!/[.\/]adblockplus\.org$/.test(event.origin)
68 || !("width" in event.data) 101 || !("width" in event.data)
69 || !("height" in event.data)) 102 || !("height" in event.data))
70 return; 103 return;
71 104
72 var width = event.data.width; 105 resizePopup(event.data.width, event.data.height);
73 var height = event.data.height;
74 iframe.width = width;
75 iframe.height = height;
76 iframe.style.marginTop = -height/2 + "px";
77 iframe.style.marginLeft = -width/2 + "px";
78 popupMessageReceived = true;
79 window.removeEventListener("message", popupMessageListener);
80 }; 106 };
81 // Firefox requires last parameter to be true to be triggered by unprivilege d pages 107 // Firefox requires last parameter to be true to be triggered by
108 // unprivileged pages
82 window.addEventListener("message", popupMessageListener, false, true); 109 window.addEventListener("message", popupMessageListener, false, true);
83 110
84 var popupLoadListener = function() 111 var popupLoadListener = function()
85 { 112 {
113 if (!popupMessageReceived && isGecko)
114 {
115 var rootElement = iframe.contentDocument.documentElement;
116 var width = rootElement.dataset.width;
117 var height = rootElement.dataset.height;
118 if (width && height)
119 resizePopup(width, height);
120 }
121
86 if (popupMessageReceived) 122 if (popupMessageReceived)
87 { 123 {
88 iframe.className = "visible"; 124 iframe.className = "visible";
89 125
90 var popupCloseListener = function() 126 var popupCloseListener = function()
91 { 127 {
92 iframe.className = glassPane.className = ""; 128 iframe.className = glassPane.className = "";
93 document.removeEventListener("click", popupCloseListener); 129 document.removeEventListener("click", popupCloseListener);
94 }; 130 };
95 document.addEventListener("click", popupCloseListener, false); 131 document.addEventListener("click", popupCloseListener, false);
96 } 132 }
97 else 133 else
98 { 134 {
99 glassPane.className = ""; 135 glassPane.className = "";
100 window.removeEventListener("message", popupMessageListener); 136 window.removeEventListener("message", popupMessageListener);
101 } 137 }
102 138
103 iframe.removeEventListener("load", popupLoadListener); 139 iframe.removeEventListener("load", popupLoadListener);
104 }; 140 };
105 iframe.addEventListener("load", popupLoadListener, false); 141 iframe.addEventListener("load", popupLoadListener, false);
106 142
107 iframe.src = url; 143 iframe.src = url;
108 glassPane.className = "visible"; 144 glassPane.className = "visible";
109 } 145 }
110 })(this); 146 })(this);
LEFTRIGHT

Powered by Google App Engine
This is Rietveld