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