1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
// 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"
#include "content/public/browser/restore_type.h"
AndroidLiveTabContext::AndroidLiveTabContext(TabModel* tab_model)
: tab_model_(tab_model) {}
// Called in tab restore service, but expected to do nothing on 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::RestoreType::CURRENT_SESSION, &nav_entries);
// Create new tab.
tab_model_->CreateTab(nullptr, web_contents, -1);
return sessions::ContentLiveTab::GetForWebContents(web_contents);
}
// Currently does nothing.
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 does nothing.
void AndroidLiveTabContext::CloseTab() {
NOTIMPLEMENTED();
}
// static.
sessions::LiveTabContext* AndroidLiveTabContext::FindContextForWebContents(
const content::WebContents* contents) {
TabAndroid* tab_android = TabAndroid::FromWebContents(contents);
if (!tab_android)
return nullptr;
TabModel* model = TabModelList::FindTabModelWithId(
tab_android->window_id().id());
return model ? model->GetLiveTabContext() : nullptr;
}
// static.
sessions::LiveTabContext* AndroidLiveTabContext::FindContextWithID(
SessionID::id_type desired_id) {
// Find the model with desired id.
TabModel* tab_model = TabModelList::FindTabModelWithId(desired_id);
// If we can't find the correct model, fall back to first non-incognito model.
if (!tab_model || tab_model->IsOffTheRecord()) {
for (auto it = TabModelList::begin(); it != TabModelList::end(); ++it) {
TabModel* model = *it;
if (!model->IsOffTheRecord()) {
return model->GetLiveTabContext();
}
}
}
return tab_model ? tab_model->GetLiveTabContext() : nullptr;
}
|