0

[unseasoned-pdf] Dedicate a method for print preview doc loaded code

Move print preview specific document loaded code to dedicated method.
This is the last step before migrating DocumentLoadComplete() from
OutOfProcessInstance to PdfViewPluginBase, so the implmentation can be
used by PdfViewWebPlugin as well.

Bug: 1140629
Change-Id: I9cd1fce573bde5b415ec98176b5b2a3884d6d849
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2786215
Commit-Queue: Daniel Hosseinian <dhoss@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#866775}
This commit is contained in:
Daniel Hosseinian
2021-03-25 20:56:47 +00:00
committed by Chromium LUCI CQ
parent 7cc3ecae84
commit d44f024afd
6 changed files with 26 additions and 12 deletions

@ -1042,18 +1042,8 @@ void OutOfProcessInstance::DocumentLoadComplete() {
UserMetricsRecordAction("PDF.LoadSuccess");
RecordDocumentMetrics();
// Note: If we are in print preview mode the scroll location is retained
// across document loads so we don't want to scroll again and override it.
if (IsPrintPreview()) {
if (IsPreviewingPDF(print_preview_page_count_)) {
SendPrintPreviewLoadedNotification();
} else {
DCHECK_EQ(0, print_preview_loaded_page_count_);
print_preview_loaded_page_count_ = 1;
AppendBlankPrintPreviewPages();
}
OnGeometryChanged(0, 0);
}
if (IsPrintPreview())
OnPrintPreviewLoaded();
SendAttachments();
SendBookmarks();
@ -1467,6 +1457,19 @@ void OutOfProcessInstance::DidStopLoading() {
did_call_start_loading_ = false;
}
void OutOfProcessInstance::OnPrintPreviewLoaded() {
// Scroll location is retained across document loads in print preview mode, so
// there's no need to override the scroll position by scrolling again.
if (IsPreviewingPDF(print_preview_page_count_)) {
SendPrintPreviewLoadedNotification();
} else {
DCHECK_EQ(0, print_preview_loaded_page_count_);
print_preview_loaded_page_count_ = 1;
AppendBlankPrintPreviewPages();
}
OnGeometryChanged(0, 0);
}
void OutOfProcessInstance::SetContentRestrictions(int content_restrictions) {
pp::PDF::SetContentRestriction(this, content_restrictions);
}

@ -159,6 +159,7 @@ class OutOfProcessInstance : public PdfViewPluginBase,
void SetContentRestrictions(int content_restrictions) override;
void DidStartLoading() override;
void DidStopLoading() override;
void OnPrintPreviewLoaded() override;
void UserMetricsRecordAction(const std::string& action) override;
private:

@ -258,6 +258,9 @@ class PdfViewPluginBase : public PDFEngine::Client,
virtual void DidStartLoading() = 0;
virtual void DidStopLoading() = 0;
// Performs tasks necessary when the document is loaded in print preview mode.
virtual void OnPrintPreviewLoaded() = 0;
// Records metrics about the document metadata.
void RecordDocumentMetrics();

@ -119,6 +119,8 @@ class FakePdfViewPluginBase : public PdfViewPluginBase {
MOCK_METHOD(void, DidStopLoading, (), (override));
MOCK_METHOD(void, OnPrintPreviewLoaded, (), (override));
MOCK_METHOD(void, UserMetricsRecordAction, (const std::string&), (override));
base::Value sent_message_;

@ -454,6 +454,10 @@ void PdfViewWebPlugin::DidStopLoading() {
NOTIMPLEMENTED();
}
void PdfViewWebPlugin::OnPrintPreviewLoaded() {
NOTIMPLEMENTED();
}
void PdfViewWebPlugin::UserMetricsRecordAction(const std::string& action) {
base::RecordAction(base::UserMetricsAction(action.c_str()));
}

@ -132,6 +132,7 @@ class PdfViewWebPlugin final : public PdfViewPluginBase,
void SetContentRestrictions(int content_restrictions) override;
void DidStartLoading() override;
void DidStopLoading() override;
void OnPrintPreviewLoaded() override;
void UserMetricsRecordAction(const std::string& action) override;
private: