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

Conversation

@LuisThein
Copy link
Contributor

Description

Based on this pull request #968 that was closed, I added the functionality to set a custom User Agent and get the current User Agent in the current WebView version.

Related Issues

flutter/flutter#28256

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (flutter analyze) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • 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 signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate a breaking change in CHANGELOG.md and increment major revision).
  • No, this is not a breaking change.

LuisThein and others added 6 commits July 26, 2019 13:09
  - Added userAgent field to WebView
  - Added userAgent getter to WebViewController
  - Updated CreationParams and WebViewSettings
  - Added MethodChannel for 'getUserAgent'
  - added updateUserAgent Method
  - added getUserAgent Method
  - userAgent gets set in flutter example
  - added onGetUserAgent Method
  - added updateUserAgent Method
  - updated applySettings Method
  - added tests for get/set User Agent
  - allow currentValue.userAgent/newValue.userAgent to be null in _clearUnchangedWebSettings
@LuisThein LuisThein requested a review from amirh as a code owner July 27, 2019 12:24
@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@LuisThein
Copy link
Contributor Author

LuisThein commented Jul 27, 2019

Updated emails for CLA.

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@tp
Copy link

tp commented Jul 30, 2019

Thank you @LuisThein, we're already making use of this as we had the same requirement to change the user agent :)

_addIfNonNull('jsMode', settings.javascriptMode?.index);
_addIfNonNull('hasNavigationDelegate', settings.hasNavigationDelegate);
_addIfNonNull('debuggingEnabled', settings.debuggingEnabled);
_addIfNonNull('userAgent', settings.userAgent);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if we rebuild a WebView that had an explicitly set userAgent and set the userAgent to null. IIUC the way this currently propagates will lead to preserving the previous user agent. I'd expect it to go back to the platform's default user agent.

We should add an test for this scenario as well (build with an explicitly set user agent, rebuild with user agent set to null)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I changed it so that the user agent can be set to null and the default platform user agent is used after a rebuild. Additionally I adapted the same logic for the FakePlatformWebView unit tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!
I think we should avoid updating the user agent each time the widget is rebuilt.
It seems like we're lacking the ability to express presence/absence of a setting that may be null. One way to do it would be to use some kind of an optional type.

I pushed 7976151 with a proposal on how to do that, let me know whether that makes sense to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that is a nice way to handle nullable settings and I agree that updating the user agent every rebuild is unnecessary.

@amirh amirh added the in review label Aug 2, 2019
LuisThein and others added 5 commits August 5, 2019 10:35
  - Updated Dartdoc comments
  - Changed tests to reuse one globalkey
  - Added test for rebuilding the webView with no user agent after setting the user agent
  - Added comment to _webSettingsToMap regarding nullability of user agent
  - Changed handling of null user agent in FakePlatformWebView according to changes in WebviewMethodChannel
@LuisThein
Copy link
Contributor Author

Added requested changes and updated branch.

@amirh
Copy link
Contributor

amirh commented Aug 14, 2019

@LuisThein I pushed a few changes to your branch.
I'm ok with the current state of this PR.
Let me know whether the updates I pushed makes sense to you as well.

Copy link
Contributor

@amirh amirh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

I pushed a few changes to the branch, let me know if these make sense to you.

  - Renoved functions involved in getting the user agent
  - Updated tests to inject javascript to get the current user agent
  - updated changelog
Copy link
Contributor

@amirh amirh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants