Skip to content
This repository has been archived by the owner on Oct 2, 2018. It is now read-only.

Printing #252

Merged
merged 1 commit into from
Feb 8, 2015
Merged

Printing #252

merged 1 commit into from
Feb 8, 2015

Conversation

twiss
Copy link
Collaborator

@twiss twiss commented Dec 10, 2014

WIP, because mobile UX could be better. In particular, if someone wants to test Chrome iOS that would be much appreciated.

@ferndot
Copy link
Member

ferndot commented Dec 12, 2014

Works well in Firefox Desktop.

You might want to check if window.print() is available, and hide the menu item on platforms that do not support it, such as Firefox OS.

@twiss
Copy link
Collaborator Author

twiss commented Dec 12, 2014

hide the menu item on platforms that do not support it, such as Firefox OS

I would like to do this, but

You might want to check if window.print() is available

have you tested this? Because window.print is there on Firefox and Chrome android, it just doesn't do anything (https://crbug.com/322303). Also, we probably can't tell if printing is available at all (https://addons.mozilla.org/mobile/addon/cloud-printer/). So maybe we should rename the button to "Print view" or something on non-desktop?

@ferndot
Copy link
Member

ferndot commented Dec 16, 2014

What about: http://stackoverflow.com/a/9273097

@twiss
Copy link
Collaborator Author

twiss commented Dec 16, 2014

Well, you have to call print first before you can know whether it worked. So we could point out that they have to select print from their browser menu, but we don't even know if it's there.

@ferndot
Copy link
Member

ferndot commented Dec 16, 2014

Well, you have to call print first before you can know whether it worked.

My idea is that we use the current implementation, and then alert the user and close the popup if the print fails (instead of doing nothing).

@twiss
Copy link
Collaborator Author

twiss commented Dec 16, 2014

But there are also browsers where window.print() doesn't work, but there is in fact an option to print in the browser menu.

@ferndot
Copy link
Member

ferndot commented Dec 17, 2014

Hmm, maybe we could include that in the alert. It could say, "We cannot print this file automatically. Please select 'Print' from inside your browser if it is available."

@twiss
Copy link
Collaborator Author

twiss commented Dec 17, 2014

Done. Could you add both l10n ids? Also, this probably requires some more thinking about security than I did (postMessage, untrusted documents).

@ferndot
Copy link
Member

ferndot commented Dec 20, 2014

I will add the IDs. What security concerns did you have?

});
reader.readAsText(new Blob([
[
'<!DOCTYPE html>',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not block merging, but is there a way that we could put this in an HTML file?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible, but you would probably need similar tricks to those in #246 to get it working in Firefox (not that that's bad, maybe we could unify the document displaying of both places).

@twiss
Copy link
Collaborator Author

twiss commented Dec 20, 2014

What security concerns did you have?

As I said, I haven't thought about it at all, but basically:

  • MDN always warns about postMessage with target "*", and we're doing just that
  • Documents aren't sandboxed

@HR HR mentioned this pull request Dec 29, 2014
47 tasks
@ferndot
Copy link
Member

ferndot commented Jan 16, 2015

MDN always warns about postMessage with target "*", and we're doing just that

IIRC @jackd1 did some sort of workaround for this in the module loader. Jack, could you clarify?

@jackd1
Copy link
Member

jackd1 commented Jan 16, 2015

I used XHR to get the html, then replaced all occurrences of [ORIGIN_OF_MAIN_DOCUMENT] in all of the scripts with the actual origin, basically like an include of sorts. Failing to replace it would result in the script not being authenticated aND refusing communication with the parent.

@twiss
Copy link
Collaborator Author

twiss commented Jan 17, 2015

There's another call to postMessage * in this PR though, although it doesn't seem like a problem to me.

That leaves sandboxing. There is CSP sandbox, which is identical to iframe sandbox, but Firefox doesn't support it (https://bugzil.la/671389). Another possibility is maybe somehow getting the window to be a different origin than the opener, which (I think) happens if the opener doesn't have an origin, so that could work.

@twiss
Copy link
Collaborator Author

twiss commented Feb 1, 2015

Another possibility is maybe somehow getting the window to be a different origin than the opener, which (I think) happens if the opener doesn't have an origin, so that could work.

I tried this and not surprisingly it doesn't work, probably for the same https://bugzil.la/1095808 mentioned in the bug for this (#206 (comment)).

My only idea left is manually sanitizing the document, I'll file a bug for that.

@twiss
Copy link
Collaborator Author

twiss commented Feb 4, 2015

I've changed my mind, among other reasons because https://bugzil.la/1095808 seems to be specific to printing to a file.

The document to be printed is now sandboxed, for details see commit message.

@ferndot
Copy link
Member

ferndot commented Feb 4, 2015

That looks like a good solution 👍

Currently scripts in documents are allowed, so we need to sandbox them
so they can't go and read other documents.

We can't put the document in a sandboxed iframe because that breaks
clean pagination and reflow. Currently, meta sandbox is poorly
supported, as are Service Workers (which would also be a heavyweight
solution).

So we open the window from a sandboxed iframe, because no-allow-same-
origin trickles down to the opened window. We then position that iframe
over the print button, because of popup blockers.
@ferndot ferndot added this to the v0.4 milestone Feb 6, 2015
ferndot added a commit that referenced this pull request Feb 8, 2015
@ferndot ferndot merged commit 9001958 into codexa:develop Feb 8, 2015
@twiss twiss deleted the print branch February 8, 2015 01:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants