Index: chrome/browser/sessions/session_restore_android.cc |
diff --git a/chrome/browser/sessions/session_restore_android.cc b/chrome/browser/sessions/session_restore_android.cc |
index e283e88b70f6ec0fa3ef89b0057350d039fe2ec3..8c14d6b43dd94e40a15a656ebf5d37162f1d1c27 100644 |
--- a/chrome/browser/sessions/session_restore_android.cc |
+++ b/chrome/browser/sessions/session_restore_android.cc |
@@ -1,4 +1,4 @@ |
-// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Copyright (c) 2010 The Chromium Authors. All rights reserved. |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
@@ -6,14 +6,46 @@ |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/browser/sessions/session_types.h" |
-#include "webkit/glue/window_open_disposition.h" |
+#include "chrome/browser/ui/browser.h" |
+#include "chrome/browser/ui/browser_finder.h" |
+#include "chrome/browser/ui/android/tab_model/tab_model.h" |
+#include "chrome/browser/ui/android/tab_model/tab_model_list.h" |
+#include "content/public/browser/navigation_controller.h" |
+#include "content/public/browser/web_contents.h" |
+#include "ipc/ipc_message.h" |
// static |
+// The android implementation does not do anything "foreign session" specific. |
+// We use it to restore tabs from "recently closed" too. |
void SessionRestore::RestoreForeignSessionTab( |
- content::WebContents* source_web_contents, |
+ content::WebContents* web_contents, |
const SessionTab& session_tab, |
WindowOpenDisposition disposition) { |
- NOTIMPLEMENTED() << "TODO(yfriedman, dtrainor): Upstream this."; |
+ // FIXME: This is ugly, but right now we don't have a better way of getting |
+ // the profile from here. |
+ Profile* profile = static_cast<Profile*>(web_contents->GetBrowserContext()); |
+ TabModel* tab_model = TabModelList::GetTabModelWithProfile(profile); |
+ DCHECK(tab_model); |
+ |
+ std::vector<content::NavigationEntry*> entries; |
+ TabNavigation::CreateNavigationEntriesFromTabNavigations( |
+ profile, session_tab.navigations, &entries); |
+ content::BrowserContext* context = profile; |
+ content::WebContents* new_web_contents = content::WebContents::Create( |
+ context, NULL, MSG_ROUTING_NONE, 0, 0); |
+ int selected_index = session_tab.current_navigation_index; |
+ // Since the current_navigation_index can be larger than the index for number |
+ // of navigations in the current sessions (chrome://newtab is not stored), we |
+ // must perform bounds checking. Lowest value allowed is 0, so we need to |
+ // check for max if navigations.size() == 0 or if selected_index is negative. |
+ selected_index = std::max( |
+ 0, |
+ std::min(selected_index, |
+ static_cast<int>(session_tab.navigations.size() - 1))); |
sky
2012/07/31 15:26:09
This is problematic if navigations is empty
felipeg
2012/08/01 16:00:58
Good catch.
I am surprised that we did not see the
|
+ new_web_contents->GetController().Restore(selected_index, |
+ true, /* from_last_session */ |
+ &entries); |
+ tab_model->CreateTab(new_web_contents); |
} |
// static |
@@ -21,5 +53,5 @@ void SessionRestore::RestoreForeignSessionWindows( |
Profile* profile, |
std::vector<const SessionWindow*>::const_iterator begin, |
std::vector<const SessionWindow*>::const_iterator end) { |
- NOTREACHED(); |
+ NOTIMPLEMENTED(); |
} |