Add privacy local data inventory
This commit is contained in:
@@ -6,6 +6,7 @@ pub use error::CoreError;
|
||||
pub use state::{
|
||||
BookmarkImportSummary, BrowserCore, BrowserSnapshot, ELYBOOKMARKS_FILE_EXTENSION,
|
||||
ELYBOOKMARKS_SCHEMA_VERSION, ELYSPACE_FILE_EXTENSION, ELYSPACE_SCHEMA_VERSION,
|
||||
ElyBookmarksPackage, ElySpacePackage, InitialBrowserConfig, InstalledPlugin, PluginAuditAction,
|
||||
PluginAuditEvent, SiteDataClearance, SpaceImportProfileMapping, TrashedSpace,
|
||||
ElyBookmarksPackage, ElySpacePackage, InitialBrowserConfig, InstalledPlugin,
|
||||
LocalDataInventory, PluginAuditAction, PluginAuditEvent, SiteDataClearance,
|
||||
SpaceImportProfileMapping, TrashedSpace,
|
||||
};
|
||||
|
||||
@@ -40,6 +40,7 @@ pub use bookmarks::{
|
||||
ElyBookmarksPackage,
|
||||
};
|
||||
pub use plugins::{InstalledPlugin, PluginAuditAction, PluginAuditEvent};
|
||||
pub use privacy::LocalDataInventory;
|
||||
pub use site_data::SiteDataClearance;
|
||||
pub use space_exports::{
|
||||
ELYSPACE_FILE_EXTENSION, ELYSPACE_SCHEMA_VERSION, ElySpacePackage, SpaceImportProfileMapping,
|
||||
@@ -97,6 +98,7 @@ pub struct BrowserSnapshot {
|
||||
pub download_entries: Vec<DownloadEntry>,
|
||||
pub history_entries: Vec<HistoryEntry>,
|
||||
pub active_profile_history_entry_count: usize,
|
||||
pub local_data_inventory: LocalDataInventory,
|
||||
pub tab_groups: Vec<TabGroup>,
|
||||
pub split_layouts: Vec<SplitLayout>,
|
||||
pub installed_plugins: Vec<InstalledPlugin>,
|
||||
@@ -385,6 +387,7 @@ impl BrowserCore {
|
||||
download_entries: self.visible_downloads(),
|
||||
history_entries: self.visible_history(),
|
||||
active_profile_history_entry_count: self.active_profile_history_count(),
|
||||
local_data_inventory: self.active_profile_local_data_inventory(),
|
||||
tab_groups: self.visible_tab_groups(),
|
||||
split_layouts: self.visible_split_layouts(),
|
||||
installed_plugins: self.installed_plugins.clone(),
|
||||
|
||||
@@ -2,6 +2,79 @@ use ely_domain::{DiagnosticsReportingPolicy, HistoryRecordingPolicy};
|
||||
|
||||
use super::BrowserCore;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
|
||||
pub struct LocalDataInventory {
|
||||
open_tabs: usize,
|
||||
archived_tabs: usize,
|
||||
bookmarks: usize,
|
||||
notes: usize,
|
||||
reading_list: usize,
|
||||
history_entries: usize,
|
||||
site_permissions: usize,
|
||||
site_permission_audit_events: usize,
|
||||
downloads: usize,
|
||||
}
|
||||
|
||||
impl LocalDataInventory {
|
||||
#[must_use]
|
||||
pub fn open_tabs(self) -> usize {
|
||||
self.open_tabs
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn archived_tabs(self) -> usize {
|
||||
self.archived_tabs
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn bookmarks(self) -> usize {
|
||||
self.bookmarks
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn notes(self) -> usize {
|
||||
self.notes
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn reading_list(self) -> usize {
|
||||
self.reading_list
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn history_entries(self) -> usize {
|
||||
self.history_entries
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn site_permissions(self) -> usize {
|
||||
self.site_permissions
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn site_permission_audit_events(self) -> usize {
|
||||
self.site_permission_audit_events
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn downloads(self) -> usize {
|
||||
self.downloads
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn total_items(self) -> usize {
|
||||
self.open_tabs
|
||||
+ self.archived_tabs
|
||||
+ self.bookmarks
|
||||
+ self.notes
|
||||
+ self.reading_list
|
||||
+ self.history_entries
|
||||
+ self.site_permissions
|
||||
+ self.site_permission_audit_events
|
||||
+ self.downloads
|
||||
}
|
||||
}
|
||||
|
||||
impl BrowserCore {
|
||||
pub fn set_history_recording_policy(&mut self, policy: HistoryRecordingPolicy) {
|
||||
self.history_recording_policy = policy;
|
||||
@@ -25,4 +98,49 @@ impl BrowserCore {
|
||||
pub fn diagnostics_reporting_policy(&self) -> DiagnosticsReportingPolicy {
|
||||
self.diagnostics_reporting_policy
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn active_profile_local_data_inventory(&self) -> LocalDataInventory {
|
||||
let profile_id = &self.active_profile_id;
|
||||
|
||||
LocalDataInventory {
|
||||
open_tabs: self.tabs.iter().filter(|tab| tab.profile_id() == profile_id).count(),
|
||||
archived_tabs: self
|
||||
.archived_tabs
|
||||
.iter()
|
||||
.filter(|archived| archived.tab().profile_id() == profile_id)
|
||||
.count(),
|
||||
bookmarks: self
|
||||
.bookmarks
|
||||
.iter()
|
||||
.filter(|entry| entry.profile_id() == profile_id)
|
||||
.count(),
|
||||
notes: self.notes.iter().filter(|entry| entry.profile_id() == profile_id).count(),
|
||||
reading_list: self
|
||||
.reading_list
|
||||
.iter()
|
||||
.filter(|entry| entry.profile_id() == profile_id)
|
||||
.count(),
|
||||
history_entries: self
|
||||
.history_entries
|
||||
.iter()
|
||||
.filter(|entry| entry.profile_id() == profile_id)
|
||||
.count(),
|
||||
site_permissions: self
|
||||
.site_permissions
|
||||
.iter()
|
||||
.filter(|entry| entry.profile_id() == profile_id)
|
||||
.count(),
|
||||
site_permission_audit_events: self
|
||||
.site_permission_audit_events
|
||||
.iter()
|
||||
.filter(|event| event.profile_id() == profile_id)
|
||||
.count(),
|
||||
downloads: self
|
||||
.download_entries
|
||||
.iter()
|
||||
.filter(|entry| entry.profile_id() == profile_id)
|
||||
.count(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
use std::error::Error;
|
||||
|
||||
use ely_browser_core::{BrowserCore, InitialBrowserConfig};
|
||||
use ely_domain::{ProfileKind, SiteOrigin, SitePermissionDecision, SitePermissionFeature, UrlText};
|
||||
|
||||
#[test]
|
||||
fn local_data_inventory_counts_active_profile_data() -> Result<(), Box<dyn Error>> {
|
||||
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
let default_profile_id = core.snapshot()?.active_profile_id;
|
||||
|
||||
core.open_tab(UrlText::parse("https://example.com/research")?);
|
||||
core.bookmark_active_tab()?;
|
||||
core.save_active_url_note("profile note")?;
|
||||
core.save_active_tab_to_reading_list()?;
|
||||
core.record_download_started(
|
||||
UrlText::parse("https://example.com/report.pdf")?,
|
||||
"report.pdf",
|
||||
Some(2048),
|
||||
)?;
|
||||
core.set_site_permission(
|
||||
SiteOrigin::parse("https://example.com")?,
|
||||
SitePermissionFeature::Camera,
|
||||
SitePermissionDecision::AllowAlways,
|
||||
)?;
|
||||
let archived_tab_id = core.open_tab(UrlText::parse("https://servo.org/")?);
|
||||
core.close_tab(&archived_tab_id)?;
|
||||
|
||||
let personal_profile_id = core.create_profile("Personal", 0xf54e00, ProfileKind::Standard)?;
|
||||
core.open_tab(UrlText::parse("https://personal.example/research")?);
|
||||
core.bookmark_active_tab()?;
|
||||
core.save_active_url_note("personal note")?;
|
||||
core.record_download_started(
|
||||
UrlText::parse("https://personal.example/report.pdf")?,
|
||||
"personal-report.pdf",
|
||||
Some(4096),
|
||||
)?;
|
||||
core.set_site_permission(
|
||||
SiteOrigin::parse("https://personal.example")?,
|
||||
SitePermissionFeature::Notifications,
|
||||
SitePermissionDecision::DenyAlways,
|
||||
)?;
|
||||
|
||||
core.select_profile(&default_profile_id)?;
|
||||
let inventory = core.snapshot()?.local_data_inventory;
|
||||
|
||||
assert_eq!(inventory.open_tabs(), 2);
|
||||
assert_eq!(inventory.archived_tabs(), 1);
|
||||
assert_eq!(inventory.bookmarks(), 1);
|
||||
assert_eq!(inventory.notes(), 1);
|
||||
assert_eq!(inventory.reading_list(), 1);
|
||||
assert_eq!(inventory.history_entries(), 2);
|
||||
assert_eq!(inventory.site_permissions(), 1);
|
||||
assert_eq!(inventory.site_permission_audit_events(), 1);
|
||||
assert_eq!(inventory.downloads(), 1);
|
||||
assert_eq!(inventory.total_items(), 11);
|
||||
|
||||
core.select_profile(&personal_profile_id)?;
|
||||
let personal_inventory = core.snapshot()?.local_data_inventory;
|
||||
|
||||
assert_eq!(personal_inventory.open_tabs(), 2);
|
||||
assert_eq!(personal_inventory.bookmarks(), 1);
|
||||
assert_eq!(personal_inventory.notes(), 1);
|
||||
assert_eq!(personal_inventory.history_entries(), 1);
|
||||
assert_eq!(personal_inventory.site_permissions(), 1);
|
||||
assert_eq!(personal_inventory.site_permission_audit_events(), 1);
|
||||
assert_eq!(personal_inventory.downloads(), 1);
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user