Bug 1015115 - switch to cloneInto in pdf.js, r?yury

This commit is contained in:
Gijs Kruitbosch 2014-05-23 13:35:33 +01:00 committed by Yury Delendik
parent c321f51e54
commit da93e65d8c

View File

@ -160,6 +160,18 @@ function getLocalizedString(strings, id, property) {
return id;
}
function makeContentReadable(obj, window) {
if (Cu.cloneInto) {
return Cu.cloneInto(obj, window);
}
var expose = {};
for (let k in obj) {
expose[k] = "r";
}
obj.__exposedProps__ = expose;
return obj;
}
// PDF data storage
function PdfDataListener(length) {
this.length = length; // less than 0, if length is unknown
@ -704,9 +716,7 @@ RequestListener.prototype.receive = function(event) {
}
if (sync) {
var response = actions[action].call(this.actions, data);
var detail = event.detail;
detail.__exposedProps__ = {response: 'r'};
detail.response = response;
event.detail.response = response;
} else {
var response;
if (!event.detail.callback) {
@ -716,9 +726,8 @@ RequestListener.prototype.receive = function(event) {
response = function sendResponse(response) {
try {
var listener = doc.createEvent('CustomEvent');
listener.initCustomEvent('pdf.js.response', true, false,
{response: response,
__exposedProps__: {response: 'r'}});
let detail = makeContentReadable({response: response}, doc.defaultView);
listener.initCustomEvent('pdf.js.response', true, false, detail);
return message.dispatchEvent(listener);
} catch (e) {
// doc is no longer accessible because the requestor is already
@ -761,13 +770,13 @@ FindEventManager.prototype.handleEvent = function(e) {
var contentWindow = this.contentWindow;
// Only forward the events if they are for our dom window.
if (chromeWindow.gBrowser.selectedBrowser.contentWindow === contentWindow) {
var detail = e.detail;
detail.__exposedProps__ = {
query: 'r',
caseSensitive: 'r',
highlightAll: 'r',
findPrevious: 'r'
var detail = {
query: e.detail.query,
caseSensitive: e.detail.caseSensitive,
highlightAll: e.detail.highlightAll,
findPrevious: e.detail.findPrevious
};
detail = makeContentReadable(detail, contentWindow);
var forward = contentWindow.document.createEvent('CustomEvent');
forward.initCustomEvent(e.type, true, true, detail);
contentWindow.dispatchEvent(forward);