[iOS] Remove PageNotAvailableController

This CL removes the PageNotAvailableController.
This controller was only instatiated in BVC, when no other
NativeController were available for a specific URL.
However, all the possible cases of displaying a NativeContent are
guarded with a check on the provider to know if it can display a
native content for the URL.

So if there was a case where it was possible to display this controller,
the DCHECK would have been hit.

Bug: 725239, 944008
Change-Id: Iace04dea9f85bed31cec626e0098f8cf1ef9bc71
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1533905
Reviewed-by: Mark Cogan <marq@chromium.org>
Reviewed-by: Matt Menke <mmenke@chromium.org>
Reviewed-by: Eugene But <eugenebut@chromium.org>
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#643374}
diff --git a/components/error_page_strings.grdp b/components/error_page_strings.grdp
index fcd9f61..a67082d8 100644
--- a/components/error_page_strings.grdp
+++ b/components/error_page_strings.grdp
@@ -351,11 +351,4 @@
     </message>
   </if>
 
-  <!-- iOS specific error page messages -->
-  <if expr="is_ios">
-    <message name="IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE_NO_EMPHASIS" desc="Summary in the error page when we can't connect to a site. [iOS only]">
-      The webpage at <ph name="SITE">$1<ex>google.xom</ex></ph> might be temporarily down or it may have moved permanently to a new web address.
-    </message>
-  </if>
-
 </grit-part>
diff --git a/ios/chrome/browser/ui/BUILD.gn b/ios/chrome/browser/ui/BUILD.gn
index dd89273..3e99325a 100644
--- a/ios/chrome/browser/ui/BUILD.gn
+++ b/ios/chrome/browser/ui/BUILD.gn
@@ -63,7 +63,6 @@
     "file_locations_unittest.mm",
     "native_content_controller_unittest.mm",
     "network_activity_indicator_manager_unittest.mm",
