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

Side by Side Diff: chrome/browser/extensions/context_menu_matcher.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: rebase and fix conflicts Created 8 years, 2 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_MATCHER_H_
6 #define CHROME_BROWSER_EXTENSIONS_CONTEXT_MENU_MATCHER_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 ExtensionContextMenuBrowserTest;
17 class Profile;
18
19 namespace extensions {
20
21 // This class contains code that is shared between the various places where
22 // context menu items added by the extension or app should be shown.
23 class ContextMenuMatcher {
24 public:
25 static const size_t kMaxExtensionItemTitleLength;
26
27 // The |filter| will be called on possibly matching menu items, and its
28 // result is used to determine which items to actually append to the menu.
29 ContextMenuMatcher(Profile* profile,
30 ui::SimpleMenuModel::Delegate* delegate,
31 ui::SimpleMenuModel* menu_model,
32 const base::Callback<bool(const MenuItem*)>& filter);
33
34 // This is a helper function to append items for one particular extension.
35 // The |index| parameter is used for assigning id's, and is incremented for
36 // each item actually added.
37 void AppendExtensionItems(const std::string& extension_id,
38 const string16& selection_text,
39 int* index);
40
41 void Clear();
42
43 bool IsCommandIdChecked(int command_id) const;
44 bool IsCommandIdEnabled(int command_id) const;
45 void ExecuteCommand(int command_id,
46 const content::ContextMenuParams& params);
47
48 private:
49 friend class ::ExtensionContextMenuBrowserTest;
50
51 MenuItem::List GetRelevantExtensionItems(
52 const MenuItem::List& items,
53 bool can_cross_incognito);
54
55 // Used for recursively adding submenus of extension items.
56 void RecursivelyAppendExtensionItems(
57 const MenuItem::List& items,
58 bool can_cross_incognito,
59 const string16& selection_text,
60 ui::SimpleMenuModel* menu_model,
61 int* index);
62
63 // Attempts to get an MenuItem given the id of a context menu item.
64 extensions::MenuItem* GetExtensionMenuItem(int id) const;
65
66 // This will set the icon on the most recently-added item in the menu_model_.
67 void SetExtensionIcon(const std::string& extension_id);
68
69 Profile* profile_;
70 ui::SimpleMenuModel* menu_model_;
71 ui::SimpleMenuModel::Delegate* delegate_;
72
73 base::Callback<bool(const MenuItem*)> filter_;
74
75 // Maps the id from a context menu item to the MenuItem's internal id.
76 std::map<int, extensions::MenuItem::Id> extension_item_map_;
77
78 // Keep track of and clean up menu models for submenus.
79 ScopedVector<ui::SimpleMenuModel> extension_menu_models_;
80
81 DISALLOW_COPY_AND_ASSIGN(ContextMenuMatcher);
82 };
83
84 } // namespace extensions
85
86 #endif // CHROME_BROWSER_EXTENSIONS_CONTEXT_MENU_MATCHER_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/context_menu/context_menu_api.cc ('k') | chrome/browser/extensions/context_menu_matcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698