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

Side by Side Diff: common.js

Issue 29321336: Issue 2381 - Added share overlay to options page (Closed)
Patch Set: Rebased to a40c644fc2aa Created July 29, 2015, 12:27 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « background.js ('k') | firstRun.html » ('j') | options.js » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
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/>.
16 */
17
saroyanm 2015/09/08 17:33:49 I think we should use "strict" here as well, but n
Thomas Greiner 2015/09/23 14:03:05 The reason for that is that adding strict mode aft
18 (function(global)
19 {
20 global.E = function E(id)
21 {
22 return document.getElementById(id);
23 }
24
25 global.getDocLink = function(link, callback)
26 {
27 ext.backgroundPage.sendMessage({
28 type: "app.get",
29 what: "doclink",
30 link: link
31 }, callback);
32 }
33
34 global.checkShareResource = function(url, callback)
35 {
36 ext.backgroundPage.sendMessage(
37 {
38 type: "filters.blocked",
39 url: url,
40 requestType: "SCRIPT",
41 docDomain: "adblockplus.org",
42 thirdParty: true
43 }, callback);
44 }
45
46 global.openSharePopup = function(url)
47 {
48 var glassPane = E("glass-pane");
49 if (!glassPane)
50 {
51 glassPane = document.createElement("div");
52 glassPane.setAttribute("id", "glass-pane");
53 document.body.appendChild(glassPane);
54 }
55
56 var iframe = E("share-popup");
57 if (!iframe)
58 {
59 iframe = document.createElement("iframe");
60 iframe.setAttribute("id", "share-popup");
61 iframe.setAttribute("scrolling", "no");
62 glassPane.appendChild(iframe);
63 }
64
65 // Firefox 38+ no longer allows messaging using postMessage so we need
66 // to have a fake top level frame to avoid problems with scripts that try to
67 // communicate with the first-run page
68 var isGecko = ("Components" in window);
69 if (isGecko)
70 {
71 try
72 {
73 var Ci = Components.interfaces;
74 iframe.contentWindow
75 .QueryInterface(Ci.nsIInterfaceRequestor)
76 .getInterface(Ci.nsIDocShell)
77 .setIsBrowserInsideApp(Ci.nsIScriptSecurityManager.UNKNOWN_APP_ID);
78 }
79 catch(ex)
80 {
81 console.error(ex);
82 }
83 }
84
85 var popupMessageReceived = false;
86 function resizePopup(width, height)
87 {
88 iframe.width = width;
89 iframe.height = height;
90 iframe.style.marginTop = -height / 2 + "px";
91 iframe.style.marginLeft = -width / 2 + "px";
92 popupMessageReceived = true;
93 window.removeEventListener("message", popupMessageListener);
94 }
95
96 var popupMessageListener = function(event)
97 {
98 if (!/[.\/]adblockplus\.org$/.test(event.origin)
99 || !("width" in event.data)
100 || !("height" in event.data))
101 return;
102
103 resizePopup(event.data.width, event.data.height);
104 };
105 // Firefox requires last parameter to be true to be triggered by
106 // unprivileged pages
107 window.addEventListener("message", popupMessageListener, false, true);
108
109 var popupLoadListener = function()
110 {
111 if (!popupMessageReceived && isGecko)
112 {
113 var rootElement = iframe.contentDocument.documentElement;
114 var width = rootElement.dataset.width;
115 var height = rootElement.dataset.height;
116 if (width && height)
117 resizePopup(width, height);
118 }
119
120 if (popupMessageReceived)
121 {
122 iframe.className = "visible";
saroyanm 2015/09/08 17:33:49 This implementation is inconsistent, with other si
Thomas Greiner 2015/09/23 14:03:05 Agreed, let's work on consistency changes separate
123
124 var popupCloseListener = function()
125 {
126 iframe.className = glassPane.className = "";
127 document.removeEventListener("click", popupCloseListener);
128 };
129 document.addEventListener("click", popupCloseListener, false);
130 }
131 else
132 {
133 glassPane.className = "";
134 window.removeEventListener("message", popupMessageListener);
135 }
136
137 iframe.removeEventListener("load", popupLoadListener);
138 };
139 iframe.addEventListener("load", popupLoadListener, false);
140
141 iframe.src = url;
142 glassPane.className = "visible";
143 }
144 })(this);
OLDNEW
« no previous file with comments | « background.js ('k') | firstRun.html » ('j') | options.js » ('J')

Powered by Google App Engine
This is Rietveld