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

Side by Side Diff: lib/appSupport.js

Issue 29322679: Issue 1730 - Fixed abp:subscribe functionality with e10s (Closed)
Patch Set: Created July 20, 2015, 3:19 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
OLDNEW
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
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 let browser = (exports.getBrowser ? exports.getBrowser(window) : null); 205 let browser = (exports.getBrowser ? exports.getBrowser(window) : null);
206 if (browser) 206 if (browser)
207 { 207 {
208 let listeners = progressListeners.get(window); 208 let listeners = progressListeners.get(window);
209 for (let i = 0; i < listeners.length; i++) 209 for (let i = 0; i < listeners.length; i++)
210 browser.removeProgressListener(listeners[i]); 210 browser.removeProgressListener(listeners[i]);
211 } 211 }
212 progressListeners.delete(window); 212 progressListeners.delete(window);
213 }; 213 };
214 214
215 /**
216 * Maps windows to a list of click listeners.
217 */
218 let clickListeners = new WeakMap();
219
220 /**
221 * Makes sure that a function is called whenever the user clicks inside the
222 * browser's content area.
223 */
224 exports.addBrowserClickListener = function addBrowserClickListener(/**Window*/ w indow, /**Function*/ callback)
225 {
226 let browser = (exports.getBrowser ? exports.getBrowser(window) : null);
227 if (browser)
228 {
229 browser.addEventListener("click", callback, true);
230
231 if (clickListeners.has(window))
232 clickListeners.get(window).push(callback);
233 else
234 clickListeners.set(window, [callback]);
235 }
236 };
237
238 /**
239 * Removes all click listeners registered for a window, to be called on
240 * cleanup.
241 */
242 exports.removeBrowserClickListeners = function removeBrowserClickListeners(/**Wi ndow*/ window)
243 {
244 if (!clickListeners.has(window))
245 return;
246
247 let browser = (exports.getBrowser ? exports.getBrowser(window) : null);
248 if (browser)
249 {
250 let listeners = clickListeners.get(window);
251 for (let i = 0; i < listeners.length; i++)
252 browser.removeEventListener("click", listeners[i], true);
253 }
254 clickListeners.delete(window);
255 };
256
257 let {application} = require("info"); 215 let {application} = require("info");
258 switch (application) 216 switch (application)
259 { 217 {
260 case "firefox": 218 case "firefox":
261 { 219 {
262 exports.isKnownWindow = function ff_isKnownWindow(window) 220 exports.isKnownWindow = function ff_isKnownWindow(window)
263 { 221 {
264 return (window.document.documentElement.getAttribute("windowtype") == "nav igator:browser"); 222 return (window.document.documentElement.getAttribute("windowtype") == "nav igator:browser");
265 }; 223 };
266 224
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 { 310 {
353 return null; 311 return null;
354 } 312 }
355 } 313 }
356 else 314 else
357 { 315 {
358 let browser = exports.getBrowser(window); 316 let browser = exports.getBrowser(window);
359 return (browser ? browser.currentURI : null); 317 return (browser ? browser.currentURI : null);
360 } 318 }
361 }; 319 };
362 320
363 // for Seamonkey we have to ignore same document flag because of 321 // for Seamonkey we have to ignore same document flag because of
364 // bug #1035171 (https://bugzilla.mozilla.org/show_bug.cgi?id=1035171) 322 // bug #1035171 (https://bugzilla.mozilla.org/show_bug.cgi?id=1035171)
365 let origAddBrowserLocationListener = exports.addBrowserLocationListener; 323 let origAddBrowserLocationListener = exports.addBrowserLocationListener;
366 exports.addBrowserLocationListener = function sm_addBrowserLocationListener( window, callback, ignoreSameDoc) 324 exports.addBrowserLocationListener = function sm_addBrowserLocationListener( window, callback, ignoreSameDoc)
367 { 325 {
368 origAddBrowserLocationListener(window, callback, false); 326 origAddBrowserLocationListener(window, callback, false);
369 }; 327 };
370 328
371 exports.contentContextMenu = ["contentAreaContextMenu", "mailContext"]; 329 exports.contentContextMenu = ["contentAreaContextMenu", "mailContext"];
372 330
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 568
611 let messageListener = listener.messageListener; 569 let messageListener = listener.messageListener;
612 let index = ("gMessageListeners" in window ? window.gMessageListeners.inde xOf(messageListener) : -1); 570 let index = ("gMessageListeners" in window ? window.gMessageListeners.inde xOf(messageListener) : -1);
613 if (index >= 0) 571 if (index >= 0)
614 window.gMessageListeners.splice(index, 1); 572 window.gMessageListeners.splice(index, 1);
615 573
616 listener.detach(); 574 listener.detach();
617 progressListeners.delete(window); 575 progressListeners.delete(window);
618 }; 576 };
619 577
620 exports.addBrowserClickListener = function addBrowserClickListener(/**Window */ window, /**Function*/ callback)
621 {
622 if (clickListeners.has(window))
623 {
624 clickListeners.get(window).callbacks.push(callback);
625 return;
626 }
627
628 let callbacks = [callback];
629 let listener = new BrowserChangeListener(window, function(oldBrowser, newB rowser)
630 {
631 if (oldBrowser)
632 for (let i = 0; i < callbacks.length; i++)
633 oldBrowser.removeEventListener("click", callbacks[i], true);
634 if (newBrowser)
635 for (let i = 0; i < callbacks.length; i++)
636 newBrowser.addEventListener("click", callbacks[i], true);
637 });
638 listener.callbacks = callbacks;
639
640 clickListeners.set(window, listener);
641 };
642
643 exports.removeBrowserClickListeners = function removeBrowserClickListeners(/ **Window*/ window)
644 {
645 if (!clickListeners.has(window))
646 return;
647
648 let listener = clickListeners.get(window);
649 listener.detach();
650
651 clickListeners.delete(window);
652 };
653
654 // Make sure to close/reopen list of blockable items when the user changes t abs 578 // Make sure to close/reopen list of blockable items when the user changes t abs
655 let {WindowObserver} = require("windowObserver"); 579 let {WindowObserver} = require("windowObserver");
656 new WindowObserver({ 580 new WindowObserver({
657 listeners: new WeakMap(), 581 listeners: new WeakMap(),
658 applyToWindow: function(window) 582 applyToWindow: function(window)
659 { 583 {
660 if (!exports.isKnownWindow(window) || this.listeners.has(window)) 584 if (!exports.isKnownWindow(window) || this.listeners.has(window))
661 return; 585 return;
662 586
663 let {Utils} = require("utils"); 587 let {Utils} = require("utils");
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 exports.removeBrowserLocationListeners = function ffn_removeBrowserLocationL isteners(/**Window*/ window) 723 exports.removeBrowserLocationListeners = function ffn_removeBrowserLocationL isteners(/**Window*/ window)
800 { 724 {
801 if (!progressListeners.has(window)) 725 if (!progressListeners.has(window))
802 return; 726 return;
803 727
804 let listener = progressListeners.get(window); 728 let listener = progressListeners.get(window);
805 listener.detach(); 729 listener.detach();
806 progressListeners.delete(window); 730 progressListeners.delete(window);
807 }; 731 };
808 732
809 exports.addBrowserClickListener = function ffn_addBrowserClickListener(/**Wi ndow*/ window, /**Function*/ callback)
810 {
811 if (clickListeners.has(window))
812 {
813 clickListeners.get(window).callbacks.push(callback);
814 return;
815 }
816
817 let callbacks = [callback];
818 let listener = new BrowserChangeListener(window, function(oldBrowser, newB rowser)
819 {
820 if (oldBrowser)
821 for (let i = 0; i < callbacks.length; i++)
822 oldBrowser.removeEventListener("click", callbacks[i], true);
823 if (newBrowser)
824 for (let i = 0; i < callbacks.length; i++)
825 newBrowser.addEventListener("click", callbacks[i], true);
826 });
827 listener.callbacks = callbacks;
828
829 clickListeners.set(window, listener);
830 };
831
832 exports.removeBrowserClickListeners = function ffn_removeBrowserClickListene rs(/**Window*/ window)
833 {
834 if (!clickListeners.has(window))
835 return;
836
837 let listener = clickListeners.get(window);
838 listener.detach();
839
840 clickListeners.delete(window);
841 };
842
843 let {Filter} = require("filterClasses"); 733 let {Filter} = require("filterClasses");
844 let {Prefs} = require("prefs"); 734 let {Prefs} = require("prefs");
845 let {Policy} = require("contentPolicy"); 735 let {Policy} = require("contentPolicy");
846 let {UI} = require("ui"); 736 let {UI} = require("ui");
847 let {Utils} = require("utils"); 737 let {Utils} = require("utils");
848 738
849 let toggleWhitelist = function(window) 739 let toggleWhitelist = function(window)
850 { 740 {
851 if (!Prefs.enabled) 741 if (!Prefs.enabled)
852 { 742 {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
952 event.state = {id: require("info").addonID}; 842 event.state = {id: require("info").addonID};
953 browser._contentWindow.dispatchEvent(event); 843 browser._contentWindow.dispatchEvent(event);
954 }); 844 });
955 }); 845 });
956 }, true); 846 }, true);
957 }; 847 };
958 848
959 break; 849 break;
960 } 850 }
961 } 851 }
OLDNEW

Powered by Google App Engine
This is Rietveld