OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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 "chrome/browser/android/tab_android.h" | |
6 #include "chrome/browser/profiles/profile.h" | |
7 #include "chrome/browser/ui/android/tab_model/android_live_tab_context.h" | |
8 #include "chrome/browser/ui/android/tab_model/tab_model.h" | |
9 #include "chrome/browser/ui/android/tab_model/tab_model_list.h" | |
10 #include "components/sessions/content/content_live_tab.h" | |
11 #include "components/sessions/content/content_serialized_navigation_builder.h" | |
12 #include "content/public/browser/browser_context.h" | |
13 #include "content/public/browser/navigation_entry.h" | |
14 | |
15 | |
16 AndroidLiveTabContext::AndroidLiveTabContext(TabModel* tab_model) | |
17 : tab_model_(tab_model) {} | |
18 | |
19 // Not supported by android. | |
20 void AndroidLiveTabContext::ShowBrowserWindow() { | |
21 } | |
22 | |
23 const SessionID& AndroidLiveTabContext::GetSessionID() const { | |
24 return tab_model_->SessionId(); | |
25 } | |
26 | |
27 int AndroidLiveTabContext::GetTabCount() const { | |
28 return tab_model_->GetTabCount(); | |
29 } | |
30 | |
31 int AndroidLiveTabContext::GetSelectedIndex() const { | |
32 return tab_model_->GetActiveIndex(); | |
33 } | |
34 | |
35 // Not supported by android. | |
36 std::string AndroidLiveTabContext::GetAppName() const { | |
37 return std::string(); | |
38 } | |
39 | |
40 sessions::LiveTab* AndroidLiveTabContext::GetLiveTabAt(int index) const { | |
41 TabAndroid* tab_android = tab_model_->GetTabAt(index); | |
42 if (!tab_android || !tab_android->web_contents()) | |
43 return nullptr; | |
44 | |
45 return sessions::ContentLiveTab::GetForWebContents( | |
46 tab_android->web_contents()); | |
47 } | |
48 | |
49 sessions::LiveTab* AndroidLiveTabContext::GetActiveLiveTab() const { | |
50 content::WebContents* web_contents = tab_model_->GetActiveWebContents(); | |
51 if (!web_contents) | |
52 return nullptr; | |
53 | |
54 return sessions::ContentLiveTab::GetForWebContents(web_contents); | |
55 } | |
56 | |
57 // Not supported by android. | |
58 bool AndroidLiveTabContext::IsTabPinned(int index) const { | |
59 return false; | |
60 } | |
61 | |
62 sessions::LiveTab* AndroidLiveTabContext::AddRestoredTab( | |
63 const std::vector<sessions::SerializedNavigationEntry>& navigations, | |
64 int tab_index, | |
65 int selected_navigation, | |
66 const std::string& extension_app_id, | |
67 bool select, | |
68 bool pin, | |
69 bool from_last_session, | |
70 const sessions::PlatformSpecificTabData* tab_platform_data, | |
71 const std::string& user_agent_override) { | |
72 Profile* profile = tab_model_->GetProfile(); | |
73 | |
74 // Prepare navigation history. | |
75 std::vector<std::unique_ptr<content::NavigationEntry>> nav_entries = | |
76 sessions::ContentSerializedNavigationBuilder::ToNavigationEntries( | |
77 navigations, profile); | |
78 | |
79 // Restore web contents with navigation history. | |
80 content::WebContents* web_contents = content::WebContents::Create( | |
81 content::WebContents::CreateParams(profile)); | |
82 web_contents->GetController().Restore( | |
83 selected_navigation, | |
84 content::NavigationController::RESTORE_CURRENT_SESSION, | |
85 &nav_entries); | |
86 return sessions::ContentLiveTab::GetForWebContents(web_contents); | |
87 } | |
88 | |
89 // Currently do nothing. | |
90 sessions::LiveTab* AndroidLiveTabContext::ReplaceRestoredTab( | |
91 const std::vector<sessions::SerializedNavigationEntry>& navigations, | |
92 int selected_navigation, | |
93 bool from_last_session, | |
94 const std::string& extension_app_id, | |
95 const sessions::PlatformSpecificTabData* tab_platform_data, | |
96 const std::string& user_agent_override) { | |
97 NOTIMPLEMENTED(); | |
98 return nullptr; | |
99 } | |
100 | |
101 // Currently do nothing. | |
102 void AndroidLiveTabContext::CloseTab() { | |
103 NOTIMPLEMENTED(); | |
104 } | |
105 | |
106 // static. | |
107 sessions::LiveTabContext* AndroidLiveTabContext::FindContextForWebContents( | |
108 const content::WebContents* contents) { | |
109 TabAndroid* tab_android = TabAndroid::FromWebContents(contents); | |
110 TabModel* model = TabModelList::FindTabModelWithId( | |
111 tab_android->window_id().id()); | |
112 | |
113 return model ? model->GetLiveTabContext() : nullptr; | |
114 } | |
115 | |
116 // static. | |
117 sessions::LiveTabContext* AndroidLiveTabContext::FindContextWithID( | |
118 SessionID::id_type desired_id) { | |
119 TabModel* model = TabModelList::FindTabModelWithId(desired_id); | |
Theresa
2016/07/06 18:51:06
This gets called from tab_restore_service_helper (
xingliu
2016/07/06 22:35:41
Done.
| |
120 return model ? model->GetLiveTabContext() : nullptr; | |
121 } | |
OLD | NEW |