Commit 3ab78ff2 authored by edchin's avatar edchin Committed by Commit Bot

[ios] Fix snapshot when switching incognito mode

This fixes a bug in which snapshots are blank when opening a new tab
from an incognito tab (and vice versa).

This fixes two issues:
1) We must take a snapshot of the current tab before switching to
a different incognito mode. This was not happening.
2) We must prevent blank snapshots from overwriting perfectly good ones.

Bug: 778235
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I761244b2459d0f38f999d630d19643764533ebaf
Reviewed-on: https://chromium-review.googlesource.com/764854Reviewed-by: default avataredchin <edchin@chromium.org>
Reviewed-by: default avatarKurt Horimoto <kkhorimoto@chromium.org>
Commit-Queue: edchin <edchin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#515998}
parent 49c07418
...@@ -4340,6 +4340,12 @@ bubblePresenterForFeature:(const base::Feature&)feature ...@@ -4340,6 +4340,12 @@ bubblePresenterForFeature:(const base::Feature&)feature
- (void)openNewTab:(OpenNewTabCommand*)command { - (void)openNewTab:(OpenNewTabCommand*)command {
if (self.isOffTheRecord != command.incognito) { if (self.isOffTheRecord != command.incognito) {
// Must take a snapshot of the tab before we switch the incognito mode
// because the currentTab will change after the switch.
Tab* currentTab = [_model currentTab];
if (currentTab) {
[currentTab updateSnapshotWithOverlay:YES visibleFrameOnly:YES];
}
// Not for this browser state, send it on its way. // Not for this browser state, send it on its way.
[self.dispatcher switchModesAndOpenNewTab:command]; [self.dispatcher switchModesAndOpenNewTab:command];
return; return;
...@@ -4376,8 +4382,15 @@ bubblePresenterForFeature:(const base::Feature&)feature ...@@ -4376,8 +4382,15 @@ bubblePresenterForFeature:(const base::Feature&)feature
DCHECK(self.visible || self.dismissingModal || DCHECK(self.visible || self.dismissingModal ||
(TabSwitcherPresentsBVCEnabled() && (TabSwitcherPresentsBVCEnabled() &&
self.parentViewController.isBeingPresented)); self.parentViewController.isBeingPresented));
// In most cases, we want to take a snapshot of the current tab before opening
// a new tab. However, if the current tab is not fully visible (did not finish
// |-viewDidAppear:|, then we must not take an empty snapshot, replacing an
// existing snapshot for the tab. This can happen when a new regular tab is
// opened from an incognito tab. A different BVC is displayed, which may not
// have enough time to finish appearing before a snapshot is requested.
Tab* currentTab = [_model currentTab]; Tab* currentTab = [_model currentTab];
if (currentTab) { if (currentTab && self.viewVisible) {
[currentTab updateSnapshotWithOverlay:YES visibleFrameOnly:YES]; [currentTab updateSnapshotWithOverlay:YES visibleFrameOnly:YES];
} }
[self addSelectedTabWithURL:GURL(kChromeUINewTabURL) [self addSelectedTabWithURL:GURL(kChromeUINewTabURL)
......
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