-    "page_not_available_controller_unittest.mm",
   ]
   deps = [
     ":native_content_controller_test_xib",
@@ -218,10 +217,7 @@
 
 source_set("ui_internal") {
   configs += [ "//build/config/compiler:enable_arc" ]
-  sources = [
-    "page_not_available_controller.h",
-    "page_not_available_controller.mm",
-  ]
+  sources = []
   deps = [
     ":notifications",
     ":resources",
diff --git a/ios/chrome/browser/ui/browser_view/browser_view_controller.mm b/ios/chrome/browser/ui/browser_view/browser_view_controller.mm
index 1a1c73b..5ae91b2a 100644
--- a/ios/chrome/browser/ui/browser_view/browser_view_controller.mm
+++ b/ios/chrome/browser/ui/browser_view/browser_view_controller.mm
@@ -121,7 +121,6 @@
 #import "ios/chrome/browser/ui/ntp/ntp_util.h"
 #import "ios/chrome/browser/ui/omnibox/popup/omnibox_popup_presenter.h"
 #import "ios/chrome/browser/ui/overscroll_actions/overscroll_actions_controller.h"
-#import "ios/chrome/browser/ui/page_not_available_controller.h"
 #import "ios/chrome/browser/ui/payments/payment_request_manager.h"
 #import "ios/chrome/browser/ui/popup_menu/popup_menu_coordinator.h"
 #import "ios/chrome/browser/ui/presenters/vertical_animation_container.h"
@@ -3681,13 +3680,9 @@
   } else if (url_host == kChromeUICrashHost) {
     // There is no native controller for kChromeUICrashHost, it is instead
     // handled as any other renderer crash by the SadTabTabHelper.
-    // nativeController must be set to nil to prevent defaulting to a
-    // PageNotAvailableController.
     nativeController = nil;
   } else {
-    DCHECK(![self hasControllerForURL:url]);
-    // In any other case the PageNotAvailableController is returned.
-    nativeController = [[PageNotAvailableController alloc] initWithUrl:url];
+    NOTREACHED();
   }
   // If a native controller is vended before its tab is added to the tab model,
   // use the temporary key and add it under the new tab's tabId in the
diff --git a/ios/chrome/browser/ui/browser_view/browser_view_controller_unittest.mm b/ios/chrome/browser/ui/browser_view/browser_view_controller_unittest.mm
index 78f288d..b5709c7 100644
--- a/ios/chrome/browser/ui/browser_view/browser_view_controller_unittest.mm
+++ b/ios/chrome/browser/ui/browser_view/browser_view_controller_unittest.mm
@@ -44,7 +44,6 @@
 #import "ios/chrome/browser/ui/commands/open_new_tab_command.h"
 #import "ios/chrome/browser/ui/commands/page_info_commands.h"
 #import "ios/chrome/browser/ui/ntp/new_tab_page_controller.h"
-#import "ios/chrome/browser/ui/page_not_available_controller.h"
 #import "ios/chrome/browser/ui/toolbar/public/omnibox_focuser.h"
 #include "ios/chrome/browser/ui/ui_feature_flags.h"
 #include "ios/chrome/browser/ui/util/ui_util.h"
@@ -311,21 +310,6 @@
   EXPECT_TRUE(webStateImpl_->IsVisible());
 }
 
-TEST_F(BrowserViewControllerTest, TestNativeContentController) {
-  id<CRWNativeContent> controller =
-      [bvc_ controllerForURL:GURL(kChromeUINewTabURL)
-                    webState:webStateImpl_.get()];
-  if (!base::FeatureList::IsEnabled(kBrowserContainerContainsNTP)) {
-    EXPECT_TRUE(controller != nil);
-    EXPECT_TRUE([controller isMemberOfClass:[NewTabPageController class]]);
-  }
-
-  controller = [bvc_ controllerForURL:GURL(kChromeUISettingsURL)
-                             webState:webStateImpl_.get()];
-  EXPECT_TRUE(controller != nil);
-  EXPECT_TRUE([controller isMemberOfClass:[PageNotAvailableController class]]);
-}
-
 // TODO(altse): Needs a testing |Profile| that implements AutocompleteClassifier
 //             before enabling again.
 TEST_F(BrowserViewControllerTest, DISABLED_TestShieldWasTapped) {
diff --git a/ios/chrome/browser/ui/page_not_available_controller.h b/ios/chrome/browser/ui/page_not_available_controller.h
deleted file mode 100644
index deeaaec..0000000
--- a/ios/chrome/browser/ui/page_not_available_controller.h
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright 2012 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.
-
-#ifndef IOS_CHROME_BROWSER_UI_PAGE_NOT_AVAILABLE_CONTROLLER_H_
-#define IOS_CHROME_BROWSER_UI_PAGE_NOT_AVAILABLE_CONTROLLER_H_
-
-#import "ios/chrome/browser/ui/native_content_controller.h"
-
-// A native controller for the case where the URL is not valid and/or the page
-// is not available.
-@interface PageNotAvailableController : NativeContentController
-
-// Property to allow setting a custom description for the content.
-@property(nonatomic, copy) NSString* descriptionText;
-
-// Designated initializer.
-- (instancetype)initWithUrl:(const GURL&)url NS_DESIGNATED_INITIALIZER;
-
-- (instancetype)initWithNibName:(NSString*)nibName
-                            url:(const GURL&)url NS_UNAVAILABLE;
-
-@end
-
-#endif  // IOS_CHROME_BROWSER_UI_PAGE_NOT_AVAILABLE_CONTROLLER_H_
diff --git a/ios/chrome/browser/ui/page_not_available_controller.mm b/ios/chrome/browser/ui/page_not_available_controller.mm
deleted file mode 100644
index ec4d6ee..0000000
--- a/ios/chrome/browser/ui/page_not_available_controller.mm
+++ /dev/null
@@ -1,128 +0,0 @@
-// Copyright 2012 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 "ios/chrome/browser/ui/page_not_available_controller.h"
-
-#include "base/i18n/rtl.h"
-#include "base/logging.h"
-
-#include "base/strings/sys_string_conversions.h"
-#include "base/strings/utf_string_conversions.h"
-#include "components/strings/grit/components_strings.h"
-#include "components/url_formatter/url_formatter.h"
-#include "ui/base/l10n/l10n_util.h"
-#include "ui/base/l10n/l10n_util_mac.h"
-
-#if !defined(__has_feature) || !__has_feature(objc_arc)
-#error "This file requires ARC support."
-#endif
-
-namespace {
-// Top padding for |self.titleLabel|.
-const CGFloat kTitleLabelTopPadding = 20.0;
-// Height for |self.titleLabel|.
-const CGFloat kTitleLabelHeight = 38.0;
-// Top padding for |self.descriptionView|.
-const CGFloat kDescriptionViewTopPadding = 66.0;
-// Bottom padding for |self.descriptionView|.
-const CGFloat kDescriptionViewBottomPadding = 20.0;
-// Horizontal padding between subviews and |self.view|.
-const CGFloat kHorizontalPadding = 20.0;
-// Font size for |self.titleLabel|.
-const CGFloat kTitleLabelFontSize = 18.0;
-// Font size for |self.descriptionView|.
-const CGFloat kDescriptionViewFontSize = 17.0;
-}
-
-@interface PageNotAvailableController () {
-}
-
-// The title label displayed centered at the top of the screen.
-@property(nonatomic, strong) UILabel* titleLabel;
-
-// TextView containing a detailed description of the problem.
-@property(nonatomic, strong) UITextView* descriptionView;
-
-@end
-
-@implementation PageNotAvailableController
-
-@synthesize titleLabel = _titleLabel;
-@synthesize descriptionView = _descriptionView;
-@synthesize descriptionText = _descriptionText;
-
-- (instancetype)initWithUrl:(const GURL&)url {
-  self = [super initWithNibName:nil url:url];
-  if (self) {
-    // Use the host as the page title, unless the URL has a custom scheme.
-    if (self.url.SchemeIsHTTPOrHTTPS()) {
-      self.title = base::SysUTF16ToNSString(
-          url_formatter::IDNToUnicode(self.url.host()));
-    } else {
-      base::string16 formattedURL = url_formatter::FormatUrl(
-          self.url, url_formatter::kFormatUrlOmitNothing,
-          net::UnescapeRule::NORMAL, nullptr, nullptr, nullptr);
-      if (base::i18n::IsRTL()) {
-        base::i18n::WrapStringWithLTRFormatting(&formattedURL);
-      }
-      self.title = base::SysUTF16ToNSString(formattedURL);
-    }
-
-    // |self.view| setup.
-    CGRect windowBounds = [UIApplication sharedApplication].keyWindow.bounds;
-    UIView* view = [[UIView alloc] initWithFrame:windowBounds];
-    [view setBackgroundColor:[UIColor whiteColor]];
-    [view setAutoresizingMask:(UIViewAutoresizingFlexibleWidth |
-                               UIViewAutoresizingFlexibleHeight)];
-    self.view = view;
-
-    // |self.titleLabel| setup.
-    CGRect titleLabelFrame = windowBounds;
-    titleLabelFrame.origin.x += kHorizontalPadding;
-    titleLabelFrame.size.width -= 2.0 * kHorizontalPadding;
-    titleLabelFrame.origin.y += kTitleLabelTopPadding;
-    titleLabelFrame.size.height = kTitleLabelHeight;
-    _titleLabel = [[UILabel alloc] initWithFrame:titleLabelFrame];
-    _titleLabel.text =
-        l10n_util::GetNSString(IDS_ERRORPAGES_HEADING_NOT_AVAILABLE);
-    _titleLabel.autoresizingMask = (UIViewAutoresizingFlexibleBottomMargin |
-                                    UIViewAutoresizingFlexibleWidth);
-    _titleLabel.font =
-        [UIFont fontWithName:@"Helvetica-Bold" size:kTitleLabelFontSize];
-    _titleLabel.textAlignment = NSTextAlignmentCenter;
-    [self.view addSubview:_titleLabel];
-
-    // |self.descriptionView| setup.
-    CGRect descriptionViewFrame = windowBounds;
-    descriptionViewFrame.origin.x += kHorizontalPadding;
-    descriptionViewFrame.size.width -= 2 * kHorizontalPadding;
-    descriptionViewFrame.origin.y = kDescriptionViewTopPadding;
-    descriptionViewFrame.size.height = CGRectGetHeight(windowBounds) -
-                                       descriptionViewFrame.origin.y -
-                                       kDescriptionViewBottomPadding;
-    _descriptionView = [[UITextView alloc] initWithFrame:descriptionViewFrame];
-    _descriptionView.text = l10n_util::GetNSStringF(
-        IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE_NO_EMPHASIS,
-        base::UTF8ToUTF16(self.url.spec()));
-    _descriptionView.autoresizingMask =
-        UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
-    _descriptionView.font = [UIFont systemFontOfSize:kDescriptionViewFontSize];
-    _descriptionView.editable = NO;
-    [self.view addSubview:_descriptionView];
-  }
-  return self;
-}
-
-- (instancetype)initWithNibName:(NSString*)nibName
-                            url:(const GURL&)url NS_UNAVAILABLE {
-  NOTREACHED();
-  return nil;
-}
-
-- (void)setDescriptionText:(NSString*)descriptionText {
-  _descriptionText = [descriptionText copy];
-  _descriptionView.text = _descriptionText;
-}
-
-@end
diff --git a/ios/chrome/browser/ui/page_not_available_controller_unittest.mm b/ios/chrome/browser/ui/page_not_available_controller_unittest.mm
deleted file mode 100644
index a699a95..0000000
--- a/ios/chrome/browser/ui/page_not_available_controller_unittest.mm
+++ /dev/null
@@ -1,27 +0,0 @@
-// Copyright 2015 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 "ios/chrome/browser/ui/page_not_available_controller.h"
-
-#include "base/logging.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "testing/platform_test.h"
-
-#if !defined(__has_feature) || !__has_feature(objc_arc)
-#error "This file requires ARC support."
-#endif
-
-namespace {
-
-using PageNotAvailableControllerTest = PlatformTest;
-
-TEST_F(PageNotAvailableControllerTest, TestInitWithURL) {
-  GURL url = GURL("http://foo.bar.com");
-  PageNotAvailableController* controller =
-      [[PageNotAvailableController alloc] initWithUrl:url];
-  EXPECT_EQ(url, controller.url);
-  EXPECT_TRUE(controller.view);
-}
-
-}  // namespace