Skip to content

Commit

Permalink
Merge branch 'v6.2.0-beta.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
pichillilorenzo committed Dec 2, 2024
2 parents 1e7091c + 1ba712b commit 0aaf7a0
Show file tree
Hide file tree
Showing 27 changed files with 860 additions and 61 deletions.
4 changes: 3 additions & 1 deletion flutter_inappwebview/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@

#### Platform Interface
- Added `saveState`, `restoreState` methods to `PlatformInAppWebViewController` class
- Added `useOnAjaxReadyStateChange`, `useOnAjaxProgress` properties to `InAppWebViewSettings`
- Added `useOnAjaxReadyStateChange`, `useOnAjaxProgress`, `useOnShowFileChooser` properties to `InAppWebViewSettings`
- Added `onShowFileChooser` WebView events

#### Android Platform
- Implemented `saveState`, `restoreState` InAppWebViewController methods
- Implemented `onShowFileChooser` WebView event
- Merged "Android: implemented PlatformPrintJobController.onComplete" [#2216](https://github.com/pichillilorenzo/flutter_inappwebview/pull/2216) (thanks to [Doflatango](https://github.com/Doflatango))

#### macOS and iOS Platforms
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,4 +609,9 @@ class InAppBrowser implements PlatformInAppBrowserEvents {

@override
void onAcceleratorKeyPressed(AcceleratorKeyPressedDetail detail) {}

@override
FutureOr<ShowFileChooserResponse?> onShowFileChooser(ShowFileChooserRequest request) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ class HeadlessInAppWebView {
)? onMicrophoneCaptureStateChanged,
void Function(InAppWebViewController controller, Size oldContentSize, Size newContentSize)? onContentSizeChanged,
void Function(InAppWebViewController controller, ProcessFailedDetail detail)? onProcessFailed,
void Function(InAppWebViewController controller, AcceleratorKeyPressedDetail detail)? onAcceleratorKeyPressed})
void Function(InAppWebViewController controller, AcceleratorKeyPressedDetail detail)? onAcceleratorKeyPressed,
FutureOr<ShowFileChooserResponse?> Function(InAppWebViewController controller, ShowFileChooserRequest request)? onShowFileChooser})
: this.fromPlatformCreationParams(
params: PlatformHeadlessInAppWebViewCreationParams(
controllerFromPlatform: (PlatformInAppWebViewController controller) =>
Expand Down Expand Up @@ -521,6 +522,10 @@ class HeadlessInAppWebView {
? (controller, detail) =>
onAcceleratorKeyPressed.call(controller, detail)
: null,
onShowFileChooser: onShowFileChooser != null
? (controller, request) =>
onShowFileChooser.call(controller, request)
: null,
));

///{@macro flutter_inappwebview_platform_interface.PlatformHeadlessInAppWebView.run}
Expand Down
18 changes: 11 additions & 7 deletions flutter_inappwebview/lib/src/in_app_webview/in_app_webview.dart
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import 'dart:async';
import 'dart:collection';
import 'dart:typed_data';

import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter_inappwebview_platform_interface/flutter_inappwebview_platform_interface.dart';
import '../webview_environment/webview_environment.dart';
import 'headless_in_app_webview.dart';
import 'in_app_webview_controller.dart';

import '../find_interaction/find_interaction_controller.dart';
import '../pull_to_refresh/main.dart';
import '../pull_to_refresh/pull_to_refresh_controller.dart';
import '../webview_environment/webview_environment.dart';
import 'headless_in_app_webview.dart';
import 'in_app_webview_controller.dart';

///{@macro flutter_inappwebview_platform_interface.PlatformInAppWebViewWidget}
class InAppWebView extends StatefulWidget {
Expand Down Expand Up @@ -167,7 +166,8 @@ class InAppWebView extends StatefulWidget {
)? onMicrophoneCaptureStateChanged,
void Function(InAppWebViewController controller, Size oldContentSize, Size newContentSize)? onContentSizeChanged,
void Function(InAppWebViewController controller, ProcessFailedDetail detail)? onProcessFailed,
void Function(InAppWebViewController controller, AcceleratorKeyPressedDetail detail)? onAcceleratorKeyPressed})
void Function(InAppWebViewController controller, AcceleratorKeyPressedDetail detail)? onAcceleratorKeyPressed,
FutureOr<ShowFileChooserResponse?> Function(InAppWebViewController controller, ShowFileChooserRequest request)? onShowFileChooser})
: this.fromPlatformCreationParams(
key: key,
params: PlatformInAppWebViewWidgetCreationParams(
Expand Down Expand Up @@ -542,6 +542,10 @@ class InAppWebView extends StatefulWidget {
? (controller, detail) =>
onAcceleratorKeyPressed.call(controller, detail)
: null,
onShowFileChooser: onShowFileChooser != null
? (controller, request) =>
onShowFileChooser.call(controller, request)
: null,
gestureRecognizers: gestureRecognizers,
headlessWebView: headlessWebView?.platform,
preventGestureDelay: preventGestureDelay,
Expand Down
1 change: 1 addition & 0 deletions flutter_inappwebview_android/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- Updated flutter_inappwebview_platform_interface version to ^1.4.0-beta.3
- Implemented `saveState`, `restoreState` InAppWebViewController methods
- Implemented `onShowFileChooser` WebView event
- Merged "Android: implemented PlatformPrintJobController.onComplete" [#2216](https://github.com/pichillilorenzo/flutter_inappwebview/pull/2216) (thanks to [Doflatango](https://github.com/Doflatango))
- Fixed "When useShouldInterceptAjaxRequest is true, some ajax requests doesn't work" [#2197](https://github.com/pichillilorenzo/flutter_inappwebview/issues/2197)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
package com.pichillilorenzo.flutter_inappwebview_android.types;

import android.annotation.TargetApi;
import android.os.Build;
import android.webkit.WebChromeClient;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

public class ShowFileChooserRequest {
private int mode;
@NonNull
private List<String> acceptTypes;
private boolean isCaptureEnabled;
@Nullable
private String title;
@Nullable
private String filenameHint;

public ShowFileChooserRequest(int mode, @NonNull List<String> acceptTypes, boolean isCaptureEnabled, @Nullable String title, @Nullable String filenameHint) {
this.mode = mode;
this.acceptTypes = acceptTypes;
this.isCaptureEnabled = isCaptureEnabled;
this.title = title;
this.filenameHint = filenameHint;
}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static ShowFileChooserRequest fromFileChooserParams(WebChromeClient.FileChooserParams fileChooserParams) {
int mode = fileChooserParams.getMode();
List<String> acceptTypes = Arrays.asList(fileChooserParams.getAcceptTypes());
boolean isCaptureEnabled = fileChooserParams.isCaptureEnabled();
String title = fileChooserParams.getTitle() != null ? fileChooserParams.getTitle().toString() : null;
String filenameHint = fileChooserParams.getFilenameHint();
return new ShowFileChooserRequest(mode, acceptTypes, isCaptureEnabled, title, filenameHint);
}

@Nullable
public static ShowFileChooserRequest fromMap(@Nullable Map<String, Object> map) {
if (map == null) {
return null;
}
int mode = (int) map.get("mode");
List<String> acceptTypes = (List<String>) map.get("acceptTypes");
boolean isCaptureEnabled = (boolean) map.get("isCaptureEnabled");
String title = (String) map.get("title");
String filenameHint = (String) map.get("filenameHint");
return new ShowFileChooserRequest(mode, acceptTypes, isCaptureEnabled, title, filenameHint);
}

public Map<String, Object> toMap() {
Map<String, Object> showFileChooserRequestMap = new HashMap<>();
showFileChooserRequestMap.put("mode", mode);
showFileChooserRequestMap.put("acceptTypes", acceptTypes);
showFileChooserRequestMap.put("isCaptureEnabled", isCaptureEnabled);
showFileChooserRequestMap.put("title", title);
showFileChooserRequestMap.put("filenameHint", filenameHint);
return showFileChooserRequestMap;
}


public int getMode() {
return mode;
}

public void setMode(int mode) {
this.mode = mode;
}

public @NonNull List<String> getAcceptTypes() {
return acceptTypes;
}

public void setAcceptTypes(@NonNull List<String> acceptTypes) {
this.acceptTypes = acceptTypes;
}

public boolean isCaptureEnabled() {
return isCaptureEnabled;
}

public void setCaptureEnabled(boolean captureEnabled) {
isCaptureEnabled = captureEnabled;
}

@Nullable
public String getTitle() {
return title;
}

public void setTitle(@Nullable String title) {
this.title = title;
}

@Nullable
public String getFilenameHint() {
return filenameHint;
}

public void setFilenameHint(@Nullable String filenameHint) {
this.filenameHint = filenameHint;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

ShowFileChooserRequest that = (ShowFileChooserRequest) o;
return mode == that.mode && isCaptureEnabled == that.isCaptureEnabled && acceptTypes.equals(that.acceptTypes) && Objects.equals(title, that.title) && Objects.equals(filenameHint, that.filenameHint);
}

@Override
public int hashCode() {
int result = mode;
result = 31 * result + acceptTypes.hashCode();
result = 31 * result + Boolean.hashCode(isCaptureEnabled);
result = 31 * result + Objects.hashCode(title);
result = 31 * result + Objects.hashCode(filenameHint);
return result;
}

@NonNull
@Override
public String toString() {
return "ShowFileChooserRequest{" +
"mode=" + mode +
", acceptTypes=" + acceptTypes +
", isCaptureEnabled=" + isCaptureEnabled +
", title='" + title + '\'' +
", filenameHint='" + filenameHint + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.pichillilorenzo.flutter_inappwebview_android.types;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.List;
import java.util.Map;
import java.util.Objects;

public class ShowFileChooserResponse {
private boolean handledByClient;
@Nullable
private List<String> filePaths;

public ShowFileChooserResponse(boolean handledByClient, @Nullable List<String> filePaths) {
this.handledByClient = handledByClient;
this.filePaths = filePaths;
}

@Nullable
public static ShowFileChooserResponse fromMap(@Nullable Map<String, Object> map) {
if (map == null) {
return null;
}
boolean handledByClient = (boolean) map.get("handledByClient");
List<String> filePaths = (List<String>) map.get("filePaths");
return new ShowFileChooserResponse(handledByClient, filePaths);
}

public boolean isHandledByClient() {
return handledByClient;
}

public void setHandledByClient(boolean handledByClient) {
this.handledByClient = handledByClient;
}

@Nullable
public List<String> getFilePaths() {
return filePaths;
}

public void setFilePaths(@Nullable List<String> filePaths) {
this.filePaths = filePaths;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

ShowFileChooserResponse that = (ShowFileChooserResponse) o;
return handledByClient == that.handledByClient && Objects.equals(filePaths, that.filePaths);
}

@Override
public int hashCode() {
int result = Boolean.hashCode(handledByClient);
result = 31 * result + Objects.hashCode(filePaths);
return result;
}

@NonNull
@Override
public String toString() {
return "ShowFileChooserResponse{" +
"handledByClient=" + handledByClient +
", filePaths=" + filePaths +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
import com.pichillilorenzo.flutter_inappwebview_android.types.SafeBrowsingResponse;
import com.pichillilorenzo.flutter_inappwebview_android.types.ServerTrustAuthResponse;
import com.pichillilorenzo.flutter_inappwebview_android.types.ServerTrustChallenge;
import com.pichillilorenzo.flutter_inappwebview_android.types.ShowFileChooserRequest;
import com.pichillilorenzo.flutter_inappwebview_android.types.ShowFileChooserResponse;
import com.pichillilorenzo.flutter_inappwebview_android.types.SslCertificateExt;
import com.pichillilorenzo.flutter_inappwebview_android.types.SyncBaseCallbackResultImpl;
import com.pichillilorenzo.flutter_inappwebview_android.types.URLRequest;
Expand Down Expand Up @@ -1360,6 +1362,23 @@ public void onRequestFocus() {
channel.invokeMethod("onRequestFocus", obj);
}

public static class ShowFileChooserCallback extends BaseCallbackResultImpl<ShowFileChooserResponse> {
@Nullable
@Override
public ShowFileChooserResponse decodeResult(@Nullable Object obj) {
return ShowFileChooserResponse.fromMap((Map<String, Object>) obj);
}
}

public void onShowFileChooser(ShowFileChooserRequest request, @NonNull ShowFileChooserCallback callback) {
MethodChannel channel = getChannel();
if (channel == null) {
callback.defaultBehaviour(null);
return;
}
channel.invokeMethod("onShowFileChooser", request.toMap(), callback);
}

@Override
public void dispose() {
super.dispose();
Expand Down
Loading

0 comments on commit 0aaf7a0

Please sign in to comment.