Home | History | Annotate | Download | only in sessions
      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/profiles/profile.h"
     10 #include "chrome/browser/sessions/session_types.h"
     11 #include "chrome/browser/ui/browser.h"
     12 #include "chrome/browser/ui/browser_finder.h"
     13 #include "chrome/browser/ui/android/tab_model/tab_model.h"
     14 #include "chrome/browser/ui/android/tab_model/tab_model_list.h"
     15 #include "content/public/browser/navigation_controller.h"
     16 #include "content/public/browser/web_contents.h"
     17 
     18 // The android implementation does not do anything "foreign session" specific.
     19 // We use it to restore tabs from "recently closed" too.
     20 // static
     21 content::WebContents* SessionRestore::RestoreForeignSessionTab(
     22     content::WebContents* web_contents,
     23     const SessionTab& session_tab,
     24     WindowOpenDisposition disposition) {
     25   DCHECK(session_tab.navigations.size() > 0);
     26   content::BrowserContext* context = web_contents->GetBrowserContext();
     27   Profile* profile = Profile::FromBrowserContext(context);
     28   TabModel* tab_model = TabModelList::GetTabModelWithProfile(profile);
     29   DCHECK(tab_model);
     30   std::vector<content::NavigationEntry*> entries =
     31       sessions::SerializedNavigationEntry::ToNavigationEntries(
     32           session_tab.navigations, profile);
     33   content::WebContents* new_web_contents = content::WebContents::Create(
     34       content::WebContents::CreateParams(context));
     35   int selected_index = session_tab.normalized_navigation_index();
     36   new_web_contents->GetController().Restore(
     37       selected_index,
     38       content::NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY,
     39       &entries);
     40   tab_model->CreateTab(new_web_contents);
     41   return new_web_contents;
     42 }
     43 
     44 // static
     45 std::vector<Browser*> SessionRestore::RestoreForeignSessionWindows(
     46     Profile* profile,
     47     chrome::HostDesktopType host_desktop_type,
     48     std::vector<const SessionWindow*>::const_iterator begin,
     49     std::vector<const SessionWindow*>::const_iterator end) {
     50   NOTREACHED();
     51   return std::vector<Browser*>();
     52 }
     53