-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[webview_flutter]Add the loadRequest
method
#4169
Conversation
.../webview_flutter/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterWebView.java
Outdated
Show resolved
Hide resolved
.../webview_flutter/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterWebView.java
Outdated
Show resolved
Hide resolved
packages/webview_flutter/webview_flutter/ios/Classes/FlutterWebView.h
Outdated
Show resolved
Hide resolved
packages/webview_flutter/webview_flutter/ios/Classes/FlutterWebView.m
Outdated
Show resolved
Hide resolved
packages/webview_flutter/webview_flutter/ios/Classes/FlutterWebView.m
Outdated
Show resolved
Hide resolved
packages/webview_flutter/webview_flutter/ios/Classes/FlutterWebView.m
Outdated
Show resolved
Hide resolved
packages/webview_flutter/webview_flutter/ios/Classes/FlutterWebView.m
Outdated
Show resolved
Hide resolved
# Conflicts: # packages/webview_flutter/webview_flutter/android/build.gradle # packages/webview_flutter/webview_flutter/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterWebView.java
# Conflicts: # packages/webview_flutter/webview_flutter/CHANGELOG.md # packages/webview_flutter/webview_flutter/pubspec.yaml
…to webview_flutter/add_post_url
All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the ℹ️ Googlers: Go here for more info. |
@googlebot I consent. |
@googlebot I consent. |
loadUrl
methodloadRequest
method
@@ -102,6 +110,12 @@ public void onProgressChanged(WebView view, int progress) { | |||
|
|||
platformThreadHandler = new Handler(context.getMainLooper()); | |||
|
|||
executorService = Executors.newFixedThreadPool(4); |
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.
Please add a comment explaining how the number 4 was derived; it seems very arbitrary.
@@ -282,6 +299,7 @@ public void onMethodCall(MethodCall methodCall, Result result) { | |||
} | |||
} | |||
|
|||
@Deprecated |
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 deprecating a private method?
final WebViewRequest webViewRequest = buildWebViewRequest(methodCall); | ||
if (webViewRequest == null) { | ||
result.error("missing_args", "Missing arguments", null); | ||
} else { |
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: early return rather than else?
null); | ||
} else { | ||
webView.loadDataWithBaseURL( | ||
webViewRequest.getUrl(), content, "text/html", "UTF-8", null); |
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.
Are we certain that the request URL is always correct? E.g., what happens here in the case of a server-side redirect to a different origin?
@@ -90,6 +91,7 @@ void main() { | |||
final Map<String, String> headers = <String, String>{ | |||
'test_header': 'flutter_test_header' | |||
}; | |||
// ignore: deprecated_member_use |
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 there no new integration tests using the new API?
@@ -187,6 +188,30 @@ abstract class WebViewPlatformController { | |||
"WebView loadUrl is not implemented on the current platform"); | |||
} | |||
|
|||
/// Loads the specified URL. | |||
/// | |||
/// [WebViewRequest] must not be null. |
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.
Don't document things that are communicated by the type (and enforced by the compiler)
/// If [WebViewRequest.body] is not null, it will be added as HTTP body | ||
/// for the request. | ||
/// | ||
/// [WebViewRequest.uri] must not be null. |
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.
'headers': this.headers, | ||
'body': this.body, | ||
}; | ||
} |
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.
Please add simple unit tests of this class, validating that toJson
works.
required WebViewRequest request, | ||
}) async { | ||
assert(request != null); | ||
_validateUri(request.uri); |
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 not just inline this? It's a trivial method that's only used once.
await controller.loadUrl('https://google.com', headers: headers); | ||
|
||
expect(platform.lastUrlLoaded, 'https://google.com'); | ||
expect(platform.lastRequestHeaders, headers); | ||
}); | ||
}); | ||
|
||
testWidgets('Set UserAgent', (WidgetTester tester) async { | ||
await tester.pumpWidget(const WebView( | ||
initialUrl: 'https://youtube.com', |
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 there no new tests for the new API?
@ydag Any news about this PR? :) This feature would be really great |
Closing this PR as it is currently being reworked, starting with #4450. |
This PR adds the
loadRequest
method to unify all supported HTTP methods for loading a page with URL that are defined inWebViewLoadMethod
. Also, it adds theWebViewRequest
class to define parameters that can be used to load a page inWebView
.Related issues :
If you had to change anything in the flutter/tests repo, include a link to the migration guide as per the breaking change policy.
Pre-launch Checklist
dart format
.)[shared_preferences]
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.