Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/session_restore.h" | 5 #include "chrome/browser/sessions/session_restore.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <list> | 10 #include <list> |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 | 79 |
| 80 bool HasSingleNewTabPage(Browser* browser) { | 80 bool HasSingleNewTabPage(Browser* browser) { |
| 81 if (browser->tab_strip_model()->count() != 1) | 81 if (browser->tab_strip_model()->count() != 1) |
| 82 return false; | 82 return false; |
| 83 const content::WebContents* active_tab = | 83 const content::WebContents* active_tab = |
| 84 browser->tab_strip_model()->GetWebContentsAt(0); | 84 browser->tab_strip_model()->GetWebContentsAt(0); |
| 85 return active_tab->GetURL() == chrome::kChromeUINewTabURL || | 85 return active_tab->GetURL() == chrome::kChromeUINewTabURL || |
| 86 search::IsInstantNTP(active_tab); | 86 search::IsInstantNTP(active_tab); |
| 87 } | 87 } |
| 88 | 88 |
| 89 Profile* SafeProfileForNewWindows(Profile* profile) { | |
| 90 // Guest sessions must always be OffTheRecord when opening windows. | |
| 91 return profile->IsGuestSession() ? profile->GetOffTheRecordProfile() | |
|
sky
2017/06/07 19:21:40
I'm a little confused by this, and forgive me beca
shrike
2017/06/07 20:19:05
Gosh, I wish could even start to comment. I know n
| |
| 92 : profile; | |
| 93 } | |
| 94 | |
| 89 class SessionRestoreImpl; | 95 class SessionRestoreImpl; |
| 90 | 96 |
| 91 // Pointers to SessionRestoreImpls which are currently restoring the session. | 97 // Pointers to SessionRestoreImpls which are currently restoring the session. |
| 92 std::set<SessionRestoreImpl*>* active_session_restorers = nullptr; | 98 std::set<SessionRestoreImpl*>* active_session_restorers = nullptr; |
| 93 | 99 |
| 94 // SessionRestoreImpl --------------------------------------------------------- | 100 // SessionRestoreImpl --------------------------------------------------------- |
| 95 | 101 |
| 96 // SessionRestoreImpl is responsible for fetching the set of tabs to create | 102 // SessionRestoreImpl is responsible for fetching the set of tabs to create |
| 97 // from SessionService. SessionRestoreImpl deletes itself when done. | 103 // from SessionService. SessionRestoreImpl deletes itself when done. |
| 98 | 104 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 207 WindowOpenDisposition disposition) { | 213 WindowOpenDisposition disposition) { |
| 208 DCHECK(!tab.navigations.empty()); | 214 DCHECK(!tab.navigations.empty()); |
| 209 int selected_index = tab.current_navigation_index; | 215 int selected_index = tab.current_navigation_index; |
| 210 selected_index = std::max( | 216 selected_index = std::max( |
| 211 0, | 217 0, |
| 212 std::min(selected_index, static_cast<int>(tab.navigations.size() - 1))); | 218 std::min(selected_index, static_cast<int>(tab.navigations.size() - 1))); |
| 213 | 219 |
| 214 bool use_new_window = disposition == WindowOpenDisposition::NEW_WINDOW; | 220 bool use_new_window = disposition == WindowOpenDisposition::NEW_WINDOW; |
| 215 | 221 |
| 216 Browser* browser = use_new_window | 222 Browser* browser = use_new_window |
| 217 ? new Browser(Browser::CreateParams(profile_, true)) | 223 ? new Browser(Browser::CreateParams( |
| 224 SafeProfileForNewWindows(profile_), true)) | |
| 218 : browser_; | 225 : browser_; |
| 219 | 226 |
| 220 RecordAppLaunchForTab(browser, tab, selected_index); | 227 RecordAppLaunchForTab(browser, tab, selected_index); |
| 221 | 228 |
| 222 WebContents* web_contents; | 229 WebContents* web_contents; |
| 223 if (disposition == WindowOpenDisposition::CURRENT_TAB) { | 230 if (disposition == WindowOpenDisposition::CURRENT_TAB) { |
| 224 DCHECK(!use_new_window); | 231 DCHECK(!use_new_window); |
| 225 web_contents = chrome::ReplaceRestoredTab( | 232 web_contents = chrome::ReplaceRestoredTab( |
| 226 browser, tab.navigations, selected_index, true, tab.extension_app_id, | 233 browser, tab.navigations, selected_index, true, tab.extension_app_id, |
| 227 nullptr, tab.user_agent_override); | 234 nullptr, tab.user_agent_override); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 285 // | 292 // |
| 286 // If successful, this begins loading tabs and deletes itself when all tabs | 293 // If successful, this begins loading tabs and deletes itself when all tabs |
| 287 // have been loaded. | 294 // have been loaded. |
| 288 // | 295 // |
| 289 // Returns the Browser that was created, if any. | 296 // Returns the Browser that was created, if any. |
| 290 Browser* FinishedTabCreation(bool succeeded, | 297 Browser* FinishedTabCreation(bool succeeded, |
| 291 bool created_tabbed_browser, | 298 bool created_tabbed_browser, |
| 292 std::vector<RestoredTab>* contents_created) { | 299 std::vector<RestoredTab>* contents_created) { |
| 293 Browser* browser = nullptr; | 300 Browser* browser = nullptr; |
| 294 if (!created_tabbed_browser && always_create_tabbed_browser_) { | 301 if (!created_tabbed_browser && always_create_tabbed_browser_) { |
| 295 browser = new Browser(Browser::CreateParams(profile_, false)); | 302 browser = new Browser( |
| 303 Browser::CreateParams(SafeProfileForNewWindows(profile_), false)); | |
| 296 if (urls_to_open_.empty()) { | 304 if (urls_to_open_.empty()) { |
| 297 // No tab browsers were created and no URLs were supplied on the command | 305 // No tab browsers were created and no URLs were supplied on the command |
| 298 // line. Open the new tab page. | 306 // line. Open the new tab page. |
| 299 urls_to_open_.push_back(GURL(chrome::kChromeUINewTabURL)); | 307 urls_to_open_.push_back(GURL(chrome::kChromeUINewTabURL)); |
| 300 } | 308 } |
| 301 AppendURLsToBrowser(browser, urls_to_open_); | 309 AppendURLsToBrowser(browser, urls_to_open_); |
| 302 browser->window()->Show(); | 310 browser->window()->Show(); |
| 303 } | 311 } |
| 304 | 312 |
| 305 if (succeeded) { | 313 if (succeeded) { |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 622 DCHECK(web_contents->GetController().NeedsReload()); | 630 DCHECK(web_contents->GetController().NeedsReload()); |
| 623 | 631 |
| 624 return web_contents; | 632 return web_contents; |
| 625 } | 633 } |
| 626 | 634 |
| 627 Browser* CreateRestoredBrowser(Browser::Type type, | 635 Browser* CreateRestoredBrowser(Browser::Type type, |
| 628 gfx::Rect bounds, | 636 gfx::Rect bounds, |
| 629 const std::string& workspace, | 637 const std::string& workspace, |
| 630 ui::WindowShowState show_state, | 638 ui::WindowShowState show_state, |
| 631 const std::string& app_name) { | 639 const std::string& app_name) { |
| 632 Browser::CreateParams params(type, profile_, false); | 640 Profile* profile = SafeProfileForNewWindows(profile_); |
| 641 Browser::CreateParams params(type, profile, false); | |
| 633 if (!app_name.empty()) { | 642 if (!app_name.empty()) { |
| 634 const bool trusted_source = true; // We only store trusted app windows. | 643 const bool trusted_source = true; // We only store trusted app windows. |
| 635 params = Browser::CreateParams::CreateForApp(app_name, trusted_source, | 644 params = Browser::CreateParams::CreateForApp(app_name, trusted_source, |
| 636 bounds, profile_, false); | 645 bounds, profile, false); |
| 637 } else { | 646 } else { |
| 638 params.initial_bounds = bounds; | 647 params.initial_bounds = bounds; |
| 639 } | 648 } |
| 640 params.initial_show_state = show_state; | 649 params.initial_show_state = show_state; |
| 641 params.initial_workspace = workspace; | 650 params.initial_workspace = workspace; |
| 642 params.is_session_restore = true; | 651 params.is_session_restore = true; |
| 643 return new Browser(params); | 652 return new Browser(params); |
| 644 } | 653 } |
| 645 | 654 |
| 646 void ShowBrowser(Browser* browser, int selected_tab_index) { | 655 void ShowBrowser(Browser* browser, int selected_tab_index) { |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 844 // static | 853 // static |
| 845 SessionRestore::CallbackSubscription | 854 SessionRestore::CallbackSubscription |
| 846 SessionRestore::RegisterOnSessionRestoredCallback( | 855 SessionRestore::RegisterOnSessionRestoredCallback( |
| 847 const base::Callback<void(int)>& callback) { | 856 const base::Callback<void(int)>& callback) { |
| 848 return on_session_restored_callbacks()->Add(callback); | 857 return on_session_restored_callbacks()->Add(callback); |
| 849 } | 858 } |
| 850 | 859 |
| 851 // static | 860 // static |
| 852 base::CallbackList<void(int)>* | 861 base::CallbackList<void(int)>* |
| 853 SessionRestore::on_session_restored_callbacks_ = nullptr; | 862 SessionRestore::on_session_restored_callbacks_ = nullptr; |
| OLD | NEW |