| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_EXTENSIONS_CONTEXT_MENU_MATCHER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_CONTEXT_MENU_MATCHER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_CONTEXT_MENU_MATCHER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_CONTEXT_MENU_MATCHER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 // The |filter| will be called on possibly matching menu items, and its | 37 // The |filter| will be called on possibly matching menu items, and its |
| 38 // result is used to determine which items to actually append to the menu. | 38 // result is used to determine which items to actually append to the menu. |
| 39 ContextMenuMatcher(content::BrowserContext* context, | 39 ContextMenuMatcher(content::BrowserContext* context, |
| 40 ui::SimpleMenuModel::Delegate* delegate, | 40 ui::SimpleMenuModel::Delegate* delegate, |
| 41 ui::SimpleMenuModel* menu_model, | 41 ui::SimpleMenuModel* menu_model, |
| 42 const base::Callback<bool(const MenuItem*)>& filter); | 42 const base::Callback<bool(const MenuItem*)>& filter); |
| 43 | 43 |
| 44 // This is a helper function to append items for one particular extension. | 44 // This is a helper function to append items for one particular extension. |
| 45 // The |index| parameter is used for assigning id's, and is incremented for | 45 // The |index| parameter is used for assigning id's, and is incremented for |
| 46 // each item actually added. |is_action_menu| is used for browser and page | 46 // each item actually added. |
| 47 // action context menus, in which menu items are not placed in submenus | |
| 48 // and the extension's icon is not shown. | |
| 49 void AppendExtensionItems(const MenuItem::ExtensionKey& extension_key, | 47 void AppendExtensionItems(const MenuItem::ExtensionKey& extension_key, |
| 50 const base::string16& selection_text, | 48 const base::string16& selection_text, |
| 51 int* index, | 49 int* index); |
| 52 bool is_action_menu); | |
| 53 | 50 |
| 54 void Clear(); | 51 void Clear(); |
| 55 | 52 |
| 56 // This function returns the top level context menu title of an extension | 53 // This function returns the top level context menu title of an extension |
| 57 // based on a printable selection text. | 54 // based on a printable selection text. |
| 58 base::string16 GetTopLevelContextMenuTitle( | 55 base::string16 GetTopLevelContextMenuTitle( |
| 59 const MenuItem::ExtensionKey& extension_key, | 56 const MenuItem::ExtensionKey& extension_key, |
| 60 const base::string16& selection_text); | 57 const base::string16& selection_text); |
| 61 | 58 |
| 62 bool IsCommandIdChecked(int command_id) const; | 59 bool IsCommandIdChecked(int command_id) const; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 76 | 73 |
| 77 MenuItem::List GetRelevantExtensionItems( | 74 MenuItem::List GetRelevantExtensionItems( |
| 78 const MenuItem::List& items, | 75 const MenuItem::List& items, |
| 79 bool can_cross_incognito); | 76 bool can_cross_incognito); |
| 80 | 77 |
| 81 // Used for recursively adding submenus of extension items. | 78 // Used for recursively adding submenus of extension items. |
| 82 void RecursivelyAppendExtensionItems(const MenuItem::List& items, | 79 void RecursivelyAppendExtensionItems(const MenuItem::List& items, |
| 83 bool can_cross_incognito, | 80 bool can_cross_incognito, |
| 84 const base::string16& selection_text, | 81 const base::string16& selection_text, |
| 85 ui::SimpleMenuModel* menu_model, | 82 ui::SimpleMenuModel* menu_model, |
| 86 int* index, | 83 int* index); |
| 87 bool is_action_menu_top_level); | |
| 88 | 84 |
| 89 // Attempts to get an MenuItem given the id of a context menu item. | 85 // Attempts to get an MenuItem given the id of a context menu item. |
| 90 extensions::MenuItem* GetExtensionMenuItem(int id) const; | 86 extensions::MenuItem* GetExtensionMenuItem(int id) const; |
| 91 | 87 |
| 92 // This will set the icon on the most recently-added item in the menu_model_. | 88 // This will set the icon on the most recently-added item in the menu_model_. |
| 93 void SetExtensionIcon(const std::string& extension_id); | 89 void SetExtensionIcon(const std::string& extension_id); |
| 94 | 90 |
| 95 content::BrowserContext* browser_context_; | 91 content::BrowserContext* browser_context_; |
| 96 ui::SimpleMenuModel* menu_model_; | 92 ui::SimpleMenuModel* menu_model_; |
| 97 ui::SimpleMenuModel::Delegate* delegate_; | 93 ui::SimpleMenuModel::Delegate* delegate_; |
| 98 | 94 |
| 99 base::Callback<bool(const MenuItem*)> filter_; | 95 base::Callback<bool(const MenuItem*)> filter_; |
| 100 | 96 |
| 101 // Maps the id from a context menu item to the MenuItem's internal id. | 97 // Maps the id from a context menu item to the MenuItem's internal id. |
| 102 std::map<int, extensions::MenuItem::Id> extension_item_map_; | 98 std::map<int, extensions::MenuItem::Id> extension_item_map_; |
| 103 | 99 |
| 104 // Keep track of and clean up menu models for submenus. | 100 // Keep track of and clean up menu models for submenus. |
| 105 ScopedVector<ui::SimpleMenuModel> extension_menu_models_; | 101 ScopedVector<ui::SimpleMenuModel> extension_menu_models_; |
| 106 | 102 |
| 107 DISALLOW_COPY_AND_ASSIGN(ContextMenuMatcher); | 103 DISALLOW_COPY_AND_ASSIGN(ContextMenuMatcher); |
| 108 }; | 104 }; |
| 109 | 105 |
| 110 } // namespace extensions | 106 } // namespace extensions |
| 111 | 107 |
| 112 #endif // CHROME_BROWSER_EXTENSIONS_CONTEXT_MENU_MATCHER_H_ | 108 #endif // CHROME_BROWSER_EXTENSIONS_CONTEXT_MENU_MATCHER_H_ |
| OLD | NEW |