Add preprocessor directives for the extension; and refactor FirefoxCom callback

This commit is contained in:
Yury Delendik 2014-05-28 10:21:58 -05:00
parent da93e65d8c
commit 68b037ffb0
2 changed files with 15 additions and 5 deletions

View File

@ -161,15 +161,22 @@ function getLocalizedString(strings, id, property) {
} }
function makeContentReadable(obj, window) { function makeContentReadable(obj, window) {
//#if MOZCENTRAL
return Cu.cloneInto(obj, window);
//#else
if (Cu.cloneInto) { if (Cu.cloneInto) {
return Cu.cloneInto(obj, window); return Cu.cloneInto(obj, window);
} }
if (typeof obj !== 'object' || obj === null) {
return obj;
}
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;
//#endif
} }
// PDF data storage // PDF data storage
@ -698,7 +705,7 @@ var StandardChromeActions = (function StandardChromeActionsClosure() {
return StandardChromeActions; return StandardChromeActions;
})(); })();
// Event listener to trigger chrome privedged code. // Event listener to trigger chrome privileged code.
function RequestListener(actions) { function RequestListener(actions) {
this.actions = actions; this.actions = actions;
} }
@ -719,7 +726,7 @@ RequestListener.prototype.receive = function(event) {
event.detail.response = response; event.detail.response = response;
} else { } else {
var response; var response;
if (!event.detail.callback) { if (!event.detail.responseExpected) {
doc.documentElement.removeChild(message); doc.documentElement.removeChild(message);
response = null; response = null;
} else { } else {

View File

@ -64,9 +64,12 @@ var FirefoxCom = (function FirefoxComClosure() {
document.documentElement.appendChild(request); document.documentElement.appendChild(request);
var sender = document.createEvent('CustomEvent'); var sender = document.createEvent('CustomEvent');
sender.initCustomEvent('pdf.js.message', true, false, sender.initCustomEvent('pdf.js.message', true, false, {
{action: action, data: data, sync: false, action: action,
callback: callback}); data: data,
sync: false,
responseExpected: !!callback
});
return request.dispatchEvent(sender); return request.dispatchEvent(sender);
} }
}; };