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