Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
49 changes: 48 additions & 1 deletion packages/webview_flutter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,50 @@
## 3.0.7
* upgraded android gradle library version to 8.4.2

## 3.0.6
* enable mixed content in Android webview

## 3.0.5
* fix poor response performance for fast clicks in iOS webview

## 3.0.4
* Add navigation prevention logic when url is loading app

## 3.0.3
* Fix android issues with creating platform views

## 3.0.2
* fix conflict with original webview_flutter

## 3.0.1
* Add Javascript alert and confirm handlers on Android and iOS

## 3.0.0+5

* fix error in setAcceptThirdPartyCookies in ios

## 3.0.0+4

* Add setAcceptThirdPartyCookies functionality in ios

## 3.0.0+3

* fixed podspec name for ios

## 3.0.0+2

* fixed support for ios

## 3.0.0+1

* fixed methodCall argument error in setAcceptThirdPartyCookies

## 3.0.0

* Changed package name to iamport_webview_flutter
* Added support to allow third party cookies on Android
* Added support to load data with base URL on Android

## 2.0.4

* Fix a bug where `allowsInlineMediaPlayback` is not respected on iOS.
Expand All @@ -10,7 +57,7 @@ the wrong side of the screen.
## 2.0.2

* Fixes bug where text fields are hidden behind the keyboard
when hybrid composition is used [flutter/issues/75667](https://github.com/flutter/flutter/issues/75667).
when hybrid composition is used [flutter/issues/75667](https://github.com/flutter/flutter/issues/7566 7).

## 2.0.1

Expand Down
17 changes: 10 additions & 7 deletions packages/webview_flutter/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
group 'io.flutter.plugins.webviewflutter'
version '1.0-SNAPSHOT'

buildscript {
repositories {
google()
jcenter()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
classpath 'com.android.tools.build:gradle:8.4.2'
}
}

rootProject.allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}

apply plugin: 'com.android.library'

android {
compileSdkVersion 29
compileSdk 34

namespace = 'kr.iamport.iamport_webview_flutter'

defaultConfig {
minSdkVersion 16
Expand All @@ -33,7 +34,9 @@ android {
}

dependencies {
implementation 'androidx.annotation:annotation:1.0.0'
implementation 'androidx.webkit:webkit:1.0.0'
implementation 'androidx.annotation:annotation:1.8.0'
implementation 'androidx.webkit:webkit:1.11.0'
}

buildToolsVersion = '34.0.0'
}
15 changes: 15 additions & 0 deletions packages/webview_flutter/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
#
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx1024m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
#
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
#Tue May 11 19:59:30 KST 2021
android.useAndroidX=true
android.enableJetifier=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Wed Jun 12 15:47:58 KST 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion packages/webview_flutter/android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
rootProject.name = 'webview_flutter'
include ':iamport_webview_flutter'
2 changes: 0 additions & 2 deletions packages/webview_flutter/android/src/main/AndroidManifest.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package io.flutter.plugins.webviewflutter;
package kr.iamport.iamport_webview_flutter;

import static android.hardware.display.DisplayManager.DisplayListener;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package io.flutter.plugins.webviewflutter;
package kr.iamport.iamport_webview_flutter;

import android.os.Build;
import android.os.Build.VERSION_CODES;
Expand All @@ -18,7 +18,7 @@ class FlutterCookieManager implements MethodCallHandler {
private final MethodChannel methodChannel;

FlutterCookieManager(BinaryMessenger messenger) {
methodChannel = new MethodChannel(messenger, "plugins.flutter.io/cookie_manager");
methodChannel = new MethodChannel(messenger, "plugins.flutter.io/imp_cookie_manager");
methodChannel.setMethodCallHandler(this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,25 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package io.flutter.plugins.webviewflutter;
package kr.iamport.iamport_webview_flutter;

import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.hardware.display.DisplayManager;
import android.os.Build;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.CookieManager;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebStorage;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.webkit.JsResult;
import androidx.annotation.NonNull;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.MethodCall;
Expand Down Expand Up @@ -77,6 +82,49 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) {
public void onProgressChanged(WebView view, int progress) {
flutterWebViewClient.onLoadingProgress(progress);
}

@Override
public boolean onJsAlert(WebView view, String url, String message, final JsResult result) {
new AlertDialog.Builder(view.getContext())
.setTitle(url + "에 삽입된 내용")
.setMessage(message)
.setPositiveButton(android.R.string.ok,
new AlertDialog.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
result.confirm();
}
})
.setCancelable(false)
.create()
.show();

return true;
}

@Override
public boolean onJsConfirm(WebView view, String url, String message, final JsResult result) {
new AlertDialog.Builder(view.getContext())
.setTitle(url + "에 삽입된 내용")
.setMessage(message)
.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
result.confirm();
}
})
.setNegativeButton(android.R.string.cancel,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
result.cancel();
}
})
.setCancelable(false)
.create()
.show();

