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

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

Issue 10696148: Move TabStripModelDelegate off Browser into its own class. (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.h ('k') | chrome/browser/ui/browser_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.h" 5 #include "chrome/browser/ui/browser.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #include <shellapi.h> 9 #include <shellapi.h>
10 #endif // OS_WIN 10 #endif // OS_WIN
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" 95 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h"
96 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" 96 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
97 #include "chrome/browser/ui/browser_command_controller.h" 97 #include "chrome/browser/ui/browser_command_controller.h"
98 #include "chrome/browser/ui/browser_commands.h" 98 #include "chrome/browser/ui/browser_commands.h"
99 #include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h" 99 #include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h"
100 #include "chrome/browser/ui/browser_dialogs.h" 100 #include "chrome/browser/ui/browser_dialogs.h"
101 #include "chrome/browser/ui/browser_finder.h" 101 #include "chrome/browser/ui/browser_finder.h"
102 #include "chrome/browser/ui/browser_list.h" 102 #include "chrome/browser/ui/browser_list.h"
103 #include "chrome/browser/ui/browser_navigator.h" 103 #include "chrome/browser/ui/browser_navigator.h"
104 #include "chrome/browser/ui/browser_tab_restore_service_delegate.h" 104 #include "chrome/browser/ui/browser_tab_restore_service_delegate.h"
105 #include "chrome/browser/ui/browser_tab_strip_model_delegate.h"
105 #include "chrome/browser/ui/browser_tabstrip.h" 106 #include "chrome/browser/ui/browser_tabstrip.h"
106 #include "chrome/browser/ui/browser_toolbar_model_delegate.h" 107 #include "chrome/browser/ui/browser_toolbar_model_delegate.h"
107 #include "chrome/browser/ui/browser_ui_prefs.h" 108 #include "chrome/browser/ui/browser_ui_prefs.h"
108 #include "chrome/browser/ui/browser_window.h" 109 #include "chrome/browser/ui/browser_window.h"
109 #include "chrome/browser/ui/chrome_pages.h" 110 #include "chrome/browser/ui/chrome_pages.h"
110 #include "chrome/browser/ui/chrome_select_file_policy.h" 111 #include "chrome/browser/ui/chrome_select_file_policy.h"
111 #include "chrome/browser/ui/constrained_window_tab_helper.h" 112 #include "chrome/browser/ui/constrained_window_tab_helper.h"
112 #include "chrome/browser/ui/extensions/shell_window.h" 113 #include "chrome/browser/ui/extensions/shell_window.h"
113 #include "chrome/browser/ui/find_bar/find_bar.h" 114 #include "chrome/browser/ui/find_bar/find_bar.h"
114 #include "chrome/browser/ui/find_bar/find_bar_controller.h" 115 #include "chrome/browser/ui/find_bar/find_bar_controller.h"
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 } 294 }
294 295
295 /////////////////////////////////////////////////////////////////////////////// 296 ///////////////////////////////////////////////////////////////////////////////
296 // Browser, Constructors, Creation, Showing: 297 // Browser, Constructors, Creation, Showing:
297 298
298 Browser::Browser(Type type, Profile* profile) 299 Browser::Browser(Type type, Profile* profile)
299 : type_(type), 300 : type_(type),
300 profile_(profile), 301 profile_(profile),
301 window_(NULL), 302 window_(NULL),
302 ALLOW_THIS_IN_INITIALIZER_LIST( 303 ALLOW_THIS_IN_INITIALIZER_LIST(
303 tab_strip_model_(new TabStripModel(this, profile))), 304 tab_strip_model_delegate_(
305 new chrome::BrowserTabStripModelDelegate(this))),
306 ALLOW_THIS_IN_INITIALIZER_LIST(
307 tab_strip_model_(new TabStripModel(tab_strip_model_delegate_.get(),
308 profile))),
304 app_type_(APP_TYPE_HOST), 309 app_type_(APP_TYPE_HOST),
305 chrome_updater_factory_(this), 310 chrome_updater_factory_(this),
306 cancel_download_confirmation_state_(NOT_PROMPTED), 311 cancel_download_confirmation_state_(NOT_PROMPTED),
307 initial_show_state_(ui::SHOW_STATE_DEFAULT), 312 initial_show_state_(ui::SHOW_STATE_DEFAULT),
308 is_session_restore_(false), 313 is_session_restore_(false),
309 ALLOW_THIS_IN_INITIALIZER_LIST( 314 ALLOW_THIS_IN_INITIALIZER_LIST(
310 unload_controller_(new chrome::UnloadController(this))), 315 unload_controller_(new chrome::UnloadController(this))),
311 weak_factory_(this), 316 weak_factory_(this),
312 ALLOW_THIS_IN_INITIALIZER_LIST( 317 ALLOW_THIS_IN_INITIALIZER_LIST(
313 content_setting_bubble_model_delegate_( 318 content_setting_bubble_model_delegate_(
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after
976 } 981 }
977 982
978 /////////////////////////////////////////////////////////////////////////////// 983 ///////////////////////////////////////////////////////////////////////////////
979 // Browser, PageNavigator implementation: 984 // Browser, PageNavigator implementation:
980 985
981 WebContents* Browser::OpenURL(const OpenURLParams& params) { 986 WebContents* Browser::OpenURL(const OpenURLParams& params) {
982 return OpenURLFromTab(NULL, params); 987 return OpenURLFromTab(NULL, params);
983 } 988 }
984 989
985 /////////////////////////////////////////////////////////////////////////////// 990 ///////////////////////////////////////////////////////////////////////////////
986 // Browser, TabStripModelDelegate implementation:
987
988 TabContents* Browser::AddBlankTab(bool foreground) {
989 return AddBlankTabAt(-1, foreground);
990 }
991
992 TabContents* Browser::AddBlankTabAt(int index, bool foreground) {
993 // Time new tab page creation time. We keep track of the timing data in
994 // WebContents, but we want to include the time it takes to create the
995 // WebContents object too.
996 base::TimeTicks new_tab_start_time = base::TimeTicks::Now();
997 chrome::NavigateParams params(this, GURL(chrome::kChromeUINewTabURL),
998 content::PAGE_TRANSITION_TYPED);
999 params.disposition = foreground ? NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB;
1000 params.tabstrip_index = index;
1001 chrome::Navigate(&params);
1002 params.target_contents->web_contents()->SetNewTabStartTime(
1003 new_tab_start_time);
1004 return params.target_contents;
1005 }
1006
1007 Browser* Browser::CreateNewStripWithContents(
1008 TabContents* detached_contents,
1009 const gfx::Rect& window_bounds,
1010 const DockInfo& dock_info,
1011 bool maximize) {
1012 DCHECK(CanSupportWindowFeature(FEATURE_TABSTRIP));
1013
1014 gfx::Rect new_window_bounds = window_bounds;
1015 if (dock_info.GetNewWindowBounds(&new_window_bounds, &maximize))
1016 dock_info.AdjustOtherWindowBounds();
1017
1018 // Create an empty new browser window the same size as the old one.
1019 Browser* browser = new Browser(TYPE_TABBED, profile_);
1020 browser->set_override_bounds(new_window_bounds);
1021 browser->set_initial_show_state(
1022 maximize ? ui::SHOW_STATE_MAXIMIZED : ui::SHOW_STATE_NORMAL);
1023 browser->InitBrowserWindow();
1024 browser->tab_strip_model()->AppendTabContents(detached_contents, true);
1025 // Make sure the loading state is updated correctly, otherwise the throbber
1026 // won't start if the page is loading.
1027 browser->LoadingStateChanged(detached_contents->web_contents());
1028 return browser;
1029 }
1030
1031 int Browser::GetDragActions() const {
1032 return TabStripModelDelegate::TAB_TEAROFF_ACTION | (tab_count() > 1 ?
1033 TabStripModelDelegate::TAB_MOVE_ACTION : 0);
1034 }
1035
1036 TabContents* Browser::CreateTabContentsForURL(
1037 const GURL& url, const content::Referrer& referrer, Profile* profile,
1038 content::PageTransition transition, bool defer_load,
1039 SiteInstance* instance) const {
1040 TabContents* contents = chrome::TabContentsFactory(profile, instance,
1041 MSG_ROUTING_NONE, chrome::GetActiveWebContents(this), NULL);
1042 if (!defer_load) {
1043 // Load the initial URL before adding the new tab contents to the tab strip
1044 // so that the tab contents has navigation state.
1045 contents->web_contents()->GetController().LoadURL(
1046 url, referrer, transition, std::string());
1047 }
1048
1049 return contents;
1050 }
1051
1052 bool Browser::CanDuplicateContentsAt(int index) {
1053 NavigationController& nc =
1054 chrome::GetWebContentsAt(this, index)->GetController();
1055 return nc.GetWebContents() && nc.GetLastCommittedEntry();
1056 }
1057
1058 void Browser::DuplicateContentsAt(int index) {
1059 TabContents* contents = chrome::GetTabContentsAt(this, index);
1060 CHECK(contents);
1061 TabContents* contents_dupe = contents->Clone();
1062
1063 bool pinned = false;
1064 if (CanSupportWindowFeature(FEATURE_TABSTRIP)) {
1065 // If this is a tabbed browser, just create a duplicate tab inside the same
1066 // window next to the tab being duplicated.
1067 int index = tab_strip_model_->GetIndexOfTabContents(contents);
1068 pinned = tab_strip_model_->IsTabPinned(index);
1069 int add_types = TabStripModel::ADD_ACTIVE |
1070 TabStripModel::ADD_INHERIT_GROUP |
1071 (pinned ? TabStripModel::ADD_PINNED : 0);
1072 tab_strip_model_->InsertTabContentsAt(index + 1, contents_dupe, add_types);
1073 } else {
1074 Browser* browser = NULL;
1075 if (is_app()) {
1076 CHECK(!is_type_popup());
1077 CHECK(!is_type_panel());
1078 browser = Browser::CreateWithParams(
1079 Browser::CreateParams::CreateForApp(
1080 TYPE_POPUP, app_name_, gfx::Rect(),profile_));
1081 } else if (is_type_popup()) {
1082 browser = Browser::CreateWithParams(
1083 Browser::CreateParams(TYPE_POPUP, profile_));
1084 }
1085
1086 // Preserve the size of the original window. The new window has already
1087 // been given an offset by the OS, so we shouldn't copy the old bounds.
1088 BrowserWindow* new_window = browser->window();
1089 new_window->SetBounds(gfx::Rect(new_window->GetRestoredBounds().origin(),
1090 window()->GetRestoredBounds().size()));
1091
1092 // We need to show the browser now. Otherwise ContainerWin assumes the
1093 // WebContents is invisible and won't size it.
1094 browser->window()->Show();
1095
1096 // The page transition below is only for the purpose of inserting the tab.
1097 chrome::AddTab(browser, contents_dupe, content::PAGE_TRANSITION_LINK);
1098 }
1099
1100 SessionService* session_service =
1101 SessionServiceFactory::GetForProfileIfExisting(profile_);
1102 if (session_service)
1103 session_service->TabRestored(contents_dupe, pinned);
1104 }
1105
1106 void Browser::CloseFrameAfterDragSession() {
1107 #if !defined(OS_MACOSX)
1108 // This is scheduled to run after we return to the message loop because
1109 // otherwise the frame will think the drag session is still active and ignore
1110 // the request.
1111 // TODO(port): figure out what is required here in a cross-platform world
1112 MessageLoop::current()->PostTask(
1113 FROM_HERE, base::Bind(&Browser::CloseFrame, weak_factory_.GetWeakPtr()));
1114 #endif
1115 }
1116
1117 void Browser::CreateHistoricalTab(TabContents* contents) {
1118 // We don't create historical tabs for incognito windows or windows without
1119 // profiles.
1120 if (!profile() || profile()->IsOffTheRecord())
1121 return;
1122
1123 // We don't create historical tabs for print preview tabs.
1124 if (contents->web_contents()->GetURL() == GURL(chrome::kChromeUIPrintURL))
1125 return;
1126
1127 TabRestoreService* service =
1128 TabRestoreServiceFactory::GetForProfile(profile());
1129
1130 // We only create historical tab entries for tabbed browser windows.
1131 if (service && CanSupportWindowFeature(FEATURE_TABSTRIP)) {
1132 service->CreateHistoricalTab(contents->web_contents(),
1133 tab_strip_model_->GetIndexOfTabContents(contents));
1134 }
1135 }
1136
1137 bool Browser::RunUnloadListenerBeforeClosing(TabContents* contents) {
1138 return Browser::RunUnloadEventsHelper(contents->web_contents());
1139 }
1140
1141 bool Browser::CanBookmarkAllTabs() const {
1142 return chrome::CanBookmarkAllTabs(this);
1143 }
1144
1145 void Browser::BookmarkAllTabs() {
1146 chrome::BookmarkAllTabs(this);
1147 }
1148
1149 bool Browser::CanRestoreTab() {
1150 return chrome::CanRestoreTab(this);
1151 }
1152
1153 void Browser::RestoreTab() {
1154 chrome::RestoreTab(this);
1155 }
1156
1157 ///////////////////////////////////////////////////////////////////////////////
1158 // Browser, TabStripModelObserver implementation: 991 // Browser, TabStripModelObserver implementation:
1159 992
1160 void Browser::TabInsertedAt(TabContents* contents, 993 void Browser::TabInsertedAt(TabContents* contents,
1161 int index, 994 int index,
1162 bool foreground) { 995 bool foreground) {
1163 SetAsDelegate(contents, this); 996 SetAsDelegate(contents, this);
1164 contents->restore_tab_helper()->SetWindowID(session_id()); 997 contents->restore_tab_helper()->SetWindowID(session_id());
1165 998
1166 SyncHistoryWithTabs(index); 999 SyncHistoryWithTabs(index);
1167 1000
(...skipping 1378 matching lines...) Expand 10 before | Expand all | Expand 10 after
2546 if (contents && !allow_js_access) { 2379 if (contents && !allow_js_access) {
2547 contents->web_contents()->GetController().LoadURL( 2380 contents->web_contents()->GetController().LoadURL(
2548 target_url, 2381 target_url,
2549 content::Referrer(), 2382 content::Referrer(),
2550 content::PAGE_TRANSITION_LINK, 2383 content::PAGE_TRANSITION_LINK,
2551 std::string()); // No extra headers. 2384 std::string()); // No extra headers.
2552 } 2385 }
2553 2386
2554 return contents != NULL; 2387 return contents != NULL;
2555 } 2388 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser.h ('k') | chrome/browser/ui/browser_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698