Skip to content
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

Add FXIOS-10667 Content blocklist support via Remote Settings #23342

Merged
merged 8 commits into from
Nov 25, 2024

Conversation

mattreaganmozilla
Copy link
Collaborator

📜 Tickets

Jira ticket
Github issue

💡 Description

Initial updates to support Remote Settings for content blocking lists in iOS client. Changes:

  • Removes our previous Shavar shell script and related code in bootstrap.sh
  • Fixes old Xcode project references to disconnect-* files
  • Updates older code that was loading the JSON data directly from bundle to instead route that through the Remote Settings APIs so we have more control over how that data is vended

This is still a work-in-progress and there are a few areas that will need to be updated further (I have not added or updated tests etc.).

Result

2024-11-22 15:52:23.738 💙 INFO [adblock] ContentBlocker - Compiling any lists not already in rule store...
2024-11-22 15:52:23.738 💙 INFO [adblock] ContentBlocker - Will compile list: disconnect-block-advertising
2024-11-22 15:52:23.745 💙 INFO [adblock] ContentBlocker - Will compile list: disconnect-block-analytics
2024-11-22 15:52:23.745 💙 INFO [adblock] ContentBlocker - Will compile list: disconnect-block-social
2024-11-22 15:52:23.745 💙 INFO [adblock] ContentBlocker - Will compile list: disconnect-block-cryptomining
2024-11-22 15:52:23.746 💙 INFO [adblock] ContentBlocker - Will compile list: disconnect-block-fingerprinting
2024-11-22 15:52:23.746 💙 INFO [adblock] ContentBlocker - Will compile list: disconnect-block-cookies-advertising
2024-11-22 15:52:23.746 💙 INFO [adblock] ContentBlocker - Will compile list: disconnect-block-cookies-analytics
2024-11-22 15:52:23.746 💙 INFO [adblock] ContentBlocker - Will compile list: disconnect-block-cookies-social
2024-11-22 15:52:24.147 💙 INFO [adblock] ContentBlocker - Compiled 8 of 8 lists checked. 0 errors.

📝 Checklist

You have to check all boxes before merging

  • Filled in the above information (tickets numbers and description of your work)
  • Updated the PR name to follow our PR naming guidelines
  • Wrote unit tests and/or ensured the tests suite is passing
  • When working on UI, I checked and implemented accessibility (minimum Dynamic Text and VoiceOver)
  • If needed, I updated documentation / comments for complex code and public methods
  • If needed, added a backport comment (example @Mergifyio backport release/v120)

@@ -46,6 +46,3 @@ cp -r .githooks/* .git/hooks/

# Make the hooks are executable
chmod +x .git/hooks/*

# Run and update content blocker
./content_blocker_update.sh
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @clarmso Just a quick heads up that we are removing this content blocker update script from the bootstrap.sh.

I'm not aware of any issues this should cause on Bitrise but wanted to make sure you were looped in. Thanks

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed that this script is also responsible for running the code that generates our MainFrameAtDocument*.js files. So I'm fixing this right now, should have an update pushed soon.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Update: the above issue should be fixed now.)

@mobiletest-ci-bot
Copy link

mobiletest-ci-bot commented Nov 25, 2024

Messages
📖 Project coverage: 32.69%
📖 Edited 6 files
📖 Created 1 files

Client.app: Coverage: 31.58

File Coverage
ContentBlocker.swift 2.68% ⚠️
TrackingProtectionPageStats.swift 53.19%
RemoteDataType.swift 49.28% ⚠️

Generated by 🚫 Danger Swift against 6ccd1bb

@mattreaganmozilla mattreaganmozilla added the Do Not Merge ⛔️ This issue is a work in progress and is not ready to land label Nov 25, 2024
@mattreaganmozilla
Copy link
Collaborator Author

I believe the way the script is removed currently will break the generation of our MainFrameAtDocument*.js files, adding Do Not Merge until a fix is pushed up for that. Taking a closer look.

@mattreaganmozilla mattreaganmozilla removed the Do Not Merge ⛔️ This issue is a work in progress and is not ready to land label Nov 25, 2024
Copy link
Collaborator

@issammani issammani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks @mattreaganmozilla. Thanks. I see some stuff we can improve in the future, but this a really good place to start.

Comment on lines +309 to +310
guard let data = try? lists.loadLocalSettingsFileAsJSON(fileName: list) else { continue }
guard let newHash = calculateHash(for: data) else { continue }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really something we can support right now, but once we figure out caching we can also get the file digest from RS for attachments.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes and I believe there is some overlap between the current caching and RS so we may be able to clean up and/or remove some of this later down the road.

}
}

/// Loads the local settings for the given data type record, returning the
/// decoded objects.
/// - Returns: settings decoded to their RemoteDataTypeRecord.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eventually I think we would want to converge to the desktop implementation where a record and attachment is a one to one mapping. So the API might look like record.get_attachment. But this also works.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way this was sort of grafted onto the RS code isn't great and it's a bit clunky, but it's just the initial step in cleaning up the previous shavar scripts. I'm happy to revisit/update anything here. We can definitely sync further on this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@issammani Once this lands, I can add a patch for you two to review the attachment portion where yes you can do some part in python however locally it should all work out in terms of record.getAttachment(...name)

Comment on lines +50 to +52
# Install Node.js dependencies and build user scripts
npm install
npm run build
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch. Not sure why npm was part of content_blocker_update.sh before 🤔

Comment on lines -18 to -20
cd BrowserKit
swift run || true
swift run
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I believe removal of this also means we can clean up some of the related code in BrowserKit (e.g. ContentBlockerGenerator)?

Copy link
Collaborator

@issammani issammani Nov 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I converted it to a much simpler python script. My initial plan was to use it as is and have docker multistage build ( like I did in this tmp repo ) to build a binary from swift and use it, but that overcomplicates the build process. We don't need that code anymore.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok thanks, I might create a follow-up task for that cleanup and just put up a quick separate PR to remove it.

@mattreaganmozilla mattreaganmozilla merged commit c527e91 into mozilla-mobile:main Nov 25, 2024
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants