firefox-ios icon indicating copy to clipboard operation
firefox-ios copied to clipboard

Refactor FXIOS-9833 General favicon related improvements to SiteImageModel and related classes

Open ih-codes opened this issue 1 year ago • 0 comments

:scroll: Tickets

Jira ticket Github issue

:bulb: Description

Note to self: I have the merge destination currently set to my other favicon refactor branch so the changes can be more clearly reviewed. But merge in FXIOS-9667 fix first.


Apologies for the long PR. 🙈 Most of the changes are naming improvements. Half the changes are in the unit tests.

General refactoring for some things I noticed while finishing up the favicon rework:

  • Simplified SiteImageModel so it won't be possible to get empty cache key strings, empty resource URL strings, String and URL representation of the same data (siteURL, siteURLString), etc.
  • Generalized SiteImageModel so it has a single resource URL rather than separate hero and favicon URLs (it only has one type after all...) and a non-optional siteURL (doesn't make sense to have a SiteImageModel if no site)
  • Moved cache key generation to the SiteImageModel and vastly simplified the logic (seemed unnecessarily complicated). Made sure all code needing cache keys calls this method.
  • Updated "site" param naming to be "model" when passing around a SiteImageModel (site is misleading)
  • Methods prefixed with "getURL" or "getImage" that actually returned a SiteImageModel now return what they say they're returning (e.g. a URL, a UIImage, etc.)
  • Instead of passing around .absoluteString of several URLs, just pass around the URL to avoid redundant conversions
  • Updated some documentation that referred to old code
  • Remove optionals where there was no need to be optional
  • Add a guard so we don't try to cache empty faviconURLs from the Tab metadata update didSet after loading a webpage
  • Prefer modern concurrency to execute UI updates on the main thread instead of GCD (especially when inside a Task)
  • Removed unnecessary do/catch blocks, or moved them to be more contextual with what they were wrapping
  • Unit test updates. SiteImageHandlerTests no longer test the exact same things as ImageHandlerTests (hence deleted tests).
  • Added a few FIXMEs for discussion

:pencil: Checklist

You have to check all boxes before merging

  • [x] Filled in the above information (tickets numbers and description of your work)
  • [x] Updated the PR name to follow our PR naming guidelines
  • [x] 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)

ih-codes avatar Aug 23 '24 16:08 ih-codes