| Index: chrome/renderer/print_web_view_helper.cc
|
| diff --git a/chrome/renderer/print_web_view_helper.cc b/chrome/renderer/print_web_view_helper.cc
|
| index ef8e5d51472dfcaa29e60762b68c52e372cd88bc..341bfd8e5dc349cb7b4f7a136205a93da96caa24 100644
|
| --- a/chrome/renderer/print_web_view_helper.cc
|
| +++ b/chrome/renderer/print_web_view_helper.cc
|
| @@ -14,10 +14,12 @@
|
| #include "chrome/common/chrome_switches.h"
|
| #include "chrome/common/print_messages.h"
|
| #include "chrome/common/render_messages.h"
|
| +#include "chrome/common/url_constants.h"
|
| #include "chrome/renderer/prerender/prerender_helper.h"
|
| #include "content/renderer/render_view.h"
|
| #include "grit/generated_resources.h"
|
| #include "printing/metafile.h"
|
| +#include "printing/print_job_constants.h"
|
| #include "printing/units.h"
|
| #include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h"
|
| #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
|
| @@ -25,9 +27,11 @@
|
| #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
|
| #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
|
| #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h"
|
| -#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h"
|
| +#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
|
| #include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h"
|
| +#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
|
| #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h"
|
| +#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h"
|
| #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
|
| #include "ui/base/l10n/l10n_util.h"
|
|
|
| @@ -51,6 +55,8 @@ using WebKit::WebView;
|
|
|
| namespace {
|
|
|
| +const double kMinDpi = 1.0;
|
| +
|
| int GetDPI(const PrintMsg_Print_Params* print_params) {
|
| #if defined(OS_MACOSX)
|
| // On the Mac, the printable area is in points, don't do any scaling based
|
| @@ -166,14 +172,18 @@ void PrintWebViewHelper::PrintPage(WebKit::WebFrame* frame) {
|
| bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) {
|
| bool handled = true;
|
| IPC_BEGIN_MESSAGE_MAP(PrintWebViewHelper, message)
|
| + IPC_MESSAGE_HANDLER(PrintMsg_PrintSetupWhitelist,
|
| + OnPrintSetupWhitelist)
|
| + IPC_MESSAGE_HANDLER(PrintMsg_PrintTeardownWhitelist,
|
| + OnPrintTeardownWhitelist)
|
| + IPC_MESSAGE_HANDLER(PrintMsg_PrintForPrintPreview,
|
| + OnPrintForPrintPreview)
|
| IPC_MESSAGE_HANDLER(PrintMsg_PrintPages, OnPrintPages)
|
| IPC_MESSAGE_HANDLER(PrintMsg_InitiatePrintPreview,
|
| OnInitiatePrintPreview)
|
| IPC_MESSAGE_HANDLER(PrintMsg_PrintNodeUnderContextMenu,
|
| OnPrintNodeUnderContextMenu)
|
| IPC_MESSAGE_HANDLER(PrintMsg_PrintPreview, OnPrintPreview)
|
| - IPC_MESSAGE_HANDLER(PrintMsg_PrintForPrintPreview,
|
| - OnPrintForPrintPreview)
|
| IPC_MESSAGE_HANDLER(PrintMsg_PrintingDone, OnPrintingDone)
|
| IPC_MESSAGE_HANDLER(PrintMsg_ResetScriptedPrintCount,
|
| ResetScriptedPrintCount)
|
| @@ -182,6 +192,22 @@ bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) {
|
| return handled;
|
| }
|
|
|
| +void PrintWebViewHelper::OnPrintSetupWhitelist(std::string host) {
|
| + WebKit::WebSecurityPolicy::addOriginAccessWhitelistEntry(
|
| + GURL(chrome::kChromeUIPrintHost),
|
| + WebKit::WebString::fromUTF8(chrome::kHttpsScheme),
|
| + WebKit::WebString::fromUTF8(host),
|
| + true);
|
| +}
|
| +
|
| +void PrintWebViewHelper::OnPrintTeardownWhitelist(std::string host) {
|
| + WebKit::WebSecurityPolicy::removeOriginAccessWhitelistEntry(
|
| + GURL(chrome::kChromeUIPrintHost),
|
| + WebKit::WebString::fromUTF8(chrome::kHttpsScheme),
|
| + WebKit::WebString::fromUTF8(host),
|
| + true);
|
| +}
|
| +
|
| void PrintWebViewHelper::OnPrintForPrintPreview(
|
| const DictionaryValue& job_settings) {
|
| DCHECK(is_preview_);
|
| @@ -209,7 +235,6 @@ void PrintWebViewHelper::OnPrintForPrintPreview(
|
| NOTREACHED() << "Failed to initialize print page settings";
|
| return;
|
| }
|
| -
|
| if (!UpdatePrintSettings(job_settings)) {
|
| DidFinishPrinting(FAIL_PRINT);
|
| return;
|
| @@ -589,7 +614,7 @@ bool PrintWebViewHelper::InitPrintSettings(WebKit::WebFrame* frame,
|
| l10n_util::GetStringUTF16(IDS_DEFAULT_PRINTER_NOT_FOUND_WARNING));
|
| return false;
|
| }
|
| - if (!settings.params.dpi || !settings.params.document_cookie) {
|
| + if (settings.params.dpi < kMinDpi || settings.params.document_cookie == 0) {
|
| // Invalid print page settings.
|
| NOTREACHED();
|
| return false;
|
| @@ -602,15 +627,22 @@ bool PrintWebViewHelper::InitPrintSettings(WebKit::WebFrame* frame,
|
|
|
| bool PrintWebViewHelper::UpdatePrintSettings(
|
| const DictionaryValue& job_settings) {
|
| - PrintMsg_PrintPages_Params settings;
|
| - Send(new PrintHostMsg_UpdatePrintSettings(routing_id(),
|
| - print_pages_params_->params.document_cookie, job_settings, &settings));
|
| + bool print_to_cloud = job_settings.HasKey(printing::kSettingCloudPrintId);
|
| + if (print_to_cloud) {
|
| + // TODO(abodenha@chromium.org) Really update the settings for a cloud
|
| + // printer.
|
| + return true;
|
| + } else {
|
| + PrintMsg_PrintPages_Params settings;
|
| + Send(new PrintHostMsg_UpdatePrintSettings(routing_id(),
|
| + print_pages_params_->params.document_cookie, job_settings, &settings));
|
|
|
| - if (!settings.params.dpi)
|
| - return false;
|
| + if (settings.params.dpi < kMinDpi)
|
| + return false;
|
|
|
| - print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings));
|
| - return true;
|
| + print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings));
|
| + return true;
|
| + }
|
| }
|
|
|
| bool PrintWebViewHelper::GetPrintSettingsFromUser(WebKit::WebFrame* frame,
|
|
|