| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/app/chrome_dll_resource.h" // IDC_HISTORY_MENU | 5 #include "chrome/app/chrome_dll_resource.h" // IDC_HISTORY_MENU |
| 6 #include "chrome/browser/browser.h" | 6 #include "chrome/browser/browser.h" |
| 7 #import "chrome/browser/cocoa/history_menu_cocoa_controller.h" | 7 #import "chrome/browser/cocoa/history_menu_cocoa_controller.h" |
| 8 #include "chrome/browser/browser_list.h" | 8 #include "chrome/browser/browser_list.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/cocoa/event_utils.h" |
| 10 #include "chrome/browser/history/history.h" | 11 #include "chrome/browser/history/history.h" |
| 11 #include "chrome/browser/history/history_types.h" | 12 #include "chrome/browser/history/history_types.h" |
| 12 #include "chrome/browser/tab_contents/tab_contents.h" | 13 #include "chrome/browser/tab_contents/tab_contents.h" |
| 13 #import "chrome/common/cocoa_utils.h" | |
| 14 #include "webkit/glue/window_open_disposition.h" | 14 #include "webkit/glue/window_open_disposition.h" |
| 15 | 15 |
| 16 @implementation HistoryMenuCocoaController | 16 @implementation HistoryMenuCocoaController |
| 17 | 17 |
| 18 - (id)initWithBridge:(HistoryMenuBridge*)bridge { | 18 - (id)initWithBridge:(HistoryMenuBridge*)bridge { |
| 19 if ((self = [super init])) { | 19 if ((self = [super init])) { |
| 20 bridge_ = bridge; | 20 bridge_ = bridge; |
| 21 DCHECK(bridge_); | 21 DCHECK(bridge_); |
| 22 } | 22 } |
| 23 return self; | 23 return self; |
| 24 } | 24 } |
| 25 | 25 |
| 26 // Open the URL of the given history item in the current tab. | 26 // Open the URL of the given history item in the current tab. |
| 27 - (void)openURLForItem:(HistoryMenuBridge::HistoryItem&)node { | 27 - (void)openURLForItem:(HistoryMenuBridge::HistoryItem&)node { |
| 28 Browser* browser = BrowserList::GetLastActive(); | 28 Browser* browser = Browser::GetOrCreateTabbedBrowser(bridge_->profile()); |
| 29 | 29 WindowOpenDisposition disposition = |
| 30 if (!browser) { // No windows open? | 30 event_utils::WindowOpenDispositionFromNSEvent([NSApp currentEvent]); |
| 31 Browser::OpenEmptyWindow(bridge_->profile()); | 31 browser->OpenURL(node.url, GURL(), disposition, |
| 32 browser = BrowserList::GetLastActive(); | 32 PageTransition::AUTO_BOOKMARK); |
| 33 } | |
| 34 DCHECK(browser); | |
| 35 TabContents* tab_contents = browser->GetSelectedTabContents(); | |
| 36 DCHECK(tab_contents); | |
| 37 | |
| 38 // A TabContents is a PageNavigator, so we can OpenURL() on it. | |
| 39 WindowOpenDisposition disposition = event_utils::DispositionFromEventFlags( | |
| 40 [[NSApp currentEvent] modifierFlags]); | |
| 41 tab_contents->OpenURL(node.url, GURL(), disposition, | |
| 42 PageTransition::AUTO_BOOKMARK); | |
| 43 } | 33 } |
| 44 | 34 |
| 45 - (HistoryMenuBridge::HistoryItem)itemForTag:(NSInteger)tag { | 35 - (HistoryMenuBridge::HistoryItem)itemForTag:(NSInteger)tag { |
| 46 std::vector<HistoryMenuBridge::HistoryItem>* results = NULL; | 36 std::vector<HistoryMenuBridge::HistoryItem>* results = NULL; |
| 47 NSInteger tag_base = 0; | 37 NSInteger tag_base = 0; |
| 48 if (tag > IDC_HISTORY_MENU_VISITED && tag < IDC_HISTORY_MENU_CLOSED) { | 38 if (tag > IDC_HISTORY_MENU_VISITED && tag < IDC_HISTORY_MENU_CLOSED) { |
| 49 results = bridge_->visited_results(); | 39 results = bridge_->visited_results(); |
| 50 tag_base = IDC_HISTORY_MENU_VISITED; | 40 tag_base = IDC_HISTORY_MENU_VISITED; |
| 51 } else if (tag > IDC_HISTORY_MENU_CLOSED) { | 41 } else if (tag > IDC_HISTORY_MENU_CLOSED) { |
| 52 results = bridge_->closed_results(); | 42 results = bridge_->closed_results(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 63 } | 53 } |
| 64 | 54 |
| 65 - (IBAction)openHistoryMenuItem:(id)sender { | 55 - (IBAction)openHistoryMenuItem:(id)sender { |
| 66 NSInteger tag = [sender tag]; | 56 NSInteger tag = [sender tag]; |
| 67 HistoryMenuBridge::HistoryItem item = [self itemForTag:tag]; | 57 HistoryMenuBridge::HistoryItem item = [self itemForTag:tag]; |
| 68 DCHECK(item.url.is_valid()); | 58 DCHECK(item.url.is_valid()); |
| 69 [self openURLForItem:item]; | 59 [self openURLForItem:item]; |
| 70 } | 60 } |
| 71 | 61 |
| 72 @end // HistoryMenuCocoaController | 62 @end // HistoryMenuCocoaController |
| OLD | NEW |