From: Brendan Dahl Date: Tue, 15 May 2012 17:33:01 +0000 (-0700) Subject: Merge upstream. Use new l10n. X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=080c3e79fc7b76ff92f9abebd594b8b7f69c8232;p=pdf.js.git Merge upstream. Use new l10n. --- 080c3e79fc7b76ff92f9abebd594b8b7f69c8232 diff --cc extensions/firefox/components/PdfStreamConverter.js index 9f5cc6b,1bcccbe..ced6b10 --- a/extensions/firefox/components/PdfStreamConverter.js +++ b/extensions/firefox/components/PdfStreamConverter.js @@@ -11,18 -11,27 +11,29 @@@ const Cr = Components.results const Cu = Components.utils; const PDFJS_EVENT_ID = 'pdf.js.message'; const PDF_CONTENT_TYPE = 'application/pdf'; -const EXT_PREFIX = 'extensions.uriloader@pdf.js'; +const EXT_ID = 'uriloader@pdf.js'; +const EXT_PREFIX = 'extensions.' + EXT_ID; const MAX_DATABASE_LENGTH = 4096; + const FIREFOX_ID = '{ec8030f7-c20a-464f-9b0e-13a3a9e97384}'; + const SEAMONKEY_ID = '{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}'; Cu.import('resource://gre/modules/XPCOMUtils.jsm'); Cu.import('resource://gre/modules/Services.jsm'); Cu.import('resource://gre/modules/NetUtil.jsm'); +Cu.import('resource://gre/modules/AddonManager.jsm'); - let privateBrowsing = Cc['@mozilla.org/privatebrowsing;1'] - .getService(Ci.nsIPrivateBrowsingService); - let inPrivateBrowswing = privateBrowsing.privateBrowsingEnabled; + let appInfo = Cc['@mozilla.org/xre/app-info;1'] + .getService(Ci.nsIXULAppInfo); + let privateBrowsing, inPrivateBrowsing; + + if (appInfo.ID === FIREFOX_ID) { + privateBrowsing = Cc['@mozilla.org/privatebrowsing;1'] + .getService(Ci.nsIPrivateBrowsingService); + inPrivateBrowsing = privateBrowsing.privateBrowsingEnabled; + } else if (appInfo.ID === SEAMONKEY_ID) { + privateBrowsing = null; + inPrivateBrowsing = false; + } function getBoolPref(pref, def) { try { @@@ -61,12 -70,27 +72,32 @@@ function getDOMWindow(aChannel) return win; } - // Fake l10n until we get the real l10n sorted out. - var mozL10n = { - get: function(key, args, fallback) { - return fallback; + function getLocalizedStrings(path) { + var stringBundle = Cc['@mozilla.org/intl/stringbundle;1']. + getService(Ci.nsIStringBundleService). + createBundle('chrome://pdf.js/locale/' + path); + + var map = {}; + var enumerator = stringBundle.getSimpleEnumeration(); + while (enumerator.hasMoreElements()) { + var string = enumerator.getNext().QueryInterface(Ci.nsIPropertyElement); + var key = string.key, property = 'textContent'; + var i = key.lastIndexOf('.'); + if (i >= 0) { + property = key.substring(i + 1); + key = key.substring(0, i); + } + if (!(key in map)) + map[key] = {}; + map[key][property] = string.value; } - }; + return map; + } ++function getLocalizedString(strings, id) { ++ if (id in strings) ++ return strings[id]['textContent']; ++ return id; ++} // All the priviledged actions. function ChromeActions() { @@@ -122,35 -146,21 +153,47 @@@ ChromeActions.prototype = getLocale: function() { return getStringPref('general.useragent.locale', 'en-US'); }, + getStrings: function(data) { + try { + // Lazy initialization of localizedStrings + if (!('localizedStrings' in this)) + this.localizedStrings = getLocalizedStrings('viewer.properties'); + + var result = this.localizedStrings[data]; + return JSON.stringify(result || null); + } catch (e) { + log('Unable to retrive localized strings: ' + e); + return 'null'; + } + }, pdfBugEnabled: function() { return getBoolPref(EXT_PREFIX + '.pdfBugEnabled', false); + }, + fallback: function(url) { ++ var strings = getLocalizedStrings('chrome.properties'); + var self = this; - var message = mozL10n.get('unsupported_feature', null, - 'An unsupported feature was detected in this PDF document.'); ++ var message = getLocalizedString(strings, 'unsupported_feature'); + var win = Services.wm.getMostRecentWindow('navigator:browser'); + var notificationBox = win.gBrowser.getNotificationBox(); + var buttons = [{ - label: mozL10n.get('download_document', null, 'Download Document'), ++ label: getLocalizedString(strings, 'download_document'), + accessKey: null, + callback: function() { + self.download(url); + } + }, { - label: mozL10n.get('disable_viewer', null, - 'Disable Mozilla PDF Viewer'), ++ label: getLocalizedString(strings, 'disable_viewer'), + accessKey: null, + callback: function() { + AddonManager.getAddonByID(EXT_ID, function(aAddon) { + aAddon.userDisabled = true; + win.gBrowser.contentWindow.location.reload(); + }); + } + }]; + notificationBox.appendNotification(message, 'pdfjs-fallback', null, + notificationBox.PRIORITY_WARNING_LOW, + buttons); } }; diff --cc l10n/en-US/chrome.properties index 0000000,0000000..f0f4bcb new file mode 100644 --- /dev/null +++ b/l10n/en-US/chrome.properties @@@ -1,0 -1,0 +1,3 @@@ ++unsupported_feature=An unsupported feature was detected in this PDF document. ++download_document=Download Document ++disable_viewer=Disable Mozilla PDF Viewer diff --cc make.js index 0a39e0b,88f7c69..e166b6b --- a/make.js +++ b/make.js @@@ -91,14 -97,15 +97,19 @@@ target.locale = function() continue; } + mkdir('-p', EXTENSION_LOCALE_OUTPUT + '/' + locale); + chromeManifestContent += 'locale pdf.js ' + locale + ' locale/' + locale + '/\n'; + if (test('-f', path + '/viewer.properties')) { var properties = cat(path + '/viewer.properties'); - if (locale == DEFAULT_LOCALE) - viewerOutput = '[*]\n' + properties + '\n' + viewerOutput; - else - viewerOutput = viewerOutput + '[' + locale + ']\n' + properties + '\n'; + viewerOutput += '[' + locale + ']\n' + properties + '\n'; + cp(path + '/viewer.properties', EXTENSION_LOCALE_OUTPUT + '/' + locale); + } + ++ if (test('-f', path + '/chrome.properties')) { ++ cp(path + '/chrome.properties', EXTENSION_LOCALE_OUTPUT + '/' + locale); + } + if (test('-f', path + '/metadata.inc')) { var metadata = cat(path + '/metadata.inc'); metadataContent += metadata;