Bug 1153958 - Make manifest processor e10s friendly. r=ehsan

--HG--
extra : rebase_source : 6adae4a21054173a709573fae11248d0526960a0
This commit is contained in:
Marcos Caceres 2015-04-14 16:00:00 +02:00
Родитель 13d9def98b
Коммит 6833b3bd48
5 изменённых файлов: 22 добавлений и 16 удалений

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

@ -101,14 +101,18 @@ ManifestProcessor.prototype = {
// * manifestURL: the URL of the manifest, to resolve URLs.
// * docURL: the URL of the owner doc, for security checks.
process({
jsonText, manifestURL, docURL
jsonText: aJsonText,
manifestURL: aManifestURL,
docURL: aDocURL
}) {
const manifestURL = new URL(aManifestURL);
const docURL = new URL(aDocURL);
const console = new ConsoleAPI({
prefix: 'Web Manifest: '
});
let rawManifest = {};
try {
rawManifest = JSON.parse(jsonText);
rawManifest = JSON.parse(aJsonText);
} catch (e) {}
if (typeof rawManifest !== 'object' || rawManifest === null) {
let msg = 'Manifest needs to be an object.';
@ -124,7 +128,8 @@ ManifestProcessor.prototype = {
short_name: processShortNameMember(rawManifest),
};
processedManifest.scope = processScopeMember(rawManifest, manifestURL,
docURL, processedManifest.start_url);
docURL, new URL(processedManifest.start_url));
return processedManifest;
function processNameMember(aManifest) {
@ -188,8 +193,11 @@ ManifestProcessor.prototype = {
expectedType: 'string',
trim: false
};
const value = extractValue(spec, console);
let scopeURL;
const value = extractValue(spec, console);
if (value === undefined || value === '') {
return undefined;
}
try {
scopeURL = new URL(value, aManifestURL);
} catch (e) {
@ -210,7 +218,7 @@ ManifestProcessor.prototype = {
console.warn(msg);
return undefined;
}
return scopeURL;
return scopeURL.href;
}
function processStartURLMember(aManifest, aManifestURL, aDocURL) {
@ -221,7 +229,7 @@ ManifestProcessor.prototype = {
expectedType: 'string',
trim: false
};
let result = new URL(aDocURL);
let result = new URL(aDocURL).href;
const value = extractValue(spec, console);
if (value === undefined || value === '') {
return result;
@ -237,7 +245,7 @@ ManifestProcessor.prototype = {
let msg = 'start_url must be same origin as document.';
console.warn(msg);
} else {
result = potentialResult;
result = potentialResult.href;
}
return result;
}
@ -248,7 +256,7 @@ this.ManifestProcessor = ManifestProcessor;
function IconsProcessor() {}
// Static getters
Object.defineProperties(IconsProcessor,{
Object.defineProperties(IconsProcessor, {
'onlyDecimals': {
get: function() {
return /^\d+$/;
@ -324,7 +332,7 @@ IconsProcessor.process = function(aManifest, aBaseURL, console) {
let url;
if (value && value.length) {
try {
url = new URL(value, aBaseURL);
url = new URL(value, aBaseURL).href;
} catch (e) {}
}
return url;

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

@ -1,5 +1,4 @@
[DEFAULT]
skip-if = e10s
support-files =
common.js

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

@ -61,7 +61,7 @@ data.jsonText = JSON.stringify(noSrc);
var result = processor.process(data);
ise(result.icons.length, 0, expected);
var expected = `Expect icon's src to be an instance of URL.`;
var expected = `Expect icon's src to be a string.`;
var withSrc = {
icons: [{
src: 'pass'
@ -69,7 +69,7 @@ var withSrc = {
};
data.jsonText = JSON.stringify(withSrc);
var result = processor.process(data);
ise(SpecialPowers.unwrap(result.icons[0].src) instanceof URL, true, expected);
ise(typeof result.icons[0].src, "string", expected);
var expected = `Expect only icons with a src prop to be kept.`;
var withSrc = {

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

@ -20,7 +20,7 @@ invalidJson.forEach((testString) => {
var expected = `Expect to recover from invalid JSON: ${testString}`;
data.jsonText = testString;
var result = processor.process(data);
SimpleTest.ok(result.start_url.href === docURL.href, true, expected);
SimpleTest.ise(result.start_url, docURL.href, expected);
});
var validButUnhelpful = ["1", 1, "", "[{}]", "null"];
@ -28,7 +28,7 @@ validButUnhelpful.forEach((testString) => {
var expected = `Expect to recover from invalid JSON: ${testString}`;
data.jsonText = testString;
var result = processor.process(data);
SimpleTest.ok(result.start_url.href === docURL.href, true, expected);
SimpleTest.ise(result.start_url, docURL.href, expected);
});
</script>
</head>

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

@ -47,8 +47,7 @@ URLs.forEach((url) => {
});
var absURL = new URL(url, manifestURL).toString();
var result = processor.process(data);
console.log(result);
ise(String(result.scope), absURL, expected);
ise(result.scope, absURL, expected);
});
var expected = 'If start URL is not in scope, return undefined.';