This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[webview_flutter] Initial v4.0 platform interface implementation #5109
Merged
fluttergithubbot
merged 39 commits into
flutter:main
from
Baseflow:issue/94051_webview_4.0
May 18, 2022
Merged
Changes from 8 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
ee662ec
Refactor to v4
mvanbeusekom 06bb7b6
First definition of platform interface v4
mvanbeusekom d8ce25f
Converted WebResourceError to full delegate
mvanbeusekom 75cc8e5
Merge branch 'issue/94051_webview_4.0' of github.com:Baseflow/flutter…
mvanbeusekom 2abdd4a
Processed feedback on pull request
mvanbeusekom 78c56e6
Fixed formatting
mvanbeusekom 3b5bad5
Removed obsolete import statements
mvanbeusekom 8684ac3
Applied feedback on WebViewControllerDelegate pull request
mvanbeusekom 5302592
Implemented PR feedback. (Unit tests not yet updated)
BeMacized 19c4580
Update tests
BeMacized 196b4d8
Process PR feedback
BeMacized 9361b8c
Process PR feedback
BeMacized fd81633
Add missing license block
BeMacized 3936ff5
Add missing comments
BeMacized 405219c
Applied feedback on pull requests.
mvanbeusekom 8495c24
Fixed formatting
mvanbeusekom c772654
Regenerate mock classes after rename
mvanbeusekom f42f022
Fixed formatting
mvanbeusekom dca96f0
Removed WebSettings object.
mvanbeusekom 221e386
Fixed formatting
mvanbeusekom 9760d52
Bump version number
mvanbeusekom b13b4dd
Added dependency on meta package
mvanbeusekom d488453
Rebased on main
mvanbeusekom 978121e
Merge remote-tracking branch 'upstream/main' into issue/94051_webview…
mvanbeusekom 46bca5f
Applied feedback from review
mvanbeusekom e2be2b8
Merge remote-tracking branch 'upstream/main' into issue/94051_webview…
mvanbeusekom fa54703
Rearrange folder structure to allow easier migration final version
mvanbeusekom d065f93
Update example in documentation
mvanbeusekom 76b2a02
Make ...CreationParams immutable
mvanbeusekom 4cc0f56
Made JavaScriptChannelRegistry available
mvanbeusekom 44d7782
Added PR feedback
mvanbeusekom 789fd5a
Added clearLocalStorage method and test
mvanbeusekom 51a1f76
Merge remote-tracking branch 'upstream/main' into issue/94051_webview…
mvanbeusekom ca99630
Refactored 'Delegate' postfix according to latest discussion
mvanbeusekom 241d3b4
Merge remote-tracking branch 'upstream/main' into issue/94051_webview…
mvanbeusekom 3e22600
Apply feedback from PR
mvanbeusekom dfb48ca
Merge remote-tracking branch 'upstream/main' into issue/94051_webview…
mvanbeusekom 1db2d18
Apply feedback from PR
mvanbeusekom 1487730
Merge remote-tracking branch 'upstream/main' into issue/94051_webview…
mvanbeusekom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
...r/webview_flutter_platform_interface/lib/src/v4/navigation_callback_handler_delegate.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import 'dart:async'; | ||
|
|
||
| import 'package:flutter/foundation.dart'; | ||
| import 'package:plugin_platform_interface/plugin_platform_interface.dart'; | ||
|
|
||
| import 'webview_platform.dart'; | ||
|
|
||
| /// Interface for callbacks made by [NavigationCallbackHandlerDelegate]. | ||
| /// | ||
| /// The webview plugin implements this class, and passes an instance to the | ||
| /// [NavigationCallbackHandlerDelegate]. | ||
| /// [NavigationCallbackHandlerDelegate] is notifying this handler on events that | ||
| /// happened on the platform's webview. | ||
mvanbeusekom marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| abstract class NavigationCallbackHandlerDelegate extends PlatformInterface { | ||
bparrishMines marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
mvanbeusekom marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// Creates a new [NavigationCallbacksHandlerDelegate] | ||
| factory NavigationCallbackHandlerDelegate() { | ||
| final NavigationCallbackHandlerDelegate callbackHandlerDelegate = | ||
| WebViewPlatform.instance!.createNavigationCallbackHandlerDelegate(); | ||
| PlatformInterface.verify(callbackHandlerDelegate, _token); | ||
| return callbackHandlerDelegate; | ||
| } | ||
|
|
||
| /// Used by the platform implementation to create a new | ||
| /// [NavigationCallbackHandlerDelegate]. | ||
BeMacized marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// | ||
| /// Should only be used by platform implementations because they can't extend | ||
| /// a class that only contains a factory constructor. | ||
| @protected | ||
| NavigationCallbackHandlerDelegate.implementation() : super(token: _token); | ||
|
|
||
| static final Object _token = Object(); | ||
|
|
||
| /// Sets the callback method that is invoked by the | ||
| /// [WebViewPlatformControllerDelegate] when a navigation request is pending. | ||
BeMacized marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Future<void> setOnNavigationRequest( | ||
| void Function({required String url, required bool isForMainFrame}) | ||
| onNavigationRequest, | ||
| ) { | ||
| throw UnimplementedError( | ||
| 'setOnNavigationRequest is not implemented on the current platform.'); | ||
| } | ||
|
|
||
| /// Sets the callback method that is invoked by [WebViewControllerDelegate] | ||
| /// when a page has started loading. | ||
| Future<void> setOnPageStarted( | ||
| void Function(String url) onPageStarted, | ||
| ) { | ||
| throw UnimplementedError( | ||
| 'setOnPageStarted is not implemented on the current platform.'); | ||
| } | ||
|
|
||
| /// Sets the callback method that is invoked by [WebViewControllerDelegate] | ||
| /// when a page has finished loading. | ||
| Future<void> setOnPageFinished( | ||
| void Function(String url) onPageFinished, | ||
| ) { | ||
| throw UnimplementedError( | ||
| 'setOnPageFinished is not implemented on the current platform.'); | ||
| } | ||
|
|
||
| /// Sets the callback method that is invoked by [WebViewControllerDelegate] | ||
| /// when a page is loading. | ||
| /// | ||
| /// Only works when [WebSettings.hasProgressTracking] is set to `true`. | ||
| Future<void> setOnProgress( | ||
| void Function(int progress) onProgress, | ||
| ) { | ||
| throw UnimplementedError( | ||
| 'setOnProgress is not implemented on the current platform.'); | ||
| } | ||
|
|
||
| /// Sets the callback that is invoked when a resource loading error occurred.. | ||
| Future<void> setOnWebResourceError( | ||
| void Function(WebResourceErrorDelegate error) onWebResourceError, | ||
| ) { | ||
| throw UnimplementedError( | ||
| 'setOnWebResourceError is not implemented on the current platform.'); | ||
| } | ||
| } | ||
17 changes: 17 additions & 0 deletions
17
...bview_flutter/webview_flutter_platform_interface/lib/src/v4/types/javascript_message.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import 'package:meta/meta.dart'; | ||
|
|
||
| /// A message that was sent by JavaScript code running in a [WebView]. | ||
| @sealed | ||
BeMacized marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| class JavaScriptMessage { | ||
| /// Constructs a JavaScript message object. | ||
| /// | ||
| /// The `message` parameter must not be null. | ||
BeMacized marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const JavaScriptMessage(this.message) : assert(message != null); | ||
|
|
||
| /// The contents of the message that was sent by the JavaScript code. | ||
| final String message; | ||
| } | ||
12 changes: 12 additions & 0 deletions
12
.../webview_flutter/webview_flutter_platform_interface/lib/src/v4/types/javascript_mode.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| /// Describes the state of JavaScript support in a given web view. | ||
| enum JavaScriptMode { | ||
| /// JavaScript execution is disabled. | ||
| disabled, | ||
|
|
||
| /// JavaScript execution is not restricted. | ||
| unrestricted, | ||
| } |
129 changes: 129 additions & 0 deletions
129
...ter/webview_flutter_platform_interface/lib/src/v4/types/load_request_params_delegate.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import 'dart:typed_data'; | ||
|
|
||
| import 'package:flutter/foundation.dart'; | ||
| import 'package:plugin_platform_interface/plugin_platform_interface.dart'; | ||
| import 'package:webview_flutter_platform_interface/src/v4/webview_controller_delegate.dart'; | ||
|
|
||
| import '../webview_platform.dart'; | ||
|
|
||
| /// Defines the supported HTTP methods for loading a page in | ||
| /// [WebViewControllerDelegate]. | ||
| enum LoadRequestMethod { | ||
| /// HTTP GET method. | ||
| get, | ||
|
|
||
| /// HTTP POST method. | ||
| post, | ||
| } | ||
|
|
||
| /// Extension methods on the [LoadRequestMethod] enum. | ||
| extension LoadRequestMethodExtensions on LoadRequestMethod { | ||
| /// Converts [LoadRequestMethod] to [String] format. | ||
| String serialize() { | ||
| switch (this) { | ||
| case LoadRequestMethod.get: | ||
| return 'get'; | ||
| case LoadRequestMethod.post: | ||
| return 'post'; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Defines the parameters that can be used to load a page with the | ||
| /// [WebViewControllerDelegate]. | ||
BeMacized marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// | ||
| /// Platform specific implementations can add additional fields by extending this | ||
| /// class and provide a factory method that takes the | ||
| /// [LoadRequestParamsDelegate] as a parameter. | ||
| /// | ||
| /// {@tool sample} | ||
| /// This example demonstrates how to extend the [LoadRequestParamsDelegate] to | ||
| /// provide additional platform specific parameters. | ||
| /// | ||
| /// Note that the additional parameters should always accept `null` or have a | ||
| /// default value to prevent breaking changes. | ||
| /// | ||
| /// ```dart | ||
| /// class AndroidLoadRequestParamsDelegate extends LoadRequestParamsDelegate { | ||
| /// AndroidLoadRequestParamsDelegate._( | ||
| /// LoadRequestParamsDelegate loadRequestParams, | ||
| /// this.historyUrl, | ||
| /// ) : super( | ||
| /// uri: loadRequestParams.uri, | ||
| /// method: loadRequestParams.method, | ||
| /// headers: loadRequestParams.headers, | ||
| /// body: loadRequestParams.body, | ||
| /// ); | ||
| /// | ||
| /// factory AndroidLoadRequestParamsDelegate.fromLoadRequestParamsDelegate( | ||
| /// LoadRequestParamsDelegate loadRequestParams, { | ||
| /// Uri? historyUrl, | ||
| /// }) { | ||
| /// return AndroidLoadRequestParamsDelegate._( | ||
| /// loadRequestParams: loadRequestParams, | ||
| /// historyUrl: historyUrl, | ||
| /// ); | ||
| /// } | ||
| /// | ||
| /// final Uri? historyUrl; | ||
| /// } | ||
| /// ``` | ||
| /// {@end-tool} | ||
| class LoadRequestParamsDelegate extends PlatformInterface { | ||
| /// Creates a new [LoadRequestParamsDelegate]. | ||
| factory LoadRequestParamsDelegate({ | ||
| required Uri uri, | ||
| required LoadRequestMethod method, | ||
| Map<String, String> headers = const <String, String>{}, | ||
| Uint8List? body, | ||
| }) { | ||
| final LoadRequestParamsDelegate loadRequestParamsDelegate = | ||
| WebViewPlatform.instance!.createLoadRequestParamsDelegate( | ||
| uri: uri, | ||
| method: method, | ||
| headers: headers, | ||
| body: body, | ||
| ); | ||
| PlatformInterface.verify(loadRequestParamsDelegate, _token); | ||
| return loadRequestParamsDelegate; | ||
| } | ||
|
|
||
| /// Used by the platform implementation to create a new | ||
| /// [LoadRequestParamsDelegate]. | ||
| /// | ||
| /// Should only be used by platform implementations because they can't extend | ||
| /// a class that only contains a factory constructor. | ||
| @protected | ||
| LoadRequestParamsDelegate.implementation({ | ||
| required this.uri, | ||
| required this.method, | ||
| required this.headers, | ||
| this.body, | ||
| }) : super(token: _token); | ||
|
|
||
| static final Object _token = Object(); | ||
|
|
||
| /// URI for the request. | ||
| final Uri uri; | ||
|
|
||
| /// HTTP method used to make the request. | ||
| final LoadRequestMethod method; | ||
|
|
||
| /// Headers for the request. | ||
| final Map<String, String> headers; | ||
|
|
||
| /// HTTP body for the request. | ||
| final Uint8List? body; | ||
|
|
||
| /// Serializes the [WebViewRequest] to JSON. | ||
| Map<String, dynamic> toJson() => <String, dynamic>{ | ||
| 'uri': uri.toString(), | ||
| 'method': method.serialize(), | ||
| 'headers': headers, | ||
| 'body': body, | ||
| }; | ||
| } | ||
10 changes: 10 additions & 0 deletions
10
packages/webview_flutter/webview_flutter_platform_interface/lib/src/v4/types/types.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| export 'javascript_message.dart'; | ||
| export 'javascript_mode.dart'; | ||
| export 'load_request_params_delegate.dart'; | ||
| export 'web_resource_error_delegate.dart'; | ||
| export 'web_settings_delegate.dart'; | ||
| export 'webview_cookie.dart'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.