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