OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/sessions/session_restore.h" | 5 #include "chrome/browser/sessions/session_restore.h" |
6 | 6 |
7 #include "chrome/browser/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
8 #include "chrome/browser/sessions/session_types.h" | 8 #include "chrome/browser/sessions/session_types.h" |
9 #include "webkit/glue/window_open_disposition.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/browser_finder.h" |
| 11 #include "chrome/browser/ui/android/tab_model/tab_model.h" |
| 12 #include "chrome/browser/ui/android/tab_model/tab_model_list.h" |
| 13 #include "content/public/browser/navigation_controller.h" |
| 14 #include "content/public/browser/web_contents.h" |
| 15 #include "ipc/ipc_message.h" |
10 | 16 |
11 // static | 17 // static |
| 18 // The android implementation does not do anything "foreign session" specific. |
| 19 // We use it to restore tabs from "recently closed" too. |
12 void SessionRestore::RestoreForeignSessionTab( | 20 void SessionRestore::RestoreForeignSessionTab( |
13 content::WebContents* source_web_contents, | 21 content::WebContents* web_contents, |
14 const SessionTab& session_tab, | 22 const SessionTab& session_tab, |
15 WindowOpenDisposition disposition) { | 23 WindowOpenDisposition disposition) { |
16 NOTIMPLEMENTED() << "TODO(yfriedman, dtrainor): Upstream this."; | 24 DCHECK(session_tab.navigations.size() > 0); |
| 25 content::BrowserContext* context = web_contents->GetBrowserContext(); |
| 26 Profile* profile = Profile::FromBrowserContext(context); |
| 27 TabModel* tab_model = TabModelList::GetTabModelWithProfile(profile); |
| 28 DCHECK(tab_model); |
| 29 std::vector<content::NavigationEntry*> entries; |
| 30 TabNavigation::CreateNavigationEntriesFromTabNavigations( |
| 31 profile, session_tab.navigations, &entries); |
| 32 content::WebContents* new_web_contents = content::WebContents::Create( |
| 33 context, NULL, MSG_ROUTING_NONE, 0, 0); |
| 34 int selected_index = session_tab.normalized_navigation_index(); |
| 35 new_web_contents->GetController().Restore(selected_index, |
| 36 true, /* from_last_session */ |
| 37 &entries); |
| 38 tab_model->CreateTab(new_web_contents); |
17 } | 39 } |
18 | 40 |
19 // static | 41 // static |
20 void SessionRestore::RestoreForeignSessionWindows( | 42 void SessionRestore::RestoreForeignSessionWindows( |
21 Profile* profile, | 43 Profile* profile, |
22 std::vector<const SessionWindow*>::const_iterator begin, | 44 std::vector<const SessionWindow*>::const_iterator begin, |
23 std::vector<const SessionWindow*>::const_iterator end) { | 45 std::vector<const SessionWindow*>::const_iterator end) { |
24 NOTREACHED(); | 46 NOTREACHED(); |
25 } | 47 } |
OLD | NEW |