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

[wip] use CWVWebView embedder in iOS #24657

Draft
wants to merge 42 commits into
base: master
Choose a base branch
from
Draft

Conversation

kylehickinson
Copy link
Collaborator

@kylehickinson kylehickinson commented Jul 15, 2024

Do not merge, meant for gathering feedback on this solution's direction

Running list:

Needs Migration

  • session restoration data check/migration: SessionTab holds onto WKWebView.interactionState, need to drop it or ignore it while restoring CWVWebView and vice-versa.
  • Optional: Swap to Chromium safe browsing implementation
  • Optional: Use HTTPS Upgrade tab helpers

Broken Features

  • SSL certificate pinning (not supported by Chromium)
  • block javascript shield (not supported by Chromium)
  • link previews (not supported by Chromium)
  • sampled top page color KVO (private API)
  • multiple downloads at once (UI-only: progress doesn't show combined, downloads are parallel now)
  • redirected loads (getInternalRedirect, loading a new request before cancelling an active load) on pages that fail to load in the end hit DCHECK (e.g. http://api.segment.io will get upgraded to https but the link itself is blocked by PiHole/content blockers)

Cosmetic Issues

Product Changes

  • user agent contains CriOS
  • error pages now match desktop/android but lose Brave branding
  • block scripts shield may be removed
  • iPad uses mobile user agent by default, controlled by pref
  • Chromium doesnt support link previews

Accesses WebKit

These access -[CWVWebView(Extras) underlyingWebView] or -[CWVWebView(Extras) WKConfiguration] directly and should be migrated over if possible

  • content blockers access (WKWebViewConfiguration)
  • cookie store access (WKWebViewConfiguration)
  • deprecated javascript control preference (WKWebViewConfiguration)
  • Sampled page top color (WKWebView - private API)
  • PDF data in Leo (WKWebView - private API)
  • zoom level (WKWebView - private API). There is FontSizeTabHelper as a replacement but it's worse
  • playlist web loader (WKWebView - loadHTMLString), only exposed for testing in Chromium

Cleanup

  • remove user agent from BraveCoreMain initializer
  • fix unit tests
  • fixme's
  • optimize patches/overrides
  • layering violation fixes
  • gn check pass
  • presubmit pass
  • document what's accessible from CWVWebView

New Feature Support

  • Autofill Passwords
  • Autofill Credit Cards
  • Autofill Addresses

Security Checklist

TBD

@kylehickinson kylehickinson self-assigned this Jul 15, 2024
common_flags = [ "-fapplication-extension" ]
cflags_objc = common_flags
cflags_objcc = common_flags
defines = [ "CWV_IMPLEMENTATION" ]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This needs to be redefined for cwv_exports.h to properly export the symbols since we're copying public headers as-is

@kylehickinson kylehickinson added CI/skip Do not run CI builds (except noplatform) CI/skip-all-linters Do not run linters and presubmit checks labels Jul 15, 2024
@stoletheminerals stoletheminerals self-requested a review July 16, 2024 11:26
Comment on lines -1397 to -1418
if webView.fullscreenState == .inFullscreen || webView.fullscreenState == .enteringFullscreen {
webView.closeAllMediaPresentations {
self.present(alertController, animated: true)
}
return
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@kylehickinson kylehickinson force-pushed the ios-cwvwebview branch 5 times, most recently from 6ccffe6 to 66895b3 Compare July 23, 2024 17:08

- (CWVReuseCheckService*)reuseCheckService {
- if (!_reuseCheckService && self.persistent) {
- affiliations::AffiliationService* affiliation_service =
Copy link
Collaborator

Choose a reason for hiding this comment

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

this AffiliationService seems concerning in general, I asked @ShivanKaul and @pes10k about it because it looks like something we might want to just replace with a no-op implemenation

Copy link
Collaborator Author

@kylehickinson kylehickinson Jul 24, 2024

Choose a reason for hiding this comment

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

Right now I don't compile any of the actual affiliation services (I just dont include them in the //brave/ios/web_view target) which is why this implementation is patched out and would return nil always. We'd likely go the route of compiling //ios/web_view as is though before landing this and no-op them with chromium_src overrides

Copy link
Collaborator

Choose a reason for hiding this comment

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

it looks like this is something to do with credential sharing with apps, but we already disable it by disabling the fetch

Copy link
Collaborator

@bridiver bridiver Jul 24, 2024

Choose a reason for hiding this comment

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

What was the reason this was commented out?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Its commented out because we dont compile the necessary files for it atm (just //ios/web_view/internal/affiliations/web_view_affiliation_service_factory.h/mm at this point)

ApplicationContext::~ApplicationContext() = default;

PrefService* ApplicationContext::GetLocalState() {
return GetApplicationContext()->GetLocalState();
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks a layering violation because I don't think ios/web_view is supposed to access ios/chrome/browser, but I'm a bit confused about why it has a separate ApplicationContext

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Discussed in DM but will reiterate here anyways: ios/web_view basically has a whole "app" setup (custom ApplicationContext, custom WebClient, custom factories) because its completely independent from //ios/chrome. This isn't really helpful for us though because we already have the Chrome app setup in place, so we basically have to replace all of ios/web_views implementations with the Chrome ones. This may need better overrides to avoid layering violations though

]
}

source_set("web_view") {
Copy link
Collaborator

Choose a reason for hiding this comment

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

why are we adding these here instead of using web_view_sources, etc...?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It was originally to control what was compiled, the hope is to be able to eventually just use //ios/web_view:web_view_sources directly as more chromium_src overrides + patches are added


# This file exposes the //ios/web_view embedder as a regular source_set

ios_web_view_public_headers = [
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this different from ios_web_view_public_headers in ios/web_view/BUILD.gn? If so it would be better to use +=/-= instead of duplicating

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 parts under our own 1 extra public header aren't different but since the original list is defined in a GN file and not GNI I couldn't access them to add into our framework so for now it was duped. If its possible to get to let me know!

@kylehickinson kylehickinson force-pushed the ios-cwvwebview branch 2 times, most recently from 4be9903 to 0231609 Compare July 25, 2024 16:12
the underlying WebState needs to be associated with the Browser/WebStateList and be assigned a SessionID from the Browser so for now we'll go back to using the fake WebState to handle this. For FaviconDriver we can use WebFaviconDriver in the future but need to add an observer to Swift side to update Tab.favicon properly
This change removes a majority of underlying web view access which would create the web view too early for `target=_blank` style links and hit an assertion in WebKit
this should instead be patched/overridden at the service/factory level, we wont use this variable on CWVWebViewConfiguration either way
this is already handled by Chromium
rewrites `chrome` schemes to `brave` when formatting and loads them as standard requests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI/skip Do not run CI builds (except noplatform) CI/skip-all-linters Do not run linters and presubmit checks CI/storybook-url Deploy storybook and provide a unique URL for each build needs-security-review
Projects
None yet
3 participants