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 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | const { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components; |
michael@0 | 5 | const { Services } = Cu.import('resource://gre/modules/Services.jsm'); |
michael@0 | 6 | |
michael@0 | 7 | var browser = Services.wm.getMostRecentWindow('navigator:browser'); |
michael@0 | 8 | var connection = browser.navigator.mozMobileConnections[0]; |
michael@0 | 9 | |
michael@0 | 10 | // provide a fake APN and enable data connection. |
michael@0 | 11 | function enableDataConnection() { |
michael@0 | 12 | let setLock = browser.navigator.mozSettings.createLock(); |
michael@0 | 13 | setLock.set({ |
michael@0 | 14 | 'ril.data.enabled': true, |
michael@0 | 15 | 'ril.data.apnSettings': [ |
michael@0 | 16 | [ |
michael@0 | 17 | {'carrier':'T-Mobile US', |
michael@0 | 18 | 'apn':'epc.tmobile.com', |
michael@0 | 19 | 'mmsc':'http://mms.msg.eng.t-mobile.com/mms/wapenc', |
michael@0 | 20 | 'types':['default','supl','mms']} |
michael@0 | 21 | ] |
michael@0 | 22 | ] |
michael@0 | 23 | }); |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | // enable 3G radio |
michael@0 | 27 | function enableRadio() { |
michael@0 | 28 | if (connection.radioState !== 'enabled') { |
michael@0 | 29 | connection.setRadioEnabled(true); |
michael@0 | 30 | } |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | // disable 3G radio |
michael@0 | 34 | function disableRadio() { |
michael@0 | 35 | if (connection.radioState === 'enabled') { |
michael@0 | 36 | connection.setRadioEnabled(false); |
michael@0 | 37 | } |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | addMessageListener('prepare-network', function(message) { |
michael@0 | 41 | //RIL DOM events will be pending until RIL receiveing system-message-listener-ready event. |
michael@0 | 42 | Services.obs.notifyObservers(null, 'system-message-listener-ready', null); |
michael@0 | 43 | |
michael@0 | 44 | connection.addEventListener('datachange', function onDataChange() { |
michael@0 | 45 | if (connection.data.connected) { |
michael@0 | 46 | connection.removeEventListener('datachange', onDataChange); |
michael@0 | 47 | Services.prefs.setIntPref('network.proxy.type', 2); |
michael@0 | 48 | sendAsyncMessage('network-ready', true); |
michael@0 | 49 | } |
michael@0 | 50 | }); |
michael@0 | 51 | |
michael@0 | 52 | enableRadio(); |
michael@0 | 53 | enableDataConnection(); |
michael@0 | 54 | }); |
michael@0 | 55 | |
michael@0 | 56 | addMessageListener('network-cleanup', function(message) { |
michael@0 | 57 | connection.addEventListener('datachange', function onDataChange() { |
michael@0 | 58 | if (!connection.data.connected) { |
michael@0 | 59 | connection.removeEventListener('datachange', onDataChange); |
michael@0 | 60 | Services.prefs.setIntPref('network.proxy.type', 2); |
michael@0 | 61 | sendAsyncMessage('network-disabled', true); |
michael@0 | 62 | } |
michael@0 | 63 | }); |
michael@0 | 64 | disableRadio(); |
michael@0 | 65 | }); |