Commit 3106caf4 authored by Lorenzo Pichilli's avatar Lorenzo Pichilli

fix iOS setCookie #196, added iOS shared Process Pool #196, added scrollTo and scrollBy methods

parent 8486cd04
This diff is collapsed.
...@@ -24,11 +24,10 @@ ...@@ -24,11 +24,10 @@
- Added `onSafeBrowsingHit` event (available only for Android) - Added `onSafeBrowsingHit` event (available only for Android)
- Added `onJsAlert`, `onJsConfirm` and `onJsPrompt` events to manage javascript popup dialogs - Added `onJsAlert`, `onJsConfirm` and `onJsPrompt` events to manage javascript popup dialogs
- Added `onReceivedHttpAuthRequest` event - Added `onReceivedHttpAuthRequest` event
- Added `clearCache()` method - Added `clearCache`, `scrollTo`, `scrollBy`, `getHtml`, `injectJavascriptFileFromAsset` and `injectCSSFileFromAsset` methods method
- Added `HttpAuthCredentialDatabase` class - Added `HttpAuthCredentialDatabase` class
- Added `onReceivedServerTrustAuthRequest` and `onReceivedClientCertRequest` events to manage SSL requests - Added `onReceivedServerTrustAuthRequest` and `onReceivedClientCertRequest` events to manage SSL requests
- Added `onFindResultReceived` event, `findAllAsync`, `findNext` and `clearMatches` methods - Added `onFindResultReceived` event, `findAllAsync`, `findNext` and `clearMatches` methods
- Added `getHtml`, `injectJavascriptFileFromAsset` and `injectCSSFileFromAsset` methods
- Added `shouldInterceptAjaxRequest`, `onAjaxReadyStateChange`, `onAjaxProgress` and `shouldInterceptFetchRequest` events with `useShouldInterceptAjaxRequest` and `useShouldInterceptFetchRequest` webview options - Added `shouldInterceptAjaxRequest`, `onAjaxReadyStateChange`, `onAjaxProgress` and `shouldInterceptFetchRequest` events with `useShouldInterceptAjaxRequest` and `useShouldInterceptFetchRequest` webview options
- Added `onNavigationStateChange` event - Added `onNavigationStateChange` event
- Fun: added `getTRexRunnerHtml` and `getTRexRunnerCss` methods to get html (with javascript) and css to recreate the Chromium's t-rex runner game - Fun: added `getTRexRunnerHtml` and `getTRexRunnerCss` methods to get html (with javascript) and css to recreate the Chromium's t-rex runner game
......
...@@ -286,6 +286,22 @@ public class FlutterWebView implements PlatformView, MethodCallHandler { ...@@ -286,6 +286,22 @@ public class FlutterWebView implements PlatformView, MethodCallHandler {
result.success(false); result.success(false);
} }
break; break;
case "scrollTo":
if (webView != null) {
Integer x = (Integer) call.argument("x");
Integer y = (Integer) call.argument("y");
webView.scrollTo(x, y);
}
result.success(true);
break;
case "scrollBy":
if (webView != null) {
Integer x = (Integer) call.argument("x");
Integer y = (Integer) call.argument("y");
webView.scrollBy(x, y);
}
result.success(true);
break;
default: default:
result.notImplemented(); result.notImplemented();
} }
......
...@@ -2,10 +2,9 @@ ...@@ -2,10 +2,9 @@
# This is a generated file; do not edit or check into version control. # This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=/Users/lorenzopichilli/flutter" export "FLUTTER_ROOT=/Users/lorenzopichilli/flutter"
export "FLUTTER_APPLICATION_PATH=/Users/lorenzopichilli/Desktop/flutter_inappbrowser/example" export "FLUTTER_APPLICATION_PATH=/Users/lorenzopichilli/Desktop/flutter_inappbrowser/example"
export "FLUTTER_TARGET=/Users/lorenzopichilli/Desktop/flutter_inappbrowser/example/lib/main.dart" export "FLUTTER_TARGET=lib/main.dart"
export "FLUTTER_BUILD_DIR=build" export "FLUTTER_BUILD_DIR=build"
export "SYMROOT=${SOURCE_ROOT}/../build/ios" export "SYMROOT=${SOURCE_ROOT}/../build/ios"
export "FLUTTER_FRAMEWORK_DIR=/Users/lorenzopichilli/flutter/bin/cache/artifacts/engine/ios" export "FLUTTER_FRAMEWORK_DIR=/Users/lorenzopichilli/flutter/bin/cache/artifacts/engine/ios"
export "FLUTTER_BUILD_NAME=1.0.0" export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1" export "FLUTTER_BUILD_NUMBER=1"
export "TRACK_WIDGET_CREATION=true"
...@@ -83,18 +83,21 @@ class _InAppWebViewExampleScreenState extends State<InAppWebViewExampleScreen> { ...@@ -83,18 +83,21 @@ class _InAppWebViewExampleScreenState extends State<InAppWebViewExampleScreen> {
title: Text('InAppBrowser'), title: Text('InAppBrowser'),
onTap: () { onTap: () {
Navigator.popAndPushNamed(context, '/InAppBrowser'); Navigator.popAndPushNamed(context, '/InAppBrowser');
dispose();
}, },
), ),
ListTile( ListTile(
title: Text('ChromeSafariBrowser'), title: Text('ChromeSafariBrowser'),
onTap: () { onTap: () {
Navigator.popAndPushNamed(context, '/ChromeSafariBrowser'); Navigator.popAndPushNamed(context, '/ChromeSafariBrowser');
dispose();
}, },
), ),
ListTile( ListTile(
title: Text('InAppWebView'), title: Text('InAppWebView'),
onTap: () { onTap: () {
Navigator.popAndPushNamed(context, '/'); Navigator.popAndPushNamed(context, '/');
dispose();
}, },
), ),
], ],
...@@ -119,11 +122,11 @@ class _InAppWebViewExampleScreenState extends State<InAppWebViewExampleScreen> { ...@@ -119,11 +122,11 @@ class _InAppWebViewExampleScreenState extends State<InAppWebViewExampleScreen> {
BoxDecoration(border: Border.all(color: Colors.blueAccent)), BoxDecoration(border: Border.all(color: Colors.blueAccent)),
child: InAppWebView( child: InAppWebView(
//initialUrl: "https://www.youtube.com/embed/M7lc1UVf-VE?playsinline=1", //initialUrl: "https://www.youtube.com/embed/M7lc1UVf-VE?playsinline=1",
//initialUrl: "https://github.com", initialUrl: "https://github.com",
//initialUrl: "chrome://safe-browsing/match?type=malware", //initialUrl: "chrome://safe-browsing/match?type=malware",
//initialUrl: "http://192.168.1.20:8081/", //initialUrl: "http://192.168.1.20:8081/",
//initialUrl: "https://192.168.1.20:4433/", //initialUrl: "https://192.168.1.20:4433/",
initialFile: "assets/index.html", //initialFile: "assets/index.html",
initialHeaders: {}, initialHeaders: {},
initialOptions: InAppWebViewWidgetOptions( initialOptions: InAppWebViewWidgetOptions(
inAppWebViewOptions: InAppWebViewOptions( inAppWebViewOptions: InAppWebViewOptions(
...@@ -131,12 +134,12 @@ class _InAppWebViewExampleScreenState extends State<InAppWebViewExampleScreen> { ...@@ -131,12 +134,12 @@ class _InAppWebViewExampleScreenState extends State<InAppWebViewExampleScreen> {
//disableHorizontalScroll: false, //disableHorizontalScroll: false,
debuggingEnabled: true, debuggingEnabled: true,
clearCache: true, clearCache: true,
useShouldOverrideUrlLoading: true, //useShouldOverrideUrlLoading: true,
useOnTargetBlank: true, useOnTargetBlank: true,
useOnLoadResource: true, //useOnLoadResource: true,
useOnDownloadStart: true, //useOnDownloadStart: true,
useShouldInterceptAjaxRequest: true, //useShouldInterceptAjaxRequest: true,
useShouldInterceptFetchRequest: true, //useShouldInterceptFetchRequest: true,
//preferredContentMode: InAppWebViewUserPreferredContentMode.DESKTOP, //preferredContentMode: InAppWebViewUserPreferredContentMode.DESKTOP,
resourceCustomSchemes: [ resourceCustomSchemes: [
"my-special-custom-scheme" "my-special-custom-scheme"
...@@ -192,8 +195,7 @@ class _InAppWebViewExampleScreenState extends State<InAppWebViewExampleScreen> { ...@@ -192,8 +195,7 @@ class _InAppWebViewExampleScreenState extends State<InAppWebViewExampleScreen> {
this.url = url; this.url = url;
}); });
}, },
onLoadStop: onLoadStop: (InAppWebViewController controller, String url) async {
(InAppWebViewController controller, String url) async {
print("stopped $url"); print("stopped $url");
if (Platform.isAndroid) { if (Platform.isAndroid) {
controller.clearSslPreferences(); controller.clearSslPreferences();
...@@ -202,6 +204,15 @@ class _InAppWebViewExampleScreenState extends State<InAppWebViewExampleScreen> { ...@@ -202,6 +204,15 @@ class _InAppWebViewExampleScreenState extends State<InAppWebViewExampleScreen> {
//controller.findAllAsync("flutter"); //controller.findAllAsync("flutter");
print(await controller.getFavicons()); print(await controller.getFavicons());
print(await CookieManager.instance().getCookies(url: url)); print(await CookieManager.instance().getCookies(url: url));
//await CookieManager.instance().setCookie(url: url, name: "myCookie", value: "myValue");
//print(await CookieManager.instance().getCookies(url: url));
//await Future.delayed(const Duration(milliseconds: 2000));
//controller.scrollTo(x: 0, y: 500);
//await Future.delayed(const Duration(milliseconds: 2000));
//controller.scrollBy(x: 0, y: 150);
},
onScrollChanged: (InAppWebViewController controller, int x, int y) {
//print("\nSCROLLED\n");
}, },
onLoadError: (InAppWebViewController controller, String url, onLoadError: (InAppWebViewController controller, String url,
int code, String message) async { int code, String message) async {
......
...@@ -302,6 +302,22 @@ public class FlutterWebViewController: NSObject, FlutterPlatformView { ...@@ -302,6 +302,22 @@ public class FlutterWebViewController: NSObject, FlutterPlatformView {
} }
result(true) result(true)
break break
case "scrollTo":
if webView != nil {
let x = arguments!["x"] as! Int
let y = arguments!["y"] as! Int
webView!.scrollTo(x: x, y: y)
}
result(true)
break
case "scrollBy":
if webView != nil {
let x = arguments!["x"] as! Int
let y = arguments!["y"] as! Int
webView!.scrollBy(x: x, y: y)
}
result(true)
break
case "removeFromSuperview": case "removeFromSuperview":
webView!.removeFromSuperview() webView!.removeFromSuperview()
result(true) result(true)
......
...@@ -886,6 +886,8 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi ...@@ -886,6 +886,8 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi
public static func preWKWebViewConfiguration(options: InAppWebViewOptions?) -> WKWebViewConfiguration { public static func preWKWebViewConfiguration(options: InAppWebViewOptions?) -> WKWebViewConfiguration {
let configuration = WKWebViewConfiguration() let configuration = WKWebViewConfiguration()
configuration.processPool = WKProcessPoolManager.sharedProcessPool
if #available(iOS 10.0, *) { if #available(iOS 10.0, *) {
configuration.mediaTypesRequiringUserActionForPlayback = ((options?.mediaPlaybackRequiresUserGesture)!) ? .all : [] configuration.mediaTypesRequiringUserActionForPlayback = ((options?.mediaPlaybackRequiresUserGesture)!) ? .all : []
} else { } else {
...@@ -1811,7 +1813,7 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi ...@@ -1811,7 +1813,7 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi
scrollView.contentOffset = CGPoint(x: lastScrollX, y: scrollView.contentOffset.y); scrollView.contentOffset = CGPoint(x: lastScrollX, y: scrollView.contentOffset.y);
} }
} }
if navigationDelegate != nil { if navigationDelegate != nil && !(disableVerticalScroll && disableHorizontalScroll) {
let x = Int(scrollView.contentOffset.x / scrollView.contentScaleFactor) let x = Int(scrollView.contentOffset.x / scrollView.contentScaleFactor)
let y = Int(scrollView.contentOffset.y / scrollView.contentScaleFactor) let y = Int(scrollView.contentOffset.y / scrollView.contentScaleFactor)
onScrollChanged(x: x, y: y) onScrollChanged(x: x, y: y)
...@@ -2127,6 +2129,16 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi ...@@ -2127,6 +2129,16 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi
evaluateJavaScript("wkwebview_ClearMatches();", completionHandler: completionHandler) evaluateJavaScript("wkwebview_ClearMatches();", completionHandler: completionHandler)
} }
func scrollTo(x: Int, y: Int) {
scrollView.setContentOffset(CGPoint(x: x, y: y), animated: false)
}
func scrollBy(x: Int, y: Int) {
let newX = CGFloat(x) + scrollView.contentOffset.x
let newY = CGFloat(y) + scrollView.contentOffset.y
scrollView.setContentOffset(CGPoint(x: newX, y: newY), animated: false)
}
public override func removeFromSuperview() { public override func removeFromSuperview() {
configuration.userContentController.removeScriptMessageHandler(forName: "consoleLog") configuration.userContentController.removeScriptMessageHandler(forName: "consoleLog")
configuration.userContentController.removeScriptMessageHandler(forName: "consoleDebug") configuration.userContentController.removeScriptMessageHandler(forName: "consoleDebug")
......
...@@ -93,8 +93,9 @@ class MyCookieManager: NSObject, FlutterPlugin { ...@@ -93,8 +93,9 @@ class MyCookieManager: NSObject, FlutterPlugin {
properties[.secure] = (isSecure != nil && isSecure!) ? "TRUE" : "FALSE" properties[.secure] = (isSecure != nil && isSecure!) ? "TRUE" : "FALSE"
let cookie = HTTPCookie(properties: properties)! let cookie = HTTPCookie(properties: properties)!
MyCookieManager.httpCookieStore!.setCookie(cookie) MyCookieManager.httpCookieStore!.setCookie(cookie, completionHandler: {() in
result(true) result(true)
})
} }
public static func getCookies(url: String, result: @escaping FlutterResult) { public static func getCookies(url: String, result: @escaping FlutterResult) {
......
//
// WKProcessPoolManager.swift
// flutter_inappbrowser
//
// Created by Lorenzo Pichilli on 19/11/2019.
//
import Foundation
import WebKit
class WKProcessPoolManager {
static let sharedProcessPool = WKProcessPool()
}
...@@ -336,8 +336,6 @@ class _InAppWebViewState extends State<InAppWebView> { ...@@ -336,8 +336,6 @@ class _InAppWebViewState extends State<InAppWebView> {
@override @override
void dispose(){ void dispose(){
super.dispose(); super.dispose();
if (Platform.isIOS)
_controller._channel.invokeMethod('removeFromSuperview');
} }
void _onPlatformViewCreated(int id) { void _onPlatformViewCreated(int id) {
...@@ -1406,4 +1404,44 @@ class InAppWebViewController { ...@@ -1406,4 +1404,44 @@ class InAppWebViewController {
Future<String> getTRexRunnerCss() async { Future<String> getTRexRunnerCss() async {
return await rootBundle.loadString("packages/flutter_inappbrowser/t_rex_runner/t-rex.css"); return await rootBundle.loadString("packages/flutter_inappbrowser/t_rex_runner/t-rex.css");
} }
///Scrolls the WebView to the position.
///
///[x] represents the x position to scroll to.
///
///[y] represents the y position to scroll to.
Future<void> scrollTo({@required int x, @required int y}) async {
assert(x != null && y != null);
Map<String, dynamic> args = <String, dynamic>{};
if (_inAppBrowserUuid != null && _inAppBrowser != null) {
_inAppBrowser.throwIsNotOpened();
args.putIfAbsent('uuid', () => _inAppBrowserUuid);
}
args.putIfAbsent('x', () => x);
args.putIfAbsent('y', () => y);
await _channel.invokeMethod('scrollTo', args);
}
///Moves the scrolled position of the WebView.
///
///[x] represents the amount of pixels to scroll by horizontally.
///
///[y] represents the amount of pixels to scroll by vertically.
Future<void> scrollBy({@required int x, @required int y}) async {
assert(x != null && y != null);
Map<String, dynamic> args = <String, dynamic>{};
if (_inAppBrowserUuid != null && _inAppBrowser != null) {
_inAppBrowser.throwIsNotOpened();
args.putIfAbsent('uuid', () => _inAppBrowserUuid);
}
args.putIfAbsent('x', () => x);
args.putIfAbsent('y', () => y);
await _channel.invokeMethod('scrollBy', args);
}
/*Future<void> dispose() async {
Map<String, dynamic> args = <String, dynamic>{};
if (Platform.isIOS)
await _channel.invokeMethod('removeFromSuperview', args);
}*/
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment