Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
ee662ec
Refactor to v4
mvanbeusekom Mar 24, 2022
06bb7b6
First definition of platform interface v4
mvanbeusekom Mar 25, 2022
d8ce25f
Converted WebResourceError to full delegate
mvanbeusekom Mar 31, 2022
75cc8e5
Merge branch 'issue/94051_webview_4.0' of github.com:Baseflow/flutter…
mvanbeusekom Mar 31, 2022
2abdd4a
Processed feedback on pull request
mvanbeusekom Apr 1, 2022
78c56e6
Fixed formatting
mvanbeusekom Apr 1, 2022
3b5bad5
Removed obsolete import statements
mvanbeusekom Apr 1, 2022
8684ac3
Applied feedback on WebViewControllerDelegate pull request
mvanbeusekom Apr 4, 2022
5302592
Implemented PR feedback. (Unit tests not yet updated)
BeMacized Apr 6, 2022
19c4580
Update tests
BeMacized Apr 6, 2022
196b4d8
Process PR feedback
BeMacized Apr 11, 2022
9361b8c
Process PR feedback
BeMacized Apr 11, 2022
fd81633
Add missing license block
BeMacized Apr 11, 2022
3936ff5
Add missing comments
BeMacized Apr 12, 2022
405219c
Applied feedback on pull requests.
mvanbeusekom Apr 12, 2022
8495c24
Fixed formatting
mvanbeusekom Apr 12, 2022
c772654
Regenerate mock classes after rename
mvanbeusekom Apr 12, 2022
f42f022
Fixed formatting
mvanbeusekom Apr 12, 2022
dca96f0
Removed WebSettings object.
mvanbeusekom Apr 13, 2022
221e386
Fixed formatting
mvanbeusekom Apr 13, 2022
9760d52
Bump version number
mvanbeusekom Apr 13, 2022
b13b4dd
Added dependency on meta package
mvanbeusekom Apr 13, 2022
d488453
Rebased on main
mvanbeusekom Apr 13, 2022
978121e
Merge remote-tracking branch 'upstream/main' into issue/94051_webview…
mvanbeusekom Apr 14, 2022
46bca5f
Applied feedback from review
mvanbeusekom Apr 14, 2022
e2be2b8
Merge remote-tracking branch 'upstream/main' into issue/94051_webview…
mvanbeusekom Apr 14, 2022
fa54703
Rearrange folder structure to allow easier migration final version
mvanbeusekom Apr 14, 2022
d065f93
Update example in documentation
mvanbeusekom Apr 14, 2022
76b2a02
Make ...CreationParams immutable
mvanbeusekom Apr 14, 2022
4cc0f56
Made JavaScriptChannelRegistry available
mvanbeusekom Apr 15, 2022
44d7782
Added PR feedback
mvanbeusekom Apr 19, 2022
789fd5a
Added clearLocalStorage method and test
mvanbeusekom Apr 20, 2022
51a1f76
Merge remote-tracking branch 'upstream/main' into issue/94051_webview…
mvanbeusekom May 10, 2022
ca99630
Refactored 'Delegate' postfix according to latest discussion
mvanbeusekom May 11, 2022
241d3b4
Merge remote-tracking branch 'upstream/main' into issue/94051_webview…
mvanbeusekom May 11, 2022
3e22600
Apply feedback from PR
mvanbeusekom May 11, 2022
dfb48ca
Merge remote-tracking branch 'upstream/main' into issue/94051_webview…
mvanbeusekom May 11, 2022
1db2d18
Apply feedback from PR
mvanbeusekom May 13, 2022
1487730
Merge remote-tracking branch 'upstream/main' into issue/94051_webview…
mvanbeusekom May 18, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.9.0

* Adds the first iteration of the v4 webview_flutter interface implementation.

## 1.8.2

* Migrates from `ui.hash*` to `Object.hash*`.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// 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 'types/javascript_channel.dart';
import 'types/javascript_message.dart';

