Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Side by Side Diff: chrome/browser/sessions/tab_restore_service_helper.cc

Issue 1321713005: Abstract WebContents/NavigationController from core TabRestore code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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/tab_restore_service_helper.h" 5 #include "chrome/browser/sessions/tab_restore_service_helper.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "chrome/browser/sessions/tab_restore_service_delegate.h" 13 #include "chrome/browser/sessions/tab_restore_service_delegate.h"
14 #include "chrome/browser/sessions/tab_restore_service_observer.h" 14 #include "chrome/browser/sessions/tab_restore_service_observer.h"
15 #include "components/sessions/content/content_serialized_navigation_builder.h" 15 #include "components/sessions/core/open_tab.h"
16 #include "components/sessions/core/tab_restore_service_client.h" 16 #include "components/sessions/core/tab_restore_service_client.h"
17 #include "components/sessions/serialized_navigation_entry.h"
17 #include "components/sessions/session_types.h" 18 #include "components/sessions/session_types.h"
18 #include "content/public/browser/navigation_controller.h"
19 #include "content/public/browser/navigation_entry.h"
20 #include "content/public/browser/web_contents.h"
21 19
22 using content::NavigationController; 20 using sessions::OpenTab;
23 using content::NavigationEntry;
24 using content::WebContents;
25 21
26 // TabRestoreServiceHelper::Observer ------------------------------------------- 22 // TabRestoreServiceHelper::Observer -------------------------------------------
27 23
28 TabRestoreServiceHelper::Observer::~Observer() {} 24 TabRestoreServiceHelper::Observer::~Observer() {}
29 25
30 void TabRestoreServiceHelper::Observer::OnClearEntries() {} 26 void TabRestoreServiceHelper::Observer::OnClearEntries() {}
31 27
32 void TabRestoreServiceHelper::Observer::OnRestoreEntryById( 28 void TabRestoreServiceHelper::Observer::OnRestoreEntryById(
33 SessionID::id_type id, 29 SessionID::id_type id,
34 Entries::const_iterator entry_iterator) { 30 Entries::const_iterator entry_iterator) {
(...skipping 25 matching lines...) Expand all
60 void TabRestoreServiceHelper::AddObserver( 56 void TabRestoreServiceHelper::AddObserver(
61 TabRestoreServiceObserver* observer) { 57 TabRestoreServiceObserver* observer) {
62 observer_list_.AddObserver(observer); 58 observer_list_.AddObserver(observer);
63 } 59 }
64 60
65 void TabRestoreServiceHelper::RemoveObserver( 61 void TabRestoreServiceHelper::RemoveObserver(
66 TabRestoreServiceObserver* observer) { 62 TabRestoreServiceObserver* observer) {
67 observer_list_.RemoveObserver(observer); 63 observer_list_.RemoveObserver(observer);
68 } 64 }
69 65
70 void TabRestoreServiceHelper::CreateHistoricalTab( 66 void TabRestoreServiceHelper::CreateHistoricalTab(OpenTab* open_tab,
71 content::WebContents* contents, 67 int index) {
72 int index) {
73 if (restoring_) 68 if (restoring_)
74 return; 69 return;
75 70
76 TabRestoreServiceDelegate* delegate = 71 TabRestoreServiceDelegate* delegate =
77 client_->FindTabRestoreServiceDelegateForWebContents(contents); 72 client_->FindTabRestoreServiceDelegateForTab(open_tab);
78 if (closing_delegates_.find(delegate) != closing_delegates_.end()) 73 if (closing_delegates_.find(delegate) != closing_delegates_.end())
79 return; 74 return;
80 75
81 scoped_ptr<Tab> local_tab(new Tab()); 76 scoped_ptr<Tab> local_tab(new Tab());
82 PopulateTab(local_tab.get(), index, delegate, &contents->GetController()); 77 PopulateTab(local_tab.get(), index, delegate, open_tab);
83 if (local_tab->navigations.empty()) 78 if (local_tab->navigations.empty())
84 return; 79 return;
85 80
86 AddEntry(local_tab.release(), true, true); 81 AddEntry(local_tab.release(), true, true);
87 } 82 }
88 83
89 void TabRestoreServiceHelper::BrowserClosing( 84 void TabRestoreServiceHelper::BrowserClosing(
90 TabRestoreServiceDelegate* delegate) { 85 TabRestoreServiceDelegate* delegate) {
91 closing_delegates_.insert(delegate); 86 closing_delegates_.insert(delegate);
92 87
93 scoped_ptr<Window> window(new Window()); 88 scoped_ptr<Window> window(new Window());
94 window->selected_tab_index = delegate->GetSelectedIndex(); 89 window->selected_tab_index = delegate->GetSelectedIndex();
95 window->timestamp = TimeNow(); 90 window->timestamp = TimeNow();
96 window->app_name = delegate->GetAppName(); 91 window->app_name = delegate->GetAppName();
97 92
98 // Don't use std::vector::resize() because it will push copies of an empty tab 93 // Don't use std::vector::resize() because it will push copies of an empty tab
99 // into the vector, which will give all tabs in a window the same ID. 94 // into the vector, which will give all tabs in a window the same ID.
100 for (int i = 0; i < delegate->GetTabCount(); ++i) { 95 for (int i = 0; i < delegate->GetTabCount(); ++i) {
101 window->tabs.push_back(Tab()); 96 window->tabs.push_back(Tab());
102 } 97 }
103 size_t entry_index = 0; 98 size_t entry_index = 0;
104 for (int tab_index = 0; tab_index < delegate->GetTabCount(); ++tab_index) { 99 for (int tab_index = 0; tab_index < delegate->GetTabCount(); ++tab_index) {
105 PopulateTab(&(window->tabs[entry_index]), 100 PopulateTab(&(window->tabs[entry_index]), tab_index, delegate,
106 tab_index, 101 delegate->GetOpenTabAt(tab_index));
107 delegate,
108 &delegate->GetWebContentsAt(tab_index)->GetController());
109 if (window->tabs[entry_index].navigations.empty()) { 102 if (window->tabs[entry_index].navigations.empty()) {
110 window->tabs.erase(window->tabs.begin() + entry_index); 103 window->tabs.erase(window->tabs.begin() + entry_index);
111 } else { 104 } else {
112 window->tabs[entry_index].browser_id = delegate->GetSessionID().id(); 105 window->tabs[entry_index].browser_id = delegate->GetSessionID().id();
113 entry_index++; 106 entry_index++;
114 } 107 }
115 } 108 }
116 if (window->tabs.size() == 1 && window->app_name.empty()) { 109 if (window->tabs.size() == 1 && window->app_name.empty()) {
117 // Short-circuit creating a Window if only 1 tab was present. This fixes 110 // Short-circuit creating a Window if only 1 tab was present. This fixes
118 // http://crbug.com/56744. Copy the Tab because it's owned by an object on 111 // http://crbug.com/56744. Copy the Tab because it's owned by an object on
(...skipping 16 matching lines...) Expand all
135 if (observer_) 128 if (observer_)
136 observer_->OnClearEntries(); 129 observer_->OnClearEntries();
137 STLDeleteElements(&entries_); 130 STLDeleteElements(&entries_);
138 NotifyTabsChanged(); 131 NotifyTabsChanged();
139 } 132 }
140 133
141 const TabRestoreService::Entries& TabRestoreServiceHelper::entries() const { 134 const TabRestoreService::Entries& TabRestoreServiceHelper::entries() const {
142 return entries_; 135 return entries_;
143 } 136 }
144 137
145 std::vector<content::WebContents*> 138 std::vector<OpenTab*> TabRestoreServiceHelper::RestoreMostRecentEntry(
146 TabRestoreServiceHelper::RestoreMostRecentEntry(
147 TabRestoreServiceDelegate* delegate, 139 TabRestoreServiceDelegate* delegate,
148 int host_desktop_type) { 140 int host_desktop_type) {
149 if (entries_.empty()) 141 if (entries_.empty())
150 return std::vector<WebContents*>(); 142 return std::vector<OpenTab*>();
151 143
152 return RestoreEntryById(delegate, entries_.front()->id, host_desktop_type, 144 return RestoreEntryById(delegate, entries_.front()->id, host_desktop_type,
153 UNKNOWN); 145 UNKNOWN);
154 } 146 }
155 147
156 TabRestoreService::Tab* TabRestoreServiceHelper::RemoveTabEntryById( 148 TabRestoreService::Tab* TabRestoreServiceHelper::RemoveTabEntryById(
157 SessionID::id_type id) { 149 SessionID::id_type id) {
158 Entries::iterator i = GetEntryIteratorById(id); 150 Entries::iterator i = GetEntryIteratorById(id);
159 if (i == entries_.end()) 151 if (i == entries_.end())
160 return NULL; 152 return NULL;
161 153
162 Entry* entry = *i; 154 Entry* entry = *i;
163 if (entry->type != TabRestoreService::TAB) 155 if (entry->type != TabRestoreService::TAB)
164 return NULL; 156 return NULL;
165 157
166 Tab* tab = static_cast<Tab*>(entry); 158 Tab* tab = static_cast<Tab*>(entry);
167 entries_.erase(i); 159 entries_.erase(i);
168 return tab; 160 return tab;
169 } 161 }
170 162
171 std::vector<content::WebContents*> TabRestoreServiceHelper::RestoreEntryById( 163 std::vector<OpenTab*> TabRestoreServiceHelper::RestoreEntryById(
172 TabRestoreServiceDelegate* delegate, 164 TabRestoreServiceDelegate* delegate,
173 SessionID::id_type id, 165 SessionID::id_type id,
174 int host_desktop_type, 166 int host_desktop_type,
175 WindowOpenDisposition disposition) { 167 WindowOpenDisposition disposition) {
176 Entries::iterator entry_iterator = GetEntryIteratorById(id); 168 Entries::iterator entry_iterator = GetEntryIteratorById(id);
177 if (entry_iterator == entries_.end()) 169 if (entry_iterator == entries_.end())
178 // Don't hoark here, we allow an invalid id. 170 // Don't hoark here, we allow an invalid id.
179 return std::vector<WebContents*>(); 171 return std::vector<OpenTab*>();
180 172
181 if (observer_) 173 if (observer_)
182 observer_->OnRestoreEntryById(id, entry_iterator); 174 observer_->OnRestoreEntryById(id, entry_iterator);
183 restoring_ = true; 175 restoring_ = true;
184 Entry* entry = *entry_iterator; 176 Entry* entry = *entry_iterator;
185 177
186 // If the entry's ID does not match the ID that is being restored, then the 178 // If the entry's ID does not match the ID that is being restored, then the
187 // entry is a window from which a single tab will be restored. 179 // entry is a window from which a single tab will be restored.
188 bool restoring_tab_in_window = entry->id != id; 180 bool restoring_tab_in_window = entry->id != id;
189 181
190 if (!restoring_tab_in_window) { 182 if (!restoring_tab_in_window) {
191 entries_.erase(entry_iterator); 183 entries_.erase(entry_iterator);
192 entry_iterator = entries_.end(); 184 entry_iterator = entries_.end();
193 } 185 }
194 186
195 // |delegate| will be NULL in cases where one isn't already available (eg, 187 // |delegate| will be NULL in cases where one isn't already available (eg,
196 // when invoked on Mac OS X with no windows open). In this case, create a 188 // when invoked on Mac OS X with no windows open). In this case, create a
197 // new browser into which we restore the tabs. 189 // new browser into which we restore the tabs.
198 std::vector<WebContents*> web_contents; 190 std::vector<OpenTab*> open_tabs;
199 if (entry->type == TabRestoreService::TAB) { 191 if (entry->type == TabRestoreService::TAB) {
200 Tab* tab = static_cast<Tab*>(entry); 192 Tab* tab = static_cast<Tab*>(entry);
201 WebContents* restored_tab = NULL; 193 OpenTab* restored_tab = NULL;
202 delegate = RestoreTab(*tab, delegate, host_desktop_type, disposition, 194 delegate = RestoreTab(*tab, delegate, host_desktop_type, disposition,
203 &restored_tab); 195 &restored_tab);
204 web_contents.push_back(restored_tab); 196 open_tabs.push_back(restored_tab);
205 delegate->ShowBrowserWindow(); 197 delegate->ShowBrowserWindow();
206 } else if (entry->type == TabRestoreService::WINDOW) { 198 } else if (entry->type == TabRestoreService::WINDOW) {
207 TabRestoreServiceDelegate* current_delegate = delegate; 199 TabRestoreServiceDelegate* current_delegate = delegate;
208 Window* window = static_cast<Window*>(entry); 200 Window* window = static_cast<Window*>(entry);
209 201
210 // When restoring a window, either the entire window can be restored, or a 202 // When restoring a window, either the entire window can be restored, or a
211 // single tab within it. If the entry's ID matches the one to restore, then 203 // single tab within it. If the entry's ID matches the one to restore, then
212 // the entire window will be restored. 204 // the entire window will be restored.
213 if (!restoring_tab_in_window) { 205 if (!restoring_tab_in_window) {
214 delegate = client_->CreateTabRestoreServiceDelegate(host_desktop_type, 206 delegate = client_->CreateTabRestoreServiceDelegate(host_desktop_type,
215 window->app_name); 207 window->app_name);
216 for (size_t tab_i = 0; tab_i < window->tabs.size(); ++tab_i) { 208 for (size_t tab_i = 0; tab_i < window->tabs.size(); ++tab_i) {
217 const Tab& tab = window->tabs[tab_i]; 209 const Tab& tab = window->tabs[tab_i];
218 WebContents* restored_tab = delegate->AddRestoredTab( 210 OpenTab* restored_tab = delegate->AddRestoredTab(
219 tab.navigations, delegate->GetTabCount(), 211 tab.navigations, delegate->GetTabCount(),
220 tab.current_navigation_index, tab.extension_app_id, 212 tab.current_navigation_index, tab.extension_app_id,
221 static_cast<int>(tab_i) == window->selected_tab_index, tab.pinned, 213 static_cast<int>(tab_i) == window->selected_tab_index, tab.pinned,
222 tab.from_last_session, tab.client_data.get(), 214 tab.from_last_session, tab.client_data.get(),
223 tab.user_agent_override); 215 tab.user_agent_override);
224 if (restored_tab) { 216 if (restored_tab) {
225 restored_tab->GetController().LoadIfNecessary(); 217 restored_tab->LoadIfNecessary();
226 client_->OnTabRestored( 218 client_->OnTabRestored(
227 tab.navigations.at(tab.current_navigation_index).virtual_url()); 219 tab.navigations.at(tab.current_navigation_index).virtual_url());
228 web_contents.push_back(restored_tab); 220 open_tabs.push_back(restored_tab);
229 } 221 }
230 } 222 }
231 // All the window's tabs had the same former browser_id. 223 // All the window's tabs had the same former browser_id.
232 if (window->tabs[0].has_browser()) { 224 if (window->tabs[0].has_browser()) {
233 UpdateTabBrowserIDs(window->tabs[0].browser_id, 225 UpdateTabBrowserIDs(window->tabs[0].browser_id,
234 delegate->GetSessionID().id()); 226 delegate->GetSessionID().id());
235 } 227 }
236 } else { 228 } else {
237 // Restore a single tab from the window. Find the tab that matches the ID 229 // Restore a single tab from the window. Find the tab that matches the ID
238 // in the window and restore it. 230 // in the window and restore it.
239 for (std::vector<Tab>::iterator tab_i = window->tabs.begin(); 231 for (std::vector<Tab>::iterator tab_i = window->tabs.begin();
240 tab_i != window->tabs.end(); ++tab_i) { 232 tab_i != window->tabs.end(); ++tab_i) {
241 const Tab& tab = *tab_i; 233 const Tab& tab = *tab_i;
242 if (tab.id == id) { 234 if (tab.id == id) {
243 WebContents* restored_tab = NULL; 235 OpenTab* restored_tab = NULL;
244 delegate = RestoreTab(tab, delegate, host_desktop_type, disposition, 236 delegate = RestoreTab(tab, delegate, host_desktop_type, disposition,
245 &restored_tab); 237 &restored_tab);
246 web_contents.push_back(restored_tab); 238 open_tabs.push_back(restored_tab);
247 window->tabs.erase(tab_i); 239 window->tabs.erase(tab_i);
248 // If restoring the tab leaves the window with nothing else, delete it 240 // If restoring the tab leaves the window with nothing else, delete it
249 // as well. 241 // as well.
250 if (!window->tabs.size()) { 242 if (!window->tabs.size()) {
251 entries_.erase(entry_iterator); 243 entries_.erase(entry_iterator);
252 delete entry; 244 delete entry;
253 } else { 245 } else {
254 // Update the browser ID of the rest of the tabs in the window so if 246 // Update the browser ID of the rest of the tabs in the window so if
255 // any one is restored, it goes into the same window as the tab 247 // any one is restored, it goes into the same window as the tab
256 // being restored now. 248 // being restored now.
257 UpdateTabBrowserIDs(tab.browser_id, 249 UpdateTabBrowserIDs(tab.browser_id,
258 delegate->GetSessionID().id()); 250 delegate->GetSessionID().id());
259 for (std::vector<Tab>::iterator tab_j = window->tabs.begin(); 251 for (std::vector<Tab>::iterator tab_j = window->tabs.begin();
260 tab_j != window->tabs.end(); ++tab_j) { 252 tab_j != window->tabs.end(); ++tab_j) {
261 (*tab_j).browser_id = delegate->GetSessionID().id(); 253 (*tab_j).browser_id = delegate->GetSessionID().id();
262 } 254 }
263 } 255 }
264 break; 256 break;
265 } 257 }
266 } 258 }
267 } 259 }
268 delegate->ShowBrowserWindow(); 260 delegate->ShowBrowserWindow();
269 261
270 if (disposition == CURRENT_TAB && current_delegate && 262 if (disposition == CURRENT_TAB && current_delegate &&
271 current_delegate->GetActiveWebContents()) { 263 current_delegate->GetActiveOpenTab()) {
272 current_delegate->CloseTab(); 264 current_delegate->CloseTab();
273 } 265 }
274 } else { 266 } else {
275 NOTREACHED(); 267 NOTREACHED();
276 } 268 }
277 269
278 if (!restoring_tab_in_window) { 270 if (!restoring_tab_in_window) {
279 delete entry; 271 delete entry;
280 } 272 }
281 273
282 restoring_ = false; 274 restoring_ = false;
283 NotifyTabsChanged(); 275 NotifyTabsChanged();
284 return web_contents; 276 return open_tabs;
285 } 277 }
286 278
287 void TabRestoreServiceHelper::NotifyTabsChanged() { 279 void TabRestoreServiceHelper::NotifyTabsChanged() {
288 FOR_EACH_OBSERVER(TabRestoreServiceObserver, observer_list_, 280 FOR_EACH_OBSERVER(TabRestoreServiceObserver, observer_list_,
289 TabRestoreServiceChanged(tab_restore_service_)); 281 TabRestoreServiceChanged(tab_restore_service_));
290 } 282 }
291 283
292 void TabRestoreServiceHelper::NotifyLoaded() { 284 void TabRestoreServiceHelper::NotifyLoaded() {
293 FOR_EACH_OBSERVER(TabRestoreServiceObserver, observer_list_, 285 FOR_EACH_OBSERVER(TabRestoreServiceObserver, observer_list_,
294 TabRestoreServiceLoaded(tab_restore_service_)); 286 TabRestoreServiceLoaded(tab_restore_service_));
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 if (entry->type == TabRestoreService::TAB) 352 if (entry->type == TabRestoreService::TAB)
361 return ValidateTab(static_cast<Tab*>(entry)); 353 return ValidateTab(static_cast<Tab*>(entry));
362 354
363 if (entry->type == TabRestoreService::WINDOW) 355 if (entry->type == TabRestoreService::WINDOW)
364 return ValidateWindow(static_cast<Window*>(entry)); 356 return ValidateWindow(static_cast<Window*>(entry));
365 357
366 NOTREACHED(); 358 NOTREACHED();
367 return false; 359 return false;
368 } 360 }
369 361
370 void TabRestoreServiceHelper::PopulateTab( 362 void TabRestoreServiceHelper::PopulateTab(Tab* tab,
371 Tab* tab, 363 int index,
372 int index, 364 TabRestoreServiceDelegate* delegate,
373 TabRestoreServiceDelegate* delegate, 365 OpenTab* open_tab) {
374 NavigationController* controller) { 366 const int pending_index = open_tab->GetPendingEntryIndex();
375 const int pending_index = controller->GetPendingEntryIndex(); 367 int entry_count = open_tab->GetEntryCount();
376 int entry_count = controller->GetEntryCount();
377 if (entry_count == 0 && pending_index == 0) 368 if (entry_count == 0 && pending_index == 0)
378 entry_count++; 369 entry_count++;
379 tab->navigations.resize(static_cast<int>(entry_count)); 370 tab->navigations.resize(static_cast<int>(entry_count));
380 for (int i = 0; i < entry_count; ++i) { 371 for (int i = 0; i < entry_count; ++i) {
381 NavigationEntry* entry = (i == pending_index) ? 372 sessions::SerializedNavigationEntry entry =
382 controller->GetPendingEntry() : controller->GetEntryAtIndex(i); 373 (i == pending_index) ? open_tab->GetPendingEntry()
383 tab->navigations[i] = 374 : open_tab->GetEntryAtIndex(i);
384 sessions::ContentSerializedNavigationBuilder::FromNavigationEntry( 375 tab->navigations[i] = entry;
385 i, *entry);
386 } 376 }
387 tab->timestamp = TimeNow(); 377 tab->timestamp = TimeNow();
388 tab->current_navigation_index = controller->GetCurrentEntryIndex(); 378 tab->current_navigation_index = open_tab->GetCurrentEntryIndex();
389 if (tab->current_navigation_index == -1 && entry_count > 0) 379 if (tab->current_navigation_index == -1 && entry_count > 0)
390 tab->current_navigation_index = 0; 380 tab->current_navigation_index = 0;
391 tab->tabstrip_index = index; 381 tab->tabstrip_index = index;
392 382
393 tab->extension_app_id = 383 tab->extension_app_id = client_->GetExtensionAppIDForTab(open_tab);
394 client_->GetExtensionAppIDForWebContents(controller->GetWebContents());
395 384
396 tab->user_agent_override = 385 tab->user_agent_override = open_tab->GetUserAgentOverride();
397 controller->GetWebContents()->GetUserAgentOverride();
398 386
399 tab->client_data = 387 tab->client_data = client_->GetTabClientDataForTab(open_tab);
400 client_->GetTabClientDataForWebContents(controller->GetWebContents());
401 388
402 // Delegate may be NULL during unit tests. 389 // Delegate may be NULL during unit tests.
403 if (delegate) { 390 if (delegate) {
404 tab->browser_id = delegate->GetSessionID().id(); 391 tab->browser_id = delegate->GetSessionID().id();
405 tab->pinned = delegate->IsTabPinned(tab->tabstrip_index); 392 tab->pinned = delegate->IsTabPinned(tab->tabstrip_index);
406 } 393 }
407 } 394 }
408 395
409 TabRestoreServiceDelegate* TabRestoreServiceHelper::RestoreTab( 396 TabRestoreServiceDelegate* TabRestoreServiceHelper::RestoreTab(
410 const Tab& tab, 397 const Tab& tab,
411 TabRestoreServiceDelegate* delegate, 398 TabRestoreServiceDelegate* delegate,
412 int host_desktop_type, 399 int host_desktop_type,
413 WindowOpenDisposition disposition, 400 WindowOpenDisposition disposition,
414 WebContents** contents) { 401 OpenTab** open_tab) {
415 WebContents* web_contents; 402 OpenTab* restored_tab;
416 if (disposition == CURRENT_TAB && delegate) { 403 if (disposition == CURRENT_TAB && delegate) {
417 web_contents = delegate->ReplaceRestoredTab( 404 restored_tab = delegate->ReplaceRestoredTab(
418 tab.navigations, tab.current_navigation_index, tab.from_last_session, 405 tab.navigations, tab.current_navigation_index, tab.from_last_session,
419 tab.extension_app_id, tab.client_data.get(), tab.user_agent_override); 406 tab.extension_app_id, tab.client_data.get(), tab.user_agent_override);
420 } else { 407 } else {
421 // We only respsect the tab's original browser if there's no disposition. 408 // We only respsect the tab's original browser if there's no disposition.
422 if (disposition == UNKNOWN && tab.has_browser()) { 409 if (disposition == UNKNOWN && tab.has_browser()) {
423 delegate = client_->FindTabRestoreServiceDelegateWithID( 410 delegate = client_->FindTabRestoreServiceDelegateWithID(
424 tab.browser_id, host_desktop_type); 411 tab.browser_id, host_desktop_type);
425 } 412 }
426 413
427 int tab_index = -1; 414 int tab_index = -1;
(...skipping 10 matching lines...) Expand all
438 UpdateTabBrowserIDs(tab.browser_id, delegate->GetSessionID().id()); 425 UpdateTabBrowserIDs(tab.browser_id, delegate->GetSessionID().id());
439 } 426 }
440 427
441 // Place the tab at the end if the tab index is no longer valid or 428 // Place the tab at the end if the tab index is no longer valid or
442 // we were passed a specific disposition. 429 // we were passed a specific disposition.
443 if (tab_index < 0 || tab_index > delegate->GetTabCount() || 430 if (tab_index < 0 || tab_index > delegate->GetTabCount() ||
444 disposition != UNKNOWN) { 431 disposition != UNKNOWN) {
445 tab_index = delegate->GetTabCount(); 432 tab_index = delegate->GetTabCount();
446 } 433 }
447 434
448 web_contents = delegate->AddRestoredTab( 435 restored_tab = delegate->AddRestoredTab(
449 tab.navigations, tab_index, tab.current_navigation_index, 436 tab.navigations, tab_index, tab.current_navigation_index,
450 tab.extension_app_id, disposition != NEW_BACKGROUND_TAB, tab.pinned, 437 tab.extension_app_id, disposition != NEW_BACKGROUND_TAB, tab.pinned,
451 tab.from_last_session, tab.client_data.get(), tab.user_agent_override); 438 tab.from_last_session, tab.client_data.get(), tab.user_agent_override);
452 web_contents->GetController().LoadIfNecessary(); 439 restored_tab->LoadIfNecessary();
453 } 440 }
454 client_->OnTabRestored( 441 client_->OnTabRestored(
455 tab.navigations.at(tab.current_navigation_index).virtual_url()); 442 tab.navigations.at(tab.current_navigation_index).virtual_url());
456 if (contents) 443 if (open_tab)
457 *contents = web_contents; 444 *open_tab = restored_tab;
458 445
459 return delegate; 446 return delegate;
460 } 447 }
461 448
462 449
463 bool TabRestoreServiceHelper::ValidateTab(Tab* tab) { 450 bool TabRestoreServiceHelper::ValidateTab(Tab* tab) {
464 if (tab->navigations.empty()) 451 if (tab->navigations.empty())
465 return false; 452 return false;
466 453
467 tab->current_navigation_index = 454 tab->current_navigation_index =
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 Tab* tab = static_cast<Tab*>(entry); 526 Tab* tab = static_cast<Tab*>(entry);
540 if (tab->browser_id == old_id) 527 if (tab->browser_id == old_id)
541 tab->browser_id = new_id; 528 tab->browser_id = new_id;
542 } 529 }
543 } 530 }
544 } 531 }
545 532
546 base::Time TabRestoreServiceHelper::TimeNow() const { 533 base::Time TabRestoreServiceHelper::TimeNow() const {
547 return time_factory_ ? time_factory_->TimeNow() : base::Time::Now(); 534 return time_factory_ ? time_factory_->TimeNow() : base::Time::Now();
548 } 535 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698