[webview_flutter] Proof of concept web implementation#4565
[webview_flutter] Proof of concept web implementation#4565BeMacized wants to merge 17 commits intoflutter:masterfrom
Conversation
stuartmorgan-g
left a comment
There was a problem hiding this comment.
A few notes from a quick skim; I'll leave the full review to @ditman
packages/webview_flutter/webview_flutter_web/example/pubspec.yaml
Outdated
Show resolved
Hide resolved
packages/webview_flutter/webview_flutter_web/lib/shims/dart_ui_fake.dart
Show resolved
Hide resolved
packages/webview_flutter/webview_flutter_web/lib/webview_flutter_web.dart
Show resolved
Hide resolved
There was a problem hiding this comment.
This LGTM, I've only left a bunch of minor nits, and some confused questions about the New Way of federating things :)
The analysis is also complaining a little bit:
error - lib/webview_flutter_web.dart:64:7 - Missing concrete implementation of 'WebViewPlatformController.loadFlutterAsset'. Try implementing the missing method, or make the class abstract. - non_abstract_class_inherits_abstract_member
info - example/lib/main.dart:35:18 - Specify type annotations. - always_specify_types
info - example/lib/web_view.dart:330:37 - Prefer const with constant constructors. - prefer_const_constructors
info - example/lib/web_view.dart:382:16 - Prefer const with constant constructors. - prefer_const_constructors
info - lib/shims/dart_ui.dart:8:1 - Use Flutter TODO format: // TODO(username): message, https://URL-to-issue. - flutter_style_todos
packages/webview_flutter/webview_flutter_web/lib/webview_flutter_web.dart
Outdated
Show resolved
Hide resolved
packages/webview_flutter/webview_flutter_web/lib/webview_flutter_web.dart
Outdated
Show resolved
Hide resolved
packages/webview_flutter/webview_flutter_web/lib/webview_flutter_web.dart
Show resolved
Hide resolved
| } | ||
|
|
||
| /// Factory class for creating [HttpRequest] instances. | ||
| class HttpRequestFactory { |
There was a problem hiding this comment.
Why this factory, instead of asking users to pass in an HttpRequest object?
There was a problem hiding this comment.
(This is used to be mocked in tests, to ensure that the WebViewRequest is correctly parsed; I have a comment about this approach below)
There was a problem hiding this comment.
The only reason this factory exists, is so that HttpRequest.request can be mocked in the tests.
Ideally we wouldn't have this class at all, but I'm not sure how else I'd mock it.
Having the user supply the HttpRequest object is not really an option, because as far as I can see, the http request is fired immediately when HttpRequest.request(...) is called.
If you know of a better way to do this, I'd be very interested as it feels like a bit much just for a mock.
| /// when the file cannot be found. | ||
| /// | ||
| /// See also: [authorization headers](http://en.wikipedia.org/wiki/Basic_access_authentication). | ||
| Future<HttpRequest> request(String url, |
There was a problem hiding this comment.
I think this would be more useful if it was:
Future<HttpRequest> fromWebViewRequest(WebViewRequest webViewRequest) {
...
return HttpRequest.request(webViewRequest.url,
...
);then have the HttpRequestFactory class (or maybe the bare fromWebViewRequest function) unit-tested with as many weird WebViewRequest examples as needed, rather than having to make this an overrideable property just to see that the loadRequest method is extracting the correct values from the WebViewRequest object, and passing the expected values to this method.
What do you think?
(This is a completely private API, so this can be done later, if wanted)
There was a problem hiding this comment.
As mentioned above, this factory only exists for directly mocking HttpRequest.request. If this is something we need to unit test please let me know, but I assumed it would not be the case as it's nothing more than a direct pass-through.
Whether the correct request is generated from the WebViewRequest in loadRequest should already be unit tested.
| Future<bool> clearCookies() async => false; | ||
|
|
||
| /// Gets called when the plugin is registered. | ||
| static void registerWith(Registrar registrar) {} |
There was a problem hiding this comment.
Shouldn't this method be registering the instance of the plugin to the WebWebViewPlatform class? There's no global WebViewPlugin.instance anymore? Or is this the new way of doing federation?
PS: let's say we want to add web support to the webview (core) example here. Can it be done?
There was a problem hiding this comment.
I have to confess that I'm not entirely sure. Afaik the federation is like Stuart mentioned below not very standard on this plugin. I assumed this method would not be needed, but the generated_plugin_registrant.dart in the example does require it to be here. @mvanbeusekom maybe you have some extra info?
There was a problem hiding this comment.
Yep, this is normally what we use to set the "instance" of the platform-specific plugin in other plugins (see url_launcher_web for example). However this plugin is not federated exactly the same as others, so that's why this method is empty (see comment).
|
…er_web.dart Co-authored-by: David Iglesias <[email protected]>
…ebview_flutter/web_impl
|
This pull request was opened against a branch other than master. Since Flutter pull requests should not normally be opened against branches other than master, I have changed the base to master. If this was intended, you may modify the base back to master. See the Release Process for information about how other branches get updated. Reviewers: Use caution before merging pull requests to branches other than master, unless this is an intentional hotfix/cherrypick. |
Ah, yes @stuartmorgan, that issue helped to understand what's going on in this PR, thanks for the link! |
Is this a problem with the generated mock? |
@ditman Seems like it. As this is from a generated file, I'm not really sure how to go about fixing it. I've regenerated the mocks just to be sure, but it doesn't seem to have an effect. |
stuartmorgan-g
left a comment
There was a problem hiding this comment.
A few minor things
packages/webview_flutter/webview_flutter_web/lib/webview_flutter_web.dart
Outdated
Show resolved
Hide resolved
Are there non-web shims for the class being mocked? If so, perhaps those shims have the wrong types. If minor edits to the generated file work, then let's just do that (with comments), and then follow up with an issue to try to find a better solution. If minor edits aren't enough, can you make a manual fake that does what you need? It looks like you're not using that many methods/properties. |
|
In this case, the class being problematic seems to be (This is normally easier said than done, but in general you should only mock classes owned by your package) |
|
I just noticed that it's only failing on |
|
Looks like this change: dart-lang/sdk@017850f (it's likely that mocks generated on |
|
I had the same thought; I'm locally testing changing to Object? to see if stable is happy. |
|
It's also missing integration tests; I'm trying to figure out if we can useful test anything without being able to inspect the iframe. It's probably useful to at least have something that builds the whole plugin and checks that calling |
Yep. I'll push that shortly once I figure out what to do with integration tests. |
|
Wait, why does the example only have post when post doesn't work on web? @BeMacized do you have an updated example already, or should I fix it now? |
|
@stuartmorgan it seems that POST does work on web, as long as CORS/same domain passes. The only thing POST seems to do is to read the response body from the request, and render it as text on the iframe via a data: URL (if I understood the code correctly) ((It's a very odd thing to demonstrate, though)) |
|
Oh, I missed that; I thought the only thing we were supporting was setting the |
This is correct. The current example should be up to date.
I left these out, as when I tried writing these, I got an error message telling me that integration tests were not yet supported on web. |
I see, this is just me being unfamiliar with the webview_flutter examples. The main page does the standard simple load, and then there's a menu for other things. This is the subset of that standard example that works here. It's a bit odd in the context of this package that doesn't have many options, but that's fine. I'll look at a simple integration test though.
Where you using |
This could very well have been the case yes. I can take another look at writing some integration tests tomorrow morning if needed. |
|
@BeMacized I have very minimal integration tests ready, and a fix for the unit test. Can you open this branch to pushes from Flutter contributors so I can push them? |
|
Closing in favor of #4594, which fixed/added tests. |
This PR adds a very limited proof of concept for a web implementation of the webview_flutter plugin in a separate package named webview_flutter_web.
Due to various limits on the web platform, this version currently only supports a few features.
Because of its limited functionality, it currently is not compatible with the example of the app-facing plugin, only its own included example.
The provided shims for dart:ui are still triggering analysis warnings that I'm not sure how to resolve.(Something to do with flutter/flutter#55000). I cannot seem to disable all of the warnings that occur for the shim files, and I have not been able to figure out if providing a custom
analysis_options.yamlthat excludes the shim directory is a possibility here.Likewise a check fails due to there being no integration tests. As far as I know these are not a thing yet for the web platform, but I'm not sure how to disable the check.
Relevant issue:
Pre-launch Checklist
dart format.)[shared_preferences]pubspec.yamlwith an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.mdto 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.