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