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 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:
View unified diff | Download patch
« no previous file with comments | « background.js ('k') | firstRun.html » ('j') | no next file with comments »
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
18 "use strict";
19
20 (function(global)
21 {
22 global.E = function E(id)
23 {
24 return document.getElementById(id);
25 }
26
27 global.getDocLink = function(link, callback)
28 {
29 ext.backgroundPage.sendMessage({
30 type: "app.get",
31 what: "doclink",
32 link: link
33 }, callback);
34 }
35
36 global.checkShareResource = function(url, callback)
37 {
38 ext.backgroundPage.sendMessage(
39 {
40 type: "filters.blocked",
41 url: url,
42 requestType: "SCRIPT",
43 docDomain: "adblockplus.org",
44 thirdParty: true
45 }, callback);
46 }
47
48 global.openSharePopup = function(url)
49 {
50 var glassPane = E("glass-pane");
51 if (!glassPane)
52 {
53 glassPane = document.createElement("div");
54 glassPane.setAttribute("id", "glass-pane");
55 document.body.appendChild(glassPane);
56 }
57
58 var iframe = E("share-popup");
59 if (!iframe)
60 {
61 iframe = document.createElement("iframe");
62 iframe.setAttribute("id", "share-popup");
63 iframe.setAttribute("scrolling", "no");
64 glassPane.appendChild(iframe);
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
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 }
97
98 var popupMessageListener = function(event)
99 {
100 if (!/[.\/]adblockplus\.org$/.test(event.origin)
101 || !("width" in event.data)
102 || !("height" in event.data))
103 return;
104
105 resizePopup(event.data.width, event.data.height);
106 };
107 // Firefox requires last parameter to be true to be triggered by
108 // unprivileged pages
109 window.addEventListener("message", popupMessageListener, false, true);
110
111 var popupLoadListener = function()
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
122 if (popupMessageReceived)
123 {
124 iframe.className = "visible";
125
126 var popupCloseListener = function()
127 {
128 iframe.className = glassPane.className = "";
129 document.removeEventListener("click", popupCloseListener);
130 };
131 document.addEventListener("click", popupCloseListener, false);
132 }
133 else
134 {
135 glassPane.className = "";
136 window.removeEventListener("message", popupMessageListener);
137 }
138
139 iframe.removeEventListener("load", popupLoadListener);
140 };
141 iframe.addEventListener("load", popupLoadListener, false);
142
143 iframe.src = url;
144 glassPane.className = "visible";
145 }
146 })(this);
OLDNEW
« no previous file with comments | « background.js ('k') | firstRun.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld