Skip to content

Commit

Permalink
[webview_flutter_web] Add support for the credentialless attribute. (…
Browse files Browse the repository at this point in the history
…#151557)
  • Loading branch information
uldall committed Jul 11, 2024
1 parent 57d42e4 commit 69fd8f8
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
4 changes: 4 additions & 0 deletions packages/webview_flutter/webview_flutter_web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.2.4

* Adds support for setting the credentialless attribute on the <iframe> element.

## 0.2.3

* Migrates to `package:web`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class _WebViewExample extends StatefulWidget {

class _WebViewExampleState extends State<_WebViewExample> {
final PlatformWebViewController _controller = PlatformWebViewController(
const PlatformWebViewControllerCreationParams(),
WebWebViewControllerCreationParams(),
)..loadRequest(
LoadRequestParams(
uri: Uri.parse('https://flutter.dev'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,32 @@ import 'http_request_factory.dart';
@immutable
class WebWebViewControllerCreationParams
extends PlatformWebViewControllerCreationParams {
/// Creates a new [AndroidWebViewControllerCreationParams] instance.
/// Creates a new [WebWebViewControllerCreationParams] instance.
/// [iFrameCredentialless] can be used to set the credentialless attribute on the <iframe>.
WebWebViewControllerCreationParams({
@visibleForTesting this.httpRequestFactory = const HttpRequestFactory(),
}) : super();
bool iFrameCredentialless = false,
}) : iFrame = web.HTMLIFrameElement()
..id = 'webView${_nextIFrameId++}'
..style.width = '100%'
..style.height = '100%'
..style.border = 'none'
..setAttribute(
'credentialless', iFrameCredentialless ? 'true' : 'false'),
super();

/// Creates a [WebWebViewControllerCreationParams] instance based on [PlatformWebViewControllerCreationParams].
/// [iFrameCredentialless] can be used to set the credentialless attribute on the <iframe>.
WebWebViewControllerCreationParams.fromPlatformWebViewControllerCreationParams(
// Recommended placeholder to prevent being broken by platform interface.
// ignore: avoid_unused_constructor_parameters
PlatformWebViewControllerCreationParams params, {
@visibleForTesting
HttpRequestFactory httpRequestFactory = const HttpRequestFactory(),
}) : this(httpRequestFactory: httpRequestFactory);
bool iFrameCredentialless = false,
}) : this(
httpRequestFactory: httpRequestFactory,
iFrameCredentialless: iFrameCredentialless);

static int _nextIFrameId = 0;

Expand All @@ -39,11 +52,7 @@ class WebWebViewControllerCreationParams

/// The underlying element used as the WebView.
@visibleForTesting
final web.HTMLIFrameElement iFrame = web.HTMLIFrameElement()
..id = 'webView${_nextIFrameId++}'
..style.width = '100%'
..style.height = '100%'
..style.border = 'none';
final web.HTMLIFrameElement iFrame;
}

/// An implementation of [PlatformWebViewController] using Flutter for Web API.
Expand Down
2 changes: 1 addition & 1 deletion packages/webview_flutter/webview_flutter_web/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: webview_flutter_web
description: A Flutter plugin that provides a WebView widget on web.
repository: https://github.com/flutter/packages/tree/main/packages/webview_flutter/webview_flutter_web
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+webview%22
version: 0.2.3
version: 0.2.4

environment:
sdk: ^3.3.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ void main() {
expect(params.iFrame.style.width, '100%');
expect(params.iFrame.style.height, '100%');
expect(params.iFrame.style.border, 'none');
expect(params.iFrame.attributes.getNamedItem('credentialless')!.value,
'false');
});

test('sets iFrame attribute credentialless', () {
final WebWebViewControllerCreationParams params =
WebWebViewControllerCreationParams(iFrameCredentialless: true);

expect(params.iFrame.attributes.getNamedItem('credentialless')!.value,
'true');
});
});

Expand Down

0 comments on commit 69fd8f8

Please sign in to comment.