From 4f9783da3f60146db6b493bf3abe6bdb299259c4 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Tue, 2 Feb 2016 16:47:51 -0800 Subject: [PATCH] Bug 1086997 - Localize developer warnings issued by the manifest processor. r=baku --- dom/locales/en-US/chrome/dom/dom.properties | 10 +++++++++ dom/manifest/ImageObjectProcessor.jsm | 2 +- dom/manifest/ManifestProcessor.jsm | 23 +++++++++------------ dom/manifest/ValueExtractor.jsm | 14 +++++++------ 4 files changed, 29 insertions(+), 20 deletions(-) diff --git a/dom/locales/en-US/chrome/dom/dom.properties b/dom/locales/en-US/chrome/dom/dom.properties index c68d464b7c07..b8b874b5e6e2 100644 --- a/dom/locales/en-US/chrome/dom/dom.properties +++ b/dom/locales/en-US/chrome/dom/dom.properties @@ -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 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'). diff --git a/dom/manifest/ImageObjectProcessor.jsm b/dom/manifest/ImageObjectProcessor.jsm index 33392048076e..ab1975e3cea1 100644 --- a/dom/manifest/ImageObjectProcessor.jsm +++ b/dom/manifest/ImageObjectProcessor.jsm @@ -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 diff --git a/dom/manifest/ManifestProcessor.jsm b/dom/manifest/ManifestProcessor.jsm index 71b1e9066c3d..6d5e6e38a73c 100644 --- a/dom/manifest/ManifestProcessor.jsm +++ b/dom/manifest/ManifestProcessor.jsm @@ -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; } diff --git a/dom/manifest/ValueExtractor.jsm b/dom/manifest/ValueExtractor.jsm index b1dd034a3a8b..f3dd259053c9 100644 --- a/dom/manifest/ValueExtractor.jsm +++ b/dom/manifest/ValueExtractor.jsm @@ -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; }