Home | History | Annotate | Download | only in download
      1 // Copyright (c) 2011 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.
      4 
      5 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SHELF_CONTEXT_MENU_H_
      6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SHELF_CONTEXT_MENU_H_
      7 
      8 #include "base/basictypes.h"
      9 #include "base/compiler_specific.h"
     10 #include "base/memory/scoped_ptr.h"
     11 #include "base/strings/string16.h"
     12 #include "content/public/browser/download_item.h"
     13 #include "ui/base/models/simple_menu_model.h"
     14 
     15 namespace content {
     16 class PageNavigator;
     17 }
     18 
     19 // This class is responsible for the download shelf context menu. Platform
     20 // specific subclasses are responsible for creating and running the menu.
     21 //
     22 // The DownloadItem corresponding to the context menu is observed for removal or
     23 // destruction.
     24 class DownloadShelfContextMenu : public ui::SimpleMenuModel::Delegate,
     25                                  public content::DownloadItem::Observer {
     26  public:
     27   enum ContextMenuCommands {
     28     SHOW_IN_FOLDER = 1,    // Open a folder view window with the item selected.
     29     OPEN_WHEN_COMPLETE,    // Open the download when it's finished.
     30     ALWAYS_OPEN_TYPE,      // Default this file extension to always open.
     31     CANCEL,                // Cancel the download.
     32     TOGGLE_PAUSE,          // Pause or resume a download.
     33     DISCARD,               // Discard the malicious download.
     34     KEEP,                  // Keep the malicious download.
     35     LEARN_MORE_SCANNING,   // Show information about download scanning.
     36     LEARN_MORE_INTERRUPTED,// Show information about interrupted downloads.
     37   };
     38 
     39   virtual ~DownloadShelfContextMenu();
     40 
     41   content::DownloadItem* download_item() const { return download_item_; }
     42 
     43  protected:
     44   DownloadShelfContextMenu(content::DownloadItem* download_item,
     45                            content::PageNavigator* navigator);
     46 
     47   // Returns the correct menu model depending on the state of the download item.
     48   // Returns NULL if the download was destroyed.
     49   ui::SimpleMenuModel* GetMenuModel();
     50 
     51   // ui::SimpleMenuModel::Delegate:
     52   virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
     53   virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
     54   virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE;
     55   virtual bool GetAcceleratorForCommandId(
     56       int command_id,
     57       ui::Accelerator* accelerator) OVERRIDE;
     58   virtual bool IsItemForCommandIdDynamic(int command_id) const OVERRIDE;
     59   virtual string16 GetLabelForCommandId(int command_id) const OVERRIDE;
     60 
     61  private:
     62   // Detaches self from |download_item_|. Called when the DownloadItem is
     63   // destroyed or when this object is being destroyed.
     64   void DetachFromDownloadItem();
     65 
     66   // content::DownloadItem::Observer
     67   virtual void OnDownloadDestroyed(content::DownloadItem* download) OVERRIDE;
     68 
     69   ui::SimpleMenuModel* GetInProgressMenuModel();
     70   ui::SimpleMenuModel* GetFinishedMenuModel();
     71   ui::SimpleMenuModel* GetInterruptedMenuModel();
     72   ui::SimpleMenuModel* GetMaliciousMenuModel();
     73 
     74   // We show slightly different menus if the download is in progress vs. if the
     75   // download has finished.
     76   scoped_ptr<ui::SimpleMenuModel> in_progress_download_menu_model_;
     77   scoped_ptr<ui::SimpleMenuModel> finished_download_menu_model_;
     78   scoped_ptr<ui::SimpleMenuModel> interrupted_download_menu_model_;
     79   scoped_ptr<ui::SimpleMenuModel> malicious_download_menu_model_;
     80 
     81   // Information source.
     82   content::DownloadItem* download_item_;
     83 
     84   // Used to open tabs.
     85   content::PageNavigator* navigator_;
     86 
     87   DISALLOW_COPY_AND_ASSIGN(DownloadShelfContextMenu);
     88 };
     89 
     90 #endif  // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SHELF_CONTEXT_MENU_H_
     91