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 | |
| 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 | |
| 87 // Create new tab. | |
| 88 tab_model_->CreateTab(NULL, web_contents, -1); | |
| 89 return sessions::ContentLiveTab::GetForWebContents(web_contents); | |
| 90 } | |
| 91 | |
| 92 // Currently do nothing. | |
|
Theresa
2016/07/07 19:00:13
nit: "Currently does nothing."
xingliu
2016/07/08 21:26:48
Done.
| |
| 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 do nothing. | |
| 105 void AndroidLiveTabContext::CloseTab() { | |
| 106 NOTIMPLEMENTED(); | |
| 107 } | |
| 108 | |
| 109 // static. | |
| 110 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
| |
| 111 const content::WebContents* contents) { | |
| 112 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.
| |
| 113 TabModel* model = TabModelList::FindTabModelWithId( | |
| 114 tab_android->window_id().id()); | |
| 115 | |
| 116 return model ? model->GetLiveTabContext() : nullptr; | |
| 117 } | |
| 118 | |
| 119 // static. | |
| 120 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
| |
| 121 SessionID::id_type desired_id) { | |
| 122 // Find the model with desired id. | |
| 123 TabModel* model = TabModelList::FindTabModelWithId(desired_id); | |
| 124 | |
| 125 // 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.
| |
| 126 if (!model || model->IsOffTheRecord()) { | |
| 127 for (auto it = TabModelList::begin(); it != TabModelList::end(); ++it) { | |
| 128 TabModel* model = *it; | |
| 129 if (!model->IsOffTheRecord()) { | |
| 130 return model->GetLiveTabContext(); | |
| 131 } | |
| 132 } | |
| 133 } | |
| 134 | |
| 135 return model ? model->GetLiveTabContext() : nullptr; | |
| 136 } | |
| OLD | NEW |