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

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

Issue 2585233003: Upstream Chrome on iOS source code [2/11]. (Closed)
Patch Set: Created 4 years 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ios/chrome/browser/sessions/tab_restore_service_delegate_impl_ios.h"
6
7 #include <memory>
8 #include <utility>
9
10 #include "base/logging.h"
11 #include "base/strings/sys_string_conversions.h"
12 #include "components/sessions/core/session_types.h"
13 #include "components/sessions/ios/ios_serialized_navigation_builder.h"
14 #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
15 #import "ios/chrome/browser/tabs/tab.h"
16 #import "ios/chrome/browser/tabs/tab_model.h"
17 #include "ios/chrome/browser/ui/browser_ios.h"
18 #include "ios/chrome/browser/ui/browser_list_ios.h"
19 #import "ios/web/navigation/navigation_manager_impl.h"
20 #include "ios/web/public/navigation_item.h"
21 #import "ios/web/web_state/web_state_impl.h"
22 #import "net/base/mac/url_conversions.h"
23
24 using web::WebStateImpl;
25
26 TabRestoreServiceDelegateImplIOS::TabRestoreServiceDelegateImplIOS(
27 ios::ChromeBrowserState* browser_state)
28 : browser_state_(browser_state) {}
29
30 TabRestoreServiceDelegateImplIOS::~TabRestoreServiceDelegateImplIOS() {}
31
32 TabModel* TabRestoreServiceDelegateImplIOS::tab_model() const {
33 id<BrowserIOS> browser =
34 BrowserListIOS::GetLastActiveWithBrowserState(browser_state_);
35 return [browser tabModel];
36 }
37
38 void TabRestoreServiceDelegateImplIOS::ShowBrowserWindow() {
39 // No need to do anything here, as the singleton browser "window" is already
40 // shown.
41 }
42
43 const SessionID& TabRestoreServiceDelegateImplIOS::GetSessionID() const {
44 return session_id_;
45 }
46
47 int TabRestoreServiceDelegateImplIOS::GetTabCount() const {
48 return [tab_model() count];
49 }
50
51 int TabRestoreServiceDelegateImplIOS::GetSelectedIndex() const {
52 TabModel* tabModel = tab_model();
53 return [tabModel indexOfTab:[tabModel currentTab]];
54 }
55
56 std::string TabRestoreServiceDelegateImplIOS::GetAppName() const {
57 return std::string();
58 }
59
60 sessions::LiveTab* TabRestoreServiceDelegateImplIOS::GetLiveTabAt(
61 int index) const {
62 return nullptr;
63 }
64
65 sessions::LiveTab* TabRestoreServiceDelegateImplIOS::GetActiveLiveTab() const {
66 return nullptr;
67 }
68
69 bool TabRestoreServiceDelegateImplIOS::IsTabPinned(int index) const {
70 return false;
71 }
72
73 sessions::LiveTab* TabRestoreServiceDelegateImplIOS::AddRestoredTab(
74 const std::vector<sessions::SerializedNavigationEntry>& navigations,
75 int tab_index,
76 int selected_navigation,
77 const std::string& extension_app_id,
78 bool select,
79 bool pin,
80 bool from_last_session,
81 const sessions::PlatformSpecificTabData* tab_platform_data,
82 const std::string& user_agent_override) {
83 DCHECK_LT(selected_navigation, static_cast<int>(navigations.size()));
84
85 std::unique_ptr<WebStateImpl> webState(new WebStateImpl(browser_state_));
86 ScopedVector<web::NavigationItem> items =
87 sessions::IOSSerializedNavigationBuilder::ToNavigationItems(navigations);
88 webState->GetNavigationManagerImpl().ReplaceSessionHistory(
89 std::move(items), selected_navigation);
90 TabModel* tabModel = tab_model();
91 Tab* tab =
92 [tabModel insertTabWithWebState:std::move(webState) atIndex:tab_index];
93 // TODO(crbug.com/661636): Handle tab-switch animation somehow...
94 [tabModel setCurrentTab:tab];
95 return nullptr;
96 }
97
98 sessions::LiveTab* TabRestoreServiceDelegateImplIOS::ReplaceRestoredTab(
99 const std::vector<sessions::SerializedNavigationEntry>& navigations,
100 int selected_navigation,
101 bool from_last_session,
102 const std::string& extension_app_id,
103 const sessions::PlatformSpecificTabData* tab_platform_data,
104 const std::string& user_agent_override) {
105 DCHECK_LT(selected_navigation, static_cast<int>(navigations.size()));
106
107 // Desktop Chrome creates a new tab and deletes the old one. The net result
108 // is that the NTP is not in the session history of the restored tab. Do
109 // the same by replacing the tab's navigation history which will also force it
110 // to reload.
111 Tab* tab = tab_model().currentTab;
112 [tab replaceHistoryWithNavigations:navigations
113 currentIndex:selected_navigation];
114 return nullptr;
115 }
116
117 void TabRestoreServiceDelegateImplIOS::CloseTab() {
118 [[tab_model() currentTab] close];
119 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698