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

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

Issue 6893046: added CTRL+Click and SHIFT+Click handler for context menu, Back and Forward. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: make this patch applicable to the latest trunk Created 9 years, 6 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_navigator.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) 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 22 matching lines...) Expand all
33 #include "chrome/browser/character_encoding.h" 33 #include "chrome/browser/character_encoding.h"
34 #include "chrome/browser/debugger/devtools_manager.h" 34 #include "chrome/browser/debugger/devtools_manager.h"
35 #include "chrome/browser/debugger/devtools_toggle_action.h" 35 #include "chrome/browser/debugger/devtools_toggle_action.h"
36 #include "chrome/browser/debugger/devtools_window.h" 36 #include "chrome/browser/debugger/devtools_window.h"
37 #include "chrome/browser/download/download_item.h" 37 #include "chrome/browser/download/download_item.h"
38 #include "chrome/browser/download/download_item_model.h" 38 #include "chrome/browser/download/download_item_model.h"
39 #include "chrome/browser/download/download_manager.h" 39 #include "chrome/browser/download/download_manager.h"
40 #include "chrome/browser/download/download_shelf.h" 40 #include "chrome/browser/download/download_shelf.h"
41 #include "chrome/browser/download/download_started_animation.h" 41 #include "chrome/browser/download/download_started_animation.h"
42 #include "chrome/browser/download/save_package.h" 42 #include "chrome/browser/download/save_package.h"
43 #include "chrome/browser/event_disposition.h"
43 #include "chrome/browser/extensions/crx_installer.h" 44 #include "chrome/browser/extensions/crx_installer.h"
44 #include "chrome/browser/extensions/extension_browser_event_router.h" 45 #include "chrome/browser/extensions/extension_browser_event_router.h"
45 #include "chrome/browser/extensions/extension_disabled_infobar_delegate.h" 46 #include "chrome/browser/extensions/extension_disabled_infobar_delegate.h"
46 #include "chrome/browser/extensions/extension_host.h" 47 #include "chrome/browser/extensions/extension_host.h"
47 #include "chrome/browser/extensions/extension_prefs.h" 48 #include "chrome/browser/extensions/extension_prefs.h"
48 #include "chrome/browser/extensions/extension_service.h" 49 #include "chrome/browser/extensions/extension_service.h"
49 #include "chrome/browser/extensions/extension_tab_helper.h" 50 #include "chrome/browser/extensions/extension_tab_helper.h"
50 #include "chrome/browser/extensions/extension_tabs_module.h" 51 #include "chrome/browser/extensions/extension_tabs_module.h"
51 #include "chrome/browser/favicon/favicon_tab_helper.h" 52 #include "chrome/browser/favicon/favicon_tab_helper.h"
52 #include "chrome/browser/first_run/first_run.h" 53 #include "chrome/browser/first_run/first_run.h"
(...skipping 1132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1185 tab_handler_->GetTabStripModel()->active_index(), 1186 tab_handler_->GetTabStripModel()->active_index(),
1186 wrapper); 1187 wrapper);
1187 } 1188 }
1188 1189
1189 bool Browser::CanRestoreTab() { 1190 bool Browser::CanRestoreTab() {
1190 return command_updater_.IsCommandEnabled(IDC_RESTORE_TAB); 1191 return command_updater_.IsCommandEnabled(IDC_RESTORE_TAB);
1191 } 1192 }
1192 1193
1193 bool Browser::NavigateToIndexWithDisposition(int index, 1194 bool Browser::NavigateToIndexWithDisposition(int index,
1194 WindowOpenDisposition disp) { 1195 WindowOpenDisposition disp) {
1195 NavigationController& controller = 1196 TabContentsWrapper* tab = GetOrCloneTabWrapperForDisposition(disp);
1196 GetOrCloneTabForDisposition(disp)->controller(); 1197
1198 NavigationController& controller = tab->controller();
1197 if (index < 0 || index >= controller.entry_count()) 1199 if (index < 0 || index >= controller.entry_count())
1198 return false; 1200 return false;
1199 controller.GoToIndex(index); 1201 controller.GoToIndex(index);
1202
1203 CreateNewBrowserForDisposition(tab, disp);
1204
1200 return true; 1205 return true;
1201 } 1206 }
1202 1207
1203 browser::NavigateParams Browser::GetSingletonTabNavigateParams( 1208 browser::NavigateParams Browser::GetSingletonTabNavigateParams(
1204 const GURL& url) { 1209 const GURL& url) {
1205 browser::NavigateParams params(this, url, PageTransition::AUTO_BOOKMARK); 1210 browser::NavigateParams params(this, url, PageTransition::AUTO_BOOKMARK);
1206 params.disposition = SINGLETON_TAB; 1211 params.disposition = SINGLETON_TAB;
1207 params.window_action = browser::NavigateParams::SHOW_WINDOW; 1212 params.window_action = browser::NavigateParams::SHOW_WINDOW;
1208 params.user_gesture = true; 1213 params.user_gesture = true;
1209 return params; 1214 return params;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1262 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_VERTICAL_TABS, show_main_ui); 1267 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_VERTICAL_TABS, show_main_ui);
1263 command_updater_.UpdateCommandEnabled(IDC_COMPACT_NAVBAR, show_main_ui); 1268 command_updater_.UpdateCommandEnabled(IDC_COMPACT_NAVBAR, show_main_ui);
1264 #if defined (ENABLE_PROFILING) && !defined(NO_TCMALLOC) 1269 #if defined (ENABLE_PROFILING) && !defined(NO_TCMALLOC)
1265 command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui); 1270 command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui);
1266 #endif 1271 #endif
1267 } 1272 }
1268 1273
1269 /////////////////////////////////////////////////////////////////////////////// 1274 ///////////////////////////////////////////////////////////////////////////////
1270 // Browser, Assorted browser commands: 1275 // Browser, Assorted browser commands:
1271 1276
1272 bool Browser::ShouldOpenNewTabForWindowDisposition( 1277 bool Browser::ShouldOpenNewTabForDisposition(
1273 WindowOpenDisposition disposition) { 1278 WindowOpenDisposition disposition) {
1274 return (disposition == NEW_FOREGROUND_TAB || 1279 return (disposition == NEW_FOREGROUND_TAB ||
1275 disposition == NEW_BACKGROUND_TAB); 1280 disposition == NEW_BACKGROUND_TAB);
1276 } 1281 }
1277 1282
1278 TabContents* Browser::GetOrCloneTabForDisposition( 1283 TabContents* Browser::GetOrCloneTabForDisposition(
1279 WindowOpenDisposition disposition) { 1284 WindowOpenDisposition disposition) {
1285 return GetOrCloneTabWrapperForDisposition(disposition)->tab_contents();
1286 }
1287
1288 TabContentsWrapper* Browser::GetOrCloneTabWrapperForDisposition(
1289 WindowOpenDisposition disposition) {
1280 TabContentsWrapper* current_tab = GetSelectedTabContentsWrapper(); 1290 TabContentsWrapper* current_tab = GetSelectedTabContentsWrapper();
1281 if (ShouldOpenNewTabForWindowDisposition(disposition)) { 1291
1282 current_tab = current_tab->Clone(); 1292 if (disposition == NEW_WINDOW)
1293 return current_tab->Clone();
1294
1295 if (ShouldOpenNewTabForDisposition(disposition)) {
1296 TabContentsWrapper* new_tab = current_tab->Clone();
1283 tab_handler_->GetTabStripModel()->AddTabContents( 1297 tab_handler_->GetTabStripModel()->AddTabContents(
1284 current_tab, -1, PageTransition::LINK, 1298 new_tab, -1, PageTransition::LINK,
1285 disposition == NEW_FOREGROUND_TAB ? TabStripModel::ADD_ACTIVE : 1299 disposition == NEW_FOREGROUND_TAB ? TabStripModel::ADD_ACTIVE :
1286 TabStripModel::ADD_NONE); 1300 TabStripModel::ADD_NONE);
1301 return new_tab;
1287 } 1302 }
1288 return current_tab->tab_contents(); 1303
1304 return current_tab;
1305 }
1306
1307 void Browser::CreateNewBrowserForDisposition(
1308 TabContentsWrapper* tab_contents, WindowOpenDisposition disposition) {
1309 if (disposition == NEW_WINDOW) {
1310 Browser* browser = Create(profile_);
1311 browser->AddTab(tab_contents, PageTransition::LINK);
1312 browser->window()->Show();
1313 }
1289 } 1314 }
1290 1315
1291 void Browser::UpdateTabStripModelInsertionPolicy() { 1316 void Browser::UpdateTabStripModelInsertionPolicy() {
1292 tab_handler_->GetTabStripModel()->SetInsertionPolicy(UseVerticalTabs() ? 1317 tab_handler_->GetTabStripModel()->SetInsertionPolicy(UseVerticalTabs() ?
1293 TabStripModel::INSERT_BEFORE : TabStripModel::INSERT_AFTER); 1318 TabStripModel::INSERT_BEFORE : TabStripModel::INSERT_AFTER);
1294 } 1319 }
1295 1320
1296 void Browser::UseVerticalTabsChanged() { 1321 void Browser::UseVerticalTabsChanged() {
1297 UpdateTabStripModelInsertionPolicy(); 1322 UpdateTabStripModelInsertionPolicy();
1298 window()->ToggleTabStripMode(); 1323 window()->ToggleTabStripMode();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1345 bool can_close = !watcher || watcher->CanCloseBrowser(this); 1370 bool can_close = !watcher || watcher->CanCloseBrowser(this);
1346 if (!can_close && is_attempting_to_close_browser_) 1371 if (!can_close && is_attempting_to_close_browser_)
1347 CancelWindowClose(); 1372 CancelWindowClose();
1348 return can_close; 1373 return can_close;
1349 } 1374 }
1350 1375
1351 void Browser::GoBack(WindowOpenDisposition disposition) { 1376 void Browser::GoBack(WindowOpenDisposition disposition) {
1352 UserMetrics::RecordAction(UserMetricsAction("Back")); 1377 UserMetrics::RecordAction(UserMetricsAction("Back"));
1353 1378
1354 TabContentsWrapper* current_tab = GetSelectedTabContentsWrapper(); 1379 TabContentsWrapper* current_tab = GetSelectedTabContentsWrapper();
1355 if (current_tab->controller().CanGoBack()) { 1380 if (!current_tab->controller().CanGoBack())
1356 TabContents* new_tab = GetOrCloneTabForDisposition(disposition); 1381 return;
1357 // If we are on an interstitial page and clone the tab, it won't be copied 1382
1358 // to the new tab, so we don't need to go back. 1383 TabContentsWrapper* new_tab = GetOrCloneTabWrapperForDisposition(disposition);
1359 if (current_tab->tab_contents()->showing_interstitial_page() && 1384 if (current_tab->tab_contents()->showing_interstitial_page() &&
1360 (new_tab != current_tab->tab_contents())) 1385 (new_tab != current_tab))
1361 return; 1386 return;
1362 new_tab->controller().GoBack(); 1387
1363 } 1388 new_tab->controller().GoBack();
1389
1390 CreateNewBrowserForDisposition(new_tab, disposition);
1364 } 1391 }
1365 1392
1366 void Browser::GoForward(WindowOpenDisposition disposition) { 1393 void Browser::GoForward(WindowOpenDisposition disposition) {
1367 UserMetrics::RecordAction(UserMetricsAction("Forward")); 1394 UserMetrics::RecordAction(UserMetricsAction("Forward"));
1368 if (GetSelectedTabContentsWrapper()->controller().CanGoForward()) 1395
1369 GetOrCloneTabForDisposition(disposition)->controller().GoForward(); 1396 TabContentsWrapper* current_tab = GetSelectedTabContentsWrapper();
1397 if (!current_tab->controller().CanGoForward())
1398 return;
1399
1400 TabContentsWrapper* new_tab = GetOrCloneTabWrapperForDisposition(disposition);
1401 new_tab->controller().GoForward();
1402
1403 CreateNewBrowserForDisposition(new_tab, disposition);
1370 } 1404 }
1371 1405
1372 void Browser::Reload(WindowOpenDisposition disposition) { 1406 void Browser::Reload(WindowOpenDisposition disposition) {
1373 UserMetrics::RecordAction(UserMetricsAction("Reload")); 1407 UserMetrics::RecordAction(UserMetricsAction("Reload"));
1374 ReloadInternal(disposition, false); 1408 ReloadInternal(disposition, false);
1375 } 1409 }
1376 1410
1377 void Browser::ReloadIgnoringCache(WindowOpenDisposition disposition) { 1411 void Browser::ReloadIgnoringCache(WindowOpenDisposition disposition) {
1378 UserMetrics::RecordAction(UserMetricsAction("ReloadIgnoringCache")); 1412 UserMetrics::RecordAction(UserMetricsAction("ReloadIgnoringCache"));
1379 ReloadInternal(disposition, true); 1413 ReloadInternal(disposition, true);
(...skipping 1109 matching lines...) Expand 10 before | Expand all | Expand 10 after
2489 2523
2490 bool Browser::ExecuteCommandIfEnabled(int id) { 2524 bool Browser::ExecuteCommandIfEnabled(int id) {
2491 if (command_updater_.SupportsCommand(id) && 2525 if (command_updater_.SupportsCommand(id) &&
2492 command_updater_.IsCommandEnabled(id)) { 2526 command_updater_.IsCommandEnabled(id)) {
2493 ExecuteCommand(id); 2527 ExecuteCommand(id);
2494 return true; 2528 return true;
2495 } 2529 }
2496 return false; 2530 return false;
2497 } 2531 }
2498 2532
2533 bool Browser::ExecuteContextMenuCommand(int id, int event_flags) {
2534 switch (id) {
2535 case IDC_BACK:
2536 GoBack(browser::DispositionFromEventFlags(event_flags));
2537 return true;
2538 case IDC_FORWARD:
2539 GoForward(browser::DispositionFromEventFlags(event_flags));
2540 return true;
2541 case IDC_RELOAD:
2542 Reload(browser::DispositionFromEventFlags(event_flags));
2543 return true;
2544 }
2545
2546 return false;
2547 }
2548
2499 bool Browser::IsReservedCommandOrKey(int command_id, 2549 bool Browser::IsReservedCommandOrKey(int command_id,
2500 const NativeWebKeyboardEvent& event) { 2550 const NativeWebKeyboardEvent& event) {
2501 #if defined(OS_CHROMEOS) 2551 #if defined(OS_CHROMEOS)
2502 // Chrome OS's top row of keys produces F1-10. Make sure that web pages 2552 // Chrome OS's top row of keys produces F1-10. Make sure that web pages
2503 // aren't able to block Chrome from performing the standard actions for F1-F4 2553 // aren't able to block Chrome from performing the standard actions for F1-F4
2504 // (F5-7 are grabbed by other X clients and hence don't need this protection, 2554 // (F5-7 are grabbed by other X clients and hence don't need this protection,
2505 // and F8-10 are handled separately in Chrome via a GDK event filter, but 2555 // and F8-10 are handled separately in Chrome via a GDK event filter, but
2506 // let's future-proof this). 2556 // let's future-proof this).
2507 ui::KeyboardCode key_code = 2557 ui::KeyboardCode key_code =
2508 static_cast<ui::KeyboardCode>(event.windowsKeyCode); 2558 static_cast<ui::KeyboardCode>(event.windowsKeyCode);
(...skipping 2187 matching lines...) Expand 10 before | Expand all | Expand 10 after
4696 TabContents* current_tab = GetSelectedTabContents(); 4746 TabContents* current_tab = GetSelectedTabContents();
4697 if (current_tab) { 4747 if (current_tab) {
4698 content_restrictions = current_tab->content_restrictions(); 4748 content_restrictions = current_tab->content_restrictions();
4699 NavigationEntry* active_entry = current_tab->controller().GetActiveEntry(); 4749 NavigationEntry* active_entry = current_tab->controller().GetActiveEntry();
4700 // See comment in UpdateCommandsForTabState about why we call url(). 4750 // See comment in UpdateCommandsForTabState about why we call url().
4701 if (!SavePackage::IsSavableURL(active_entry ? active_entry->url() : GURL())) 4751 if (!SavePackage::IsSavableURL(active_entry ? active_entry->url() : GURL()))
4702 content_restrictions |= CONTENT_RESTRICTION_SAVE; 4752 content_restrictions |= CONTENT_RESTRICTION_SAVE;
4703 } 4753 }
4704 return content_restrictions; 4754 return content_restrictions;
4705 } 4755 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser.h ('k') | chrome/browser/ui/browser_navigator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698