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.8k
[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 2 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
60 changes: 60 additions & 0 deletions
60
...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,60 @@ | ||
// 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 'types/types.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.
Show resolved
Hide resolved
|
||
abstract class NavigationCallbackHandlerDelegate extends PlatformInterface { | ||
bparrishMines marked this conversation as resolved.
Show resolved
Hide resolved
mvanbeusekom marked this conversation as resolved.
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.
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(); | ||
|
||
/// Invoked by [WebViewPlatformControllerDelegate] when a navigation request | ||
/// is pending. | ||
/// | ||
/// If true is returned the navigation is allowed, otherwise it is blocked. | ||
FutureOr<bool> onNavigationRequest( | ||
mvanbeusekom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{required String url, required bool isForMainFrame}); | ||
|
||
/// Invoked by [WebViewPlatformControllerDelegate] when a page has started | ||
/// loading. | ||
void onPageStarted(String url); | ||
|
||
/// Invoked by [WebViewPlatformControllerDelegate] when a page has finished | ||
/// loading. | ||
void onPageFinished(String url); | ||
|
||
/// Invoked by [WebViewPlatformControllerDelegate] when a page is loading. | ||
/// | ||
/// Only works when [WebSettings.hasProgressTracking] is set to `true`. | ||
void onProgress(int progress); | ||
|
||
/// Report web resource loading error to the host application. | ||
void onWebResourceError(WebResourceError error); | ||
} |
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
...view_flutter/webview_flutter_platform_interface/lib/src/v4/types/load_request_params.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]. | ||
mvanbeusekom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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]. | ||
/// | ||
/// 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. | ||
mvanbeusekom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// | ||
/// ```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, | ||
required Map<String, String> headers, | ||
mvanbeusekom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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>{ | ||
mvanbeusekom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
'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_mode.dart'; | ||
export 'load_request_params.dart'; | ||
export 'web_resource_error.dart'; | ||
export 'web_resource_error_type.dart'; | ||
export 'web_settings.dart'; | ||
export 'webview_cookie.dart'; |
60 changes: 60 additions & 0 deletions
60
...bview_flutter/webview_flutter_platform_interface/lib/src/v4/types/web_resource_error.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,60 @@ | ||
// 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'; | ||
|
||
import 'web_resource_error_type.dart'; | ||
|
||
/// Error returned in `WebView.onWebResourceError` when a web resource loading error has occurred. | ||
@sealed | ||
mvanbeusekom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
class WebResourceError { | ||
BeMacized marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// Creates a new [WebResourceError] | ||
/// | ||
/// A user should not need to instantiate this class, but will receive one in | ||
/// [WebResourceErrorCallback]. | ||
WebResourceError({ | ||
required this.errorCode, | ||
required this.description, | ||
this.domain, | ||
this.errorType, | ||
this.failingUrl, | ||
}) : assert(errorCode != null), | ||
assert(description != null); | ||
|
||
/// Raw code of the error from the respective platform. | ||
/// | ||
/// On Android, the error code will be a constant from a | ||
/// [WebViewClient](https://developer.android.com/reference/android/webkit/WebViewClient#summary) and | ||
/// will have a corresponding [errorType]. | ||
/// | ||
/// On iOS, the error code will be a constant from `NSError.code` in | ||
/// Objective-C. See | ||
/// https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ErrorHandlingCocoa/ErrorObjectsDomains/ErrorObjectsDomains.html | ||
/// for more information on error handling on iOS. Some possible error codes | ||
/// can be found at https://developer.apple.com/documentation/webkit/wkerrorcode?language=objc. | ||
final int errorCode; | ||
|
||
/// The domain of where to find the error code. | ||
/// | ||
/// This field is only available on iOS and represents a "domain" from where | ||
/// the [errorCode] is from. This value is taken directly from an `NSError` | ||
/// in Objective-C. See | ||
/// https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ErrorHandlingCocoa/ErrorObjectsDomains/ErrorObjectsDomains.html | ||
/// for more information on error handling on iOS. | ||
final String? domain; | ||
mvanbeusekom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/// Description of the error that can be used to communicate the problem to the user. | ||
final String description; | ||
|
||
/// The type this error can be categorized as. | ||
/// | ||
/// This will never be `null` on Android, but can be `null` on iOS. | ||
final WebResourceErrorType? errorType; | ||
|
||
/// Gets the URL for which the resource request was made. | ||
/// | ||
/// This value is not provided on iOS. Alternatively, you can keep track of | ||
/// the last values provided to [WebViewPlatformController.loadUrl]. | ||
final String? failingUrl; | ||
} |
66 changes: 66 additions & 0 deletions
66
..._flutter/webview_flutter_platform_interface/lib/src/v4/types/web_resource_error_type.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,66 @@ | ||
// 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. | ||
|
||
/// Possible error type categorizations used by [WebResourceError]. | ||
enum WebResourceErrorType { | ||
/// User authentication failed on server. | ||
authentication, | ||
|
||
/// Malformed URL. | ||
badUrl, | ||
|
||
/// Failed to connect to the server. | ||
connect, | ||
|
||
/// Failed to perform SSL handshake. | ||
failedSslHandshake, | ||
|
||
/// Generic file error. | ||
file, | ||
|
||
/// File not found. | ||
fileNotFound, | ||
|
||
/// Server or proxy hostname lookup failed. | ||
hostLookup, | ||
|
||
/// Failed to read or write to the server. | ||
io, | ||
|
||
/// User authentication failed on proxy. | ||
proxyAuthentication, | ||
|
||
/// Too many redirects. | ||
redirectLoop, | ||
|
||
/// Connection timed out. | ||
timeout, | ||
|
||
/// Too many requests during this load. | ||
tooManyRequests, | ||
|
||
/// Generic error. | ||
unknown, | ||
|
||
/// Resource load was canceled by Safe Browsing. | ||
unsafeResource, | ||
|
||
/// Unsupported authentication scheme (not basic or digest). | ||
unsupportedAuthScheme, | ||
|
||
/// Unsupported URI scheme. | ||
unsupportedScheme, | ||
|
||
/// The web content process was terminated. | ||
webContentProcessTerminated, | ||
|
||
/// The web view was invalidated. | ||
webViewInvalidated, | ||
|
||
/// A JavaScript exception occurred. | ||
javaScriptExceptionOccurred, | ||
|
||
/// The result of JavaScript execution could not be returned. | ||
javaScriptResultTypeIsUnsupported, | ||
} |
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.