[webview_flutter] iOS: Make `webViewWebContentProcessDidTerminate` invoke `onWebResourceError` (#3212)

diff --git a/packages/webview_flutter/CHANGELOG.md b/packages/webview_flutter/CHANGELOG.md
index 29c3cd8..4aa559e 100644
--- a/packages/webview_flutter/CHANGELOG.md
+++ b/packages/webview_flutter/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 1.0.6
+
+* Invoke the WebView.onWebResourceError on iOS when the webview content process crashes.
+
 ## 1.0.5
 
 * Fix example in the readme.
diff --git a/packages/webview_flutter/example/ios/Runner.xcodeproj/project.pbxproj b/packages/webview_flutter/example/ios/Runner.xcodeproj/project.pbxproj
index ef6bc3e..33e9d97 100644
--- a/packages/webview_flutter/example/ios/Runner.xcodeproj/project.pbxproj
+++ b/packages/webview_flutter/example/ios/Runner.xcodeproj/project.pbxproj
@@ -9,6 +9,7 @@
 /* Begin PBXBuildFile section */
 		1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; };
 		3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
+		686B4BF92548DBC7000AEA36 /* FLTWKNavigationDelegateTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 686B4BF82548DBC7000AEA36 /* FLTWKNavigationDelegateTests.m */; };
 		68BDCAF623C3F97800D9C032 /* FLTWebViewTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 68BDCAF523C3F97800D9C032 /* FLTWebViewTests.m */; };
 		978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */; };
 		97C146F31CF9000F007C117D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 97C146F21CF9000F007C117D /* main.m */; };
@@ -46,6 +47,7 @@
 		1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; };
 		1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
 		3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
+		686B4BF82548DBC7000AEA36 /* FLTWKNavigationDelegateTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FLTWKNavigationDelegateTests.m; path = ../../../ios/Tests/FLTWKNavigationDelegateTests.m; sourceTree = "<group>"; };
 		68BDCAE923C3F7CB00D9C032 /* webview_flutter_exampleTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = webview_flutter_exampleTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
 		68BDCAED23C3F7CB00D9C032 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
 		68BDCAF523C3F97800D9C032 /* FLTWebViewTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FLTWebViewTests.m; path = ../../../ios/Tests/FLTWebViewTests.m; sourceTree = "<group>"; };
@@ -86,6 +88,7 @@
 		68BDCAEA23C3F7CB00D9C032 /* webview_flutter_exampleTests */ = {
 			isa = PBXGroup;
 			children = (
+				686B4BF82548DBC7000AEA36 /* FLTWKNavigationDelegateTests.m */,
 				68BDCAF523C3F97800D9C032 /* FLTWebViewTests.m */,
 				68BDCAED23C3F7CB00D9C032 /* Info.plist */,
 			);
@@ -218,6 +221,9 @@
 				LastUpgradeCheck = 1030;
 				ORGANIZATIONNAME = "The Chromium Authors";
 				TargetAttributes = {
+					68BDCAE823C3F7CB00D9C032 = {
+						ProvisioningStyle = Automatic;
+					};
 					97C146ED1CF9000F007C117D = {
 						CreatedOnToolsVersion = 7.3.1;
 					};
@@ -336,6 +342,7 @@
 			buildActionMask = 2147483647;
 			files = (
 				68BDCAF623C3F97800D9C032 /* FLTWebViewTests.m in Sources */,
+				686B4BF92548DBC7000AEA36 /* FLTWKNavigationDelegateTests.m in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
diff --git a/packages/webview_flutter/ios/Classes/FLTWKNavigationDelegate.m b/packages/webview_flutter/ios/Classes/FLTWKNavigationDelegate.m
index dd9608d..7eb08da 100644
--- a/packages/webview_flutter/ios/Classes/FLTWKNavigationDelegate.m
+++ b/packages/webview_flutter/ios/Classes/FLTWKNavigationDelegate.m
@@ -104,4 +104,13 @@
                        withError:(NSError *)error {
   [self onWebResourceError:error];
 }
+
+- (void)webViewWebContentProcessDidTerminate:(WKWebView *)webView {
+  NSError *contentProcessTerminatedError =
+      [[NSError alloc] initWithDomain:WKErrorDomain
+                                 code:WKErrorWebContentProcessTerminated
+                             userInfo:nil];
+  [self onWebResourceError:contentProcessTerminatedError];
+}
+
 @end
diff --git a/packages/webview_flutter/ios/Tests/FLTWKNavigationDelegateTests.m b/packages/webview_flutter/ios/Tests/FLTWKNavigationDelegateTests.m
new file mode 100644
index 0000000..b22f9aa
--- /dev/null
+++ b/packages/webview_flutter/ios/Tests/FLTWKNavigationDelegateTests.m
@@ -0,0 +1,41 @@
+// Copyright 2019 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+@import Flutter;
+@import XCTest;
+@import webview_flutter;
+
+// OCMock library doesn't generate a valid modulemap.
+#import <OCMock/OCMock.h>
+
+@interface FLTWKNavigationDelegateTests : XCTestCase
+
+@property(strong, nonatomic) FlutterMethodChannel *mockMethodChannel;
+@property(strong, nonatomic) FLTWKNavigationDelegate *navigationDelegate;
+
+@end
+
+@implementation FLTWKNavigationDelegateTests
+
+- (void)setUp {
+  self.mockMethodChannel = OCMClassMock(FlutterMethodChannel.class);
+  self.navigationDelegate =
+      [[FLTWKNavigationDelegate alloc] initWithChannel:self.mockMethodChannel];
+}
+
+- (void)testWebViewWebContentProcessDidTerminateCallsRecourseErrorChannel {
+  if (@available(iOS 9.0, *)) {
+    // `webViewWebContentProcessDidTerminate` is only available on iOS 9.0 and above.
+    WKWebView *webview = OCMClassMock(WKWebView.class);
+    [self.navigationDelegate webViewWebContentProcessDidTerminate:webview];
+    OCMVerify([self.mockMethodChannel
+        invokeMethod:@"onWebResourceError"
+           arguments:[OCMArg checkWithBlock:^BOOL(NSDictionary *args) {
+             XCTAssertEqualObjects(args[@"errorType"], @"webContentProcessTerminated");
+             return true;
+           }]]);
+  }
+}
+
+@end
diff --git a/packages/webview_flutter/pubspec.yaml b/packages/webview_flutter/pubspec.yaml
index 504e2ce..27190da 100644
--- a/packages/webview_flutter/pubspec.yaml
+++ b/packages/webview_flutter/pubspec.yaml
@@ -1,6 +1,6 @@
 name: webview_flutter
 description: A Flutter plugin that provides a WebView widget on Android and iOS.
-version: 1.0.5
+version: 1.0.6
 homepage: https://github.com/flutter/plugins/tree/master/packages/webview_flutter
 
 environment: