diff --git a/.github/ISSUE_TEMPLATE/BUG_REPORT.md b/.github/ISSUE_TEMPLATE/BUG_REPORT.md index 283e9357..46107d40 100644 --- a/.github/ISSUE_TEMPLATE/BUG_REPORT.md +++ b/.github/ISSUE_TEMPLATE/BUG_REPORT.md @@ -6,7 +6,7 @@ about: Something is crashing or not working as intended ## Environment -**App version:** +**Plugin version:** **Android version:** **Device information:** **Flutter version:** diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 94a25f7f..46ea4792 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -2,5 +2,6 @@ + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 1e99327e..10429288 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -15,24 +15,52 @@ + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + - - - - - - + + - - + @@ -56,10 +84,9 @@ - - + + - @@ -70,8 +97,8 @@ - - + + @@ -79,8 +106,8 @@ - - + + @@ -89,10 +116,25 @@ - + - - + + + + + + + + + + + + + + + + + @@ -109,17 +151,6 @@ - window. - onLoadHttpError - microphone - Action - Action { - Action action; - Response { - 'action': this.action - : this.action - this. - Event fires onSafe onPermission onPermissionRequest @@ -139,6 +170,17 @@ iltInZoomControls databaseEnabled Cookie + \ + `shouldOverrideUrlLoading + useshouldOverrideUrlLoading + initiald + shouldOverrideUrlLoading + BAAAAACK + loadData + iNitialData + pauseTimers + historyUrl + data activity.getPreferences(0) @@ -161,14 +203,6 @@ - + @@ -340,10 +394,6 @@ - - - - @@ -351,6 +401,11 @@ + + + + + + - + @@ -481,7 +537,7 @@ - + @@ -489,7 +545,7 @@ - + @@ -519,55 +575,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -728,11 +735,6 @@ - - - - - @@ -763,16 +765,6 @@ - - - - - - - - - - @@ -797,40 +789,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -851,49 +809,151 @@ - + + + + - - + + + + + + + + + + + + + + + + + + + + + + + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - - + - - + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + diff --git a/CHANGELOG.md b/CHANGELOG.md index e9320188..4aa3d71b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +## 2.1.0 + +- Added `pause` and `resume` methods for Android. +- Added `pauseTimers` and `resumeTimers` methods. +- Added new `historyUrl` optional parameter for `loadData` and `openData` methods and `InAppWebViewInitialData` class. It is used only on Android. +- Fix "problems with onReceivedHttpAuthRequest when initialData is used" [#201](https://github.com/pichillilorenzo/flutter_inappwebview/issues/201) +- Fix "System ui (status bar and navigation bar) doesn't hide automatically" [#202](https://github.com/pichillilorenzo/flutter_inappwebview/issues/202) + ## 2.0.1+1 - Fixed error "java.lang.ClassCastException: $Proxy1 cannot be cast to android.view.WindowManagerImpl" on Android when using native alert dialogs diff --git a/README.md b/README.md index 320c0f5f..e9e42820 100644 --- a/README.md +++ b/README.md @@ -427,12 +427,12 @@ Instead, on the `onLoadStop` WebView event, you can use `callHandler` directly: * `onLoadHttpError`: Event fired when the InAppWebView main page receives an HTTP error. * `onProgressChanged`: Event fired when the current progress of loading a page is changed. * `onConsoleMessage`: Event fired when the InAppWebView receives a ConsoleMessage. -* `shouldOverrideUrlLoading`: Give the host application a chance to take control when a URL is about to be loaded in the current WebView. -* `onLoadResource`: Event fired when the InAppWebView loads a resource. +* `shouldOverrideUrlLoading`: Give the host application a chance to take control when a URL is about to be loaded in the current WebView (to use this event, the `useShouldOverrideUrlLoading` option must be `true`). +* `onLoadResource`: Event fired when the InAppWebView loads a resource (to use this event, the `useOnLoadResource` option must be `true`). * `onScrollChanged`: Event fired when the InAppWebView scrolls. -* `onDownloadStart`: Event fired when InAppWebView recognizes and starts a downloadable file. +* `onDownloadStart`: Event fired when InAppWebView recognizes and starts a downloadable file (to use this event, the `useOnDownloadStart` option must be `true`). * `onLoadResourceCustomScheme`: Event fired when the InAppWebView finds the `custom-scheme` while loading a resource. Here you can handle the url request and return a CustomSchemeResponse to load a specific resource encoded to `base64`. -* `onTargetBlank`: Event fired when the InAppWebView tries to open a link with `target="_blank"`. +* `onTargetBlank`: Event fired when the InAppWebView tries to open a link with `target="_blank"` (to use this event, the `useOnTargetBlank` option must be `true`). * `onGeolocationPermissionsShowPrompt`: Event that notifies the host application that web content from the specified origin is attempting to use the Geolocation API, but no permission state is currently set for that origin (available only on Android). * `onJsAlert`: Event fired when javascript calls the `alert()` method to display an alert dialog. * `onJsConfirm`: Event fired when javascript calls the `confirm()` method to display a confirm dialog. @@ -442,10 +442,10 @@ Instead, on the `onLoadStop` WebView event, you can use `callHandler` directly: * `onReceivedServerTrustAuthRequest`: Event fired when the WebView need to perform server trust authentication (certificate validation). * `onReceivedClientCertRequest`: Notify the host application to handle an SSL client certificate request. * `onFindResultReceived`: Event fired as find-on-page operations progress. -* `shouldInterceptAjaxRequest`: Event fired when an `XMLHttpRequest` is sent to a server. -* `onAjaxReadyStateChange`: Event fired whenever the `readyState` attribute of an `XMLHttpRequest` changes. -* `onAjaxProgress`: Event fired as an `XMLHttpRequest` progress. -* `shouldInterceptFetchRequest`: Event fired when a request is sent to a server through [Fetch API](https://developer.mozilla.org/it/docs/Web/API/Fetch_API). +* `shouldInterceptAjaxRequest`: Event fired when an `XMLHttpRequest` is sent to a server (to use this event, the `useShouldInterceptAjaxRequest` option must be `true`). +* `onAjaxReadyStateChange`: Event fired whenever the `readyState` attribute of an `XMLHttpRequest` changes (to use this event, the `useShouldInterceptAjaxRequest` option must be `true`). +* `onAjaxProgress`: Event fired as an `XMLHttpRequest` progress (to use this event, the `useShouldInterceptAjaxRequest` option must be `true`). +* `shouldInterceptFetchRequest`: Event fired when a request is sent to a server through [Fetch API](https://developer.mozilla.org/it/docs/Web/API/Fetch_API) (to use this event, the `useShouldInterceptFetchRequest` option must be `true`). * `onNavigationStateChange`: Event fired when the navigation state of the InAppWebView changes. * `onPermissionRequest`: Event fired when the webview is requesting permission to access the specified resources and the permission currently isn't granted or denied (available only on Android). diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/FlutterWebView.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/FlutterWebView.java index fcaae2b5..2d921eae 100644 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/FlutterWebView.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/FlutterWebView.java @@ -76,7 +76,8 @@ public class FlutterWebView implements PlatformView, MethodCallHandler { String mimeType = initialData.get("mimeType"); String encoding = initialData.get("encoding"); String baseUrl = initialData.get("baseUrl"); - webView.loadDataWithBaseURL(baseUrl, data, mimeType, encoding, null); + String historyUrl = initialData.get("historyUrl"); + webView.loadDataWithBaseURL(baseUrl, data, mimeType, encoding, historyUrl); } else webView.loadUrl(initialUrl, initialHeaders); @@ -117,9 +118,10 @@ public class FlutterWebView implements PlatformView, MethodCallHandler { String mimeType = (String) call.argument("mimeType"); String encoding = (String) call.argument("encoding"); String baseUrl = (String) call.argument("baseUrl"); + String historyUrl = (String) call.argument("historyUrl"); if (webView != null) - webView.loadData(data, mimeType, encoding, baseUrl, result); + webView.loadData(data, mimeType, encoding, baseUrl, historyUrl, result); else result.success(false); } @@ -300,6 +302,38 @@ public class FlutterWebView implements PlatformView, MethodCallHandler { } result.success(true); break; + case "pause": + if (webView != null) { + webView.onPause(); + result.success(true); + } else { + result.success(false); + } + break; + case "resume": + if (webView != null) { + webView.onResume(); + result.success(true); + } else { + result.success(false); + } + break; + case "pauseTimers": + if (webView != null) { + webView.pauseTimers(); + result.success(true); + } else { + result.success(false); + } + break; + case "resumeTimers": + if (webView != null) { + webView.resumeTimers(); + result.success(true); + } else { + result.success(false); + } + break; default: result.notImplemented(); } diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppBrowser.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppBrowser.java index 6c794b5a..7bd15b85 100644 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppBrowser.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppBrowser.java @@ -153,7 +153,8 @@ public class InAppBrowser implements MethodChannel.MethodCallHandler { String mimeType = (String) call.argument("mimeType"); String encoding = (String) call.argument("encoding"); String baseUrl = (String) call.argument("baseUrl"); - openData(activity, uuid, options, data, mimeType, encoding, baseUrl); + String historyUrl = (String) call.argument("historyUrl"); + openData(activity, uuid, options, data, mimeType, encoding, baseUrl, historyUrl); result.success(true); } }); @@ -180,7 +181,8 @@ public class InAppBrowser implements MethodChannel.MethodCallHandler { String mimeType = (String) call.argument("mimeType"); String encoding = (String) call.argument("encoding"); String baseUrl = (String) call.argument("baseUrl"); - loadData(uuid, data, mimeType, encoding, baseUrl, result); + String historyUrl = (String) call.argument("historyUrl"); + loadData(uuid, data, mimeType, encoding, baseUrl, historyUrl, result); } break; case "loadFile": @@ -460,7 +462,7 @@ public class InAppBrowser implements MethodChannel.MethodCallHandler { result.error(LOG_TAG, "No WebView fallback declared.", null); } - public void openData(Activity activity, String uuid, HashMap options, String data, String mimeType, String encoding, String baseUrl) { + public void openData(Activity activity, String uuid, HashMap options, String data, String mimeType, String encoding, String baseUrl, String historyUrl) { Intent intent = new Intent(activity, InAppBrowserActivity.class); Bundle extras = new Bundle(); @@ -471,6 +473,7 @@ public class InAppBrowser implements MethodChannel.MethodCallHandler { extras.putString("mimeType", mimeType); extras.putString("encoding", encoding); extras.putString("baseUrl", baseUrl); + extras.putString("historyUrl", historyUrl); intent.putExtras(extras); activity.startActivity(intent); @@ -513,10 +516,10 @@ public class InAppBrowser implements MethodChannel.MethodCallHandler { inAppBrowserActivity.postUrl(url, postData, result); } - public void loadData(String uuid, String data, String mimeType, String encoding, String baseUrl, Result result) { + public void loadData(String uuid, String data, String mimeType, String encoding, String baseUrl, String historyUrl, Result result) { InAppBrowserActivity inAppBrowserActivity = webViewActivities.get(uuid); if (inAppBrowserActivity != null) - inAppBrowserActivity.loadData(data, mimeType, encoding, baseUrl, result); + inAppBrowserActivity.loadData(data, mimeType, encoding, baseUrl, historyUrl, result); } public void loadFile(String uuid, String url, Map headers, Result result) { diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppBrowserActivity.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppBrowserActivity.java index 497d3d1d..0f4e3c21 100644 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppBrowserActivity.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppBrowserActivity.java @@ -88,7 +88,8 @@ public class InAppBrowserActivity extends AppCompatActivity { String mimeType = b.getString("mimeType"); String encoding = b.getString("encoding"); String baseUrl = b.getString("baseUrl"); - webView.loadDataWithBaseURL(baseUrl, data, mimeType, encoding, null); + String historyUrl = b.getString("historyUrl"); + webView.loadDataWithBaseURL(baseUrl, data, mimeType, encoding, historyUrl); } Map obj = new HashMap<>(); @@ -228,9 +229,9 @@ public class InAppBrowserActivity extends AppCompatActivity { } } - public void loadData(String data, String mimeType, String encoding, String baseUrl, MethodChannel.Result result) { + public void loadData(String data, String mimeType, String encoding, String baseUrl, String historyUrl, MethodChannel.Result result) { if (webView != null) { - webView.loadData(data, mimeType, encoding, baseUrl, result); + webView.loadData(data, mimeType, encoding, baseUrl, historyUrl, result); } else { result.error(LOG_TAG, "webView is null", null); } diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebView/InAppWebView.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebView/InAppWebView.java index a4fe8adb..38a86bef 100644 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebView/InAppWebView.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebView/InAppWebView.java @@ -794,8 +794,8 @@ final public class InAppWebView extends InputAwareWebView { result.success(true); } - public void loadData(String data, String mimeType, String encoding, String baseUrl, MethodChannel.Result result) { - loadDataWithBaseURL(baseUrl, data, mimeType, encoding, null); + public void loadData(String data, String mimeType, String encoding, String baseUrl, String historyUrl, MethodChannel.Result result) { + loadDataWithBaseURL(baseUrl, data, mimeType, encoding, historyUrl); result.success(true); } diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebView/InAppWebViewChromeClient.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebView/InAppWebViewChromeClient.java index 8f255334..d2c02781 100644 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebView/InAppWebViewChromeClient.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebView/InAppWebViewChromeClient.java @@ -98,7 +98,16 @@ public class InAppWebViewChromeClient extends WebChromeClient implements PluginR this.mCustomViewCallback = paramCustomViewCallback; this.mCustomView.setBackgroundColor(Color.parseColor("#000000")); ((FrameLayout) decorView).addView(this.mCustomView, new FrameLayout.LayoutParams(-1, -1)); - decorView.setSystemUiVisibility(3846 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); + decorView.setSystemUiVisibility( + View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY + // Set the content to appear under the system bars so that the + // content doesn't resize when the system bars hide and show. + | View.SYSTEM_UI_FLAG_LAYOUT_STABLE + | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION + | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN + // Hide the nav bar and status bar + | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION + | View.SYSTEM_UI_FLAG_FULLSCREEN); } @Override diff --git a/example/assets/index.html b/example/assets/index.html index 7cd13b03..a5c09316 100644 --- a/example/assets/index.html +++ b/example/assets/index.html @@ -4,7 +4,7 @@ - Flutter InAppBrowser + Flutter InAppWebView @@ -14,7 +14,7 @@
-

