1// Copyright (c) 2012 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/sessions/session_restore.h" 6 7#include <vector> 8 9#include "chrome/browser/android/tab_android.h" 10#include "chrome/browser/profiles/profile.h" 11#include "chrome/browser/sessions/session_types.h" 12#include "chrome/browser/ui/android/tab_model/tab_model.h" 13#include "chrome/browser/ui/android/tab_model/tab_model_list.h" 14#include "chrome/browser/ui/browser.h" 15#include "chrome/browser/ui/browser_finder.h" 16#include "content/public/browser/navigation_controller.h" 17#include "content/public/browser/web_contents.h" 18 19// The android implementation does not do anything "foreign session" specific. 20// We use it to restore tabs from "recently closed" too. 21// static 22content::WebContents* SessionRestore::RestoreForeignSessionTab( 23 content::WebContents* web_contents, 24 const SessionTab& session_tab, 25 WindowOpenDisposition disposition) { 26 DCHECK(session_tab.navigations.size() > 0); 27 content::BrowserContext* context = web_contents->GetBrowserContext(); 28 Profile* profile = Profile::FromBrowserContext(context); 29 TabModel* tab_model = TabModelList::GetTabModelForWebContents(web_contents); 30 DCHECK(tab_model); 31 std::vector<content::NavigationEntry*> entries = 32 sessions::SerializedNavigationEntry::ToNavigationEntries( 33 session_tab.navigations, profile); 34 content::WebContents* new_web_contents = content::WebContents::Create( 35 content::WebContents::CreateParams(context)); 36 int selected_index = session_tab.normalized_navigation_index(); 37 new_web_contents->GetController().Restore( 38 selected_index, 39 content::NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, 40 &entries); 41 42 TabAndroid* current_tab = TabAndroid::FromWebContents(web_contents); 43 DCHECK(current_tab); 44 if (disposition == CURRENT_TAB) { 45 current_tab->SwapTabContents(web_contents, new_web_contents, false, false); 46 delete web_contents; 47 } else { 48 DCHECK(disposition == NEW_FOREGROUND_TAB || 49 disposition == NEW_BACKGROUND_TAB); 50 tab_model->CreateTab(new_web_contents, current_tab->GetAndroidId()); 51 } 52 return new_web_contents; 53} 54 55// static 56std::vector<Browser*> SessionRestore::RestoreForeignSessionWindows( 57 Profile* profile, 58 chrome::HostDesktopType host_desktop_type, 59 std::vector<const SessionWindow*>::const_iterator begin, 60 std::vector<const SessionWindow*>::const_iterator end) { 61 NOTREACHED(); 62 return std::vector<Browser*>(); 63} 64