Commit 3c86aa45 authored by Mark Cogan's avatar Mark Cogan Committed by Commit Bot

[iOS] Decouple completion handler from new tab creation in BVC.

This CL decouples the addition of a tab completion block from the other
tab opening code in the BVC. This will allow the tab opening logic
(which is just tab model manipulation) to be moved out of the BVC.

Bug: 903338
Change-Id: Ibc7ba411c2cbec58dd11ac7cb65e2b9284eb811c
Reviewed-on: https://chromium-review.googlesource.com/c/1323558
Commit-Queue: Mark Cogan <marq@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606825}
parent 5c30a792
...@@ -77,11 +77,11 @@ typedef Tab* (^mock_gurl_nsuinteger_pagetransition)(const GURL&, ...@@ -77,11 +77,11 @@ typedef Tab* (^mock_gurl_nsuinteger_pagetransition)(const GURL&,
- (Tab*)addSelectedTabWithURL:(const GURL&)url - (Tab*)addSelectedTabWithURL:(const GURL&)url
atIndex:(NSUInteger)position atIndex:(NSUInteger)position
transition:(ui::PageTransition)transition transition:(ui::PageTransition)transition;
tabAddedCompletion:(ProceduralBlock)completion;
- (void)expectNewForegroundTab; - (void)expectNewForegroundTab;
- (void)setActive:(BOOL)active; - (void)setActive:(BOOL)active;
- (TabModel*)tabModel; - (TabModel*)tabModel;
- (void)appendTabAddedCompletion:(ProceduralBlock)completion;
- (void)browserStateDestroyed; - (void)browserStateDestroyed;
- (void)shutdown; - (void)shutdown;
@end @end
...@@ -96,12 +96,10 @@ typedef Tab* (^mock_gurl_nsuinteger_pagetransition)(const GURL&, ...@@ -96,12 +96,10 @@ typedef Tab* (^mock_gurl_nsuinteger_pagetransition)(const GURL&,
- (Tab*)addSelectedTabWithURL:(const GURL&)url - (Tab*)addSelectedTabWithURL:(const GURL&)url
atIndex:(NSUInteger)position atIndex:(NSUInteger)position
transition:(ui::PageTransition)transition transition:(ui::PageTransition)transition {
tabAddedCompletion:(ProceduralBlock)completion {
self.tabURL = url; self.tabURL = url;
self.position = position; self.position = position;
self.transition = transition; self.transition = transition;
self.foregroundTabWasAddedCompletionBlock = completion;
return nil; return nil;
} }
...@@ -127,6 +125,10 @@ typedef Tab* (^mock_gurl_nsuinteger_pagetransition)(const GURL&, ...@@ -127,6 +125,10 @@ typedef Tab* (^mock_gurl_nsuinteger_pagetransition)(const GURL&,
return nil; return nil;
} }
- (void)appendTabAddedCompletion:(ProceduralBlock)completion {
self.foregroundTabWasAddedCompletionBlock = completion;
}
- (void)browserStateDestroyed { - (void)browserStateDestroyed {
// no-op // no-op
} }
......
...@@ -2229,10 +2229,10 @@ enum class ShowTabSwitcherSnapshotResult { ...@@ -2229,10 +2229,10 @@ enum class ShowTabSwitcherSnapshotResult {
Tab* currentTabInTargetBVC = [[targetBVC tabModel] currentTab]; Tab* currentTabInTargetBVC = [[targetBVC tabModel] currentTab];
if (!(currentTabInTargetBVC.webState && if (!(currentTabInTargetBVC.webState &&
IsURLNtp(currentTabInTargetBVC.webState->GetVisibleURL()))) { IsURLNtp(currentTabInTargetBVC.webState->GetVisibleURL()))) {
[targetBVC appendTabAddedCompletion:tabOpenedCompletion];
return [targetBVC addSelectedTabWithURL:URL return [targetBVC addSelectedTabWithURL:URL
atIndex:NSNotFound atIndex:NSNotFound
transition:transition transition:transition];
tabAddedCompletion:tabOpenedCompletion];
} }
Tab* newTab = currentTabInTargetBVC; Tab* newTab = currentTabInTargetBVC;
...@@ -2325,10 +2325,10 @@ enum class ShowTabSwitcherSnapshotResult { ...@@ -2325,10 +2325,10 @@ enum class ShowTabSwitcherSnapshotResult {
targetMode == ApplicationMode::NORMAL targetMode == ApplicationMode::NORMAL
? TabSwitcherDismissalMode::NORMAL ? TabSwitcherDismissalMode::NORMAL
: TabSwitcherDismissalMode::INCOGNITO; : TabSwitcherDismissalMode::INCOGNITO;
[targetBVC appendTabAddedCompletion:tabOpenedCompletion];
tab = [targetBVC addSelectedTabWithURL:url tab = [targetBVC addSelectedTabWithURL:url
atIndex:tabIndex atIndex:tabIndex
transition:transition transition:transition];
tabAddedCompletion:tabOpenedCompletion];
} else { } else {
// Voice search, QRScanner and the omnibox are presented by the BVC. // Voice search, QRScanner and the omnibox are presented by the BVC.
// They must be started after the BVC view is added in the hierarchy. // They must be started after the BVC view is added in the hierarchy.
......
...@@ -112,11 +112,6 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint ...@@ -112,11 +112,6 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint
- (void)openNewTabFromOriginPoint:(CGPoint)originPoint - (void)openNewTabFromOriginPoint:(CGPoint)originPoint
focusOmnibox:(BOOL)focusOmnibox; focusOmnibox:(BOOL)focusOmnibox;
// Add a new tab with the given url, appends it to the end of the model,
// and makes it the selected tab. The selected tab is returned.
- (Tab*)addSelectedTabWithURL:(const GURL&)url
transition:(ui::PageTransition)transition;
// Add a new tab with the given url, at the given |position|, // Add a new tab with the given url, at the given |position|,
// and makes it the selected tab. The selected tab is returned. // and makes it the selected tab. The selected tab is returned.
// If |position| == NSNotFound the tab will be added at the end of the stack. // If |position| == NSNotFound the tab will be added at the end of the stack.
...@@ -124,14 +119,10 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint ...@@ -124,14 +119,10 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint
atIndex:(NSUInteger)position atIndex:(NSUInteger)position
transition:(ui::PageTransition)transition; transition:(ui::PageTransition)transition;
// Add a new tab with the given url, at the given |position|, // Adds |tabAddedCompletion| to the completion block (if any) that will be run
// and makes it the selected tab. The selected tab is returned. // the next time a tab is added to the TabModel this object was initialized
// If |position| == NSNotFound the tab will be added at the end of the stack. // with.
// |tabAddedCompletion| is called after the tab is added (if not nil). - (void)appendTabAddedCompletion:(ProceduralBlock)tabAddedCompletion;
- (Tab*)addSelectedTabWithURL:(const GURL&)url
atIndex:(NSUInteger)position
transition:(ui::PageTransition)transition
tabAddedCompletion:(ProceduralBlock)tabAddedCompletion;
// Informs the BVC that a new foreground tab is about to be opened. This is // Informs the BVC that a new foreground tab is about to be opened. This is
// intended to be called before setWebUsageSuspended:NO in cases where a new tab // intended to be called before setWebUsageSuspended:NO in cases where a new tab
......
...@@ -835,8 +835,7 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -835,8 +835,7 @@ NSString* const kBrowserViewControllerSnackbarCategory =
- (Tab*)addSelectedTabWithURL:(const GURL&)url - (Tab*)addSelectedTabWithURL:(const GURL&)url
postData:(TemplateURLRef::PostContent*)postData postData:(TemplateURLRef::PostContent*)postData
atIndex:(NSUInteger)position atIndex:(NSUInteger)position
transition:(ui::PageTransition)transition transition:(ui::PageTransition)transition;
tabAddedCompletion:(ProceduralBlock)tabAddedCompletion;
// Whether the given tab's URL is an application specific URL. // Whether the given tab's URL is an application specific URL.
- (BOOL)isTabNativePage:(Tab*)tab; - (BOOL)isTabNativePage:(Tab*)tab;
// Returns the view to use when animating a page in or out, positioning it to // Returns the view to use when animating a page in or out, positioning it to
...@@ -1439,34 +1438,32 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint { ...@@ -1439,34 +1438,32 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint {
->UpdateSnapshot(/*with_overlays=*/true, /*visible_frame_only=*/true); ->UpdateSnapshot(/*with_overlays=*/true, /*visible_frame_only=*/true);
} }
[self addSelectedTabWithURL:GURL(kChromeUINewTabURL) [self addSelectedTabWithURL:GURL(kChromeUINewTabURL)
transition:ui::PAGE_TRANSITION_TYPED];
}
- (Tab*)addSelectedTabWithURL:(const GURL&)url
transition:(ui::PageTransition)transition {
return [self addSelectedTabWithURL:url
atIndex:self.tabModel.count atIndex:self.tabModel.count
transition:transition]; transition:ui::PAGE_TRANSITION_TYPED];
} }
- (Tab*)addSelectedTabWithURL:(const GURL&)url - (Tab*)addSelectedTabWithURL:(const GURL&)url
atIndex:(NSUInteger)position atIndex:(NSUInteger)position
transition:(ui::PageTransition)transition { transition:(ui::PageTransition)transition {
return [self addSelectedTabWithURL:url return [self addSelectedTabWithURL:url
postData:NULL
atIndex:position atIndex:position
transition:transition transition:transition];
tabAddedCompletion:nil];
} }
- (Tab*)addSelectedTabWithURL:(const GURL&)url - (void)appendTabAddedCompletion:(ProceduralBlock)tabAddedCompletion {
atIndex:(NSUInteger)position if (tabAddedCompletion) {
transition:(ui::PageTransition)transition if (self.foregroundTabWasAddedCompletionBlock) {
tabAddedCompletion:(ProceduralBlock)tabAddedCompletion { ProceduralBlock oldForegroundTabWasAddedCompletionBlock =
return [self addSelectedTabWithURL:url self.foregroundTabWasAddedCompletionBlock;
postData:NULL self.foregroundTabWasAddedCompletionBlock = ^{
atIndex:position oldForegroundTabWasAddedCompletionBlock();
transition:transition tabAddedCompletion();
tabAddedCompletion:tabAddedCompletion]; };
} else {
self.foregroundTabWasAddedCompletionBlock = tabAddedCompletion;
}
}
} }
- (void)expectNewForegroundTab { - (void)expectNewForegroundTab {
...@@ -2852,15 +2849,13 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint { ...@@ -2852,15 +2849,13 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint {
return [self addSelectedTabWithURL:url return [self addSelectedTabWithURL:url
postData:postData postData:postData
atIndex:self.tabModel.count atIndex:self.tabModel.count
transition:transition transition:transition];
tabAddedCompletion:nil];
} }
- (Tab*)addSelectedTabWithURL:(const GURL&)URL - (Tab*)addSelectedTabWithURL:(const GURL&)URL
postData:(TemplateURLRef::PostContent*)postData postData:(TemplateURLRef::PostContent*)postData
atIndex:(NSUInteger)position atIndex:(NSUInteger)position
transition:(ui::PageTransition)transition transition:(ui::PageTransition)transition {
tabAddedCompletion:(ProceduralBlock)tabAddedCompletion {
if (position == NSNotFound) if (position == NSNotFound)
position = self.tabModel.count; position = self.tabModel.count;
DCHECK(position <= self.tabModel.count); DCHECK(position <= self.tabModel.count);
...@@ -2877,19 +2872,6 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint { ...@@ -2877,19 +2872,6 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint {
params.extra_headers = @{@"Content-Type" : contentType}; params.extra_headers = @{@"Content-Type" : contentType};
} }
if (tabAddedCompletion) {
if (self.foregroundTabWasAddedCompletionBlock) {
ProceduralBlock oldForegroundTabWasAddedCompletionBlock =
self.foregroundTabWasAddedCompletionBlock;
self.foregroundTabWasAddedCompletionBlock = ^{
oldForegroundTabWasAddedCompletionBlock();
tabAddedCompletion();
};
} else {
self.foregroundTabWasAddedCompletionBlock = tabAddedCompletion;
}
}
Tab* tab = [self.tabModel insertTabWithLoadParams:params Tab* tab = [self.tabModel insertTabWithLoadParams:params
opener:nil opener:nil
openedByDOM:NO openedByDOM:NO
...@@ -5323,7 +5305,9 @@ nativeContentHeaderHeightForPreloadController:(PreloadController*)controller ...@@ -5323,7 +5305,9 @@ nativeContentHeaderHeightForPreloadController:(PreloadController*)controller
- (void)captivePortalDetectorTabHelper: - (void)captivePortalDetectorTabHelper:
(CaptivePortalDetectorTabHelper*)tabHelper (CaptivePortalDetectorTabHelper*)tabHelper
connectWithLandingURL:(const GURL&)landingURL { connectWithLandingURL:(const GURL&)landingURL {
[self addSelectedTabWithURL:landingURL transition:ui::PAGE_TRANSITION_TYPED]; [self addSelectedTabWithURL:landingURL
atIndex:self.tabModel.count
transition:ui::PAGE_TRANSITION_TYPED];
} }
#pragma mark - PageInfoPresentation #pragma mark - PageInfoPresentation
......
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