Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | const MOCK_ALERTS_CID = SpecialPowers.wrap(SpecialPowers.Components).ID("{48068bc2-40ab-4904-8afd-4cdfb3a385f3}"); |
michael@0 | 2 | const ALERTS_SERVICE_CONTRACT_ID = "@mozilla.org/alerts-service;1"; |
michael@0 | 3 | |
michael@0 | 4 | const MOCK_SYSTEM_ALERTS_CID = SpecialPowers.wrap(SpecialPowers.Components).ID("{e86d888c-e41b-4b78-9104-2f2742a532de}"); |
michael@0 | 5 | const SYSTEM_ALERTS_SERVICE_CONTRACT_ID = "@mozilla.org/system-alerts-service;1"; |
michael@0 | 6 | |
michael@0 | 7 | var registrar = SpecialPowers.wrap(SpecialPowers.Components).manager. |
michael@0 | 8 | QueryInterface(SpecialPowers.Ci.nsIComponentRegistrar); |
michael@0 | 9 | |
michael@0 | 10 | var mockAlertsService = { |
michael@0 | 11 | showAlertNotification: function(imageUrl, title, text, textClickable, |
michael@0 | 12 | cookie, alertListener, name, bidi, lang) { |
michael@0 | 13 | // probably should do this async.... |
michael@0 | 14 | SpecialPowers.wrap(alertListener).observe(null, "alertshow", cookie); |
michael@0 | 15 | |
michael@0 | 16 | if (SpecialPowers.getBoolPref("notification.prompt.testing.click_on_notification") == true) { |
michael@0 | 17 | SpecialPowers.wrap(alertListener).observe(null, "alertclickcallback", cookie); |
michael@0 | 18 | } |
michael@0 | 19 | |
michael@0 | 20 | SpecialPowers.wrap(alertListener).observe(null, "alertfinished", cookie); |
michael@0 | 21 | }, |
michael@0 | 22 | |
michael@0 | 23 | showAppNotification: function(imageUrl, title, text, alertListener, details) { |
michael@0 | 24 | this.showAlertNotification(imageUrl, title, text, details.textClickable, "", |
michael@0 | 25 | alertListener, details.name, details.dir, details.lang); |
michael@0 | 26 | }, |
michael@0 | 27 | |
michael@0 | 28 | QueryInterface: function(aIID) { |
michael@0 | 29 | if (SpecialPowers.wrap(aIID).equals(SpecialPowers.Ci.nsISupports) || |
michael@0 | 30 | SpecialPowers.wrap(aIID).equals(SpecialPowers.Ci.nsIAlertsService) || |
michael@0 | 31 | SpecialPowers.wrap(aIID).equals(SpecialPowers.Ci.nsIAppNotificationService)) { |
michael@0 | 32 | return this; |
michael@0 | 33 | } |
michael@0 | 34 | throw SpecialPowers.Components.results.NS_ERROR_NO_INTERFACE; |
michael@0 | 35 | }, |
michael@0 | 36 | |
michael@0 | 37 | createInstance: function(aOuter, aIID) { |
michael@0 | 38 | if (aOuter != null) { |
michael@0 | 39 | throw SpecialPowers.Components.results.NS_ERROR_NO_AGGREGATION; |
michael@0 | 40 | } |
michael@0 | 41 | return this.QueryInterface(aIID); |
michael@0 | 42 | } |
michael@0 | 43 | }; |
michael@0 | 44 | mockAlertsService = SpecialPowers.wrapCallbackObject(mockAlertsService); |
michael@0 | 45 | |
michael@0 | 46 | function setup_notifications(allowPrompt, forceClick, callback) { |
michael@0 | 47 | SpecialPowers.pushPrefEnv({'set': [["notification.prompt.testing", true], |
michael@0 | 48 | ["notification.prompt.testing.allow", allowPrompt], |
michael@0 | 49 | ["notification.prompt.testing.click_on_notification", forceClick]]}, |
michael@0 | 50 | callback); |
michael@0 | 51 | |
michael@0 | 52 | registrar.registerFactory(MOCK_SYSTEM_ALERTS_CID, "system alerts service", |
michael@0 | 53 | SYSTEM_ALERTS_SERVICE_CONTRACT_ID, |
michael@0 | 54 | mockAlertsService); |
michael@0 | 55 | |
michael@0 | 56 | registrar.registerFactory(MOCK_ALERTS_CID, "alerts service", |
michael@0 | 57 | ALERTS_SERVICE_CONTRACT_ID, |
michael@0 | 58 | mockAlertsService); |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | function reset_notifications() { |
michael@0 | 62 | registrar.unregisterFactory(MOCK_SYSTEM_ALERTS_CID, mockAlertsService); |
michael@0 | 63 | registrar.unregisterFactory(MOCK_ALERTS_CID, mockAlertsService); |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | function is_feature_enabled() { |
michael@0 | 67 | return navigator.mozNotification && SpecialPowers.getBoolPref("notification.feature.enabled"); |
michael@0 | 68 | } |
michael@0 | 69 |