Merge pull request #5406 from Snuffleupagus/lint-firefox-jsm

[Firefox] Enable linting of *.jsm files and update the code style in extensions/firefox/content
This commit is contained in:
Tim van der Meij 2014-12-15 20:54:22 +01:00
commit 01cf21955e
8 changed files with 189 additions and 145 deletions

View File

@ -1,3 +1,5 @@
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
/* Copyright 2012 Mozilla Foundation /* Copyright 2012 Mozilla Foundation
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -12,10 +14,13 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* jshint esnext:true, maxlen:100 */
'use strict';
// Don't remove this file. FF15+ expects PdfJs module to be present at resource://pdf.js/PdfJs.jsm // Don't remove this file. FF15+ expects PdfJs module to be present at resource://pdf.js/PdfJs.jsm
// See https://mxr.mozilla.org/mozilla-central/source/browser/components/nsBrowserGlue.js // See https://mxr.mozilla.org/mozilla-central/source/browser/components/nsBrowserGlue.js
var EXPORTED_SYMBOLS = ["PdfJs"]; var EXPORTED_SYMBOLS = ['PdfJs'];
let PdfJs = { let PdfJs = {
init: function PdfJs_init() {} init: function PdfJs_init() {}

View File

@ -1,3 +1,5 @@
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
/* Copyright 2012 Mozilla Foundation /* Copyright 2012 Mozilla Foundation
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -12,8 +14,13 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* jshint esnext:true */
/* globals Components, Services, XPCOMUtils, PdfjsChromeUtils, PdfRedirector,
PdfjsContentUtils, DEFAULT_PREFERENCES, PdfStreamConverter */
var EXPORTED_SYMBOLS = ["PdfJs"]; 'use strict';
var EXPORTED_SYMBOLS = ['PdfJs'];
const Cc = Components.classes; const Cc = Components.classes;
const Ci = Components.interfaces; const Ci = Components.interfaces;
@ -25,11 +32,12 @@ const PREF_PREFIX = 'pdfjs';
const PREF_DISABLED = PREF_PREFIX + '.disabled'; const PREF_DISABLED = PREF_PREFIX + '.disabled';
const PREF_MIGRATION_VERSION = PREF_PREFIX + '.migrationVersion'; const PREF_MIGRATION_VERSION = PREF_PREFIX + '.migrationVersion';
const PREF_PREVIOUS_ACTION = PREF_PREFIX + '.previousHandler.preferredAction'; const PREF_PREVIOUS_ACTION = PREF_PREFIX + '.previousHandler.preferredAction';
const PREF_PREVIOUS_ASK = PREF_PREFIX + '.previousHandler.alwaysAskBeforeHandling'; const PREF_PREVIOUS_ASK = PREF_PREFIX +
'.previousHandler.alwaysAskBeforeHandling';
const PREF_DISABLED_PLUGIN_TYPES = 'plugin.disable_full_page_plugin_for_types'; const PREF_DISABLED_PLUGIN_TYPES = 'plugin.disable_full_page_plugin_for_types';
const TOPIC_PDFJS_HANDLER_CHANGED = 'pdfjs:handlerChanged'; const TOPIC_PDFJS_HANDLER_CHANGED = 'pdfjs:handlerChanged';
const TOPIC_PLUGINS_LIST_UPDATED = "plugins-list-updated"; const TOPIC_PLUGINS_LIST_UPDATED = 'plugins-list-updated';
const TOPIC_PLUGIN_INFO_UPDATED = "plugin-info-updated"; const TOPIC_PLUGIN_INFO_UPDATED = 'plugin-info-updated';
const PDF_CONTENT_TYPE = 'application/pdf'; const PDF_CONTENT_TYPE = 'application/pdf';
Cu.import('resource://gre/modules/XPCOMUtils.jsm'); Cu.import('resource://gre/modules/XPCOMUtils.jsm');
@ -42,10 +50,10 @@ XPCOMUtils.defineLazyServiceGetter(Svc, 'mime',
XPCOMUtils.defineLazyServiceGetter(Svc, 'pluginHost', XPCOMUtils.defineLazyServiceGetter(Svc, 'pluginHost',
'@mozilla.org/plugin/host;1', '@mozilla.org/plugin/host;1',
'nsIPluginHost'); 'nsIPluginHost');
XPCOMUtils.defineLazyModuleGetter(this, "PdfjsChromeUtils", XPCOMUtils.defineLazyModuleGetter(this, 'PdfjsChromeUtils',
"resource://pdf.js/PdfjsChromeUtils.jsm"); 'resource://pdf.js/PdfjsChromeUtils.jsm');
XPCOMUtils.defineLazyModuleGetter(this, "PdfjsContentUtils", XPCOMUtils.defineLazyModuleGetter(this, 'PdfjsContentUtils',
"resource://pdf.js/PdfjsContentUtils.jsm"); 'resource://pdf.js/PdfjsContentUtils.jsm');
function getBoolPref(aPref, aDefaultValue) { function getBoolPref(aPref, aDefaultValue) {
try { try {
@ -64,7 +72,7 @@ function getIntPref(aPref, aDefaultValue) {
} }
function isDefaultHandler() { function isDefaultHandler() {
if (Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_CONTENT) { if (Services.appinfo.processType === Services.appinfo.PROCESS_TYPE_CONTENT) {
return PdfjsContentUtils.isDefaultHandlerApp(); return PdfjsContentUtils.isDefaultHandlerApp();
} }
return PdfjsChromeUtils.isDefaultHandlerApp(); return PdfjsChromeUtils.isDefaultHandlerApp();
@ -119,8 +127,10 @@ let PdfJs = {
_initialized: false, _initialized: false,
init: function init(remote) { init: function init(remote) {
if (Services.appinfo.processType != Services.appinfo.PROCESS_TYPE_DEFAULT) { if (Services.appinfo.processType !==
throw new Error("PdfJs.init should only get called in the parent process."); Services.appinfo.PROCESS_TYPE_DEFAULT) {
throw new Error('PdfJs.init should only get called ' +
'in the parent process.');
} }
PdfjsChromeUtils.init(); PdfjsChromeUtils.init();
if (!remote) { if (!remote) {
@ -224,9 +234,9 @@ let PdfJs = {
prefs.setCharPref(PREF_DISABLED_PLUGIN_TYPES, types.join(',')); prefs.setCharPref(PREF_DISABLED_PLUGIN_TYPES, types.join(','));
// Update the category manager in case the plugins are already loaded. // Update the category manager in case the plugins are already loaded.
let categoryManager = Cc["@mozilla.org/categorymanager;1"]; let categoryManager = Cc['@mozilla.org/categorymanager;1'];
categoryManager.getService(Ci.nsICategoryManager). categoryManager.getService(Ci.nsICategoryManager).
deleteCategoryEntry("Gecko-Content-Viewers", deleteCategoryEntry('Gecko-Content-Viewers',
PDF_CONTENT_TYPE, PDF_CONTENT_TYPE,
false); false);
}, },
@ -234,8 +244,9 @@ let PdfJs = {
// nsIObserver // nsIObserver
observe: function observe(aSubject, aTopic, aData) { observe: function observe(aSubject, aTopic, aData) {
this.updateRegistration(); this.updateRegistration();
if (Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_DEFAULT) { if (Services.appinfo.processType ===
let jsm = "resource://pdf.js/PdfjsChromeUtils.jsm"; Services.appinfo.PROCESS_TYPE_DEFAULT) {
let jsm = 'resource://pdf.js/PdfjsChromeUtils.jsm';
let PdfjsChromeUtils = Components.utils.import(jsm, {}).PdfjsChromeUtils; let PdfjsChromeUtils = Components.utils.import(jsm, {}).PdfjsChromeUtils;
PdfjsChromeUtils.notifyChildOfSettingsChange(); PdfjsChromeUtils.notifyChildOfSettingsChange();
} }
@ -267,9 +278,9 @@ let PdfJs = {
} }
// Check if there is an enabled pdf plugin. // Check if there is an enabled pdf plugin.
// Note: this check is performed last because getPluginTags() triggers costly // Note: this check is performed last because getPluginTags() triggers
// plugin list initialization (bug 881575) // costly plugin list initialization (bug 881575)
let tags = Cc["@mozilla.org/plugin/host;1"]. let tags = Cc['@mozilla.org/plugin/host;1'].
getService(Ci.nsIPluginHost). getService(Ci.nsIPluginHost).
getPluginTags(); getPluginTags();
let enabledPluginFound = tags.some(function(tag) { let enabledPluginFound = tags.some(function(tag) {
@ -287,9 +298,9 @@ let PdfJs = {
}, },
_ensureRegistered: function _ensureRegistered() { _ensureRegistered: function _ensureRegistered() {
if (this._registered) if (this._registered) {
return; return;
}
this._pdfStreamConverterFactory = new Factory(); this._pdfStreamConverterFactory = new Factory();
Cu.import('resource://pdf.js/PdfStreamConverter.jsm'); Cu.import('resource://pdf.js/PdfStreamConverter.jsm');
this._pdfStreamConverterFactory.register(PdfStreamConverter); this._pdfStreamConverterFactory.register(PdfStreamConverter);
@ -305,9 +316,9 @@ let PdfJs = {
}, },
_ensureUnregistered: function _ensureUnregistered() { _ensureUnregistered: function _ensureUnregistered() {
if (!this._registered) if (!this._registered) {
return; return;
}
this._pdfStreamConverterFactory.unregister(); this._pdfStreamConverterFactory.unregister();
Cu.unload('resource://pdf.js/PdfStreamConverter.jsm'); Cu.unload('resource://pdf.js/PdfStreamConverter.jsm');
delete this._pdfStreamConverterFactory; delete this._pdfStreamConverterFactory;

View File

@ -14,7 +14,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* jshint esnext:true */ /* jshint esnext:true, maxlen:120 */
/* globals Components, Services */
'use strict'; 'use strict';
@ -23,7 +24,7 @@ this.EXPORTED_SYMBOLS = ['PdfJsTelemetry'];
const Cu = Components.utils; const Cu = Components.utils;
Cu.import('resource://gre/modules/Services.jsm'); Cu.import('resource://gre/modules/Services.jsm');
const ADDON_ID = "uriloader@pdf.js"; const ADDON_ID = 'uriloader@pdf.js';
var Telemetry = Services.telemetry; var Telemetry = Services.telemetry;
@ -36,9 +37,9 @@ try {
if (ffVersion === 36) { if (ffVersion === 36) {
// Probing FF36 to check if it has new API. // Probing FF36 to check if it has new API.
try { try {
Telemetry.registerAddonHistogram(ADDON_ID, "PDF_36", Telemetry.registerAddonHistogram(ADDON_ID, 'PDF_36',
Telemetry.HISTOGRAM_LINEAR, 1, 40, 41); Telemetry.HISTOGRAM_LINEAR, 1, 40, 41);
var histogram = Telemetry.getAddonHistogram(ADDON_ID, "PDF_36"); var histogram = Telemetry.getAddonHistogram(ADDON_ID, 'PDF_36');
histogram.add(36); histogram.add(36);
} catch (e) { } catch (e) {
oldTelemetryAPI = true; oldTelemetryAPI = true;
@ -66,47 +67,47 @@ registerAddonHistogram(ADDON_ID, 'PDF_VIEWER_TIME_TO_VIEW_MS', Telemetry.HISTOGR
this.PdfJsTelemetry = { this.PdfJsTelemetry = {
onViewerIsUsed: function () { onViewerIsUsed: function () {
let histogram = Telemetry.getAddonHistogram(ADDON_ID, "PDF_VIEWER_USED"); let histogram = Telemetry.getAddonHistogram(ADDON_ID, 'PDF_VIEWER_USED');
histogram.add(true); histogram.add(true);
}, },
onFallback: function () { onFallback: function () {
let histogram = Telemetry.getAddonHistogram(ADDON_ID, "PDF_VIEWER_FALLBACK_SHOWN"); let histogram = Telemetry.getAddonHistogram(ADDON_ID, 'PDF_VIEWER_FALLBACK_SHOWN');
histogram.add(true); histogram.add(true);
}, },
onDocumentSize: function (size) { onDocumentSize: function (size) {
let histogram = Telemetry.getAddonHistogram(ADDON_ID, "PDF_VIEWER_DOCUMENT_SIZE_KB"); let histogram = Telemetry.getAddonHistogram(ADDON_ID, 'PDF_VIEWER_DOCUMENT_SIZE_KB');
histogram.add(size / 1024); histogram.add(size / 1024);
}, },
onDocumentVersion: function (versionId) { onDocumentVersion: function (versionId) {
let histogram = Telemetry.getAddonHistogram(ADDON_ID, "PDF_VIEWER_DOCUMENT_VERSION"); let histogram = Telemetry.getAddonHistogram(ADDON_ID, 'PDF_VIEWER_DOCUMENT_VERSION');
histogram.add(versionId); histogram.add(versionId);
}, },
onDocumentGenerator: function (generatorId) { onDocumentGenerator: function (generatorId) {
let histogram = Telemetry.getAddonHistogram(ADDON_ID, "PDF_VIEWER_DOCUMENT_GENERATOR"); let histogram = Telemetry.getAddonHistogram(ADDON_ID, 'PDF_VIEWER_DOCUMENT_GENERATOR');
histogram.add(generatorId); histogram.add(generatorId);
}, },
onEmbed: function (isObject) { onEmbed: function (isObject) {
let histogram = Telemetry.getAddonHistogram(ADDON_ID, "PDF_VIEWER_EMBED"); let histogram = Telemetry.getAddonHistogram(ADDON_ID, 'PDF_VIEWER_EMBED');
histogram.add(isObject); histogram.add(isObject);
}, },
onFontType: function (fontTypeId) { onFontType: function (fontTypeId) {
let histogram = Telemetry.getAddonHistogram(ADDON_ID, "PDF_VIEWER_FONT_TYPES"); let histogram = Telemetry.getAddonHistogram(ADDON_ID, 'PDF_VIEWER_FONT_TYPES');
histogram.add(fontTypeId); histogram.add(fontTypeId);
}, },
onForm: function (isAcroform) { onForm: function (isAcroform) {
let histogram = Telemetry.getAddonHistogram(ADDON_ID, "PDF_VIEWER_FORM"); let histogram = Telemetry.getAddonHistogram(ADDON_ID, 'PDF_VIEWER_FORM');
histogram.add(isAcroform); histogram.add(isAcroform);
}, },
onPrint: function () { onPrint: function () {
let histogram = Telemetry.getAddonHistogram(ADDON_ID, "PDF_VIEWER_PRINT"); let histogram = Telemetry.getAddonHistogram(ADDON_ID, 'PDF_VIEWER_PRINT');
histogram.add(true); histogram.add(true);
}, },
onStreamType: function (streamTypeId) { onStreamType: function (streamTypeId) {
let histogram = Telemetry.getAddonHistogram(ADDON_ID, "PDF_VIEWER_STREAM_TYPES"); let histogram = Telemetry.getAddonHistogram(ADDON_ID, 'PDF_VIEWER_STREAM_TYPES');
histogram.add(streamTypeId); histogram.add(streamTypeId);
}, },
onTimeToView: function (ms) { onTimeToView: function (ms) {
let histogram = Telemetry.getAddonHistogram(ADDON_ID, "PDF_VIEWER_TIME_TO_VIEW_MS"); let histogram = Telemetry.getAddonHistogram(ADDON_ID, 'PDF_VIEWER_TIME_TO_VIEW_MS');
histogram.add(ms); histogram.add(ms);
} }
}; };

View File

@ -14,7 +14,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* jshint esnext:true */ /* jshint esnext:true, maxlen: 100 */
/* globals Components, Services */
'use strict'; 'use strict';
@ -25,47 +26,47 @@ Cu.import('resource://gre/modules/Services.jsm');
this.PdfJsTelemetry = { this.PdfJsTelemetry = {
onViewerIsUsed: function () { onViewerIsUsed: function () {
let histogram = Services.telemetry.getHistogramById("PDF_VIEWER_USED"); let histogram = Services.telemetry.getHistogramById('PDF_VIEWER_USED');
histogram.add(true); histogram.add(true);
}, },
onFallback: function () { onFallback: function () {
let histogram = Services.telemetry.getHistogramById("PDF_VIEWER_FALLBACK_SHOWN"); let histogram = Services.telemetry.getHistogramById('PDF_VIEWER_FALLBACK_SHOWN');
histogram.add(true); histogram.add(true);
}, },
onDocumentSize: function (size) { onDocumentSize: function (size) {
let histogram = Services.telemetry.getHistogramById("PDF_VIEWER_DOCUMENT_SIZE_KB"); let histogram = Services.telemetry.getHistogramById('PDF_VIEWER_DOCUMENT_SIZE_KB');
histogram.add(size / 1024); histogram.add(size / 1024);
}, },
onDocumentVersion: function (versionId) { onDocumentVersion: function (versionId) {
let histogram = Services.telemetry.getHistogramById("PDF_VIEWER_DOCUMENT_VERSION"); let histogram = Services.telemetry.getHistogramById('PDF_VIEWER_DOCUMENT_VERSION');
histogram.add(versionId); histogram.add(versionId);
}, },
onDocumentGenerator: function (generatorId) { onDocumentGenerator: function (generatorId) {
let histogram = Services.telemetry.getHistogramById("PDF_VIEWER_DOCUMENT_GENERATOR"); let histogram = Services.telemetry.getHistogramById('PDF_VIEWER_DOCUMENT_GENERATOR');
histogram.add(generatorId); histogram.add(generatorId);
}, },
onEmbed: function (isObject) { onEmbed: function (isObject) {
let histogram = Services.telemetry.getHistogramById("PDF_VIEWER_EMBED"); let histogram = Services.telemetry.getHistogramById('PDF_VIEWER_EMBED');
histogram.add(isObject); histogram.add(isObject);
}, },
onFontType: function (fontTypeId) { onFontType: function (fontTypeId) {
let histogram = Services.telemetry.getHistogramById("PDF_VIEWER_FONT_TYPES"); let histogram = Services.telemetry.getHistogramById('PDF_VIEWER_FONT_TYPES');
histogram.add(fontTypeId); histogram.add(fontTypeId);
}, },
onForm: function (isAcroform) { onForm: function (isAcroform) {
let histogram = Services.telemetry.getHistogramById("PDF_VIEWER_FORM"); let histogram = Services.telemetry.getHistogramById('PDF_VIEWER_FORM');
histogram.add(isAcroform); histogram.add(isAcroform);
}, },
onPrint: function () { onPrint: function () {
let histogram = Services.telemetry.getHistogramById("PDF_VIEWER_PRINT"); let histogram = Services.telemetry.getHistogramById('PDF_VIEWER_PRINT');
histogram.add(true); histogram.add(true);
}, },
onStreamType: function (streamTypeId) { onStreamType: function (streamTypeId) {
let histogram = Services.telemetry.getHistogramById("PDF_VIEWER_STREAM_TYPES"); let histogram = Services.telemetry.getHistogramById('PDF_VIEWER_STREAM_TYPES');
histogram.add(streamTypeId); histogram.add(streamTypeId);
}, },
onTimeToView: function (ms) { onTimeToView: function (ms) {
let histogram = Services.telemetry.getHistogramById("PDF_VIEWER_TIME_TO_VIEW_MS"); let histogram = Services.telemetry.getHistogramById('PDF_VIEWER_TIME_TO_VIEW_MS');
histogram.add(ms); histogram.add(ms);
} }
}; };

View File

@ -16,7 +16,7 @@
*/ */
/* jshint esnext:true */ /* jshint esnext:true */
/* globals Components, Services, XPCOMUtils, NetUtil, PrivateBrowsingUtils, /* globals Components, Services, XPCOMUtils, NetUtil, PrivateBrowsingUtils,
dump, NetworkManager, PdfJsTelemetry */ dump, NetworkManager, PdfJsTelemetry, PdfjsContentUtils */
'use strict'; 'use strict';
@ -153,21 +153,24 @@ function getLocalizedStrings(path) {
property = key.substring(i + 1); property = key.substring(i + 1);
key = key.substring(0, i); key = key.substring(0, i);
} }
if (!(key in map)) if (!(key in map)) {
map[key] = {}; map[key] = {};
}
map[key][property] = string.value; map[key][property] = string.value;
} }
return map; return map;
} }
function getLocalizedString(strings, id, property) { function getLocalizedString(strings, id, property) {
property = property || 'textContent'; property = property || 'textContent';
if (id in strings) if (id in strings) {
return strings[id][property]; return strings[id][property];
}
return id; return id;
} }
function makeContentReadable(obj, window) { function makeContentReadable(obj, window) {
//#if MOZCENTRAL //#if MOZCENTRAL
/* jshint -W027 */
return Cu.cloneInto(obj, window); return Cu.cloneInto(obj, window);
//#else //#else
if (Cu.cloneInto) { if (Cu.cloneInto) {
@ -178,7 +181,7 @@ function makeContentReadable(obj, window) {
} }
var expose = {}; var expose = {};
for (let k in obj) { for (let k in obj) {
expose[k] = "r"; expose[k] = 'r';
} }
obj.__exposedProps__ = expose; obj.__exposedProps__ = expose;
return obj; return obj;
@ -274,7 +277,7 @@ ChromeActions.prototype = {
// the original url. // the original url.
var originalUri = NetUtil.newURI(data.originalUrl); var originalUri = NetUtil.newURI(data.originalUrl);
var filename = data.filename; var filename = data.filename;
if (typeof filename !== 'string' || if (typeof filename !== 'string' ||
(!/\.pdf$/i.test(filename) && !data.isAttachment)) { (!/\.pdf$/i.test(filename) && !data.isAttachment)) {
filename = 'document.pdf'; filename = 'document.pdf';
} }
@ -293,8 +296,9 @@ ChromeActions.prototype = {
} }
NetUtil.asyncFetch(netChannel, function(aInputStream, aResult) { NetUtil.asyncFetch(netChannel, function(aInputStream, aResult) {
if (!Components.isSuccessCode(aResult)) { if (!Components.isSuccessCode(aResult)) {
if (sendResponse) if (sendResponse) {
sendResponse(true); sendResponse(true);
}
return; return;
} }
// Create a nsIInputStreamChannel so we can set the url on the channel // Create a nsIInputStreamChannel so we can set the url on the channel
@ -328,11 +332,13 @@ ChromeActions.prototype = {
this.extListener.onStartRequest(aRequest, aContext); this.extListener.onStartRequest(aRequest, aContext);
}, },
onStopRequest: function(aRequest, aContext, aStatusCode) { onStopRequest: function(aRequest, aContext, aStatusCode) {
if (this.extListener) if (this.extListener) {
this.extListener.onStopRequest(aRequest, aContext, aStatusCode); this.extListener.onStopRequest(aRequest, aContext, aStatusCode);
}
// Notify the content code we're done downloading. // Notify the content code we're done downloading.
if (sendResponse) if (sendResponse) {
sendResponse(false); sendResponse(false);
}
}, },
onDataAvailable: function(aRequest, aContext, aInputStream, aOffset, onDataAvailable: function(aRequest, aContext, aInputStream, aOffset,
aCount) { aCount) {
@ -350,9 +356,9 @@ ChromeActions.prototype = {
getStrings: function(data) { getStrings: function(data) {
try { try {
// Lazy initialization of localizedStrings // Lazy initialization of localizedStrings
if (!('localizedStrings' in this)) if (!('localizedStrings' in this)) {
this.localizedStrings = getLocalizedStrings('viewer.properties'); this.localizedStrings = getLocalizedStrings('viewer.properties');
}
var result = this.localizedStrings[data]; var result = this.localizedStrings[data];
return JSON.stringify(result || null); return JSON.stringify(result || null);
} catch (e) { } catch (e) {
@ -405,10 +411,10 @@ ChromeActions.prototype = {
if (!documentStats || typeof documentStats !== 'object') { if (!documentStats || typeof documentStats !== 'object') {
break; break;
} }
var streamTypes = documentStats.streamTypes; var i, streamTypes = documentStats.streamTypes;
if (Array.isArray(streamTypes)) { if (Array.isArray(streamTypes)) {
var STREAM_TYPE_ID_LIMIT = 20; var STREAM_TYPE_ID_LIMIT = 20;
for (var i = 0; i < STREAM_TYPE_ID_LIMIT; i++) { for (i = 0; i < STREAM_TYPE_ID_LIMIT; i++) {
if (streamTypes[i] && if (streamTypes[i] &&
!this.telemetryState.streamTypesUsed[i]) { !this.telemetryState.streamTypesUsed[i]) {
PdfJsTelemetry.onStreamType(i); PdfJsTelemetry.onStreamType(i);
@ -419,7 +425,7 @@ ChromeActions.prototype = {
var fontTypes = documentStats.fontTypes; var fontTypes = documentStats.fontTypes;
if (Array.isArray(fontTypes)) { if (Array.isArray(fontTypes)) {
var FONT_TYPE_ID_LIMIT = 20; var FONT_TYPE_ID_LIMIT = 20;
for (var i = 0; i < FONT_TYPE_ID_LIMIT; i++) { for (i = 0; i < FONT_TYPE_ID_LIMIT; i++) {
if (fontTypes[i] && if (fontTypes[i] &&
!this.telemetryState.fontTypesUsed[i]) { !this.telemetryState.fontTypesUsed[i]) {
PdfJsTelemetry.onFontType(i); PdfJsTelemetry.onFontType(i);
@ -452,8 +458,9 @@ ChromeActions.prototype = {
getLocalizedString(strings, 'open_with_different_viewer', 'accessKey')); getLocalizedString(strings, 'open_with_different_viewer', 'accessKey'));
}, },
updateFindControlState: function(data) { updateFindControlState: function(data) {
if (!this.supportsIntegratedFind()) if (!this.supportsIntegratedFind()) {
return; return;
}
// Verify what we're sending to the findbar. // Verify what we're sending to the findbar.
var result = data.result; var result = data.result;
var findPrevious = data.findPrevious; var findPrevious = data.findPrevious;
@ -738,11 +745,11 @@ RequestListener.prototype.receive = function(event) {
log('Unknown action: ' + action); log('Unknown action: ' + action);
return; return;
} }
var response;
if (sync) { if (sync) {
var response = actions[action].call(this.actions, data); response = actions[action].call(this.actions, data);
event.detail.response = response; event.detail.response = response;
} else { } else {
var response;
if (!event.detail.responseExpected) { if (!event.detail.responseExpected) {
doc.documentElement.removeChild(message); doc.documentElement.removeChild(message);
response = null; response = null;
@ -750,7 +757,8 @@ RequestListener.prototype.receive = function(event) {
response = function sendResponse(response) { response = function sendResponse(response) {
try { try {
var listener = doc.createEvent('CustomEvent'); var listener = doc.createEvent('CustomEvent');
let detail = makeContentReadable({response: response}, doc.defaultView); let detail = makeContentReadable({response: response},
doc.defaultView);
listener.initCustomEvent('pdf.js.response', true, false, detail); listener.initCustomEvent('pdf.js.response', true, false, detail);
return message.dispatchEvent(listener); return message.dispatchEvent(listener);
} catch (e) { } catch (e) {
@ -1024,10 +1032,11 @@ PdfStreamConverter.prototype = {
return; return;
} }
if (Components.isSuccessCode(aStatusCode)) if (Components.isSuccessCode(aStatusCode)) {
this.dataListener.finish(); this.dataListener.finish();
else } else {
this.dataListener.error(aStatusCode); this.dataListener.error(aStatusCode);
}
delete this.dataListener; delete this.dataListener;
delete this.binaryStream; delete this.binaryStream;
} }

View File

@ -14,7 +14,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/*globals DEFAULT_PREFERENCES */ /* jshint esnext:true */
/* globals Components, Services, XPCOMUtils, DEFAULT_PREFERENCES */
'use strict'; 'use strict';
@ -52,39 +53,42 @@ let PdfjsChromeUtils = {
init: function () { init: function () {
if (!this._ppmm) { if (!this._ppmm) {
// global parent process message manager (PPMM) // global parent process message manager (PPMM)
this._ppmm = Cc["@mozilla.org/parentprocessmessagemanager;1"].getService(Ci.nsIMessageBroadcaster); this._ppmm = Cc['@mozilla.org/parentprocessmessagemanager;1'].
this._ppmm.addMessageListener("PDFJS:Parent:clearUserPref", this); getService(Ci.nsIMessageBroadcaster);
this._ppmm.addMessageListener("PDFJS:Parent:setIntPref", this); this._ppmm.addMessageListener('PDFJS:Parent:clearUserPref', this);
this._ppmm.addMessageListener("PDFJS:Parent:setBoolPref", this); this._ppmm.addMessageListener('PDFJS:Parent:setIntPref', this);
this._ppmm.addMessageListener("PDFJS:Parent:setCharPref", this); this._ppmm.addMessageListener('PDFJS:Parent:setBoolPref', this);
this._ppmm.addMessageListener("PDFJS:Parent:setStringPref", this); this._ppmm.addMessageListener('PDFJS:Parent:setCharPref', this);
this._ppmm.addMessageListener("PDFJS:Parent:isDefaultHandlerApp", this); this._ppmm.addMessageListener('PDFJS:Parent:setStringPref', this);
this._ppmm.addMessageListener('PDFJS:Parent:isDefaultHandlerApp', this);
// global dom message manager (MMg) // global dom message manager (MMg)
this._mmg = Cc["@mozilla.org/globalmessagemanager;1"].getService(Ci.nsIMessageListenerManager); this._mmg = Cc['@mozilla.org/globalmessagemanager;1'].
this._mmg.addMessageListener("PDFJS:Parent:getChromeWindow", this); getService(Ci.nsIMessageListenerManager);
this._mmg.addMessageListener("PDFJS:Parent:getFindBar", this); this._mmg.addMessageListener('PDFJS:Parent:getChromeWindow', this);
this._mmg.addMessageListener("PDFJS:Parent:displayWarning", this); this._mmg.addMessageListener('PDFJS:Parent:getFindBar', this);
this._mmg.addMessageListener('PDFJS:Parent:displayWarning', this);
// observer to handle shutdown // observer to handle shutdown
Services.obs.addObserver(this, "quit-application", false); Services.obs.addObserver(this, 'quit-application', false);
} }
}, },
uninit: function () { uninit: function () {
if (this._ppmm) { if (this._ppmm) {
this._ppmm.removeMessageListener("PDFJS:Parent:clearUserPref", this); this._ppmm.removeMessageListener('PDFJS:Parent:clearUserPref', this);
this._ppmm.removeMessageListener("PDFJS:Parent:setIntPref", this); this._ppmm.removeMessageListener('PDFJS:Parent:setIntPref', this);
this._ppmm.removeMessageListener("PDFJS:Parent:setBoolPref", this); this._ppmm.removeMessageListener('PDFJS:Parent:setBoolPref', this);
this._ppmm.removeMessageListener("PDFJS:Parent:setCharPref", this); this._ppmm.removeMessageListener('PDFJS:Parent:setCharPref', this);
this._ppmm.removeMessageListener("PDFJS:Parent:setStringPref", this); this._ppmm.removeMessageListener('PDFJS:Parent:setStringPref', this);
this._ppmm.removeMessageListener("PDFJS:Parent:isDefaultHandlerApp", this); this._ppmm.removeMessageListener('PDFJS:Parent:isDefaultHandlerApp',
this);
this._mmg.removeMessageListener("PDFJS:Parent:getChromeWindow", this); this._mmg.removeMessageListener('PDFJS:Parent:getChromeWindow', this);
this._mmg.removeMessageListener("PDFJS:Parent:getFindBar", this); this._mmg.removeMessageListener('PDFJS:Parent:getFindBar', this);
this._mmg.removeMessageListener("PDFJS:Parent:displayWarning", this); this._mmg.removeMessageListener('PDFJS:Parent:displayWarning', this);
Services.obs.removeObserver(this, "quit-application", false); Services.obs.removeObserver(this, 'quit-application', false);
this._mmg = null; this._mmg = null;
this._ppmm = null; this._ppmm = null;
@ -98,14 +102,14 @@ let PdfjsChromeUtils = {
* the module's registration. * the module's registration.
*/ */
notifyChildOfSettingsChange: function () { notifyChildOfSettingsChange: function () {
if (Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_DEFAULT && if (Services.appinfo.processType ===
this._ppmm) { Services.appinfo.PROCESS_TYPE_DEFAULT && this._ppmm) {
// XXX kinda bad, we want to get the parent process mm associated // XXX kinda bad, we want to get the parent process mm associated
// with the content process. _ppmm is currently the global process // with the content process. _ppmm is currently the global process
// manager, which means this is going to fire to every child process // manager, which means this is going to fire to every child process
// we have open. Unfortunately I can't find a way to get at that // we have open. Unfortunately I can't find a way to get at that
// process specific mm from js. // process specific mm from js.
this._ppmm.broadcastAsyncMessage("PDFJS:Child:refreshSettings", {}); this._ppmm.broadcastAsyncMessage('PDFJS:Child:refreshSettings', {});
} }
}, },
@ -114,38 +118,38 @@ let PdfjsChromeUtils = {
*/ */
observe: function(aSubject, aTopic, aData) { observe: function(aSubject, aTopic, aData) {
if (aTopic == "quit-application") { if (aTopic === 'quit-application') {
this.uninit(); this.uninit();
} }
}, },
receiveMessage: function (aMsg) { receiveMessage: function (aMsg) {
switch (aMsg.name) { switch (aMsg.name) {
case "PDFJS:Parent:clearUserPref": case 'PDFJS:Parent:clearUserPref':
this._clearUserPref(aMsg.data.name); this._clearUserPref(aMsg.data.name);
break; break;
case "PDFJS:Parent:setIntPref": case 'PDFJS:Parent:setIntPref':
this._setIntPref(aMsg.data.name, aMsg.data.value); this._setIntPref(aMsg.data.name, aMsg.data.value);
break; break;
case "PDFJS:Parent:setBoolPref": case 'PDFJS:Parent:setBoolPref':
this._setBoolPref(aMsg.data.name, aMsg.data.value); this._setBoolPref(aMsg.data.name, aMsg.data.value);
break; break;
case "PDFJS:Parent:setCharPref": case 'PDFJS:Parent:setCharPref':
this._setCharPref(aMsg.data.name, aMsg.data.value); this._setCharPref(aMsg.data.name, aMsg.data.value);
break; break;
case "PDFJS:Parent:setStringPref": case 'PDFJS:Parent:setStringPref':
this._setStringPref(aMsg.data.name, aMsg.data.value); this._setStringPref(aMsg.data.name, aMsg.data.value);
break; break;
case "PDFJS:Parent:isDefaultHandlerApp": case 'PDFJS:Parent:isDefaultHandlerApp':
return this.isDefaultHandlerApp(); return this.isDefaultHandlerApp();
case "PDFJS:Parent:displayWarning": case 'PDFJS:Parent:displayWarning':
this._displayWarning(aMsg); this._displayWarning(aMsg);
break; break;
// CPOW getters // CPOW getters
case "PDFJS:Parent:getChromeWindow": case 'PDFJS:Parent:getChromeWindow':
return this._getChromeWindow(aMsg); return this._getChromeWindow(aMsg);
case "PDFJS:Parent:getFindBar": case 'PDFJS:Parent:getFindBar':
return this._getFindBar(aMsg); return this._getFindBar(aMsg);
} }
}, },
@ -178,8 +182,8 @@ let PdfjsChromeUtils = {
let unPrefixedName = aPrefName.split(PREF_PREFIX + '.'); let unPrefixedName = aPrefName.split(PREF_PREFIX + '.');
if (unPrefixedName[0] !== '' || if (unPrefixedName[0] !== '' ||
this._allowedPrefNames.indexOf(unPrefixedName[1]) === -1) { this._allowedPrefNames.indexOf(unPrefixedName[1]) === -1) {
let msg = "'" + aPrefName + "' "; let msg = '"' + aPrefName + '" ' +
msg += "can't be accessed from content. See PdfjsChromeUtils." 'can\'t be accessed from content. See PdfjsChromeUtils.';
throw new Error(msg); throw new Error(msg);
} }
}, },
@ -219,8 +223,8 @@ let PdfjsChromeUtils = {
*/ */
isDefaultHandlerApp: function () { isDefaultHandlerApp: function () {
var handlerInfo = Svc.mime.getFromTypeAndExtension(PDF_CONTENT_TYPE, 'pdf'); var handlerInfo = Svc.mime.getFromTypeAndExtension(PDF_CONTENT_TYPE, 'pdf');
return !handlerInfo.alwaysAskBeforeHandling && return (!handlerInfo.alwaysAskBeforeHandling &&
handlerInfo.preferredAction == Ci.nsIHandlerInfo.handleInternally; handlerInfo.preferredAction === Ci.nsIHandlerInfo.handleInternally);
}, },
/* /*
@ -285,13 +289,13 @@ function PdfjsFindbarWrapper(aBrowser) {
} }
//#endif //#endif
this._findbar = tabbrowser.getFindBar(tab); this._findbar = tabbrowser.getFindBar(tab);
}; }
PdfjsFindbarWrapper.prototype = { PdfjsFindbarWrapper.prototype = {
__exposedProps__: { __exposedProps__: {
addEventListener: "r", addEventListener: 'r',
removeEventListener: "r", removeEventListener: 'r',
updateControlState: "r", updateControlState: 'r',
}, },
_findbar: null, _findbar: null,
@ -300,7 +304,8 @@ PdfjsFindbarWrapper.prototype = {
}, },
addEventListener: function (aType, aListener, aUseCapture, aWantsUntrusted) { addEventListener: function (aType, aListener, aUseCapture, aWantsUntrusted) {
this._findbar.addEventListener(aType, aListener, aUseCapture, aWantsUntrusted); this._findbar.addEventListener(aType, aListener, aUseCapture,
aWantsUntrusted);
}, },
removeEventListener: function (aType, aListener, aUseCapture) { removeEventListener: function (aType, aListener, aUseCapture) {
@ -310,11 +315,11 @@ PdfjsFindbarWrapper.prototype = {
function PdfjsWindowWrapper(aBrowser) { function PdfjsWindowWrapper(aBrowser) {
this._window = aBrowser.ownerDocument.defaultView; this._window = aBrowser.ownerDocument.defaultView;
}; }
PdfjsWindowWrapper.prototype = { PdfjsWindowWrapper.prototype = {
__exposedProps__: { __exposedProps__: {
valueOf: "r", valueOf: 'r',
}, },
_window: null, _window: null,
@ -322,4 +327,3 @@ PdfjsWindowWrapper.prototype = {
return this._window.valueOf(); return this._window.valueOf();
} }
}; };

View File

@ -1,3 +1,5 @@
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
/* Copyright 2012 Mozilla Foundation /* Copyright 2012 Mozilla Foundation
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -12,6 +14,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* jshint esnext:true */
/* globals Components, Services, XPCOMUtils */
'use strict'; 'use strict';
@ -33,23 +37,25 @@ let PdfjsContentUtils = {
*/ */
get isRemote() { get isRemote() {
return Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_CONTENT; return (Services.appinfo.processType ===
Services.appinfo.PROCESS_TYPE_CONTENT);
}, },
init: function () { init: function () {
// child *process* mm, or when loaded into the parent for in-content // child *process* mm, or when loaded into the parent for in-content
// support the psuedo child process mm 'child PPMM'. // support the psuedo child process mm 'child PPMM'.
if (!this._mm) { if (!this._mm) {
this._mm = Cc["@mozilla.org/childprocessmessagemanager;1"].getService(Ci.nsISyncMessageSender); this._mm = Cc['@mozilla.org/childprocessmessagemanager;1'].
this._mm.addMessageListener("PDFJS:Child:refreshSettings", this); getService(Ci.nsISyncMessageSender);
Services.obs.addObserver(this, "quit-application", false); this._mm.addMessageListener('PDFJS:Child:refreshSettings', this);
Services.obs.addObserver(this, 'quit-application', false);
} }
}, },
uninit: function () { uninit: function () {
if (this._mm) { if (this._mm) {
this._mm.removeMessageListener("PDFJS:Child:refreshSettings", this); this._mm.removeMessageListener('PDFJS:Child:refreshSettings', this);
Services.obs.removeObserver(this, "quit-application"); Services.obs.removeObserver(this, 'quit-application');
} }
this._mm = null; this._mm = null;
}, },
@ -61,34 +67,34 @@ let PdfjsContentUtils = {
*/ */
clearUserPref: function (aPrefName) { clearUserPref: function (aPrefName) {
this._mm.sendSyncMessage("PDFJS:Parent:clearUserPref", { this._mm.sendSyncMessage('PDFJS:Parent:clearUserPref', {
name: aPrefName name: aPrefName
}); });
}, },
setIntPref: function (aPrefName, aPrefValue) { setIntPref: function (aPrefName, aPrefValue) {
this._mm.sendSyncMessage("PDFJS:Parent:setIntPref", { this._mm.sendSyncMessage('PDFJS:Parent:setIntPref', {
name: aPrefName, name: aPrefName,
value: aPrefValue value: aPrefValue
}); });
}, },
setBoolPref: function (aPrefName, aPrefValue) { setBoolPref: function (aPrefName, aPrefValue) {
this._mm.sendSyncMessage("PDFJS:Parent:setBoolPref", { this._mm.sendSyncMessage('PDFJS:Parent:setBoolPref', {
name: aPrefName, name: aPrefName,
value: aPrefValue value: aPrefValue
}); });
}, },
setCharPref: function (aPrefName, aPrefValue) { setCharPref: function (aPrefName, aPrefValue) {
this._mm.sendSyncMessage("PDFJS:Parent:setCharPref", { this._mm.sendSyncMessage('PDFJS:Parent:setCharPref', {
name: aPrefName, name: aPrefName,
value: aPrefValue value: aPrefValue
}); });
}, },
setStringPref: function (aPrefName, aPrefValue) { setStringPref: function (aPrefName, aPrefValue) {
this._mm.sendSyncMessage("PDFJS:Parent:setStringPref", { this._mm.sendSyncMessage('PDFJS:Parent:setStringPref', {
name: aPrefName, name: aPrefName,
value: aPrefValue value: aPrefValue
}); });
@ -99,7 +105,7 @@ let PdfjsContentUtils = {
* handler app settings only available in the parent process. * handler app settings only available in the parent process.
*/ */
isDefaultHandlerApp: function () { isDefaultHandlerApp: function () {
return this._mm.sendSyncMessage("PDFJS:Parent:isDefaultHandlerApp")[0]; return this._mm.sendSyncMessage('PDFJS:Parent:isDefaultHandlerApp')[0];
}, },
/* /*
@ -112,7 +118,7 @@ let PdfjsContentUtils = {
.getInterface(Ci.nsIDocShell) .getInterface(Ci.nsIDocShell)
.QueryInterface(Ci.nsIInterfaceRequestor) .QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIContentFrameMessageManager); .getInterface(Ci.nsIContentFrameMessageManager);
winmm.sendAsyncMessage("PDFJS:Parent:displayWarning", { winmm.sendAsyncMessage('PDFJS:Parent:displayWarning', {
message: aMessage, message: aMessage,
label: aLabel, label: aLabel,
accessKey: accessKey accessKey: accessKey
@ -126,17 +132,18 @@ let PdfjsContentUtils = {
*/ */
observe: function(aSubject, aTopic, aData) { observe: function(aSubject, aTopic, aData) {
if (aTopic == "quit-application") { if (aTopic === 'quit-application') {
this.uninit(); this.uninit();
} }
}, },
receiveMessage: function (aMsg) { receiveMessage: function (aMsg) {
switch (aMsg.name) { switch (aMsg.name) {
case "PDFJS:Child:refreshSettings": case 'PDFJS:Child:refreshSettings':
// Only react to this if we are remote. // Only react to this if we are remote.
if (Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_CONTENT) { if (Services.appinfo.processType ===
let jsm = "resource://pdf.js/PdfJs.jsm"; Services.appinfo.PROCESS_TYPE_CONTENT) {
let jsm = 'resource://pdf.js/PdfJs.jsm';
let pdfjs = Components.utils.import(jsm, {}).PdfJs; let pdfjs = Components.utils.import(jsm, {}).PdfJs;
pdfjs.updateRegistration(); pdfjs.updateRegistration();
} }
@ -159,12 +166,14 @@ let PdfjsContentUtils = {
// send over a small container for the object we want. // send over a small container for the object we want.
let suitcase = { let suitcase = {
_window: null, _window: null,
setChromeWindow: function (aObj) { this._window = aObj; } setChromeWindow: function (aObj) {
} this._window = aObj;
if (!winmm.sendSyncMessage("PDFJS:Parent:getChromeWindow", {}, }
};
if (!winmm.sendSyncMessage('PDFJS:Parent:getChromeWindow', {},
{ suitcase: suitcase })[0]) { { suitcase: suitcase })[0]) {
Cu.reportError("A request for a CPOW wrapped chrome window " + Cu.reportError('A request for a CPOW wrapped chrome window ' +
"failed for unknown reasons."); 'failed for unknown reasons.');
return null; return null;
} }
return suitcase._window; return suitcase._window;
@ -179,12 +188,14 @@ let PdfjsContentUtils = {
.getInterface(Ci.nsIContentFrameMessageManager); .getInterface(Ci.nsIContentFrameMessageManager);
let suitcase = { let suitcase = {
_findbar: null, _findbar: null,
setFindBar: function (aObj) { this._findbar = aObj; } setFindBar: function (aObj) {
} this._findbar = aObj;
if (!winmm.sendSyncMessage("PDFJS:Parent:getFindBar", {}, }
};
if (!winmm.sendSyncMessage('PDFJS:Parent:getFindBar', {},
{ suitcase: suitcase })[0]) { { suitcase: suitcase })[0]) {
Cu.reportError("A request for a CPOW wrapped findbar " + Cu.reportError('A request for a CPOW wrapped findbar ' +
"failed for unknown reasons."); 'failed for unknown reasons.');
return null; return null;
} }
return suitcase._findbar; return suitcase._findbar;

View File

@ -1460,8 +1460,10 @@ target.lint = function() {
echo('jshint is not installed -- installing...'); echo('jshint is not installed -- installing...');
exec('npm install jshint@2.4.x'); // TODO read version from package.json exec('npm install jshint@2.4.x'); // TODO read version from package.json
} }
// Lint the Firefox specific *.jsm files.
var options = '--extra-ext .jsm';
var exitCode = exec('"' + jshintPath + '" .').code; var exitCode = exec('"' + jshintPath + '" ' + options + ' .').code;
if (exitCode === 0) { if (exitCode === 0) {
echo('files checked, no errors found'); echo('files checked, no errors found');
} }