Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Side by Side Diff: chrome/browser/extensions/context_menu_manager.h

Issue 10918103: Give platform apps control over launcher right-click context menu. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_EXTENSIONS_CONTEXT_MENU_MANAGER_H_
6 #define CHROME_BROWSER_EXTENSIONS_CONTEXT_MENU_MANAGER_H_
7
8 #include <map>
9
10 #include "base/callback.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/scoped_vector.h"
13 #include "chrome/browser/extensions/menu_manager.h"
14 #include "ui/base/models/simple_menu_model.h"
15
16 class Profile;
17
18 namespace extensions {
19
20 // Shared code between various extension context menu related things
21 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
22 public:
23 static const size_t kMaxExtensionItemTitleLength;
24
25 ContextMenuManager(Profile* profile,
26 ui::SimpleMenuModel::Delegate* delegate,
27 ui::SimpleMenuModel* menu_model,
28 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.
29
30 // This is a helper function to append items for one particular extension.
31 // The |index| parameter is used for assigning id's, and is incremented for
32 // each item actually added.
33 void AppendExtensionItems(const std::string& extension_id,
34 const string16& selection_text,
35 int* index);
36
37 void Clear();
38
39 bool IsCommandIdChecked(int command_id) const;
40 bool IsCommandIdEnabled(int command_id) const;
41 void ExecuteCommand(int command_id,
42 const content::ContextMenuParams& params);
43
44 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.
45
46 // 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.
47 std::map<int, MenuItem::Id>::iterator map_begin() {
48 return extension_item_map_.begin();
49 }
50
51 std::map<int, MenuItem::Id>::iterator map_end() {
52 return extension_item_map_.end();
53 }
54
55 private:
56 MenuItem::List GetRelevantExtensionItems(
57 const MenuItem::List& items,
58 bool can_cross_incognito);
59
60 // Used for recursively adding submenus of extension items.
61 void RecursivelyAppendExtensionItems(
62 const MenuItem::List& items,
63 bool can_cross_incognito,
64 const string16& selection_text,
65 ui::SimpleMenuModel* menu_model,
66 int* index);
67
68 // Attempts to get an MenuItem given the id of a context menu item.
69 extensions::MenuItem* GetExtensionMenuItem(int id) const;
70
71 // This will set the icon on the most recently-added item in the menu_model_.
72 void SetExtensionIcon(const std::string& extension_id);
73
74 Profile* profile_;
75 ui::SimpleMenuModel* menu_model_;
76 ui::SimpleMenuModel::Delegate* delegate_;
77
78 base::Callback<bool(const MenuItem*)> filter_;
79
80 // Maps the id from a context menu item to the MenuItem's internal id.
81 std::map<int, extensions::MenuItem::Id> extension_item_map_;
82
83 // Keep track of and clean up menu models for submenus.
84 ScopedVector<ui::SimpleMenuModel> extension_menu_models_;
85
86 DISALLOW_COPY_AND_ASSIGN(ContextMenuManager);
87 };
88
89 } // namespace extensions
90
91 #endif // CHROME_BROWSER_EXTENSIONS_CONTEXT_MENU_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698