Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #20162 from nullaus/bug1009780
Browse files Browse the repository at this point in the history
bug 1009780 - Improve open mechanism for downloads.
  • Loading branch information
nullaus committed Jun 8, 2014
2 parents 0874095 + 5248b80 commit 3553e4f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
6 changes: 4 additions & 2 deletions apps/pdfjs/content/web/viewer.js
Expand Up @@ -5378,12 +5378,14 @@ window.addEventListener('afterprint', function afterPrint(evt) {
})();

window.navigator.mozSetMessageHandler('activity', function(activity) {
var url = activity.source.data.url;
var blob = activity.source.data.blob;
PDFJS.maxImageSize = 1024 * 1024;

var url = URL.createObjectURL(blob);
PDFView.open(url);

var cancelButton = document.getElementById('activityClose');
cancelButton.addEventListener('click', function() {
activity.postResult('close');
});
});

8 changes: 8 additions & 0 deletions apps/pdfjs/manifest.webapp
Expand Up @@ -20,6 +20,14 @@
},
"orientation": "default",
"activities": {
"open" : {
"filters": {
"type": "application/pdf"
},
"disposition": "window",
"href": "/content/web/viewer.html",
"returnValue": true
},
"view" : {
"filters": {
"type": "application/pdf"
Expand Down
9 changes: 5 additions & 4 deletions apps/settings/test/unit/download_helper_test.js
Expand Up @@ -180,15 +180,16 @@ suite('DownloadHelper', function() {

var req = DownloadHelper.open(download);

// We should always attempt to 'open' all content types.
req.onsuccess = function() {
assert.ok(false);
assert.ok(true);
stubFormatter.restore();
done();
};

req.onerror = function(evt) {
assert.equal(evt.target.error.code,
DownloadHelper.CODE.MIME_TYPE_NOT_SUPPORTED);
stubFormatter.restore();
assert.ok(false,
'All content types should be openable via third party apps.');
done();
};
});
Expand Down
19 changes: 16 additions & 3 deletions shared/js/download/download_helper.js
Expand Up @@ -308,10 +308,23 @@ var DownloadHelper = (function() {
function loaded() {
var type = getType(download);

//
// The 'open' action will always launch an activity using the original
// content type to allow for third party applications to handle
// arbitrary types of content.
//
// The 'share' action on the other hand only works with known mime
// types at this time.
//

if (type.length === 0) {
sendError(req, 'Mime type not supported: ' + type,
CODE.MIME_TYPE_NOT_SUPPORTED);
return;
type = download.contentType;

if (actionType !== ActionsFactory.TYPE.OPEN) {
sendError(req, 'Mime type not supported: ' + type,
CODE.MIME_TYPE_NOT_SUPPORTED);
return;
}
}

var blobReq = getBlob(download);
Expand Down

0 comments on commit 3553e4f

Please sign in to comment.