| 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 #import "chrome/browser/ui/cocoa/history_menu_cocoa_controller.h" | 5 #import "chrome/browser/ui/cocoa/history_menu_cocoa_controller.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_vector.h" | 7 #include "base/memory/scoped_vector.h" |
| 8 #include "chrome/app/chrome_command_ids.h" // IDC_HISTORY_MENU | 8 #include "chrome/app/chrome_command_ids.h" // IDC_HISTORY_MENU |
| 9 #import "chrome/browser/app_controller_mac.h" | 9 #import "chrome/browser/app_controller_mac.h" |
| 10 #include "chrome/browser/history/history.h" | 10 #include "chrome/browser/history/history.h" |
| 11 #include "chrome/browser/history/history_types.h" | 11 #include "chrome/browser/history/history_types.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/sessions/tab_restore_service.h" |
| 14 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
| 13 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/browser/ui/browser_tab_restore_service_delegate.h" | 16 #include "chrome/browser/ui/browser_tab_restore_service_delegate.h" |
| 15 #include "chrome/browser/ui/cocoa/event_utils.h" | 17 #include "chrome/browser/ui/cocoa/event_utils.h" |
| 16 #include "webkit/glue/window_open_disposition.h" | 18 #include "webkit/glue/window_open_disposition.h" |
| 17 | 19 |
| 18 @implementation HistoryMenuCocoaController | 20 @implementation HistoryMenuCocoaController |
| 19 | 21 |
| 20 - (id)initWithBridge:(HistoryMenuBridge*)bridge { | 22 - (id)initWithBridge:(HistoryMenuBridge*)bridge { |
| 21 if ((self = [super init])) { | 23 if ((self = [super init])) { |
| 22 bridge_ = bridge; | 24 bridge_ = bridge; |
| 23 DCHECK(bridge_); | 25 DCHECK(bridge_); |
| 24 } | 26 } |
| 25 return self; | 27 return self; |
| 26 } | 28 } |
| 27 | 29 |
| 28 - (BOOL)validateMenuItem:(NSMenuItem*)menuItem { | 30 - (BOOL)validateMenuItem:(NSMenuItem*)menuItem { |
| 29 AppController* controller = [NSApp delegate]; | 31 AppController* controller = [NSApp delegate]; |
| 30 return [controller keyWindowIsNotModal]; | 32 return [controller keyWindowIsNotModal]; |
| 31 } | 33 } |
| 32 | 34 |
| 33 // Open the URL of the given history item in the current tab. | 35 // Open the URL of the given history item in the current tab. |
| 34 - (void)openURLForItem:(const HistoryMenuBridge::HistoryItem*)node { | 36 - (void)openURLForItem:(const HistoryMenuBridge::HistoryItem*)node { |
| 35 Browser* browser = Browser::GetOrCreateTabbedBrowser(bridge_->profile()); | 37 Browser* browser = Browser::GetOrCreateTabbedBrowser(bridge_->profile()); |
| 36 WindowOpenDisposition disposition = | 38 WindowOpenDisposition disposition = |
| 37 event_utils::WindowOpenDispositionFromNSEvent([NSApp currentEvent]); | 39 event_utils::WindowOpenDispositionFromNSEvent([NSApp currentEvent]); |
| 38 | 40 |
| 39 // If this item can be restored using TabRestoreService, do so. Otherwise, | 41 // If this item can be restored using TabRestoreService, do so. Otherwise, |
| 40 // just load the URL. | 42 // just load the URL. |
| 41 TabRestoreService* service = bridge_->profile()->GetTabRestoreService(); | 43 TabRestoreService* service = |
| 44 TabRestoreServiceFactory::GetForProfile(bridge_->profile()); |
| 42 if (node->session_id && service) { | 45 if (node->session_id && service) { |
| 43 service->RestoreEntryById(browser->tab_restore_service_delegate(), | 46 service->RestoreEntryById(browser->tab_restore_service_delegate(), |
| 44 node->session_id, false); | 47 node->session_id, false); |
| 45 } else { | 48 } else { |
| 46 DCHECK(node->url.is_valid()); | 49 DCHECK(node->url.is_valid()); |
| 47 browser->OpenURL(node->url, GURL(), disposition, | 50 browser->OpenURL(node->url, GURL(), disposition, |
| 48 PageTransition::AUTO_BOOKMARK); | 51 PageTransition::AUTO_BOOKMARK); |
| 49 } | 52 } |
| 50 } | 53 } |
| 51 | 54 |
| 52 - (IBAction)openHistoryMenuItem:(id)sender { | 55 - (IBAction)openHistoryMenuItem:(id)sender { |
| 53 const HistoryMenuBridge::HistoryItem* item = | 56 const HistoryMenuBridge::HistoryItem* item = |
| 54 bridge_->HistoryItemForMenuItem(sender); | 57 bridge_->HistoryItemForMenuItem(sender); |
| 55 [self openURLForItem:item]; | 58 [self openURLForItem:item]; |
| 56 } | 59 } |
| 57 | 60 |
| 58 @end // HistoryMenuCocoaController | 61 @end // HistoryMenuCocoaController |
| OLD | NEW |