BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / history_menu_cocoa_controller.mm
blobed86edd610dab1453fff8f85e4ff3e7705d63df1
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
3 // found in the LICENSE file.
5 #import "chrome/browser/ui/cocoa/history_menu_cocoa_controller.h"
7 #include "chrome/app/chrome_command_ids.h"  // IDC_HISTORY_MENU
8 #import "chrome/browser/app_controller_mac.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/sessions/tab_restore_service_factory.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_finder.h"
13 #include "chrome/browser/ui/browser_navigator.h"
14 #include "chrome/browser/ui/browser_tab_restore_service_delegate.h"
15 #include "chrome/browser/ui/host_desktop.h"
16 #include "components/history/core/browser/history_service.h"
17 #include "components/history/core/browser/history_types.h"
18 #include "components/sessions/core/tab_restore_service.h"
19 #import "ui/base/cocoa/cocoa_base_utils.h"
20 #include "ui/base/window_open_disposition.h"
22 using content::OpenURLParams;
23 using content::Referrer;
25 @implementation HistoryMenuCocoaController
27 - (id)initWithBridge:(HistoryMenuBridge*)bridge {
28   if ((self = [super init])) {
29     bridge_ = bridge;
30     DCHECK(bridge_);
31   }
32   return self;
35 - (BOOL)validateMenuItem:(NSMenuItem*)menuItem {
36   AppController* controller = [NSApp delegate];
37   return ![controller keyWindowIsModal];
40 // Open the URL of the given history item in the current tab.
41 - (void)openURLForItem:(const HistoryMenuBridge::HistoryItem*)node {
42   // If this item can be restored using TabRestoreService, do so. Otherwise,
43   // just load the URL.
44   sessions::TabRestoreService* service =
45       TabRestoreServiceFactory::GetForProfile(bridge_->profile());
46   if (node->session_id && service) {
47     Browser* browser = chrome::FindTabbedBrowser(bridge_->profile(), false,
48         chrome::HOST_DESKTOP_TYPE_NATIVE);
49     BrowserTabRestoreServiceDelegate* delegate = browser ?
50         browser->tab_restore_service_delegate() : NULL;
51     service->RestoreEntryById(delegate, node->session_id,
52         chrome::HOST_DESKTOP_TYPE_NATIVE, UNKNOWN);
53   } else {
54     DCHECK(node->url.is_valid());
55     WindowOpenDisposition disposition =
56         ui::WindowOpenDispositionFromNSEvent([NSApp currentEvent]);
57     chrome::NavigateParams params(bridge_->profile(), node->url,
58         ui::PAGE_TRANSITION_AUTO_BOOKMARK);
59     params.disposition = disposition;
60     chrome::Navigate(&params);
61   }
64 - (IBAction)openHistoryMenuItem:(id)sender {
65   const HistoryMenuBridge::HistoryItem* item =
66       bridge_->HistoryItemForMenuItem(sender);
67   [self openURLForItem:item];
70 @end  // HistoryMenuCocoaController