| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SHELF_CONTEXT_MENU_H_ | 5 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SHELF_CONTEXT_MENU_H_ |
| 6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SHELF_CONTEXT_MENU_H_ | 6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SHELF_CONTEXT_MENU_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
| 12 #include "chrome/browser/download/download_command.h" |
| 12 #include "content/public/browser/download_item.h" | 13 #include "content/public/browser/download_item.h" |
| 13 #include "ui/base/models/simple_menu_model.h" | 14 #include "ui/base/models/simple_menu_model.h" |
| 14 | 15 |
| 15 namespace content { | 16 namespace content { |
| 16 class PageNavigator; | 17 class PageNavigator; |
| 17 } | 18 } |
| 18 | 19 |
| 19 // This class is responsible for the download shelf context menu. Platform | 20 // This class is responsible for the download shelf context menu. Platform |
| 20 // specific subclasses are responsible for creating and running the menu. | 21 // specific subclasses are responsible for creating and running the menu. |
| 21 // | 22 // |
| 22 // The DownloadItem corresponding to the context menu is observed for removal or | 23 // The DownloadItem corresponding to the context menu is observed for removal or |
| 23 // destruction. | 24 // destruction. |
| 24 class DownloadShelfContextMenu : public ui::SimpleMenuModel::Delegate, | 25 class DownloadShelfContextMenu : public ui::SimpleMenuModel::Delegate, |
| 25 public content::DownloadItem::Observer { | 26 public content::DownloadItem::Observer { |
| 26 public: | 27 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 PLATFORM_OPEN, // Open using platform handler. | |
| 32 CANCEL, // Cancel the download. | |
| 33 TOGGLE_PAUSE, // Pause or resume a download. | |
| 34 DISCARD, // Discard the malicious download. | |
| 35 KEEP, // Keep the malicious download. | |
| 36 LEARN_MORE_SCANNING, // Show information about download scanning. | |
| 37 LEARN_MORE_INTERRUPTED,// Show information about interrupted downloads. | |
| 38 }; | |
| 39 | |
| 40 ~DownloadShelfContextMenu() override; | 28 ~DownloadShelfContextMenu() override; |
| 41 | 29 |
| 42 content::DownloadItem* download_item() const { return download_item_; } | 30 content::DownloadItem* download_item() const { return download_item_; } |
| 43 | 31 |
| 44 protected: | 32 protected: |
| 45 DownloadShelfContextMenu(content::DownloadItem* download_item, | 33 DownloadShelfContextMenu(content::DownloadItem* download_item, |
| 46 content::PageNavigator* navigator); | 34 content::PageNavigator* navigator); |
| 47 | 35 |
| 48 // Returns the correct menu model depending on the state of the download item. | 36 // Returns the correct menu model depending on the state of the download item. |
| 49 // Returns NULL if the download was destroyed. | 37 // Returns NULL if the download was destroyed. |
| 50 ui::SimpleMenuModel* GetMenuModel(); | 38 ui::SimpleMenuModel* GetMenuModel(); |
| 51 | 39 |
| 52 // ui::SimpleMenuModel::Delegate: | 40 // ui::SimpleMenuModel::Delegate: |
| 53 bool IsCommandIdEnabled(int command_id) const override; | 41 bool IsCommandIdEnabled(int command_id) const override; |
| 54 bool IsCommandIdChecked(int command_id) const override; | 42 bool IsCommandIdChecked(int command_id) const override; |
| 55 bool IsCommandIdVisible(int command_id) const override; | 43 bool IsCommandIdVisible(int command_id) const override; |
| 56 void ExecuteCommand(int command_id, int event_flags) override; | 44 void ExecuteCommand(int command_id, int event_flags) override; |
| 57 bool GetAcceleratorForCommandId(int command_id, | 45 bool GetAcceleratorForCommandId(int command_id, |
| 58 ui::Accelerator* accelerator) override; | 46 ui::Accelerator* accelerator) override; |
| 59 bool IsItemForCommandIdDynamic(int command_id) const override; | 47 bool IsItemForCommandIdDynamic(int command_id) const override; |
| 60 base::string16 GetLabelForCommandId(int command_id) const override; | 48 base::string16 GetLabelForCommandId(int command_id) const override; |
| 61 | 49 |
| 62 private: | 50 private: |
| 51 int GetStringIdForCommand(DownloadCommand::Commands command) const; |
| 52 |
| 63 // Detaches self from |download_item_|. Called when the DownloadItem is | 53 // Detaches self from |download_item_|. Called when the DownloadItem is |
| 64 // destroyed or when this object is being destroyed. | 54 // destroyed or when this object is being destroyed. |
| 65 void DetachFromDownloadItem(); | 55 void DetachFromDownloadItem(); |
| 66 | 56 |
| 67 // content::DownloadItem::Observer | 57 // content::DownloadItem::Observer |
| 68 void OnDownloadDestroyed(content::DownloadItem* download) override; | 58 void OnDownloadDestroyed(content::DownloadItem* download) override; |
| 69 | 59 |
| 70 ui::SimpleMenuModel* GetInProgressMenuModel(); | 60 ui::SimpleMenuModel* GetInProgressMenuModel(); |
| 71 ui::SimpleMenuModel* GetFinishedMenuModel(); | 61 ui::SimpleMenuModel* GetFinishedMenuModel(); |
| 72 ui::SimpleMenuModel* GetInterruptedMenuModel(); | 62 ui::SimpleMenuModel* GetInterruptedMenuModel(); |
| 73 ui::SimpleMenuModel* GetMaybeMaliciousMenuModel(); | 63 ui::SimpleMenuModel* GetMaybeMaliciousMenuModel(); |
| 74 ui::SimpleMenuModel* GetMaliciousMenuModel(); | 64 ui::SimpleMenuModel* GetMaliciousMenuModel(); |
| 75 | 65 |
| 76 int GetAlwaysOpenStringId() const; | |
| 77 | |
| 78 #if defined(OS_WIN) || defined(OS_LINUX) || \ | |
| 79 (defined(OS_MACOSX) && !defined(OS_IOS)) | |
| 80 bool IsDownloadPdf() const; | |
| 81 bool CanOpenPdfInSystemViewer() const; | |
| 82 #endif | |
| 83 | |
| 84 // We show slightly different menus if the download is in progress vs. if the | 66 // We show slightly different menus if the download is in progress vs. if the |
| 85 // download has finished. | 67 // download has finished. |
| 86 scoped_ptr<ui::SimpleMenuModel> in_progress_download_menu_model_; | 68 scoped_ptr<ui::SimpleMenuModel> in_progress_download_menu_model_; |
| 87 scoped_ptr<ui::SimpleMenuModel> finished_download_menu_model_; | 69 scoped_ptr<ui::SimpleMenuModel> finished_download_menu_model_; |
| 88 scoped_ptr<ui::SimpleMenuModel> interrupted_download_menu_model_; | 70 scoped_ptr<ui::SimpleMenuModel> interrupted_download_menu_model_; |
| 89 scoped_ptr<ui::SimpleMenuModel> maybe_malicious_download_menu_model_; | 71 scoped_ptr<ui::SimpleMenuModel> maybe_malicious_download_menu_model_; |
| 90 scoped_ptr<ui::SimpleMenuModel> malicious_download_menu_model_; | 72 scoped_ptr<ui::SimpleMenuModel> malicious_download_menu_model_; |
| 91 | 73 |
| 92 // Information source. | 74 // Information source. |
| 93 content::DownloadItem* download_item_; | 75 content::DownloadItem* download_item_; |
| 76 DownloadCommand download_command_; |
| 94 | 77 |
| 95 // Used to open tabs. | 78 // Used to open tabs. |
| 96 content::PageNavigator* navigator_; | 79 content::PageNavigator* navigator_; |
| 97 | 80 |
| 98 #if defined(OS_WIN) | 81 #if defined(OS_WIN) |
| 99 bool is_adobe_pdf_reader_up_to_date_; | 82 bool is_adobe_pdf_reader_up_to_date_; |
| 100 #endif | 83 #endif |
| 101 | 84 |
| 102 DISALLOW_COPY_AND_ASSIGN(DownloadShelfContextMenu); | 85 DISALLOW_COPY_AND_ASSIGN(DownloadShelfContextMenu); |
| 103 }; | 86 }; |
| 104 | 87 |
| 105 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SHELF_CONTEXT_MENU_H_ | 88 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SHELF_CONTEXT_MENU_H_ |
| OLD | NEW |