| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <shellapi.h> | 8 #include <shellapi.h> |
| 9 #include <windows.h> | 9 #include <windows.h> |
| 10 #endif // OS_WIN | 10 #endif // OS_WIN |
| (...skipping 1172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1183 tab_handler_->GetTabStripModel()->active_index(), | 1183 tab_handler_->GetTabStripModel()->active_index(), |
| 1184 wrapper); | 1184 wrapper); |
| 1185 } | 1185 } |
| 1186 | 1186 |
| 1187 bool Browser::CanRestoreTab() { | 1187 bool Browser::CanRestoreTab() { |
| 1188 return command_updater_.IsCommandEnabled(IDC_RESTORE_TAB); | 1188 return command_updater_.IsCommandEnabled(IDC_RESTORE_TAB); |
| 1189 } | 1189 } |
| 1190 | 1190 |
| 1191 bool Browser::NavigateToIndexWithDisposition(int index, | 1191 bool Browser::NavigateToIndexWithDisposition(int index, |
| 1192 WindowOpenDisposition disp) { | 1192 WindowOpenDisposition disp) { |
| 1193 NavigationController& controller = | 1193 TabContentsWrapper* tab = GetOrCloneTabWrapperForDisposition(disp); |
| 1194 GetOrCloneTabForDisposition(disp)->controller(); | 1194 |
| 1195 NavigationController& controller = tab->controller(); |
| 1195 if (index < 0 || index >= controller.entry_count()) | 1196 if (index < 0 || index >= controller.entry_count()) |
| 1196 return false; | 1197 return false; |
| 1197 controller.GoToIndex(index); | 1198 controller.GoToIndex(index); |
| 1199 |
| 1200 CreateNewBrowserForDisposition(tab, disp); |
| 1201 |
| 1198 return true; | 1202 return true; |
| 1199 } | 1203 } |
| 1200 | 1204 |
| 1201 browser::NavigateParams Browser::GetSingletonTabNavigateParams( | 1205 browser::NavigateParams Browser::GetSingletonTabNavigateParams( |
| 1202 const GURL& url) { | 1206 const GURL& url) { |
| 1203 browser::NavigateParams params(this, url, PageTransition::AUTO_BOOKMARK); | 1207 browser::NavigateParams params(this, url, PageTransition::AUTO_BOOKMARK); |
| 1204 params.disposition = SINGLETON_TAB; | 1208 params.disposition = SINGLETON_TAB; |
| 1205 params.window_action = browser::NavigateParams::SHOW_WINDOW; | 1209 params.window_action = browser::NavigateParams::SHOW_WINDOW; |
| 1206 params.user_gesture = true; | 1210 params.user_gesture = true; |
| 1207 return params; | 1211 return params; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1260 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_VERTICAL_TABS, show_main_ui); | 1264 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_VERTICAL_TABS, show_main_ui); |
| 1261 command_updater_.UpdateCommandEnabled(IDC_COMPACT_NAVBAR, show_main_ui); | 1265 command_updater_.UpdateCommandEnabled(IDC_COMPACT_NAVBAR, show_main_ui); |
| 1262 #if defined (ENABLE_PROFILING) && !defined(NO_TCMALLOC) | 1266 #if defined (ENABLE_PROFILING) && !defined(NO_TCMALLOC) |
| 1263 command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui); | 1267 command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui); |
| 1264 #endif | 1268 #endif |
| 1265 } | 1269 } |
| 1266 | 1270 |
| 1267 /////////////////////////////////////////////////////////////////////////////// | 1271 /////////////////////////////////////////////////////////////////////////////// |
| 1268 // Browser, Assorted browser commands: | 1272 // Browser, Assorted browser commands: |
| 1269 | 1273 |
| 1270 bool Browser::ShouldOpenNewTabForWindowDisposition( | 1274 bool Browser::ShouldOpenNewTabForDisposition( |
| 1271 WindowOpenDisposition disposition) { | 1275 WindowOpenDisposition disposition) { |
| 1272 return (disposition == NEW_FOREGROUND_TAB || | 1276 return (disposition == NEW_FOREGROUND_TAB || |
| 1273 disposition == NEW_BACKGROUND_TAB); | 1277 disposition == NEW_BACKGROUND_TAB); |
| 1274 } | 1278 } |
| 1275 | 1279 |
| 1276 TabContents* Browser::GetOrCloneTabForDisposition( | 1280 TabContents* Browser::GetOrCloneTabForDisposition( |
| 1277 WindowOpenDisposition disposition) { | 1281 WindowOpenDisposition disposition) { |
| 1282 return GetOrCloneTabWrapperForDisposition(disposition)->tab_contents(); |
| 1283 } |
| 1284 |
| 1285 TabContentsWrapper* Browser::GetOrCloneTabWrapperForDisposition( |
| 1286 WindowOpenDisposition disposition) { |
| 1278 TabContentsWrapper* current_tab = GetSelectedTabContentsWrapper(); | 1287 TabContentsWrapper* current_tab = GetSelectedTabContentsWrapper(); |
| 1279 if (ShouldOpenNewTabForWindowDisposition(disposition)) { | 1288 |
| 1280 current_tab = current_tab->Clone(); | 1289 if (disposition == NEW_WINDOW) |
| 1290 return current_tab->Clone(); |
| 1291 |
| 1292 if (ShouldOpenNewTabForDisposition(disposition)) { |
| 1293 TabContentsWrapper* new_tab = current_tab->Clone(); |
| 1281 tab_handler_->GetTabStripModel()->AddTabContents( | 1294 tab_handler_->GetTabStripModel()->AddTabContents( |
| 1282 current_tab, -1, PageTransition::LINK, | 1295 new_tab, -1, PageTransition::LINK, |
| 1283 disposition == NEW_FOREGROUND_TAB ? TabStripModel::ADD_ACTIVE : | 1296 disposition == NEW_FOREGROUND_TAB ? TabStripModel::ADD_ACTIVE : |
| 1284 TabStripModel::ADD_NONE); | 1297 TabStripModel::ADD_NONE); |
| 1298 return new_tab; |
| 1285 } | 1299 } |
| 1286 return current_tab->tab_contents(); | 1300 |
| 1301 return current_tab; |
| 1302 } |
| 1303 |
| 1304 void Browser::CreateNewBrowserForDisposition( |
| 1305 TabContentsWrapper* tab_contents, WindowOpenDisposition disposition) { |
| 1306 if (disposition == NEW_WINDOW) { |
| 1307 Browser* browser = Create(profile_); |
| 1308 browser->AddTab(tab_contents, PageTransition::LINK); |
| 1309 browser->window()->Show(); |
| 1310 } |
| 1287 } | 1311 } |
| 1288 | 1312 |
| 1289 void Browser::UpdateTabStripModelInsertionPolicy() { | 1313 void Browser::UpdateTabStripModelInsertionPolicy() { |
| 1290 tab_handler_->GetTabStripModel()->SetInsertionPolicy(UseVerticalTabs() ? | 1314 tab_handler_->GetTabStripModel()->SetInsertionPolicy(UseVerticalTabs() ? |
| 1291 TabStripModel::INSERT_BEFORE : TabStripModel::INSERT_AFTER); | 1315 TabStripModel::INSERT_BEFORE : TabStripModel::INSERT_AFTER); |
| 1292 } | 1316 } |
| 1293 | 1317 |
| 1294 void Browser::UseVerticalTabsChanged() { | 1318 void Browser::UseVerticalTabsChanged() { |
| 1295 UpdateTabStripModelInsertionPolicy(); | 1319 UpdateTabStripModelInsertionPolicy(); |
| 1296 window()->ToggleTabStripMode(); | 1320 window()->ToggleTabStripMode(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1343 bool can_close = !watcher || watcher->CanCloseBrowser(this); | 1367 bool can_close = !watcher || watcher->CanCloseBrowser(this); |
| 1344 if (!can_close && is_attempting_to_close_browser_) | 1368 if (!can_close && is_attempting_to_close_browser_) |
| 1345 CancelWindowClose(); | 1369 CancelWindowClose(); |
| 1346 return can_close; | 1370 return can_close; |
| 1347 } | 1371 } |
| 1348 | 1372 |
| 1349 void Browser::GoBack(WindowOpenDisposition disposition) { | 1373 void Browser::GoBack(WindowOpenDisposition disposition) { |
| 1350 UserMetrics::RecordAction(UserMetricsAction("Back")); | 1374 UserMetrics::RecordAction(UserMetricsAction("Back")); |
| 1351 | 1375 |
| 1352 TabContentsWrapper* current_tab = GetSelectedTabContentsWrapper(); | 1376 TabContentsWrapper* current_tab = GetSelectedTabContentsWrapper(); |
| 1353 if (current_tab->controller().CanGoBack()) { | 1377 if (!current_tab->controller().CanGoBack()) |
| 1354 TabContents* new_tab = GetOrCloneTabForDisposition(disposition); | 1378 return; |
| 1355 // If we are on an interstitial page and clone the tab, it won't be copied | 1379 |
| 1356 // to the new tab, so we don't need to go back. | 1380 TabContentsWrapper* new_tab = GetOrCloneTabWrapperForDisposition(disposition); |
| 1357 if (current_tab->tab_contents()->showing_interstitial_page() && | 1381 if (current_tab->tab_contents()->showing_interstitial_page() && |
| 1358 (new_tab != current_tab->tab_contents())) | 1382 (new_tab != current_tab)) |
| 1359 return; | 1383 return; |
| 1360 new_tab->controller().GoBack(); | 1384 |
| 1361 } | 1385 new_tab->controller().GoBack(); |
| 1386 |
| 1387 CreateNewBrowserForDisposition(new_tab, disposition); |
| 1362 } | 1388 } |
| 1363 | 1389 |
| 1364 void Browser::GoForward(WindowOpenDisposition disposition) { | 1390 void Browser::GoForward(WindowOpenDisposition disposition) { |
| 1365 UserMetrics::RecordAction(UserMetricsAction("Forward")); | 1391 UserMetrics::RecordAction(UserMetricsAction("Forward")); |
| 1366 if (GetSelectedTabContentsWrapper()->controller().CanGoForward()) | 1392 |
| 1367 GetOrCloneTabForDisposition(disposition)->controller().GoForward(); | 1393 TabContentsWrapper* current_tab = GetSelectedTabContentsWrapper(); |
| 1394 if (!current_tab->controller().CanGoForward()) |
| 1395 return; |
| 1396 |
| 1397 TabContentsWrapper* new_tab = GetOrCloneTabWrapperForDisposition(disposition); |
| 1398 new_tab->controller().GoForward(); |
| 1399 |
| 1400 CreateNewBrowserForDisposition(new_tab, disposition); |
| 1368 } | 1401 } |
| 1369 | 1402 |
| 1370 void Browser::Reload(WindowOpenDisposition disposition) { | 1403 void Browser::Reload(WindowOpenDisposition disposition) { |
| 1371 UserMetrics::RecordAction(UserMetricsAction("Reload")); | 1404 UserMetrics::RecordAction(UserMetricsAction("Reload")); |
| 1372 ReloadInternal(disposition, false); | 1405 ReloadInternal(disposition, false); |
| 1373 } | 1406 } |
| 1374 | 1407 |
| 1375 void Browser::ReloadIgnoringCache(WindowOpenDisposition disposition) { | 1408 void Browser::ReloadIgnoringCache(WindowOpenDisposition disposition) { |
| 1376 UserMetrics::RecordAction(UserMetricsAction("ReloadIgnoringCache")); | 1409 UserMetrics::RecordAction(UserMetricsAction("ReloadIgnoringCache")); |
| 1377 ReloadInternal(disposition, true); | 1410 ReloadInternal(disposition, true); |
| (...skipping 3326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4704 TabContents* current_tab = GetSelectedTabContents(); | 4737 TabContents* current_tab = GetSelectedTabContents(); |
| 4705 if (current_tab) { | 4738 if (current_tab) { |
| 4706 content_restrictions = current_tab->content_restrictions(); | 4739 content_restrictions = current_tab->content_restrictions(); |
| 4707 NavigationEntry* active_entry = current_tab->controller().GetActiveEntry(); | 4740 NavigationEntry* active_entry = current_tab->controller().GetActiveEntry(); |
| 4708 // See comment in UpdateCommandsForTabState about why we call url(). | 4741 // See comment in UpdateCommandsForTabState about why we call url(). |
| 4709 if (!SavePackage::IsSavableURL(active_entry ? active_entry->url() : GURL())) | 4742 if (!SavePackage::IsSavableURL(active_entry ? active_entry->url() : GURL())) |
| 4710 content_restrictions |= CONTENT_RESTRICTION_SAVE; | 4743 content_restrictions |= CONTENT_RESTRICTION_SAVE; |
| 4711 } | 4744 } |
| 4712 return content_restrictions; | 4745 return content_restrictions; |
| 4713 } | 4746 } |
| OLD | NEW |