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 #6012 from asutherland/gallery-share-filenames
Browse files Browse the repository at this point in the history
Bug 805532 - [gallery] share activity does not expose the filename of the shared file, r=djf, a=blocking-basecamp for Bug 799827
  • Loading branch information
asutherland committed Oct 26, 2012
2 parents 4f69cd3 + 2afa609 commit 78451cc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
13 changes: 9 additions & 4 deletions apps/gallery/js/gallery.js
Expand Up @@ -883,17 +883,21 @@ $('thumbnails-share-button').onclick = function() {
* Image data is passed as data: URLs because we can't pass blobs
*/
function shareFiles(filenames) {
var urls = [];
var urls = [], justnames = [];
getDataURLForNextFile();

function getDataURLForNextFile() {
if (urls.length === filenames.length) {
shareURLs(urls);
shareURLs(urls, justnames);
}
else {
var i = urls.length;
var filename = filenames[i];
photodb.getFile(filename, function(file) {
// filename is identical to file.name, both of which may contain path
// information. We want to let the recipient know the name of the
// file, but not the path components.
justnames.push(filename.substring(filename.lastIndexOf('/') + 1));
var reader = new FileReader();
reader.readAsBinaryString(file);
reader.onload = function() {
Expand All @@ -907,13 +911,14 @@ function shareFiles(filenames) {

// This is called by shareFile once the filenames have
// been converted to data URLs
function shareURLs(urls) {
function shareURLs(urls, filenames) {
var a = new MozActivity({
name: 'share',
data: {
type: 'image/*',
number: urls.length,
urls: urls
urls: urls,
filenames: filenames
}
});

Expand Down
10 changes: 7 additions & 3 deletions test_apps/share-receiver/js/share-receiver.js
Expand Up @@ -2,7 +2,7 @@ window.onload = function() {
navigator.mozSetMessageHandler('activity', function(activityRequest) {
activity = activityRequest;
if (activityRequest.source.name === 'share') {
addImages(activityRequest.source.data.urls);
addImages(activityRequest.source.data);
}
});

Expand All @@ -15,12 +15,16 @@ function done() {
activity.postResult('shared');
}

function addImages(urls) {
function addImages(data) {
var urls = data.urls, filenames = data.filenames;
console.log('share receiver: got', urls.length, 'images');
urls.forEach(function(url) {
urls.forEach(function(url, iUrl) {
var img = document.createElement('img');
img.style.width = '100px';
img.src = url;
document.body.appendChild(img);
var label = document.createElement('span');
label.textContent = filenames[iUrl];
document.body.appendChild(label);
});
}

0 comments on commit 78451cc

Please sign in to comment.