-
Notifications
You must be signed in to change notification settings - Fork 965
[iOS] Prepare CWVWebView web embedder for use in iOS #26957
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
Conversation
66c250f
to
18f7570
Compare
58f7166
to
dbd74e5
Compare
Chromium major version is behind target branch (132.0.6834.111 vs 133.0.6943.27). Please rebase. |
dbd74e5
to
7e2255a
Compare
@@ -0,0 +1,2 @@ | |||
# Common linting false posititives from Obj-C syntax in headers | |||
filter=-readability/casting,-whitespace/parens,-whitespace/operators |
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.
why do we have an issue with this if upstream doesn't have it in their config?
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.
Im not sure, we have the same issue in our own ios
folder https://github.com/brave/brave-core/blob/master/ios/CPPLINT.cfg
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.
what specifically is triggering it?
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.
src/brave/chromium_src/ios/web_view/internal/cwv_web_view_configuration_internal.h:34: (cpplint) Using C-style cast. Use reinterpret_cast<CWVWebView*>(...) instead [readability/casting] [4]
src/brave/chromium_src/ios/web_view/internal/cwv_web_view_internal.h:15: (cpplint) Using C-style cast. Use reinterpret_cast<NSData*>(...) instead [readability/casting] [4]
** Presubmit Messages: 1 **
The actual lines it references don't make sense. For instance the first one is just a standard Obj-C method:
- (void)registerWebView:(CWVWebView*)webView;
The second is
+ (BOOL)_isRestoreDataValid:(NSData*)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.
cc @goodov if you have any ideas?
@@ -0,0 +1,4 @@ | |||
include_rules = [ | |||
"+brave/components/https_upgrade_exceptions/browser", | |||
"+brave/ios/browser/application_context", |
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.
this can probably go in chromium_src/ios/chrome/browser/DEPS
// (usually by crashing, though possibly by other means). | ||
- (void)webViewWebContentProcessDidTerminate:(CWVWebView*)webView; | ||
|
||
+- (BOOL)webView:(CWVWebView*)webView shouldBlockUniversalLinksForRequest:(NSURLRequest*)request; |
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.
#define webViewWebContentProcessDidTerminate webView:(CWVWebView*)webView didRequestHTTPAuthForProtectionSpace... rest of methods we add... webViewWebContentProcessDidTerminate
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.
We can't use chromium_src overrides for these public headers because they are copied into the BraveCore framework target (public headers folder), so they have to be patched at rest
#pragma mark - Autofill | ||
|
||
- (CWVAutofillController*)autofillController { | ||
+ BRAVE_NOP_SERVICE |
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.
can we override AutofillAgent
to be a no-op?
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.
We could be this is still to ensure you cant access it from the CWVWebView
property
} | ||
|
||
[self attachSecurityInterstitialHelpersToWebStateIfNecessary]; | ||
+ BRAVE_ATTACH_TAB_HELPERS |
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.
why are we attaching general tab helpers here? Shouldn't this happen automatically through BrowserWebStateListDelegate
if we are adding them in upstream AttachTabHelpers
?
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.
None of the ios/web_view
parts go through Browser
/WebStateList
#pragma mark - Translation | ||
|
||
- (CWVTranslationController*)translationController { | ||
+ BRAVE_NOP_SERVICE |
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.
same as below
}() | ||
|
||
@dynamicMemberLookup | ||
class WebViewModel: ObservableObject { |
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.
What is the class for/what does it do? Please add comments
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 this was just thrown together to demonstrate the CWVWebView
in a small shell app. This code specifically model glue for SwiftUI so the shell UI updates properly when observable properties change
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.
oic, this was the thing I was asking about to run
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.
can you add comments explaining?
return (cachedProtobufStorage != nil || cachedSessionStorage != nil); | ||
} | ||
|
||
+ (id)objectFromValue:(const base::Value*)value { |
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.
why does this need to be a method on CWVWebView? Can't we just use NSObjectFromValue
directly?
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.
Its a function in an anonymous namespace defined in cwv_web_view.mm
and not exposed in cwv_web_view_internal.h
so this seemed like the easiest solution: https://source.chromium.org/chromium/chromium/src/+/main:ios/web_view/internal/cwv_web_view.mm;l=114
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 think we should keep the same name and not drop NS?
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.
It'd be against typical Obj-C naming conventions, you don't include the class prefixes in the method naming
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.
this is effectively private since it's internal, right? It can only be used within CWVWebView?
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.
Correct
"//brave/ios/web_view/public/cwv_ssl_status_extras.h", | ||
"//brave/ios/web_view/public/cwv_x509_certificate_extras.h", | ||
"//brave/ios/web_view/public/cwv_web_view_extras.h", | ||
|
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.
empty line?
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.
To separate the //brave specific extras and the headers coming from Chromium's //ios/web_view
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
// Copyright (c) 2019 The Brave Authors. All rights reserved. |
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.
we backdated it?
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.
This file was moved into the web subdirectory to match chromium, but its been around since 2019
|
||
/// A list of default website preferences. | ||
OBJC_EXPORT | ||
@interface DefaultHostContentSettings : NSObject |
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.
this is fine for now, but we should really have an api wrapper for host content settings map in general
ios/browser/web/brave_web_client.mm
Outdated
features.push_back( | ||
security_interstitials::IOSSecurityInterstitialJavaScriptFeature:: | ||
GetInstance()); | ||
features.push_back(translate::TranslateJavaScriptFeature::GetInstance()); |
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 thought we weren't using chromium translate?
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.
We actually are now but not through JavaScriptFeature
, this is actually supposed to be removed though until we can properly support it as a JavaScriptFeature
})); | ||
} | ||
|
||
- (WKWebView*)underlyingWebView { |
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.
why aren't we just exposing the CRWWebController
as an attribute and then we can also use that for createPDF
, etc...
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.
As per DM:
- We don't want to expose
CRWWebController
as its essentially theWKWebView
handler, which we want to avoid using and overtime will use it less (for when we eventually can support ause_blink
build) - We can't expose
CRWWebController
as-is, would have to wrap it anyways
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.
discussed in DM, but maybe this should be internalWebView
or something?
config_provider.UpdateScripts(); | ||
} | ||
|
||
- (void)createPDF:(void (^)(NSData* _Nullable))completionHandler { |
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.
createFullPagePdf
to match upstream method. It's much easier to find things when names match
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 after removing https upgrade code that needs fixes in desktop first
6ce5992
to
9b658bf
Compare
9b658bf
to
b3ed162
Compare
[puLL-Merge] - brave/brave-core@26957 DescriptionThis PR adds support for CWVWebView (Chromium WebView) integration in Brave iOS, allowing Brave to reuse Chromium's WebKit implementation while adding Brave-specific features and customizations. The changes include:
ChangesChangesBy File Category: Core Web Client Changes:
WebView Extensions:
Build & Project Config:
Test App:
sequenceDiagram
participant App as WebShell App
participant Core as BraveCoreMain
participant WebView as CWVWebView
participant Client as WebClient
App->>Core: Initialize
Core->>Client: Configure WebClient
App->>Core: Get WebViewConfiguration
Core-->>App: Return configuration
App->>WebView: Create with configuration
WebView->>Client: Setup navigation handlers
WebView->>WebView: Attach Brave features
App->>WebView: Load initial URL
WebView->>Client: Process navigation
Security Hotspots
Possible Issues
|
Released in v1.78.4 |
This is the split-up contents of #24657. This PR in particular only adds the
CWVWebView
API and exposes it to the iOS app but does not actually contain the code that usesCWVWebView
in the iOS app. There is a shell target added (WebShell
) for simple tests, for more comprehensive tests involving multiple tabs, please use theios-cwvwebview-impl
branchResolves brave/brave-browser#42838
Submitter Checklist:
QA/Yes
orQA/No
;release-notes/include
orrelease-notes/exclude
;OS/...
) to the associated issuenpm run test -- brave_browser_tests
,npm run test -- brave_unit_tests
wikinpm run presubmit
wiki,npm run gn_check
,npm run tslint
git rebase master
(if needed)Reviewer Checklist:
gn
After-merge Checklist:
changes has landed on
Test Plan: