mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-11 20:35:50 +00:00
Bug 1135018 - Move getjson from webide/ to shared/. r=jryans
--HG-- rename : browser/devtools/webide/modules/remote-resources.js => browser/devtools/shared/getjson.js
This commit is contained in:
parent
318629d58d
commit
059619bafc
@ -3,23 +3,22 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
const {Cu, CC} = require("chrome");
|
||||
const {Promise: promise} = Cu.import("resource://gre/modules/Promise.jsm", {});
|
||||
const promise = require("promise");
|
||||
const {Services} = Cu.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
const XMLHttpRequest = CC("@mozilla.org/xmlextras/xmlhttprequest;1");
|
||||
|
||||
function getJSON(bypassCache, pref) {
|
||||
// Downloads and caches a JSON file from a URL given by the pref.
|
||||
exports.getJSON = function (prefName, bypassCache) {
|
||||
if (!bypassCache) {
|
||||
try {
|
||||
let str = Services.prefs.getCharPref(pref + "_cache");
|
||||
let str = Services.prefs.getCharPref(prefName + "_cache");
|
||||
let json = JSON.parse(str);
|
||||
return promise.resolve(json);
|
||||
} catch(e) {/* no pref or invalid json. Let's continue */}
|
||||
}
|
||||
|
||||
|
||||
let deferred = promise.defer();
|
||||
|
||||
let xhr = new XMLHttpRequest();
|
||||
|
||||
xhr.onload = () => {
|
||||
@ -27,9 +26,9 @@ function getJSON(bypassCache, pref) {
|
||||
try {
|
||||
json = JSON.parse(xhr.responseText);
|
||||
} catch(e) {
|
||||
return deferred.reject("Not valid JSON");
|
||||
return deferred.reject("Invalid JSON");
|
||||
}
|
||||
Services.prefs.setCharPref(pref + "_cache", xhr.responseText);
|
||||
Services.prefs.setCharPref(prefName + "_cache", xhr.responseText);
|
||||
deferred.resolve(json);
|
||||
}
|
||||
|
||||
@ -37,18 +36,8 @@ function getJSON(bypassCache, pref) {
|
||||
deferred.reject("Network error");
|
||||
}
|
||||
|
||||
xhr.open("get", Services.prefs.getCharPref(pref));
|
||||
xhr.open("get", Services.prefs.getCharPref(prefName));
|
||||
xhr.send();
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
|
||||
|
||||
exports.GetTemplatesJSON = function(bypassCache) {
|
||||
return getJSON(bypassCache, "devtools.webide.templatesURL");
|
||||
}
|
||||
|
||||
exports.GetAddonsJSON = function(bypassCache) {
|
||||
return getJSON(bypassCache, "devtools.webide.addonsURL");
|
||||
}
|
@ -51,6 +51,7 @@ EXTRA_JS_MODULES.devtools.shared += [
|
||||
'devices.js',
|
||||
'doorhanger.js',
|
||||
'frame-script-utils.js',
|
||||
'getjson.js',
|
||||
'inplace-editor.js',
|
||||
'observable-object.js',
|
||||
'options-view.js',
|
||||
|
@ -15,9 +15,10 @@ XPCOMUtils.defineLazyModuleGetter(this, "Downloads", "resource://gre/modules/Dow
|
||||
const {require} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}).devtools;
|
||||
const {FileUtils} = Cu.import("resource://gre/modules/FileUtils.jsm");
|
||||
const {AppProjects} = require("devtools/app-manager/app-projects");
|
||||
const APP_CREATOR_LIST = "devtools.webide.templatesURL";
|
||||
const {AppManager} = require("devtools/webide/app-manager");
|
||||
const {GetTemplatesJSON} = require("devtools/webide/remote-resources");
|
||||
const {getJSON} = require("devtools/shared/getjson");
|
||||
|
||||
const TEMPLATES_URL = "devtools.webide.templatesURL";
|
||||
|
||||
let gTemplateList = null;
|
||||
|
||||
@ -30,11 +31,11 @@ window.addEventListener("load", function onLoad() {
|
||||
window.removeEventListener("load", onLoad);
|
||||
let projectNameNode = document.querySelector("#project-name");
|
||||
projectNameNode.addEventListener("input", canValidate, true);
|
||||
getJSON();
|
||||
getTemplatesJSON();
|
||||
}, true);
|
||||
|
||||
function getJSON() {
|
||||
GetTemplatesJSON().then(list => {
|
||||
function getTemplatesJSON() {
|
||||
getJSON(TEMPLATES_URL).then(list => {
|
||||
if (!Array.isArray(list)) {
|
||||
throw new Error("JSON response not an array");
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ const {Promise: promise} = Cu.import("resource://gre/modules/Promise.jsm", {});
|
||||
const ProjectEditor = require("projecteditor/projecteditor");
|
||||
const {Devices} = Cu.import("resource://gre/modules/devtools/Devices.jsm");
|
||||
const {GetAvailableAddons} = require("devtools/webide/addons");
|
||||
const {GetTemplatesJSON, GetAddonsJSON} = require("devtools/webide/remote-resources");
|
||||
const {getJSON} = require("devtools/shared/getjson");
|
||||
const utils = require("devtools/webide/utils");
|
||||
const Telemetry = require("devtools/shared/telemetry");
|
||||
const {RuntimeScanners, WiFiScanner} = require("devtools/webide/runtimes");
|
||||
@ -34,8 +34,9 @@ const HELP_URL = "https://developer.mozilla.org/docs/Tools/WebIDE/Troubleshootin
|
||||
const MAX_ZOOM = 1.4;
|
||||
const MIN_ZOOM = 0.6;
|
||||
|
||||
// download template index early
|
||||
GetTemplatesJSON(true);
|
||||
// Download remote resources early
|
||||
getJSON("devtools.webide.addonsURL", true);
|
||||
getJSON("devtools.webide.templatesURL", true);
|
||||
|
||||
// See bug 989619
|
||||
console.log = console.log.bind(console);
|
||||
|
@ -5,9 +5,11 @@
|
||||
const {Cu} = require("chrome");
|
||||
const {Promise: promise} = Cu.import("resource://gre/modules/Promise.jsm");
|
||||
const {AddonManager} = Cu.import("resource://gre/modules/AddonManager.jsm");
|
||||
const {EventEmitter} = Cu.import("resource://gre/modules/devtools/event-emitter.js");
|
||||
const {Services} = Cu.import("resource://gre/modules/Services.jsm");
|
||||
const {GetAddonsJSON} = require("devtools/webide/remote-resources");
|
||||
const {getJSON} = require("devtools/shared/getjson");
|
||||
const EventEmitter = require("devtools/toolkit/event-emitter");
|
||||
|
||||
const ADDONS_URL = "devtools.webide.addonsURL";
|
||||
|
||||
let SIMULATOR_LINK = Services.prefs.getCharPref("devtools.webide.simulatorAddonsURL");
|
||||
let ADB_LINK = Services.prefs.getCharPref("devtools.webide.adbAddonURL");
|
||||
@ -54,7 +56,7 @@ let GetAvailableAddons = exports.GetAvailableAddons = function() {
|
||||
simulators: [],
|
||||
adb: null
|
||||
}
|
||||
GetAddonsJSON(true).then(json => {
|
||||
getJSON(ADDONS_URL, true).then(json => {
|
||||
for (let stability in json) {
|
||||
for (let version of json[stability]) {
|
||||
addons.simulators.push(new SimulatorAddon(stability, version));
|
||||
|
@ -25,7 +25,6 @@ EXTRA_JS_MODULES.devtools.webide += [
|
||||
'modules/build.js',
|
||||
'modules/config-view.js',
|
||||
'modules/project-list.js',
|
||||
'modules/remote-resources.js',
|
||||
'modules/runtimes.js',
|
||||
'modules/simulator-process.js',
|
||||
'modules/simulators.js',
|
||||
|
Loading…
Reference in New Issue
Block a user