Commit 2c6af4ab authored by edchin's avatar edchin Committed by Commit Bot

[ios] Remove rootViewController from /download

A method (-controllerForUnhandledContent:) was in CRWWebDelegate when
it belongs in CRWNativeContentProvider protocol.
This helped pull the implementation out of tab.mm and into the BVC,
which can provide a base view controller for presenting UI,
instead of using rootViewController for presentation.

Bug: 791206
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: If82dcb4f16a64d5e1fef99e2805588e92f2ca4d9
Reviewed-on: https://chromium-review.googlesource.com/807306
Commit-Queue: edchin <edchin@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Reviewed-by: default avataredchin <edchin@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521591}
parent e2620c99
...@@ -341,6 +341,15 @@ bool IsPrerenderTabEvictionExperimentalGroup() { ...@@ -341,6 +341,15 @@ bool IsPrerenderTabEvictionExperimentalGroup() {
return nil; return nil;
} }
// Override the CRWNativeContentProvider methods to cancel any prerenders that
// require native content.
- (id<CRWNativeContent>)controllerForUnhandledContentAtURL:(const GURL&)URL
webState:
(web::WebState*)webState {
[self schedulePrerenderCancel];
return nil;
}
#pragma mark - #pragma mark -
#pragma mark Private Methods #pragma mark Private Methods
......
...@@ -117,7 +117,6 @@ source_set("tabs_internal") { ...@@ -117,7 +117,6 @@ source_set("tabs_internal") {
"//ios/chrome/browser/ui:ui_internal", "//ios/chrome/browser/ui:ui_internal",
"//ios/chrome/browser/ui/alert_coordinator", "//ios/chrome/browser/ui/alert_coordinator",
"//ios/chrome/browser/ui/commands", "//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/ui/download",
"//ios/chrome/browser/ui/fullscreen", "//ios/chrome/browser/ui/fullscreen",
"//ios/chrome/browser/ui/fullscreen:legacy_fullscreen", "//ios/chrome/browser/ui/fullscreen:legacy_fullscreen",
"//ios/chrome/browser/ui/overscroll_actions", "//ios/chrome/browser/ui/overscroll_actions",
......
...@@ -78,7 +78,6 @@ ...@@ -78,7 +78,6 @@
#import "ios/chrome/browser/ui/commands/open_new_tab_command.h" #import "ios/chrome/browser/ui/commands/open_new_tab_command.h"
#import "ios/chrome/browser/ui/commands/open_url_command.h" #import "ios/chrome/browser/ui/commands/open_url_command.h"
#import "ios/chrome/browser/ui/commands/show_signin_command.h" #import "ios/chrome/browser/ui/commands/show_signin_command.h"
#import "ios/chrome/browser/ui/download/download_manager_controller.h"
#import "ios/chrome/browser/ui/fullscreen/fullscreen_features.h" #import "ios/chrome/browser/ui/fullscreen/fullscreen_features.h"
#import "ios/chrome/browser/ui/fullscreen/legacy_fullscreen_controller.h" #import "ios/chrome/browser/ui/fullscreen/legacy_fullscreen_controller.h"
#import "ios/chrome/browser/ui/open_in_controller.h" #import "ios/chrome/browser/ui/open_in_controller.h"
...@@ -654,15 +653,6 @@ void TabInfoBarObserver::OnInfoBarReplaced(infobars::InfoBar* old_infobar, ...@@ -654,15 +653,6 @@ void TabInfoBarObserver::OnInfoBarReplaced(infobars::InfoBar* old_infobar,
return _openInController; return _openInController;
} }
- (id<CRWNativeContent>)controllerForUnhandledContentAtURL:(const GURL&)url {
// Shows download manager UI for unhandled content.
DownloadManagerController* downloadController =
[[DownloadManagerController alloc] initWithWebState:self.webState
downloadURL:url];
[downloadController start];
return downloadController;
}
- (void)handleExportableFile:(net::HttpResponseHeaders*)headers { - (void)handleExportableFile:(net::HttpResponseHeaders*)headers {
// Only "application/pdf" is supported for now. // Only "application/pdf" is supported for now.
if (self.webState->GetContentsMimeType() != "application/pdf") if (self.webState->GetContentsMimeType() != "application/pdf")
......
...@@ -310,6 +310,7 @@ source_set("ui_internal") { ...@@ -310,6 +310,7 @@ source_set("ui_internal") {
"//ios/chrome/browser/ui/content_suggestions:content_suggestions_constant", "//ios/chrome/browser/ui/content_suggestions:content_suggestions_constant",
"//ios/chrome/browser/ui/context_menu", "//ios/chrome/browser/ui/context_menu",
"//ios/chrome/browser/ui/dialogs:dialogs_internal", "//ios/chrome/browser/ui/dialogs:dialogs_internal",
"//ios/chrome/browser/ui/download",
"//ios/chrome/browser/ui/elements:elements_internal", "//ios/chrome/browser/ui/elements:elements_internal",
"//ios/chrome/browser/ui/external_search", "//ios/chrome/browser/ui/external_search",
"//ios/chrome/browser/ui/find_bar", "//ios/chrome/browser/ui/find_bar",
......
...@@ -138,6 +138,7 @@ ...@@ -138,6 +138,7 @@
#import "ios/chrome/browser/ui/context_menu/context_menu_coordinator.h" #import "ios/chrome/browser/ui/context_menu/context_menu_coordinator.h"
#import "ios/chrome/browser/ui/dialogs/dialog_presenter.h" #import "ios/chrome/browser/ui/dialogs/dialog_presenter.h"
#import "ios/chrome/browser/ui/dialogs/java_script_dialog_presenter_impl.h" #import "ios/chrome/browser/ui/dialogs/java_script_dialog_presenter_impl.h"
#import "ios/chrome/browser/ui/download/download_manager_controller.h"
#import "ios/chrome/browser/ui/elements/activity_overlay_coordinator.h" #import "ios/chrome/browser/ui/elements/activity_overlay_coordinator.h"
#import "ios/chrome/browser/ui/external_file_controller.h" #import "ios/chrome/browser/ui/external_file_controller.h"
#import "ios/chrome/browser/ui/external_search/external_search_coordinator.h" #import "ios/chrome/browser/ui/external_search/external_search_coordinator.h"
...@@ -3555,6 +3556,17 @@ bubblePresenterForFeature:(const base::Feature&)feature ...@@ -3555,6 +3556,17 @@ bubblePresenterForFeature:(const base::Feature&)feature
return nativeController; return nativeController;
} }
- (id<CRWNativeContent>)controllerForUnhandledContentAtURL:(const GURL&)URL
webState:
(web::WebState*)webState {
DownloadManagerController* downloadController =
[[DownloadManagerController alloc] initWithWebState:webState
downloadURL:URL
baseViewController:self];
[downloadController start];
return downloadController;
}
- (id)nativeControllerForTab:(Tab*)tab { - (id)nativeControllerForTab:(Tab*)tab {
id nativeController = tab.webController.nativeController; id nativeController = tab.webController.nativeController;
return nativeController ? nativeController : _temporaryNativeController; return nativeController ? nativeController : _temporaryNativeController;
......
...@@ -23,9 +23,10 @@ class WebState; ...@@ -23,9 +23,10 @@ class WebState;
// Initializes a controller for content from |url| using |webState| to provide // Initializes a controller for content from |url| using |webState| to provide
// the context to open a controller that allows the user to install Google Drive // the context to open a controller that allows the user to install Google Drive
// if they don't have it installed. // if they don't have it installed. Present UI from |baseViewController|.
- (instancetype)initWithWebState:(web::WebState*)webState - (instancetype)initWithWebState:(web::WebState*)webState
downloadURL:(const GURL&)url; downloadURL:(const GURL&)url
baseViewController:(UIViewController*)baseViewController;
// Starts loading the data for the file at the url passed into the // Starts loading the data for the file at the url passed into the
// initializer. This should only be called once, immediately after // initializer. This should only be called once, immediately after
......
...@@ -490,6 +490,9 @@ class DownloadContentDelegate : public URLFetcherDelegate { ...@@ -490,6 +490,9 @@ class DownloadContentDelegate : public URLFetcherDelegate {
// downloaded. // downloaded.
@property(nonatomic) double fractionDownloaded; @property(nonatomic) double fractionDownloaded;
// The base view controller from which to present UI.
@property(nonatomic, readonly, weak) UIViewController* baseViewController;
@end @end
@implementation DownloadManagerController @implementation DownloadManagerController
...@@ -520,9 +523,11 @@ class DownloadContentDelegate : public URLFetcherDelegate { ...@@ -520,9 +523,11 @@ class DownloadContentDelegate : public URLFetcherDelegate {
@synthesize fileTypeLabelCentered = _fileTypeLabelCentered; @synthesize fileTypeLabelCentered = _fileTypeLabelCentered;
@synthesize downloadStartedTime = _downloadStartedTime; @synthesize downloadStartedTime = _downloadStartedTime;
@synthesize fractionDownloaded = _fractionDownloaded; @synthesize fractionDownloaded = _fractionDownloaded;
@synthesize baseViewController = _baseViewController;
- (instancetype)initWithWebState:(web::WebState*)webState - (instancetype)initWithWebState:(web::WebState*)webState
downloadURL:(const GURL&)url { downloadURL:(const GURL&)url
baseViewController:(UIViewController*)baseViewController {
self = [super initWithNibName:@"DownloadManagerController" url:url]; self = [super initWithNibName:@"DownloadManagerController" url:url];
if (self) { if (self) {
_downloadManagerId = g_download_manager_id++; _downloadManagerId = g_download_manager_id++;
...@@ -532,6 +537,7 @@ class DownloadContentDelegate : public URLFetcherDelegate { ...@@ -532,6 +537,7 @@ class DownloadContentDelegate : public URLFetcherDelegate {
_headFetcherDelegate.reset(new DownloadHeadDelegate(self)); _headFetcherDelegate.reset(new DownloadHeadDelegate(self));
_contentFetcherDelegate.reset(new DownloadContentDelegate(self)); _contentFetcherDelegate.reset(new DownloadContentDelegate(self));
_downloadFilePath = base::FilePath(); _downloadFilePath = base::FilePath();
_baseViewController = baseViewController;
[_documentContainer [_documentContainer
setBackgroundColor:UIColorFromRGB(kUndownloadedDocumentColor)]; setBackgroundColor:UIColorFromRGB(kUndownloadedDocumentColor)];
...@@ -1037,19 +1043,15 @@ class DownloadContentDelegate : public URLFetcherDelegate { ...@@ -1037,19 +1043,15 @@ class DownloadContentDelegate : public URLFetcherDelegate {
#pragma mark - Errors #pragma mark - Errors
- (void)displayUnableToOpenFileDialog { - (void)displayUnableToOpenFileDialog {
// This code is called inside a xib file, I am using the topViewController.
UIViewController* topViewController =
[[[UIApplication sharedApplication] keyWindow] rootViewController];
NSString* title = NSString* title =
l10n_util::GetNSString(IDS_IOS_DOWNLOAD_MANAGER_UNABLE_TO_OPEN_FILE); l10n_util::GetNSString(IDS_IOS_DOWNLOAD_MANAGER_UNABLE_TO_OPEN_FILE);
NSString* message = NSString* message =
l10n_util::GetNSString(IDS_IOS_DOWNLOAD_MANAGER_NO_APP_MESSAGE); l10n_util::GetNSString(IDS_IOS_DOWNLOAD_MANAGER_NO_APP_MESSAGE);
_alertCoordinator = _alertCoordinator = [[AlertCoordinator alloc]
[[AlertCoordinator alloc] initWithBaseViewController:topViewController initWithBaseViewController:self.baseViewController
title:title title:title
message:message]; message:message];
StoreKitTabHelper* tabHelper = StoreKitTabHelper::FromWebState(_webState); StoreKitTabHelper* tabHelper = StoreKitTabHelper::FromWebState(_webState);
if (tabHelper) { if (tabHelper) {
......
...@@ -63,7 +63,8 @@ class DownloadManagerControllerTest : public ChromeWebTest { ...@@ -63,7 +63,8 @@ class DownloadManagerControllerTest : public ChromeWebTest {
helper->SetLauncher(mock_launcher); helper->SetLauncher(mock_launcher);
_controller = _controller =
[[DownloadManagerController alloc] initWithWebState:web_state() [[DownloadManagerController alloc] initWithWebState:web_state()
downloadURL:kTestURL]; downloadURL:kTestURL
baseViewController:nil];
} }
std::unique_ptr<net::TestURLFetcherFactory> _fetcher_factory; std::unique_ptr<net::TestURLFetcherFactory> _fetcher_factory;
__strong DownloadManagerController* _controller; __strong DownloadManagerController* _controller;
......
...@@ -39,4 +39,11 @@ ...@@ -39,4 +39,11 @@
return nativeContent == _nativeContent.end() ? nil : nativeContent->second; return nativeContent == _nativeContent.end() ? nil : nativeContent->second;
} }
- (id<CRWNativeContent>)controllerForUnhandledContentAtURL:(const GURL&)URL
webState:
(web::WebState*)webState {
auto nativeContent = _nativeContent.find(URL);
return nativeContent == _nativeContent.end() ? nil : nativeContent->second;
}
@end @end
...@@ -40,6 +40,15 @@ class WebState; ...@@ -40,6 +40,15 @@ class WebState;
withError:(NSError*)error withError:(NSError*)error
isPost:(BOOL)isPost; isPost:(BOOL)isPost;
// Returns an autoreleased controller for driving a native view contained
// within the web content area for unhandled content at |URL|. |webState|
// triggered the navigation to |URL|.
// TODO(crbug.com/791806) DEPRECATED! Clients must use web::DownloadController
// for renderer initiated downloads.
- (id<CRWNativeContent>)controllerForUnhandledContentAtURL:(const GURL&)URL
webState:
(web::WebState*)webState;
@end @end
#endif // IOS_WEB_PUBLIC_WEB_STATE_UI_CRW_NATIVE_CONTENT_PROVIDER_H_ #endif // IOS_WEB_PUBLIC_WEB_STATE_UI_CRW_NATIVE_CONTENT_PROVIDER_H_
...@@ -60,12 +60,6 @@ class GURL; ...@@ -60,12 +60,6 @@ class GURL;
- (BOOL)webController:(CRWWebController*)webController - (BOOL)webController:(CRWWebController*)webController
shouldOpenExternalURL:(const GURL&)URL; shouldOpenExternalURL:(const GURL&)URL;
// Called to ask the delegate for a controller to display the given url,
// which contained content that the UIWebView couldn't display. Returns
// the native controller to display if the delegate can handle the url,
// or nil otherwise.
- (id<CRWNativeContent>)controllerForUnhandledContentAtURL:(const GURL&)url;
// Called to retrieve the height of any header that is overlaying on top of the // Called to retrieve the height of any header that is overlaying on top of the
// web view. This can be used to implement, for e.g. a toolbar that changes // web view. This can be used to implement, for e.g. a toolbar that changes
// height dynamically. Returning a non-zero height affects the visible frame // height dynamically. Returning a non-zero height affects the visible frame
......
...@@ -2955,11 +2955,10 @@ registerLoadRequestForURL:(const GURL&)requestURL ...@@ -2955,11 +2955,10 @@ registerLoadRequestForURL:(const GURL&)requestURL
![MIMEType isEqualToString:@"application/vnd.apple.pkpass"]) { ![MIMEType isEqualToString:@"application/vnd.apple.pkpass"]) {
// This block is executed to handle legacy download navigation. // This block is executed to handle legacy download navigation.
const GURL errorGURL = net::GURLWithNSURL(errorURL); const GURL errorGURL = net::GURLWithNSURL(errorURL);
if (errorGURL.is_valid() && if (errorGURL.is_valid()) {
[_delegate respondsToSelector:@selector
(controllerForUnhandledContentAtURL:)]) {
id<CRWNativeContent> controller = id<CRWNativeContent> controller =
[_delegate controllerForUnhandledContentAtURL:errorGURL]; [_nativeProvider controllerForUnhandledContentAtURL:errorGURL
webState:self.webState];
if (controller) { if (controller) {
[self loadCompleteWithSuccess:NO forNavigation:navigation]; [self loadCompleteWithSuccess:NO forNavigation:navigation];
[self removeWebView]; [self removeWebView];
......
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