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_API_CONTEXT_MENU_CONTEXT_MENU_API_H__ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_CONTEXT_MENU_CONTEXT_MENU_API_H__ |
6 #define CHROME_BROWSER_EXTENSIONS_API_CONTEXT_MENU_CONTEXT_MENU_API_H__ | 6 #define CHROME_BROWSER_EXTENSIONS_API_CONTEXT_MENU_CONTEXT_MENU_API_H__ |
7 | 7 |
8 #include "chrome/browser/extensions/extension_function.h" | 8 #include "chrome/browser/extensions/extension_function.h" |
9 #include "chrome/browser/extensions/menu_manager.h" | |
10 #include "chrome/common/extensions/url_pattern_set.h" | |
11 | |
12 class MenuItem; | |
13 | |
14 namespace base { | |
15 class DictionaryValue; | |
16 } | |
17 | 9 |
18 namespace extensions { | 10 namespace extensions { |
19 | 11 |
20 class ExtensionContextMenuFunction : public SyncExtensionFunction { | 12 class CreateContextMenuFunction : public SyncExtensionFunction { |
21 protected: | |
22 virtual ~ExtensionContextMenuFunction() {} | |
not at google - send to devlin
2012/07/26 04:16:20
woo!
| |
23 | |
24 // Helper function to read and parse a list of menu item contexts. | |
25 bool ParseContexts(const base::DictionaryValue& properties, | |
26 const char* key, | |
27 MenuItem::ContextList* result); | |
28 | |
29 // Looks in properties for the "type" key, and reads the value in |result|. On | |
30 // error, returns false and puts an error message into error_. If the key is | |
31 // not present, |result| is set to |default_value| and the return value is | |
32 // true. | |
33 bool ParseType(const base::DictionaryValue& properties, | |
34 const MenuItem::Type& default_value, | |
35 MenuItem::Type* result); | |
36 | |
37 // Helper to read and parse the "checked" property. | |
38 bool ParseChecked(MenuItem::Type type, | |
39 const base::DictionaryValue& properties, | |
40 bool default_value, | |
41 bool* checked); | |
42 | |
43 // Helper to read an ID from the Value*. The ID can be either a string or | |
44 // integer. | |
45 bool ParseID(const Value* value, MenuItem::Id* result); | |
46 | |
47 // If the parentId key was specified in properties, this will try looking up | |
48 // an MenuItem with that id and set it into |result|. Returns false | |
49 // on error, with an explanation written into error_. Note that if the | |
50 // parentId key is not in properties, this will return true and leave |result| | |
51 // unset. Also, it is considered an error if the item found has a type other | |
52 // than NORMAL. | |
53 bool GetParent(const base::DictionaryValue& properties, | |
54 const MenuManager& manager, | |
55 MenuItem** result); | |
56 }; | |
57 | |
58 class CreateContextMenuFunction : public ExtensionContextMenuFunction { | |
59 public: | 13 public: |
60 DECLARE_EXTENSION_FUNCTION_NAME("contextMenus.create") | 14 DECLARE_EXTENSION_FUNCTION_NAME("contextMenus.create") |
61 | 15 |
62 protected: | 16 protected: |
63 virtual ~CreateContextMenuFunction() {} | 17 virtual ~CreateContextMenuFunction() {} |
64 | 18 |
65 // ExtensionFunction: | 19 // ExtensionFunction: |
66 virtual bool RunImpl() OVERRIDE; | 20 virtual bool RunImpl() OVERRIDE; |
67 }; | 21 }; |
68 | 22 |
69 class UpdateContextMenuFunction : public ExtensionContextMenuFunction { | 23 class UpdateContextMenuFunction : public SyncExtensionFunction { |
70 public: | 24 public: |
71 DECLARE_EXTENSION_FUNCTION_NAME("contextMenus.update") | 25 DECLARE_EXTENSION_FUNCTION_NAME("contextMenus.update") |
72 | 26 |
73 protected: | 27 protected: |
74 virtual ~UpdateContextMenuFunction() {} | 28 virtual ~UpdateContextMenuFunction() {} |
75 | 29 |
76 // ExtensionFunction: | 30 // ExtensionFunction: |
77 virtual bool RunImpl() OVERRIDE; | 31 virtual bool RunImpl() OVERRIDE; |
78 }; | 32 }; |
79 | 33 |
80 class RemoveContextMenuFunction : public ExtensionContextMenuFunction { | 34 class RemoveContextMenuFunction : public SyncExtensionFunction { |
81 public: | 35 public: |
82 DECLARE_EXTENSION_FUNCTION_NAME("contextMenus.remove") | 36 DECLARE_EXTENSION_FUNCTION_NAME("contextMenus.remove") |
83 | 37 |
84 protected: | 38 protected: |
85 virtual ~RemoveContextMenuFunction() {} | 39 virtual ~RemoveContextMenuFunction() {} |
86 | 40 |
87 // ExtensionFunction: | 41 // ExtensionFunction: |
88 virtual bool RunImpl() OVERRIDE; | 42 virtual bool RunImpl() OVERRIDE; |
89 }; | 43 }; |
90 | 44 |
91 class RemoveAllContextMenusFunction : public ExtensionContextMenuFunction { | 45 class RemoveAllContextMenusFunction : public SyncExtensionFunction { |
92 public: | 46 public: |
93 DECLARE_EXTENSION_FUNCTION_NAME("contextMenus.removeAll") | 47 DECLARE_EXTENSION_FUNCTION_NAME("contextMenus.removeAll") |
94 | 48 |
95 protected: | 49 protected: |
96 virtual ~RemoveAllContextMenusFunction() {} | 50 virtual ~RemoveAllContextMenusFunction() {} |
97 | 51 |
98 // ExtensionFunction: | 52 // ExtensionFunction: |
99 virtual bool RunImpl() OVERRIDE; | 53 virtual bool RunImpl() OVERRIDE; |
100 }; | 54 }; |
101 | 55 |
102 } // namespace extensions | 56 } // namespace extensions |
103 | 57 |
104 #endif // CHROME_BROWSER_EXTENSIONS_API_CONTEXT_MENU_CONTEXT_MENU_API_H__ | 58 #endif // CHROME_BROWSER_EXTENSIONS_API_CONTEXT_MENU_CONTEXT_MENU_API_H__ |
OLD | NEW |