diff --git a/browser/extensions/mortar/host/common/ppapi-runtime.jsm b/browser/extensions/mortar/host/common/ppapi-runtime.jsm index c97851663df8..349dee9883b8 100644 --- a/browser/extensions/mortar/host/common/ppapi-runtime.jsm +++ b/browser/extensions/mortar/host/common/ppapi-runtime.jsm @@ -1720,6 +1720,7 @@ class PPAPIInstance { let mouseEventInit = { altkey: event.altkey, button: event.button, + buttons: event.buttons, clientX: event.clientX - rect.left, clientY: event.clientY - rect.top, ctrlKey: event.ctrlKey, @@ -1820,6 +1821,12 @@ class PPAPIInstance { // We need permission for showing print dialog to get print settings this.mm.sendAsyncMessage("ppapipdf.js:getPrintSettings"); break; + case 'openLink': + this.mm.sendAsyncMessage("ppapipdf.js:openLink", { + url: message.url, + disposition: message.disposition + }); + break; case 'viewport': case 'rotateClockwise': case 'rotateCounterclockwise': @@ -3126,25 +3133,37 @@ dump(`callFromJSON: < ${JSON.stringify(call)}\n`); if (event instanceof KeyboardInputEvent) { if (event.domEvent.location == event.domEvent.DOM_KEY_LOCATION_NUMPAD) { - modifiers &= PP_InputEvent_Modifier.PP_INPUTEVENT_MODIFIER_ISKEYPAD; + modifiers |= PP_InputEvent_Modifier.PP_INPUTEVENT_MODIFIER_ISKEYPAD; } else if (event.domEvent.location & event.domEvent.DOM_KEY_LOCATION_LEFT) { - modifiers &= PP_InputEvent_Modifier.PP_INPUTEVENT_MODIFIER_ISLEFT; + modifiers |= PP_InputEvent_Modifier.PP_INPUTEVENT_MODIFIER_ISLEFT; } else if (event.domEvent.location & event.domEvent.DOM_KEY_LOCATION_RIGHT) { - modifiers &= PP_InputEvent_Modifier.PP_INPUTEVENT_MODIFIER_ISRIGHT; + modifiers |= PP_InputEvent_Modifier.PP_INPUTEVENT_MODIFIER_ISRIGHT; } if (event.domEvent.repeat) { - modifiers &= PP_InputEvent_Modifier.PP_INPUTEVENT_MODIFIER_ISAUTOREPEAT; + modifiers |= PP_InputEvent_Modifier.PP_INPUTEVENT_MODIFIER_ISAUTOREPEAT; } } else if (event instanceof MouseInputEvent) { - if (event.domEvent.buttons && 0x01) { - modifiers &= PP_InputEvent_Modifier.PP_INPUTEVENT_MODIFIER_LEFTBUTTONDOWN; + if (event.domEvent.buttons & 0x01) { + modifiers |= PP_InputEvent_Modifier.PP_INPUTEVENT_MODIFIER_LEFTBUTTONDOWN; } - if (event.domEvent.buttons && 0x04) { - modifiers &= PP_InputEvent_Modifier.PP_INPUTEVENT_MODIFIER_MIDDLEBUTTONDOWN; + if (event.domEvent.buttons & 0x04) { + modifiers |= PP_InputEvent_Modifier.PP_INPUTEVENT_MODIFIER_MIDDLEBUTTONDOWN; } - if (event.domEvent.buttons && 0x02) { - modifiers &= PP_InputEvent_Modifier.PP_INPUTEVENT_MODIFIER_RIGHTBUTTONDOWN; + if (event.domEvent.buttons & 0x02) { + modifiers |= PP_InputEvent_Modifier.PP_INPUTEVENT_MODIFIER_RIGHTBUTTONDOWN; + } + if (event.domEvent.type == 'mouseup') { + // mouseup event indicates the key released only in domEvent.button + // rather than domEvent.buttons, but PDFium do use modifiers to + // determine which button is released. So we make it up here. + if (event.domEvent.button == 0) { + modifiers |= PP_InputEvent_Modifier.PP_INPUTEVENT_MODIFIER_LEFTBUTTONDOWN; + } else if (event.domEvent.button == 1) { + modifiers |= PP_InputEvent_Modifier.PP_INPUTEVENT_MODIFIER_MIDDLEBUTTONDOWN; + } else if (event.domEvent.button == 2) { + modifiers |= PP_InputEvent_Modifier.PP_INPUTEVENT_MODIFIER_RIGHTBUTTONDOWN; + } } } diff --git a/browser/extensions/mortar/host/pdf/chrome/js/viewport.js b/browser/extensions/mortar/host/pdf/chrome/js/viewport.js index b2ea4538ae56..389978318b55 100644 --- a/browser/extensions/mortar/host/pdf/chrome/js/viewport.js +++ b/browser/extensions/mortar/host/pdf/chrome/js/viewport.js @@ -782,6 +782,13 @@ class Viewport { case 'goToPage': this.page = message.page; break; + case 'navigate': + this._doAction({ + type: 'openLink', + url: message.url, + disposition: message.disposition + }); + break; } } } diff --git a/browser/extensions/mortar/host/pdf/ppapi-content-sandbox.js b/browser/extensions/mortar/host/pdf/ppapi-content-sandbox.js index 02232284c49c..4c3c1eeaadd2 100644 --- a/browser/extensions/mortar/host/pdf/ppapi-content-sandbox.js +++ b/browser/extensions/mortar/host/pdf/ppapi-content-sandbox.js @@ -180,6 +180,31 @@ mm.addMessageListener("ppapipdf.js:printPDF", ({ data }) => { }); }); +mm.addMessageListener("ppapipdf.js:openLink", ({data}) => { + const PDFIUM_WINDOW_OPEN_DISPOSITION = { + CURRENT_TAB: 1, + NEW_FOREGROUND_TAB: 3, + NEW_BACKGROUND_TAB: 4, + NEW_WINDOW: 6, + }; + switch(data.disposition) { + case PDFIUM_WINDOW_OPEN_DISPOSITION.CURRENT_TAB: + containerWindow.location.href = data.url; + break; + // We don't support opening in background tab for now. Just open it in + // foreground tab. + case PDFIUM_WINDOW_OPEN_DISPOSITION.NEW_FOREGROUND_TAB: + case PDFIUM_WINDOW_OPEN_DISPOSITION.NEW_BACKGROUND_TAB: + containerWindow.open(data.url); + break; + case PDFIUM_WINDOW_OPEN_DISPOSITION.NEW_WINDOW: + containerWindow.open(data.url, "", + "noopener=1,menubar=1,toolbar=1," + + "location=1,personalbar=1,status=1,resizable"); + break; + } +}); + mm.addMessageListener("ppapipdf.js:save", () => { let url = containerWindow.document.location; let filename = "document.pdf";