Removed all the dependencies: uuid, device_info, intl, and mime

This commit is contained in:
Lorenzo Pichilli 2021-03-01 03:21:07 +01:00
parent 87e617a523
commit 74550d1186
31 changed files with 1345 additions and 130 deletions

View File

@ -1,7 +1,6 @@
<component name="libraryTable">
<library name="Flutter Plugins">
<CLASSES>
<root url="file://$USER_HOME$/flutter/.pub-cache/hosted/pub.dartlang.org/device_info-2.0.0-nullsafety.2" />
<root url="file://$PROJECT_DIR$" />
</CLASSES>
<JAVADOC />

View File

@ -1,6 +1,7 @@
## 5.0.5-nullsafety.1
- Updated Android `WebChromeClient.getDefaultVideoPoster`
- Removed all the dependencies: `uuid`, `device_info`, `intl`, and `mime`
## 5.0.4-nullsafety.1

View File

@ -24,6 +24,7 @@ public class InAppWebViewFlutterPlugin implements FlutterPlugin, ActivityAware {
protected static final String LOG_TAG = "InAppWebViewFlutterPL";
public static PlatformUtil platformUtil;
public static InAppBrowserManager inAppBrowserManager;
public static HeadlessInAppWebViewManager headlessInAppWebViewManager;
public static ChromeSafariBrowserManager chromeSafariBrowserManager;
@ -70,6 +71,7 @@ public class InAppWebViewFlutterPlugin implements FlutterPlugin, ActivityAware {
platformViewRegistry.registerViewFactory(
"com.pichillilorenzo/flutter_inappwebview", new FlutterWebViewFactory(messenger, flutterView));
platformUtil = new PlatformUtil(messenger);
inAppWebViewStatic = new InAppWebViewStatic(messenger);
myCookieManager = new MyCookieManager(messenger);
myWebStorage = new MyWebStorage(messenger);
@ -84,6 +86,10 @@ public class InAppWebViewFlutterPlugin implements FlutterPlugin, ActivityAware {
@Override
public void onDetachedFromEngine(FlutterPluginBinding binding) {
if (platformUtil != null) {
platformUtil.dispose();
platformUtil = null;
}
if (inAppBrowserManager != null) {
inAppBrowserManager.dispose();
inAppBrowserManager = null;

View File

@ -306,7 +306,7 @@ public class MyCookieManager implements MethodChannel.MethodCallHandler {
}
public static String getCookieExpirationDate(Long timestamp) {
final SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy hh:mm:ss z", Locale.US);
final SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy hh:mm:ss z", Locale.US);
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
return sdf.format(new Date(timestamp));
}

View File

@ -0,0 +1,67 @@
package com.pichillilorenzo.flutter_inappwebview;
import android.os.Build;
import androidx.annotation.Nullable;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
public class PlatformUtil implements MethodChannel.MethodCallHandler {
public MethodChannel channel;
protected static final String LOG_TAG = "PlatformUtil";
public PlatformUtil(BinaryMessenger messenger) {
channel = new MethodChannel(messenger, "com.pichillilorenzo/flutter_inappwebview_platformutil");
channel.setMethodCallHandler(this);
}
@Override
public void onMethodCall(MethodCall call, final MethodChannel.Result result) {
switch (call.method) {
case "getSystemVersion":
result.success(String.valueOf(Build.VERSION.SDK_INT));
break;
case "formatDate":
long date = (long) call.argument("date");
String format = (String) call.argument("format");
Locale locale = PlatformUtil.getLocaleFromString((String) call.argument("locale"));
String timezone = (String) call.argument("timezone");
if (timezone == null) {
timezone = "UTC";
}
result.success(PlatformUtil.formatDate(date, format, locale, TimeZone.getTimeZone(timezone)));
break;
default:
result.notImplemented();
}
}
public static Locale getLocaleFromString(@Nullable String locale) {
if (locale == null) {
return Locale.US;
}
String[] localeSplitted = locale.split("_");
String language = localeSplitted[0];
String country = localeSplitted.length > 1 ? localeSplitted[1] : "";
String variant = localeSplitted.length > 2 ? localeSplitted[2] : "";
return new Locale(language, country, variant);
}
public static String formatDate(long date, String format, Locale locale, TimeZone timezone) {
final SimpleDateFormat sdf = new SimpleDateFormat(format, locale);
sdf.setTimeZone(timezone);
return sdf.format(new Date(date));
}
public void dispose() {
channel.setMethodCallHandler(null);
}
}

View File

@ -15,7 +15,7 @@ import io.flutter.plugin.common.MethodChannel;
public class ActionBroadcastReceiver extends BroadcastReceiver {
protected static final String LOG_TAG = "ActionBroadcastReceiver";
public static final String KEY_ACTION_ID = "com.pichillilorenzo.flutter_inappwebview.ChromeCustomTabs.ACTION_ID";
public static final String KEY_ACTION_UUID = "com.pichillilorenzo.flutter_inappwebview.ChromeCustomTabs.ACTION_UUID";
public static final String KEY_ACTION_VIEW_ID = "com.pichillilorenzo.flutter_inappwebview.ChromeCustomTabs.ACTION_VIEW_ID";
public static final String KEY_URL_TITLE = "android.intent.extra.SUBJECT";
@Override
@ -23,11 +23,11 @@ public class ActionBroadcastReceiver extends BroadcastReceiver {
String url = intent.getDataString();
if (url != null) {
Bundle b = intent.getExtras();
String uuid = b.getString(KEY_ACTION_UUID);
String viewId = b.getString(KEY_ACTION_VIEW_ID);
int id = b.getInt(KEY_ACTION_ID);
String title = b.getString(KEY_URL_TITLE);
MethodChannel channel = new MethodChannel(Shared.messenger, "com.pichillilorenzo/flutter_chromesafaribrowser_" + uuid);
MethodChannel channel = new MethodChannel(Shared.messenger, "com.pichillilorenzo/flutter_chromesafaribrowser_" + viewId);
Map<String, Object> obj = new HashMap<>();
obj.put("url", url);
obj.put("title", title);

View File

@ -26,7 +26,7 @@ public class ChromeCustomTabsActivity extends Activity implements MethodChannel.
protected static final String LOG_TAG = "CustomTabsActivity";
public MethodChannel channel;
public String uuid;
public String id;
public CustomTabsIntent.Builder builder;
public ChromeCustomTabsOptions options;
public CustomTabActivityHelper customTabActivityHelper;
@ -43,9 +43,9 @@ public class ChromeCustomTabsActivity extends Activity implements MethodChannel.
Bundle b = getIntent().getExtras();
assert b != null;
uuid = b.getString("uuid");
id = b.getString("id");
channel = new MethodChannel(Shared.messenger, "com.pichillilorenzo/flutter_chromesafaribrowser_" + uuid);
channel = new MethodChannel(Shared.messenger, "com.pichillilorenzo/flutter_chromesafaribrowser_" + id);
channel.setMethodCallHandler(this);
final String url = b.getString("url");
@ -201,7 +201,7 @@ public class ChromeCustomTabsActivity extends Activity implements MethodChannel.
Bundle extras = new Bundle();
extras.putInt(ActionBroadcastReceiver.KEY_ACTION_ID, actionSourceId);
extras.putString(ActionBroadcastReceiver.KEY_ACTION_UUID, uuid);
extras.putString(ActionBroadcastReceiver.KEY_ACTION_VIEW_ID, id);
actionIntent.putExtras(extras);
return PendingIntent.getBroadcast(

View File

@ -28,7 +28,7 @@ public class ChromeSafariBrowserManager implements MethodChannel.MethodCallHandl
@Override
public void onMethodCall(final MethodCall call, final MethodChannel.Result result) {
final Activity activity = Shared.activity;
final String uuid = (String) call.argument("uuid");
final String id = (String) call.argument("id");
switch (call.method) {
case "open":
@ -36,7 +36,7 @@ public class ChromeSafariBrowserManager implements MethodChannel.MethodCallHandl
String url = (String) call.argument("url");
HashMap<String, Object> options = (HashMap<String, Object>) call.argument("options");
List<HashMap<String, Object>> menuItemList = (List<HashMap<String, Object>>) call.argument("menuItemList");
open(activity, uuid, url, options, menuItemList, result);
open(activity, id, url, options, menuItemList, result);
}
break;
case "isAvailable":
@ -47,7 +47,7 @@ public class ChromeSafariBrowserManager implements MethodChannel.MethodCallHandl
}
}
public void open(Activity activity, String uuid, String url, HashMap<String, Object> options,
public void open(Activity activity, String id, String url, HashMap<String, Object> options,
List<HashMap<String, Object>> menuItemList, MethodChannel.Result result) {
Intent intent = null;
@ -55,7 +55,7 @@ public class ChromeSafariBrowserManager implements MethodChannel.MethodCallHandl
extras.putString("fromActivity", activity.getClass().getName());
extras.putString("url", url);
extras.putBoolean("isData", false);
extras.putString("uuid", uuid);
extras.putString("id", id);
extras.putSerializable("options", options);
extras.putSerializable("menuItemList", (Serializable) menuItemList);

View File

@ -46,7 +46,7 @@ public class InAppBrowserActivity extends AppCompatActivity implements InAppBrow
static final String LOG_TAG = "InAppBrowserActivity";
public MethodChannel channel;
public Integer windowId;
public String uuid;
public String id;
public InAppWebView webView;
public ActionBar actionBar;
public Menu menu;
@ -67,10 +67,10 @@ public class InAppBrowserActivity extends AppCompatActivity implements InAppBrow
}
Bundle b = getIntent().getExtras();
uuid = b.getString("uuid");
id = b.getString("id");
windowId = b.getInt("windowId");
channel = new MethodChannel(Shared.messenger, "com.pichillilorenzo/flutter_inappbrowser_" + uuid);
channel = new MethodChannel(Shared.messenger, "com.pichillilorenzo/flutter_inappbrowser_" + id);
setContentView(R.layout.activity_web_view);

View File

@ -64,31 +64,31 @@ public class InAppBrowserManager implements MethodChannel.MethodCallHandler {
switch (call.method) {
case "openUrlRequest":
{
String uuid = (String) call.argument("uuid");
String id = (String) call.argument("id");
Map<String, Object> urlRequest = (Map<String, Object>) call.argument("urlRequest");
Map<String, Object> options = (Map<String, Object>) call.argument("options");
Map<String, Object> contextMenu = (Map<String, Object>) call.argument("contextMenu");
Integer windowId = (Integer) call.argument("windowId");
List<Map<String, Object>> initialUserScripts = (List<Map<String, Object>>) call.argument("initialUserScripts");
openUrlRequest(activity, uuid, urlRequest, options, contextMenu, windowId, initialUserScripts);
openUrlRequest(activity, id, urlRequest, options, contextMenu, windowId, initialUserScripts);
}
result.success(true);
break;
case "openFile":
{
String uuid = (String) call.argument("uuid");
String id = (String) call.argument("id");
String assetFilePath = (String) call.argument("assetFilePath");
Map<String, Object> options = (Map<String, Object>) call.argument("options");
Map<String, Object> contextMenu = (Map<String, Object>) call.argument("contextMenu");
Integer windowId = (Integer) call.argument("windowId");
List<Map<String, Object>> initialUserScripts = (List<Map<String, Object>>) call.argument("initialUserScripts");
openFile(activity, uuid, assetFilePath, options, contextMenu, windowId, initialUserScripts);
openFile(activity, id, assetFilePath, options, contextMenu, windowId, initialUserScripts);
}
result.success(true);
break;
case "openData":
{
String uuid = (String) call.argument("uuid");
String id = (String) call.argument("id");
Map<String, Object> options = (Map<String, Object>) call.argument("options");
String data = (String) call.argument("data");
String mimeType = (String) call.argument("mimeType");
@ -98,7 +98,7 @@ public class InAppBrowserManager implements MethodChannel.MethodCallHandler {
Map<String, Object> contextMenu = (Map<String, Object>) call.argument("contextMenu");
Integer windowId = (Integer) call.argument("windowId");
List<Map<String, Object>> initialUserScripts = (List<Map<String, Object>>) call.argument("initialUserScripts");
openData(activity, uuid, options, data, mimeType, encoding, baseUrl, historyUrl, contextMenu, windowId, initialUserScripts);
openData(activity, id, options, data, mimeType, encoding, baseUrl, historyUrl, contextMenu, windowId, initialUserScripts);
}
result.success(true);
break;
@ -189,12 +189,12 @@ public class InAppBrowserManager implements MethodChannel.MethodCallHandler {
}
}
public void openUrlRequest(Activity activity, String uuid, Map<String, Object> urlRequest, Map<String, Object> options,
public void openUrlRequest(Activity activity, String id, Map<String, Object> urlRequest, Map<String, Object> options,
Map<String, Object> contextMenu, Integer windowId, List<Map<String, Object>> initialUserScripts) {
Bundle extras = new Bundle();
extras.putString("fromActivity", activity.getClass().getName());
extras.putSerializable("initialUrlRequest", (Serializable) urlRequest);
extras.putString("uuid", uuid);
extras.putString("id", id);
extras.putSerializable("options", (Serializable) options);
extras.putSerializable("contextMenu", (Serializable) contextMenu);
extras.putInt("windowId", windowId != null ? windowId : -1);
@ -202,12 +202,12 @@ public class InAppBrowserManager implements MethodChannel.MethodCallHandler {
startInAppBrowserActivity(activity, extras);
}
public void openFile(Activity activity, String uuid, String assetFilePath, Map<String, Object> options,
public void openFile(Activity activity, String id, String assetFilePath, Map<String, Object> options,
Map<String, Object> contextMenu, Integer windowId, List<Map<String, Object>> initialUserScripts) {
Bundle extras = new Bundle();
extras.putString("fromActivity", activity.getClass().getName());
extras.putString("initialFile", assetFilePath);
extras.putString("uuid", uuid);
extras.putString("id", id);
extras.putSerializable("options", (Serializable) options);
extras.putSerializable("contextMenu", (Serializable) contextMenu);
extras.putInt("windowId", windowId != null ? windowId : -1);
@ -215,10 +215,10 @@ public class InAppBrowserManager implements MethodChannel.MethodCallHandler {
startInAppBrowserActivity(activity, extras);
}
public void openData(Activity activity, String uuid, Map<String, Object> options, String data, String mimeType, String encoding,
public void openData(Activity activity, String id, Map<String, Object> options, String data, String mimeType, String encoding,
String baseUrl, String historyUrl, Map<String, Object> contextMenu, Integer windowId, List<Map<String, Object>> initialUserScripts) {
Bundle extras = new Bundle();
extras.putString("uuid", uuid);
extras.putString("id", id);
extras.putSerializable("options", (Serializable) options);
extras.putString("initialData", data);
extras.putString("initialMimeType", mimeType);

View File

@ -50,18 +50,18 @@ public class HeadlessInAppWebViewManager implements MethodChannel.MethodCallHand
@Override
public void onMethodCall(final MethodCall call, final Result result) {
final Activity activity = Shared.activity;
final String uuid = (String) call.argument("uuid");
final String id = (String) call.argument("id");
switch (call.method) {
case "createHeadlessWebView":
{
HashMap<String, Object> params = (HashMap<String, Object>) call.argument("params");
createHeadlessWebView(activity, uuid, params);
createHeadlessWebView(activity, id, params);
}
result.success(true);
break;
case "disposeHeadlessWebView":
disposeHeadlessWebView(uuid);
disposeHeadlessWebView(id);
result.success(true);
break;
default:
@ -70,15 +70,15 @@ public class HeadlessInAppWebViewManager implements MethodChannel.MethodCallHand
}
public void createHeadlessWebView(Activity activity, String uuid, HashMap<String, Object> params) {
FlutterWebView flutterWebView = new FlutterWebView(Shared.messenger, activity, uuid, params, null);
flutterWebViews.put(uuid, flutterWebView);
public void createHeadlessWebView(Activity activity, String id, HashMap<String, Object> params) {
FlutterWebView flutterWebView = new FlutterWebView(Shared.messenger, activity, id, params, null);
flutterWebViews.put(id, flutterWebView);
}
public void disposeHeadlessWebView(String uuid) {
if (flutterWebViews.containsKey(uuid)) {
flutterWebViews.get(uuid).dispose();
flutterWebViews.remove(uuid);
public void disposeHeadlessWebView(String id) {
if (flutterWebViews.containsKey(id)) {
flutterWebViews.get(id).dispose();
flutterWebViews.remove(id);
}
}

View File

@ -1 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"device_info","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/device_info-2.0.0-nullsafety.2/","dependencies":[]},{"name":"flutter_downloader","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_downloader-1.5.2/","dependencies":[]},{"name":"flutter_inappwebview","path":"/Users/lorenzopichilli/Desktop/flutter_inappwebview/","dependencies":["device_info"]},{"name":"integration_test","path":"/Users/lorenzopichilli/flutter/packages/integration_test/","dependencies":[]},{"name":"path_provider","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-2.0.0-nullsafety/","dependencies":[]},{"name":"permission_handler","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/permission_handler-5.1.0+2/","dependencies":[]},{"name":"url_launcher","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-6.0.0-nullsafety.6/","dependencies":[]}],"android":[{"name":"device_info","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/device_info-2.0.0-nullsafety.2/","dependencies":[]},{"name":"flutter_downloader","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_downloader-1.5.2/","dependencies":[]},{"name":"flutter_inappwebview","path":"/Users/lorenzopichilli/Desktop/flutter_inappwebview/","dependencies":["device_info"]},{"name":"integration_test","path":"/Users/lorenzopichilli/flutter/packages/integration_test/","dependencies":[]},{"name":"path_provider","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-2.0.0-nullsafety/","dependencies":[]},{"name":"permission_handler","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/permission_handler-5.1.0+2/","dependencies":[]},{"name":"url_launcher","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-6.0.0-nullsafety.6/","dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-0.0.5-nullsafety/","dependencies":[]},{"name":"url_launcher_macos","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_macos-0.1.0-nullsafety.2/","dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_linux-0.2.0-nullsafety/","dependencies":[]},{"name":"url_launcher_linux","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_linux-0.1.0-nullsafety.3/","dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_windows-0.1.0-nullsafety.3/","dependencies":[]},{"name":"url_launcher_windows","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_windows-0.1.0-nullsafety.2/","dependencies":[]}],"web":[]},"dependencyGraph":[{"name":"device_info","dependencies":[]},{"name":"flutter_downloader","dependencies":[]},{"name":"flutter_inappwebview","dependencies":["device_info"]},{"name":"integration_test","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos","path_provider_linux","path_provider_windows"]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_macos","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"permission_handler","dependencies":[]},{"name":"url_launcher","dependencies":["url_launcher_linux","url_launcher_macos","url_launcher_windows"]},{"name":"url_launcher_linux","dependencies":[]},{"name":"url_launcher_macos","dependencies":[]},{"name":"url_launcher_windows","dependencies":[]}],"date_created":"2021-02-28 03:33:24.583173","version":"1.27.0-4.0.pre"}
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_downloader","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_downloader-1.5.2/","dependencies":[]},{"name":"flutter_inappwebview","path":"/Users/lorenzopichilli/Desktop/flutter_inappwebview/","dependencies":[]},{"name":"integration_test","path":"/Users/lorenzopichilli/flutter/packages/integration_test/","dependencies":[]},{"name":"path_provider","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-2.0.0-nullsafety/","dependencies":[]},{"name":"permission_handler","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/permission_handler-5.1.0+2/","dependencies":[]},{"name":"url_launcher","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-6.0.0-nullsafety.6/","dependencies":[]}],"android":[{"name":"flutter_downloader","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_downloader-1.5.2/","dependencies":[]},{"name":"flutter_inappwebview","path":"/Users/lorenzopichilli/Desktop/flutter_inappwebview/","dependencies":[]},{"name":"integration_test","path":"/Users/lorenzopichilli/flutter/packages/integration_test/","dependencies":[]},{"name":"path_provider","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-2.0.0-nullsafety/","dependencies":[]},{"name":"permission_handler","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/permission_handler-5.1.0+2/","dependencies":[]},{"name":"url_launcher","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-6.0.0-nullsafety.6/","dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-0.0.5-nullsafety/","dependencies":[]},{"name":"url_launcher_macos","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_macos-0.1.0-nullsafety.2/","dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_linux-0.2.0-nullsafety/","dependencies":[]},{"name":"url_launcher_linux","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_linux-0.1.0-nullsafety.3/","dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_windows-0.1.0-nullsafety.3/","dependencies":[]},{"name":"url_launcher_windows","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_windows-0.1.0-nullsafety.2/","dependencies":[]}],"web":[]},"dependencyGraph":[{"name":"flutter_downloader","dependencies":[]},{"name":"flutter_inappwebview","dependencies":[]},{"name":"integration_test","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos","path_provider_linux","path_provider_windows"]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_macos","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"permission_handler","dependencies":[]},{"name":"url_launcher","dependencies":["url_launcher_linux","url_launcher_macos","url_launcher_windows"]},{"name":"url_launcher_linux","dependencies":[]},{"name":"url_launcher_macos","dependencies":[]},{"name":"url_launcher_windows","dependencies":[]}],"date_created":"2021-03-01 03:17:40.431874","version":"1.27.0-4.0.pre"}

View File

@ -258,7 +258,6 @@
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/OrderedSet/OrderedSet.framework",
"${BUILT_PRODUCTS_DIR}/device_info/device_info.framework",
"${BUILT_PRODUCTS_DIR}/flutter_downloader/flutter_downloader.framework",
"${BUILT_PRODUCTS_DIR}/flutter_inappwebview/flutter_inappwebview.framework",
"${BUILT_PRODUCTS_DIR}/integration_test/integration_test.framework",
@ -268,7 +267,6 @@
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/OrderedSet.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/device_info.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/flutter_downloader.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/flutter_inappwebview.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/integration_test.framework",

View File

@ -37,27 +37,27 @@ public class InAppBrowserManager: NSObject, FlutterPlugin {
switch call.method {
case "openUrlRequest":
let uuid = arguments!["uuid"] as! String
let id = arguments!["id"] as! String
let urlRequest = arguments!["urlRequest"] as! [String:Any?]
let options = arguments!["options"] as! [String: Any?]
let contextMenu = arguments!["contextMenu"] as! [String: Any]
let windowId = arguments!["windowId"] as? Int64
let initialUserScripts = arguments!["initialUserScripts"] as? [[String: Any]]
openUrlRequest(uuid: uuid, urlRequest: urlRequest, options: options, contextMenu: contextMenu, windowId: windowId, initialUserScripts: initialUserScripts)
openUrlRequest(id: id, urlRequest: urlRequest, options: options, contextMenu: contextMenu, windowId: windowId, initialUserScripts: initialUserScripts)
result(true)
break
case "openFile":
let uuid = arguments!["uuid"] as! String
let id = arguments!["id"] as! String
let assetFilePath = arguments!["assetFilePath"] as! String
let options = arguments!["options"] as! [String: Any?]
let contextMenu = arguments!["contextMenu"] as! [String: Any]
let windowId = arguments!["windowId"] as? Int64
let initialUserScripts = arguments!["initialUserScripts"] as? [[String: Any]]
openFile(uuid: uuid, assetFilePath: assetFilePath, options: options, contextMenu: contextMenu, windowId: windowId, initialUserScripts: initialUserScripts)
openFile(id: id, assetFilePath: assetFilePath, options: options, contextMenu: contextMenu, windowId: windowId, initialUserScripts: initialUserScripts)
result(true)
break
case "openData":
let uuid = arguments!["uuid"] as! String
let id = arguments!["id"] as! String
let options = arguments!["options"] as! [String: Any?]
let data = arguments!["data"] as! String
let mimeType = arguments!["mimeType"] as! String
@ -66,7 +66,7 @@ public class InAppBrowserManager: NSObject, FlutterPlugin {
let contextMenu = arguments!["contextMenu"] as! [String: Any]
let windowId = arguments!["windowId"] as? Int64
let initialUserScripts = arguments!["initialUserScripts"] as? [[String: Any]]
openData(uuid: uuid, options: options, data: data, mimeType: mimeType, encoding: encoding, baseUrl: baseUrl,
openData(id: id, options: options, data: data, mimeType: mimeType, encoding: encoding, baseUrl: baseUrl,
contextMenu: contextMenu, windowId: windowId, initialUserScripts: initialUserScripts)
result(true)
break
@ -98,11 +98,11 @@ public class InAppBrowserManager: NSObject, FlutterPlugin {
return webViewController
}
public func openUrlRequest(uuid: String, urlRequest: [String:Any?], options: [String: Any?],
public func openUrlRequest(id: String, urlRequest: [String:Any?], options: [String: Any?],
contextMenu: [String: Any], windowId: Int64?, initialUserScripts: [[String: Any]]?) {
let webViewController = prepareInAppBrowserWebViewController(options: options)
webViewController.uuid = uuid
webViewController.id = id
webViewController.initialUrlRequest = URLRequest.init(fromPluginMap: urlRequest)
webViewController.contextMenu = contextMenu
webViewController.windowId = windowId
@ -111,11 +111,11 @@ public class InAppBrowserManager: NSObject, FlutterPlugin {
presentViewController(webViewController: webViewController)
}
public func openFile(uuid: String, assetFilePath: String, options: [String: Any?],
public func openFile(id: String, assetFilePath: String, options: [String: Any?],
contextMenu: [String: Any], windowId: Int64?, initialUserScripts: [[String: Any]]?) {
let webViewController = prepareInAppBrowserWebViewController(options: options)
webViewController.uuid = uuid
webViewController.id = id
webViewController.initialFile = assetFilePath
webViewController.contextMenu = contextMenu
webViewController.windowId = windowId
@ -124,11 +124,11 @@ public class InAppBrowserManager: NSObject, FlutterPlugin {
presentViewController(webViewController: webViewController)
}
public func openData(uuid: String, options: [String: Any?], data: String, mimeType: String, encoding: String,
public func openData(id: String, options: [String: Any?], data: String, mimeType: String, encoding: String,
baseUrl: String, contextMenu: [String: Any], windowId: Int64?, initialUserScripts: [[String: Any]]?) {
let webViewController = prepareInAppBrowserWebViewController(options: options)
webViewController.uuid = uuid
webViewController.id = id
webViewController.initialData = data
webViewController.initialMimeType = mimeType
webViewController.initialEncoding = encoding

View File

@ -21,7 +21,7 @@ public class InAppBrowserWebViewController: UIViewController, InAppBrowserDelega
var progressBar: UIProgressView!
var tmpWindow: UIWindow?
var uuid: String = ""
var id: String = ""
var windowId: Int64?
var webView: InAppWebView!
var channel: FlutterMethodChannel?
@ -39,7 +39,7 @@ public class InAppBrowserWebViewController: UIViewController, InAppBrowserDelega
var methodCallDelegate: InAppWebViewMethodHandler?
public override func loadView() {
channel = FlutterMethodChannel(name: "com.pichillilorenzo/flutter_inappbrowser_" + uuid, binaryMessenger: SwiftFlutterPlugin.instance!.registrar!.messenger())
channel = FlutterMethodChannel(name: "com.pichillilorenzo/flutter_inappbrowser_" + id, binaryMessenger: SwiftFlutterPlugin.instance!.registrar!.messenger())
var userScripts: [UserScript] = []
for intialUserScript in initialUserScripts {

View File

@ -121,7 +121,7 @@ public class FlutterWebViewController: NSObject, FlutterPlatformView {
self.myView!.alpha = 0.01
UIApplication.shared.keyWindow!.insertSubview(self.myView!, at: 0)
let arguments: [String: Any] = ["uuid": viewId]
let arguments: [String: Any] = ["id": viewId]
channel!.invokeMethod("onHeadlessWebViewCreated", arguments: arguments)
}
}

View File

@ -31,16 +31,16 @@ public class HeadlessInAppWebViewManager: NSObject, FlutterPlugin {
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
let arguments = call.arguments as? NSDictionary
let uuid: String = arguments!["uuid"] as! String
let id: String = arguments!["id"] as! String
switch call.method {
case "createHeadlessWebView":
let params = arguments!["params"] as! [String: Any?]
createHeadlessWebView(uuid: uuid, params: params)
createHeadlessWebView(id: id, params: params)
result(true)
break
case "disposeHeadlessWebView":
disposeHeadlessWebView(uuid: uuid)
disposeHeadlessWebView(id: id)
result(true)
break
default:
@ -49,17 +49,17 @@ public class HeadlessInAppWebViewManager: NSObject, FlutterPlugin {
}
}
public func createHeadlessWebView(uuid: String, params: [String: Any?]) {
public func createHeadlessWebView(id: String, params: [String: Any?]) {
let controller = FlutterWebViewController(registrar: HeadlessInAppWebViewManager.registrar!,
withFrame: CGRect.zero,
viewIdentifier: uuid,
viewIdentifier: id,
arguments: params as NSDictionary)
flutterWebViews[uuid] = controller
flutterWebViews[id] = controller
}
public func disposeHeadlessWebView(uuid: String) {
if let _ = flutterWebViews[uuid] {
flutterWebViews.removeValue(forKey: uuid)
public func disposeHeadlessWebView(id: String) {
if let _ = flutterWebViews[id] {
flutterWebViews.removeValue(forKey: id)
}
}
}

View File

@ -0,0 +1,63 @@
//
// PlatformUtil.swift
// flutter_inappwebview
//
// Created by Lorenzo Pichilli on 01/03/21.
//
import Foundation
class PlatformUtil: NSObject, FlutterPlugin {
static var registrar: FlutterPluginRegistrar?
static var channel: FlutterMethodChannel?
static func register(with registrar: FlutterPluginRegistrar) {
}
init(registrar: FlutterPluginRegistrar) {
super.init()
InAppWebViewStatic.registrar = registrar
InAppWebViewStatic.channel = FlutterMethodChannel(name: "com.pichillilorenzo/flutter_inappwebview_platformutil", binaryMessenger: registrar.messenger())
registrar.addMethodCallDelegate(self, channel: InAppWebViewStatic.channel!)
}
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
let arguments = call.arguments as? NSDictionary
switch call.method {
case "getSystemVersion":
let device = UIDevice.current
result(device.systemVersion)
break
case "formatDate":
let date = arguments!["date"] as! Int64
let format = arguments!["format"] as! String
let locale = PlatformUtil.getLocaleFromString(locale: arguments!["locale"] as? String)
let timezone = TimeZone.init(abbreviation: arguments!["timezone"] as? String ?? "UTC")!
result(PlatformUtil.formatDate(date: date, format: format, locale: locale, timezone: timezone))
break
default:
result(FlutterMethodNotImplemented)
break
}
}
static public func getLocaleFromString(locale: String?) -> Locale {
guard let locale = locale else {
return Locale.init(identifier: "en_US")
}
return Locale.init(identifier: locale)
}
static public func getDateFromMilliseconds(date: Int64) -> Date {
return Date(timeIntervalSince1970: TimeInterval(Double(date)/1000))
}
static public func formatDate(date: Int64, format: String, locale: Locale, timezone: TimeZone) -> String {
let formatter = DateFormatter()
formatter.dateFormat = format
formatter.timeZone = timezone
return formatter.string(from: PlatformUtil.getDateFromMilliseconds(date: date))
}
}

View File

@ -32,11 +32,11 @@ public class ChromeSafariBrowserManager: NSObject, FlutterPlugin {
switch call.method {
case "open":
let uuid: String = arguments!["uuid"] as! String
let id: String = arguments!["id"] as! String
let url = arguments!["url"] as! String
let options = arguments!["options"] as! [String: Any?]
let menuItemList = arguments!["menuItemList"] as! [[String: Any]]
open(uuid: uuid, url: url, options: options, menuItemList: menuItemList, result: result)
open(id: id, url: url, options: options, menuItemList: menuItemList, result: result)
break
case "isAvailable":
if #available(iOS 9.0, *) {
@ -51,7 +51,7 @@ public class ChromeSafariBrowserManager: NSObject, FlutterPlugin {
}
}
public func open(uuid: String, url: String, options: [String: Any?], menuItemList: [[String: Any]], result: @escaping FlutterResult) {
public func open(id: String, url: String, options: [String: Any?], menuItemList: [[String: Any]], result: @escaping FlutterResult) {
let absoluteUrl = URL(string: url)!.absoluteURL
if #available(iOS 9.0, *) {
@ -75,7 +75,7 @@ public class ChromeSafariBrowserManager: NSObject, FlutterPlugin {
safari = SafariViewController(url: absoluteUrl)
}
safari.uuid = uuid
safari.id = id
safari.menuItemList = menuItemList
safari.prepareMethodChannel()
safari.delegate = safari

View File

@ -13,7 +13,7 @@ public class SafariViewController: SFSafariViewController, FlutterPlugin, SFSafa
var channel: FlutterMethodChannel?
var safariOptions: SafariBrowserOptions?
var uuid: String = ""
var id: String = ""
var menuItemList: [[String: Any]] = []
public static func register(with registrar: FlutterPluginRegistrar) {
@ -25,7 +25,7 @@ public class SafariViewController: SFSafariViewController, FlutterPlugin, SFSafa
}
public func prepareMethodChannel() {
channel = FlutterMethodChannel(name: "com.pichillilorenzo/flutter_chromesafaribrowser_" + uuid, binaryMessenger: SwiftFlutterPlugin.instance!.registrar!.messenger())
channel = FlutterMethodChannel(name: "com.pichillilorenzo/flutter_chromesafaribrowser_" + id, binaryMessenger: SwiftFlutterPlugin.instance!.registrar!.messenger())
SwiftFlutterPlugin.instance!.registrar!.addMethodCallDelegate(self, channel: channel!)
}
@ -104,7 +104,7 @@ public class SafariViewController: SFSafariViewController, FlutterPlugin, SFSafa
public func safariViewController(_ controller: SFSafariViewController, activityItemsFor URL: URL, title: String?) -> [UIActivity] {
var uiActivities: [UIActivity] = []
menuItemList.forEach { (menuItem) in
let activity = CustomUIActivity(uuid: uuid, id: menuItem["id"] as! Int64, url: URL, title: title, label: menuItem["label"] as? String, type: nil, image: nil)
let activity = CustomUIActivity(viewId: id, id: menuItem["id"] as! Int64, url: URL, title: title, label: menuItem["label"] as? String, type: nil, image: nil)
uiActivities.append(activity)
}
return uiActivities
@ -141,7 +141,7 @@ public class SafariViewController: SFSafariViewController, FlutterPlugin, SFSafa
}
class CustomUIActivity : UIActivity {
var uuid: String
var viewId: String
var id: Int64
var url: URL
var title: String?
@ -149,8 +149,8 @@ class CustomUIActivity : UIActivity {
var label: String?
var image: UIImage?
init(uuid: String, id: Int64, url: URL, title: String?, label: String?, type: UIActivity.ActivityType?, image: UIImage?) {
self.uuid = uuid
init(viewId: String, id: Int64, url: URL, title: String?, label: String?, type: UIActivity.ActivityType?, image: UIImage?) {
self.viewId = viewId
self.id = id
self.url = url
self.title = title
@ -180,7 +180,7 @@ class CustomUIActivity : UIActivity {
}
override func perform() {
let channel = FlutterMethodChannel(name: "com.pichillilorenzo/flutter_chromesafaribrowser_" + uuid, binaryMessenger: SwiftFlutterPlugin.instance!.registrar!.messenger())
let channel = FlutterMethodChannel(name: "com.pichillilorenzo/flutter_chromesafaribrowser_" + viewId, binaryMessenger: SwiftFlutterPlugin.instance!.registrar!.messenger())
let arguments: [String: Any?] = [
"url": url.absoluteString,

View File

@ -26,6 +26,7 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin {
static var instance: SwiftFlutterPlugin?
var registrar: FlutterPluginRegistrar?
var platformUtil: PlatformUtil?
var inAppWebViewStatic: InAppWebViewStatic?
var myCookieManager: Any?
var myWebStorageManager: Any?
@ -43,6 +44,7 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin {
self.registrar = registrar
registrar.register(FlutterWebViewFactory(registrar: registrar) as FlutterPlatformViewFactory, withId: "com.pichillilorenzo/flutter_inappwebview")
platformUtil = PlatformUtil(registrar: registrar)
inAppBrowserManager = InAppBrowserManager(registrar: registrar)
headlessInAppWebViewManager = HeadlessInAppWebViewManager(registrar: registrar)
chromeSafariBrowserManager = ChromeSafariBrowserManager(registrar: registrar)

View File

@ -1,4 +0,0 @@
import 'package:uuid/uuid.dart';
// ignore: non_constant_identifier_names
final UUID_GENERATOR = Uuid();

View File

@ -2,8 +2,8 @@ import 'dart:async';
import 'dart:collection';
import 'package:flutter/services.dart';
import 'package:flutter_inappwebview/src/util.dart';
import '../_uuid_generator.dart';
import 'chrome_safari_browser_options.dart';
class ChromeSafariBrowserAlreadyOpenedException implements Exception {
@ -37,7 +37,7 @@ class ChromeSafariBrowserNotOpenedException implements Exception {
///`android.support.customtabs.action.CustomTabsService` in your `AndroidManifest.xml`
///(you can read more about it here: https://developers.google.com/web/android/custom-tabs/best-practices#applications_targeting_android_11_api_level_30_or_above).
class ChromeSafariBrowser {
late String uuid;
late String id;
Map<int, ChromeSafariBrowserMenuItem> _menuItems = new HashMap();
bool _isOpened = false;
late MethodChannel _channel;
@ -45,9 +45,9 @@ class ChromeSafariBrowser {
const MethodChannel('com.pichillilorenzo/flutter_chromesafaribrowser');
ChromeSafariBrowser() {
uuid = UUID_GENERATOR.v4();
id = ViewIdGenerator.generateId();
this._channel =
MethodChannel('com.pichillilorenzo/flutter_chromesafaribrowser_$uuid');
MethodChannel('com.pichillilorenzo/flutter_chromesafaribrowser_$id');
this._channel.setMethodCallHandler(handleMethod);
_isOpened = false;
}
@ -93,7 +93,7 @@ class ChromeSafariBrowser {
});
Map<String, dynamic> args = <String, dynamic>{};
args.putIfAbsent('uuid', () => uuid);
args.putIfAbsent('id', () => id);
args.putIfAbsent('url', () => url.toString());
args.putIfAbsent('options', () => options?.toMap() ?? {});
args.putIfAbsent('menuItemList', () => menuItemList);

View File

@ -1,13 +1,12 @@
import 'dart:async';
import 'dart:io';
import 'package:device_info/device_info.dart';
import 'package:flutter/services.dart';
import 'package:intl/intl.dart';
import 'in_app_webview/in_app_webview_controller.dart';
import 'in_app_webview/in_app_webview_options.dart';
import 'in_app_webview/headless_in_app_webview.dart';
import 'platform_util.dart';
import 'types.dart';
@ -72,9 +71,8 @@ class CookieManager {
assert(path.isNotEmpty);
if (Platform.isIOS) {
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
var version = double.tryParse(iosInfo.systemVersion);
var platformUtil = PlatformUtil();
var version = double.tryParse(await platformUtil.getSystemVersion());
if (version != null && version < 11.0) {
await _setCookieWithJavaScript(
url: url,
@ -121,7 +119,7 @@ class CookieManager {
name + "=" + value + "; Domain=" + domain + "; Path=" + path;
if (expiresDate != null)
cookieValue += "; Expires=" + _getCookieExpirationDate(expiresDate);
cookieValue += "; Expires=" + await _getCookieExpirationDate(expiresDate);
if (maxAge != null) cookieValue += "; Max-Age=" + maxAge.toString();
@ -169,9 +167,8 @@ class CookieManager {
assert(url.toString().isNotEmpty);
if (Platform.isIOS) {
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
var version = double.tryParse(iosInfo.systemVersion);
var platformUtil = PlatformUtil();
var version = double.tryParse(await platformUtil.getSystemVersion());
if (version != null && version < 11.0) {
return await _getCookiesWithJavaScript(
url: url, webViewController: iosBelow11WebViewController);
@ -269,9 +266,8 @@ class CookieManager {
assert(name.isNotEmpty);
if (Platform.isIOS) {
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
var version = double.tryParse(iosInfo.systemVersion);
var platformUtil = PlatformUtil();
var version = double.tryParse(await platformUtil.getSystemVersion());
if (version != null && version < 11.0) {
List<Cookie> cookies = await _getCookiesWithJavaScript(
url: url, webViewController: iosBelow11WebViewController);
@ -326,9 +322,8 @@ class CookieManager {
assert(name.isNotEmpty);
if (Platform.isIOS) {
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
var version = double.tryParse(iosInfo.systemVersion);
var platformUtil = PlatformUtil();
var version = double.tryParse(await platformUtil.getSystemVersion());
if (version != null && version < 11.0) {
await _setCookieWithJavaScript(
url: url,
@ -371,9 +366,8 @@ class CookieManager {
assert(url.toString().isNotEmpty);
if (Platform.isIOS) {
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
var version = double.tryParse(iosInfo.systemVersion);
var platformUtil = PlatformUtil();
var version = double.tryParse(await platformUtil.getSystemVersion());
if (version != null && version < 11.0) {
List<Cookie> cookies = await _getCookiesWithJavaScript(
url: url, webViewController: iosBelow11WebViewController);
@ -408,15 +402,13 @@ class CookieManager {
String _getDomainName(Uri url) {
String domain = url.host;
// ignore: unnecessary_null_comparison
if (domain == null) return "";
return domain.startsWith("www.") ? domain.substring(4) : domain;
}
String _getCookieExpirationDate(int expiresDate) {
Future<String> _getCookieExpirationDate(int expiresDate) async {
var platformUtil = PlatformUtil();
var dateTime = DateTime.fromMillisecondsSinceEpoch(expiresDate).toUtc();
return DateFormat('EEE, d MMM yyyy hh:mm:ss', "en_US").format(dateTime) +
' GMT';
return await platformUtil.formatDate(date: dateTime, format: 'EEE, dd MMM yyyy hh:mm:ss z', locale: 'en_US', timezone: 'GMT');
}
}

View File

@ -3,10 +3,10 @@ import 'dart:collection';
import 'dart:typed_data';
import 'package:flutter/services.dart';
import 'package:flutter_inappwebview/src/util.dart';
import '../context_menu.dart';
import '../types.dart';
import '../_uuid_generator.dart';
import '../in_app_webview/in_app_webview_controller.dart';
import '../in_app_webview/in_app_webview_options.dart';
@ -41,7 +41,7 @@ class InAppBrowserNotOpenedException implements Exception {
///The [webViewController] field can be used to access the [InAppWebViewController] API.
class InAppBrowser {
///Browser's UUID.
late String uuid;
late String id;
///Context menu used by the browser. It should be set before opening the browser.
ContextMenu? contextMenu;
@ -62,13 +62,13 @@ class InAppBrowser {
///
InAppBrowser({this.windowId, this.initialUserScripts}) {
uuid = UUID_GENERATOR.v4();
id = ViewIdGenerator.generateId();
this._channel =
MethodChannel('com.pichillilorenzo/flutter_inappbrowser_$uuid');
MethodChannel('com.pichillilorenzo/flutter_inappbrowser_$id');
this._channel.setMethodCallHandler(handleMethod);
_isOpened = false;
webViewController = new InAppWebViewController.fromInAppBrowser(
uuid, this._channel, this, this.initialUserScripts);
id, this._channel, this, this.initialUserScripts);
}
Future<dynamic> handleMethod(MethodCall call) async {
@ -98,7 +98,7 @@ class InAppBrowser {
assert(urlRequest.url != null && urlRequest.url.toString().isNotEmpty);
Map<String, dynamic> args = <String, dynamic>{};
args.putIfAbsent('uuid', () => uuid);
args.putIfAbsent('id', () => id);
args.putIfAbsent('urlRequest', () => urlRequest.toMap());
args.putIfAbsent('options',
() => options?.toMap() ?? InAppBrowserClassOptions().toMap());
@ -151,7 +151,7 @@ class InAppBrowser {
assert(assetFilePath.isNotEmpty);
Map<String, dynamic> args = <String, dynamic>{};
args.putIfAbsent('uuid', () => uuid);
args.putIfAbsent('id', () => id);
args.putIfAbsent('assetFilePath', () => assetFilePath);
args.putIfAbsent('options',
() => options?.toMap() ?? InAppBrowserClassOptions().toMap());
@ -181,7 +181,7 @@ class InAppBrowser {
this.throwIfAlreadyOpened(message: 'Cannot open data!');
Map<String, dynamic> args = <String, dynamic>{};
args.putIfAbsent('uuid', () => uuid);
args.putIfAbsent('id', () => id);
args.putIfAbsent('options',
() => options?.toMap() ?? InAppBrowserClassOptions().toMap());
args.putIfAbsent('data', () => data);
@ -209,7 +209,7 @@ class InAppBrowser {
Future<void> show() async {
this.throwIfNotOpened();
Map<String, dynamic> args = <String, dynamic>{};
args.putIfAbsent('uuid', () => uuid);
args.putIfAbsent('id', () => id);
await _channel.invokeMethod('show', args);
}

View File

@ -2,7 +2,8 @@ import 'dart:io';
import 'dart:async';
import 'package:flutter/services.dart' show rootBundle;
import 'package:mime/mime.dart';
import 'mime_type_resolver.dart';
///This class allows you to create a simple server on `http://localhost:[port]/` in order to be able to load your assets file on a server. The default [port] value is `8080`.
class InAppLocalhostServer {
@ -54,8 +55,7 @@ class InAppLocalhostServer {
var contentType = ['text', 'html'];
if (!request.requestedUri.path.endsWith('/') &&
request.requestedUri.pathSegments.isNotEmpty) {
var mimeType =
lookupMimeType(request.requestedUri.path, headerBytes: body);
var mimeType = MimeTypeResolver.lookup(request.requestedUri.path);
if (mimeType != null) {
contentType = mimeType.split('/');
}

View File

@ -2,10 +2,10 @@ import 'dart:collection';
import 'dart:typed_data';
import 'package:flutter/services.dart';
import 'package:flutter_inappwebview/src/util.dart';
import '../context_menu.dart';
import '../types.dart';
import '../_uuid_generator.dart';
import 'webview.dart';
import 'in_app_webview_controller.dart';
import 'in_app_webview_options.dart';
@ -15,7 +15,7 @@ import 'in_app_webview_options.dart';
///
///Remember to dispose it when you don't need it anymore.
class HeadlessInAppWebView implements WebView {
late String uuid;
late String id;
bool _isDisposed = true;
static const MethodChannel _sharedChannel =
const MethodChannel('com.pichillilorenzo/flutter_headless_inappwebview');
@ -86,8 +86,8 @@ class HeadlessInAppWebView implements WebView {
this.initialOptions,
this.contextMenu,
this.initialUserScripts}) {
uuid = UUID_GENERATOR.v4();
webViewController = new InAppWebViewController(uuid, this);
id = ViewIdGenerator.generateId();
webViewController = new InAppWebViewController(id, this);
}
Future<dynamic> handleMethod(MethodCall call) async {
@ -109,7 +109,7 @@ class HeadlessInAppWebView implements WebView {
}
_isDisposed = false;
Map<String, dynamic> args = <String, dynamic>{};
args.putIfAbsent('uuid', () => uuid);
args.putIfAbsent('id', () => id);
args.putIfAbsent(
'params',
() => <String, dynamic>{
@ -133,7 +133,7 @@ class HeadlessInAppWebView implements WebView {
return;
}
Map<String, dynamic> args = <String, dynamic>{};
args.putIfAbsent('uuid', () => uuid);
args.putIfAbsent('id', () => id);
await _sharedChannel.invokeMethod('disposeHeadlessWebView', args);
_isDisposed = true;
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,38 @@
import 'package:flutter/services.dart';
class PlatformUtil {
static PlatformUtil? _instance;
static const MethodChannel _channel = const MethodChannel(
'com.pichillilorenzo/flutter_inappwebview_platformutil');
static PlatformUtil instance() {
return (_instance != null) ? _instance! : _init();
}
static PlatformUtil _init() {
_channel.setMethodCallHandler(_handleMethod);
_instance = PlatformUtil();
return _instance!;
}
static Future<dynamic> _handleMethod(MethodCall call) async {}
String? _cachedSystemVersion;
Future<String> getSystemVersion() async {
if (_cachedSystemVersion != null) {
return _cachedSystemVersion!;
}
Map<String, dynamic> args = <String, dynamic>{};
_cachedSystemVersion = await _channel.invokeMethod('getSystemVersion', args);
return _cachedSystemVersion!;
}
Future<String> formatDate({required DateTime date, required String format, String locale = "en_US", String timezone = "UTC"}) async {
Map<String, dynamic> args = <String, dynamic>{};
args.putIfAbsent('date', () => date.millisecondsSinceEpoch);
args.putIfAbsent('format', () => format);
args.putIfAbsent('locale', () => locale);
args.putIfAbsent('timezone', () => timezone);
return await _channel.invokeMethod('formatDate', args);
}
}

View File

@ -1,7 +1,42 @@
import 'dart:math';
import 'dart:typed_data';
import 'package:flutter/material.dart';
class ViewIdGenerator {
static int _count = 0;
/// Math.Random()-based RNG. All platforms, fast, not cryptographically strong. Optional Seed passable.
static Uint8List mathRNG({int seed = -1}) {
var b = Uint8List(16);
var rand = (seed == -1) ? Random() : Random(seed);
for (var i = 0; i < 16; i++) {
b[i] = rand.nextInt(256);
}
(seed == -1) ? b.shuffle() : b.shuffle(Random(seed));
return b;
}
/// Crypto-Strong RNG. All platforms, unknown speed, cryptographically strong (theoretically)
static Uint8List cryptoRNG() {
var b = Uint8List(16);
var rand = Random.secure();
for (var i = 0; i < 16; i++) {
b[i] = rand.nextInt(256);
}
return b;
}
static String generateId() {
_count++;
return _count.toString() + cryptoRNG().map((e) => e.toString()).join('');
}
}
extension UtilColor on Color {
static Color? fromStringRepresentation(String colorValue) {
if (colorValue.startsWith("#")) {

View File

@ -10,10 +10,6 @@ environment:
dependencies:
flutter:
sdk: flutter
uuid: ^3.0.0-nullsafety.1
mime: ^1.0.0
intl: ^0.17.0
device_info: ^2.0.0-nullsafety.2
dev_dependencies:
flutter_test: