| OLD | NEW |
| 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_model.h" | 5 #import "ios/chrome/browser/tabs/tab_model.h" |
| 6 | 6 |
| 7 #include <list> | 7 #include <list> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 @"kTabModelTabDeselectedNotification"; | 59 @"kTabModelTabDeselectedNotification"; |
| 60 NSString* const kTabModelNewTabWillOpenNotification = | 60 NSString* const kTabModelNewTabWillOpenNotification = |
| 61 @"kTabModelNewTabWillOpenNotification"; | 61 @"kTabModelNewTabWillOpenNotification"; |
| 62 NSString* const kTabModelTabKey = @"tab"; | 62 NSString* const kTabModelTabKey = @"tab"; |
| 63 NSString* const kTabModelPageLoadSuccess = @"pageLoadSuccess"; | 63 NSString* const kTabModelPageLoadSuccess = @"pageLoadSuccess"; |
| 64 NSString* const kTabModelOpenInBackgroundKey = @"shouldOpenInBackground"; | 64 NSString* const kTabModelOpenInBackgroundKey = @"shouldOpenInBackground"; |
| 65 | 65 |
| 66 namespace { | 66 namespace { |
| 67 | 67 |
| 68 // Updates CRWSessionCertificatePolicyManager's certificate policy cache. | 68 // Updates CRWSessionCertificatePolicyManager's certificate policy cache. |
| 69 void UpdateCertificatePolicyCacheFromWebState(web::WebState* web_state) { | 69 void UpdateCertificatePolicyCacheFromWebState(web::WebStateImpl* webState) { |
| 70 DCHECK([NSThread isMainThread]); | 70 DCHECK([NSThread isMainThread]); |
| 71 DCHECK(web_state); | 71 DCHECK(webState); |
| 72 scoped_refptr<web::CertificatePolicyCache> policy_cache = | 72 scoped_refptr<web::CertificatePolicyCache> policy_cache = |
| 73 web::BrowserState::GetCertificatePolicyCache( | 73 web::BrowserState::GetCertificatePolicyCache(webState->GetBrowserState()); |
| 74 web_state->GetBrowserState()); | 74 CRWSessionController* controller = |
| 75 // TODO(crbug.com/454984): Remove CRWSessionController usage once certificate | 75 webState->GetNavigationManagerImpl().GetSessionController(); |
| 76 // policy manager is moved to NavigationManager. | |
| 77 CRWSessionController* controller = static_cast<web::WebStateImpl*>(web_state) | |
| 78 ->GetNavigationManagerImpl() | |
| 79 .GetSessionController(); | |
| 80 [[controller sessionCertificatePolicyManager] | 76 [[controller sessionCertificatePolicyManager] |
| 81 updateCertificatePolicyCache:policy_cache]; | 77 updateCertificatePolicyCache:policy_cache]; |
| 82 } | 78 } |
| 83 | 79 |
| 84 // Populates the certificate policy cache based on the current entries of the | 80 // Populates the certificate policy cache based on the current entries of the |
| 85 // given tabs. | 81 // given tabs. |
| 86 void RestoreCertificatePolicyCacheFromTabs(NSArray* tabs) { | 82 void RestoreCertificatePolicyCacheFromTabs(NSArray* tabs) { |
| 87 DCHECK([NSThread isMainThread]); | 83 DCHECK([NSThread isMainThread]); |
| 88 for (Tab* tab in tabs) { | 84 for (Tab* tab in tabs) { |
| 89 UpdateCertificatePolicyCacheFromWebState(tab.webStateImpl); | 85 UpdateCertificatePolicyCacheFromWebState(tab.webStateImpl); |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 // important to the backend code to always have a sync window delegate. | 247 // important to the backend code to always have a sync window delegate. |
| 252 if (!_browserState->IsOffTheRecord()) { | 248 if (!_browserState->IsOffTheRecord()) { |
| 253 // Set up the usage recorder before tabs are created. | 249 // Set up the usage recorder before tabs are created. |
| 254 _tabUsageRecorder.reset(new TabUsageRecorder(self)); | 250 _tabUsageRecorder.reset(new TabUsageRecorder(self)); |
| 255 } | 251 } |
| 256 _syncedWindowDelegate.reset(new TabModelSyncedWindowDelegate(self)); | 252 _syncedWindowDelegate.reset(new TabModelSyncedWindowDelegate(self)); |
| 257 | 253 |
| 258 _tabs.reset([[NSMutableArray alloc] init]); | 254 _tabs.reset([[NSMutableArray alloc] init]); |
| 259 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; | 255 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; |
| 260 if (window) { | 256 if (window) { |
| 261 web::WebState::CreateParams params(_browserState); | 257 while (window.unclaimedSessions) { |
| 262 for (CRWNavigationManagerStorage* session in window.sessions) { | 258 std::unique_ptr<web::WebStateImpl> webState = [window nextSession]; |
| 263 std::unique_ptr<web::WebState> webState = | |
| 264 web::WebState::Create(params, session); | |
| 265 DCHECK_EQ(webState->GetBrowserState(), _browserState); | 259 DCHECK_EQ(webState->GetBrowserState(), _browserState); |
| 266 // Restore the CertificatePolicyCache. | 260 // Restore the CertificatePolicyCache. |
| 267 UpdateCertificatePolicyCacheFromWebState(webState.get()); | 261 UpdateCertificatePolicyCacheFromWebState(webState.get()); |
| 268 // Create a new tab for each entry in the window. Don't send delegate | 262 // Create a new tab for each entry in the window. Don't send delegate |
| 269 // notifications for each restored tab, only when all done. | 263 // notifications for each restored tab, only when all done. |
| 270 base::scoped_nsobject<Tab> tab( | 264 base::scoped_nsobject<Tab> tab( |
| 271 [[Tab alloc] initWithWebState:std::move(webState) model:self]); | 265 [[Tab alloc] initWithWebState:std::move(webState) model:self]); |
| 272 [tab webController].usePlaceholderOverlay = YES; | 266 [tab webController].usePlaceholderOverlay = YES; |
| 273 [tab fetchFavicon]; | 267 [tab fetchFavicon]; |
| 274 [_tabs addObject:tab]; | 268 [_tabs addObject:tab]; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 } | 308 } |
| 315 | 309 |
| 316 - (instancetype)init { | 310 - (instancetype)init { |
| 317 NOTREACHED(); | 311 NOTREACHED(); |
| 318 return nil; | 312 return nil; |
| 319 } | 313 } |
| 320 | 314 |
| 321 - (BOOL)restoreSessionWindow:(SessionWindowIOS*)window { | 315 - (BOOL)restoreSessionWindow:(SessionWindowIOS*)window { |
| 322 DCHECK(_browserState); | 316 DCHECK(_browserState); |
| 323 DCHECK(window); | 317 DCHECK(window); |
| 324 NSArray* sessions = window.sessions; | 318 if (!window.unclaimedSessions) |
| 325 if (!sessions.count) | |
| 326 return NO; | 319 return NO; |
| 327 size_t oldCount = [_tabs count]; | 320 size_t oldCount = [_tabs count]; |
| 328 size_t index = oldCount; | 321 size_t index = oldCount; |
| 329 web::WebState::CreateParams params(_browserState); | 322 while (window.unclaimedSessions) { |
| 330 for (CRWNavigationManagerStorage* session in sessions) { | 323 std::unique_ptr<web::WebStateImpl> webState = [window nextSession]; |
| 331 std::unique_ptr<web::WebState> webState = | |
| 332 web::WebState::Create(params, session); | |
| 333 DCHECK_EQ(webState->GetBrowserState(), _browserState); | 324 DCHECK_EQ(webState->GetBrowserState(), _browserState); |
| 334 Tab* tab = [self insertTabWithWebState:std::move(webState) atIndex:index++]; | 325 Tab* tab = [self insertTabWithWebState:std::move(webState) atIndex:index++]; |
| 335 tab.webController.usePlaceholderOverlay = YES; | 326 tab.webController.usePlaceholderOverlay = YES; |
| 336 // Restore the CertificatePolicyCache. Note that after calling Pass() | 327 // Restore the CertificatePolicyCache. Note that after calling Pass() |
| 337 // |webState| is invalid, so we need to get the webstate from |tab|. | 328 // |webState| is invalid, so we need to get the webstate from |tab|. |
| 338 UpdateCertificatePolicyCacheFromWebState(tab.webStateImpl); | 329 UpdateCertificatePolicyCacheFromWebState(tab.webStateImpl); |
| 339 } | 330 } |
| 340 DCHECK([_tabs count] > oldCount); | 331 DCHECK([_tabs count] > oldCount); |
| 341 // If any tab was restored, the saved selected tab must be selected. | 332 // If any tab was restored, the saved selected tab must be selected. |
| 342 if ([_tabs count] > oldCount) { | 333 if ([_tabs count] > oldCount) { |
| (...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 850 - (SessionWindowIOS*)windowForSavingSession { | 841 - (SessionWindowIOS*)windowForSavingSession { |
| 851 // Background tabs will already have their state preserved, but not the | 842 // Background tabs will already have their state preserved, but not the |
| 852 // fg tab. Do it now. | 843 // fg tab. Do it now. |
| 853 [_currentTab recordStateInHistory]; | 844 [_currentTab recordStateInHistory]; |
| 854 | 845 |
| 855 // Build the array of sessions. Copy the session objects as the saving will | 846 // Build the array of sessions. Copy the session objects as the saving will |
| 856 // be done on a separate thread. | 847 // be done on a separate thread. |
| 857 // TODO(crbug.com/661986): This could get expensive especially since this | 848 // TODO(crbug.com/661986): This could get expensive especially since this |
| 858 // window may never be saved (if another call comes in before the delay). | 849 // window may never be saved (if another call comes in before the delay). |
| 859 SessionWindowIOS* window = [[[SessionWindowIOS alloc] init] autorelease]; | 850 SessionWindowIOS* window = [[[SessionWindowIOS alloc] init] autorelease]; |
| 860 for (Tab* tab in self) { | 851 for (Tab* tab in _tabs.get()) { |
| 861 web::WebState* webState = tab.webState; | 852 DCHECK(tab.webStateImpl); |
| 862 DCHECK(webState); | 853 std::unique_ptr<web::WebStateImpl> webStateCopy( |
| 863 [window addSerializedSession:webState->BuildSerializedNavigationManager()]; | 854 tab.webStateImpl->CopyForSessionWindow()); |
| 855 [window addSession:std::move(webStateCopy)]; |
| 864 } | 856 } |
| 865 window.selectedIndex = [self indexOfTab:_currentTab]; | 857 window.selectedIndex = [self indexOfTab:_currentTab]; |
| 866 return window; | 858 return window; |
| 867 } | 859 } |
| 868 | 860 |
| 869 - (BOOL)isNTPTab:(Tab*)tab { | 861 - (BOOL)isNTPTab:(Tab*)tab { |
| 870 std::string host = tab.url.host(); | 862 std::string host = tab.url.host(); |
| 871 return host == kChromeUINewTabHost || host == kChromeUIBookmarksHost; | 863 return host == kChromeUINewTabHost || host == kChromeUIBookmarksHost; |
| 872 } | 864 } |
| 873 | 865 |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1073 web::NavigationManager::WebLoadParams params(URL); | 1065 web::NavigationManager::WebLoadParams params(URL); |
| 1074 params.referrer = referrer; | 1066 params.referrer = referrer; |
| 1075 params.transition_type = ui::PAGE_TRANSITION_TYPED; | 1067 params.transition_type = ui::PAGE_TRANSITION_TYPED; |
| 1076 [[tab webController] loadWithParams:params]; | 1068 [[tab webController] loadWithParams:params]; |
| 1077 [tab webController].webUsageEnabled = webUsageEnabled_; | 1069 [tab webController].webUsageEnabled = webUsageEnabled_; |
| 1078 [self insertTab:tab atIndex:index]; | 1070 [self insertTab:tab atIndex:index]; |
| 1079 return tab; | 1071 return tab; |
| 1080 } | 1072 } |
| 1081 | 1073 |
| 1082 @end | 1074 @end |
| OLD | NEW |