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

Side by Side Diff: ios/chrome/browser/sessions/tab_restore_service_delegate_impl_ios.mm

Issue 2775623002: [ios] WebStateList owns all WebState it manages. (Closed)
Patch Set: Fix gn check 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 | « ios/chrome/browser/sessions/BUILD.gn ('k') | ios/chrome/browser/tabs/BUILD.gn » ('j') | 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 #include "ios/chrome/browser/sessions/tab_restore_service_delegate_impl_ios.h" 5 #include "ios/chrome/browser/sessions/tab_restore_service_delegate_impl_ios.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/strings/sys_string_conversions.h" 11 #include "base/strings/sys_string_conversions.h"
12 #include "components/sessions/core/session_types.h" 12 #include "components/sessions/core/session_types.h"
13 #include "components/sessions/ios/ios_serialized_navigation_builder.h" 13 #include "components/sessions/ios/ios_serialized_navigation_builder.h"
14 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" 14 #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
15 #import "ios/chrome/browser/tabs/tab.h" 15 #import "ios/chrome/browser/tabs/tab.h"
16 #import "ios/chrome/browser/tabs/tab_model.h" 16 #import "ios/chrome/browser/tabs/tab_model.h"
17 #import "ios/chrome/browser/tabs/tab_model_list.h" 17 #import "ios/chrome/browser/tabs/tab_model_list.h"
18 #import "ios/shared/chrome/browser/tabs/web_state_list.h"
18 #import "ios/web/navigation/navigation_manager_impl.h" 19 #import "ios/web/navigation/navigation_manager_impl.h"
19 #include "ios/web/public/navigation_item.h" 20 #include "ios/web/public/navigation_item.h"
20 #import "ios/web/web_state/web_state_impl.h" 21 #import "ios/web/web_state/web_state_impl.h"
21 #import "net/base/mac/url_conversions.h" 22 #import "net/base/mac/url_conversions.h"
22 23
23 using web::WebStateImpl;
24
25 TabRestoreServiceDelegateImplIOS::TabRestoreServiceDelegateImplIOS( 24 TabRestoreServiceDelegateImplIOS::TabRestoreServiceDelegateImplIOS(
26 ios::ChromeBrowserState* browser_state) 25 ios::ChromeBrowserState* browser_state)
27 : browser_state_(browser_state) {} 26 : browser_state_(browser_state) {}
28 27
29 TabRestoreServiceDelegateImplIOS::~TabRestoreServiceDelegateImplIOS() {} 28 TabRestoreServiceDelegateImplIOS::~TabRestoreServiceDelegateImplIOS() {}
30 29
31 TabModel* TabRestoreServiceDelegateImplIOS::tab_model() const { 30 TabModel* TabRestoreServiceDelegateImplIOS::tab_model() const {
32 return GetLastActiveTabModelForChromeBrowserState(browser_state_); 31 return GetLastActiveTabModelForChromeBrowserState(browser_state_);
33 } 32 }
34 33
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 int selected_navigation, 72 int selected_navigation,
74 const std::string& extension_app_id, 73 const std::string& extension_app_id,
75 bool select, 74 bool select,
76 bool pin, 75 bool pin,
77 bool from_last_session, 76 bool from_last_session,
78 const sessions::PlatformSpecificTabData* tab_platform_data, 77 const sessions::PlatformSpecificTabData* tab_platform_data,
79 const std::string& user_agent_override) { 78 const std::string& user_agent_override) {
80 DCHECK_LT(selected_navigation, static_cast<int>(navigations.size())); 79 DCHECK_LT(selected_navigation, static_cast<int>(navigations.size()));
81 80
82 web::WebState::CreateParams params(browser_state_); 81 web::WebState::CreateParams params(browser_state_);
83 std::unique_ptr<WebStateImpl> webState(new WebStateImpl(params)); 82 std::unique_ptr<web::WebStateImpl> web_state(new web::WebStateImpl(params));
84 std::vector<std::unique_ptr<web::NavigationItem>> items = 83 std::vector<std::unique_ptr<web::NavigationItem>> items =
85 sessions::IOSSerializedNavigationBuilder::ToNavigationItems(navigations); 84 sessions::IOSSerializedNavigationBuilder::ToNavigationItems(navigations);
86 webState->GetNavigationManagerImpl().ReplaceSessionHistory( 85 web_state->GetNavigationManagerImpl().ReplaceSessionHistory(
87 std::move(items), selected_navigation); 86 std::move(items), selected_navigation);
88 TabModel* tabModel = tab_model(); 87
89 Tab* tab = 88 WebStateList* web_state_list = [tab_model() webStateList];
90 [tabModel insertTabWithWebState:std::move(webState) atIndex:tab_index]; 89 web_state_list->InsertWebState(tab_index, std::move(web_state));
91 // TODO(crbug.com/661636): Handle tab-switch animation somehow... 90 // TODO(crbug.com/661636): Handle tab-switch animation somehow...
92 [tabModel setCurrentTab:tab]; 91 web_state_list->ActivateWebStateAt(tab_index);
93 return nullptr; 92 return nullptr;
94 } 93 }
95 94
96 sessions::LiveTab* TabRestoreServiceDelegateImplIOS::ReplaceRestoredTab( 95 sessions::LiveTab* TabRestoreServiceDelegateImplIOS::ReplaceRestoredTab(
97 const std::vector<sessions::SerializedNavigationEntry>& navigations, 96 const std::vector<sessions::SerializedNavigationEntry>& navigations,
98 int selected_navigation, 97 int selected_navigation,
99 bool from_last_session, 98 bool from_last_session,
100 const std::string& extension_app_id, 99 const std::string& extension_app_id,
101 const sessions::PlatformSpecificTabData* tab_platform_data, 100 const sessions::PlatformSpecificTabData* tab_platform_data,
102 const std::string& user_agent_override) { 101 const std::string& user_agent_override) {
103 DCHECK_LT(selected_navigation, static_cast<int>(navigations.size())); 102 DCHECK_LT(selected_navigation, static_cast<int>(navigations.size()));
104 103
105 // Desktop Chrome creates a new tab and deletes the old one. The net result 104 // Desktop Chrome creates a new tab and deletes the old one. The net result
106 // is that the NTP is not in the session history of the restored tab. Do 105 // is that the NTP is not in the session history of the restored tab. Do
107 // the same by replacing the tab's navigation history which will also force it 106 // the same by replacing the tab's navigation history which will also force it
108 // to reload. 107 // to reload.
109 Tab* tab = tab_model().currentTab; 108 Tab* tab = tab_model().currentTab;
110 [tab replaceHistoryWithNavigations:navigations 109 [tab replaceHistoryWithNavigations:navigations
111 currentIndex:selected_navigation]; 110 currentIndex:selected_navigation];
112 return nullptr; 111 return nullptr;
113 } 112 }
114 113
115 void TabRestoreServiceDelegateImplIOS::CloseTab() { 114 void TabRestoreServiceDelegateImplIOS::CloseTab() {
116 [[tab_model() currentTab] close]; 115 WebStateList* web_state_list = [tab_model() webStateList];
116 web_state_list->CloseWebStateAt(web_state_list->active_index());
117 } 117 }
OLDNEW
« no previous file with comments | « ios/chrome/browser/sessions/BUILD.gn ('k') | ios/chrome/browser/tabs/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698