Commit 00c53980 authored by David Jean's avatar David Jean Committed by Commit Bot

[ios] fix crash and mismatch incognito/normal in history

Since history always has normal browser state, even in incognito, pass down a
new load strategy forcing incognito from main_controller.
Catch a load in current tab for the other mode and forward to other service.
Fix crash with calling pre-render before checking if we have a web state.

Bug: 960728, 960732, 947005
Change-Id: I591e60ea7bf1e08ac27d6b63b8ba60fffa03e938
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1599466
Commit-Queue: David Jean <djean@chromium.org>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#658544}
parent a24e5d11
......@@ -1480,7 +1480,9 @@ enum class EnterTabSwitcherSnapshotResult {
_historyCoordinator =
[[HistoryCoordinator alloc] initWithBaseViewController:self.currentBVC
browserState:_mainBrowserState];
_historyCoordinator.loadStrategy = UrlLoadStrategy::NORMAL;
_historyCoordinator.loadStrategy = [self currentPageIsIncognito]
? UrlLoadStrategy::ALWAYS_IN_INCOGNITO
: UrlLoadStrategy::NORMAL;
_historyCoordinator.dispatcher = self.mainBVC.dispatcher;
[_historyCoordinator start];
}
......
......@@ -15,6 +15,7 @@ enum class UrlLoadStrategy {
NORMAL = 0,
ALWAYS_NEW_FOREGROUND_TAB = 1 << 0,
ALWAYS_IN_INCOGNITO = 1 << 1,
};
// UrlLoadingService wrapper around web::NavigationManager::WebLoadParams,
......
......@@ -17,6 +17,7 @@
#import "ios/chrome/browser/url_loading/app_url_loading_service.h"
#import "ios/chrome/browser/url_loading/url_loading_notifier.h"
#import "ios/chrome/browser/url_loading/url_loading_params.h"
#import "ios/chrome/browser/url_loading/url_loading_service_factory.h"
#import "ios/chrome/browser/url_loading/url_loading_util.h"
#import "ios/chrome/browser/web/load_timing_tab_helper.h"
#import "ios/chrome/browser/web_state_list/web_state_list.h"
......@@ -84,7 +85,21 @@ void UrlLoadingService::Load(const UrlLoadParams& params) {
Dispatch(fixed_params);
break;
}
default: {
case UrlLoadStrategy::ALWAYS_IN_INCOGNITO: {
ios::ChromeBrowserState* browser_state = browser_->GetBrowserState();
if (params.disposition == WindowOpenDisposition::CURRENT_TAB &&
!browser_state->IsOffTheRecord()) {
UrlLoadingServiceFactory::GetForBrowserState(
browser_state->GetOffTheRecordChromeBrowserState())
->Load(params);
} else {
UrlLoadParams fixed_params = params;
fixed_params.in_incognito = YES;
Dispatch(fixed_params);
}
break;
}
case UrlLoadStrategy::NORMAL: {
Dispatch(params);
break;
}
......@@ -128,24 +143,20 @@ void UrlLoadingService::LoadUrlInCurrentTab(const UrlLoadParams& params) {
return;
}
// Ask the prerender service to load this URL if it can, and return if it does
// so.
PrerenderService* prerenderService =
PrerenderServiceFactory::GetForBrowserState(browser_state);
WebStateList* web_state_list = browser_->GetWebStateList();
id<SessionWindowRestoring> restorer =
(id<SessionWindowRestoring>)browser_->GetTabModel();
if (prerenderService && prerenderService->MaybeLoadPrerenderedURL(
web_params.url, web_params.transition_type,
web_state_list, restorer)) {
notifier_->TabDidPrerenderUrl(web_params.url, web_params.transition_type);
return;
}
// Some URLs are not allowed while in incognito. If we are in incognito and
// load a disallowed URL, instead create a new tab not in the incognito state.
if (browser_state->IsOffTheRecord() &&
!IsURLAllowedInIncognito(web_params.url)) {
// Also if there's no current web state, that means there is no current tab
// to open in, so this also redirects to a new tab.
WebStateList* web_state_list = browser_->GetWebStateList();
web::WebState* current_web_state = web_state_list->GetActiveWebState();
if (!current_web_state || (browser_state->IsOffTheRecord() &&
!IsURLAllowedInIncognito(web_params.url))) {
if (prerenderService) {
prerenderService->CancelPrerender();
}
notifier_->TabFailedToLoadUrl(web_params.url, web_params.transition_type);
UrlLoadParams params =
UrlLoadParams::InNewTab(web_params.url, web_params.virtual_url);
......@@ -155,8 +166,16 @@ void UrlLoadingService::LoadUrlInCurrentTab(const UrlLoadParams& params) {
return;
}
web::WebState* current_web_state = web_state_list->GetActiveWebState();
DCHECK(current_web_state);
// Ask the prerender service to load this URL if it can, and return if it does
// so.
id<SessionWindowRestoring> restorer =
(id<SessionWindowRestoring>)browser_->GetTabModel();
if (prerenderService && prerenderService->MaybeLoadPrerenderedURL(
web_params.url, web_params.transition_type,
web_state_list, restorer)) {
notifier_->TabDidPrerenderUrl(web_params.url, web_params.transition_type);
return;
}
BOOL typedOrGeneratedTransition =
PageTransitionCoreTypeIs(web_params.transition_type,
......
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