return true;
}
}

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
Expand Down Expand Up @@ -110,7 +158,11 @@ public void onProgressChanged(WebView view, int progress) {
webView.getSettings().setSupportMultipleWindows(true);
webView.setWebChromeClient(new FlutterWebChromeClient());

methodChannel = new MethodChannel(messenger, "plugins.flutter.io/webview_" + id);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
}

methodChannel = new MethodChannel(messenger, "plugins.flutter.io/imp_webview_" + id);
methodChannel.setMethodCallHandler(this);

flutterWebViewClient = new FlutterWebViewClient(methodChannel);
Expand Down Expand Up @@ -193,6 +245,9 @@ public void onMethodCall(MethodCall methodCall, Result result) {
case "loadUrl":
loadUrl(methodCall, result);
break;
case "loadDataWithBaseURL":
loadDataWithBaseURL(methodCall, result);
break;
case "updateSettings":
updateSettings(methodCall, result);
break;
Expand Down Expand Up @@ -226,6 +281,9 @@ public void onMethodCall(MethodCall methodCall, Result result) {
case "clearCache":
clearCache(result);
break;
case "setAcceptThirdPartyCookies":
setAcceptThirdPartyCookies(methodCall, result);
break;
case "getTitle":
getTitle(result);
break;
Expand Down Expand Up @@ -258,6 +316,21 @@ private void loadUrl(MethodCall methodCall, Result result) {
result.success(null);
}

@SuppressWarnings("unchecked")
private void loadDataWithBaseURL(MethodCall methodCall, Result result) {
Map<String, Object> request = (Map<String, Object>) methodCall.arguments;
String baseUrl = (String) request.get("url");
String data = (String) request.get("data");
if(data == null) {
data = "";
}
String mimeType = (String) request.get("mimeType");
String encoding = (String) request.get("encoding");
String failUrl = (String) request.get("failUrl");
webView.loadDataWithBaseURL(baseUrl, data, mimeType, encoding, failUrl);
result.success(null);
}

private void canGoBack(Result result) {
result.success(webView.canGoBack());
}
Expand Down Expand Up @@ -436,6 +509,15 @@ private void updateUserAgent(String userAgent) {
webView.getSettings().setUserAgentString(userAgent);
}

private void setAcceptThirdPartyCookies(MethodCall methodCall, Result result) {
// Map<String, Object> request = (Map<String, Object>) methodCall.arguments;
boolean accept = (boolean) methodCall.arguments;
// boolean accept = (boolean) request.get("accept");
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
CookieManager.getInstance().setAcceptThirdPartyCookies(this.webView, accept);
result.success(0);
}

@Override
public void dispose() {
methodChannel.setMethodCallHandler(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package io.flutter.plugins.webviewflutter;
package kr.iamport.iamport_webview_flutter;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build;
import android.util.Log;
import android.view.KeyEvent;
Expand All @@ -18,7 +19,10 @@
import androidx.webkit.WebResourceErrorCompat;
import androidx.webkit.WebViewClientCompat;
import io.flutter.plugin.common.MethodChannel;

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

Expand Down Expand Up @@ -95,9 +99,23 @@ boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
// we just return false to allow the navigation.
//
// For more details see: https://github.com/flutter/flutter/issues/25329#issuecomment-464863209
if(isAppUrl(request.getUrl().toString())) {
return true;
}
return request.isForMainFrame();
}

boolean isAppUrl(String uri) {
try {
String scheme = Uri.parse(uri).getScheme();
List<String> schemeList = Arrays.asList("http", "https", "about", "data", "");

return !schemeList.contains(scheme);
} catch (Exception ignored) {
return false;
}
}

boolean shouldOverrideUrlLoading(WebView view, String url) {
if (!hasNavigationDelegate) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package io.flutter.plugins.webviewflutter;
package kr.iamport.iamport_webview_flutter;

import static android.content.Context.INPUT_METHOD_SERVICE;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package io.flutter.plugins.webviewflutter;
package kr.iamport.iamport_webview_flutter;

import android.os.Handler;
import android.os.Looper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package io.flutter.plugins.webviewflutter;
package kr.iamport.iamport_webview_flutter;

import android.os.Handler;
import android.os.IBinder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package io.flutter.plugins.webviewflutter;
package kr.iamport.iamport_webview_flutter;

import android.content.Context;
import android.view.View;
Expand Down
Loading