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

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: rebase Created 7 years 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 c891b250fe4f7cf38a8663fabc339c1706bddefd..7ea4b71b124b6bad7afbbfdde87f25e50ae93928 100644
--- a/chrome/renderer/printing/print_web_view_helper.cc
+++ b/android_webview/renderer/print_web_view_helper.cc
@@ -1,11 +1,14 @@
-// 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"
+// TODO(sgurun) copied from chrome/renderer. Remove after crbug.com/322276
+
+#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 +19,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 +46,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 {
@@ -63,6 +65,8 @@ enum PrintPreviewHelperEvents {
const double kMinDpi = 1.0;
+#if 0
+// TODO(sgurun) android_webview hack
const char kPageLoadScriptFormat[] =
"document.open(); document.write(%s); document.close();";
@@ -76,6 +80,7 @@ void ExecuteScript(blink::WebFrame* frame,
std::string script = base::StringPrintf(script_format, json.c_str());
frame->executeScript(blink::WebString(UTF8ToUTF16(script)));
}
+#endif
int GetDPI(const PrintMsg_Print_Params* print_params) {
#if defined(OS_MACOSX)
@@ -365,13 +370,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 +417,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 +456,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.
@@ -720,6 +726,8 @@ PrintWebViewHelper::PrintWebViewHelper(content::RenderView* render_view)
is_loading_(false),
is_scripted_preview_delayed_(false),
weak_ptr_factory_(this) {
+ // TODO(sgurun) enable window.print() for webview crbug.com/322303
+ SetScriptedPrintBlocked(true);
}
PrintWebViewHelper::~PrintWebViewHelper() {}
@@ -756,11 +764,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;
@@ -1095,6 +1106,7 @@ bool PrintWebViewHelper::FinalizePrintReadyDocument() {
DCHECK_GT(buf_size, 0u);
PrintHostMsg_DidPreviewDocument_Params preview_params;
+ preview_params.reuse_existing_data = false;
preview_params.data_size = buf_size;
preview_params.document_cookie = print_pages_params_->params.document_cookie;
preview_params.expected_pages_count =
@@ -1197,12 +1209,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)) {
@@ -1241,6 +1256,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;
@@ -1379,9 +1395,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;
}
@@ -1437,6 +1456,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,
@@ -1448,6 +1469,7 @@ bool PrintWebViewHelper::UpdatePrintSettings(
l10n_util::GetStringUTF16(
IDS_PRINT_PREVIEW_INVALID_PRINTER_SETTINGS));
}
+#endif // !defined(OS_ANDROID)
}
return false;
}
@@ -1617,7 +1639,6 @@ void PrintWebViewHelper::IncrementScriptedPrintCount() {
last_cancelled_script_print_ = base::Time::Now();
}
-
void PrintWebViewHelper::ShowScriptedPrintPreview() {
if (is_scripted_preview_delayed_) {
is_scripted_preview_delayed_ = false;
« no previous file with comments | « android_webview/renderer/print_web_view_helper.h ('k') | android_webview/renderer/print_web_view_helper_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698