Fix code style in extensions/firefox/content/PdfStreamConverter.jsm

This commit is contained in:
Jonas Jenwald 2014-08-26 16:53:28 +02:00
parent 8921606b68
commit 4da57c3b85

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;
} }