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

Side by Side Diff: chrome/browser/ui/browser_tabrestore.cc

Issue 15055003: Do not submit: high level overview patch. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix build. Created 7 years, 7 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 | Annotate | Revision Log
OLDNEW
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/ui/browser_tabrestore.h" 5 #include "chrome/browser/ui/browser_tabrestore.h"
6 6
7 #include "chrome/browser/extensions/tab_helper.h" 7 #include "chrome/browser/extensions/tab_helper.h"
8 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/sessions/session_service.h" 9 #include "chrome/browser/sessions/session_service.h"
10 #include "chrome/browser/sessions/session_service_factory.h" 10 #include "chrome/browser/sessions/session_service_factory.h"
11 #include "chrome/browser/sessions/session_tab_helper.h"
11 #include "chrome/browser/tab_contents/tab_util.h" 12 #include "chrome/browser/tab_contents/tab_util.h"
12 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/browser_window.h" 14 #include "chrome/browser/ui/browser_window.h"
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" 15 #include "chrome/browser/ui/tabs/tab_strip_model.h"
15 #include "content/public/browser/navigation_controller.h" 16 #include "content/public/browser/navigation_controller.h"
16 #include "content/public/browser/navigation_entry.h" 17 #include "content/public/browser/navigation_entry.h"
17 #include "content/public/browser/session_storage_namespace.h" 18 #include "content/public/browser/session_storage_namespace.h"
18 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
19 #include "content/public/browser/web_contents_view.h" 20 #include "content/public/browser/web_contents_view.h"
20 21
(...skipping 15 matching lines...) Expand all
36 NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY; 37 NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY;
37 } 38 }
38 39
39 WebContents* CreateRestoredTab( 40 WebContents* CreateRestoredTab(
40 Browser* browser, 41 Browser* browser,
41 const std::vector<SerializedNavigationEntry>& navigations, 42 const std::vector<SerializedNavigationEntry>& navigations,
42 int selected_navigation, 43 int selected_navigation,
43 const std::string& extension_app_id, 44 const std::string& extension_app_id,
44 bool from_last_session, 45 bool from_last_session,
45 content::SessionStorageNamespace* session_storage_namespace, 46 content::SessionStorageNamespace* session_storage_namespace,
46 const std::string& user_agent_override) { 47 const std::string& user_agent_override,
48 const int64 sync_id) {
47 GURL restore_url = navigations.at(selected_navigation).virtual_url(); 49 GURL restore_url = navigations.at(selected_navigation).virtual_url();
48 // TODO(ajwong): Remove the temporary session_storage_namespace_map when 50 // TODO(ajwong): Remove the temporary session_storage_namespace_map when
49 // we teach session restore to understand that one tab can have multiple 51 // we teach session restore to understand that one tab can have multiple
50 // SessionStorageNamespace objects. Also remove the 52 // SessionStorageNamespace objects. Also remove the
51 // session_storage_namespace.h include since we only need that to assign 53 // session_storage_namespace.h include since we only need that to assign
52 // into the map. 54 // into the map.
53 content::SessionStorageNamespaceMap session_storage_namespace_map; 55 content::SessionStorageNamespaceMap session_storage_namespace_map;
54 session_storage_namespace_map[std::string()] = session_storage_namespace; 56 session_storage_namespace_map[std::string()] = session_storage_namespace;
55 WebContents::CreateParams create_params( 57 WebContents::CreateParams create_params(
56 browser->profile(), 58 browser->profile(),
57 tab_util::GetSiteInstanceForNewTab(browser->profile(), restore_url)); 59 tab_util::GetSiteInstanceForNewTab(browser->profile(), restore_url));
58 WebContents* base_web_contents = 60 WebContents* base_web_contents =
59 browser->tab_strip_model()->GetActiveWebContents(); 61 browser->tab_strip_model()->GetActiveWebContents();
60 if (base_web_contents) { 62 if (base_web_contents) {
61 create_params.initial_size = 63 create_params.initial_size =
62 base_web_contents->GetView()->GetContainerSize(); 64 base_web_contents->GetView()->GetContainerSize();
63 } 65 }
64 WebContents* web_contents = content::WebContents::CreateWithSessionStorage( 66 WebContents* web_contents = content::WebContents::CreateWithSessionStorage(
65 create_params, 67 create_params,
66 session_storage_namespace_map); 68 session_storage_namespace_map);
67 extensions::TabHelper::CreateForWebContents(web_contents); 69 extensions::TabHelper::CreateForWebContents(web_contents);
68 extensions::TabHelper::FromWebContents(web_contents)-> 70 SessionTabHelper::CreateForWebContents(web_contents);
69 SetExtensionAppById(extension_app_id); 71 SessionTabHelper::FromWebContents(web_contents)->SetSessionSyncId(sync_id);
72 extensions::TabHelper::FromWebContents(web_contents)
73 ->SetExtensionAppById(extension_app_id);
70 std::vector<NavigationEntry*> entries = 74 std::vector<NavigationEntry*> entries =
71 SerializedNavigationEntry::ToNavigationEntries( 75 SerializedNavigationEntry::ToNavigationEntries(navigations,
72 navigations, browser->profile()); 76 browser->profile());
73 web_contents->SetUserAgentOverride(user_agent_override); 77 web_contents->SetUserAgentOverride(user_agent_override);
74 web_contents->GetController().Restore( 78 web_contents->GetController().Restore(
75 selected_navigation, GetRestoreType(browser, from_last_session), 79 selected_navigation, GetRestoreType(browser, from_last_session),
76 &entries); 80 &entries);
77 DCHECK_EQ(0u, entries.size()); 81 DCHECK_EQ(0u, entries.size());
78 82
79 return web_contents; 83 return web_contents;
80 } 84 }
81 85
82 } // namespace 86 } // namespace
83 87
84 content::WebContents* AddRestoredTab( 88 content::WebContents* AddRestoredTab(
85 Browser* browser, 89 Browser* browser,
86 const std::vector<SerializedNavigationEntry>& navigations, 90 const std::vector<SerializedNavigationEntry>& navigations,
87 int tab_index, 91 int tab_index,
88 int selected_navigation, 92 int selected_navigation,
89 const std::string& extension_app_id, 93 const std::string& extension_app_id,
90 bool select, 94 bool select,
91 bool pin, 95 bool pin,
92 bool from_last_session, 96 bool from_last_session,
93 content::SessionStorageNamespace* session_storage_namespace, 97 content::SessionStorageNamespace* session_storage_namespace,
94 const std::string& user_agent_override) { 98 const std::string& user_agent_override,
99 const int64& sync_id) {
95 WebContents* web_contents = CreateRestoredTab(browser, 100 WebContents* web_contents = CreateRestoredTab(browser,
96 navigations, 101 navigations,
97 selected_navigation, 102 selected_navigation,
98 extension_app_id, 103 extension_app_id,
99 from_last_session, 104 from_last_session,
100 session_storage_namespace, 105 session_storage_namespace,
101 user_agent_override); 106 user_agent_override,
107 sync_id);
102 108
103 int add_types = select ? TabStripModel::ADD_ACTIVE 109 int add_types = select ? TabStripModel::ADD_ACTIVE
104 : TabStripModel::ADD_NONE; 110 : TabStripModel::ADD_NONE;
105 if (pin) { 111 if (pin) {
106 int first_mini_tab_idx = 112 int first_mini_tab_idx =
107 browser->tab_strip_model()->IndexOfFirstNonMiniTab(); 113 browser->tab_strip_model()->IndexOfFirstNonMiniTab();
108 tab_index = std::min(tab_index, first_mini_tab_idx); 114 tab_index = std::min(tab_index, first_mini_tab_idx);
109 add_types |= TabStripModel::ADD_PINNED; 115 add_types |= TabStripModel::ADD_PINNED;
110 } 116 }
111 browser->tab_strip_model()->InsertWebContentsAt(tab_index, web_contents, 117 browser->tab_strip_model()->InsertWebContentsAt(tab_index, web_contents,
(...skipping 18 matching lines...) Expand all
130 return web_contents; 136 return web_contents;
131 } 137 }
132 138
133 void ReplaceRestoredTab( 139 void ReplaceRestoredTab(
134 Browser* browser, 140 Browser* browser,
135 const std::vector<SerializedNavigationEntry>& navigations, 141 const std::vector<SerializedNavigationEntry>& navigations,
136 int selected_navigation, 142 int selected_navigation,
137 bool from_last_session, 143 bool from_last_session,
138 const std::string& extension_app_id, 144 const std::string& extension_app_id,
139 content::SessionStorageNamespace* session_storage_namespace, 145 content::SessionStorageNamespace* session_storage_namespace,
140 const std::string& user_agent_override) { 146 const std::string& user_agent_override,
147 const int64& sync_id) {
141 WebContents* web_contents = CreateRestoredTab(browser, 148 WebContents* web_contents = CreateRestoredTab(browser,
142 navigations, 149 navigations,
143 selected_navigation, 150 selected_navigation,
144 extension_app_id, 151 extension_app_id,
145 from_last_session, 152 from_last_session,
146 session_storage_namespace, 153 session_storage_namespace,
147 user_agent_override); 154 user_agent_override,
155 sync_id);
148 156
149 // ReplaceWebContentsAt won't animate in the restoration, so manually do the 157 // ReplaceWebContentsAt won't animate in the restoration, so manually do the
150 // equivalent of ReplaceWebContentsAt. 158 // equivalent of ReplaceWebContentsAt.
151 TabStripModel* tab_strip = browser->tab_strip_model(); 159 TabStripModel* tab_strip = browser->tab_strip_model();
152 int insertion_index = tab_strip->active_index(); 160 int insertion_index = tab_strip->active_index();
153 tab_strip->InsertWebContentsAt(insertion_index + 1, 161 tab_strip->InsertWebContentsAt(insertion_index + 1,
154 web_contents, 162 web_contents,
155 TabStripModel::ADD_ACTIVE | 163 TabStripModel::ADD_ACTIVE |
156 TabStripModel::ADD_INHERIT_GROUP); 164 TabStripModel::ADD_INHERIT_GROUP);
157 tab_strip->CloseWebContentsAt(insertion_index, TabStripModel::CLOSE_NONE); 165 tab_strip->CloseWebContentsAt(insertion_index, TabStripModel::CLOSE_NONE);
158 } 166 }
159 167
160 } // namespace chrome 168 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698