Commit b9f59d7c authored by Daniel Hosseinian's avatar Daniel Hosseinian Committed by Commit Bot

Set flag in PrintPreviewUI if source is a PDF.

Currently, PrintPreviewUI knows only if a source is modifiable or not.
Both PDF and Flash sources are not modifiable and there is no way to
distinguish them in the print preview UI. Knowing this information will
allow changes to PDF printing while Flash is still supported on Chrome.

The Renderer process can determine if the source is a PDF if a PDF
interface can be loaded in the PepperPluginInstanceImpl class. The
information is then relayed to the Browser process through an
existing IPC message.

Bug: 989978
Change-Id: If04a82d77d330e53a7425fcc9fdda862371f8bae
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1788484Reviewed-by: default avatarRaymes Khoury <raymes@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Commit-Queue: Daniel Hosseinian <dhoss@chromium.org>
Cr-Commit-Position: refs/heads/master@{#695971}
parent 18058e87
...@@ -575,6 +575,7 @@ void PrintPreviewUI::SetInitialParams( ...@@ -575,6 +575,7 @@ void PrintPreviewUI::SetInitialParams(
PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(
print_preview_dialog->GetWebUI()->GetController()); print_preview_dialog->GetWebUI()->GetController());
print_preview_ui->source_is_modifiable_ = params.is_modifiable; print_preview_ui->source_is_modifiable_ = params.is_modifiable;
print_preview_ui->source_is_pdf_ = params.is_pdf;
print_preview_ui->source_has_selection_ = params.has_selection; print_preview_ui->source_has_selection_ = params.has_selection;
print_preview_ui->print_selection_only_ = params.selection_only; print_preview_ui->print_selection_only_ = params.selection_only;
} }
......
...@@ -61,6 +61,8 @@ class PrintPreviewUI : public ConstrainedWebDialogUI { ...@@ -61,6 +61,8 @@ class PrintPreviewUI : public ConstrainedWebDialogUI {
bool source_is_modifiable() const { return source_is_modifiable_; } bool source_is_modifiable() const { return source_is_modifiable_; }
bool source_is_pdf() const { return source_is_pdf_; }
bool source_has_selection() const { return source_has_selection_; } bool source_has_selection() const { return source_has_selection_; }
bool print_selection_only() const { return print_selection_only_; } bool print_selection_only() const { return print_selection_only_; }
...@@ -257,6 +259,9 @@ class PrintPreviewUI : public ConstrainedWebDialogUI { ...@@ -257,6 +259,9 @@ class PrintPreviewUI : public ConstrainedWebDialogUI {
// Indicates whether the source document can be modified. // Indicates whether the source document can be modified.
bool source_is_modifiable_ = true; bool source_is_modifiable_ = true;
// Indicates whether the source document is a PDF.
bool source_is_pdf_ = false;
// Indicates whether the source document has selection. // Indicates whether the source document has selection.
bool source_has_selection_ = false; bool source_has_selection_ = false;
......
...@@ -135,10 +135,10 @@ PrintMsg_PrintFrame_Params::~PrintMsg_PrintFrame_Params() {} ...@@ -135,10 +135,10 @@ PrintMsg_PrintFrame_Params::~PrintMsg_PrintFrame_Params() {}
PrintHostMsg_RequestPrintPreview_Params:: PrintHostMsg_RequestPrintPreview_Params::
PrintHostMsg_RequestPrintPreview_Params() PrintHostMsg_RequestPrintPreview_Params()
: is_modifiable(false), : is_modifiable(false),
is_pdf(false),
webnode_only(false), webnode_only(false),
has_selection(false), has_selection(false),
selection_only(false) { selection_only(false) {}
}
PrintHostMsg_RequestPrintPreview_Params:: PrintHostMsg_RequestPrintPreview_Params::
~PrintHostMsg_RequestPrintPreview_Params() {} ~PrintHostMsg_RequestPrintPreview_Params() {}
......
...@@ -90,6 +90,7 @@ struct PrintHostMsg_RequestPrintPreview_Params { ...@@ -90,6 +90,7 @@ struct PrintHostMsg_RequestPrintPreview_Params {
PrintHostMsg_RequestPrintPreview_Params(); PrintHostMsg_RequestPrintPreview_Params();
~PrintHostMsg_RequestPrintPreview_Params(); ~PrintHostMsg_RequestPrintPreview_Params();
bool is_modifiable; bool is_modifiable;
bool is_pdf;
bool webnode_only; bool webnode_only;
bool has_selection; bool has_selection;
bool selection_only; bool selection_only;
...@@ -214,6 +215,7 @@ IPC_STRUCT_TRAITS_END() ...@@ -214,6 +215,7 @@ IPC_STRUCT_TRAITS_END()
#if BUILDFLAG(ENABLE_PRINT_PREVIEW) #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
IPC_STRUCT_TRAITS_BEGIN(PrintHostMsg_RequestPrintPreview_Params) IPC_STRUCT_TRAITS_BEGIN(PrintHostMsg_RequestPrintPreview_Params)
IPC_STRUCT_TRAITS_MEMBER(is_modifiable) IPC_STRUCT_TRAITS_MEMBER(is_modifiable)
IPC_STRUCT_TRAITS_MEMBER(is_pdf)
IPC_STRUCT_TRAITS_MEMBER(webnode_only) IPC_STRUCT_TRAITS_MEMBER(webnode_only)
IPC_STRUCT_TRAITS_MEMBER(has_selection) IPC_STRUCT_TRAITS_MEMBER(has_selection)
IPC_STRUCT_TRAITS_MEMBER(selection_only) IPC_STRUCT_TRAITS_MEMBER(selection_only)
......
...@@ -57,6 +57,7 @@ ...@@ -57,6 +57,7 @@
#include "third_party/blink/public/web/web_local_frame_client.h" #include "third_party/blink/public/web/web_local_frame_client.h"
#include "third_party/blink/public/web/web_navigation_control.h" #include "third_party/blink/public/web/web_navigation_control.h"
#include "third_party/blink/public/web/web_plugin.h" #include "third_party/blink/public/web/web_plugin.h"
#include "third_party/blink/public/web/web_plugin_container.h"
#include "third_party/blink/public/web/web_plugin_document.h" #include "third_party/blink/public/web/web_plugin_document.h"
#include "third_party/blink/public/web/web_print_params.h" #include "third_party/blink/public/web/web_print_params.h"
#include "third_party/blink/public/web/web_print_preset_options.h" #include "third_party/blink/public/web/web_print_preset_options.h"
...@@ -352,6 +353,17 @@ bool IsPrintingNodeOrPdfFrame(const blink::WebLocalFrame* frame, ...@@ -352,6 +353,17 @@ bool IsPrintingNodeOrPdfFrame(const blink::WebLocalFrame* frame,
return plugin && plugin->SupportsPaginatedPrint(); return plugin && plugin->SupportsPaginatedPrint();
} }
bool IsPrintingPdf(blink::WebLocalFrame* frame, const blink::WebNode& node) {
blink::WebPlugin* plugin;
if (node.IsNull()) {
plugin = GetPlugin(frame);
} else {
blink::WebPluginContainer* plugin_container = node.PluginContainer();
plugin = plugin_container ? plugin_container->Plugin() : nullptr;
}
return plugin && plugin->IsPdfPlugin();
}
#if BUILDFLAG(ENABLE_PRINT_PREVIEW) #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
// Returns true if the current destination printer is PRINT_TO_PDF. // Returns true if the current destination printer is PRINT_TO_PDF.
bool IsPrintToPdfRequested(const base::DictionaryValue& job_settings) { bool IsPrintToPdfRequested(const base::DictionaryValue& job_settings) {
...@@ -2176,9 +2188,11 @@ void PrintRenderFrameHelper::RequestPrintPreview(PrintPreviewRequestType type) { ...@@ -2176,9 +2188,11 @@ void PrintRenderFrameHelper::RequestPrintPreview(PrintPreviewRequestType type) {
if (!weak_this) if (!weak_this)
return; return;
const bool is_modifiable = print_preview_context_.IsModifiable(); const bool is_modifiable = print_preview_context_.IsModifiable();
const bool is_pdf = print_preview_context_.IsPdf();
const bool has_selection = print_preview_context_.HasSelection(); const bool has_selection = print_preview_context_.HasSelection();
PrintHostMsg_RequestPrintPreview_Params params; PrintHostMsg_RequestPrintPreview_Params params;
params.is_modifiable = is_modifiable; params.is_modifiable = is_modifiable;
params.is_pdf = is_pdf;
params.has_selection = has_selection; params.has_selection = has_selection;
switch (type) { switch (type) {
case PRINT_PREVIEW_SCRIPTED: { case PRINT_PREVIEW_SCRIPTED: {
...@@ -2301,6 +2315,7 @@ void PrintRenderFrameHelper::PrintPreviewContext::InitWithFrame( ...@@ -2301,6 +2315,7 @@ void PrintRenderFrameHelper::PrintPreviewContext::InitWithFrame(
source_frame_.Reset(web_frame); source_frame_.Reset(web_frame);
source_node_.Reset(); source_node_.Reset();
CalculateIsModifiable(); CalculateIsModifiable();
CalculateIsPdf();
} }
void PrintRenderFrameHelper::PrintPreviewContext::InitWithNode( void PrintRenderFrameHelper::PrintPreviewContext::InitWithNode(
...@@ -2312,6 +2327,7 @@ void PrintRenderFrameHelper::PrintPreviewContext::InitWithNode( ...@@ -2312,6 +2327,7 @@ void PrintRenderFrameHelper::PrintPreviewContext::InitWithNode(
source_frame_.Reset(web_node.GetDocument().GetFrame()); source_frame_.Reset(web_node.GetDocument().GetFrame());
source_node_ = web_node; source_node_ = web_node;
CalculateIsModifiable(); CalculateIsModifiable();
CalculateIsPdf();
} }
void PrintRenderFrameHelper::PrintPreviewContext::OnPrintPreview() { void PrintRenderFrameHelper::PrintPreviewContext::OnPrintPreview() {
...@@ -2435,6 +2451,11 @@ bool PrintRenderFrameHelper::PrintPreviewContext::IsModifiable() const { ...@@ -2435,6 +2451,11 @@ bool PrintRenderFrameHelper::PrintPreviewContext::IsModifiable() const {
return is_modifiable_; return is_modifiable_;
} }
bool PrintRenderFrameHelper::PrintPreviewContext::IsPdf() const {
DCHECK(state_ != UNINITIALIZED);
return is_pdf_;
}
bool PrintRenderFrameHelper::PrintPreviewContext::HasSelection() { bool PrintRenderFrameHelper::PrintPreviewContext::HasSelection() {
return IsModifiable() && source_frame()->HasSelection(); return IsModifiable() && source_frame()->HasSelection();
} }
...@@ -2507,10 +2528,13 @@ void PrintRenderFrameHelper::PrintPreviewContext::ClearContext() { ...@@ -2507,10 +2528,13 @@ void PrintRenderFrameHelper::PrintPreviewContext::ClearContext() {
} }
void PrintRenderFrameHelper::PrintPreviewContext::CalculateIsModifiable() { void PrintRenderFrameHelper::PrintPreviewContext::CalculateIsModifiable() {
// The only kind of node we can print right now is a PDF node.
is_modifiable_ = !IsPrintingNodeOrPdfFrame(source_frame(), source_node_); is_modifiable_ = !IsPrintingNodeOrPdfFrame(source_frame(), source_node_);
} }
void PrintRenderFrameHelper::PrintPreviewContext::CalculateIsPdf() {
is_pdf_ = IsPrintingPdf(source_frame(), source_node_);
}
void PrintRenderFrameHelper::SetPrintPagesParams( void PrintRenderFrameHelper::SetPrintPagesParams(
const PrintMsg_PrintPages_Params& settings) { const PrintMsg_PrintPages_Params& settings) {
print_pages_params_ = std::make_unique<PrintMsg_PrintPages_Params>(settings); print_pages_params_ = std::make_unique<PrintMsg_PrintPages_Params>(settings);
......
...@@ -436,6 +436,7 @@ class PrintRenderFrameHelper ...@@ -436,6 +436,7 @@ class PrintRenderFrameHelper
int GetNextPageNumber(); int GetNextPageNumber();
bool IsRendering() const; bool IsRendering() const;
bool IsModifiable() const; bool IsModifiable() const;
bool IsPdf() const;
bool HasSelection(); bool HasSelection();
bool IsLastPageOfPrintReadyMetafile() const; bool IsLastPageOfPrintReadyMetafile() const;
bool IsFinalPageRendered() const; bool IsFinalPageRendered() const;
...@@ -474,6 +475,8 @@ class PrintRenderFrameHelper ...@@ -474,6 +475,8 @@ class PrintRenderFrameHelper
void CalculateIsModifiable(); void CalculateIsModifiable();
void CalculateIsPdf();
// Specifies what to render for print preview. // Specifies what to render for print preview.
FrameReference source_frame_; FrameReference source_frame_;
blink::WebNode source_node_; blink::WebNode source_node_;
...@@ -493,6 +496,10 @@ class PrintRenderFrameHelper ...@@ -493,6 +496,10 @@ class PrintRenderFrameHelper
// True, if the document source is modifiable. e.g. HTML and not PDF. // True, if the document source is modifiable. e.g. HTML and not PDF.
bool is_modifiable_ = true; bool is_modifiable_ = true;
// True, if the document source is a PDF. Used to distinguish from
// other plugins such as Flash.
bool is_pdf_ = false;
// Specifies the total number of pages in the print ready metafile. // Specifies the total number of pages in the print ready metafile.
int print_ready_metafile_page_count_ = 0; int print_ready_metafile_page_count_ = 0;
......
...@@ -2058,6 +2058,10 @@ bool PepperPluginInstanceImpl::GetPrintPresetOptionsFromDocument( ...@@ -2058,6 +2058,10 @@ bool PepperPluginInstanceImpl::GetPrintPresetOptionsFromDocument(
return true; return true;
} }
bool PepperPluginInstanceImpl::IsPdfPlugin() {
return LoadPdfInterface();
}
bool PepperPluginInstanceImpl::CanRotateView() { bool PepperPluginInstanceImpl::CanRotateView() {
if (!LoadPdfInterface() || module()->is_crashed()) if (!LoadPdfInterface() || module()->is_crashed())
return false; return false;
......
...@@ -276,6 +276,7 @@ class CONTENT_EXPORT PepperPluginInstanceImpl ...@@ -276,6 +276,7 @@ class CONTENT_EXPORT PepperPluginInstanceImpl
void PrintEnd(); void PrintEnd();
bool GetPrintPresetOptionsFromDocument( bool GetPrintPresetOptionsFromDocument(
blink::WebPrintPresetOptions* preset_options); blink::WebPrintPresetOptions* preset_options);
bool IsPdfPlugin();
bool CanRotateView(); bool CanRotateView();
void RotateView(blink::WebPlugin::RotationType type); void RotateView(blink::WebPlugin::RotationType type);
......
...@@ -457,6 +457,14 @@ bool PepperWebPluginImpl::GetPrintPresetOptionsFromDocument( ...@@ -457,6 +457,14 @@ bool PepperWebPluginImpl::GetPrintPresetOptionsFromDocument(
return instance_->GetPrintPresetOptionsFromDocument(preset_options); return instance_->GetPrintPresetOptionsFromDocument(preset_options);
} }
bool PepperWebPluginImpl::IsPdfPlugin() {
// Re-entrancy may cause JS to try to execute script on the plugin before it
// is fully initialized. See: crbug.com/715747.
if (!instance_)
return false;
return instance_->IsPdfPlugin();
}
bool PepperWebPluginImpl::CanRotateView() { bool PepperWebPluginImpl::CanRotateView() {
// Re-entrancy may cause JS to try to execute script on the plugin before it // Re-entrancy may cause JS to try to execute script on the plugin before it
// is fully initialized. See: crbug.com/715747. // is fully initialized. See: crbug.com/715747.
......
...@@ -73,6 +73,7 @@ class PepperWebPluginImpl : public blink::WebPlugin { ...@@ -73,6 +73,7 @@ class PepperWebPluginImpl : public blink::WebPlugin {
blink::WebURL LinkAtPosition(const blink::WebPoint& position) const override; blink::WebURL LinkAtPosition(const blink::WebPoint& position) const override;
bool GetPrintPresetOptionsFromDocument( bool GetPrintPresetOptionsFromDocument(
blink::WebPrintPresetOptions* preset_options) override; blink::WebPrintPresetOptions* preset_options) override;
bool IsPdfPlugin() override;
bool StartFind(const blink::WebString& search_text, bool StartFind(const blink::WebString& search_text,
bool case_sensitive, bool case_sensitive,
int identifier) override; int identifier) override;
......
...@@ -143,6 +143,8 @@ class WebPlugin { ...@@ -143,6 +143,8 @@ class WebPlugin {
virtual bool GetPrintPresetOptionsFromDocument(WebPrintPresetOptions*) { virtual bool GetPrintPresetOptionsFromDocument(WebPrintPresetOptions*) {
return false; return false;
} }
// Returns true if the plugin is a PDF plugin.
virtual bool IsPdfPlugin() { return false; }
// Sets up printing with the specified printParams. Returns the number of // Sets up printing with the specified printParams. Returns the number of
// pages to be printed at these settings. // pages to be printed at these settings.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment