summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-12 21:59:46 +0000
committerthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-12 21:59:46 +0000
commit69401287af172586685346e5dd6b7e22b923f224 (patch)
tree83f06741df13bcaa361c48d1091d39016a9074e1
parent54b0fa8b93d0d5d132502d91cee97f8f5cc74e6a (diff)
downloadchromium_src-69401287af172586685346e5dd6b7e22b923f224.zip
chromium_src-69401287af172586685346e5dd6b7e22b923f224.tar.gz
chromium_src-69401287af172586685346e5dd6b7e22b923f224.tar.bz2
Print Preview: Disable controls when printing an embedded PDF.
BUG=79524 TEST=Open a page with an embedded PDF, right click and print. Review URL: http://codereview.chromium.org/6969031 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85199 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/printing/print_preview_message_handler.cc2
-rw-r--r--chrome/browser/resources/print_preview.js12
-rw-r--r--chrome/browser/ui/webui/print_preview_ui.cc7
-rw-r--r--chrome/browser/ui/webui/print_preview_ui.h6
-rw-r--r--chrome/common/print_messages.h3
-rw-r--r--chrome/renderer/print_web_view_helper.cc12
-rw-r--r--chrome/renderer/print_web_view_helper.h4
-rw-r--r--chrome/renderer/print_web_view_helper_linux.cc3
-rw-r--r--chrome/renderer/print_web_view_helper_mac.mm1
-rw-r--r--chrome/renderer/print_web_view_helper_win.cc4
10 files changed, 39 insertions, 15 deletions
diff --git a/chrome/browser/printing/print_preview_message_handler.cc b/chrome/browser/printing/print_preview_message_handler.cc
index 089ee0e..94ea8cf 100644
--- a/chrome/browser/printing/print_preview_message_handler.cc
+++ b/chrome/browser/printing/print_preview_message_handler.cc
@@ -90,7 +90,7 @@ void PrintPreviewMessageHandler::OnPagesReadyForPreview(
print_preview_ui->OnPreviewDataIsAvailable(
params.expected_pages_count,
wrapper->print_view_manager()->RenderSourceName(),
- tab_contents()->contents_mime_type());
+ params.modifiable);
}
void PrintPreviewMessageHandler::OnPrintPreviewNodeUnderContextMenu() {
diff --git a/chrome/browser/resources/print_preview.js b/chrome/browser/resources/print_preview.js
index 5c2bb57..37e82eb 100644
--- a/chrome/browser/resources/print_preview.js
+++ b/chrome/browser/resources/print_preview.js
@@ -35,9 +35,8 @@ var isPreviewStillLoading = true;
// Currently selected printer capabilities.
var printerCapabilities;
-// Mime type of the initiator page. Used to disable some printing options
-// when the mime type is application/pdf.
-var previewDataMimeType = null;
+// Used to disable some printing options when the preview is not modifiable.
+var previewModifiable = false;
// Destination list special value constants.
const PRINT_TO_PDF = 'Print To PDF';
@@ -420,7 +419,7 @@ function onPDFLoad() {
$('dancing-dots').classList.add('invisible');
setControlsDisabled(false);
- if (previewDataMimeType == "application/pdf") {
+ if (!previewModifiable) {
$('landscape').disabled = true;
$('portrait').disabled = true;
}
@@ -435,10 +434,11 @@ function onPDFLoad() {
* Called from PrintPreviewUI::PreviewDataIsAvailable().
* @param {number} pageCount The expected total pages count.
* @param {string} jobTitle The print job title.
+ * @param {boolean} modifiable If the preview is modifiable.
*
*/
-function updatePrintPreview(pageCount, jobTitle, mimeType) {
- previewDataMimeType = mimeType;
+function updatePrintPreview(pageCount, jobTitle, modifiable) {
+ previewModifiable = modifiable;
if (totalPageCount == -1)
totalPageCount = pageCount;
diff --git a/chrome/browser/ui/webui/print_preview_ui.cc b/chrome/browser/ui/webui/print_preview_ui.cc
index e9afb22..5bbc8a4 100644
--- a/chrome/browser/ui/webui/print_preview_ui.cc
+++ b/chrome/browser/ui/webui/print_preview_ui.cc
@@ -37,9 +37,10 @@ void PrintPreviewUI::OnInitiatorTabClosed(
void PrintPreviewUI::OnPreviewDataIsAvailable(int expected_pages_count,
const string16& job_title,
- const std::string& mime_type) {
+ bool modifiable) {
FundamentalValue pages_count(expected_pages_count);
StringValue title(job_title);
- StringValue mime(mime_type);
- CallJavascriptFunction("updatePrintPreview", pages_count, title, mime);
+ FundamentalValue is_preview_modifiable(modifiable);
+ CallJavascriptFunction("updatePrintPreview", pages_count, title,
+ is_preview_modifiable);
}
diff --git a/chrome/browser/ui/webui/print_preview_ui.h b/chrome/browser/ui/webui/print_preview_ui.h
index 3e10cab..99a8878 100644
--- a/chrome/browser/ui/webui/print_preview_ui.h
+++ b/chrome/browser/ui/webui/print_preview_ui.h
@@ -6,6 +6,8 @@
#define CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_UI_H_
#pragma once
+#include <string>
+
#include "base/memory/ref_counted.h"
#include "content/browser/webui/web_ui.h"
@@ -21,9 +23,11 @@ class PrintPreviewUI : public WebUI {
// Notify the Web UI renderer that preview data is available.
// |expected_pages_count| specifies the total number of pages.
// |job_title| is the title of the page being previewed.
+ // |modifiable| indicates if the preview can be rerendered with different
+ // print settings.
void OnPreviewDataIsAvailable(int expected_pages_count,
const string16& job_title,
- const std::string& mime_type);
+ bool modifiable);
// Notify the Web UI that initiator tab is closed, so we can disable all
// the controls that need the initiator tab for generating the preview data.
diff --git a/chrome/common/print_messages.h b/chrome/common/print_messages.h
index d0c7c62..a9ba711 100644
--- a/chrome/common/print_messages.h
+++ b/chrome/common/print_messages.h
@@ -82,6 +82,9 @@ IPC_STRUCT_BEGIN(PrintHostMsg_DidPreviewDocument_Params)
// Store the expected pages count.
IPC_STRUCT_MEMBER(int, expected_pages_count)
+
+ // Whether the preview can be modified.
+ IPC_STRUCT_MEMBER(bool, modifiable)
IPC_STRUCT_END()
// Parameters to describe a rendered page.
diff --git a/chrome/renderer/print_web_view_helper.cc b/chrome/renderer/print_web_view_helper.cc
index 5602fd0..f07ef87 100644
--- a/chrome/renderer/print_web_view_helper.cc
+++ b/chrome/renderer/print_web_view_helper.cc
@@ -17,10 +17,12 @@
#include "printing/metafile.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"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
#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/WebSize.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
@@ -497,6 +499,16 @@ void PrintWebViewHelper::GetPageSizeAndMarginsInPoints(
ConvertPixelsToPointDouble(margin_left_in_pixels);
}
+bool PrintWebViewHelper::IsModifiable(WebKit::WebFrame* frame,
+ WebKit::WebNode* node) {
+ if (node)
+ return false;
+ std::string mime(frame->dataSource()->response().mimeType().utf8());
+ if (mime == "application/pdf")
+ return false;
+ return true;
+}
+
void PrintWebViewHelper::UpdatePrintableSizeInPrintParameters(
WebFrame* frame,
WebNode* node,
diff --git a/chrome/renderer/print_web_view_helper.h b/chrome/renderer/print_web_view_helper.h
index 4b1dd33..2a4f1ff 100644
--- a/chrome/renderer/print_web_view_helper.h
+++ b/chrome/renderer/print_web_view_helper.h
@@ -211,7 +211,7 @@ class PrintWebViewHelper : public RenderViewObserver ,
bool CopyMetafileDataToSharedMem(printing::Metafile* metafile,
base::SharedMemoryHandle* shared_mem_handle);
- static void GetPageSizeAndMarginsInPoints(
+ void GetPageSizeAndMarginsInPoints(
WebKit::WebFrame* frame,
int page_index,
const PrintMsg_Print_Params& default_params,
@@ -222,6 +222,8 @@ class PrintWebViewHelper : public RenderViewObserver ,
double* margin_bottom_in_points,
double* margin_left_in_points);
+ bool IsModifiable(WebKit::WebFrame* frame, WebKit::WebNode* node);
+
void UpdatePrintableSizeInPrintParameters(WebKit::WebFrame* frame,
WebKit::WebNode* node,
PrintMsg_Print_Params* params);
diff --git a/chrome/renderer/print_web_view_helper_linux.cc b/chrome/renderer/print_web_view_helper_linux.cc
index b64f32d..a538b9d 100644
--- a/chrome/renderer/print_web_view_helper_linux.cc
+++ b/chrome/renderer/print_web_view_helper_linux.cc
@@ -39,9 +39,10 @@ bool PrintWebViewHelper::CreatePreviewDocument(
DCHECK_GT(buf_size, 0u);
PrintHostMsg_DidPreviewDocument_Params preview_params;
+ preview_params.data_size = buf_size;
preview_params.document_cookie = params.params.document_cookie;
preview_params.expected_pages_count = page_count;
- preview_params.data_size = buf_size;
+ preview_params.modifiable = IsModifiable(frame, node);
if (!CopyMetafileDataToSharedMem(&metafile,
&(preview_params.metafile_data_handle))) {
diff --git a/chrome/renderer/print_web_view_helper_mac.mm b/chrome/renderer/print_web_view_helper_mac.mm
index af5e839..27e8487 100644
--- a/chrome/renderer/print_web_view_helper_mac.mm
+++ b/chrome/renderer/print_web_view_helper_mac.mm
@@ -92,6 +92,7 @@ bool PrintWebViewHelper::CreatePreviewDocument(
preview_params.data_size = metafile.GetDataSize();
preview_params.document_cookie = params.params.document_cookie;
preview_params.expected_pages_count = page_count;
+ preview_params.modifiable = IsModifiable(frame, node);
// Ask the browser to create the shared memory for us.
if (!CopyMetafileDataToSharedMem(&metafile,
diff --git a/chrome/renderer/print_web_view_helper_win.cc b/chrome/renderer/print_web_view_helper_win.cc
index f55f576..82dbdeb 100644
--- a/chrome/renderer/print_web_view_helper_win.cc
+++ b/chrome/renderer/print_web_view_helper_win.cc
@@ -162,10 +162,10 @@ bool PrintWebViewHelper::CreatePreviewDocument(
DCHECK_GT(buf_size, 128u);
PrintHostMsg_DidPreviewDocument_Params preview_params;
- preview_params.document_cookie = params.params.document_cookie;
preview_params.data_size = buf_size;
- preview_params.metafile_data_handle = NULL;
+ preview_params.document_cookie = params.params.document_cookie;
preview_params.expected_pages_count = page_count;
+ preview_params.modifiable = IsModifiable(frame, node);
if (!CopyMetafileDataToSharedMem(metafile.get(),
&(preview_params.metafile_data_handle))) {