/// Utility class for managing named JavaScript channels and forwarding incoming
/// messages on the correct channel.
@sealed
class JavaScriptChannelRegistry {
Comment thread
mvanbeusekom marked this conversation as resolved.
Outdated
/// Constructs a [JavaScriptChannelRegistry] initializing it with the given
/// set of [JavaScriptChannel]s.
JavaScriptChannelRegistry(Set<JavaScriptChannel>? channels) {
updateJavaScriptChannelsFromSet(channels);
}

/// Maps a channel name to a channel.
final Map<String, JavaScriptChannel> channels = <String, JavaScriptChannel>{};

/// Invoked when a JavaScript channel message is received.
void onJavaScriptChannelMessage(String channel, String message) {
final JavaScriptChannel? javaScriptChannel = channels[channel];

if (javaScriptChannel == null) {
throw ArgumentError('No channel registered with name $channel.');
}

javaScriptChannel.onMessageReceived(JavaScriptMessage(message: message));
}

/// Replaces the set of [JavaScriptChannel]s with the new set.
void updateJavaScriptChannelsFromSet(Set<JavaScriptChannel>? channels) {
this.channels.clear();
if (channels == null) {
return;
}

for (final JavaScriptChannel channel in channels) {
this.channels[channel.name] = channel;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// 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';

/// An interface defining navigation events that occur on the native platform.
///
/// The [WebViewControllerDelegate] is notifying this delegate on events that
/// happened on the platform's webview. Platform implementations should
/// implement this class and pass an instance to the [WebViewControllerDelegate].
abstract class NavigationCallbackDelegate extends PlatformInterface {
Comment thread
mvanbeusekom marked this conversation as resolved.
Outdated
/// Creates a new [NavigationCallbackDelegate]
factory NavigationCallbackDelegate(NavigationCallbackCreationParams params) {
final NavigationCallbackDelegate callbackDelegate =
WebViewPlatform.instance!.createNavigationCallbackDelegate(params);
PlatformInterface.verify(callbackDelegate, _token);
return callbackDelegate;
}

/// Used by the platform implementation to create a new [NavigationCallbackDelegate].
///
/// Should only be used by platform implementations because they can't extend
/// a class that only contains a factory constructor.
@protected
NavigationCallbackDelegate.implementation(this.params) : super(token: _token);

static final Object _token = Object();

/// The parameters used to initialize the [NavigationCallbackDelegate].
final NavigationCallbackCreationParams params;

/// Invoked when a navigation request is pending.
///
/// See [WebViewControllerDelegate.setNavigationCallbackDelegate].
Future<void> setOnNavigationRequest(
FutureOr<bool> Function({required String url, required bool isForMainFrame})
onNavigationRequest,
) {
throw UnimplementedError(
'setOnNavigationRequest is not implemented on the current platform.');
}

/// Invoked when a page has started loading.
///
/// See [WebViewControllerDelegate.setNavigationCallbackDelegate].
Future<void> setOnPageStarted(
void Function(String url) onPageStarted,
) {
throw UnimplementedError(
'setOnPageStarted is not implemented on the current platform.');
}

/// Invoked when a page has finished loading.
///
/// See [WebViewControllerDelegate.setNavigationCallbackDelegate].
Future<void> setOnPageFinished(
void Function(String url) onPageFinished,
) {
throw UnimplementedError(
'setOnPageFinished is not implemented on the current platform.');
}

/// Invoked when a page is loading to report the progress.
///
/// See [WebViewControllerDelegate.setNavigationCallbackDelegate].
Future<void> setOnProgress(
void Function(int progress) onProgress,
) {
throw UnimplementedError(
'setOnProgress is not implemented on the current platform.');
}

/// Invoked when a resource loading error occurred.
///
/// See [WebViewControllerDelegate.setNavigationCallbackDelegate].
Future<void> setOnWebResourceError(
void Function(WebResourceError error) onWebResourceError,
) {
throw UnimplementedError(
'setOnWebResourceError is not implemented on the current platform.');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// 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 'javascript_message.dart';

/// Callback type for handling messages sent from JavaScript running in a web view.
typedef JavaScriptMessageHandler = void Function(JavaScriptMessage message);

final RegExp _validChannelNames = RegExp(r'^[a-zA-Z_][a-zA-Z0-9_]*$');

/// A named channel for receiving messaged from JavaScript code running inside a web view.
class JavaScriptChannel {
/// Constructs a JavaScript channel.
///
/// The parameters `name` and `onMessageReceived` must not be null.
JavaScriptChannel({
required this.name,
required this.onMessageReceived,
}) : assert(name != null),
assert(onMessageReceived != null),
assert(_validChannelNames.hasMatch(name));

/// The channel's name.
///
/// The name must start with a letter or underscore(_), followed by any
/// combination of alphabetic characters plus digits.
///
/// Note that any JavaScript existing `window` property with this name will be
/// overriden.
final String name;

/// A callback that's invoked when a message is received through the channel.
final JavaScriptMessageHandler onMessageReceived;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// 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:flutter/foundation.dart';

/// A message that was sent by JavaScript code running in a [WebView].
///
/// Platform specific implementations can add additional fields by extending
/// this class and providing a factory method that takes the
/// [JavaScriptMessage] as a parameter.
///
/// {@tool sample}
/// This example demonstrates how to extend the [JavaScriptMessage] to
/// provide additional platform specific parameters.
///
/// When extending [JavaScriptMessage] additional parameters should always
/// accept `null` or have a default value to prevent breaking changes.
///
/// ```dart
/// @immutable
/// class WKWebViewScriptMessage extends JavaScriptMessage {
/// WKWebViewScriptMessage._(
/// JavaScriptMessage javaScriptMessage,
/// this.extraData,
/// ) : super(javaScriptMessage.message);
///
/// factory WKWebViewScriptMessage.fromJavaScripMessage(
/// JavaScriptMessage javaScripMessage, {
/// String? extraData,
/// }) {
/// return WKWebViewScriptMessage._(
/// javaScriptMessage,
/// extraData: extraData,
/// );
/// }
///
/// final String? extraData;
/// }
/// ```
/// {@end-tool}
@immutable
class JavaScriptMessage {
/// Creates a new JavaScript message object.
const JavaScriptMessage({
required this.message,
});

/// The contents of the message that was sent by the JavaScript code.
final String message;
}
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,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// 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 '../webview_controller_delegate.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].
///
/// Platform specific implementations can add additional fields by extending
/// this class.
///
/// {@tool sample}
/// This example demonstrates how to extend the [LoadRequestParams] to
/// provide additional platform specific parameters.
///
/// When extending [LoadRequestParams] additional parameters should always
/// accept `null` or have a default value to prevent breaking changes.
///
/// ```dart
/// class AndroidLoadRequestParams extends LoadRequestParams {
/// AndroidLoadRequestParams._({
/// required LoadRequestParams params,
/// this.historyUrl,
/// }) : super(
/// uri: params.uri,
/// method: params.method,
/// body: params.body,
/// headers: params.headers,
/// );
///
/// factory AndroidLoadRequestParams.fromLoadRequestParams(
/// LoadRequestParams params, {
/// Uri? historyUrl,
/// }) {
/// return AndroidLoadRequestParams._(params, historyUrl: historyUrl);
/// }
///
/// final Uri? historyUrl;
/// }
/// ```
/// {@end-tool}
@immutable
class LoadRequestParams {
/// Used by the platform implementation to create a new [LoadRequestParams].
const LoadRequestParams({
required this.uri,
required this.method,
required this.headers,
this.body,
});

/// 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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// 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:flutter/material.dart';

/// Object specifying creation parameters for creating a [NavigationCallbackDelegate].
///
/// Platform specific implementations can add additional fields by extending
/// this class.
///
/// {@tool sample}
/// This example demonstrates how to extend the [NavigationCallbackCreationParams] to
/// provide additional platform specific parameters.
///
/// When extending [NavigationCallbackCreationParams] additional
/// parameters should always accept `null` or have a default value to prevent
/// breaking changes.
///
/// ```dart
/// class AndroidNavigationCallbackCreationParams extends NavigationCallbackCreationParams {
/// AndroidNavigationCallbackCreationParams._(
/// // This parameter prevents breaking changes later.
/// // ignore: avoid_unused_constructor_parameters
/// NavigationCallbackCreationParams params, {
/// this.filter,
/// }) : super();
///
/// factory AndroidNavigationCallbackCreationParams.fromNavigationCallbackCreationParams(
/// NavigationCallbackCreationParams params, {
/// String? filter,
/// }) {
/// return AndroidNavigationCallbackCreationParams._(params, filter: filter);
/// }
///
/// final String? filter;
/// }
/// ```
/// {@end-tool}
@immutable
class NavigationCallbackCreationParams {
Comment thread
mvanbeusekom marked this conversation as resolved.
Outdated
/// Used by the platform implementation to create a new [NavigationCallbackDelegate].
const NavigationCallbackCreationParams();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// 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_channel.dart';
export 'javascript_message.dart';
export 'javascript_mode.dart';
export 'load_request_params.dart';
export 'navigation_callback_creation_params.dart';
export 'web_resource_error.dart';
export 'webview_controller_creation_params.dart';
export 'webview_cookie.dart';
export 'webview_cookie_manager_creation_params.dart';
export 'webview_widget_creation_params.dart';
Loading