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(
PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(
print_preview_dialog->GetWebUI()->GetController());
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->print_selection_only_ = params.selection_only;
}
......
......@@ -61,6 +61,8 @@ class PrintPreviewUI : public ConstrainedWebDialogUI {
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 print_selection_only() const { return print_selection_only_; }
......@@ -257,6 +259,9 @@ class PrintPreviewUI : public ConstrainedWebDialogUI {
// Indicates whether the source document can be modified.
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.
bool source_has_selection_ = false;
......
......@@ -135,10 +135,10 @@ PrintMsg_PrintFrame_Params::~PrintMsg_PrintFrame_Params() {}
PrintHostMsg_RequestPrintPreview_Params::
PrintHostMsg_RequestPrintPreview_Params()
: is_modifiable(false),
is_pdf(false),
webnode_only(false),
has_selection(false),
selection_only(false) {
}
selection_only(false) {}
PrintHostMsg_RequestPrintPreview_Params::
~PrintHostMsg_RequestPrintPreview_Params() {}
......
......@@ -90,6 +90,7 @@ struct PrintHostMsg_RequestPrintPreview_Params {
PrintHostMsg_RequestPrintPreview_Params();
~PrintHostMsg_RequestPrintPreview_Params();
bool is_modifiable;
bool is_pdf;
bool webnode_only;
bool has_selection;
bool selection_only;
......@@ -214,6 +215,7 @@ IPC_STRUCT_TRAITS_END()
#if BUILDFLAG(ENABLE_PRINT_PREVIEW)
IPC_STRUCT_TRAITS_BEGIN(PrintHostMsg_RequestPrintPreview_Params)
IPC_STRUCT_TRAITS_MEMBER(is_modifiable)
IPC_STRUCT_TRAITS_MEMBER(is_pdf)
IPC_STRUCT_TRAITS_MEMBER(webnode_only)
IPC_STRUCT_TRAITS_MEMBER(has_selection)
IPC_STRUCT_TRAITS_MEMBER(selection_only)
......
......@@ -57,6 +57,7 @@
#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_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_print_params.h"
#include "third_party/blink/public/web/web_print_preset_options.h"
......@@ -352,6 +353,17 @@ bool IsPrintingNodeOrPdfFrame(const blink::WebLocalFrame* frame,
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)
// Returns true if the current destination printer is PRINT_TO_PDF.
bool IsPrintToPdfRequested(const base::DictionaryValue& job_settings) {
......@@ -2176,9 +2188,11 @@ void PrintRenderFrameHelper::RequestPrintPreview(PrintPreviewRequestType type) {
if (!weak_this)
return;
const bool is_modifiable = print_preview_context_.IsModifiable();
const bool is_pdf = print_preview_context_.IsPdf();
const bool has_selection = print_preview_context_.HasSelection();
PrintHostMsg_RequestPrintPreview_Params params;
params.is_modifiable = is_modifiable;
params.is_pdf = is_pdf;
params.has_selection = has_selection;
switch (type) {
case PRINT_PREVIEW_SCRIPTED: {
......@@ -2301,6 +2315,7 @@ void PrintRenderFrameHelper::PrintPreviewContext::InitWithFrame(
source_frame_.Reset(web_frame);
source_node_.Reset();
CalculateIsModifiable();
CalculateIsPdf();
}
void PrintRenderFrameHelper::PrintPreviewContext::InitWithNode(
......@@ -2312,6 +2327,7 @@ void PrintRenderFrameHelper::PrintPreviewContext::InitWithNode(
source_frame_.Reset(web_node.GetDocument().GetFrame());
source_node_ = web_node;
CalculateIsModifiable();
CalculateIsPdf();
}
void PrintRenderFrameHelper::PrintPreviewContext::OnPrintPreview() {
......@@ -2435,6 +2451,11 @@ bool PrintRenderFrameHelper::PrintPreviewContext::IsModifiable() const {
return is_modifiable_;
}
bool PrintRenderFrameHelper::PrintPreviewContext::IsPdf() const {
DCHECK(state_ != UNINITIALIZED);
return is_pdf_;
}
bool PrintRenderFrameHelper::PrintPreviewContext::HasSelection() {
return IsModifiable() && source_frame()->HasSelection();
}
......@@ -2507,10 +2528,13 @@ void PrintRenderFrameHelper::PrintPreviewContext::ClearContext() {
}
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_);
}
void PrintRenderFrameHelper::PrintPreviewContext::CalculateIsPdf() {
is_pdf_ = IsPrintingPdf(source_frame(), source_node_);
}
void PrintRenderFrameHelper::SetPrintPagesParams(
const PrintMsg_PrintPages_Params& settings) {
print_pages_params_ = std::make_unique<PrintMsg_PrintPages_Params>(settings);
......
......@@ -436,6 +436,7 @@ class PrintRenderFrameHelper
int GetNextPageNumber();
bool IsRendering() const;
bool IsModifiable() const;
bool IsPdf() const;
bool HasSelection();
bool IsLastPageOfPrintReadyMetafile() const;
bool IsFinalPageRendered() const;
......@@ -474,6 +475,8 @@ class PrintRenderFrameHelper
void CalculateIsModifiable();
void CalculateIsPdf();
// Specifies what to render for print preview.
FrameReference source_frame_;
blink::WebNode source_node_;
......@@ -493,6 +496,10 @@ class PrintRenderFrameHelper
// True, if the document source is modifiable. e.g. HTML and not PDF.
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.
int print_ready_metafile_page_count_ = 0;
......
......@@ -2058,6 +2058,10 @@ bool PepperPluginInstanceImpl::GetPrintPresetOptionsFromDocument(
return true;
}
bool PepperPluginInstanceImpl::IsPdfPlugin() {
return LoadPdfInterface();
}
bool PepperPluginInstanceImpl::CanRotateView() {
if (!LoadPdfInterface() || module()->is_crashed())
return false;
......
......@@ -276,6 +276,7 @@ class CONTENT_EXPORT PepperPluginInstanceImpl
void PrintEnd();
bool GetPrintPresetOptionsFromDocument(
blink::WebPrintPresetOptions* preset_options);
bool IsPdfPlugin();
bool CanRotateView();
void RotateView(blink::WebPlugin::RotationType type);
......
......@@ -457,6 +457,14 @@ bool PepperWebPluginImpl::GetPrintPresetOptionsFromDocument(
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() {
// Re-entrancy may cause JS to try to execute script on the plugin before it
// is fully initialized. See: crbug.com/715747.
......
......@@ -73,6 +73,7 @@ class PepperWebPluginImpl : public blink::WebPlugin {
blink::WebURL LinkAtPosition(const blink::WebPoint& position) const override;
bool GetPrintPresetOptionsFromDocument(
blink::WebPrintPresetOptions* preset_options) override;
bool IsPdfPlugin() override;
bool StartFind(const blink::WebString& search_text,
bool case_sensitive,
int identifier) override;
......
......@@ -143,6 +143,8 @@ class WebPlugin {
virtual bool GetPrintPresetOptionsFromDocument(WebPrintPresetOptions*) {
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
// 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