Skip to content

Commit

Permalink
Waiting for ContentBlockingRules to be applied before navigation (#402)
Browse files Browse the repository at this point in the history
* rm WebViewConfiguration typealias

* async decidePolicyForNavigationAction + wait for content rules

* Rules compilation monitor and reporting

* Inject UserScripts+ContentBlockingRules as a single ContentBlockingAssets

* PR review fixes

* fix tests

* fix proj

* ContentBlockingUpdatingTests and fixes

* cleanup

* cleanup

* fixing tests

* fixing tests

* Report no wait time on rules loading; Report contentBlockingCompilationTime

* fix tests

* still fixing tests

* and more

* linter, please

* please..

* the tests

* c‘mon!

* get rid of it

* what you say about no runloop waiting?

* figuring out what's wrong

* at last

* bump BSK

* UserScripts generated per-tab

* fix unexpected Pixel during tests

* compileRulesWait Pixel +waitTime argument

* fixing PR issues

* leaks prevention

* fix tests

* cleanup

* set BSK to v.10.0.0

* final adjustment
  • Loading branch information
mallexxx authored and jonathanKingston committed Feb 25, 2022
1 parent 7b0e60a commit 799c53e
Show file tree
Hide file tree
Showing 35 changed files with 1,117 additions and 316 deletions.
22 changes: 17 additions & 5 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,6 @@
AAECA42024EEA4AC00EFA63A /* IndexPathExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAECA41F24EEA4AC00EFA63A /* IndexPathExtension.swift */; };
AAEEC6A927088ADB008445F7 /* FireCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAEEC6A827088ADB008445F7 /* FireCoordinator.swift */; };
AAEF6BC8276A081C0024DCF4 /* FaviconSelector.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAEF6BC7276A081C0024DCF4 /* FaviconSelector.swift */; };
AAF7D3862567CED500998667 /* WebViewConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAF7D3852567CED500998667 /* WebViewConfiguration.swift */; };
AAFCB37F25E545D400859DD4 /* PublisherExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAFCB37E25E545D400859DD4 /* PublisherExtension.swift */; };
AAFE068326C7082D005434CC /* WebKitVersionProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAFE068226C7082D005434CC /* WebKitVersionProvider.swift */; };
B31055C427A1BA1D001AC618 /* AutoconsentUserScript.swift in Sources */ = {isa = PBXBuildFile; fileRef = B31055BC27A1BA1D001AC618 /* AutoconsentUserScript.swift */; };
Expand Down Expand Up @@ -482,6 +481,10 @@
B6106BB126A7D8720013B453 /* PermissionStoreTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6106BB026A7D8720013B453 /* PermissionStoreTests.swift */; };
B6106BB326A7F4AA0013B453 /* GeolocationServiceMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6106BB226A7F4AA0013B453 /* GeolocationServiceMock.swift */; };
B6106BB526A809E60013B453 /* GeolocationProviderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6106BB426A809E60013B453 /* GeolocationProviderTests.swift */; };
B610F2BB27A145C500FCEBE9 /* RulesCompilationMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = B610F2BA27A145C500FCEBE9 /* RulesCompilationMonitor.swift */; };
B610F2E427A8F37A00FCEBE9 /* CBRCompileTimeReporterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B610F2E327A8F37A00FCEBE9 /* CBRCompileTimeReporterTests.swift */; };
B610F2EB27AA8E4500FCEBE9 /* ContentBlockingUpdatingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B610F2E527AA388100FCEBE9 /* ContentBlockingUpdatingTests.swift */; };
B610F2EC27AA8F9400FCEBE9 /* ContentBlockerRulesManagerMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = B610F2E727AA397100FCEBE9 /* ContentBlockerRulesManagerMock.swift */; };
B61EF3EC266F91E700B4D78F /* WKWebView+Download.swift in Sources */ = {isa = PBXBuildFile; fileRef = B61EF3EB266F91E700B4D78F /* WKWebView+Download.swift */; };
B61EF3F1266F922200B4D78F /* WKProcessPool+DownloadDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B61EF3F0266F922200B4D78F /* WKProcessPool+DownloadDelegate.swift */; };
B61F015525EDD5A700ABB5A3 /* UserContentController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B61F015425EDD5A700ABB5A3 /* UserContentController.swift */; };
Expand Down Expand Up @@ -1155,7 +1158,6 @@
AAECA41F24EEA4AC00EFA63A /* IndexPathExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IndexPathExtension.swift; sourceTree = "<group>"; };
AAEEC6A827088ADB008445F7 /* FireCoordinator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FireCoordinator.swift; sourceTree = "<group>"; };
AAEF6BC7276A081C0024DCF4 /* FaviconSelector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FaviconSelector.swift; sourceTree = "<group>"; };
AAF7D3852567CED500998667 /* WebViewConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebViewConfiguration.swift; sourceTree = "<group>"; };
AAFCB37E25E545D400859DD4 /* PublisherExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PublisherExtension.swift; sourceTree = "<group>"; };
AAFE068226C7082D005434CC /* WebKitVersionProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebKitVersionProvider.swift; sourceTree = "<group>"; };
B31055BC27A1BA1D001AC618 /* AutoconsentUserScript.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = AutoconsentUserScript.swift; path = Autoconsent/AutoconsentUserScript.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1184,6 +1186,10 @@
B6106BB026A7D8720013B453 /* PermissionStoreTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PermissionStoreTests.swift; sourceTree = "<group>"; };
B6106BB226A7F4AA0013B453 /* GeolocationServiceMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeolocationServiceMock.swift; sourceTree = "<group>"; };
B6106BB426A809E60013B453 /* GeolocationProviderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeolocationProviderTests.swift; sourceTree = "<group>"; };
B610F2BA27A145C500FCEBE9 /* RulesCompilationMonitor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RulesCompilationMonitor.swift; sourceTree = "<group>"; };
B610F2E327A8F37A00FCEBE9 /* CBRCompileTimeReporterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CBRCompileTimeReporterTests.swift; sourceTree = "<group>"; };
B610F2E527AA388100FCEBE9 /* ContentBlockingUpdatingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentBlockingUpdatingTests.swift; sourceTree = "<group>"; };
B610F2E727AA397100FCEBE9 /* ContentBlockerRulesManagerMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentBlockerRulesManagerMock.swift; sourceTree = "<group>"; };
B61EF3EB266F91E700B4D78F /* WKWebView+Download.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WKWebView+Download.swift"; sourceTree = "<group>"; };
B61EF3F0266F922200B4D78F /* WKProcessPool+DownloadDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WKProcessPool+DownloadDelegate.swift"; sourceTree = "<group>"; };
B61F015425EDD5A700ABB5A3 /* UserContentController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserContentController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1809,6 +1815,8 @@
9833913227AAAEEE00DAF119 /* EmbeddedTrackerDataTests.swift */,
EA1E52B42798CF98002EC53C /* ClickToLoadModelTests.swift */,
EA8AE769279FBDB20078943E /* ClickToLoadTDSTests.swift */,
B610F2E527AA388100FCEBE9 /* ContentBlockingUpdatingTests.swift */,
B610F2E727AA397100FCEBE9 /* ContentBlockerRulesManagerMock.swift */,
);
path = ContentBlocker;
sourceTree = "<group>";
Expand Down Expand Up @@ -2746,7 +2754,6 @@
85E11C2E25E7DC7E00974CAF /* ExternalURLHandler.swift */,
AA9FF95824A1ECF20039E328 /* Tab.swift */,
85AC3AEE25D5CE9800C7D2AA /* UserScripts.swift */,
AAF7D3852567CED500998667 /* WebViewConfiguration.swift */,
B61F015425EDD5A700ABB5A3 /* UserContentController.swift */,
);
path = Model;
Expand Down Expand Up @@ -3471,6 +3478,7 @@
B6A9E47E26146A800067D1B9 /* PixelArguments.swift */,
B6A9E48326146AAB0067D1B9 /* PixelParameters.swift */,
B6A9E4A2261475C70067D1B9 /* AppUsageActivityMonitor.swift */,
B610F2BA27A145C500FCEBE9 /* RulesCompilationMonitor.swift */,
B6DA44012616B28300DD1EC2 /* PixelDataStore.swift */,
B68C92C32750EF76002AC6B0 /* PixelDataRecord.swift */,
B6DA44062616B30600DD1EC2 /* PixelDataModel.xcdatamodeld */,
Expand Down Expand Up @@ -3529,6 +3537,7 @@
B6DA44272616CAE000DD1EC2 /* AppUsageActivityMonitorTests.swift */,
B6DA441D2616C84600DD1EC2 /* PixelStoreMock.swift */,
4B117F7C276C0CB5002F3D8C /* LocalStatisticsStoreTests.swift */,
B610F2E327A8F37A00FCEBE9 /* CBRCompileTimeReporterTests.swift */,
);
path = Statistics;
sourceTree = "<group>";
Expand Down Expand Up @@ -3959,6 +3968,7 @@
1430DFF524D0580F00B8978C /* TabBarViewController.swift in Sources */,
4B92929B26670D2A00AD2C21 /* BookmarkOutlineViewDataSource.swift in Sources */,
85D885B026A590A90077C374 /* NSNotificationName+PasswordManager.swift in Sources */,
B610F2BB27A145C500FCEBE9 /* RulesCompilationMonitor.swift in Sources */,
AAC30A28268E045400D2D9CD /* CrashReportReader.swift in Sources */,
85AC3B3525DA82A600C7D2AA /* DataTaskProviding.swift in Sources */,
AAEF6BC8276A081C0024DCF4 /* FaviconSelector.swift in Sources */,
Expand Down Expand Up @@ -4328,7 +4338,6 @@
4B02198A25E05FAC00ED7DEA /* FireproofDomains.swift in Sources */,
4B677442255DBEEA00025BD8 /* Database.swift in Sources */,
4B92928B26670D1700AD2C21 /* BookmarksOutlineView.swift in Sources */,
AAF7D3862567CED500998667 /* WebViewConfiguration.swift in Sources */,
B61F015525EDD5A700ABB5A3 /* UserContentController.swift in Sources */,
4BF01C00272AE74C00884A61 /* CountryList.swift in Sources */,
AAC5E4D925D6A711007F5990 /* BookmarkStore.swift in Sources */,
Expand Down Expand Up @@ -4423,6 +4432,7 @@
AA63745424C9BF9A00AB2AC4 /* SuggestionContainerTests.swift in Sources */,
AAC9C01524CAFBCE00AD1325 /* TabTests.swift in Sources */,
B69B504C2726CA2900758A2B /* MockVariantManager.swift in Sources */,
B610F2EC27AA8F9400FCEBE9 /* ContentBlockerRulesManagerMock.swift in Sources */,
B6BBF1722744CE36004F850E /* FireproofDomainsStoreMock.swift in Sources */,
4BA1A6D9258C0CB300F6F690 /* DataEncryptionTests.swift in Sources */,
EA1E52B52798CF98002EC53C /* ClickToLoadModelTests.swift in Sources */,
Expand All @@ -4445,6 +4455,7 @@
4BB99D1126FE1A84001E4761 /* SafariBookmarksReaderTests.swift in Sources */,
4B11060A25903EAC0039B979 /* CoreDataEncryptionTests.swift in Sources */,
4B9292C32667103100AD2C21 /* PasteboardBookmarkTests.swift in Sources */,
B610F2E427A8F37A00FCEBE9 /* CBRCompileTimeReporterTests.swift in Sources */,
AAEC74BB2642E67C00C2EFBC /* NSPersistentContainerExtension.swift in Sources */,
AABAF59C260A7D130085060C /* FaviconManagerMock.swift in Sources */,
AAEC74B82642E43800C2EFBC /* HistoryStoreTests.swift in Sources */,
Expand All @@ -4454,6 +4465,7 @@
4B723E0526B0003E00E14D75 /* DataImportMocks.swift in Sources */,
85AC3B1725D9BC1A00C7D2AA /* ConfigurationDownloaderTests.swift in Sources */,
B693955D26F19CD70015B914 /* DownloadListStoreTests.swift in Sources */,
B610F2EB27AA8E4500FCEBE9 /* ContentBlockingUpdatingTests.swift in Sources */,
4B0511E7262CAB3700F6079C /* UserDefaultsWrapperUtilities.swift in Sources */,
4BA1A6F6258C4F9600F6F690 /* EncryptionMocks.swift in Sources */,
B6B3E0962654DACD0040E0A2 /* UTTypeTests.swift in Sources */,
Expand Down Expand Up @@ -5407,7 +5419,7 @@
repositoryURL = "https://github.com/duckduckgo/BrowserServicesKit";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 9.0.0;
minimumVersion = 10.0.0;
};
};
AA06B6B52672AF8100F541C5 /* XCRemoteSwiftPackageReference "Sparkle" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"repositoryURL": "https://github.com/duckduckgo/BrowserServicesKit",
"state": {
"branch": null,
"revision": "a263b2f9557ecfb6b09c5daac9cebd65ddfec6a4",
"version": "9.0.0"
"revision": "b00ea4f240613766e303ccdcf7c5fed15f60ddd1",
"version": "10.0.0"
}
},
{
Expand Down
7 changes: 3 additions & 4 deletions DuckDuckGo/Autoconsent/AutoconsentUserScript.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ final class AutoconsentUserScript: NSObject, UserScriptWithAutoconsent {
var webview: WKWebView?
weak var delegate: AutoconsentUserScriptDelegate?

init(scriptSource: ScriptSourceProviding = DefaultScriptSourceProvider.shared,
config: PrivacyConfiguration = ContentBlocking.privacyConfigurationManager.privacyConfig) {
init(scriptSource: ScriptSourceProviding, config: PrivacyConfiguration) {
source = Self.loadJS("autoconsent-bundle", from: .main, withReplacements: [:])
Self.globalTabCounter += 1
tabId = Self.globalTabCounter
Expand Down Expand Up @@ -84,7 +83,7 @@ final class AutoconsentUserScript: NSObject, UserScriptWithAutoconsent {
}

func onPageReady(url: URL) {
let preferences = PrivacySecurityPreferences()
let preferences = PrivacySecurityPreferences.shared

guard preferences.autoconsentEnabled != false else {
os_log("autoconsent is disabled", log: .autoconsent, type: .debug)
Expand Down Expand Up @@ -130,7 +129,7 @@ final class AutoconsentUserScript: NSObject, UserScriptWithAutoconsent {
}

func checkUserWasPrompted(callback: @escaping (Bool) -> Void) {
var preferences = PrivacySecurityPreferences()
let preferences = PrivacySecurityPreferences.shared
guard preferences.autoconsentEnabled == nil else {
callback(true)
return
Expand Down
Loading

0 comments on commit 799c53e

Please sign in to comment.