-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[webview_flutter_wkwebview] Implementation of Objective-C WKWebView Host Apis #5341
Conversation
packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.h
Outdated
Show resolved
Hide resolved
...s/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFWebViewHostApiTests.m
Outdated
Show resolved
Hide resolved
...s/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFWebViewHostApiTests.m
Outdated
Show resolved
Hide resolved
packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewHostApi.m
Outdated
Show resolved
Hide resolved
...s/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFWebViewHostApiTests.m
Show resolved
Hide resolved
packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewHostApi.m
Outdated
Show resolved
Hide resolved
packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewHostApi.m
Outdated
Show resolved
Hide resolved
packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewHostApi.m
Outdated
Show resolved
Hide resolved
This comment was marked as off-topic.
This comment was marked as off-topic.
* | ||
* @return An NSURLRequest or nil if data could not be converted. | ||
*/ | ||
id FWFConvertURLRequestData(FWFNSUrlRequestData* 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.
I generally suggest following Apple's Obj-C-ish C function naming convention of naming the returned type for things like this (e.g., NSRectFromCGRect
rather than ConvertCGRect
), so FWFNSURLRequestFromRequestData
.
packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.m
Show resolved
Hide resolved
packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewHostApi.h
Show resolved
Hide resolved
packages/webview_flutter/webview_flutter_wkwebview/pigeons/web_kit.dart
Outdated
Show resolved
Hide resolved
packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewHostApi.m
Outdated
Show resolved
Hide resolved
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 did a full sweep of the generated names and left a bunch of suggestions. Sorry to be bikeshedding on this, it's just tricky since we're still figuring out how to navigate the intersection of the instance manager and Pigeon-generated API ordering constraints.
Jenn and/or Chris should definitely weigh in on my suggestions before you update everything, to avoid you having to rename things over and over.
@@ -376,6 +389,7 @@ abstract class WKWebViewHostApi { | |||
|
|||
void loadFlutterAsset(int instanceId, String key); | |||
|
|||
@ObjCSelector('webViewWithInstanceIdCanGoBack:') |
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, I missed this before but was reminded by a recent discussion in a code cleanup issue: the ObjC name for all of these should actually be ...WithInstanceIdentifier...
. Id
is incorrect for ObjC, and while ID
is okay, Apple uses Identifier
in their APIs and we should be consistent with that.
But I was also thinking as I looked at these that there's not much potential for confusion about what identifier we're referring to in the context of this class IMO, so we could probably just use Identifier
instead of InstanceIdentifier
everywhere. (The param can still be named instanceId
which will make things even more obvious at the declaration point.)
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.
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.
Identifier
sgtm
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.
Identifier +1
@@ -364,10 +375,12 @@ abstract class WKWebViewHostApi { | |||
|
|||
void setNavigationDelegate(int instanceId, int? navigationDelegateInstanceId); | |||
|
|||
@ObjCSelector('urlForWebViewWithInstanceId:') |
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 much as it pains me, the correct naming here is URLFor...
even though it's the start of the method. See https://developer.apple.com/documentation/webkit/wkwebview/1415005-url?language=objc for instance.
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.
maybe getUrlForWebViewWithInstanceId:
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 Maurice mentioned in another comment where I forgot, ObjC getters shouldn't actually start with get
.
@implementation FWFWebView | ||
- (void)setFrame:(CGRect)frame { | ||
[super setFrame:frame]; | ||
// Prevents the contentInsets to be adjusted by iOS and gives control to Flutter. |
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.
Nit: change "to be" to "from being".
if (!urlRequest) { | ||
*error = [FlutterError errorWithCode:@"CreateNSURLRequestFailure" | ||
message:@"Failed instantiating an NSURLRequest." | ||
details:[NSString stringWithFormat:@"Url was: '%@'", request.url]]; |
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.
Nit: "URL was:"
return self; | ||
} | ||
|
||
- (FWFWebView *)getWebViewInstance:(NSNumber *)instanceId { |
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.
getWebViewWithIdentifier:
? (see comment in other file about why "identifier")
@throw [NSException exceptionWithName:@"UnsupportedException" reason:nil userInfo:nil]; | ||
} | ||
|
||
- (void)reloadInstanceId:(nonnull NSNumber *)instanceId |
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.
reloadWebViewWithIdentifier:
@throw [NSException exceptionWithName:@"UnsupportedException" reason:nil userInfo:nil]; | ||
} | ||
|
||
- (void)setAllowsBackForwardNavigationGesturesInstanceId:(nonnull NSNumber *)instanceId |
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.
The setters are all awkward ordering-wise. setBackForwardForWebViewWithIdentifier:isAllowed:error:
?
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'd prefer to leave NavigationGestures
there, I need a lot context to know what a BackForward
mean.
The name becomes very long.
Is navigationGesture not enough? Are there other navigation gestures besides backforward navigation gesture?If not maybe:
setNavigationGesturesForWebViewWithIdentifier:isAllowed:error:
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'd prefer to leave
NavigationGestures
there, I need a lot context to know what aBackForward
mean.
Yes, I'm not sure why I dropped that. My name is clearly wrong since it doesn't disable actually going back or forward, just the gestures.
Having a long name on a method that's only ever going to be called by generated code (and tests) doesn't seem like aa big deal. That's definitely not the longest signature I've ever seen :)
@throw [NSException exceptionWithName:@"UnsupportedException" reason:nil userInfo:nil]; | ||
} | ||
|
||
- (void)setNavigationDelegateInstanceId:(nonnull NSNumber *)instanceId |
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.
setNavigationDelegateForWebViewWithIdentifier:delegateIdentifier:error:
?
@throw [NSException exceptionWithName:@"UnsupportedException" reason:nil userInfo:nil]; | ||
} | ||
|
||
- (void)setUIDelegateInstanceId:(nonnull NSNumber *)instanceId |
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.
Similarly, setUIDelegate{FWVWI}:delegateIdentifier:error:
?
packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.h
Show resolved
Hide resolved
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.
Jenn and/or Chris should definitely weigh in on my suggestions before you update everything, to avoid you having to rename things over and over.
@stuartmorgan's name suggestions LGTM
@@ -376,6 +389,7 @@ abstract class WKWebViewHostApi { | |||
|
|||
void loadFlutterAsset(int instanceId, String key); | |||
|
|||
@ObjCSelector('webViewWithInstanceIdCanGoBack:') |
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.
Identifier
sgtm
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 left a bunch more naming bikeshedding on classes I apparently didn't look at last time. I don't want to beat this PR into the ground though, and I think the patterns are mostly established now and can be applied (with mixed success depending on the name) to all the methods I flagged without me needing to re-review. If there are one or two that we want to adjust later we can do it as we go now that we have a reasonable baseline.
error:(FlutterError *_Nullable *_Nonnull)error; | ||
- (void)createDefaultDataStoreInstanceId:(NSNumber *)instanceId | ||
error:(FlutterError *_Nullable *_Nonnull)error; | ||
- (void)removeDataOfTypesInstanceId:(NSNumber *)instanceId |
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.
Apparently I didn't look at every class, sorry 😬
removeDataFromDataStoreWithIdentifier:ofTypes:secondsModifiedSinceEpoch:completion:
|
||
@protocol FWFUIViewHostApi | ||
/// @return `nil` only when `error != nil`. | ||
- (nullable NSArray<NSNumber *> *)getContentOffsetInstanceId:(NSNumber *)instanceId |
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.
contentOffsetForViewWithIdentifier:
packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFGeneratedWebKitApis.h
Outdated
Show resolved
Hide resolved
packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFGeneratedWebKitApis.h
Outdated
Show resolved
Hide resolved
packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFGeneratedWebKitApis.h
Outdated
Show resolved
Hide resolved
/// The codec used by FWFWKPreferencesHostApi. | ||
NSObject<FlutterMessageCodec> *FWFWKPreferencesHostApiGetCodec(void); | ||
|
||
@protocol FWFWKPreferencesHostApi |
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 issues for these.
NSObject<FlutterMessageCodec> *FWFWKNavigationDelegateHostApiGetCodec(void); | ||
|
||
@protocol FWFWKNavigationDelegateHostApi | ||
- (void)createInstanceId:(NSNumber *)instanceId error:(FlutterError *_Nullable *_Nonnull)error; |
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.
createWithIdentifier:error:
Implementation of a few of the Host API methods of WKWebView. I wanted to get early feedback on the method names and the organization of the code.
NOTE 2400 lines of the code is generated by pigeon, so it's not as large as it seems!
No version change:
Part of flutter/flutter#93732 and doesn't make any changes to the current implementation.
No CHANGELOG change: Incremental unused code doesn't need to be noted in the CHANGELOG.
Pre-launch Checklist
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style.///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.