Chromium Code Reviews| 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 // TODO(xingliu): add unit test for this class. | |
| 16 AndroidLiveTabContext::AndroidLiveTabContext(TabModel* tab_model) | |
| 17 : tab_model_(tab_model) {} | |
| 18 | |
| 19 // Not supported by android. | |
| 20 void AndroidLiveTabContext::ShowBrowserWindow() { | |
|
Theresa
2016/07/12 00:06:16
nit: Let's add NotReached() here so we crashes if
xingliu
2016/07/12 03:57:18
This will be called by android. Since we wired in
Theresa
2016/07/12 17:25:16
Ah, okay. Then instead of saying "Not supported by
| |
| 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 | |
| 87 // Create new tab. | |
| 88 tab_model_->CreateTab(NULL, web_contents, -1); | |
| 89 return sessions::ContentLiveTab::GetForWebContents(web_contents); | |
| 90 } | |
| 91 | |
| 92 // Currently does nothing. | |
| 93 sessions::LiveTab* AndroidLiveTabContext::ReplaceRestoredTab( | |
| 94 const std::vector<sessions::SerializedNavigationEntry>& navigations, | |
| 95 int selected_navigation, | |
| 96 bool from_last_session, | |
| 97 const std::string& extension_app_id, | |
| 98 const sessions::PlatformSpecificTabData* tab_platform_data, | |
| 99 const std::string& user_agent_override) { | |
| 100 NOTIMPLEMENTED(); | |
| 101 return nullptr; | |
| 102 } | |
| 103 | |
| 104 // Currently does nothing. | |
| 105 void AndroidLiveTabContext::CloseTab() { | |
| 106 NOTIMPLEMENTED(); | |
| 107 } | |
| 108 | |
| 109 // static. | |
| 110 sessions::LiveTabContext* AndroidLiveTabContext::FindContextForWebContents( | |
| 111 const content::WebContents* contents) { | |
| 112 TabAndroid* tab_android = TabAndroid::FromWebContents(contents); | |
| 113 if (!tab_android) | |
| 114 return nullptr; | |
| 115 | |
| 116 TabModel* model = TabModelList::FindTabModelWithId( | |
| 117 tab_android->window_id().id()); | |
| 118 | |
| 119 return model ? model->GetLiveTabContext() : nullptr; | |
| 120 } | |
| 121 | |
| 122 // static. | |
| 123 sessions::LiveTabContext* AndroidLiveTabContext::FindContextWithID( | |
| 124 SessionID::id_type desired_id) { | |
| 125 // Find the model with desired id. | |
| 126 TabModel* model = TabModelList::FindTabModelWithId(desired_id); | |
| 127 | |
| 128 // If we can't find the correct model, fall back to first non-incognito model. | |
| 129 if (!model || model->IsOffTheRecord()) { | |
| 130 for (auto it = TabModelList::begin(); it != TabModelList::end(); ++it) { | |
| 131 TabModel* model = *it; | |
| 132 if (!model->IsOffTheRecord()) { | |
| 133 return model->GetLiveTabContext(); | |
| 134 } | |
| 135 } | |
| 136 } | |
| 137 | |
| 138 return model ? model->GetLiveTabContext() : nullptr; | |
| 139 } | |
| OLD | NEW |