-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
initial FB Click to Load (WIP) #329
Conversation
@tomasstrba here is the WIP, as basis for our discussion |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lucas, nice!!! 👏 👏 👏 The biggest issues are in comments below. Architecture looks pretty good. There are also details like debug prints, etc but I expect you have them just for debugging.
replyHandler(nil, "Image not found") | ||
return | ||
} | ||
let base64String = try? Data(contentsOf: imgURL!).base64EncodedString() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My advice is to use Assets.xcassets and static variables since there are ~6 images. The advantage is lazy loading and having images in memory instead of reading them from disk every time.
Please see PrivacyIconViewModel.swift for an example
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW do you know of a way to convert an SVG represented as NSImage (or cgImage for that matter) to a Data or String representation? For PNG I can use NSImage.tiffRepresentation
, but not for SVG.
Does it really make sense to use Assets.xcassets since the app itself never uses these images but just passes b64 encoded representations to the user script?
Or if there's a way load the raw files from Assets? I've tried NSDataAsset(name: "blocked_facebook_logo")
but it just returns nil...?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry Lucas, I didn't know it is tricky to get raw data if NSImage is SVG. Feel free to use your original approach, but please use lazy loading of images with some sort of cache. It means, images shouldn't be loaded immediately after start if they aren't used and also shouldn't be loaded from disk every time they are used.
static func loadEmbeddedAsData() -> Data { | ||
let json = try? Data(contentsOf: embeddedUrl) | ||
return json! | ||
} | ||
|
||
static func loadFBConfig() -> Data { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, is this used somewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not yet, as mentioned in the intro I started doing the plumbing for loading the remote config, but shelved it for now since our config diverged from the extension version. We'll be revising these configs shortly at which point we'll use this.
) | ||
var data = "" | ||
do { | ||
data = try String(contentsOf: sdkUrl!) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of forced unwrapping that causes crash if sdkUrl is nil, we usually unwrap using guard let ...
. It is more stable and you can react to nil in more appropriate way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH we probably should crash if that file is missing? I don't see any way to recover & continue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the file is part of the bundle, then yeah crash makes sense. A slightly better practice is fatalError and appropriate error message.
There are some temporary hacks in TrackerRadarManager and ContentBlockerRulesManager to handle issues at startup, these will have to be resolved before merging There is some initial scaffolding to support loading of remote configuration but not yet enabled due to difference in config files for extension vs MacOS
c8f8c85
to
8272d5e
Compare
…-rule-lists' into la/fb-click-to-load
There is a long delay before the complete event fires, meaning we were not blocking anything for ~10 seconds upon startup
@ladamski Do you have any suggestions for how to test this? |
@bstandaert-ddg: Sure you can start with https://privacy-test-pages.glitch.me/privacy-protections/click-to-load/, comparing the behavior of this branch vs the current release build (from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ladamski, I compiled and tried this and it is such a cool feature! Can't wait to have this in the released app and tell all my friends :)
I only found one issue - "Custom Facebook Login" button opens two dialogs. I needed to click "Go back" twice to get rid of it.
Other than that it is perfect and I only have some comments related to code below, which are not important and not blockers.
|
||
static var fbTrackerDataSet: TrackerRadarKit.TrackerData = { | ||
let trackerData = (try? JSONDecoder().decode(TrackerData.self, from: fbTrackerDataFile)) ?? nil | ||
return trackerData! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to be sure. Are we using just a local json file to decode tracker data?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, right now there is no corresponding remote file. All of the CTL configs + TDS need to be refactored, which will come after this lands (these all diverged between extension / Youtube / Mac and need to be integrated again).
I addressed the issue with the duplicate window opening |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 👍 🥇
Tested again, works like a charm
@ladamski, I can't merge because BSK points to |
|
||
static var fbTrackerDataFile: Data = { | ||
let url = Bundle.main.url(forResource: "fb-tds", withExtension: "json")! | ||
return (try? Data(contentsOf: url)) ?? Data() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Important question: do we have test to ensure that this file compiles? For every embedded rule list we should have tests that check if everything is ok before the release - both parsing to TrackerData format and compilation itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've noticed that embedded rules compilation has not been done on BSK either, so I've added that on the click to load BSK branch - you can use that as a reference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bwaresiak not an explicit loading test but from my testing it does fail here if I specify an invalid FB TDS. It would blow up on a nil
value at #37, but I just made it a bit more explicit so it will do so with:
Test Case '-[Unit_Tests.AppStateChangePublisherTests testWhenAllTabsExceptOneClosedThenStateChangePublished]' started.
DuckDuckGo_Privacy_Browser/ContentBlockerRulesLists.swift:43: Fatal error: Failed to JSON decode FB-TDS
2022-01-24 20:55:46.322148-0800 DuckDuckGo[78928:4548503] DuckDuckGo_Privacy_Browser/ContentBlockerRulesLists.swift:43: Fatal error: Failed to JSON decode FB-TDS
And for compilation errors, I just added a test per your example, thank you!
* develop: Version 0.18.5 support privacy config for clickToLoad (#407) Automatically select available login (#405) initial FB Click to Load (WIP) (#329) onboarding updates (#398) Version 0.18.4 Configuration of Sparkle - Setting SUAllowsAutomaticUpdates to NO (#404) Hide downloads button if the popover is opened/closed manually (#397)
# By Alexey Martemyanov (20) and others # Via Tomas Strba (2) and others * develop: (63 commits) Tweaks of suggestions and autocomplete (#403) Bump privacy dashboard to latest version (#409) Point to the latest BrowserServicesKit branch. (#414) Move embedded TDS from BSK to platform repo (#412) Image of shield with dot replaced (#410) Expand Fireproofing to include Local Storage and IndexedDB (#408) Version 0.18.5 support privacy config for clickToLoad (#407) Automatically select available login (#405) initial FB Click to Load (WIP) (#329) onboarding updates (#398) Version 0.18.4 Configuration of Sparkle - Setting SUAllowsAutomaticUpdates to NO (#404) Hide downloads button if the popover is opened/closed manually (#397) Textfield of the homepage is empty and unfocused right after switching to the homepage (#400) Remove navigatorCredentials (#392) Remove GPC header if it exists when not needed (#366) Version 0.18.3 Fireproofing encrypted storage (#332) Fix Lock Screen UI issues (#399) ... # Conflicts: # DuckDuckGo.xcodeproj/project.pbxproj # DuckDuckGo/Crash Reports/Model/CrashReportSender.swift
There are some temporary hacks in TrackerRadarManager and ContentBlockerRulesManager to handle issues at startup, these will have to be resolved before merging
There is some initial scaffolding to support loading of remote configuration but not yet enabled due to difference in config files for extension vs MacOS
Task/Issue URL: https://app.asana.com/0/72649045549333/1201196366848275/f
Tech Design URL: https://app.asana.com/0/72649045549333/1201230845721463
CC:
Description:
Steps to test this PR:
Testing checklist:
Internal references:
Software Engineering Expectations
Technical Design Template
When ready for review, remember to post the PR in MM