Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Firefox] Replace the CPOW with asynchronous messages for the Fallback bar #5918

Merged
merged 1 commit into from
Jul 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion extensions/firefox/content/PdfStreamConverter.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -482,9 +482,23 @@ ChromeActions.prototype = {
message = getLocalizedString(strings, 'unsupported_feature');
}
PdfJsTelemetry.onFallback();
PdfjsContentUtils.displayWarning(domWindow, message, sendResponse,
PdfjsContentUtils.displayWarning(domWindow, message,
getLocalizedString(strings, 'open_with_different_viewer'),
getLocalizedString(strings, 'open_with_different_viewer', 'accessKey'));

let winmm = domWindow.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDocShell)
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIContentFrameMessageManager);

winmm.addMessageListener('PDFJS:Child:fallbackDownload',
function fallbackDownload(msg) {
let data = msg.data;
sendResponse(data.download);

winmm.removeMessageListener('PDFJS:Child:fallbackDownload',
fallbackDownload);
});
},
updateFindControlState: function(data) {
if (!this.supportsIntegratedFind()) {
Expand Down
30 changes: 18 additions & 12 deletions extensions/firefox/content/PdfjsChromeUtils.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -295,24 +295,30 @@ let PdfjsChromeUtils = {
* a pdf displayed correctly.
*/
_displayWarning: function (aMsg) {
let json = aMsg.data;
let data = aMsg.data;
let browser = aMsg.target;
let cpowCallback = aMsg.objects.callback;

let tabbrowser = browser.getTabBrowser();
let notificationBox = tabbrowser.getNotificationBox(browser);
// Flag so we don't call the response callback twice, since if the user
// clicks open with different viewer both the button callback and

// Flag so we don't send the message twice, since if the user clicks
// "open with different viewer" both the button callback and
// eventCallback will be called.
let responseSent = false;
let messageSent = false;
function sendMessage(download) {
let mm = browser.messageManager;
mm.sendAsyncMessage('PDFJS:Child:fallbackDownload',
{ download: download });
}
let buttons = [{
label: json.label,
accessKey: json.accessKey,
label: data.label,
accessKey: data.accessKey,
callback: function() {
responseSent = true;
cpowCallback(true);
messageSent = true;
sendMessage(true);
}
}];
notificationBox.appendNotification(json.message, 'pdfjs-fallback', null,
notificationBox.appendNotification(data.message, 'pdfjs-fallback', null,
notificationBox.PRIORITY_INFO_LOW,
buttons,
function eventsCallback(eventType) {
Expand All @@ -323,10 +329,10 @@ let PdfjsChromeUtils = {
}
// Don't send a response again if we already responded when the button was
// clicked.
if (responseSent) {
if (messageSent) {
return;
}
cpowCallback(false);
sendMessage(false);
});
}
};
Expand Down
4 changes: 1 addition & 3 deletions extensions/firefox/content/PdfjsContentUtils.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ let PdfjsContentUtils = {
* Request the display of a notification warning in the associated window
* when the renderer isn't sure a pdf displayed correctly.
*/
displayWarning: function (aWindow, aMessage, aCallback, aLabel, accessKey) {
displayWarning: function (aWindow, aMessage, aLabel, accessKey) {
// the child's dom frame mm associated with the window.
let winmm = aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDocShell)
Expand All @@ -122,8 +122,6 @@ let PdfjsContentUtils = {
message: aMessage,
label: aLabel,
accessKey: accessKey
}, {
callback: aCallback
});
},

Expand Down