Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: ios/chrome/browser/tabs/tab.mm

Issue 2782713002: Correct UIApplicationState check for sad tab test. (Closed)
Patch Set: nit Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "ios/chrome/browser/tabs/tab.h" 5 #import "ios/chrome/browser/tabs/tab.h"
6 6
7 #import <CoreLocation/CoreLocation.h> 7 #import <CoreLocation/CoreLocation.h>
8 #import <UIKit/UIKit.h> 8 #import <UIKit/UIKit.h>
9 9
10 #include <utility> 10 #include <utility>
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 // Tab.StateAtRendererTermination. Must be kept in sync with the UMA enum. 192 // Tab.StateAtRendererTermination. Must be kept in sync with the UMA enum.
193 enum class RendererTerminationTabState { 193 enum class RendererTerminationTabState {
194 // These two values are for when the app is in the foreground. 194 // These two values are for when the app is in the foreground.
195 FOREGROUND_TAB_FOREGROUND_APP = 0, 195 FOREGROUND_TAB_FOREGROUND_APP = 0,
196 BACKGROUND_TAB_FOREGROUND_APP, 196 BACKGROUND_TAB_FOREGROUND_APP,
197 // These are for when the app is in the background. 197 // These are for when the app is in the background.
198 FOREGROUND_TAB_BACKGROUND_APP, 198 FOREGROUND_TAB_BACKGROUND_APP,
199 BACKGROUND_TAB_BACKGROUND_APP, 199 BACKGROUND_TAB_BACKGROUND_APP,
200 TERMINATION_TAB_STATE_COUNT 200 TERMINATION_TAB_STATE_COUNT
201 }; 201 };
202
203 // Returns true if the application is in the background or inactive state.
204 bool IsApplicationStateNotActive(UIApplicationState state) {
205 return (state == UIApplicationStateBackground ||
206 state == UIApplicationStateInactive);
207 }
208
202 } // namespace 209 } // namespace
203 210
204 @interface Tab ()<CRWWebStateObserver, 211 @interface Tab ()<CRWWebStateObserver,
205 FindInPageControllerDelegate, 212 FindInPageControllerDelegate,
206 ReaderModeControllerDelegate> { 213 ReaderModeControllerDelegate> {
207 TabModel* parentTabModel_; // weak 214 TabModel* parentTabModel_; // weak
208 ios::ChromeBrowserState* browserState_; // weak 215 ios::ChromeBrowserState* browserState_; // weak
209 216
210 base::scoped_nsobject<OpenInController> openInController_; 217 base::scoped_nsobject<OpenInController> openInController_;
211 base::WeakNSProtocol<id<PassKitDialogProvider>> passKitDialogProvider_; 218 base::WeakNSProtocol<id<PassKitDialogProvider>> passKitDialogProvider_;
(...skipping 1692 matching lines...) Expand 10 before | Expand all | Expand 10 after
1904 if (securityStyle == web::SECURITY_STYLE_AUTHENTICATION_BROKEN) { 1911 if (securityStyle == web::SECURITY_STYLE_AUTHENTICATION_BROKEN) {
1905 [fullScreenController_ disableFullScreen]; 1912 [fullScreenController_ disableFullScreen];
1906 } 1913 }
1907 } 1914 }
1908 1915
1909 [parentTabModel_ notifyTabChanged:self]; 1916 [parentTabModel_ notifyTabChanged:self];
1910 [self updateFullscreenWithToolbarVisible:YES]; 1917 [self updateFullscreenWithToolbarVisible:YES];
1911 } 1918 }
1912 1919
1913 - (void)renderProcessGoneForWebState:(web::WebState*)webState { 1920 - (void)renderProcessGoneForWebState:(web::WebState*)webState {
1921 UIApplicationState state = [UIApplication sharedApplication].applicationState;
1922 BOOL applicationIsNotActive = IsApplicationStateNotActive(state);
1914 if (browserState_ && !browserState_->IsOffTheRecord()) { 1923 if (browserState_ && !browserState_->IsOffTheRecord()) {
1915 // Report the crash. 1924 // Report the crash.
1916 GetApplicationContext() 1925 GetApplicationContext()
1917 ->GetMetricsServicesManager() 1926 ->GetMetricsServicesManager()
1918 ->OnRendererProcessCrash(); 1927 ->OnRendererProcessCrash();
1919 1928
1920 // Log the tab state for the termination. 1929 // Log the tab state for the termination.
1921 RendererTerminationTabState tab_state = 1930 RendererTerminationTabState tab_state =
1922 visible_ ? RendererTerminationTabState::FOREGROUND_TAB_FOREGROUND_APP 1931 visible_ ? RendererTerminationTabState::FOREGROUND_TAB_FOREGROUND_APP
1923 : RendererTerminationTabState::BACKGROUND_TAB_FOREGROUND_APP; 1932 : RendererTerminationTabState::BACKGROUND_TAB_FOREGROUND_APP;
1924 if ([UIApplication sharedApplication].applicationState == 1933 if (applicationIsNotActive) {
1925 UIApplicationStateBackground) {
1926 tab_state = 1934 tab_state =
1927 visible_ ? RendererTerminationTabState::FOREGROUND_TAB_BACKGROUND_APP 1935 visible_ ? RendererTerminationTabState::FOREGROUND_TAB_BACKGROUND_APP
1928 : RendererTerminationTabState::BACKGROUND_TAB_BACKGROUND_APP; 1936 : RendererTerminationTabState::BACKGROUND_TAB_BACKGROUND_APP;
1929 } 1937 }
1930 UMA_HISTOGRAM_ENUMERATION( 1938 UMA_HISTOGRAM_ENUMERATION(
1931 kRendererTerminationStateHistogram, static_cast<int>(tab_state), 1939 kRendererTerminationStateHistogram, static_cast<int>(tab_state),
1932 static_cast<int>( 1940 static_cast<int>(
1933 RendererTerminationTabState::TERMINATION_TAB_STATE_COUNT)); 1941 RendererTerminationTabState::TERMINATION_TAB_STATE_COUNT));
1934 if ([parentTabModel_ tabUsageRecorder]) 1942 if ([parentTabModel_ tabUsageRecorder])
1935 [parentTabModel_ tabUsageRecorder]->RendererTerminated(self, visible_); 1943 [parentTabModel_ tabUsageRecorder]->RendererTerminated(self, visible_);
1936 } 1944 }
1937 1945
1938 BOOL applicationIsBackgrounded =
1939 [UIApplication sharedApplication].applicationState ==
1940 UIApplicationStateBackground;
1941 if (visible_) { 1946 if (visible_) {
1942 if (!applicationIsBackgrounded) { 1947 if (!applicationIsNotActive) {
1943 base::WeakNSObject<Tab> weakSelf(self); 1948 base::WeakNSObject<Tab> weakSelf(self);
1944 base::scoped_nsobject<SadTabView> sadTabView( 1949 base::scoped_nsobject<SadTabView> sadTabView(
1945 [[SadTabView alloc] initWithReloadHandler:^{ 1950 [[SadTabView alloc] initWithReloadHandler:^{
1946 base::scoped_nsobject<Tab> strongSelf([weakSelf retain]); 1951 base::scoped_nsobject<Tab> strongSelf([weakSelf retain]);
1947 1952
1948 // |check_for_repost| is true because this is called from SadTab and 1953 // |check_for_repost| is true because this is called from SadTab and
1949 // explicitly initiated by the user. 1954 // explicitly initiated by the user.
1950 [strongSelf navigationManager]->Reload(web::ReloadType::NORMAL, 1955 [strongSelf navigationManager]->Reload(web::ReloadType::NORMAL,
1951 true /* check_for_repost */); 1956 true /* check_for_repost */);
1952 }]); 1957 }]);
1953 base::scoped_nsobject<CRWContentView> contentView( 1958 base::scoped_nsobject<CRWContentView> contentView(
1954 [[CRWGenericContentView alloc] initWithView:sadTabView]); 1959 [[CRWGenericContentView alloc] initWithView:sadTabView]);
1955 self.webState->ShowTransientContentView(contentView); 1960 self.webState->ShowTransientContentView(contentView);
1956 [fullScreenController_ disableFullScreen]; 1961 [fullScreenController_ disableFullScreen];
1957 } 1962 }
1958 } else { 1963 } else {
1959 [self.webController requirePageReload]; 1964 [self.webController requirePageReload];
1960 } 1965 }
1961 // Returning to the app (after the renderer crashed in the background) and 1966 // Returning to the app (after the renderer crashed in the background) and
1962 // having the page reload is much less confusing for the user. 1967 // having the page reload is much less confusing for the user.
1963 // Note: Given that the tab is visible, calling |requirePageReload| will not 1968 // Note: Given that the tab is visible, calling |requirePageReload| will not
1964 // work when the app becomes active because there is nothing to trigger 1969 // work when the app becomes active because there is nothing to trigger
1965 // a view redisplay in that scenario. 1970 // a view redisplay in that scenario.
1966 requireReloadAfterBecomingActive_ = visible_ && applicationIsBackgrounded; 1971 requireReloadAfterBecomingActive_ = visible_ && applicationIsNotActive;
1967 [self.dialogDelegate cancelDialogForTab:self]; 1972 [self.dialogDelegate cancelDialogForTab:self];
1968 } 1973 }
1969 1974
1970 - (void)webController:(CRWWebController*)webController 1975 - (void)webController:(CRWWebController*)webController
1971 didLoadPassKitObject:(NSData*)data { 1976 didLoadPassKitObject:(NSData*)data {
1972 [self.passKitDialogProvider presentPassKitDialog:data]; 1977 [self.passKitDialogProvider presentPassKitDialog:data];
1973 } 1978 }
1974 1979
1975 #pragma mark - PrerenderDelegate 1980 #pragma mark - PrerenderDelegate
1976 1981
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
2095 2100
2096 - (TabModel*)parentTabModel { 2101 - (TabModel*)parentTabModel {
2097 return parentTabModel_; 2102 return parentTabModel_;
2098 } 2103 }
2099 2104
2100 - (FormInputAccessoryViewController*)inputAccessoryViewController { 2105 - (FormInputAccessoryViewController*)inputAccessoryViewController {
2101 return inputAccessoryViewController_.get(); 2106 return inputAccessoryViewController_.get();
2102 } 2107 }
2103 2108
2104 @end 2109 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698