Bug 740640 - B2G 3G: Support HTTP proxy. r=philikon
authorJose Antonio Olivera Ortega <josea.olivera@gmail.com>
Wed, 01 Aug 2012 07:55:43 -0700
changeset 101106 3041cf7e42ed082c615580a95e70e4945bb6e7c3
parent 101105 4c7c41b33485b3f3e6312c1cc584771a0a7e59e2
child 101107 c3606b8bbe01428d9bfd9cccda809129acd30fc2
push id23216
push userryanvm@gmail.com
push dateWed, 01 Aug 2012 21:51:28 +0000
treeherdermozilla-central@7fe96a690596 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersphilikon
bugs740640
milestone17.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 740640 - B2G 3G: Support HTTP proxy. r=philikon
dom/system/gonk/NetworkManager.js
dom/system/gonk/RadioInterfaceLayer.js
dom/system/gonk/nsINetworkManager.idl
dom/wifi/WifiWorker.js
--- a/dom/system/gonk/NetworkManager.js
+++ b/dom/system/gonk/NetworkManager.js
@@ -18,16 +18,18 @@ const NETWORKINTERFACE_CID =
 
 const DEFAULT_PREFERRED_NETWORK_TYPE = Ci.nsINetworkInterface.NETWORK_TYPE_WIFI;
 
 const TOPIC_INTERFACE_STATE_CHANGED  = "network-interface-state-changed";
 const TOPIC_INTERFACE_REGISTERED     = "network-interface-registered";
 const TOPIC_INTERFACE_UNREGISTERED   = "network-interface-unregistered";
 const TOPIC_DEFAULT_ROUTE_CHANGED    = "network-default-route-changed";
 
