Documentation
¶
Overview ¶
Package filtering provides filter management and compilation for content blocking.
Package filtering provides content blocking services for WebViews.
Index ¶
- Variables
- func InitializeFiltersAsync(manager *FilterManager) error
- type CacheMetadata
- type CompiledFilters
- type ContentBlockingService
- func (s *ContentBlockingService) GetCosmeticInjector() *cosmetic.CosmeticInjector
- func (s *ContentBlockingService) GetFilterManager() *FilterManager
- func (s *ContentBlockingService) GetStats() map[string]interface{}
- func (s *ContentBlockingService) IsReady() bool
- func (s *ContentBlockingService) RegisterWebView(wv *pkgwebkit.WebView)
- func (s *ContentBlockingService) SetFiltersReady(networkJSON []byte)
- func (s *ContentBlockingService) UnregisterWebView(wv *pkgwebkit.WebView)
- type CosmeticInjector
- type DefaultFilterCompiler
- type DiffEngine
- type FileFilterStore
- func (fs *FileFilterStore) GetCacheInfo() (bool, time.Time, error)
- func (fs *FileFilterStore) GetLastCheckTime() time.Time
- func (fs *FileFilterStore) GetSourceVersion(url string) string
- func (fs *FileFilterStore) InvalidateCache() error
- func (fs *FileFilterStore) LoadCached() (*CompiledFilters, error)
- func (fs *FileFilterStore) SaveCache(filters *CompiledFilters) error
- func (fs *FileFilterStore) SetSourceVersion(url string, version string) error
- type FilterCompiler
- type FilterListInfo
- type FilterManager
- func (fm *FilterManager) GetCosmeticCleanupScript() string
- func (fm *FilterManager) GetCosmeticRulesForDomain(domain string) []string
- func (fm *FilterManager) GetCosmeticScript() string
- func (fm *FilterManager) GetCosmeticScriptForDomain(domain string) string
- func (fm *FilterManager) GetCosmeticUpdateScript(selectors []string) string
- func (fm *FilterManager) GetNetworkFilters() ([]byte, error)
- func (fm *FilterManager) InitAsync(ctx context.Context) error
- func (fm *FilterManager) SetFiltersReadyCallback(callback FilterReadyCallback)
- func (fm *FilterManager) UpdateCosmeticRules(domain string, selectors []string)
- type FilterReadyCallback
- type FilterStore
- type FilterUpdate
- type FilterUpdater
Constants ¶
This section is empty.
Variables ¶
var ( // ErrFiltersNotReady indicates that filters are not yet compiled/loaded ErrFiltersNotReady = errors.New("filters not ready") // ErrInvalidFilterFormat indicates malformed filter data ErrInvalidFilterFormat = errors.New("invalid filter format") // ErrCacheCorrupted indicates corrupted cache data ErrCacheCorrupted = errors.New("cache corrupted") // ErrNetworkError indicates network-related errors during filter download ErrNetworkError = errors.New("network error") )
Functions ¶
func InitializeFiltersAsync ¶
func InitializeFiltersAsync(manager *FilterManager) error
InitializeFiltersAsync initializes the filtering system asynchronously
Types ¶
type CacheMetadata ¶
type CacheMetadata struct {
Version int `json:"version"`
CreatedAt time.Time `json:"created_at"`
LastUsed time.Time `json:"last_used"`
DataHash string `json:"data_hash"`
FilterHashes []string `json:"filter_hashes"` // Hashes of source filter lists
SourceVersions map[string]string `json:"source_versions"` // URL -> filter list version
LastCheckTime time.Time `json:"last_check_time"` // Last version check time
}
CacheMetadata stores information about the cache
type CompiledFilters ¶
type CompiledFilters struct {
NetworkRules []converter.WebKitRule `json:"network_rules"`
CosmeticRules map[string][]string `json:"cosmetic_rules"`
GenericHiding []string `json:"generic_hiding"`
CompiledAt time.Time `json:"compiled_at"`
Version string `json:"version"`
// contains filtered or unexported fields
}
CompiledFilters represents the compiled filter data
func NewCompiledFilters ¶
func NewCompiledFilters() *CompiledFilters
NewCompiledFilters creates a new CompiledFilters instance
func (*CompiledFilters) GetRulesForDomain ¶
func (cf *CompiledFilters) GetRulesForDomain(domain string) []string
GetRulesForDomain returns cosmetic rules for a specific domain
func (*CompiledFilters) Merge ¶
func (cf *CompiledFilters) Merge(other *CompiledFilters)
Merge combines two CompiledFilters instances
func (*CompiledFilters) ToJSON ¶
func (cf *CompiledFilters) ToJSON() ([]byte, error)
ToJSON converts network rules to JSON format
type ContentBlockingService ¶ added in v0.15.0
type ContentBlockingService struct {
// contains filtered or unexported fields
}
ContentBlockingService manages content blocking for all WebViews. It ensures network filters and cosmetic rules are applied consistently across all WebViews in the application.
func NewContentBlockingService ¶ added in v0.15.0
func NewContentBlockingService(dataDir string, filterManager *FilterManager) (*ContentBlockingService, error)
NewContentBlockingService creates a new content blocking service.
func (*ContentBlockingService) GetCosmeticInjector ¶ added in v0.15.0
func (s *ContentBlockingService) GetCosmeticInjector() *cosmetic.CosmeticInjector
GetCosmeticInjector returns the cosmetic injector.
func (*ContentBlockingService) GetFilterManager ¶ added in v0.15.0
func (s *ContentBlockingService) GetFilterManager() *FilterManager
GetFilterManager returns the underlying filter manager.
func (*ContentBlockingService) GetStats ¶ added in v0.15.0
func (s *ContentBlockingService) GetStats() map[string]interface{}
GetStats returns statistics about the content blocking service.
func (*ContentBlockingService) IsReady ¶ added in v0.15.0
func (s *ContentBlockingService) IsReady() bool
IsReady returns whether filters have been loaded and are ready to apply.
func (*ContentBlockingService) RegisterWebView ¶ added in v0.15.0
func (s *ContentBlockingService) RegisterWebView(wv *pkgwebkit.WebView)
RegisterWebView registers a WebView for content blocking. If filters are already compiled, they will be applied immediately.
func (*ContentBlockingService) SetFiltersReady ¶ added in v0.15.0
func (s *ContentBlockingService) SetFiltersReady(networkJSON []byte)
SetFiltersReady is called when filters have been parsed and are ready to compile. It compiles filters asynchronously, then applies to all registered WebViews.
func (*ContentBlockingService) UnregisterWebView ¶ added in v0.15.0
func (s *ContentBlockingService) UnregisterWebView(wv *pkgwebkit.WebView)
UnregisterWebView removes a WebView from the registry.
type CosmeticInjector ¶
type CosmeticInjector interface {
InjectRules(rules map[string][]string) error
GetScriptForDomain(domain string) string
}
CosmeticInjector defines the interface for cosmetic filter injection
type DefaultFilterCompiler ¶
type DefaultFilterCompiler struct{}
DefaultFilterCompiler implements FilterCompiler using the converter package
func NewDefaultFilterCompiler ¶
func NewDefaultFilterCompiler() *DefaultFilterCompiler
NewDefaultFilterCompiler creates a new default filter compiler
func (*DefaultFilterCompiler) CompileFromData ¶
func (dfc *DefaultFilterCompiler) CompileFromData(data []byte) (*CompiledFilters, error)
CompileFromData compiles filters from raw data bytes
func (*DefaultFilterCompiler) CompileFromSources ¶
func (dfc *DefaultFilterCompiler) CompileFromSources(ctx context.Context, sources []string) (*CompiledFilters, error)
CompileFromSources downloads and compiles filters from multiple URLs
type DiffEngine ¶
type DiffEngine struct {
}
DiffEngine handles differential updates between filter lists
type FileFilterStore ¶
type FileFilterStore struct {
// contains filtered or unexported fields
}
FileFilterStore implements FilterStore using filesystem storage
func NewFileFilterStore ¶
func NewFileFilterStore() (*FileFilterStore, error)
NewFileFilterStore creates a new file-based filter store
func (*FileFilterStore) GetCacheInfo ¶
func (fs *FileFilterStore) GetCacheInfo() (bool, time.Time, error)
GetCacheInfo returns cache existence and modification time
func (*FileFilterStore) GetLastCheckTime ¶ added in v0.15.0
func (fs *FileFilterStore) GetLastCheckTime() time.Time
GetLastCheckTime returns when versions were last checked
func (*FileFilterStore) GetSourceVersion ¶ added in v0.15.0
func (fs *FileFilterStore) GetSourceVersion(url string) string
GetSourceVersion returns the stored version for a filter list URL
func (*FileFilterStore) InvalidateCache ¶
func (fs *FileFilterStore) InvalidateCache() error
InvalidateCache removes the cache file
func (*FileFilterStore) LoadCached ¶
func (fs *FileFilterStore) LoadCached() (*CompiledFilters, error)
LoadCached loads compiled filters from cache
func (*FileFilterStore) SaveCache ¶
func (fs *FileFilterStore) SaveCache(filters *CompiledFilters) error
SaveCache saves compiled filters to cache
func (*FileFilterStore) SetSourceVersion ¶ added in v0.15.0
func (fs *FileFilterStore) SetSourceVersion(url string, version string) error
SetSourceVersion stores the version for a filter list URL
type FilterCompiler ¶
type FilterCompiler interface {
CompileFromSources(ctx context.Context, sources []string) (*CompiledFilters, error)
CompileFromData(data []byte) (*CompiledFilters, error)
}
FilterCompiler defines the interface for filter compilation
type FilterListInfo ¶
type FilterListInfo struct {
URL string
LastModified time.Time
ETag string
ContentHash string
Size int64
}
FilterListInfo stores metadata about a filter list
type FilterManager ¶
type FilterManager struct {
// contains filtered or unexported fields
}
FilterManager manages filter loading, compilation, and updates
func NewFilterManager ¶
func NewFilterManager(store FilterStore, compiler FilterCompiler) *FilterManager
NewFilterManager creates a new filter manager
func SetupFilterSystem ¶
func SetupFilterSystem() (*FilterManager, error)
SetupFilterSystem creates and initializes the complete filtering system
func (*FilterManager) GetCosmeticCleanupScript ¶
func (fm *FilterManager) GetCosmeticCleanupScript() string
GetCosmeticCleanupScript returns JavaScript to cleanup cosmetic filtering
func (*FilterManager) GetCosmeticRulesForDomain ¶
func (fm *FilterManager) GetCosmeticRulesForDomain(domain string) []string
GetCosmeticRulesForDomain returns cosmetic rules for a specific domain
func (*FilterManager) GetCosmeticScript ¶
func (fm *FilterManager) GetCosmeticScript() string
GetCosmeticScript returns the cosmetic filtering script
func (*FilterManager) GetCosmeticScriptForDomain ¶
func (fm *FilterManager) GetCosmeticScriptForDomain(domain string) string
GetCosmeticScriptForDomain returns the cosmetic filtering script for a specific domain
func (*FilterManager) GetCosmeticUpdateScript ¶
func (fm *FilterManager) GetCosmeticUpdateScript(selectors []string) string
GetCosmeticUpdateScript returns JavaScript to update cosmetic rules dynamically
func (*FilterManager) GetNetworkFilters ¶
func (fm *FilterManager) GetNetworkFilters() ([]byte, error)
GetNetworkFilters returns the compiled network filters for WebKit
func (*FilterManager) InitAsync ¶
func (fm *FilterManager) InitAsync(ctx context.Context) error
InitAsync initializes filter loading in background
func (*FilterManager) SetFiltersReadyCallback ¶
func (fm *FilterManager) SetFiltersReadyCallback(callback FilterReadyCallback)
SetFiltersReadyCallback sets a callback to be called when filters are loaded/updated
func (*FilterManager) UpdateCosmeticRules ¶
func (fm *FilterManager) UpdateCosmeticRules(domain string, selectors []string)
UpdateCosmeticRules adds new cosmetic rules for a domain
type FilterReadyCallback ¶
type FilterReadyCallback func()
FilterReadyCallback is called when filters are loaded/updated
type FilterStore ¶
type FilterStore interface {
LoadCached() (*CompiledFilters, error)
SaveCache(filters *CompiledFilters) error
GetCacheInfo() (bool, time.Time, error)
GetSourceVersion(url string) string
SetSourceVersion(url string, version string) error
GetLastCheckTime() time.Time
}
FilterStore defines the interface for filter storage operations
type FilterUpdate ¶
type FilterUpdate struct {
ListID string
URL string
Previous []byte
Current []byte
Hash string
Version string // Version extracted from content or HTTP headers
Compiled *CompiledFilters
}
FilterUpdate represents an update to a filter list
type FilterUpdater ¶
type FilterUpdater struct {
// contains filtered or unexported fields
}
FilterUpdater manages differential filter list updates
func NewFilterUpdater ¶
func NewFilterUpdater(manager *FilterManager) *FilterUpdater
NewFilterUpdater creates a new filter updater
func (*FilterUpdater) CheckAndUpdate ¶
func (fu *FilterUpdater) CheckAndUpdate(ctx context.Context) error
CheckAndUpdate checks for filter list updates and applies them