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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "chrome/browser/android/tab_android.h" | |
9 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/sessions/session_types.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" | |
11 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/browser/ui/browser_finder.h" | 15 #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/navigation_controller.h" |
16 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
17 | 18 |
18 // The android implementation does not do anything "foreign session" specific. | 19 // The android implementation does not do anything "foreign session" specific. |
19 // We use it to restore tabs from "recently closed" too. | 20 // We use it to restore tabs from "recently closed" too. |
20 // static | 21 // static |
21 content::WebContents* SessionRestore::RestoreForeignSessionTab( | 22 content::WebContents* SessionRestore::RestoreForeignSessionTab( |
22 content::WebContents* web_contents, | 23 content::WebContents* web_contents, |
23 const SessionTab& session_tab, | 24 const SessionTab& session_tab, |
24 WindowOpenDisposition disposition) { | 25 WindowOpenDisposition disposition) { |
25 DCHECK(session_tab.navigations.size() > 0); | 26 DCHECK(session_tab.navigations.size() > 0); |
26 content::BrowserContext* context = web_contents->GetBrowserContext(); | 27 content::BrowserContext* context = web_contents->GetBrowserContext(); |
27 Profile* profile = Profile::FromBrowserContext(context); | 28 Profile* profile = Profile::FromBrowserContext(context); |
28 TabModel* tab_model = TabModelList::GetTabModelWithProfile(profile); | 29 TabModel* tab_model = TabModelList::GetTabModelWithProfile(profile); |
29 DCHECK(tab_model); | 30 DCHECK(tab_model); |
30 std::vector<content::NavigationEntry*> entries = | 31 std::vector<content::NavigationEntry*> entries = |
31 sessions::SerializedNavigationEntry::ToNavigationEntries( | 32 sessions::SerializedNavigationEntry::ToNavigationEntries( |
32 session_tab.navigations, profile); | 33 session_tab.navigations, profile); |
33 content::WebContents* new_web_contents = content::WebContents::Create( | 34 content::WebContents* new_web_contents = content::WebContents::Create( |
34 content::WebContents::CreateParams(context)); | 35 content::WebContents::CreateParams(context)); |
35 int selected_index = session_tab.normalized_navigation_index(); | 36 int selected_index = session_tab.normalized_navigation_index(); |
36 new_web_contents->GetController().Restore( | 37 new_web_contents->GetController().Restore( |
37 selected_index, | 38 selected_index, |
38 content::NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, | 39 content::NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, |
39 &entries); | 40 &entries); |
40 tab_model->CreateTab(new_web_contents); | 41 |
42 if (disposition == CURRENT_TAB) { | |
43 TabAndroid* current_tab = TabAndroid::FromWebContents(web_contents); | |
44 DCHECK(current_tab); | |
45 current_tab->SwapTabContents(web_contents, new_web_contents); | |
Yaron
2013/11/04 18:48:37
looks like you're leaking the old web_contents. Fr
apiccion
2013/11/04 19:43:52
Deleted the object here. Added a comment in .h fil
| |
46 } else { | |
47 DCHECK(disposition == NEW_FOREGROUND_TAB); | |
Yaron
2013/11/04 18:48:37
DCHECK_EQ
apiccion
2013/11/04 19:43:52
Done.
| |
48 tab_model->CreateTab(new_web_contents); | |
49 } | |
41 return new_web_contents; | 50 return new_web_contents; |
42 } | 51 } |
43 | 52 |
44 // static | 53 // static |
45 std::vector<Browser*> SessionRestore::RestoreForeignSessionWindows( | 54 std::vector<Browser*> SessionRestore::RestoreForeignSessionWindows( |
46 Profile* profile, | 55 Profile* profile, |
47 chrome::HostDesktopType host_desktop_type, | 56 chrome::HostDesktopType host_desktop_type, |
48 std::vector<const SessionWindow*>::const_iterator begin, | 57 std::vector<const SessionWindow*>::const_iterator begin, |
49 std::vector<const SessionWindow*>::const_iterator end) { | 58 std::vector<const SessionWindow*>::const_iterator end) { |
50 NOTREACHED(); | 59 NOTREACHED(); |
51 return std::vector<Browser*>(); | 60 return std::vector<Browser*>(); |
52 } | 61 } |
OLD | NEW |