Chromium Code Reviews| Index: chrome/browser/extensions/context_menu_manager.h |
| diff --git a/chrome/browser/extensions/context_menu_manager.h b/chrome/browser/extensions/context_menu_manager.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f7cd3901ddb5d46d5935e1618fadb98a2e890494 |
| --- /dev/null |
| +++ b/chrome/browser/extensions/context_menu_manager.h |
| @@ -0,0 +1,91 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_EXTENSIONS_CONTEXT_MENU_MANAGER_H_ |
| +#define CHROME_BROWSER_EXTENSIONS_CONTEXT_MENU_MANAGER_H_ |
| + |
| +#include <map> |
| + |
| +#include "base/callback.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/memory/scoped_vector.h" |
| +#include "chrome/browser/extensions/menu_manager.h" |
| +#include "ui/base/models/simple_menu_model.h" |
| + |
| +class Profile; |
| + |
| +namespace extensions { |
| + |
| +// Shared code between various extension context menu related things |
| +class ContextMenuManager { |
|
asargent_no_longer_on_chrome
2012/09/10 20:25:20
I keep trying to come up with a better name to sug
Marijn Kruisselbrink
2012/09/10 23:16:57
I agree that the name of the class sucks. Unfortun
asargent_no_longer_on_chrome
2012/09/21 19:44:22
I think I have a slight preference for ContextMenu
|
| + public: |
| + static const size_t kMaxExtensionItemTitleLength; |
| + |
| + ContextMenuManager(Profile* profile, |
| + ui::SimpleMenuModel::Delegate* delegate, |
| + ui::SimpleMenuModel* menu_model, |
| + const base::Callback<bool(const MenuItem*)>& filter); |
|
asargent_no_longer_on_chrome
2012/09/10 20:25:20
It's probably worth a comment here that |filter| w
Marijn Kruisselbrink
2012/09/10 23:16:57
Done.
|
| + |
| + // This is a helper function to append items for one particular extension. |
| + // The |index| parameter is used for assigning id's, and is incremented for |
| + // each item actually added. |
| + void AppendExtensionItems(const std::string& extension_id, |
| + const string16& selection_text, |
| + int* index); |
| + |
| + void Clear(); |
| + |
| + bool IsCommandIdChecked(int command_id) const; |
| + bool IsCommandIdEnabled(int command_id) const; |
| + void ExecuteCommand(int command_id, |
| + const content::ContextMenuParams& params); |
| + |
| + static bool ContextIsLauncher(const MenuItem* item); |
|
Marijn Kruisselbrink
2012/09/06 17:54:50
This method should probably instead of being here
asargent_no_longer_on_chrome
2012/09/10 20:25:20
Yes, it might make more sense to implemented in an
Marijn Kruisselbrink
2012/09/10 23:16:57
Done.
|
| + |
| + // These two methods should only be used for tests |
|
asargent_no_longer_on_chrome
2012/09/10 20:25:20
Can you put them in a protected: section and make
Marijn Kruisselbrink
2012/09/10 23:16:57
Unfortunately the test code that uses these method
asargent_no_longer_on_chrome
2012/09/21 19:44:22
Ok - the last option sounds fine to me.
|
| + std::map<int, MenuItem::Id>::iterator map_begin() { |
| + return extension_item_map_.begin(); |
| + } |
| + |
| + std::map<int, MenuItem::Id>::iterator map_end() { |
| + return extension_item_map_.end(); |
| + } |
| + |
| + private: |
| + MenuItem::List GetRelevantExtensionItems( |
| + const MenuItem::List& items, |
| + bool can_cross_incognito); |
| + |
| + // Used for recursively adding submenus of extension items. |
| + void RecursivelyAppendExtensionItems( |
| + const MenuItem::List& items, |
| + bool can_cross_incognito, |
| + const string16& selection_text, |
| + ui::SimpleMenuModel* menu_model, |
| + int* index); |
| + |
| + // Attempts to get an MenuItem given the id of a context menu item. |
| + extensions::MenuItem* GetExtensionMenuItem(int id) const; |
| + |
| + // This will set the icon on the most recently-added item in the menu_model_. |
| + void SetExtensionIcon(const std::string& extension_id); |
| + |
| + Profile* profile_; |
| + ui::SimpleMenuModel* menu_model_; |
| + ui::SimpleMenuModel::Delegate* delegate_; |
| + |
| + base::Callback<bool(const MenuItem*)> filter_; |
| + |
| + // Maps the id from a context menu item to the MenuItem's internal id. |
| + std::map<int, extensions::MenuItem::Id> extension_item_map_; |
| + |
| + // Keep track of and clean up menu models for submenus. |
| + ScopedVector<ui::SimpleMenuModel> extension_menu_models_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ContextMenuManager); |
| +}; |
| + |
| +} // namespace extensions |
| + |
| +#endif // CHROME_BROWSER_EXTENSIONS_CONTEXT_MENU_MANAGER_H_ |