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 content::BrowserContext* context = web_contents->GetBrowserContext(); |
25 Profile* profile = Profile::FromBrowserContext(context); | |
26 TabModel* tab_model = TabModelList::GetTabModelWithProfile(profile); | |
27 DCHECK(tab_model); | |
28 std::vector<content::NavigationEntry*> entries; | |
29 TabNavigation::CreateNavigationEntriesFromTabNavigations( | |
30 profile, session_tab.navigations, &entries); | |
31 content::WebContents* new_web_contents = content::WebContents::Create( | |
32 context, NULL, MSG_ROUTING_NONE, 0, 0); | |
33 int selected_index = session_tab.current_navigation_index; | |
34 // Since the current_navigation_index can be larger than the index for number | |
35 // of navigations in the current sessions (chrome://newtab is not stored), we | |
36 // must perform bounds checking. Lowest value allowed is 0, so we need to | |
37 // check for max if navigations.size() == 0 or if selected_index is negative. | |
38 selected_index = std::max( | |
39 0, | |
40 std::min(selected_index, | |
41 static_cast<int>(session_tab.navigations.size() - 1))); | |
42 if (session_tab.navigations.size() > 0) { | |
43 new_web_contents->GetController().Restore(selected_index, | |
44 true, /* from_last_session */ | |
45 &entries); | |
46 } | |
47 tab_model->CreateTab(new_web_contents); | |
17 } | 48 } |
18 | 49 |
19 // static | 50 // static |
20 void SessionRestore::RestoreForeignSessionWindows( | 51 void SessionRestore::RestoreForeignSessionWindows( |
21 Profile* profile, | 52 Profile* profile, |
22 std::vector<const SessionWindow*>::const_iterator begin, | 53 std::vector<const SessionWindow*>::const_iterator begin, |
23 std::vector<const SessionWindow*>::const_iterator end) { | 54 std::vector<const SessionWindow*>::const_iterator end) { |
24 NOTREACHED(); | 55 NOTIMPLEMENTED(); |
Yaron
2012/08/01 20:45:02
This should remain NOTREACHED. We have no plans to
felipeg
2012/08/02 13:07:01
Done.
| |
25 } | 56 } |
OLD | NEW |