Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #24247 from ddrmanxbxfr/bug_1062803
Browse files Browse the repository at this point in the history
Bug 1062803 - Replace the custom functions used to load JSON files with ...r=alive
  • Loading branch information
BavarianTomcat committed Sep 29, 2014
2 parents b73b27f + 51cb022 commit 53890df
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 77 deletions.
26 changes: 6 additions & 20 deletions apps/system/js/eu_roaming_manager.js
@@ -1,4 +1,5 @@
/* globals SIMSlotManager, Notification, MozActivity, Promise */
/* globals SIMSlotManager, Notification, MozActivity, Promise,
LazyLoader */
'use strict';

(function(exports) {
Expand Down Expand Up @@ -334,25 +335,10 @@
},

_loadJSON: function(path) {
return new Promise(function(resolve) {
var xhr = new XMLHttpRequest();
xhr.open('GET', path, true);
xhr.responseType = 'json';
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
if (xhr.status == 200 || xhr.status === 0) {
resolve(xhr.response);
} else {
resolve(null);
}
}
};

try {
xhr.send();
} catch (e) {
resolve(null);
}
return LazyLoader.getJSON(path).then(function(json) {
return Promise.resolve(json);
}, function(error) {
return Promise.resolve(null);
});
}
};
Expand Down
18 changes: 7 additions & 11 deletions apps/system/js/icc.js
@@ -1,6 +1,6 @@
/* -*- Mode: js; js-indent-level: 2; indent-tabs-mode: nil -*- */
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */

/* global LazyLoader, DUMP */
'use strict';

var icc = {
Expand Down Expand Up @@ -77,17 +77,13 @@ var icc = {

getIccInfo: function icc_getIccInfo() {
var self = this;
var xhr = new XMLHttpRequest();
xhr.onerror = function() {
DUMP('Failed to fetch file: ' + href, xhr.statusText);
};
xhr.onload = function() {
self._defaultURL = xhr.response.defaultURL;
var url = '/resources/icc.json';
LazyLoader.getJSON(url).then(function(json) {
self._defaultURL = json.defaultURL;
DUMP('ICC default URL: ', self._defaultURL);
};
xhr.open('GET', '/resources/icc.json', true);
xhr.responseType = 'json';
xhr.send();
}, function(error) {
DUMP('Failed to fetch file: ' + url + ',' + error);
});
},

getIcc: function icc_getIcc(iccId) {
Expand Down
75 changes: 30 additions & 45 deletions apps/system/js/operator_variant/operator_variant.js
@@ -1,7 +1,7 @@
/* -*- Mode: js; js-indent-level: 2; indent-tabs-mode: nil -*- */
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */

/* globals ApnHelper */
/* globals ApnHelper, LazyLoader */

(function(exports) {
'use strict';
Expand Down Expand Up @@ -185,32 +185,24 @@
function ovh_retrieveOperatorVariantSettings(callback) {

var self = this;
var xhr = new XMLHttpRequest();
xhr.open('GET', OPERATOR_VARIANT_FILE, true);
xhr.responseType = 'json';
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status === 0)) {
var apn = xhr.response;

// The apn.json generator strips out leading zeros for mcc values. No
// need for padding in this instance.
var mcc = self._iccSettings.mcc;

// We must pad the mnc value and turn it into a string otherwise
// we could *fail* to load the appropriate settings for single digit
// *mnc* values!
var mnc = self.padLeft(self._iccSettings.mnc, 2);

// Get the type of the data network
var networkType = window.navigator
.mozMobileConnections[self._iccCardIndex]
.data.type;

// Get a list of matching APNs
callback(ApnHelper.getCompatible(apn, mcc, mnc, networkType));
}
};
xhr.send();
LazyLoader.getJSON(OPERATOR_VARIANT_FILE).then(function(apn) {
// The apn.json generator strips out leading zeros for mcc values. No
// need for padding in this instance.
var mcc = self._iccSettings.mcc;

// We must pad the mnc value and turn it into a string otherwise
// we could *fail* to load the appropriate settings for single digit
// *mnc* values!
var mnc = self.padLeft(self._iccSettings.mnc, 2);

// Get the type of the data network
var networkType = window.navigator
.mozMobileConnections[self._iccCardIndex]
.data.type;

// Get a list of matching APNs
callback(ApnHelper.getCompatible(apn, mcc, mnc, networkType));
});
},

/**
Expand Down Expand Up @@ -640,24 +632,17 @@
var WAP_UA_PROFILE_FILE = '/resources/wapuaprof.json';
var DEFAULT_KEY = '000000';

var xhr = new XMLHttpRequest();
xhr.open('GET', WAP_UA_PROFILE_FILE, true);
xhr.responseType = 'json';
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status === 0)) {
var uaprof = xhr.response;
// normalize mcc, mnc as zero padding string.
var mcc = self.padLeft(self._iccSettings.mcc, 3);
var mnc = self.padLeft(self._iccSettings.mnc, 3);

// Get the ua profile url with mcc/mnc. Fallback to default if no
// record found. If still not found, we use undefined as the default
// value
var uaProfile = uaprof[mcc + mnc] || uaprof[DEFAULT_KEY];
callback(uaProfile);
}
};
xhr.send();
LazyLoader.getJSON(WAP_UA_PROFILE_FILE).then(function(uaprof) {
// normalize mcc, mnc as zero padding string.
var mcc = self.padLeft(self._iccSettings.mcc, 3);
var mnc = self.padLeft(self._iccSettings.mnc, 3);

// Get the ua profile url with mcc/mnc. Fallback to default if no
// record found. If still not found, we use undefined as the default
// value
var uaProfile = uaprof[mcc + mnc] || uaprof[DEFAULT_KEY];
callback(uaProfile);
});
},

/**
Expand Down
1 change: 1 addition & 0 deletions apps/system/test/unit/eu_roaming_manager_test.js
@@ -1,6 +1,7 @@
/* global EuRoamingManager, Promise, Notification, MockSIMSlotManager */
'use strict';

require('shared/js/lazy_loader.js');
requireApp('system/js/eu_roaming_manager.js');
requireApp('system/shared/test/unit/mocks/mock_simslot_manager.js');

Expand Down
2 changes: 1 addition & 1 deletion apps/system/test/unit/icc_test.js
Expand Up @@ -14,7 +14,7 @@ require('/shared/test/unit/mocks/mock_navigator_moz_set_message_handler.js');
require('/shared/test/unit/mocks/mock_navigator_moz_mobile_connections.js');
require('/shared/test/unit/mocks/mock_dump.js');
require('/shared/test/unit/load_body_html_helper.js');

require('/shared/js/lazy_loader.js');

var mocksForIcc = new MocksHelper([
'Dump',
Expand Down
1 change: 1 addition & 0 deletions apps/system/test/unit/operator_variant_test.js
Expand Up @@ -4,6 +4,7 @@

'use strict';

require('/shared/js/lazy_loader.js');
requireApp('system/shared/test/unit/mocks/mock_navigator_moz_settings.js');
requireApp('system/shared/test/unit/mocks/mock_navigator_moz_icc_manager.js');
require('/shared/test/unit/mocks/mock_navigator_moz_mobile_connections.js');
Expand Down

0 comments on commit 53890df

Please sign in to comment.