Implement window.print() on Android
commit4c172eea8b6649f1c1c620d1daa20ce733cee9e1
authordgn <dgn@chromium.org>
Mon, 15 Dec 2014 21:11:23 +0000 (15 13:11 -0800)
committerCommit bot <commit-bot@chromium.org>
Mon, 15 Dec 2014 21:11:50 +0000 (15 21:11 +0000)
tree9ac7df8f0058d80866716752ec2563d6fb0b3f79
parent7dac4befc4743666c0fcbb92d02ccd3c1c6a8389
Implement window.print() on Android

Essentially wires up the window.print() and the basic printing path
to Android framwork's PrintManager.

The changes affect the basic printing path using
PrintingMessageFilter::OnScriptedPrint. When calling window.print() on
Android, it would now be called twice.

The first time is directly after the JS call, OnScriptedPrint is called
with a parameter telling it that it's being called from JS. It will then
end up calling PrintJobWorker::GetSettings, forwarding that information.
PrintJobWorker then takes care of calling PrintingController through JNI,
joining the same code path used when printing from chrome's menu in android:
Android framework's PrintManager is invoked, and it manages the preview, using
the tab to generate the output as the user changes his/her preferences.

Why so many changes for just that: the window.print() call is blocked until the
end of the process by message pumping. It has to be disabled when printing is
finished. It is currently done by setting a callback in the current
PrintingContext, that will be called when printing is done. PrintingController
stores the reference to it, but here we have two queries at the same time, and
only the latest PrintingContext would be stored. I added a field to store
separately the one coming from the initial call, so
that it can be used when printing is done to stop the message pumping.

TL;DR: When window.print() is called, the basic printing path is used to forward
the query to PrintManager. The PrintManager then uses almost the same path to
actually print the document (as previously implemented to power the 'Print...'
entry in the menu). The changes are mostly to ensure that JS returns when
printing is completed and not before (or never).

BUG=437338

Review URL: https://codereview.chromium.org/740983002

Cr-Commit-Position: refs/heads/master@{#308416}
29 files changed:
chrome/android/java/src/org/chromium/chrome/browser/Tab.java
chrome/browser/android/tab_android.cc
chrome/browser/android/tab_android.h
chrome/browser/printing/print_job_worker.cc
chrome/browser/printing/print_job_worker.h
chrome/browser/printing/printer_query.cc
chrome/browser/printing/printer_query.h
chrome/browser/printing/printing_message_filter.cc
chrome/common/print_messages.h
chrome/renderer/printing/print_web_view_helper.cc
chrome/renderer/printing/print_web_view_helper.h
printing/android/java/src/org/chromium/printing/PrintingContext.java
printing/android/java/src/org/chromium/printing/PrintingContextInterface.java
printing/android/java/src/org/chromium/printing/PrintingController.java
printing/android/java/src/org/chromium/printing/PrintingControllerImpl.java
printing/printing_context.h
printing/printing_context_android.cc
printing/printing_context_android.h
printing/printing_context_linux.cc
printing/printing_context_linux.h
printing/printing_context_mac.h
printing/printing_context_mac.mm
printing/printing_context_no_system_dialog.cc
printing/printing_context_no_system_dialog.h
printing/printing_context_system_dialog_win.cc
printing/printing_context_system_dialog_win.h
printing/printing_context_win.cc
printing/printing_context_win.h
printing/printing_context_win_unittest.cc