+const MANUAL_PROXY_CONFIGURATION = 1;
+
 const DEBUG = false;
 
 /**
  * This component watches for network interfaces changing state and then
  * adjusts routes etc. accordingly.
  */
 function NetworkManager() {
   this.networkInterfaces = {};
@@ -183,18 +185,45 @@ NetworkManager.prototype = {
   setDefaultRouteAndDNS: function setDefaultRouteAndDNS(oldInterface) {
     debug("Going to change route and DNS to " + this.active.name);
     let options = {
       cmd: this.active.dhcp ? "runDHCPAndSetDefaultRouteAndDNS" : "setDefaultRouteAndDNS",
       ifname: this.active.name,
       oldIfname: (oldInterface && oldInterface != this.active) ? oldInterface.name : null
     };
     this.worker.postMessage(options);
+    this.setNetworkProxy();
   },
 
+  setNetworkProxy: function setNetworkProxy() {
+    try {
+      if (!this.active.httpProxyHost || this.active.httpProxyHost == "") {
+        // Sets direct connection to internet.
+        Services.prefs.clearUserPref("network.proxy.type");
+        Services.prefs.clearUserPref("network.proxy.share_proxy_settings");
+        Services.prefs.clearUserPref("network.proxy.http");
+        Services.prefs.clearUserPref("network.proxy.http_port");
+        debug("No proxy support for " + this.active.name + " network interface.");
+        return;
+      }
+
+      debug("Going to set proxy settings for " + this.active.name + " network interface.");
+      // Sets manual proxy configuration.
+      Services.prefs.setIntPref("network.proxy.type", MANUAL_PROXY_CONFIGURATION);
+      // Do not use this proxy server for all protocols.
+      Services.prefs.setBoolPref("network.proxy.share_proxy_settings", false);
+      Services.prefs.setCharPref("network.proxy.http", this.active.httpProxyHost);
+      let port = this.active.httpProxyPort == "" ? 8080 : this.active.httpProxyPort;
+      Services.prefs.setIntPref("network.proxy.http_port", port);
+    } catch (ex) {
+       debug("Exception " + ex + ". Unable to set proxy setting for "
+             + this.active.name + " network interface.");
+       return;
+    }
+  },
 };
 
 const NSGetFactory = XPCOMUtils.generateNSGetFactory([NetworkManager]);
 
 
 let debug;
 if (DEBUG) {
   debug = function (s) {
--- a/dom/system/gonk/RadioInterfaceLayer.js
+++ b/dom/system/gonk/RadioInterfaceLayer.js
@@ -174,23 +174,27 @@ function RadioInterfaceLayer() {
   // Read the 'ril.radio.disabled' setting in order to start with a known
   // value at boot time.
   gSettingsService.getLock().get("ril.radio.disabled", this);
 
   // Read the APN data form the setting DB.
   gSettingsService.getLock().get("ril.data.apn", this);
   gSettingsService.getLock().get("ril.data.user", this);
   gSettingsService.getLock().get("ril.data.passwd", this);
+  gSettingsService.getLock().get("ril.data.httpProxyHost", this);
+  gSettingsService.getLock().get("ril.data.httpProxyPort", this);
   gSettingsService.getLock().get("ril.data.roaming_enabled", this);
   gSettingsService.getLock().get("ril.data.enabled", this);
   this._dataCallSettingsToRead = ["ril.data.enabled",
                                   "ril.data.roaming_enabled",
                                   "ril.data.apn",
                                   "ril.data.user",
-                                  "ril.data.passwd"];
+                                  "ril.data.passwd",
+                                  "ril.data.httpProxyHost",
+                                  "ril.data.httpProxyPort"];
 
   for each (let msgname in RIL_IPC_MSG_NAMES) {
     ppmm.addMessageListener(msgname, this);
   }
   Services.obs.addObserver(this, "xpcom-shutdown", false);
   Services.obs.addObserver(this, kMozSettingsChangedObserverTopic, false);
 
   this._sentSmsEnvelopes = {};
@@ -1023,16 +1027,18 @@ RadioInterfaceLayer.prototype = {
         break;
       case "ril.data.enabled":
         this._oldRilDataEnabledState = this.dataCallSettings["enabled"];
         // Fall through!
       case "ril.data.roaming_enabled":
       case "ril.data.apn":
       case "ril.data.user":
       case "ril.data.passwd":
+      case "ril.data.httpProxyHost":
+      case "ril.data.httpProxyPort":
         let key = aName.slice(9);
         this.dataCallSettings[key] = aResult;
         debug("'" + aName + "'" + " is now " + this.dataCallSettings[key]);
         let index = this._dataCallSettingsToRead.indexOf(aName);
         if (index != -1) {
           this._dataCallSettingsToRead.splice(index, 1);
         }
         this.updateRILNetworkInterface();
@@ -1752,16 +1758,20 @@ let RILNetworkInterface = {
   timer: null,
 
   type: Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE,
 
   name: null,
 
   dhcp: false,
 
+  httpProxyHost: null,
+
+  httpProxyPort: null,
+
   // nsIRILDataCallback
 
   dataCallStateChanged: function dataCallStateChanged(datacall) {
     debug("Data call ID: " + datacall.cid + ", interface name: " + datacall.ifname);
     if (this.connecting &&
         (datacall.state == RIL.GECKO_NETWORK_STATE_CONNECTING ||
          datacall.state == RIL.GECKO_NETWORK_STATE_CONNECTED)) {
       this.connecting = false;
@@ -1824,16 +1834,19 @@ let RILNetworkInterface = {
       this.registeredAsDataCallCallback = true;
     }
 
     if (options) {
       // Save the APN data locally for using them in connection retries. 
       this.dataCallSettings = options;
     }
 
+    this.httpProxyHost = this.dataCallSettings["httpProxyHost"];
+    this.httpProxyPort = this.dataCallSettings["httpProxyPort"];
+
     debug("Going to set up data connection with APN " + this.dataCallSettings["apn"]);
     this.mRIL.setupDataCall(RIL.DATACALL_RADIOTECHNOLOGY_GSM,
                             this.dataCallSettings["apn"], 
                             this.dataCallSettings["user"], 
                             this.dataCallSettings["passwd"],
                             RIL.DATACALL_AUTH_PAP_OR_CHAP, "IP");
     this.connecting = true;
   },
--- a/dom/system/gonk/nsINetworkManager.idl
+++ b/dom/system/gonk/nsINetworkManager.idl
@@ -2,17 +2,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsISupports.idl"
 
 /**
  * Information about networks that is exposed to network manager API consumers.
  */
-[scriptable, uuid(e016d594-3072-11e1-9b7d-0010183a41af)]
+[scriptable, uuid(57b56c6f-4c3f-4c55-bf1b-e5af22407931)]
 interface nsINetworkInterface : nsISupports
 {
   const long NETWORK_STATE_UNKNOWN = -1;
   const long NETWORK_STATE_CONNECTING = 0;
   const long NETWORK_STATE_CONNECTED = 1;
   const long NETWORK_STATE_SUSPENDED = 2;
   const long NETWORK_STATE_DISCONNECTING = 3;
   const long NETWORK_STATE_DISCONNECTED = 4;
@@ -39,16 +39,26 @@ interface nsINetworkInterface : nsISuppo
    */
   readonly attribute DOMString name;
 
   /**
    * Indicates whether DHCP should be run when the interface connects.
    */
   readonly attribute boolean dhcp;
 
+  /**
+   * The host name of the http proxy server.
+   */
+  readonly attribute DOMString httpProxyHost;
+
+  /*
+   * The port number of the http proxy server. 
+   */
+  readonly attribute long httpProxyPort;
+
 };
 
 /**
  * Manage network interfaces.
  */
 [scriptable, uuid(3bc29392-2fba-11e1-80fd-0010183a41af)]
 interface nsINetworkManager : nsISupports
 {
--- a/dom/wifi/WifiWorker.js
+++ b/dom/wifi/WifiWorker.js
@@ -1262,16 +1262,20 @@ let WifiNetworkInterface = {
   type: Ci.nsINetworkInterface.NETWORK_TYPE_WIFI,
 
   name: null,
 
   // For now we do our own DHCP. In the future this should be handed off
   // to the Network Manager.
   dhcp: false,
 
+  httpProxyHost: null,
+
+  httpProxyPort: null,
+
 };
 
 
 // TODO Make the difference between a DOM-based network object and our
 // networks objects much clearer.
 let netToDOM;
 let netFromDOM;