Commit f6353b8f authored by Lorenzo Pichilli's avatar Lorenzo Pichilli

fix #43, fix #73

parent 20afeae3
#Sun Sep 16 19:20:12 CEST 2018
gradle.version=4.4.1
#Sat Jun 01 15:11:27 CEST 2019
gradle.version=5.1.1
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<Objective-C-extensions>
<file>
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Import" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Macro" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Typedef" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Enum" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Constant" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Global" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Struct" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="FunctionPredecl" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Function" />
</file>
<class>
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Property" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Synthesize" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InitMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="StaticMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InstanceMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="DeallocMethod" />
</class>
<extensions>
<pair source="cpp" header="h" fileNamingConvention="NONE" />
<pair source="c" header="h" fileNamingConvention="NONE" />
</extensions>
</Objective-C-extensions>
</code_scheme>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with NO BOM" />
</project>
\ No newline at end of file
<component name="libraryTable">
<library name="Dart SDK">
<CLASSES>
<root url="file:///Users/lorenzo/flutter/bin/cache/dart-sdk/lib/async" />
<root url="file:///Users/lorenzo/flutter/bin/cache/dart-sdk/lib/collection" />
<root url="file:///Users/lorenzo/flutter/bin/cache/dart-sdk/lib/convert" />
<root url="file:///Users/lorenzo/flutter/bin/cache/dart-sdk/lib/core" />
<root url="file:///Users/lorenzo/flutter/bin/cache/dart-sdk/lib/developer" />
<root url="file:///Users/lorenzo/flutter/bin/cache/dart-sdk/lib/html" />
<root url="file:///Users/lorenzo/flutter/bin/cache/dart-sdk/lib/io" />
<root url="file:///Users/lorenzo/flutter/bin/cache/dart-sdk/lib/isolate" />
<root url="file:///Users/lorenzo/flutter/bin/cache/dart-sdk/lib/math" />
<root url="file:///Users/lorenzo/flutter/bin/cache/dart-sdk/lib/mirrors" />
<root url="file:///Users/lorenzo/flutter/bin/cache/dart-sdk/lib/typed_data" />
<root url="file://$USER_HOME$/flutter/bin/cache/dart-sdk/lib/async" />
<root url="file://$USER_HOME$/flutter/bin/cache/dart-sdk/lib/cli" />
<root url="file://$USER_HOME$/flutter/bin/cache/dart-sdk/lib/collection" />
<root url="file://$USER_HOME$/flutter/bin/cache/dart-sdk/lib/convert" />
<root url="file://$USER_HOME$/flutter/bin/cache/dart-sdk/lib/core" />
<root url="file://$USER_HOME$/flutter/bin/cache/dart-sdk/lib/developer" />
<root url="file://$USER_HOME$/flutter/bin/cache/dart-sdk/lib/ffi" />
<root url="file://$USER_HOME$/flutter/bin/cache/dart-sdk/lib/html" />
<root url="file://$USER_HOME$/flutter/bin/cache/dart-sdk/lib/indexed_db" />
<root url="file://$USER_HOME$/flutter/bin/cache/dart-sdk/lib/io" />
<root url="file://$USER_HOME$/flutter/bin/cache/dart-sdk/lib/isolate" />
<root url="file://$USER_HOME$/flutter/bin/cache/dart-sdk/lib/js" />
<root url="file://$USER_HOME$/flutter/bin/cache/dart-sdk/lib/js_util" />
<root url="file://$USER_HOME$/flutter/bin/cache/dart-sdk/lib/math" />
<root url="file://$USER_HOME$/flutter/bin/cache/dart-sdk/lib/mirrors" />
<root url="file://$USER_HOME$/flutter/bin/cache/dart-sdk/lib/svg" />
<root url="file://$USER_HOME$/flutter/bin/cache/dart-sdk/lib/typed_data" />
<root url="file://$USER_HOME$/flutter/bin/cache/dart-sdk/lib/web_audio" />
<root url="file://$USER_HOME$/flutter/bin/cache/dart-sdk/lib/web_gl" />
<root url="file://$USER_HOME$/flutter/bin/cache/dart-sdk/lib/web_sql" />
</CLASSES>
<JAVADOC />
<SOURCES />
......
......@@ -5,25 +5,38 @@
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
<option name="myNullables">
<value>
<list size="5">
<list size="10">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
<item index="2" class="java.lang.String" itemvalue="javax.annotation.CheckForNull" />
<item index="3" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
<item index="4" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.Nullable" />
<item index="6" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNullable" />
<item index="7" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.qual.Nullable" />
<item index="8" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableDecl" />
<item index="9" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableType" />
</list>
</value>
</option>
<option name="myNotNulls">
<value>
<list size="4">
<list size="9">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
<item index="4" class="java.lang.String" itemvalue="androidx.annotation.NonNull" />
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNonNull" />
<item index="6" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.qual.NonNull" />
<item index="7" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullDecl" />
<item index="8" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullType" />
</list>
</value>
</option>
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Android API 24 Platform" project-jdk-type="Android SDK" />
<component name="ProjectType">
<option name="id" value="io.flutter" />
</component>
</project>
\ No newline at end of file
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="example/lib/main.dart" type="FlutterRunConfigurationType" factoryName="Flutter">
<configuration default="false" name="example/lib/main.dart" type="FlutterRunConfigurationType" factoryName="Flutter" singleton="false">
<option name="filePath" value="$PROJECT_DIR$/example/lib/main.dart" />
<method />
<method v="2" />
</configuration>
</component>
\ No newline at end of file
......@@ -2,6 +2,5 @@
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
<mapping directory="$PROJECT_DIR$/example/ios/.symlinks/plugins/flutter_inappbrowser" vcs="Git" />
</component>
</project>
\ No newline at end of file
This diff is collapsed.
## 1.2.1
- Merge "Add new option to control the contentMode in Android platform" [#101](https://github.com/pichillilorenzo/flutter_inappbrowser/pull/101) (thanks to [DreamBuddy](https://github.com/DreamBuddy))
- Merge "Fix crash on xcode 10.2" [#107](https://github.com/pichillilorenzo/flutter_inappbrowser/pull/107) (thanks to [robsonfingo](https://github.com/robsonfingo))
- Merge "Remove headers_build_phase from example's Podfile" [#108](https://github.com/pichillilorenzo/flutter_inappbrowser/pull/108) (thanks to [robsonfingo](https://github.com/robsonfingo))
- Fixed "Make html5 video fullscreen" for Android [#43](https://github.com/pichillilorenzo/flutter_inappbrowser/issues/43)
- Fixed "AllowsInlineMediaPlayback not working" for iOS [#73](https://github.com/pichillilorenzo/flutter_inappbrowser/issues/73)
## 1.2.0
- Merge "Adds a transparentBackground option for iOS and Android" [#86](https://github.com/pichillilorenzo/flutter_inappbrowser/pull/86) (thanks to [matthewlloyd](https://github.com/matthewlloyd))
......
......@@ -252,7 +252,8 @@ All platforms support:
- __domStorageEnabled__: Set to `true` if you want the DOM storage API is enabled. The default value is `false`.
- __useWideViewPort__: Set to `true` if the WebView should enable support for the "viewport" HTML meta tag or should use a wide viewport. When the value of the setting is false, the layout width is always set to the width of the WebView control in device-independent (CSS) pixels. When the value is true and the page contains the viewport meta tag, the value of the width specified in the tag is used. If the page does not contain the tag or does not provide a width, then a wide viewport will be used. The default value is `true`.
- __safeBrowsingEnabled__: Set to `true` if you want the Safe Browsing is enabled. Safe Browsing allows WebView to protect against malware and phishing attacks by verifying the links. The default value is `true`.
- __textZoom__: Set text scaling of the WebView. The default value is `100`.
- __textZoom__: Set text scaling of the WebView. The default value is `100`.
- __mixedContentMode__: Configures the WebView's behavior when a secure origin attempts to load a resource from an insecure origin. By default, apps that target `Build.VERSION_CODES.KITKAT` or below default to `MIXED_CONTENT_ALWAYS_ALLOW`. Apps targeting `Build.VERSION_CODES.LOLLIPOP` default to `MIXED_CONTENT_NEVER_ALLOW`. The preferred and most secure mode of operation for the WebView is `MIXED_CONTENT_NEVER_ALLOW` and use of `MIXED_CONTENT_ALWAYS_ALLOW` is strongly discouraged.
**iOS** supports these additional options:
......@@ -828,6 +829,7 @@ Opens an `url` in a new `InAppBrowser` instance.
- __safeBrowsingEnabled__: Set to `true` if you want the Safe Browsing is enabled. Safe Browsing allows WebView to protect against malware and phishing attacks by verifying the links. The default value is `true`.
- __progressBar__: Set to `false` to hide the progress bar at the bottom of the toolbar at the top. The default value is `true`.
- __textZoom__: Set text scaling of the WebView. The default value is `100`.
- __mixedContentMode__: Configures the WebView's behavior when a secure origin attempts to load a resource from an insecure origin. By default, apps that target `Build.VERSION_CODES.KITKAT` or below default to `MIXED_CONTENT_ALWAYS_ALLOW`. Apps targeting `Build.VERSION_CODES.LOLLIPOP` default to `MIXED_CONTENT_NEVER_ALLOW`. The preferred and most secure mode of operation for the WebView is `MIXED_CONTENT_NEVER_ALLOW` and use of `MIXED_CONTENT_ALWAYS_ALLOW` is strongly discouraged.
**iOS** supports these additional options:
......
......@@ -2,6 +2,8 @@ package com.pichillilorenzo.flutter_inappbrowser.InAppWebView;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.view.View;
......@@ -9,6 +11,7 @@ import android.webkit.ConsoleMessage;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.FrameLayout;
import com.pichillilorenzo.flutter_inappbrowser.FlutterWebView;
import com.pichillilorenzo.flutter_inappbrowser.InAppBrowserActivity;
......@@ -18,24 +21,69 @@ import java.util.HashMap;
import java.util.Map;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.PluginRegistry;
public class InAppWebChromeClient extends WebChromeClient {
protected static final String LOG_TAG = "IABWebChromeClient";
private PluginRegistry.Registrar registrar;
private FlutterWebView flutterWebView;
private InAppBrowserActivity inAppBrowserActivity;
private ValueCallback<Uri[]> mUploadMessageArray;
private ValueCallback<Uri> mUploadMessage;
private final static int FILECHOOSER_RESULTCODE = 1;
public InAppWebChromeClient(Object obj) {
private View mCustomView;
private WebChromeClient.CustomViewCallback mCustomViewCallback;
protected FrameLayout mFullscreenContainer;
private int mOriginalOrientation;
private int mOriginalSystemUiVisibility;
public InAppWebChromeClient(Object obj, PluginRegistry.Registrar registrar) {
super();
this.registrar = registrar;
if (obj instanceof InAppBrowserActivity)
this.inAppBrowserActivity = (InAppBrowserActivity) obj;
else if (obj instanceof FlutterWebView)
this.flutterWebView = (FlutterWebView) obj;
}
public Bitmap getDefaultVideoPoster()
{
if (mCustomView == null) {
return null;
}
return BitmapFactory.decodeResource(this.registrar.activeContext().getResources(), 2130837573);
}
public void onHideCustomView()
{
View decorView = this.registrar.activity().getWindow().getDecorView();
((FrameLayout) decorView).removeView(this.mCustomView);
this.mCustomView = null;
decorView.setSystemUiVisibility(this.mOriginalSystemUiVisibility);
this.registrar.activity().setRequestedOrientation(this.mOriginalOrientation);
this.mCustomViewCallback.onCustomViewHidden();
this.mCustomViewCallback = null;
}
public void onShowCustomView(View paramView, WebChromeClient.CustomViewCallback paramCustomViewCallback)
{
if (this.mCustomView != null)
{
onHideCustomView();
return;
}
View decorView = this.registrar.activity().getWindow().getDecorView();
this.mCustomView = paramView;
this.mOriginalSystemUiVisibility = decorView.getSystemUiVisibility();
this.mOriginalOrientation = this.registrar.activity().getRequestedOrientation();
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);
}
@Override
public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
Map<String, Object> obj = new HashMap<>();
......
......@@ -116,7 +116,7 @@ public class InAppWebView extends WebView {
addJavascriptInterface(new JavaScriptBridgeInterface((isFromInAppBrowserActivity) ? inAppBrowserActivity : flutterWebView), JavaScriptBridgeInterface.name);
inAppWebChromeClient = new InAppWebChromeClient((isFromInAppBrowserActivity) ? inAppBrowserActivity : flutterWebView);
inAppWebChromeClient = new InAppWebChromeClient((isFromInAppBrowserActivity) ? inAppBrowserActivity : flutterWebView, this.registrar);
setWebChromeClient(inAppWebChromeClient);
inAppWebViewClient = new InAppWebViewClient((isFromInAppBrowserActivity) ? inAppBrowserActivity : flutterWebView);
......@@ -198,6 +198,8 @@ public class InAppWebView extends WebView {
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
} else if (options.mixedContentMode.equals("MIXED_CONTENT_ALWAYS_ALLOW")) {
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
} else if (options.mixedContentMode.equals("MIXED_CONTENT_NEVER_ALLOW")) {
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_NEVER_ALLOW);
}
}
}
......@@ -371,6 +373,8 @@ public class InAppWebView extends WebView {
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
} else if (newOptions.mixedContentMode.equals("MIXED_CONTENT_ALWAYS_ALLOW")) {
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
} else if (newOptions.mixedContentMode.equals("MIXED_CONTENT_NEVER_ALLOW")) {
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_NEVER_ALLOW);
}
}
}
......
......@@ -24,5 +24,5 @@ public class InAppWebViewOptions extends Options {
public boolean useWideViewPort = true;
public boolean safeBrowsingEnabled = true;
public boolean transparentBackground = false;
public String mixedContentMode = "MIXED_CONTENT_NEVER_ALLOW";
public String mixedContentMode = "";
}
......@@ -51,6 +51,8 @@
97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
9D199BB70329114343003314 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = "<group>"; };
B23847D2EEA83886DC92B60F /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = "<group>"; };
E8D91E403808A7540F18B75D /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
......@@ -79,6 +81,8 @@
647DC95AB5350DB6D2264FFE /* Pods */ = {
isa = PBXGroup;
children = (
B23847D2EEA83886DC92B60F /* Pods-Runner.debug.xcconfig */,
9D199BB70329114343003314 /* Pods-Runner.release.xcconfig */,
);
name = Pods;
sourceTree = "<group>";
......@@ -250,7 +254,7 @@
files = (
);
inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
"${PODS_ROOT}/../.symlinks/flutter/ios/Flutter.framework",
"${BUILT_PRODUCTS_DIR}/flutter_inappbrowser/flutter_inappbrowser.framework",
);
......@@ -261,7 +265,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
9740EEB61CF901F6004384FC /* Run Script */ = {
......
......@@ -54,10 +54,13 @@ class _InlineExampleScreenState extends State<InlineExampleScreen> {
decoration:
BoxDecoration(border: Border.all(color: Colors.blueAccent)),
child: InAppWebView(
//initialUrl: "https://www.youtube.com/embed/M7lc1UVf-VE?playsinline=1",
//initialUrl: "https://flutter.dev/",
initialFile: "assets/index.html",
initialHeaders: {},
initialOptions: {
//"mediaPlaybackRequiresUserGesture": false,
//"allowsInlineMediaPlayback": true,
//"useShouldOverrideUrlLoading": true,
//"useOnLoadResource": true
},
......
......@@ -86,10 +86,13 @@ class _WebviewExampleScreenState extends State<WebviewExampleScreen> {
return new Center(
child: new RaisedButton(
onPressed: () {
widget.browser.open(url: "https://google.com", options: {
"useShouldOverrideUrlLoading": true,
"useOnLoadResource": true
});
widget.browser.open(
url: "https://google.com",
options: {
"useShouldOverrideUrlLoading": true,
"useOnLoadResource": true,
}
);
},
child: Text("Open Webview Browser")),
);
......
......@@ -19,10 +19,6 @@ public class FlutterWebViewController: NSObject, FlutterPlatformView {
super.init()
self.registrar = registrar
self.viewId = viewId
webView = InAppWebView(frame: frame, configuration: WKWebViewConfiguration(), IABController: nil, IAWController: self)
let channelName = "com.pichillilorenzo/flutter_inappwebview_" + String(viewId)
self.channel = FlutterMethodChannel(name: channelName, binaryMessenger: registrar.messenger())
self.channel?.setMethodCallHandler(self.handle)
let initialUrl = (args["initialUrl"] as? String)!
let initialFile = args["initialFile"] as? String
......@@ -32,8 +28,14 @@ public class FlutterWebViewController: NSObject, FlutterPlatformView {
let options = InAppWebViewOptions()
options.parse(options: initialOptions)
webView!.options = options
let preWebviewConfiguration = InAppWebView.preWKWebViewConfiguration(options: options)
webView = InAppWebView(frame: frame, configuration: preWebviewConfiguration, IABController: nil, IAWController: self)
let channelName = "com.pichillilorenzo/flutter_inappwebview_" + String(viewId)
self.channel = FlutterMethodChannel(name: channelName, binaryMessenger: registrar.messenger())
self.channel?.setMethodCallHandler(self.handle)
webView!.options = options
webView!.prepare()
if initialFile != nil {
......
......@@ -72,7 +72,7 @@ class InAppWebView_IBWrapper: InAppWebView {
class InAppBrowserWebViewController: UIViewController, UIScrollViewDelegate, WKUIDelegate, UITextFieldDelegate {
@IBOutlet var webView: InAppWebView_IBWrapper!
@IBOutlet var containerWebView: UIView!
@IBOutlet var closeButton: UIButton!
@IBOutlet var reloadButton: UIBarButtonItem!
@IBOutlet var backButton: UIBarButtonItem!
......@@ -85,9 +85,12 @@ class InAppBrowserWebViewController: UIViewController, UIScrollViewDelegate, WKU
@IBOutlet var toolbarTop_BottomToWebViewTopConstraint: NSLayoutConstraint!
@IBOutlet var toolbarBottom_TopToWebViewBottomConstraint: NSLayoutConstraint!
@IBOutlet var containerWebView_BottomFullScreenConstraint: NSLayoutConstraint!
@IBOutlet var containerWebView_TopFullScreenConstraint: NSLayoutConstraint!
@IBOutlet var webView_BottomFullScreenConstraint: NSLayoutConstraint!
@IBOutlet var webView_TopFullScreenConstraint: NSLayoutConstraint!
var webView: InAppWebView!
weak var navigationDelegate: SwiftFlutterPlugin?
var initURL: URL?
var tmpWindow: UIWindow?
......@@ -109,10 +112,21 @@ class InAppBrowserWebViewController: UIViewController, UIScrollViewDelegate, WKU
}
override func viewWillAppear(_ animated: Bool) {
self.webView.IABController = self
if !viewPrepared {
let preWebviewConfiguration = InAppWebView.preWKWebViewConfiguration(options: webViewOptions)
self.webView = InAppWebView(frame: .zero, configuration: preWebviewConfiguration, IABController: self, IAWController: nil)
self.containerWebView.addSubview(self.webView)
prepareConstraints()
prepareWebView()
if self.initData == nil {
loadUrl(url: self.initURL!, headers: self.initHeaders)
}
else {
webView.loadData(data: initData!, mimeType: initMimeType!, encoding: initEncoding!, baseUrl: initBaseUrl!)
}
navigationDelegate?.onBrowserCreated(uuid: uuid, webView: webView)
}
viewPrepared = true
super.viewWillAppear(animated)
......@@ -122,10 +136,6 @@ class InAppBrowserWebViewController: UIViewController, UIScrollViewDelegate, WKU
override func viewDidLoad() {
super.viewDidLoad()
// webView.uiDelegate = self
// webView.navigationDelegate = nil
// webView.scrollView.delegate = self
urlField.delegate = self
urlField.text = self.initURL?.absoluteString
......@@ -149,15 +159,6 @@ class InAppBrowserWebViewController: UIViewController, UIScrollViewDelegate, WKU
spinner.hidesWhenStopped = true
spinner.isHidden = false
spinner.stopAnimating()
if self.initData == nil {
loadUrl(url: self.initURL!, headers: self.initHeaders)
}
else {
webView.loadData(data: initData!, mimeType: initMimeType!, encoding: initEncoding!, baseUrl: initBaseUrl!)
}
navigationDelegate?.onBrowserCreated(uuid: uuid, webView: webView)
}
// Prevent crashes on closing windows
......@@ -171,8 +172,19 @@ class InAppBrowserWebViewController: UIViewController, UIScrollViewDelegate, WKU
}
func prepareConstraints () {
webView_BottomFullScreenConstraint = NSLayoutConstraint(item: self.webView, attribute: NSLayoutAttribute.bottom, relatedBy: NSLayoutRelation.equal, toItem: self.view, attribute: NSLayoutAttribute.bottom, multiplier: 1, constant: 0)
webView_TopFullScreenConstraint = NSLayoutConstraint(item: self.webView, attribute: NSLayoutAttribute.top, relatedBy: NSLayoutRelation.equal, toItem: self.view, attribute: NSLayoutAttribute.top, multiplier: 1, constant: 0)
containerWebView_BottomFullScreenConstraint = NSLayoutConstraint(item: self.containerWebView, attribute: NSLayoutAttribute.bottom, relatedBy: NSLayoutRelation.equal, toItem: self.view, attribute: NSLayoutAttribute.bottom, multiplier: 1, constant: 0)
containerWebView_TopFullScreenConstraint = NSLayoutConstraint(item: self.containerWebView, attribute: NSLayoutAttribute.top, relatedBy: NSLayoutRelation.equal, toItem: self.view, attribute: NSLayoutAttribute.top, multiplier: 1, constant: 0)
webView.translatesAutoresizingMaskIntoConstraints = false
let height = NSLayoutConstraint(item: webView, attribute: .height, relatedBy: .equal, toItem: containerWebView, attribute: .height, multiplier: 1, constant: 0)
let width = NSLayoutConstraint(item: webView, attribute: .width, relatedBy: .equal, toItem: containerWebView, attribute: .width, multiplier: 1, constant: 0)
let leftConstraint = NSLayoutConstraint(item: webView, attribute: .leftMargin, relatedBy: .equal, toItem: containerWebView, attribute: .leftMargin, multiplier: 1, constant: 0)
let rightConstraint = NSLayoutConstraint(item: webView, attribute: .rightMargin, relatedBy: .equal, toItem: containerWebView, attribute: .rightMargin, multiplier: 1, constant: 0)
let bottomContraint = NSLayoutConstraint(item: webView, attribute: .bottomMargin, relatedBy: .equal, toItem: containerWebView, attribute: .bottomMargin, multiplier: 1, constant: 0)
containerWebView.addConstraints([height, width, leftConstraint, rightConstraint, bottomContraint])
webView_BottomFullScreenConstraint = NSLayoutConstraint(item: self.webView, attribute: NSLayoutAttribute.bottom, relatedBy: NSLayoutRelation.equal, toItem: self.containerWebView, attribute: NSLayoutAttribute.bottom, multiplier: 1, constant: 0)
webView_TopFullScreenConstraint = NSLayoutConstraint(item: self.webView, attribute: NSLayoutAttribute.top, relatedBy: NSLayoutRelation.equal, toItem: self.containerWebView, attribute: NSLayoutAttribute.top, multiplier: 1, constant: 0)
}
func prepareWebView() {
......@@ -194,6 +206,7 @@ class InAppBrowserWebViewController: UIViewController, UIScrollViewDelegate, WKU
else {
self.toolbarTop.isHidden = true
self.toolbarTop_BottomToWebViewTopConstraint.isActive = false
self.containerWebView_TopFullScreenConstraint.isActive = true
self.webView_TopFullScreenConstraint.isActive = true
}
......@@ -206,6 +219,7 @@ class InAppBrowserWebViewController: UIViewController, UIScrollViewDelegate, WKU
else {
self.toolbarBottom.isHidden = true
self.toolbarBottom_TopToWebViewBottomConstraint.isActive = false
self.containerWebView_BottomFullScreenConstraint.isActive = true
self.webView_BottomFullScreenConstraint.isActive = true
}
......@@ -378,6 +392,7 @@ class InAppBrowserWebViewController: UIViewController, UIScrollViewDelegate, WKU
}
if newOptionsMap["toolbarTop"] != nil && browserOptions?.toolbarTop != newOptions.toolbarTop {
self.containerWebView_TopFullScreenConstraint.isActive = !newOptions.toolbarTop
self.webView_TopFullScreenConstraint.isActive = !newOptions.toolbarTop
self.toolbarTop.isHidden = !newOptions.toolbarTop
self.toolbarTop_BottomToWebViewTopConstraint.isActive = newOptions.toolbarTop
......@@ -388,6 +403,7 @@ class InAppBrowserWebViewController: UIViewController, UIScrollViewDelegate, WKU
}
if newOptionsMap["toolbarBottom"] != nil && browserOptions?.toolbarBottom != newOptions.toolbarBottom {
self.containerWebView_BottomFullScreenConstraint.isActive = !newOptions.toolbarBottom
self.webView_BottomFullScreenConstraint.isActive = !newOptions.toolbarBottom
self.toolbarBottom.isHidden = !newOptions.toolbarBottom
self.toolbarBottom_TopToWebViewBottomConstraint.isActive = newOptions.toolbarBottom
......
......@@ -112,13 +112,13 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi
configuration.userContentController = WKUserContentController()
configuration.preferences = WKPreferences()
if (options?.transparentBackground)! {
isOpaque = false
backgroundColor = UIColor.clear
scrollView.backgroundColor = UIColor.clear
}
// prevent webView from bouncing
if (options?.disallowOverScroll)! {
if responds(to: #selector(getter: scrollView)) {
......@@ -160,15 +160,6 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi
configuration.userContentController.addUserScript(resourceObserverJSScript)
configuration.userContentController.add(self, name: "resourceLoaded")
if #available(iOS 10.0, *) {
configuration.mediaTypesRequiringUserActionForPlayback = ((options?.mediaPlaybackRequiresUserGesture)!) ? .all : []
} else {
// Fallback on earlier versions
configuration.mediaPlaybackRequiresUserAction = (options?.mediaPlaybackRequiresUserGesture)!
}
configuration.allowsInlineMediaPlayback = (options?.allowsInlineMediaPlayback)!
//keyboardDisplayRequiresUserAction = browserOptions?.keyboardDisplayRequiresUserAction
configuration.suppressesIncrementalRendering = (options?.suppressesIncrementalRendering)!
......@@ -181,8 +172,6 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi
configuration.ignoresViewportScaleLimits = (options?.ignoresViewportScaleLimits)!
}
configuration.allowsInlineMediaPlayback = (options?.allowsInlineMediaPlayback)!
if #available(iOS 9.0, *) {
configuration.allowsPictureInPictureMediaPlayback = (options?.allowsPictureInPictureMediaPlayback)!
}
......@@ -202,6 +191,21 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi
}
}
public static func preWKWebViewConfiguration(options: InAppWebViewOptions?) -> WKWebViewConfiguration {
let configuration = WKWebViewConfiguration()
if #available(iOS 10.0, *) {
configuration.mediaTypesRequiringUserActionForPlayback = ((options?.mediaPlaybackRequiresUserGesture)!) ? .all : []
} else {
// Fallback on earlier versions
configuration.mediaPlaybackRequiresUserAction = (options?.mediaPlaybackRequiresUserGesture)!
}
configuration.allowsInlineMediaPlayback = (options?.allowsInlineMediaPlayback)!
return configuration
}
override public func observeValue(forKeyPath keyPath: String?, of object: Any?,
change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if keyPath == "estimatedProgress" {
......
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14313.18" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina5_5" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment version="2048" identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14283.14"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
......@@ -21,7 +21,7 @@
<rect key="frame" x="0.0" y="0.0" width="414" height="736"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="gA9-n8-qaQ" customClass="InAppWebView_IBWrapper" customModule="flutter_inappbrowser">
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="gA9-n8-qaQ" userLabel="Container WebView" customClass="InAppWebView_IBWrapper" customModule="flutter_inappbrowser">
<rect key="frame" x="0.0" y="66" width="414" height="626"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</view>
......@@ -87,6 +87,7 @@
<connections>
<outlet property="backButton" destination="595-GQ-9lo" id="dvV-nO-BJ6"/>
<outlet property="closeButton" destination="zlr-JJ-Uuj" id="vcO-DA-ByF"/>
<outlet property="containerWebView" destination="gA9-n8-qaQ" id="lkF-Wk-Bm1"/>
<outlet property="forwardButton" destination="cCF-Ou-NU3" id="IqB-62-XYC"/>
<outlet property="reloadButton" destination="fig-ca-P2P" id="271-Gw-S2k"/>
<outlet property="shareButton" destination="skL-Lw-jYB" id="8hu-WC-OM0"/>
......@@ -96,7 +97,6 @@
<outlet property="toolbarTop" destination="vlz-kT-71x" id="WgC-80-Z28"/>
<outlet property="toolbarTop_BottomToWebViewTopConstraint" destination="Sjd-dV-din" id="vkO-Yu-xaE"/>
<outlet property="urlField" destination="sy2-Vx-Cxd" id="MCW-lJ-Ehl"/>
<outlet property="webView" destination="gA9-n8-qaQ" id="439-rj-hHB"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="cYA-mw-BIR" userLabel="First Responder" sceneMemberID="firstResponder"/>
......
......@@ -187,6 +187,7 @@ class InAppBrowser {
/// - __safeBrowsingEnabled__: Set to `true` if you want the Safe Browsing is enabled. Safe Browsing allows WebView to protect against malware and phishing attacks by verifying the links. The default value is `true`.
/// - __progressBar__: Set to `false` to hide the progress bar at the bottom of the toolbar at the top. The default value is `true`.
/// - __textZoom__: Set text scaling of the WebView. The default value is `100`.
/// - __mixedContentMode__: Configures the WebView's behavior when a secure origin attempts to load a resource from an insecure origin. By default, apps that target `Build.VERSION_CODES.KITKAT` or below default to `MIXED_CONTENT_ALWAYS_ALLOW`. Apps targeting `Build.VERSION_CODES.LOLLIPOP` default to `MIXED_CONTENT_NEVER_ALLOW`. The preferred and most secure mode of operation for the WebView is `MIXED_CONTENT_NEVER_ALLOW` and use of `MIXED_CONTENT_ALWAYS_ALLOW` is strongly discouraged.
///
/// - **iOS** supports these additional options:
///
......@@ -596,6 +597,7 @@ class InAppWebViewInitialData {
/// - __useWideViewPort__: Set to `true` if the WebView should enable support for the "viewport" HTML meta tag or should use a wide viewport. When the value of the setting is false, the layout width is always set to the width of the WebView control in device-independent (CSS) pixels. When the value is true and the page contains the viewport meta tag, the value of the width specified in the tag is used. If the page does not contain the tag or does not provide a width, then a wide viewport will be used. The default value is `true`.
/// - __safeBrowsingEnabled__: Set to `true` if you want the Safe Browsing is enabled. Safe Browsing allows WebView to protect against malware and phishing attacks by verifying the links. The default value is `true`.
/// - __textZoom__: Set text scaling of the WebView. The default value is `100`.
/// - __mixedContentMode__: Configures the WebView's behavior when a secure origin attempts to load a resource from an insecure origin. By default, apps that target `Build.VERSION_CODES.KITKAT` or below default to `MIXED_CONTENT_ALWAYS_ALLOW`. Apps targeting `Build.VERSION_CODES.LOLLIPOP` default to `MIXED_CONTENT_NEVER_ALLOW`. The preferred and most secure mode of operation for the WebView is `MIXED_CONTENT_NEVER_ALLOW` and use of `MIXED_CONTENT_ALWAYS_ALLOW` is strongly discouraged.
///
/// **iOS** supports these additional options:
///
......@@ -1291,7 +1293,7 @@ class InAppWebViewController {
}
return WebHistory(historyList, currentIndex);
}
///Dispose/Destroy the WebView.
Future<void> _dispose() async {
await _channel.invokeMethod('dispose');
}
......
name: flutter_inappbrowser
description: A Flutter plugin that allows you to add an inline webview or open an in-app browser window (inspired by the popular cordova-plugin-inappbrowser).
version: 1.2.0
version: 1.2.1
author: Lorenzo Pichilli <pichillilorenzo@gmail.com>
homepage: https://github.com/pichillilorenzo/flutter_inappbrowser
......
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