mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 777251 - B2G MMS: Configure MMS proxy settings through SettingsService. r=vicamo
This commit is contained in:
parent
f1462ce7dd
commit
5d9050d369
@ -128,14 +128,14 @@ SettingsListener.observe('language.current', 'en-US', function(value) {
|
||||
|
||||
// =================== RIL ====================
|
||||
(function RILSettingsToPrefs() {
|
||||
let strPrefs = ['ril.data.mmsc', 'ril.data.mmsproxy'];
|
||||
let strPrefs = ['ril.mms.mmsc', 'ril.mms.mmsproxy'];
|
||||
strPrefs.forEach(function(key) {
|
||||
SettingsListener.observe(key, "", function(value) {
|
||||
Services.prefs.setCharPref(key, value);
|
||||
});
|
||||
});
|
||||
|
||||
['ril.data.mmsport'].forEach(function(key) {
|
||||
['ril.mms.mmsport'].forEach(function(key) {
|
||||
SettingsListener.observe(key, null, function(value) {
|
||||
if (value != null) {
|
||||
Services.prefs.setIntPref(key, value);
|
||||
|
@ -19,6 +19,7 @@ const DEBUG = false;
|
||||
|
||||
const kNetworkInterfaceStateChangedTopic = "network-interface-state-changed";
|
||||
const kXpcomShutdownObserverTopic = "xpcom-shutdown";
|
||||
const kPrefenceChangedObserverTopic = "nsPref:changed";
|
||||
|
||||
// File modes for saving MMS attachments.
|
||||
const FILE_OPEN_MODE = FileUtils.MODE_CREATE
|
||||
@ -57,6 +58,20 @@ XPCOMUtils.defineLazyGetter(this, "MMS", function () {
|
||||
function MmsService() {
|
||||
Services.obs.addObserver(this, kXpcomShutdownObserverTopic, false);
|
||||
Services.obs.addObserver(this, kNetworkInterfaceStateChangedTopic, false);
|
||||
this.MMSProxySettings.forEach(function(name) {
|
||||
Services.prefs.addObserver(name, this, false);
|
||||
}, this);
|
||||
|
||||
try {
|
||||
this.MMSC = Services.prefs.getCharPref("ril.mms.mmsc");
|
||||
this.MMSProxy = Services.prefs.getCharPref("ril.mms.mmsproxy");
|
||||
this.MMSPort = Services.prefs.getIntPref("ril.mms.mmsport");
|
||||
this.updateMMSProxyInfo();
|
||||
} catch (e) {
|
||||
debug("Failed to initialize the MMS proxy settings from the preference.");
|
||||
this.clearMMSProxySettings();
|
||||
}
|
||||
|
||||
try {
|
||||
this.urlUAProf = Services.prefs.getCharPref('wap.UAProf.url');
|
||||
} catch (e) {
|
||||
@ -82,8 +97,15 @@ MmsService.prototype = {
|
||||
*/
|
||||
confSendDeliveryReport: CONFIG_SEND_REPORT_DEFAULT_YES,
|
||||
|
||||
proxyInfo: null,
|
||||
/** MMS proxy settings. */
|
||||
MMSC: null,
|
||||
MMSProxy: null,
|
||||
MMSPort: null,
|
||||
MMSProxyInfo: null,
|
||||
MMSProxySettings: ["ril.mms.mmsc",
|
||||
"ril.mms.mmsproxy",
|
||||
"ril.mms.mmsport"],
|
||||
MMSNetworkConnected: false,
|
||||
|
||||
/** MMS proxy filter reference count. */
|
||||
proxyFilterRefCount: 0,
|
||||
@ -539,30 +561,31 @@ MmsService.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Update proxyInfo & MMSC from preferences.
|
||||
*
|
||||
* @param enabled
|
||||
* Enable or disable MMS proxy.
|
||||
* Update the MMS proxy info.
|
||||
*/
|
||||
updateProxyInfo: function updateProxyInfo(enabled) {
|
||||
try {
|
||||
if (enabled) {
|
||||
this.MMSC = Services.prefs.getCharPref("ril.data.mmsc");
|
||||
this.proxyInfo = gpps.newProxyInfo("http",
|
||||
Services.prefs.getCharPref("ril.data.mmsproxy"),
|
||||
Services.prefs.getIntPref("ril.data.mmsport"),
|
||||
Ci.nsIProxyInfo.TRANSPARENT_PROXY_RESOLVES_HOST,
|
||||
-1, null);
|
||||
debug("updateProxyInfo: "
|
||||
+ JSON.stringify({MMSC: this.MMSC, proxyInfo: this.proxyInfo}));
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
// Failed to refresh proxy info from settings. Fallback to disable.
|
||||
updateMMSProxyInfo: function updateMMSProxyInfo() {
|
||||
if (this.MMSProxy === null || this.MMSPort === null) {
|
||||
debug("updateMMSProxyInfo: MMSProxy or MMSPort is not yet decided." );
|
||||
return;
|
||||
}
|
||||
|
||||
this.MMSProxyInfo =
|
||||
gpps.newProxyInfo("http",
|
||||
this.MMSProxy,
|
||||
this.MMSPort,
|
||||
Ci.nsIProxyInfo.TRANSPARENT_PROXY_RESOLVES_HOST,
|
||||
-1, null);
|
||||
debug("updateMMSProxyInfo: " + JSON.stringify(this.MMSProxyInfo));
|
||||
},
|
||||
|
||||
/**
|
||||
* Clear the MMS proxy settings.
|
||||
*/
|
||||
clearMMSProxySettings: function clearMMSProxySettings() {
|
||||
this.MMSC = null;
|
||||
this.proxyInfo = null;
|
||||
this.MMSProxy = null;
|
||||
this.MMSPort = null;
|
||||
this.MMSProxyInfo = null;
|
||||
},
|
||||
|
||||
// nsIMmsService
|
||||
@ -583,15 +606,43 @@ MmsService.prototype = {
|
||||
switch (topic) {
|
||||
case kNetworkInterfaceStateChangedTopic: {
|
||||
let iface = subject.QueryInterface(Ci.nsINetworkInterface);
|
||||
if ((iface.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE)
|
||||
|| (iface.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_MMS)) {
|
||||
this.updateProxyInfo(iface.state == Ci.nsINetworkInterface.NETWORK_STATE_CONNECTED);
|
||||
if (iface.type != Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE &&
|
||||
iface.type != Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_MMS) {
|
||||
return;
|
||||
}
|
||||
this.MMSNetworkConnected =
|
||||
iface.state == Ci.nsINetworkInterface.NETWORK_STATE_CONNECTED;
|
||||
break;
|
||||
}
|
||||
case kXpcomShutdownObserverTopic: {
|
||||
Services.obs.removeObserver(this, kXpcomShutdownObserverTopic);
|
||||
Services.obs.removeObserver(this, kNetworkInterfaceStateChangedTopic);
|
||||
this.MMSProxySettings.forEach(function(name) {
|
||||
Services.prefs.removeObserver(name, this);
|
||||
}, this);
|
||||
break;
|
||||
}
|
||||
case kPrefenceChangedObserverTopic: {
|
||||
try {
|
||||
switch (data) {
|
||||
case "ril.mms.mmsc":
|
||||
this.MMSC = Services.prefs.getCharPref("ril.mms.mmsc");
|
||||
break;
|
||||
case "ril.mms.mmsproxy":
|
||||
this.MMSProxy = Services.prefs.getCharPref("ril.mms.mmsproxy");
|
||||
this.updateMMSProxyInfo();
|
||||
break;
|
||||
case "ril.mms.mmsport":
|
||||
this.MMSPort = Services.prefs.getIntPref("ril.mms.mmsport");
|
||||
this.updateMMSProxyInfo();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} catch (e) {
|
||||
debug("Failed to update the MMS proxy settings from the preference.");
|
||||
this.clearMMSProxySettings();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -600,13 +651,27 @@ MmsService.prototype = {
|
||||
// nsIProtocolProxyFilter
|
||||
|
||||
applyFilter: function applyFilter(service, uri, proxyInfo) {
|
||||
if (uri.prePath == this.MMSC) {
|
||||
debug("applyFilter: match " + uri.spec);
|
||||
return this.proxyInfo;
|
||||
if (!this.MMSNetworkConnected) {
|
||||
debug("applyFilter: the MMS network is not connected.");
|
||||
return proxyInfo;
|
||||
}
|
||||
|
||||
if (this.MMSC === null || uri.prePath != this.MMSC) {
|
||||
debug("applyFilter: MMSC is not matched.");
|
||||
return proxyInfo;
|
||||
}
|
||||
|
||||
return proxyInfo;
|
||||
},
|
||||
if (this.MMSProxyInfo === null) {
|
||||
debug("applyFilter: MMS proxy info is not yet decided.");
|
||||
return proxyInfo;
|
||||
}
|
||||
|
||||
// Fall-through, reutrn the MMS proxy info.
|
||||
debug("applyFilter: MMSC is matched: " +
|
||||
JSON.stringify({ MMSC: this.MMSC,
|
||||
MMSProxyInfo: this.MMSProxyInfo }));
|
||||
return this.MMSProxyInfo;
|
||||
}
|
||||
};
|
||||
|
||||
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([MmsService]);
|
||||
|
Loading…
Reference in New Issue
Block a user