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

Unified Diff: chrome/renderer/printing/print_web_view_helper.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/renderer/printing/print_web_view_helper.cc
diff --git a/chrome/renderer/printing/print_web_view_helper.cc b/chrome/renderer/printing/print_web_view_helper.cc
index 494ab7ea024d962eb649c50843cba6b281fa2fb8..eeab5d9093b64373470128d0aa989cbe7acaebd4 100644
--- a/chrome/renderer/printing/print_web_view_helper.cc
+++ b/chrome/renderer/printing/print_web_view_helper.cc
@@ -794,9 +794,6 @@ void PrintWebViewHelper::DisablePreview() {
bool PrintWebViewHelper::IsScriptInitiatedPrintAllowed(
blink::WebFrame* frame, bool user_initiated) {
-#if defined(OS_ANDROID)
- return false;
dgn 2014/11/20 12:26:16 That's how window.print() was disabled
-#endif // defined(OS_ANDROID)
// If preview is enabled, then the print dialog is tab modal, and the user
// can always close the tab on a mis-behaving page (the system print dialog
// is app modal). If the print was initiated through user action, don't
@@ -821,6 +818,9 @@ void PrintWebViewHelper::DidStopLoading() {
// Prints |frame| which called window.print().
void PrintWebViewHelper::PrintPage(blink::WebLocalFrame* frame,
bool user_initiated) {
+
+ DLOG(INFO) << "DGN PrintPage - From Script - routing_id: " << routing_id();
+
DCHECK(frame);
// Allow Prerendering to cancel this print request if necessary.
@@ -830,15 +830,33 @@ void PrintWebViewHelper::PrintPage(blink::WebLocalFrame* frame,
return;
}
- if (!IsScriptInitiatedPrintAllowed(frame, user_initiated))
+ if (!IsScriptInitiatedPrintAllowed(frame, user_initiated)) {
+ DLOG(INFO) << "DGN PrintPage - Script printing not allowed";
return;
+ }
+#if defined(OS_ANDROID)
+ int cookie = 0;
+ if (!print_pages_params_) {
+ DLOG(INFO) << "DGN PrintPage - no print_pages_params_";
+ } else {
+ cookie = print_pages_params_->params.document_cookie;
dgn 2014/11/20 12:26:16 how to properly initialize params? I currently alw
+ DLOG(INFO) << "DGN PrintPage - print_pages_params_->params.document_cookie is " << cookie;
+ }
+
+ DLOG(INFO) << "DGN PrintPage - Sending InitiateAndroidPrint";
+ IPC::SyncMessage* msg = new PrintHostMsg_InitiateAndroidPrint(routing_id(), cookie);
+ msg->EnableMessagePumping();
+ Send(msg);
dgn 2014/11/20 12:26:16 This is the where the renderer should wait until p
+ DLOG(INFO) << "DGN PrintPage - InitiateAndroidPrint returned";
+#else
if (!g_is_preview_enabled_) {
Print(frame, blink::WebNode());
Vitaly Buka (NO REVIEWS) 2014/11/21 17:05:13 it should go into Print(frame, blink::WebNode());
} else {
print_preview_context_.InitWithFrame(frame);
RequestPrintPreview(PRINT_PREVIEW_SCRIPTED);
}
+#endif
}
bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) {
@@ -946,6 +964,7 @@ bool PrintWebViewHelper::GetPrintFrame(blink::WebLocalFrame** frame) {
#if defined(ENABLE_BASIC_PRINTING)
void PrintWebViewHelper::OnPrintPages() {
+ DLOG(INFO) << "DGN - OnPrintPages - Call from PrintManager";
blink::WebLocalFrame* frame;
if (GetPrintFrame(&frame))
Print(frame, blink::WebNode());
@@ -1244,8 +1263,12 @@ void PrintWebViewHelper::PrintNode(const blink::WebNode& node) {
void PrintWebViewHelper::Print(blink::WebLocalFrame* frame,
const blink::WebNode& node) {
// If still not finished with earlier print request simply ignore.
- if (prep_frame_view_)
+ DLOG(INFO) << "DGN Print";
+
+ if (prep_frame_view_) {
+ DLOG(INFO) << "DGN Print request ignored";
return;
+ }
FrameReference frame_ref(frame);
@@ -1255,6 +1278,8 @@ void PrintWebViewHelper::Print(blink::WebLocalFrame* frame,
return; // Failed to init print page settings.
}
+ DLOG(INFO) << "DGN CalculateNumberOfPages OK";
+
// Some full screen plugins can say they don't want to print.
if (!expected_page_count) {
DidFinishPrinting(FAIL_PRINT);
@@ -1268,6 +1293,8 @@ void PrintWebViewHelper::Print(blink::WebLocalFrame* frame,
return;
}
+ DLOG(INFO) << "DGN GetPrintSettingsFromUser OK";
+
// Render Pages for printing.
if (!RenderPagesForPrint(frame_ref.GetFrame(), node)) {
LOG(ERROR) << "RenderPagesForPrint failed";
@@ -1277,6 +1304,9 @@ void PrintWebViewHelper::Print(blink::WebLocalFrame* frame,
}
void PrintWebViewHelper::DidFinishPrinting(PrintingResult result) {
+ if (result == OK) DLOG(INFO) << "DGN DidFinishPrinting";
+ else DLOG(INFO) << "DGN DidFinishPrinting - Failure: " << result;
+
switch (result) {
case OK:
break;
@@ -1567,6 +1597,7 @@ bool PrintWebViewHelper::RenderPagesForPrint(blink::WebLocalFrame* frame,
const blink::WebNode& node) {
if (!frame || prep_frame_view_)
return false;
+
const PrintMsg_PrintPages_Params& params = *print_pages_params_;
const PrintMsg_Print_Params& print_params = params.params;
prep_frame_view_.reset(new PrepareFrameAndViewForPrint(

Powered by Google App Engine
This is Rietveld 408576698