summaryrefslogtreecommitdiffstats
path: root/chrome/browser/download/download_shelf_context_menu.h
blob: fc7bc72e561e900a6a148aba89e09982c665a4ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SHELF_CONTEXT_MENU_H_
#define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SHELF_CONTEXT_MENU_H_

#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "base/string16.h"
#include "ui/base/models/simple_menu_model.h"

class BaseDownloadItemModel;

namespace content {
class DownloadItem;
class PageNavigator;
}

// This class is responsible for the download shelf context menu. Platform
// specific subclasses are responsible for creating and running the menu.
class DownloadShelfContextMenu : public ui::SimpleMenuModel::Delegate {
 public:
  enum ContextMenuCommands {
    SHOW_IN_FOLDER = 1,  // Open a file explorer window with the item selected.
    OPEN_WHEN_COMPLETE,  // Open the download when it's finished.
    ALWAYS_OPEN_TYPE,    // Default this file extension to always open.
    CANCEL,              // Cancel the download.
    TOGGLE_PAUSE,        // Temporarily pause a download.
    DISCARD,             // Discard the malicious download.
    KEEP,                // Keep the malicious download.
    LEARN_MORE,          // Show information about download scanning.
    MENU_LAST
  };

  virtual ~DownloadShelfContextMenu();

  content::DownloadItem* download_item() const { return download_item_; }
  void set_download_item(content::DownloadItem* item) { download_item_ = item; }

 protected:
  DownloadShelfContextMenu(BaseDownloadItemModel* download_model,
                           content::PageNavigator* navigator);

  // Returns the correct menu model depending whether the download item is
  // completed or not.
  ui::SimpleMenuModel* GetMenuModel();

  // ui::SimpleMenuModel::Delegate:
  virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
  virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
  virtual void ExecuteCommand(int command_id) OVERRIDE;
  virtual bool GetAcceleratorForCommandId(
      int command_id,
      ui::Accelerator* accelerator) OVERRIDE;
  virtual bool IsItemForCommandIdDynamic(int command_id) const OVERRIDE;
  virtual string16 GetLabelForCommandId(int command_id) const OVERRIDE;

 private:
  ui::SimpleMenuModel* GetInProgressMenuModel();
  ui::SimpleMenuModel* GetFinishedMenuModel();
  ui::SimpleMenuModel* GetMaliciousMenuModel();

  // We show slightly different menus if the download is in progress vs. if the
  // download has finished.
  scoped_ptr<ui::SimpleMenuModel> in_progress_download_menu_model_;
  scoped_ptr<ui::SimpleMenuModel> finished_download_menu_model_;
  scoped_ptr<ui::SimpleMenuModel> malicious_download_menu_model_;

  // A model to control the cancel behavior.
  BaseDownloadItemModel* download_model_;

  // Information source.
  content::DownloadItem* download_item_;

  // Used to open tabs.
  content::PageNavigator* navigator_;

  DISALLOW_COPY_AND_ASSIGN(DownloadShelfContextMenu);
};

#endif  // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SHELF_CONTEXT_MENU_H_