Flutter InAppBrowser

+

Flutter InAppWebView

+ \ No newline at end of file diff --git a/example/assets/js/main.js b/example/assets/js/main.js new file mode 100644 index 00000000..12f2a70f --- /dev/null +++ b/example/assets/js/main.js @@ -0,0 +1,4 @@ +function add(a, b) { + return a + b; +} +console.log(add(10, 20)); \ No newline at end of file diff --git a/example/pubspec.yaml b/example/pubspec.yaml index fad2de88..0e3bfc27 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -46,6 +46,7 @@ flutter: - assets/index.html - assets/page-1.html - assets/page-2.html + - assets/js/ - assets/css/ - assets/images/ - assets/favicon.ico diff --git a/ios/Classes/FlutterWebViewController.swift b/ios/Classes/FlutterWebViewController.swift index 66edfe64..3d1088a3 100755 --- a/ios/Classes/FlutterWebViewController.swift +++ b/ios/Classes/FlutterWebViewController.swift @@ -318,6 +318,18 @@ public class FlutterWebViewController: NSObject, FlutterPlatformView { } result(true) break + case "pauseTimers": + if webView != nil { + webView!.pauseTimers() + } + result(true) + break + case "resumeTimers": + if webView != nil { + webView!.resumeTimers() + } + result(true) + break case "removeFromSuperview": webView!.removeFromSuperview() result(true) diff --git a/ios/Classes/InAppWebView.swift b/ios/Classes/InAppWebView.swift index c489cb08..7418b63d 100755 --- a/ios/Classes/InAppWebView.swift +++ b/ios/Classes/InAppWebView.swift @@ -689,6 +689,8 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi static var credentialsProposed: [URLCredential] = [] var lastScrollX: CGFloat = 0 var lastScrollY: CGFloat = 0 + var isPausedTimers = false + var isPausedTimersCompletionHandler: (() -> Void)? init(frame: CGRect, configuration: WKWebViewConfiguration, IABController: InAppBrowserWebViewController?, IAWController: FlutterWebViewController?) { @@ -705,6 +707,7 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi } public func prepare() { + addObserver(self, forKeyPath: #keyPath(WKWebView.estimatedProgress), options: .new, @@ -1632,6 +1635,11 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi public func webView(_ webView: WKWebView, runJavaScriptAlertPanelWithMessage message: String, initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping () -> Void) { + if (isPausedTimers) { + isPausedTimersCompletionHandler = completionHandler + return + } + onJsAlert(message: message, result: {(result) -> Void in if result is FlutterError { print((result as! FlutterError).message) @@ -2134,29 +2142,44 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi return (IABController != nil) ? SwiftFlutterPlugin.instance!.channel! : ((IAWController != nil) ? IAWController!.channel! : nil); } - func findAllAsync(find: String?, completionHandler: ((Any?, Error?) -> Void)?) { + public func findAllAsync(find: String?, completionHandler: ((Any?, Error?) -> Void)?) { let startSearch = "wkwebview_FindAllAsync('\(find ?? "")');" evaluateJavaScript(startSearch, completionHandler: completionHandler) } - func findNext(forward: Bool, completionHandler: ((Any?, Error?) -> Void)?) { + public func findNext(forward: Bool, completionHandler: ((Any?, Error?) -> Void)?) { evaluateJavaScript("wkwebview_FindNext(\(forward ? "true" : "false"));", completionHandler: completionHandler) } - func clearMatches(completionHandler: ((Any?, Error?) -> Void)?) { + public func clearMatches(completionHandler: ((Any?, Error?) -> Void)?) { evaluateJavaScript("wkwebview_ClearMatches();", completionHandler: completionHandler) } - func scrollTo(x: Int, y: Int) { + public func scrollTo(x: Int, y: Int) { scrollView.setContentOffset(CGPoint(x: x, y: y), animated: false) } - func scrollBy(x: Int, y: Int) { + public 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 func pauseTimers() { + isPausedTimers = true + let script = "alert();"; + self.evaluateJavaScript(script, completionHandler: nil) + } + + public func resumeTimers() { + if let completionHandler = isPausedTimersCompletionHandler { + completionHandler() + isPausedTimersCompletionHandler = nil + } + isPausedTimers = false + } + public override func removeFromSuperview() { configuration.userContentController.removeScriptMessageHandler(forName: "consoleLog") configuration.userContentController.removeScriptMessageHandler(forName: "consoleDebug") @@ -2175,5 +2198,6 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi IAWController?.channel?.setMethodCallHandler(nil) IABController?.webView = nil IAWController?.webView = nil + isPausedTimersCompletionHandler = nil } } diff --git a/lib/src/in_app_browser.dart b/lib/src/in_app_browser.dart index 5b80906d..5a5ca943 100644 --- a/lib/src/in_app_browser.dart +++ b/lib/src/in_app_browser.dart @@ -162,9 +162,11 @@ class InAppBrowser { ///Opens a new [InAppBrowser] instance with [data] as a content, using [baseUrl] as the base URL for it. /// - ///The [mimeType] parameter specifies the format of the data. + ///The [mimeType] parameter specifies the format of the data. The default value is `"text/html"`. /// - ///The [encoding] parameter specifies the encoding of the data. + ///The [encoding] parameter specifies the encoding of the data. The default value is `"utf8"`. + /// + ///The [historyUrl] parameter is the URL to use as the history entry. The default value is `about:blank`. If non-null, this must be a valid URL. This parameter is used only on Android. /// ///The [options] parameter specifies the options for the [InAppBrowser]. Future openData( @@ -172,6 +174,7 @@ class InAppBrowser { String mimeType = "text/html", String encoding = "utf8", String baseUrl = "about:blank", + String historyUrl = "about:blank", InAppBrowserClassOptions options}) async { assert(data != null); diff --git a/lib/src/in_app_webview.dart b/lib/src/in_app_webview.dart index 5985d9b0..45c4dac2 100755 --- a/lib/src/in_app_webview.dart +++ b/lib/src/in_app_webview.dart @@ -1115,13 +1115,18 @@ class InAppWebViewController { } ///Loads the given [data] into this WebView, using [baseUrl] as the base URL for the content. - ///The [mimeType] parameter specifies the format of the data. - ///The [encoding] parameter specifies the encoding of the data. + /// + ///The [mimeType] parameter specifies the format of the data. The default value is `"text/html"`. + /// + ///The [encoding] parameter specifies the encoding of the data. The default value is `"utf8"`. + /// + ///The [historyUrl] parameter is the URL to use as the history entry. The default value is `about:blank`. If non-null, this must be a valid URL. This parameter is used only on Android. Future loadData( {@required String data, String mimeType = "text/html", String encoding = "utf8", - String baseUrl = "about:blank"}) async { + String baseUrl = "about:blank", + String historyUrl = "about:blank"}) async { assert(data != null); Map args = {}; if (_inAppBrowserUuid != null && _inAppBrowser != null) { @@ -1132,6 +1137,7 @@ class InAppWebViewController { args.putIfAbsent('mimeType', () => mimeType); args.putIfAbsent('encoding', () => encoding); args.putIfAbsent('baseUrl', () => baseUrl); + args.putIfAbsent('historyUrl', () => historyUrl); await _channel.invokeMethod('loadData', args); } @@ -1673,6 +1679,51 @@ class InAppWebViewController { await _channel.invokeMethod('scrollBy', args); } + ///Does a best-effort attempt to pause any processing that can be paused safely, such as animations and geolocation. Note that this call does not pause JavaScript. + ///To pause JavaScript globally, use [pauseTimers()]. To resume WebView, call [resume()]. + /// + ///**NOTE**: available only on Android. + Future pause() async { + Map args = {}; + if (_inAppBrowserUuid != null && _inAppBrowser != null) { + _inAppBrowser.throwIsNotOpened(); + args.putIfAbsent('uuid', () => _inAppBrowserUuid); + } + await _channel.invokeMethod('pause', args); + } + + ///Resumes a WebView after a previous call to [pause()]. + /// + ///**NOTE**: available only on Android. + Future resume() async { + Map args = {}; + if (_inAppBrowserUuid != null && _inAppBrowser != null) { + _inAppBrowser.throwIsNotOpened(); + args.putIfAbsent('uuid', () => _inAppBrowserUuid); + } + await _channel.invokeMethod('resume', args); + } + + ///Pauses all layout, parsing, and JavaScript timers for all WebViews. This is a global requests, not restricted to just this WebView. This can be useful if the application has been paused. + Future pauseTimers() async { + Map args = {}; + if (_inAppBrowserUuid != null && _inAppBrowser != null) { + _inAppBrowser.throwIsNotOpened(); + args.putIfAbsent('uuid', () => _inAppBrowserUuid); + } + await _channel.invokeMethod('pauseTimers', args); + } + + ///Resumes all layout, parsing, and JavaScript timers for all WebViews. This will resume dispatching all timers. + Future resumeTimers() async { + Map args = {}; + if (_inAppBrowserUuid != null && _inAppBrowser != null) { + _inAppBrowser.throwIsNotOpened(); + args.putIfAbsent('uuid', () => _inAppBrowserUuid); + } + await _channel.invokeMethod('resumeTimers', args); + } + /*Future dispose() async { Map args = {}; if (Platform.isIOS) diff --git a/lib/src/types.dart b/lib/src/types.dart index f59ff9cd..976c1b28 100644 --- a/lib/src/types.dart +++ b/lib/src/types.dart @@ -82,26 +82,36 @@ class LoadedResource { } ///Initial [data] as a content for an [InAppWebView] instance, using [baseUrl] as the base URL for it. -///The [mimeType] property specifies the format of the data. -///The [encoding] property specifies the encoding of the data. class InAppWebViewInitialData { + ///A String of data in the given encoding. String data; + + ///The MIME type of the data, e.g. "text/html". The default value is `"text/html"`. String mimeType; + + ///The encoding of the data. The default value is `"utf8"`. String encoding; + + ///The URL to use as the page's base URL. The default value is `about:blank`. String baseUrl; + ///The URL to use as the history entry. The default value is `about:blank`. If non-null, this must be a valid URL. This parameter is used only on Android. + String historyUrl; + InAppWebViewInitialData( {@required this.data, this.mimeType = "text/html", this.encoding = "utf8", - this.baseUrl = "about:blank"}); + this.baseUrl = "about:blank", + this.historyUrl = "about:blank"}); Map toMap() { return { "data": data, "mimeType": mimeType, "encoding": encoding, - "baseUrl": baseUrl + "baseUrl": baseUrl, + "historyUrl": historyUrl }; } } diff --git a/nodejs_server_test_auth_basic_and_ssl/index.js b/nodejs_server_test_auth_basic_and_ssl/index.js index 0f2f1a33..1f103773 100644 --- a/nodejs_server_test_auth_basic_and_ssl/index.js +++ b/nodejs_server_test_auth_basic_and_ssl/index.js @@ -94,6 +94,11 @@ appAuthBasic.use((req, res, next) => { } }) +appAuthBasic.use(express.static(__dirname + '/public')); +appAuthBasic.get('/test-index', (req, res) => { + res.sendFile(__dirname + '/public/index.html'); +}); + appAuthBasic.get("/", (req, res) => { console.log(JSON.stringify(req.headers)) res.send(` @@ -120,6 +125,11 @@ app.use(cors()); // Parse JSON bodies (as sent by API clients) app.use(express.json()); +app.use(express.static(__dirname + '/public')); +app.get('/test-index', (req, res) => { + res.sendFile(__dirname + '/public/index.html'); +}); + app.get("/", (req, res) => { console.log(JSON.stringify(req.headers)) res.send(` diff --git a/nodejs_server_test_auth_basic_and_ssl/public/css/style.css b/nodejs_server_test_auth_basic_and_ssl/public/css/style.css new file mode 100644 index 00000000..96f7c63e --- /dev/null +++ b/nodejs_server_test_auth_basic_and_ssl/public/css/style.css @@ -0,0 +1,4 @@ +body { + background: yellow; + color: #333; +} \ No newline at end of file diff --git a/nodejs_server_test_auth_basic_and_ssl/public/index.html b/nodejs_server_test_auth_basic_and_ssl/public/index.html new file mode 100644 index 00000000..99f5d41c --- /dev/null +++ b/nodejs_server_test_auth_basic_and_ssl/public/index.html @@ -0,0 +1,15 @@ + + + + + + + Flutter InAppWebView + + + +

TEST

+
+ + + \ No newline at end of file diff --git a/nodejs_server_test_auth_basic_and_ssl/public/js/main.js b/nodejs_server_test_auth_basic_and_ssl/public/js/main.js new file mode 100644 index 00000000..5d122fd5 --- /dev/null +++ b/nodejs_server_test_auth_basic_and_ssl/public/js/main.js @@ -0,0 +1 @@ +document.querySelector("#test").innerHTML = "this is a test"; \ No newline at end of file diff --git a/pubspec.yaml b/pubspec.yaml index fa3c032c..6f40e6dc 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_inappwebview description: A Flutter plugin that allows you to add an inline webview or open an in-app browser window. -version: 2.0.1+1 +version: 2.1.0 author: Lorenzo Pichilli homepage: https://github.com/pichillilorenzo/flutter_inappwebview