Branding the Chrome Schema - RebelBrowser/rebel GitHub Wiki
Native pages in Chromium are served under the chrome:// schema. This is quite a user-facing feature, as the user will see it any time they visit e.g. the settings page, hover over a settings link, etc.
Use of this schema within the Chromium code base is too extensive to be replaced outright. Not only are there many places where the exact schema is relied upon, but it is hard-coded all over the place. Instead, a Rebel-branded schema is created as an alias to the chrome:// schema, controlled by the $rebel_browser_schema build argument.
To facilitate this, Rebel creates overrides the ChromeContentClient (on desktop and Android) and the ChromeWebClient (on iOS) with a RebelContentClient and RebelWebClient, respectively. These client setup $rebel_browser_schema as a standard, secure schema within the browser.
From there, most of the work is to perform a URL replacement to and from the chrome:// schema where needed. This is done with an extension of the URL formatter component. This component was chosen because the utilities to perform the conversions must be low-level enough to be used within //components itself, and be available on all platforms. Extending an existing component was preferable to creating a new component so that various deps do not need to be added to a bunch of BUILD.gn files where the component would be used; everywhere that the replacement is needed already depends on the URL formatter component.
To redirect navigations from the Rebel-branded schema to the chrome:// schema, single-line hooks were added to content::Navigate (on desktop and Android) and web::NavigationManager (on iOS). These hooks simple replace the Rebel-branded schema with chrome:// on the GURL being navigated to.
Unfortunately, to ensure the Rebel-branded schema is displayed to the user instead of chrome:// is a bit of a whack-a-mole scenario. For example, it needs to be separately handled in the location bar, tab hover cards, etc. The full list of locations where the reverse of the above hook was added (for all platforms) may be seen in the commit which implemented the hooks.