Merge pull request #4858 from yurydelendik/cloneInto

Bug 1015115 - switch to cloneInto in pdf.js
This commit is contained in:
Yury Delendik 2014-05-28 10:37:22 -05:00
commit a256ffffd4
2 changed files with 36 additions and 17 deletions

View File

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

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