Bug 1008825 - Synchronous XMLHttpRequest to load options.xul. r=wesj

This commit is contained in:
Vikneshwar 2014-07-07 11:23:00 +02:00
Родитель 3cccd02b12
Коммит 8168b217e1
1 изменённых файлов: 28 добавлений и 25 удалений

Просмотреть файл

@ -330,34 +330,37 @@ var Addons = {
try { try {
let optionsURL = aListItem.getAttribute("optionsURL"); let optionsURL = aListItem.getAttribute("optionsURL");
let xhr = new XMLHttpRequest(); let xhr = new XMLHttpRequest();
xhr.open("GET", optionsURL, false); xhr.open("GET", optionsURL, true);
xhr.send(); xhr.onload = function(e) {
if (xhr.responseXML) { if (xhr.responseXML) {
// Only allow <setting> for now // Only allow <setting> for now
let settings = xhr.responseXML.querySelectorAll(":root > setting"); let settings = xhr.responseXML.querySelectorAll(":root > setting");
if (settings.length > 0) { if (settings.length > 0) {
for (let i = 0; i < settings.length; i++) { for (let i = 0; i < settings.length; i++) {
var setting = settings[i]; var setting = settings[i];
var desc = stripTextNodes(setting).trim(); var desc = stripTextNodes(setting).trim();
if (!setting.hasAttribute("desc")) if (!setting.hasAttribute("desc")) {
setting.setAttribute("desc", desc); setting.setAttribute("desc", desc);
box.appendChild(setting); }
} box.appendChild(setting);
// Send an event so add-ons can prepopulate any non-preference based }
// settings // Send an event so add-ons can prepopulate any non-preference based
let event = document.createEvent("Events"); // settings
event.initEvent("AddonOptionsLoad", true, false); let event = document.createEvent("Events");
window.dispatchEvent(event); event.initEvent("AddonOptionsLoad", true, false);
window.dispatchEvent(event);
// Also send a notification to match the behavior of desktop Firefox // Also send a notification to match the behavior of desktop Firefox
let id = aListItem.getAttribute("addonID"); let id = aListItem.getAttribute("addonID");
Services.obs.notifyObservers(document, AddonManager.OPTIONS_NOTIFICATION_DISPLAYED, id); Services.obs.notifyObservers(document, AddonManager.OPTIONS_NOTIFICATION_DISPLAYED, id);
} else { } else {
// No options, so hide the header and reset the list item // No options, so hide the header and reset the list item
detailItem.setAttribute("optionsURL", ""); detailItem.setAttribute("optionsURL", "");
aListItem.setAttribute("optionsURL", ""); aListItem.setAttribute("optionsURL", "");
}
} }
} }
xhr.send(null);
} catch (e) { } } catch (e) { }
let list = document.querySelector("#addons-list"); let list = document.querySelector("#addons-list");