Commit a47abfc8 authored by Sergey Poromov's avatar Sergey Poromov Committed by Commit Bot

DLP: Add printing restrictions.

Add Data Leak Prevention features that restricts printing of DLP sensitive content.

Bug: 1124651
Test: Browsertest added.
Change-Id: I0d653f3ea2518882f3cce8a96195247152fe45fb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2390651Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Reviewed-by: default avatarNikita Podguzov <nikitapodguzov@chromium.org>
Commit-Queue: Sergey Poromov <poromov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#810118}
parent 153162a1
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "chrome/browser/ui/ash/chrome_screenshot_grabber.h" #include "chrome/browser/ui/ash/chrome_screenshot_grabber.h"
#include "content/public/browser/visibility.h" #include "content/public/browser/visibility.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
#include "ui/gfx/skia_util.h" #include "ui/gfx/skia_util.h"
...@@ -98,6 +99,19 @@ bool DlpContentManager::IsScreenshotRestricted( ...@@ -98,6 +99,19 @@ bool DlpContentManager::IsScreenshotRestricted(
return false; return false;
} }
bool DlpContentManager::IsPrintingRestricted(
content::WebContents* web_contents) const {
// If we're viewing the PDF in a MimeHandlerViewGuest, use its embedder
// WebContents.
auto* guest_view =
extensions::MimeHandlerViewGuest::FromWebContents(web_contents);
web_contents =
guest_view ? guest_view->embedder_web_contents() : web_contents;
return GetConfidentialRestrictions(web_contents)
.HasRestriction(DlpContentRestriction::kPrint);
}
/* static */ /* static */
void DlpContentManager::SetDlpContentManagerForTesting( void DlpContentManager::SetDlpContentManagerForTesting(
DlpContentManager* dlp_content_manager) { DlpContentManager* dlp_content_manager) {
......
...@@ -41,6 +41,9 @@ class DlpContentManager { ...@@ -41,6 +41,9 @@ class DlpContentManager {
// Returns whether screenshots should be restricted. // Returns whether screenshots should be restricted.
virtual bool IsScreenshotRestricted(const ScreenshotArea& area) const; virtual bool IsScreenshotRestricted(const ScreenshotArea& area) const;
// Returns whether printing should be restricted.
bool IsPrintingRestricted(content::WebContents* web_contents) const;
// The caller (test) should manage |dlp_content_manager| lifetime. // The caller (test) should manage |dlp_content_manager| lifetime.
// Reset doesn't delete the object. // Reset doesn't delete the object.
static void SetDlpContentManagerForTesting( static void SetDlpContentManagerForTesting(
......
...@@ -22,6 +22,8 @@ const DlpContentRestrictionSet kScreenshotRestricted( ...@@ -22,6 +22,8 @@ const DlpContentRestrictionSet kScreenshotRestricted(
const DlpContentRestrictionSet kNonEmptyRestrictionSet = kScreenshotRestricted; const DlpContentRestrictionSet kNonEmptyRestrictionSet = kScreenshotRestricted;
const DlpContentRestrictionSet kPrivacyScreenEnforced( const DlpContentRestrictionSet kPrivacyScreenEnforced(
DlpContentRestriction::kPrivacyScreen); DlpContentRestriction::kPrivacyScreen);
const DlpContentRestrictionSet kPrintingRestricted(
DlpContentRestriction::kPrint);
class MockPrivacyScreenHelper : public ash::PrivacyScreenDlpHelper { class MockPrivacyScreenHelper : public ash::PrivacyScreenDlpHelper {
public: public:
...@@ -212,4 +214,20 @@ TEST_F(DlpContentManagerTest, PrivacyScreenEnforcement) { ...@@ -212,4 +214,20 @@ TEST_F(DlpContentManagerTest, PrivacyScreenEnforcement) {
task_environment_.FastForwardBy(GetPrivacyScreenOffDelay()); task_environment_.FastForwardBy(GetPrivacyScreenOffDelay());
} }
TEST_F(DlpContentManagerTest, PrintingRestricted) {
std::unique_ptr<content::WebContents> web_contents = CreateWebContents();
EXPECT_EQ(manager_.GetConfidentialRestrictions(web_contents.get()),
kEmptyRestrictionSet);
EXPECT_FALSE(manager_.IsPrintingRestricted(web_contents.get()));
ChangeConfidentiality(web_contents.get(), kPrintingRestricted);
EXPECT_EQ(manager_.GetConfidentialRestrictions(web_contents.get()),
kPrintingRestricted);
EXPECT_TRUE(manager_.IsPrintingRestricted(web_contents.get()));
DestroyWebContents(web_contents.get());
EXPECT_EQ(manager_.GetConfidentialRestrictions(web_contents.get()),
kEmptyRestrictionSet);
EXPECT_FALSE(manager_.IsPrintingRestricted(web_contents.get()));
}
} // namespace policy } // namespace policy
...@@ -17,6 +17,8 @@ enum DlpContentRestriction { ...@@ -17,6 +17,8 @@ enum DlpContentRestriction {
kScreenshot = 1 << 0, kScreenshot = 1 << 0,
// Enforce ePrivacy screen when content is visible. // Enforce ePrivacy screen when content is visible.
kPrivacyScreen = 1 << 1, kPrivacyScreen = 1 << 1,
// Do not allow printing.
kPrint = 1 << 2,
}; };
// Represents set of restrictions applied to on-screen content. // Represents set of restrictions applied to on-screen content.
......
...@@ -102,9 +102,14 @@ PrintPreviewUI* PrintPreviewMessageHandler::GetPrintPreviewUI( ...@@ -102,9 +102,14 @@ PrintPreviewUI* PrintPreviewMessageHandler::GetPrintPreviewUI(
void PrintPreviewMessageHandler::OnRequestPrintPreview( void PrintPreviewMessageHandler::OnRequestPrintPreview(
content::RenderFrameHost* render_frame_host, content::RenderFrameHost* render_frame_host,
const PrintHostMsg_RequestPrintPreview_Params& params) { const PrintHostMsg_RequestPrintPreview_Params& params) {
PrintViewManager* print_view_manager =
PrintViewManager::FromWebContents(web_contents());
if (print_view_manager->RejectPrintPreviewRequestIfRestricted(
render_frame_host)) {
return;
}
if (params.webnode_only) { if (params.webnode_only) {
PrintViewManager::FromWebContents(web_contents())->PrintPreviewForWebNode( print_view_manager->PrintPreviewForWebNode(render_frame_host);
render_frame_host);
} }
PrintPreviewDialogController::PrintPreview(web_contents()); PrintPreviewDialogController::PrintPreview(web_contents());
PrintPreviewUI::SetInitialParams(GetPrintPreviewDialog(), params); PrintPreviewUI::SetInitialParams(GetPrintPreviewDialog(), params);
......
...@@ -28,6 +28,10 @@ ...@@ -28,6 +28,10 @@
#include "mojo/public/cpp/bindings/associated_remote.h" #include "mojo/public/cpp/bindings/associated_remote.h"
#include "printing/buildflags/buildflags.h" #include "printing/buildflags/buildflags.h"
#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/policy/dlp/dlp_content_manager.h"
#endif
using content::BrowserThread; using content::BrowserThread;
namespace { namespace {
...@@ -177,6 +181,14 @@ void PrintViewManager::PrintPreviewDone() { ...@@ -177,6 +181,14 @@ void PrintViewManager::PrintPreviewDone() {
print_preview_rfh_ = nullptr; print_preview_rfh_ = nullptr;
} }
bool PrintViewManager::RejectPrintPreviewRequestIfRestricted(
content::RenderFrameHost* rfh) {
if (!IsPrintingRestricted())
return false;
GetPrintRenderFrame(rfh)->OnPrintPreviewDialogClosed();
return true;
}
void PrintViewManager::RenderFrameCreated( void PrintViewManager::RenderFrameCreated(
content::RenderFrameHost* render_frame_host) { content::RenderFrameHost* render_frame_host) {
if (PrintPreviewDialogController::IsPrintPreviewURL( if (PrintPreviewDialogController::IsPrintPreviewURL(
...@@ -207,6 +219,9 @@ bool PrintViewManager::PrintPreview( ...@@ -207,6 +219,9 @@ bool PrintViewManager::PrintPreview(
if (IsCrashed()) if (IsCrashed())
return false; return false;
if (IsPrintingRestricted())
return false;
GetPrintRenderFrame(rfh)->InitiatePrintPreview(std::move(print_renderer), GetPrintRenderFrame(rfh)->InitiatePrintPreview(std::move(print_renderer),
has_selection); has_selection);
...@@ -255,6 +270,9 @@ void PrintViewManager::OnSetupScriptedPrintPreview( ...@@ -255,6 +270,9 @@ void PrintViewManager::OnSetupScriptedPrintPreview(
return; return;
} }
if (RejectPrintPreviewRequestIfRestricted(rfh))
return;
DCHECK(!print_preview_rfh_); DCHECK(!print_preview_rfh_);
print_preview_rfh_ = rfh; print_preview_rfh_ = rfh;
print_preview_state_ = SCRIPTED_PREVIEW; print_preview_state_ = SCRIPTED_PREVIEW;
...@@ -270,6 +288,9 @@ void PrintViewManager::OnSetupScriptedPrintPreview( ...@@ -270,6 +288,9 @@ void PrintViewManager::OnSetupScriptedPrintPreview(
void PrintViewManager::OnShowScriptedPrintPreview(content::RenderFrameHost* rfh, void PrintViewManager::OnShowScriptedPrintPreview(content::RenderFrameHost* rfh,
bool source_is_modifiable) { bool source_is_modifiable) {
if (print_preview_state_ != SCRIPTED_PREVIEW)
return;
DCHECK(print_preview_rfh_); DCHECK(print_preview_rfh_);
if (rfh != print_preview_rfh_) if (rfh != print_preview_rfh_)
return; return;
...@@ -323,6 +344,15 @@ void PrintViewManager::MaybeUnblockScriptedPreviewRPH() { ...@@ -323,6 +344,15 @@ void PrintViewManager::MaybeUnblockScriptedPreviewRPH() {
} }
} }
bool PrintViewManager::IsPrintingRestricted() const {
#if defined(OS_CHROMEOS)
// Don't print DLP restricted content on Chrome OS.
return policy::DlpContentManager::Get()->IsPrintingRestricted(web_contents());
#else
return false;
#endif
}
WEB_CONTENTS_USER_DATA_KEY_IMPL(PrintViewManager) WEB_CONTENTS_USER_DATA_KEY_IMPL(PrintViewManager)
} // namespace printing } // namespace printing
...@@ -58,6 +58,10 @@ class PrintViewManager : public PrintViewManagerBase, ...@@ -58,6 +58,10 @@ class PrintViewManager : public PrintViewManagerBase,
// renderer in the case of scripted print preview if needed. // renderer in the case of scripted print preview if needed.
void PrintPreviewDone(); void PrintPreviewDone();
// Checks whether printing is currently restricted and aborts print preview if
// needed.
bool RejectPrintPreviewRequestIfRestricted(content::RenderFrameHost* rfh);
// mojom::PrintManagerHost: // mojom::PrintManagerHost:
void DidShowPrintDialog() override; void DidShowPrintDialog() override;
...@@ -102,6 +106,9 @@ class PrintViewManager : public PrintViewManagerBase, ...@@ -102,6 +106,9 @@ class PrintViewManager : public PrintViewManagerBase,
void MaybeUnblockScriptedPreviewRPH(); void MaybeUnblockScriptedPreviewRPH();
// Checks whether printing is restricted due to Data Leak Protection rules.
bool IsPrintingRestricted() const;
base::OnceClosure on_print_dialog_shown_callback_; base::OnceClosure on_print_dialog_shown_callback_;
// Current state of print preview for this view. // Current state of print preview for this view.
......
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