[unseasoned-pdf] Provide common interface for content restrictions
Introduce a new enum, chrome_pdf::ContentRestriction, which maps to PP_ContentRestriction and transitively to ContentRestriction, as a Pepper-free enum for content restrictions that can be used in //pdf/. Provide a common interface for setting content restrictions. The OutOfProcessInstance implementation will call pp::PDF::SetContentRestriction, while the PdfViewWebPlugin will stay empty for now. Bug: 1140629 Change-Id: I0d49860f19066d7e9ae8a5999a43395e5b751ffe Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2785924 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Daniel Hosseinian <dhoss@chromium.org> Cr-Commit-Position: refs/heads/master@{#866764}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
eaea094b0b
commit
ce6028278c
@ -80,6 +80,7 @@ if (enable_pdf) {
|
||||
"accessibility.cc",
|
||||
"accessibility.h",
|
||||
"chunk_stream.h",
|
||||
"content_restriction.h",
|
||||
"document_attachment_info.cc",
|
||||
"document_attachment_info.h",
|
||||
"document_layout.cc",
|
||||
|
26
pdf/content_restriction.h
Normal file
26
pdf/content_restriction.h
Normal file
@ -0,0 +1,26 @@
|
||||
// Copyright 2021 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef PDF_CONTENT_RESTRICTION_H_
|
||||
#define PDF_CONTENT_RESTRICTION_H_
|
||||
|
||||
namespace chrome_pdf {
|
||||
|
||||
// Used for disabling browser commands because of restrictions on how the data
|
||||
// is to be used (i.e. can't copy/print).
|
||||
// TODO(crbug.com/702993): Must be kept in sync with `ContentRestriction` in
|
||||
// chrome/common/content_restriction.h. While there's a transitive static
|
||||
// assertion that the enums match, a direct static assertion should be added
|
||||
// when `PP_ContentRestriction` is removed.
|
||||
enum ContentRestriction {
|
||||
kContentRestrictionCopy = 1 << 0,
|
||||
kContentRestrictionCut = 1 << 1,
|
||||
kContentRestrictionPaste = 1 << 2,
|
||||
kContentRestrictionPrint = 1 << 3,
|
||||
kContentRestrictionSave = 1 << 4
|
||||
};
|
||||
|
||||
} // namespace chrome_pdf
|
||||
|
||||
#endif // PDF_CONTENT_RESTRICTION_H_
|
@ -29,6 +29,7 @@
|
||||
#include "net/base/escape.h"
|
||||
#include "pdf/accessibility.h"
|
||||
#include "pdf/accessibility_structs.h"
|
||||
#include "pdf/content_restriction.h"
|
||||
#include "pdf/document_attachment_info.h"
|
||||
#include "pdf/document_metadata.h"
|
||||
#include "pdf/pdfium/pdfium_engine.h"
|
||||
@ -1007,8 +1008,7 @@ std::unique_ptr<UrlLoader> OutOfProcessInstance::CreateUrlLoader() {
|
||||
// Disable save and print until the document is fully loaded, since they
|
||||
// would generate an incomplete document. Need to do this each time we
|
||||
// call DidStartLoading since that resets the content restrictions.
|
||||
pp::PDF::SetContentRestriction(
|
||||
this, PP_CONTENT_RESTRICTION_SAVE | PP_CONTENT_RESTRICTION_PRINT);
|
||||
SetContentRestrictions(kContentRestrictionSave | kContentRestrictionPrint);
|
||||
}
|
||||
|
||||
return CreateUrlLoaderInternal();
|
||||
@ -1074,17 +1074,16 @@ void OutOfProcessInstance::DocumentLoadComplete() {
|
||||
did_call_start_loading_ = false;
|
||||
}
|
||||
|
||||
int content_restrictions =
|
||||
PP_CONTENT_RESTRICTION_CUT | PP_CONTENT_RESTRICTION_PASTE;
|
||||
int content_restrictions = kContentRestrictionCut | kContentRestrictionPaste;
|
||||
if (!engine()->HasPermission(PDFEngine::PERMISSION_COPY))
|
||||
content_restrictions |= PP_CONTENT_RESTRICTION_COPY;
|
||||
content_restrictions |= kContentRestrictionCopy;
|
||||
|
||||
if (!engine()->HasPermission(PDFEngine::PERMISSION_PRINT_LOW_QUALITY) &&
|
||||
!engine()->HasPermission(PDFEngine::PERMISSION_PRINT_HIGH_QUALITY)) {
|
||||
content_restrictions |= PP_CONTENT_RESTRICTION_PRINT;
|
||||
content_restrictions |= kContentRestrictionPrint;
|
||||
}
|
||||
|
||||
pp::PDF::SetContentRestriction(this, content_restrictions);
|
||||
SetContentRestrictions(content_restrictions);
|
||||
}
|
||||
|
||||
void OutOfProcessInstance::RotateClockwise() {
|
||||
@ -1461,6 +1460,10 @@ void OutOfProcessInstance::LoadNextPreviewPage() {
|
||||
}
|
||||
}
|
||||
|
||||
void OutOfProcessInstance::SetContentRestrictions(int content_restrictions) {
|
||||
pp::PDF::SetContentRestriction(this, content_restrictions);
|
||||
}
|
||||
|
||||
void OutOfProcessInstance::UserMetricsRecordAction(const std::string& action) {
|
||||
// TODO(raymes): Move this function to PPB_UMA_Private.
|
||||
pp::PDF::UserMetricsRecordAction(this, pp::Var(action));
|
||||
|
@ -156,6 +156,7 @@ class OutOfProcessInstance : public PdfViewPluginBase,
|
||||
AccessibilityPageObjects page_objects) override;
|
||||
void SetAccessibilityViewportInfo(
|
||||
const AccessibilityViewportInfo& viewport_info) override;
|
||||
void SetContentRestrictions(int content_restrictions) override;
|
||||
void UserMetricsRecordAction(const std::string& action) override;
|
||||
|
||||
private:
|
||||
|
@ -247,6 +247,11 @@ class PdfViewPluginBase : public PDFEngine::Client,
|
||||
return size > 0 && size <= kMaximumSavedFileSize;
|
||||
}
|
||||
|
||||
// Disables browser commands because of restrictions on how the data is to be
|
||||
// used (i.e. can't copy/print). `content_restrictions` should have its bits
|
||||
// set by `chrome_pdf::ContentRestriction` enum values.
|
||||
virtual void SetContentRestrictions(int content_restrictions) = 0;
|
||||
|
||||
// Records metrics about the document metadata.
|
||||
void RecordDocumentMetrics();
|
||||
|
||||
|
@ -113,6 +113,8 @@ class FakePdfViewPluginBase : public PdfViewPluginBase {
|
||||
(const AccessibilityViewportInfo&),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(void, SetContentRestrictions, (int), (override));
|
||||
|
||||
MOCK_METHOD(void, UserMetricsRecordAction, (const std::string&), (override));
|
||||
|
||||
base::Value sent_message_;
|
||||
|
@ -442,6 +442,10 @@ void PdfViewWebPlugin::SetAccessibilityViewportInfo(
|
||||
NOTIMPLEMENTED();
|
||||
}
|
||||
|
||||
void PdfViewWebPlugin::SetContentRestrictions(int content_restrictions) {
|
||||
NOTIMPLEMENTED();
|
||||
}
|
||||
|
||||
void PdfViewWebPlugin::UserMetricsRecordAction(const std::string& action) {
|
||||
base::RecordAction(base::UserMetricsAction(action.c_str()));
|
||||
}
|
||||
|
@ -129,6 +129,7 @@ class PdfViewWebPlugin final : public PdfViewPluginBase,
|
||||
AccessibilityPageObjects page_objects) override;
|
||||
void SetAccessibilityViewportInfo(
|
||||
const AccessibilityViewportInfo& viewport_info) override;
|
||||
void SetContentRestrictions(int content_restrictions) override;
|
||||
void UserMetricsRecordAction(const std::string& action) override;
|
||||
|
||||
private:
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include "build/build_config.h"
|
||||
#include "pdf/accessibility_structs.h"
|
||||
#include "pdf/content_restriction.h"
|
||||
#include "pdf/document_metadata.h"
|
||||
#include "pdf/ppapi_migration/input_event_conversions.h"
|
||||
#include "ppapi/c/pp_input_event.h"
|
||||
@ -394,3 +395,14 @@ STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityScrollAlignment::kClosestToEdge,
|
||||
PP_PDF_SCROLL_ALIGNMENT_CLOSEST_EDGE);
|
||||
STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityScrollAlignment::kMaxValue,
|
||||
PP_PDF_ACCESSIBILITYSCROLLALIGNMENT_LAST);
|
||||
|
||||
STATIC_ASSERT_ENUM(chrome_pdf::kContentRestrictionCopy,
|
||||
PP_CONTENT_RESTRICTION_COPY);
|
||||
STATIC_ASSERT_ENUM(chrome_pdf::kContentRestrictionCut,
|
||||
PP_CONTENT_RESTRICTION_CUT);
|
||||
STATIC_ASSERT_ENUM(chrome_pdf::kContentRestrictionPaste,
|
||||
PP_CONTENT_RESTRICTION_PASTE);
|
||||
STATIC_ASSERT_ENUM(chrome_pdf::kContentRestrictionPrint,
|
||||
PP_CONTENT_RESTRICTION_PRINT);
|
||||
STATIC_ASSERT_ENUM(chrome_pdf::kContentRestrictionSave,
|
||||
PP_CONTENT_RESTRICTION_SAVE);
|
||||
|
Reference in New Issue
Block a user