Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Format all changes
  • Loading branch information
HugoOlthof committed Apr 12, 2023
commit e1dfa71887d102499b426d49b204956fc473c805
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void onPageFinished(

/** Passes arguments from {@link WebViewClient#onReceivedHttpError} to Dart. */
public void onPageError(
WebViewClient webViewClient, WebView webView, int statusCodeArg, Reply<Void> callback) {
WebViewClient webViewClient, WebView webView, int statusCodeArg, Reply<Void> callback) {
final Long webViewIdentifier = instanceManager.getIdentifierForStrongReference(webView);
if (webViewIdentifier == null) {
throw new IllegalStateException("Could not find identifier for WebView.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public void onPageFinished(WebView view, String url) {
}

@Override
public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
public void onReceivedHttpError(
WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
flutterApi.onPageError(this, view, errorResponse.getStatusCode(), reply -> {});
}

Expand Down Expand Up @@ -124,7 +125,8 @@ public void onPageFinished(WebView view, String url) {
}

@Override
public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
public void onReceivedHttpError(
WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
flutterApi.onPageError(this, view, errorResponse.getStatusCode(), reply -> {});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ void main() {
AndroidNavigationDelegate(_buildCreationParams());

late final int statusCode;
androidNavigationDelegate
.setOnPageError((int code) => statusCode = code);
androidNavigationDelegate.setOnPageError((int code) => statusCode = code);

CapturingWebViewClient.lastCreatedDelegate.onPageError!(
android_webview.WebView.detached(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,13 @@ WKAudiovisualMediaTypes FWFWKAudiovisualMediaTypeFromEnumData(
FWFWKNavigationResponseData *FWFWKNavigationResponseDataFromNavigationResponse(
WKNavigationResponse *response) {
return [FWFWKNavigationResponseData
makeWithResponse:FWFNSHttpUrlResponseDataFromNSURLResponse(response.response)
forMainFrame:@(response.forMainFrame)];
makeWithResponse:FWFNSHttpUrlResponseDataFromNSURLResponse(response.response)
forMainFrame:@(response.forMainFrame)];
}

FWFNSHttpUrlResponseData *FWFNSHttpUrlResponseDataFromNSURLResponse(NSURLResponse *response) {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
return [FWFNSHttpUrlResponseData
makeWithStatusCode:@(httpResponse.statusCode)];
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
return [FWFNSHttpUrlResponseData makeWithStatusCode:@(httpResponse.statusCode)];
}

FWFWKFrameInfoData *FWFWKFrameInfoDataFromWKFrameInfo(WKFrameInfo *info) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ - (void)decidePolicyForNavigationResponseForDelegate:(FWFNavigationDelegate *)in
webView:(WKWebView *)webView
navigationResponse:(WKNavigationResponse *)navigationResponse
completion:
(void (^)(FWFWKNavigationResponsePolicyEnumData *_Nullable,
NSError *_Nullable))completion {
NSNumber *webViewIdentifier =
@([self.instanceManager identifierWithStrongReferenceForInstance:webView]);
FWFWKNavigationResponseData *navigationResponseData =
FWFWKNavigationResponseDataFromNavigationResponse(navigationResponse);
[self
decidePolicyForNavigationResponseForDelegateWithIdentifier:@([self
identifierForDelegate:instance])
(void (^)(
FWFWKNavigationResponsePolicyEnumData *_Nullable,
NSError *_Nullable))completion {
NSNumber *webViewIdentifier =
@([self.instanceManager identifierWithStrongReferenceForInstance:webView]);
FWFWKNavigationResponseData *navigationResponseData =
FWFWKNavigationResponseDataFromNavigationResponse(navigationResponse);
[self decidePolicyForNavigationResponseForDelegateWithIdentifier:
@([self identifierForDelegate:instance])
webViewIdentifier:webViewIdentifier
navigationResponse:navigationResponseData
completion:completion];
Expand Down Expand Up @@ -172,7 +172,7 @@ - (void)webView:(WKWebView *)webView

- (void)webView:(WKWebView *)webView
decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse
decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler {
decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler {
[self.navigationDelegateAPI
decidePolicyForNavigationResponseForDelegate:self
webView:webView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,7 @@ extension _NavigationActionDataConverter on WKNavigationActionData {
extension _NavigationResponseDataConverter on WKNavigationResponseData {
WKNavigationResponse toNavigationResponse() {
return WKNavigationResponse(
response: response.toNSUrlResponse(),
forMainFrame: forMainFrame
);
response: response.toNSUrlResponse(), forMainFrame: forMainFrame);
}
}

Expand All @@ -214,9 +212,7 @@ extension _NSUrlRequestDataConverter on NSUrlRequestData {

extension _NSUrlResponseDataConverter on NSHttpUrlResponseData {
NSHttpUrlResponse toNSUrlResponse() {
return NSHttpUrlResponse(
statusCode: statusCode
);
return NSHttpUrlResponse(statusCode: statusCode);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class WebKitProxy {
WKNavigationAction navigationAction,
)?
decidePolicyForNavigationAction,
Future<WKNavigationResponsePolicy> Function(
Future<WKNavigationResponsePolicy> Function(
WKWebView webView,
WKNavigationResponse navigationResponse,
)?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,8 @@ class WebKitNavigationDelegate extends PlatformNavigationDelegate {
weakThis.target!._onPageStarted!(url ?? '');
}
},
decidePolicyForNavigationResponse: (WKWebView webView, WKNavigationResponse response) async {
decidePolicyForNavigationResponse:
(WKWebView webView, WKNavigationResponse response) async {
if (weakThis.target?._onPageError != null) {
weakThis.target!._onPageError!(response.response.statusCode);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -605,11 +605,8 @@ void main() {
instanceManager.getIdentifier(navigationDelegate)!,
instanceManager.getIdentifier(webView)!,
WKNavigationResponseData(
response: NSHttpUrlResponseData(
statusCode: 401
),
forMainFrame: true
),
response: NSHttpUrlResponseData(statusCode: 401),
forMainFrame: true),
);

expect(policyData.value, WKNavigationResponsePolicyEnum.cancel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,15 @@ void main() {
);

late final int callbackStatusCode;
webKitDelgate.setOnPageError((int statusCode) => callbackStatusCode = statusCode);
webKitDelgate
.setOnPageError((int statusCode) => callbackStatusCode = statusCode);

CapturingNavigationDelegate
.lastCreatedDelegate.decidePolicyForNavigationResponse!(
WKWebView.detached(),
const WKNavigationResponse(
response: NSHttpUrlResponse(statusCode: 401),
forMainFrame: true
),
);
WKWebView.detached(),
const WKNavigationResponse(
response: NSHttpUrlResponse(statusCode: 401), forMainFrame: true),
);

expect(callbackStatusCode, 401);
});
Expand Down