Skip to content
Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
build/
.fvm/

# Swift Package Manager build artifacts
.build/

flutter_driver_tests.log
tool/chromedriver
tool/chromedriver.*
Expand Down
4 changes: 2 additions & 2 deletions zikzak_inappwebview/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ include: package:flutter_lints/flutter.yaml

linter:
rules:
constant_identifier_names: ignore
deprecated_member_use_from_same_package: ignore
constant_identifier_names: false
deprecated_member_use_from_same_package: false

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
Expand Down
2 changes: 1 addition & 1 deletion zikzak_inappwebview/example/android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pluginManagement {

plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "8.4.0" apply false
id "com.android.application" version "8.6.0" apply false
id "org.jetbrains.kotlin.android" version "1.8.22" apply false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,13 @@ private void prepareCustomTabs() {
if (customSettings.toolbarBackgroundColor != null && !customSettings.toolbarBackgroundColor.isEmpty()) {
defaultColorSchemeBuilder.setToolbarColor(Color.parseColor(customSettings.toolbarBackgroundColor));
}
if (customSettings.navigationBarColor != null && !customSettings.navigationBarColor.isEmpty()) {
defaultColorSchemeBuilder.setNavigationBarColor(Color.parseColor(customSettings.navigationBarColor));
}
if (customSettings.navigationBarDividerColor != null && !customSettings.navigationBarDividerColor.isEmpty()) {
defaultColorSchemeBuilder.setNavigationBarDividerColor(Color.parseColor(customSettings.navigationBarDividerColor));
if (Build.VERSION.SDK_INT < 35) {
if (customSettings.navigationBarColor != null && !customSettings.navigationBarColor.isEmpty()) {
defaultColorSchemeBuilder.setNavigationBarColor(Color.parseColor(customSettings.navigationBarColor));
}
if (customSettings.navigationBarDividerColor != null && !customSettings.navigationBarDividerColor.isEmpty()) {
defaultColorSchemeBuilder.setNavigationBarDividerColor(Color.parseColor(customSettings.navigationBarDividerColor));
}
}
if (customSettings.secondaryToolbarColor != null && !customSettings.secondaryToolbarColor.isEmpty()) {
defaultColorSchemeBuilder.setSecondaryToolbarColor(Color.parseColor(customSettings.secondaryToolbarColor));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ private void prepareCustomTabs() {
if (customSettings.toolbarBackgroundColor != null && !customSettings.toolbarBackgroundColor.isEmpty()) {
defaultColorSchemeBuilder.setToolbarColor(Color.parseColor(customSettings.toolbarBackgroundColor));
}
if (customSettings.navigationBarColor != null && !customSettings.navigationBarColor.isEmpty()) {
defaultColorSchemeBuilder.setNavigationBarColor(Color.parseColor(customSettings.navigationBarColor));
}
if (customSettings.navigationBarDividerColor != null && !customSettings.navigationBarDividerColor.isEmpty()) {
defaultColorSchemeBuilder.setNavigationBarDividerColor(Color.parseColor(customSettings.navigationBarDividerColor));
if (Build.VERSION.SDK_INT < 35) {
if (customSettings.navigationBarColor != null && !customSettings.navigationBarColor.isEmpty()) {
defaultColorSchemeBuilder.setNavigationBarColor(Color.parseColor(customSettings.navigationBarColor));
}
if (customSettings.navigationBarDividerColor != null && !customSettings.navigationBarDividerColor.isEmpty()) {
defaultColorSchemeBuilder.setNavigationBarDividerColor(Color.parseColor(customSettings.navigationBarDividerColor));
}
}
if (customSettings.secondaryToolbarColor != null && !customSettings.secondaryToolbarColor.isEmpty()) {
defaultColorSchemeBuilder.setSecondaryToolbarColor(Color.parseColor(customSettings.secondaryToolbarColor));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import wtf.zikzak.zikzak_inappwebview_android.types.ChannelDelegateImpl;
import wtf.zikzak.zikzak_inappwebview_android.webview.in_app_webview.FlutterWebView;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -192,7 +193,7 @@ public void disposeKeepAlive(@NonNull String keepAliveId) {
flutterWebView.dispose();
}
if (keepAliveWebViews.containsKey(keepAliveId)) {
keepAliveWebViews.put(keepAliveId, null);
keepAliveWebViews.remove(keepAliveId);
}
}

Expand All @@ -205,7 +206,7 @@ public void clearAllCache(@NonNull Context context, boolean includeDiskFiles) {
@Override
public void dispose() {
super.dispose();
Collection<FlutterWebView> flutterWebViews = keepAliveWebViews.values();
Collection<FlutterWebView> flutterWebViews = new ArrayList<>(keepAliveWebViews.values());
for (FlutterWebView flutterWebView : flutterWebViews) {
String keepAliveId = flutterWebView.keepAliveId;
if (keepAliveId != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,27 +124,37 @@ public void run() {
}
}
} else {
if (initialFile != null) {
try {
webView.loadFile(initialFile);
} catch (IOException e) {
Log.e(LOG_TAG, initialFile + " asset file cannot be found!", e);
}
}
else if (initialData != null) {
String data = initialData.get("data");
String mimeType = initialData.get("mimeType");
String encoding = initialData.get("encoding");
String baseUrl = initialData.get("baseUrl");
String historyUrl = initialData.get("historyUrl");
webView.loadDataWithBaseURL(baseUrl, data, mimeType, encoding, historyUrl);
}
else if (initialUrlRequest != null) {
URLRequest urlRequest = URLRequest.fromMap(initialUrlRequest);
if (urlRequest != null) {
webView.loadUrl(urlRequest);
// Defer the initial load so the JS bridge is registered before
// the renderer receives the page load. This prevents a race where
// pages served from cache or sleeping-tab wake-ups could execute
// @document-start userscripts before window.flutter_inappwebview is defined.
webView.post(new Runnable() {
@Override
public void run() {
if (webView == null) return;
if (initialFile != null) {
try {
webView.loadFile(initialFile);
} catch (IOException e) {
Log.e(LOG_TAG, initialFile + " asset file cannot be found!", e);
}
}
else if (initialData != null) {
String data = initialData.get("data");
String mimeType = initialData.get("mimeType");
String encoding = initialData.get("encoding");
String baseUrl = initialData.get("baseUrl");
String historyUrl = initialData.get("historyUrl");
webView.loadDataWithBaseURL(baseUrl, data, mimeType, encoding, historyUrl);
}
else if (initialUrlRequest != null) {
URLRequest urlRequest = URLRequest.fromMap(initialUrlRequest);
if (urlRequest != null) {
webView.loadUrl(urlRequest);
}
}
}
}
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public final class InAppWebView
public Map<String, Object> contextMenu = null;

public Handler mainLooperHandler = new Handler(getWebViewLooper());
static Handler mHandler = new Handler();
static Handler mHandler = new Handler(Looper.getMainLooper());

public Runnable checkScrollStoppedTask;
public int initialPositionScrollStoppedTask;
Expand Down Expand Up @@ -296,12 +296,6 @@ public void prepare() {
);
}

javaScriptBridgeInterface = new JavaScriptBridgeInterface(this);
addJavascriptInterface(
javaScriptBridgeInterface,
JavaScriptBridgeJS.JAVASCRIPT_BRIDGE_NAME
);

inAppWebViewChromeClient = new InAppWebViewChromeClient(
plugin,
this,
Expand Down Expand Up @@ -332,19 +326,6 @@ public void prepare() {
);
}

if (
windowId == null ||
!WebViewFeature.isFeatureSupported(
WebViewFeature.DOCUMENT_START_SCRIPT
)
) {
// for some reason, if a WebView is created using a window id,
// the initial plugin and user scripts injected
// with WebViewCompat.addDocumentStartJavaScript will not be added!
// https://github.com/arrrrny/zikzak_inappwebview/issues/1455
prepareAndAddUserScripts();
}

if (customSettings.useOnDownloadStart) setDownloadListener(
new DownloadStartListener()
);
Expand Down Expand Up @@ -415,8 +396,7 @@ else if (
}

if (customSettings.clearCache) clearAllCache();
else if (customSettings.clearSessionCache) CookieManager.getInstance()
.removeSessionCookie();
else if (customSettings.clearSessionCache) clearSessionCookies();

if (
Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
Expand Down Expand Up @@ -444,6 +424,36 @@ else if (customSettings.clearSessionCache) CookieManager.getInstance()
Color.TRANSPARENT
);

// Defer JS bridge registration to after platform-view attach completes.
// addJavascriptInterface() and WebViewCompat.addDocumentStartJavaScript()
// (called by prepareAndAddUserScripts) hit binder IPC to the renderer
// process. Running them synchronously inside prepare() during
// FlutterWebViewFactory.create() can cause the engine's
// onPlatformViewCreated dispatch to be silently dropped on some builds.
// Deferring to View.post() ensures the engine callback fires first.
post(new Runnable() {
@Override
public void run() {
javaScriptBridgeInterface = new JavaScriptBridgeInterface(InAppWebView.this);
addJavascriptInterface(
javaScriptBridgeInterface,
JavaScriptBridgeJS.JAVASCRIPT_BRIDGE_NAME
);
if (
windowId == null ||
!WebViewFeature.isFeatureSupported(
WebViewFeature.DOCUMENT_START_SCRIPT
)
) {
// for some reason, if a WebView is created using a window id,
// the initial plugin and user scripts injected
// with WebViewCompat.addDocumentStartJavaScript will not be added!
// https://github.com/arrrrny/zikzak_inappwebview/issues/1455
prepareAndAddUserScripts();
}
}
});

if (
Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP &&
customSettings.mixedContentMode != null
Expand Down Expand Up @@ -999,6 +1009,7 @@ public boolean isLoading() {
* @deprecated
*/
@Deprecated
@SuppressWarnings("deprecation")
private void clearCookies() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
CookieManager.getInstance()
Expand All @@ -1013,6 +1024,15 @@ public void onReceiveValue(Boolean aBoolean) {}
}
}

@SuppressWarnings("deprecation")
private void clearSessionCookies() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
CookieManager.getInstance().removeSessionCookies(null);
} else {
CookieManager.getInstance().removeSessionCookie();
}
}

/**
* @deprecated
*/
Expand Down Expand Up @@ -1419,7 +1439,7 @@ else if (
else if (
newSettingsMap.get("clearSessionCache") != null &&
newCustomSettings.clearSessionCache
) CookieManager.getInstance().removeSessionCookie();
) clearSessionCookies();

if (
newSettingsMap.get("thirdPartyCookiesEnabled") != null &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
Expand Down Expand Up @@ -646,6 +647,63 @@ public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGest
}
}

if (result.getType() == WebView.HitTestResult.UNKNOWN_TYPE) {
WebView targetWebView = new WebView(getActivity());
targetWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
int windowId = 0;
if (plugin != null && plugin.inAppWebViewManager != null) {
plugin.inAppWebViewManager.windowAutoincrementId++;
windowId = plugin.inAppWebViewManager.windowAutoincrementId;
}
URLRequest request = new URLRequest(url, "GET", null, null);
CreateWindowAction createWindowAction = new CreateWindowAction(
request,
true,
isUserGesture,
false,
windowId,
isDialog
);

if (plugin != null && plugin.inAppWebViewManager != null) {
plugin.inAppWebViewManager.windowWebViewMessages.put(windowId, resultMsg);
}

if (inAppWebView != null && inAppWebView.channelDelegate != null) {
final int finalWindowId = windowId;
inAppWebView.channelDelegate.onCreateWindow(createWindowAction, new WebViewChannelDelegate.CreateWindowCallback() {
@Override
public boolean nonNullSuccess(@NonNull Boolean handledByClient) {
return !handledByClient;
}

@Override
public void defaultBehaviour(@Nullable Boolean handledByClient) {
if (plugin != null && plugin.inAppWebViewManager != null) {
plugin.inAppWebViewManager.windowWebViewMessages.remove(finalWindowId);
}
}

@Override
public void error(String errorCode, @Nullable String errorMessage, @Nullable Object errorDetails) {
Log.e(LOG_TAG, errorCode + ", " + ((errorMessage != null) ? errorMessage : ""));
defaultBehaviour(null);
}
});

return true;
}
return true;
}
});
WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
transport.setWebView(targetWebView);
resultMsg.sendToTarget();
return true;
}

URLRequest request = new URLRequest(url, "GET", null, null);
CreateWindowAction createWindowAction = new CreateWindowAction(
request,
Expand Down Expand Up @@ -865,6 +923,21 @@ public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
Uri result = null;
if (resultCode == RESULT_OK) {
result = data != null ? data.getData() : getCapturedMediaFile();
// Excludes intents who want to obtain sandbox files.
// Fixes CVE-2020-6563.
if (data != null && data.getData() != null && data.getData().getPath() != null) {
String path = data.getData().getPath();
File file = new File(path);
String normalized;
try {
normalized = file.getCanonicalPath();
} catch (IOException e) {
normalized = path;
}
if (normalized.startsWith("/data")) {
result = null;
}
}
}
if (filePathCallbackLegacy != null) {
filePathCallbackLegacy.onReceiveValue(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ public void onPageStarted(WebView view, String url, Bitmap favicon) {
}
}

@SuppressWarnings("deprecation")
public void onPageFinished(WebView view, String url) {
final InAppWebView webView = (InAppWebView) view;
webView.isLoading = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ public void onPageStarted(WebView view, String url, Bitmap favicon) {
}
}

@SuppressWarnings("deprecation")
public void onPageFinished(WebView view, String url) {
final InAppWebView webView = (InAppWebView) view;
webView.isLoading = false;
Expand Down

This file was deleted.

Loading