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