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

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

Issue 10702029: Move tab functions off Browser into browser_tabstrip and browser_tabrestore. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 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
« no previous file with comments | « chrome/browser/ui/browser_tabrestore.h ('k') | chrome/browser/ui/browser_tabstrip.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/browser_tabrestore.h"
6
7 #include "chrome/browser/extensions/extension_tab_helper.h"
8 #include "chrome/browser/sessions/session_service.h"
9 #include "chrome/browser/sessions/session_service_factory.h"
10 #include "chrome/browser/tab_contents/tab_util.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_tabstrip.h"
13 #include "chrome/browser/ui/browser_window.h"
14 #include "chrome/browser/ui/tab_contents/tab_contents.h"
15 #include "chrome/browser/ui/tabs/tab_strip_model.h"
16 #include "content/public/browser/navigation_controller.h"
17 #include "content/public/browser/navigation_entry.h"
18 #include "content/public/browser/web_contents.h"
19 #include "content/public/browser/web_contents_view.h"
20 #include "ipc/ipc_message.h"
21
22 using content::WebContents;
23 using content::NavigationController;
24 using content::NavigationEntry;
25
26 namespace chrome {
27
28 int GetIndexForInsertionDuringRestore(Browser* browser, int relative_index) {
29 return (browser->tab_strip_model()->insertion_policy() ==
30 TabStripModel::INSERT_AFTER) ? browser->tab_count() : relative_index;
31 }
32
33 content::WebContents* AddRestoredTab(
34 Browser* browser,
35 const std::vector<TabNavigation>& navigations,
36 int tab_index,
37 int selected_navigation,
38 const std::string& extension_app_id,
39 bool select,
40 bool pin,
41 bool from_last_session,
42 content::SessionStorageNamespace* storage_namespace) {
43 GURL restore_url = navigations.at(selected_navigation).virtual_url();
44 TabContents* tab_contents = chrome::TabContentsFactory(
45 browser->profile(),
46 tab_util::GetSiteInstanceForNewTab(browser->profile(), restore_url),
47 MSG_ROUTING_NONE,
48 chrome::GetActiveWebContents(browser),
49 storage_namespace);
50 WebContents* new_tab = tab_contents->web_contents();
51 tab_contents->extension_tab_helper()->SetExtensionAppById(extension_app_id);
52 std::vector<NavigationEntry*> entries;
53 TabNavigation::CreateNavigationEntriesFromTabNavigations(
54 browser->profile(), navigations, &entries);
55 new_tab->GetController().Restore(
56 selected_navigation, from_last_session, &entries);
57 DCHECK_EQ(0u, entries.size());
58
59 int add_types = select ? TabStripModel::ADD_ACTIVE :
60 TabStripModel::ADD_NONE;
61 if (pin) {
62 int first_mini_tab_idx =
63 browser->tab_strip_model()->IndexOfFirstNonMiniTab();
64 tab_index = std::min(tab_index, first_mini_tab_idx);
65 add_types |= TabStripModel::ADD_PINNED;
66 }
67 browser->tab_strip_model()->InsertTabContentsAt(tab_index, tab_contents,
68 add_types);
69 if (select) {
70 browser->window()->Activate();
71 } else {
72 // We set the size of the view here, before WebKit does its initial
73 // layout. If we don't, the initial layout of background tabs will be
74 // performed with a view width of 0, which may cause script outputs and
75 // anchor link location calculations to be incorrect even after a new
76 // layout with proper view dimensions. TabStripModel::AddTabContents()
77 // contains similar logic.
78 new_tab->GetView()->SizeContents(
79 browser->window()->GetRestoredBounds().size());
80 new_tab->WasHidden();
81 }
82 SessionService* session_service =
83 SessionServiceFactory::GetForProfileIfExisting(browser->profile());
84 if (session_service)
85 session_service->TabRestored(tab_contents, pin);
86 return new_tab;
87 }
88
89 void ReplaceRestoredTab(
90 Browser* browser,
91 const std::vector<TabNavigation>& navigations,
92 int selected_navigation,
93 bool from_last_session,
94 const std::string& extension_app_id,
95 content::SessionStorageNamespace* session_storage_namespace) {
96 GURL restore_url = navigations.at(selected_navigation).virtual_url();
97 TabContents* tab_contents = chrome::TabContentsFactory(
98 browser->profile(),
99 tab_util::GetSiteInstanceForNewTab(browser->profile(), restore_url),
100 MSG_ROUTING_NONE,
101 GetActiveWebContents(browser),
102 session_storage_namespace);
103 tab_contents->extension_tab_helper()->SetExtensionAppById(extension_app_id);
104 WebContents* replacement = tab_contents->web_contents();
105 std::vector<NavigationEntry*> entries;
106 TabNavigation::CreateNavigationEntriesFromTabNavigations(
107 browser->profile(), navigations, &entries);
108 replacement->GetController().Restore(
109 selected_navigation, from_last_session, &entries);
110 DCHECK_EQ(0u, entries.size());
111
112 browser->tab_strip_model()->ReplaceNavigationControllerAt(
113 browser->active_index(),
114 tab_contents);
115 }
116
117 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser_tabrestore.h ('k') | chrome/browser/ui/browser_tabstrip.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698