Chromium Code Reviews| 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" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
| 13 #include "chrome/browser/extensions/menu_manager.h" | 13 #include "chrome/browser/extensions/menu_manager.h" |
| 14 #include "ui/base/models/simple_menu_model.h" | 14 #include "ui/base/models/simple_menu_model.h" |
| 15 | 15 |
| 16 class ExtensionContextMenuBrowserTest; | 16 class ExtensionContextMenuBrowserTest; |
| 17 class Profile; | |
|
Devlin
2014/07/30 21:32:57
Don't need this.
gpdavis
2014/07/31 23:11:28
Done.
| |
| 17 | 18 |
| 18 namespace content { | 19 namespace content { |
| 19 class BrowserContext; | 20 class BrowserContext; |
| 20 } | 21 } |
| 21 | 22 |
| 22 namespace extensions { | 23 namespace extensions { |
| 23 | 24 |
| 24 // This class contains code that is shared between the various places where | 25 // This class contains code that is shared between the various places where |
| 25 // context menu items added by the extension or app should be shown. | 26 // context menu items added by the extension or app should be shown. |
| 26 class ContextMenuMatcher { | 27 class ContextMenuMatcher { |
| 27 public: | 28 public: |
| 28 static const size_t kMaxExtensionItemTitleLength; | 29 static const size_t kMaxExtensionItemTitleLength; |
| 29 | 30 |
| 30 // Convert a command ID so that it fits within the range for | 31 // Convert a command ID so that it fits within the range for |
| 31 // extension context menu. | 32 // extension context menu. |
| 32 static int ConvertToExtensionsCustomCommandId(int id); | 33 static int ConvertToExtensionsCustomCommandId(int id); |
| 33 | 34 |
| 34 // Returns true if the given id is one generated for extension context menu. | 35 // Returns true if the given id is one generated for extension context menu. |
| 35 static bool IsExtensionsCustomCommandId(int id); | 36 static bool IsExtensionsCustomCommandId(int id); |
| 36 | 37 |
| 37 // The |filter| will be called on possibly matching menu items, and its | 38 // 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. | 39 // result is used to determine which items to actually append to the menu. |
| 39 ContextMenuMatcher(content::BrowserContext* context, | 40 ContextMenuMatcher(content::BrowserContext* context, |
| 40 ui::SimpleMenuModel::Delegate* delegate, | 41 ui::SimpleMenuModel::Delegate* delegate, |
| 41 ui::SimpleMenuModel* menu_model, | 42 ui::SimpleMenuModel* menu_model, |
| 42 const base::Callback<bool(const MenuItem*)>& filter); | 43 const base::Callback<bool(const MenuItem*)>& filter); |
| 43 | 44 |
| 44 // This is a helper function to append items for one particular extension. | 45 // 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 | 46 // The |index| parameter is used for assigning id's, and is incremented for |
| 46 // each item actually added. | 47 // each item actually added. |is_action_menu| is used for browser and page |
| 48 // action context menus, in which menu items are not placed in submenus | |
| 49 // and the extension's icon is not shown. | |
| 47 void AppendExtensionItems(const MenuItem::ExtensionKey& extension_key, | 50 void AppendExtensionItems(const MenuItem::ExtensionKey& extension_key, |
| 48 const base::string16& selection_text, | 51 const base::string16& selection_text, |
| 49 int* index); | 52 int* index, |
| 53 bool is_action_menu); | |
| 50 | 54 |
| 51 void Clear(); | 55 void Clear(); |
| 52 | 56 |
| 53 // This function returns the top level context menu title of an extension | 57 // This function returns the top level context menu title of an extension |
| 54 // based on a printable selection text. | 58 // based on a printable selection text. |
| 55 base::string16 GetTopLevelContextMenuTitle( | 59 base::string16 GetTopLevelContextMenuTitle( |
| 56 const MenuItem::ExtensionKey& extension_key, | 60 const MenuItem::ExtensionKey& extension_key, |
| 57 const base::string16& selection_text); | 61 const base::string16& selection_text); |
| 58 | 62 |
| 59 bool IsCommandIdChecked(int command_id) const; | 63 bool IsCommandIdChecked(int command_id) const; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 73 | 77 |
| 74 MenuItem::List GetRelevantExtensionItems( | 78 MenuItem::List GetRelevantExtensionItems( |
| 75 const MenuItem::List& items, | 79 const MenuItem::List& items, |
| 76 bool can_cross_incognito); | 80 bool can_cross_incognito); |
| 77 | 81 |
| 78 // Used for recursively adding submenus of extension items. | 82 // Used for recursively adding submenus of extension items. |
| 79 void RecursivelyAppendExtensionItems(const MenuItem::List& items, | 83 void RecursivelyAppendExtensionItems(const MenuItem::List& items, |
| 80 bool can_cross_incognito, | 84 bool can_cross_incognito, |
| 81 const base::string16& selection_text, | 85 const base::string16& selection_text, |
| 82 ui::SimpleMenuModel* menu_model, | 86 ui::SimpleMenuModel* menu_model, |
| 83 int* index); | 87 int* index, |
| 88 bool is_action_menu_top_level); | |
| 84 | 89 |
| 85 // Attempts to get an MenuItem given the id of a context menu item. | 90 // Attempts to get an MenuItem given the id of a context menu item. |
| 86 extensions::MenuItem* GetExtensionMenuItem(int id) const; | 91 extensions::MenuItem* GetExtensionMenuItem(int id) const; |
| 87 | 92 |
| 88 // This will set the icon on the most recently-added item in the menu_model_. | 93 // This will set the icon on the most recently-added item in the menu_model_. |
| 89 void SetExtensionIcon(const std::string& extension_id); | 94 void SetExtensionIcon(const std::string& extension_id); |
| 90 | 95 |
| 91 content::BrowserContext* browser_context_; | 96 content::BrowserContext* browser_context_; |
| 92 ui::SimpleMenuModel* menu_model_; | 97 ui::SimpleMenuModel* menu_model_; |
| 93 ui::SimpleMenuModel::Delegate* delegate_; | 98 ui::SimpleMenuModel::Delegate* delegate_; |
| 94 | 99 |
| 95 base::Callback<bool(const MenuItem*)> filter_; | 100 base::Callback<bool(const MenuItem*)> filter_; |
| 96 | 101 |
| 97 // Maps the id from a context menu item to the MenuItem's internal id. | 102 // Maps the id from a context menu item to the MenuItem's internal id. |
| 98 std::map<int, extensions::MenuItem::Id> extension_item_map_; | 103 std::map<int, extensions::MenuItem::Id> extension_item_map_; |
| 99 | 104 |
| 100 // Keep track of and clean up menu models for submenus. | 105 // Keep track of and clean up menu models for submenus. |
| 101 ScopedVector<ui::SimpleMenuModel> extension_menu_models_; | 106 ScopedVector<ui::SimpleMenuModel> extension_menu_models_; |
| 102 | 107 |
| 103 DISALLOW_COPY_AND_ASSIGN(ContextMenuMatcher); | 108 DISALLOW_COPY_AND_ASSIGN(ContextMenuMatcher); |
| 104 }; | 109 }; |
| 105 | 110 |
| 106 } // namespace extensions | 111 } // namespace extensions |
| 107 | 112 |
| 108 #endif // CHROME_BROWSER_EXTENSIONS_CONTEXT_MENU_MATCHER_H_ | 113 #endif // CHROME_BROWSER_EXTENSIONS_CONTEXT_MENU_MATCHER_H_ |
| OLD | NEW |