Index: chrome/browser/ui/android/tab_model/android_live_tab_context.cc |
diff --git a/chrome/browser/ui/android/tab_model/android_live_tab_context.cc b/chrome/browser/ui/android/tab_model/android_live_tab_context.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d6af75e8cffafd8176630ad2e016923bbbd8c67d |
--- /dev/null |
+++ b/chrome/browser/ui/android/tab_model/android_live_tab_context.cc |
@@ -0,0 +1,136 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/android/tab_android.h" |
+#include "chrome/browser/profiles/profile.h" |
+#include "chrome/browser/ui/android/tab_model/android_live_tab_context.h" |
+#include "chrome/browser/ui/android/tab_model/tab_model.h" |
+#include "chrome/browser/ui/android/tab_model/tab_model_list.h" |
+#include "components/sessions/content/content_live_tab.h" |
+#include "components/sessions/content/content_serialized_navigation_builder.h" |
+#include "content/public/browser/browser_context.h" |
+#include "content/public/browser/navigation_entry.h" |
+ |
+ |
+AndroidLiveTabContext::AndroidLiveTabContext(TabModel* tab_model) |
+ : tab_model_(tab_model) {} |
+ |
+// Not supported by android. |
+void AndroidLiveTabContext::ShowBrowserWindow() { |
+} |
+ |
+const SessionID& AndroidLiveTabContext::GetSessionID() const { |
+ return tab_model_->SessionId(); |
+} |
+ |
+int AndroidLiveTabContext::GetTabCount() const { |
+ return tab_model_->GetTabCount(); |
+} |
+ |
+int AndroidLiveTabContext::GetSelectedIndex() const { |
+ return tab_model_->GetActiveIndex(); |
+} |
+ |
+// Not supported by android. |
+std::string AndroidLiveTabContext::GetAppName() const { |
+ return std::string(); |
+} |
+ |
+sessions::LiveTab* AndroidLiveTabContext::GetLiveTabAt(int index) const { |
+ TabAndroid* tab_android = tab_model_->GetTabAt(index); |
+ if (!tab_android || !tab_android->web_contents()) |
+ return nullptr; |
+ |
+ return sessions::ContentLiveTab::GetForWebContents( |
+ tab_android->web_contents()); |
+} |
+ |
+sessions::LiveTab* AndroidLiveTabContext::GetActiveLiveTab() const { |
+ content::WebContents* web_contents = tab_model_->GetActiveWebContents(); |
+ if (!web_contents) |
+ return nullptr; |
+ |
+ return sessions::ContentLiveTab::GetForWebContents(web_contents); |
+} |
+ |
+// Not supported by android. |
+bool AndroidLiveTabContext::IsTabPinned(int index) const { |
+ return false; |
+} |
+ |
+sessions::LiveTab* AndroidLiveTabContext::AddRestoredTab( |
+ const std::vector<sessions::SerializedNavigationEntry>& navigations, |
+ int tab_index, |
+ int selected_navigation, |
+ const std::string& extension_app_id, |
+ bool select, |
+ bool pin, |
+ bool from_last_session, |
+ const sessions::PlatformSpecificTabData* tab_platform_data, |
+ const std::string& user_agent_override) { |
+ Profile* profile = tab_model_->GetProfile(); |
+ |
+ // Prepare navigation history. |
+ std::vector<std::unique_ptr<content::NavigationEntry>> nav_entries = |
+ sessions::ContentSerializedNavigationBuilder::ToNavigationEntries( |
+ navigations, profile); |
+ |
+ // Restore web contents with navigation history. |
+ content::WebContents* web_contents = content::WebContents::Create( |
+ content::WebContents::CreateParams(profile)); |
+ web_contents->GetController().Restore( |
+ selected_navigation, |
+ content::NavigationController::RESTORE_CURRENT_SESSION, |
+ &nav_entries); |
+ |
+ // Create new tab. |
+ tab_model_->CreateTab(NULL, web_contents, -1); |
+ return sessions::ContentLiveTab::GetForWebContents(web_contents); |
+} |
+ |
+// Currently do nothing. |
Theresa
2016/07/07 19:00:13
nit: "Currently does nothing."
xingliu
2016/07/08 21:26:48
Done.
|
+sessions::LiveTab* AndroidLiveTabContext::ReplaceRestoredTab( |
+ const std::vector<sessions::SerializedNavigationEntry>& navigations, |
+ int selected_navigation, |
+ bool from_last_session, |
+ const std::string& extension_app_id, |
+ const sessions::PlatformSpecificTabData* tab_platform_data, |
+ const std::string& user_agent_override) { |
+ NOTIMPLEMENTED(); |
+ return nullptr; |
+} |
+ |
+// Currently do nothing. |
+void AndroidLiveTabContext::CloseTab() { |
+ NOTIMPLEMENTED(); |
+} |
+ |
+// static. |
+sessions::LiveTabContext* AndroidLiveTabContext::FindContextForWebContents( |
Theresa
2016/07/07 19:00:14
Is there ever a case where this would need the fal
xingliu
2016/07/08 21:26:48
I think this is used in the flow that write the br
Theresa
2016/07/12 00:06:16
Can we add a comment to that effect so it's easier
|
+ const content::WebContents* contents) { |
+ TabAndroid* tab_android = TabAndroid::FromWebContents(contents); |
Theresa
2016/07/07 19:00:13
The comment above this method in tab_android.h say
xingliu
2016/07/08 21:26:48
Done.
|
+ TabModel* model = TabModelList::FindTabModelWithId( |
+ tab_android->window_id().id()); |
+ |
+ return model ? model->GetLiveTabContext() : nullptr; |
+} |
+ |
+// static. |
+sessions::LiveTabContext* AndroidLiveTabContext::FindContextWithID( |
Theresa
2016/07/07 19:00:13
I think unit tests for the native side would be go
xingliu
2016/07/08 21:26:48
Added TODO. But current java unittest will call na
Theresa
2016/07/12 00:06:16
Thanks :)
It's still (generally) good to do unit
|
+ SessionID::id_type desired_id) { |
+ // Find the model with desired id. |
+ TabModel* model = TabModelList::FindTabModelWithId(desired_id); |
+ |
+ // if we can't find the correct model, fall back to first non-incognito model. |
Theresa
2016/07/07 19:00:13
nit: capitalize If, "... fallback to the first..."
xingliu
2016/07/08 21:26:48
Done.
|
+ if (!model || model->IsOffTheRecord()) { |
+ for (auto it = TabModelList::begin(); it != TabModelList::end(); ++it) { |
+ TabModel* model = *it; |
+ if (!model->IsOffTheRecord()) { |
+ return model->GetLiveTabContext(); |
+ } |
+ } |
+ } |
+ |
+ return model ? model->GetLiveTabContext() : nullptr; |
+} |