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

Unified Diff: android_webview/renderer/print_web_view_helper.cc

Issue 54963005: Upstream printing changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address code review Created 7 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: android_webview/renderer/print_web_view_helper.cc
diff --git a/chrome/renderer/printing/print_web_view_helper.cc b/android_webview/renderer/print_web_view_helper.cc
similarity index 98%
copy from chrome/renderer/printing/print_web_view_helper.cc
copy to android_webview/renderer/print_web_view_helper.cc
index 70faa91fb8f8297f6df471869676ae32e8c1ce9c..54b8e3c747f94ca75b3d2e328715e3ccf2861e61 100644
--- a/chrome/renderer/printing/print_web_view_helper.cc
+++ b/android_webview/renderer/print_web_view_helper.cc
@@ -1,11 +1,12 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/renderer/printing/print_web_view_helper.h"
+#include "android_webview/renderer/print_web_view_helper.h"
#include <string>
+#include "android_webview/common/print_messages.h"
#include "base/auto_reset.h"
#include "base/command_line.h"
#include "base/json/json_writer.h"
@@ -16,15 +17,9 @@
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
-#include "chrome/common/chrome_switches.h"
-#include "chrome/common/print_messages.h"
-#include "chrome/common/render_messages.h"
-#include "chrome/renderer/prerender/prerender_helper.h"
#include "content/public/renderer/render_thread.h"
#include "content/public/renderer/render_view.h"
#include "content/public/renderer/web_preferences.h"
-#include "grit/browser_resources.h"
-#include "grit/generated_resources.h"
#include "net/base/escape.h"
#include "printing/metafile.h"
#include "printing/metafile_impl.h"
@@ -49,6 +44,11 @@
#include "ui/base/resource/resource_bundle.h"
#include "webkit/common/webpreferences.h"
+// This code is copied from chrome/renderer/printing. Code is slightly
+// modified to run it with webview, and the modifications are marked
+// using OS_ANDROID.
+// TODO(sgurun): remove the code as part of componentization of printing.
+
namespace printing {
namespace {
@@ -365,13 +365,11 @@ PrintMsg_Print_Params CalculatePrintParamsForCss(
}
bool IsPrintPreviewEnabled() {
- return CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kRendererPrintPreview);
+ return false;
}
bool IsPrintThrottlingDisabled() {
- return CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kDisableScriptedPrintThrottling);
+ return true;
}
} // namespace
@@ -414,6 +412,8 @@ void PrintWebViewHelper::PrintHeaderAndFooter(
const PageSizeMargins& page_layout,
const base::DictionaryValue& header_footer_info,
const PrintMsg_Print_Params& params) {
+#if 0
+ // TODO(sgurun) android_webview hack
skia::VectorPlatformDeviceSkia* device =
static_cast<skia::VectorPlatformDeviceSkia*>(canvas->getTopDevice());
device->setDrawingArea(SkPDFDevice::kMargin_DrawingArea);
@@ -451,13 +451,14 @@ void PrintWebViewHelper::PrintHeaderAndFooter(
blink::WebPrintParams webkit_params(page_size);
webkit_params.printerDPI = GetDPI(&params);
- frame->printBegin(webkit_params);
+ frame->printBegin(webkit_params, WebKit::WebNode(), NULL);
frame->printPage(0, canvas);
frame->printEnd();
web_view->close();
device->setDrawingArea(SkPDFDevice::kContent_DrawingArea);
+#endif
}
// static - Not anonymous so that platform implementations can use it.
@@ -756,11 +757,14 @@ void PrintWebViewHelper::PrintPage(blink::WebFrame* frame,
bool user_initiated) {
DCHECK(frame);
+#if !defined(OS_ANDROID)
+ // TODO(sgurun) android_webview hack
// Allow Prerendering to cancel this print request if necessary.
if (prerender::PrerenderHelper::IsPrerendering(render_view())) {
Send(new ChromeViewHostMsg_CancelPrerenderForPrinting(routing_id()));
return;
}
+#endif // !defined(OS_ANDROID)
if (!IsScriptInitiatedPrintAllowed(frame, user_initiated))
return;
@@ -1198,12 +1202,15 @@ void PrintWebViewHelper::Print(blink::WebFrame* frame,
return;
}
+#if !defined(OS_ANDROID)
+ // TODO(sgurun) android_webview hack
// Ask the browser to show UI to retrieve the final print settings.
if (!GetPrintSettingsFromUser(frame_ref.GetFrame(), node,
expected_page_count)) {
DidFinishPrinting(OK); // Release resources and fail silently.
return;
}
+#endif // !defined(OS_ANDROID)
// Render Pages for printing.
if (!RenderPagesForPrint(frame_ref.GetFrame(), node)) {
@@ -1242,6 +1249,7 @@ void PrintWebViewHelper::DidFinishPrinting(PrintingResult result) {
print_preview_context_.Failed(notify_browser_of_print_failure_);
break;
}
+
prep_frame_view_.reset();
print_pages_params_.reset();
notify_browser_of_print_failure_ = true;
@@ -1380,9 +1388,12 @@ bool PrintWebViewHelper::CalculateNumberOfPages(blink::WebFrame* frame,
bool fit_to_paper_size = !(PrintingNodeOrPdfFrame(frame, node));
if (!InitPrintSettings(fit_to_paper_size)) {
notify_browser_of_print_failure_ = false;
+#if !defined(OS_ANDROID)
+ // TODO(sgurun) android_webview hack
render_view()->RunModalAlertDialog(
frame,
l10n_util::GetStringUTF16(IDS_PRINT_PREVIEW_INVALID_PRINTER_SETTINGS));
+#endif // !defined(OS_ANDROID)
return false;
}
@@ -1438,6 +1449,8 @@ bool PrintWebViewHelper::UpdatePrintSettings(
if (!print_for_preview_) {
print_preview_context_.set_error(PREVIEW_ERROR_INVALID_PRINTER_SETTINGS);
} else {
+#if !defined(OS_ANDROID)
+ // TODO(sgurun) android_webview hack
// PrintForPrintPreview
blink::WebFrame* print_frame = NULL;
// This may not be the right frame, but the alert will be modal,
@@ -1449,6 +1462,7 @@ bool PrintWebViewHelper::UpdatePrintSettings(
l10n_util::GetStringUTF16(
IDS_PRINT_PREVIEW_INVALID_PRINTER_SETTINGS));
}
+#endif // !defined(OS_ANDROID)
}
return false;
}
@@ -1618,7 +1632,6 @@ void PrintWebViewHelper::IncrementScriptedPrintCount() {
last_cancelled_script_print_ = base::Time::Now();
}
-
void PrintWebViewHelper::ShowScriptedPrintPreview() {
if (is_scripted_preview_delayed_) {
is_scripted_preview_delayed_ = false;
@@ -1635,7 +1648,7 @@ void PrintWebViewHelper::RequestPrintPreview(PrintPreviewRequestType type) {
params.has_selection = has_selection;
switch (type) {
case PRINT_PREVIEW_SCRIPTED: {
- // Shows scripted print preview in two stages.
+ // Shows scripted print preview in two stages.
joth 2013/11/21 19:38:03 nit indent
sgurun-gerrit only 2013/11/23 01:49:11 Done.
// 1. PrintHostMsg_SetupScriptedPrintPreview blocks this call and JS by
// pumping messages here.
// 2. PrintHostMsg_ShowScriptedPrintPreview shows preview once the
@@ -1681,6 +1694,7 @@ void PrintWebViewHelper::RequestPrintPreview(PrintPreviewRequestType type) {
bool PrintWebViewHelper::CheckForCancel() {
const PrintMsg_Print_Params& print_params = print_pages_params_->params;
bool cancel = false;
+
joth 2013/11/21 19:38:03 nit - \n
sgurun-gerrit only 2013/11/23 01:49:11 Done.
Send(new PrintHostMsg_CheckForCancel(routing_id(),
print_params.preview_ui_id,
print_params.preview_request_id,

Powered by Google App Engine
This is Rietveld 408576698