Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[webview_flutter]Add the loadRequest method #4169

Closed
wants to merge 87 commits into from

Conversation

ydag
Copy link
Contributor

@ydag ydag commented Jul 20, 2021

This PR adds the loadRequest method to unify all supported HTTP methods for loading a page with URL that are defined in WebViewLoadMethod. Also, it adds the WebViewRequest class to define parameters that can be used to load a page in WebView.

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

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Note that unlike the flutter/flutter repo, the flutter/plugins repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy.
  • I updated CHANGELOG.md to add a description of the change.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@github-actions github-actions bot added p: webview_flutter Edits files for a webview_flutter plugin platform-android platform-ios labels Jul 20, 2021
@ydag ydag changed the title Add postUrl method [webview_flutter]Add postUrl method Jul 20, 2021
@google-cla google-cla bot added the cla: yes label Jul 20, 2021
@stuartmorgan-g stuartmorgan-g self-requested a review July 22, 2021 20:19
ydag added 3 commits July 23, 2021 14:41
# Conflicts:
#	packages/webview_flutter/webview_flutter/android/build.gradle
#	packages/webview_flutter/webview_flutter/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterWebView.java
@google-cla
Copy link

google-cla bot commented Aug 31, 2021

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 @googlebot I consent. in this pull request.

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 cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@google-cla google-cla bot added cla: no and removed cla: yes labels Aug 31, 2021
@BeMacized
Copy link
Contributor

@googlebot I consent.

@google-cla google-cla bot added cla: yes and removed cla: no labels Aug 31, 2021
@ydag
Copy link
Contributor Author

ydag commented Aug 31, 2021

@googlebot I consent.

@ydag ydag changed the title [webview_flutter]Update the loadUrl method [webview_flutter]Add the loadRequest method Sep 1, 2021
@ydag ydag requested a review from stuartmorgan-g September 3, 2021 08:34
@@ -102,6 +110,12 @@ public void onProgressChanged(WebView view, int progress) {

platformThreadHandler = new Handler(context.getMainLooper());

executorService = Executors.newFixedThreadPool(4);
Copy link
Contributor

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
Copy link
Contributor

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 {
Copy link
Contributor

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);
Copy link
Contributor

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
Copy link
Contributor

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.
Copy link
Contributor

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.
Copy link
Contributor

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,
};
}
Copy link
Contributor

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);
Copy link
Contributor

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',
Copy link
Contributor

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?

@stefanschaller
Copy link

@ydag Any news about this PR? :) This feature would be really great

@BeMacized
Copy link
Contributor

Closing this PR as it is currently being reworked, starting with #4450.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
5 participants