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..030ed088d990a5cdbcde3e9ddc18d129f27f6675 100644 |
--- a/chrome/renderer/print_web_view_helper.cc |
+++ b/chrome/renderer/print_web_view_helper.cc |
@@ -18,6 +18,7 @@ |
#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 +26,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 +54,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 +171,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 +191,22 @@ bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) { |
return handled; |
} |
+void PrintWebViewHelper::OnPrintSetupWhitelist(std::string host) { |
+ WebKit::WebSecurityPolicy::addOriginAccessWhitelistEntry( |
Lei Zhang
2011/06/09 21:23:30
I'm not a web security expert. Is this ok to do?
Albert Bodenhamer
2011/06/10 01:29:36
I'm still trying to figure out the best person to
|
+ GURL("chrome://print"), |
Lei Zhang
2011/06/09 21:23:30
chrome://print -> chrome::kChromeUIPrintHost
|
+ WebKit::WebString::fromUTF8("HTTPS"), |
Lei Zhang
2011/06/09 21:23:30
HTTPS -> chrome::kHttpsScheme
|
+ WebKit::WebString::fromUTF8(host), |
+ true); |
+} |
+ |
+void PrintWebViewHelper::OnPrintTeardownWhitelist(std::string host) { |
+ WebKit::WebSecurityPolicy::removeOriginAccessWhitelistEntry( |
+ GURL("chrome://print"), |
+ WebKit::WebString::fromUTF8("HTTPS"), |
+ WebKit::WebString::fromUTF8(host), |
+ true); |
+} |
+ |
void PrintWebViewHelper::OnPrintForPrintPreview( |
const DictionaryValue& job_settings) { |
DCHECK(is_preview_); |
@@ -209,7 +234,6 @@ void PrintWebViewHelper::OnPrintForPrintPreview( |
NOTREACHED() << "Failed to initialize print page settings"; |
return; |
} |
- |
if (!UpdatePrintSettings(job_settings)) { |
DidFinishPrinting(FAIL_PRINT); |
return; |
@@ -589,7 +613,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 +626,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, |