1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_ENTERPRISE_DATA_CONTROLS_CONTENT_BROWSER_RULES_SERVICE_H_
#define COMPONENTS_ENTERPRISE_DATA_CONTROLS_CONTENT_BROWSER_RULES_SERVICE_H_
#include <vector>
#include "components/enterprise/data_controls/core/browser/rule.h"
#include "components/enterprise/data_controls/core/browser/verdict.h"
#include "components/keyed_service/core/keyed_service.h"
#include "components/prefs/pref_change_registrar.h"
#include "components/prefs/pref_service.h"
#include "content/public/browser/clipboard_types.h"
namespace data_controls {
// Abstract keyed service that provides an interface to check what restrictions
// should be applied from the DataControlsRules policy.
class RulesService : public KeyedService {
public:
~RulesService() override;
virtual Verdict GetPrintVerdict(const GURL& printed_page_url) const = 0;
// Returns a clipboard verdict to be applied to a paste action. A null browser
// context on `source` represents data coming from the OS clipboard.
// `destination` is always expected to have a valid browser context.
virtual Verdict GetPasteVerdict(
const content::ClipboardEndpoint& source,
const content::ClipboardEndpoint& destination,
const content::ClipboardMetadata& metadata) const = 0;
// Returns a clipboard verdict only based the source of the copy, without
// making any special destination assumptions. This is meant to trigger rules
// that only have "sources" conditions, and blocking/warning verdicts returned
// by this function should trigger a dialog.
virtual Verdict GetCopyRestrictedBySourceVerdict(
const GURL& source) const = 0;
// Returns a clipboard verdict with the provided source attributes, and with
// the "os_clipboard" destination. This is meant to trigger rules that make
// use of the "os_clipboard" destination attribute. Blocking verdicts returned
// by this function should replace the data put in the clipboard, and warning
// verdicts should trigger a dialog.
virtual Verdict GetCopyToOSClipboardVerdict(const GURL& source) const = 0;
// Returns true if rules indicate screenshots should be blocked. Only the
// "block" level is supported, a "warn" screenshot rule will not make this
// functions return true.
virtual bool BlockScreenshots(const GURL& url) const = 0;
protected:
explicit RulesService(PrefService* pref_service);
// Returns a `Verdict` corresponding to all triggered Data Control rules given
// the provided context.
Verdict GetVerdict(Rule::Restriction restriction,
const ActionContext& context) const;
private:
// Parse the "DataControlsRules" policy if the corresponding experiment is
// enabled, and populate `rules_`.
void OnDataControlsRulesUpdate();
// Watches changes to the "DataControlsRules" policy.
PrefChangeRegistrar pref_registrar_;
// List of rules created from the "DataControlsRules" policy.
std::vector<Rule> rules_;
};
} // namespace data_controls
#endif // COMPONENTS_ENTERPRISE_DATA_CONTROLS_CONTENT_BROWSER_RULES_SERVICE_H_
|