Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Unified Diff: chrome/browser/printing/printing_message_filter.cc

Issue 740983002: Implement window.print() on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/printing/printing_message_filter.cc
diff --git a/chrome/browser/printing/printing_message_filter.cc b/chrome/browser/printing/printing_message_filter.cc
index 6af14f7f13139f166d1dea644f004294a9b5dcdd..8a8271927a46f950a19bafb5e136a968b52865a9 100644
--- a/chrome/browser/printing/printing_message_filter.cc
+++ b/chrome/browser/printing/printing_message_filter.cc
@@ -34,6 +34,7 @@
#if defined(OS_ANDROID)
#include "base/strings/string_number_conversions.h"
+#include "chrome/browser/android/tab_android.h"
#include "chrome/browser/printing/print_view_manager_basic.h"
#include "printing/printing_context_android.h"
#endif
@@ -129,6 +130,10 @@ bool PrintingMessageFilter::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_HANDLER(PrintHostMsg_TempFileForPrintingWritten,
OnTempFileForPrintingWritten)
#endif
+#if defined(OS_ANDROID)
+ IPC_MESSAGE_HANDLER_DELAY_REPLY(PrintHostMsg_InitiateAndroidPrint,
Vitaly Buka (NO REVIEWS) 2014/11/21 17:05:12 don't need new message
+ OnInitiateAndroidPrint)
+#endif
IPC_MESSAGE_HANDLER(PrintHostMsg_IsPrintingEnabled, OnIsPrintingEnabled)
IPC_MESSAGE_HANDLER_DELAY_REPLY(PrintHostMsg_GetDefaultPrintSettings,
OnGetDefaultPrintSettings)
@@ -323,6 +328,9 @@ void PrintingMessageFilter::OnScriptedPrint(
printer_query =
queue_->CreatePrinterQuery(render_process_id_, reply_msg->routing_id());
}
+
+ DLOG(INFO) << "DGN OnScriptedPrint - cookie: " << params.cookie;
+
printer_query->GetSettings(
Vitaly Buka (NO REVIEWS) 2014/11/21 17:05:12 Here it goes into Printing::AskUserForSettings and
PrinterQuery::ASK_USER,
params.expected_pages_count,
@@ -338,6 +346,9 @@ void PrintingMessageFilter::OnScriptedPrintReply(
scoped_refptr<PrinterQuery> printer_query,
IPC::Message* reply_msg) {
PrintMsg_PrintPages_Params params;
+
+DLOG(INFO) << "DGN OnScriptedPrintReply";
+
#if defined(OS_ANDROID)
// We need to save the routing ID here because Send method below deletes the
// |reply_msg| before we can get the routing ID for the Android code.
@@ -373,6 +384,9 @@ void PrintingMessageFilter::OnScriptedPrintReply(
#if defined(OS_ANDROID)
void PrintingMessageFilter::UpdateFileDescriptor(int render_view_id, int fd) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
+
+ DLOG(INFO) << "DGN UpdateFileDescriptor";
+
content::WebContents* wc = GetWebContentsForRenderView(render_view_id);
if (!wc)
return;
@@ -380,6 +394,37 @@ void PrintingMessageFilter::UpdateFileDescriptor(int render_view_id, int fd) {
PrintViewManagerBasic::FromWebContents(wc);
print_view_manager->set_file_descriptor(base::FileDescriptor(fd, false));
}
+
+void PrintingMessageFilter::ShowPrintDialog(int render_view_id) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ content::WebContents* wc = GetWebContentsForRenderView(render_view_id);
Vitaly Buka (NO REVIEWS) 2014/11/21 17:05:13 PrintingContext::Delegate suppose provide necessar
+ TabAndroid* tab = TabAndroid::FromWebContents(wc);
+ if (tab) tab->ShowPrintDialog();
+}
+
+void PrintingMessageFilter::OnInitiateAndroidPrint(int cookie, IPC::Message* reply_msg) {
+
+ DLOG(INFO) << "DGN OnInitiateAndroidPrint - cookie: " << cookie;
+
+ scoped_refptr<PrinterQuery> printer_query = queue_->PopPrinterQuery(cookie);
+ if (!printer_query.get()) {
+ printer_query =
+ queue_->CreatePrinterQuery(render_process_id_, reply_msg->routing_id());
dgn 2014/11/20 12:26:16 Here I'm trying to get/create the PrinterQuery tha
+ }
+ printer_query->SetInitiatedFromAndroidScript();
dgn 2014/11/20 12:26:16 Placeholder method for test. Eventusally this woul
+
+ // we want it to be retrieved by the upcoming OnScriptedPrint call (that does not work)
+ queue_->QueuePrinterQuery(printer_query.get());
+
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&PrintingMessageFilter::ShowPrintDialog,
+ this,
+ reply_msg->routing_id()));
+ DLOG(INFO) << "DGN OnInitiateAndroidPrint - Post task returned";
+ Send(reply_msg); // TODO: Send that only once java's onFinish is called.
+}
+
#endif
void PrintingMessageFilter::OnUpdatePrintSettings(

Powered by Google App Engine
This is Rietveld 408576698