Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | var MockServices = (function () { |
michael@0 | 2 | "use strict"; |
michael@0 | 3 | |
michael@0 | 4 | const MOCK_ALERTS_CID = SpecialPowers.wrap(SpecialPowers.Components) |
michael@0 | 5 | .ID("{48068bc2-40ab-4904-8afd-4cdfb3a385f3}"); |
michael@0 | 6 | const ALERTS_SERVICE_CONTRACT_ID = "@mozilla.org/alerts-service;1"; |
michael@0 | 7 | |
michael@0 | 8 | const MOCK_SYSTEM_ALERTS_CID = SpecialPowers.wrap(SpecialPowers.Components) |
michael@0 | 9 | .ID("{e86d888c-e41b-4b78-9104-2f2742a532de}"); |
michael@0 | 10 | const SYSTEM_ALERTS_SERVICE_CONTRACT_ID = "@mozilla.org/system-alerts-service;1"; |
michael@0 | 11 | |
michael@0 | 12 | var registrar = SpecialPowers.wrap(SpecialPowers.Components).manager |
michael@0 | 13 | .QueryInterface(SpecialPowers.Ci.nsIComponentRegistrar); |
michael@0 | 14 | |
michael@0 | 15 | var activeNotifications = Object.create(null); |
michael@0 | 16 | |
michael@0 | 17 | var mockAlertsService = { |
michael@0 | 18 | showAlertNotification: function(imageUrl, title, text, textClickable, |
michael@0 | 19 | cookie, alertListener, name) { |
michael@0 | 20 | var listener = SpecialPowers.wrap(alertListener); |
michael@0 | 21 | activeNotifications[name] = { |
michael@0 | 22 | listener: listener, |
michael@0 | 23 | cookie: cookie |
michael@0 | 24 | }; |
michael@0 | 25 | |
michael@0 | 26 | // fake async alert show event |
michael@0 | 27 | setTimeout(function () { |
michael@0 | 28 | listener.observe(null, "alertshow", cookie); |
michael@0 | 29 | }, 100); |
michael@0 | 30 | |
michael@0 | 31 | // ?? SpecialPowers.wrap(alertListener).observe(null, "alertclickcallback", cookie); |
michael@0 | 32 | }, |
michael@0 | 33 | |
michael@0 | 34 | showAppNotification: function(imageUrl, title, text, textClickable, |
michael@0 | 35 | manifestURL, alertListener, name) { |
michael@0 | 36 | this.showAlertNotification(imageUrl, title, text, textClickable, "", alertListener, name); |
michael@0 | 37 | }, |
michael@0 | 38 | |
michael@0 | 39 | closeAlert: function(name) { |
michael@0 | 40 | var notification = activeNotifications[name]; |
michael@0 | 41 | if (notification) { |
michael@0 | 42 | notification.listener.observe(null, "alertfinished", notification.cookie); |
michael@0 | 43 | delete activeNotifications[name]; |
michael@0 | 44 | } |
michael@0 | 45 | }, |
michael@0 | 46 | |
michael@0 | 47 | QueryInterface: function(aIID) { |
michael@0 | 48 | if (SpecialPowers.wrap(aIID).equals(SpecialPowers.Ci.nsISupports) || |
michael@0 | 49 | SpecialPowers.wrap(aIID).equals(SpecialPowers.Ci.nsIAlertsService)) { |
michael@0 | 50 | return this; |
michael@0 | 51 | } |
michael@0 | 52 | throw SpecialPowers.Components.results.NS_ERROR_NO_INTERFACE; |
michael@0 | 53 | }, |
michael@0 | 54 | |
michael@0 | 55 | createInstance: function(aOuter, aIID) { |
michael@0 | 56 | if (aOuter != null) { |
michael@0 | 57 | throw SpecialPowers.Components.results.NS_ERROR_NO_AGGREGATION; |
michael@0 | 58 | } |
michael@0 | 59 | return this.QueryInterface(aIID); |
michael@0 | 60 | } |
michael@0 | 61 | }; |
michael@0 | 62 | mockAlertsService = SpecialPowers.wrapCallbackObject(mockAlertsService); |
michael@0 | 63 | |
michael@0 | 64 | // MockServices API |
michael@0 | 65 | return { |
michael@0 | 66 | register: function () { |
michael@0 | 67 | registrar.registerFactory(MOCK_ALERTS_CID, "alerts service", |
michael@0 | 68 | ALERTS_SERVICE_CONTRACT_ID, |
michael@0 | 69 | mockAlertsService); |
michael@0 | 70 | |
michael@0 | 71 | registrar.registerFactory(MOCK_SYSTEM_ALERTS_CID, "system alerts service", |
michael@0 | 72 | SYSTEM_ALERTS_SERVICE_CONTRACT_ID, |
michael@0 | 73 | mockAlertsService); |
michael@0 | 74 | }, |
michael@0 | 75 | |
michael@0 | 76 | unregister: function () { |
michael@0 | 77 | registrar.unregisterFactory(MOCK_ALERTS_CID, mockAlertsService); |
michael@0 | 78 | registrar.unregisterFactory(MOCK_SYSTEM_ALERTS_CID, mockAlertsService); |
michael@0 | 79 | }, |
michael@0 | 80 | }; |
michael@0 | 81 | })(); |