Bug 1086997 - Localize developer warnings issued by the manifest processor. r=baku

This commit is contained in:
Marco Castelluccio 2016-02-02 16:47:51 -08:00
parent 3af026a7f5
commit 4f9783da3f
4 changed files with 29 additions and 20 deletions

View File

@ -189,6 +189,16 @@ InterceptionRejectedResponseWithURL=Failed to load '%1$S'. A ServiceWorker passe
# LOCALIZATION NOTE: Do not translate "ServiceWorker", "promise", "FetchEvent.respondWith()", or "Response". %1$S is a URL. %2$S is an error string.
InterceptedNonResponseWithURL=Failed to load '%1$S'. A ServiceWorker passed a promise to FetchEvent.respondWith() that resolved with non-Response value '%2$S'.
ExecCommandCutCopyDeniedNotInputDriven=document.execCommand('cut'/'copy') was denied because it was not called from inside a short running user-generated event handler.
ManifestShouldBeObject=Manifest should be an object.
ManifestScopeURLInvalid=The scope URL is invalid.
ManifestScopeNotSameOrigin=The scope URL must be same origin as document.
ManifestStartURLOutsideScope=The start URL is outside the scope, so the scope is invalid.
ManifestStartURLInvalid=The start URL is invalid.
ManifestStartURLShouldBeSameOrigin=The start URL must be same origin as document.
# LOCALIZATION NOTE: %1$S is the name of the object whose property is invalid. %2$S is the name of the invalid property. %3$S is the expected type of the property value. E.g. "Expected the manifest's start_url member to be a string."
ManifestInvalidType=Expected the %1$S's %2$S member to be a %3$S.
# LOCALIZATION NOTE: %1$S is the name of the property whose value is invalid. %2$S is the (invalid) value of the property. E.g. "theme_color: 42 is not a valid CSS color."
ManifestInvalidCSSColor=%1$S: %2$S is not a valid CSS color.
PatternAttributeCompileFailure=Unable to check <input pattern='%S'> because the pattern is not a valid regexp: %S
# LOCALIZATION NOTE: Do not translate "postMessage" or DOMWindow. %S values are origins, like https://domain.com:port
TargetPrincipalDoesNotMatch=Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('%S') does not match the recipient window's origin ('%S').

View File

@ -6,7 +6,7 @@
* Implementation of Image Object processing algorithms from:
* http://www.w3.org/TR/appmanifest/#image-object-and-its-members
*
* This is intended to be used in conjunction with ManifestProcessor.js
* This is intended to be used in conjunction with ManifestProcessor.jsm
*
* Creates an object to process Image Objects as defined by the
* W3C specification. This is used to process things like the

View File

@ -33,6 +33,7 @@ const orientationTypes = new Set(['any', 'natural', 'landscape', 'portrait',
'landscape-secondary'
]);
Cu.import('resource://gre/modules/Console.jsm');
Cu.import("resource://gre/modules/Services.jsm");
// ValueExtractor is used by the various processors to get values
// from the manifest and to report errors.
Cu.import('resource://gre/modules/ValueExtractor.jsm');
@ -60,6 +61,8 @@ this.ManifestProcessor = { // jshint ignore:line
manifestURL: aManifestURL,
docURL: aDocURL
}) {
const domBundle = Services.strings.createBundle("chrome://global/locale/dom/dom.properties");
const console = new ConsoleAPI({
prefix: 'Web Manifest'
});
@ -70,11 +73,10 @@ this.ManifestProcessor = { // jshint ignore:line
rawManifest = JSON.parse(jsonText);
} catch (e) {}
if (typeof rawManifest !== 'object' || rawManifest === null) {
let msg = 'Manifest needs to be an object.';
console.warn(msg);
console.warn(domBundle.GetStringFromName('ManifestShouldBeObject'));
rawManifest = {};
}
const extractor = new ValueExtractor(console);
const extractor = new ValueExtractor(console, domBundle);
const imgObjProcessor = new ImageObjectProcessor(console, extractor);
const processedManifest = {
'lang': processLangMember(),
@ -165,21 +167,17 @@ this.ManifestProcessor = { // jshint ignore:line
try {
scopeURL = new URL(value, manifestURL);
} catch (e) {
let msg = 'The URL of scope is invalid.';
console.warn(msg);
console.warn(domBundle.GetStringFromName('ManifestScopeURLInvalid'));
return undefined;
}
if (scopeURL.origin !== docURL.origin) {
let msg = 'Scope needs to be same-origin as Document.';
console.warn(msg);
console.warn(domBundle.GetStringFromName('ManifestScopeNotSameOrigin'));
return undefined;
}
// If start URL is not within scope of scope URL:
let isSameOrigin = startURL && startURL.origin !== scopeURL.origin;
if (isSameOrigin || !startURL.pathname.startsWith(scopeURL.pathname)) {
let msg =
'The start URL is outside the scope, so scope is invalid.';
console.warn(msg);
console.warn(domBundle.GetStringFromName('ManifestStartURLOutsideScope'));
return undefined;
}
return scopeURL.href;
@ -202,12 +200,11 @@ this.ManifestProcessor = { // jshint ignore:line
try {
potentialResult = new URL(value, manifestURL);
} catch (e) {
console.warn('Invalid URL.');
console.warn(domBundle.GetStringFromName('ManifestStartURLInvalid'))
return result;
}
if (potentialResult.origin !== docURL.origin) {
let msg = 'start_url must be same origin as document.';
console.warn(msg);
console.warn(domBundle.GetStringFromName('ManifestStartURLShouldBeSameOrigin'));
} else {
result = potentialResult.href;
}

View File

@ -12,8 +12,9 @@ const {
interfaces: Ci
} = Components;
function ValueExtractor(aConsole) {
function ValueExtractor(aConsole, aBundle) {
this.console = aConsole;
this.domBundle = aBundle;
}
ValueExtractor.prototype = {
@ -32,9 +33,9 @@ ValueExtractor.prototype = {
const type = (isArray) ? 'array' : typeof value;
if (type !== expectedType) {
if (type !== 'undefined') {
let msg = `Expected the ${objectName}'s ${property} `;
msg += `member to be a ${expectedType}.`;
this.console.log(msg);
this.console.warn(this.domBundle.formatStringFromName("ManifestInvalidType",
[objectName, property, expectedType],
3));
}
return undefined;
}
@ -53,8 +54,9 @@ ValueExtractor.prototype = {
if (DOMUtils.isValidCSSColor(value)) {
color = value;
} else if (value) {
const msg = `${spec.property}: ${value} is not a valid CSS color.`;
this.console.warn(msg);
this.console.warn(this.domBundle.formatStringFromName("ManifestInvalidCSSColor",
[spec.property, value],
2));
}
return color;
}