OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_EXTENSION_CONTEXT_MENU_API_H__ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_CONTEXT_MENU_API_H__ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_CONTEXT_MENU_API_H__ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_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/extension_menu_manager.h" | 9 #include "chrome/browser/extensions/extension_menu_manager.h" |
| 10 #include "chrome/common/extensions/extension_extent.h" |
| 11 |
| 12 class ExtensionMenuItem; |
10 | 13 |
11 class ExtensionContextMenuFunction : public SyncExtensionFunction { | 14 class ExtensionContextMenuFunction : public SyncExtensionFunction { |
12 public: | 15 public: |
13 ~ExtensionContextMenuFunction() {} | 16 ~ExtensionContextMenuFunction() {} |
14 | 17 |
15 protected: | 18 protected: |
16 // Helper function to read and parse a list of menu item contexts. | 19 // Helper function to read and parse a list of menu item contexts. |
17 bool ParseContexts(const DictionaryValue& properties, | 20 bool ParseContexts(const DictionaryValue& properties, |
18 const wchar_t* key, | 21 const wchar_t* key, |
19 ExtensionMenuItem::ContextList* result); | 22 ExtensionMenuItem::ContextList* result); |
20 | 23 |
21 // Looks in properties for the "type" key, and reads the value in |result|. On | 24 // Looks in properties for the "type" key, and reads the value in |result|. On |
22 // error, returns false and puts an error message into error_. If the key is | 25 // error, returns false and puts an error message into error_. If the key is |
23 // not present, |result| is set to |default_value| and the return value is | 26 // not present, |result| is set to |default_value| and the return value is |
24 // true. | 27 // true. |
25 bool ParseType(const DictionaryValue& properties, | 28 bool ParseType(const DictionaryValue& properties, |
26 const ExtensionMenuItem::Type& default_value, | 29 const ExtensionMenuItem::Type& default_value, |
27 ExtensionMenuItem::Type* result); | 30 ExtensionMenuItem::Type* result); |
28 | 31 |
29 // Helper to read and parse the "checked" property. | 32 // Helper to read and parse the "checked" property. |
30 bool ParseChecked(ExtensionMenuItem::Type type, | 33 bool ParseChecked(ExtensionMenuItem::Type type, |
31 const DictionaryValue& properties, | 34 const DictionaryValue& properties, |
32 bool default_value, | 35 bool default_value, |
33 bool* checked); | 36 bool* checked); |
34 | 37 |
| 38 // Helper to read in a set of url patterns from a property with the given key |
| 39 // name. |
| 40 bool ParseURLPatterns(const DictionaryValue& properties, |
| 41 const wchar_t* key, |
| 42 ExtensionExtent* result); |
| 43 |
| 44 // Reads in any document and targetUrl patterns from |properties| and sets |
| 45 // them on |item|. |
| 46 bool SetURLPatterns(const DictionaryValue& properties, |
| 47 ExtensionMenuItem* item); |
| 48 |
35 // If the parentId key was specified in properties, this will try looking up | 49 // If the parentId key was specified in properties, this will try looking up |
36 // an ExtensionMenuItem with that id and set it into |result|. Returns false | 50 // an ExtensionMenuItem with that id and set it into |result|. Returns false |
37 // on error, with an explanation written into error_. Note that if the | 51 // on error, with an explanation written into error_. Note that if the |
38 // parentId key is not in properties, this will return true and leave |result| | 52 // parentId key is not in properties, this will return true and leave |result| |
39 // unset. Also, it is considered an error if the item found has a type other | 53 // unset. Also, it is considered an error if the item found has a type other |
40 // than NORMAL. | 54 // than NORMAL. |
41 bool GetParent(const DictionaryValue& properties, | 55 bool GetParent(const DictionaryValue& properties, |
42 const ExtensionMenuManager& manager, | 56 const ExtensionMenuManager& manager, |
43 ExtensionMenuItem** result); | 57 ExtensionMenuItem** result); |
44 }; | 58 }; |
(...skipping 16 matching lines...) Expand all Loading... |
61 DECLARE_EXTENSION_FUNCTION_NAME("contextMenus.remove") | 75 DECLARE_EXTENSION_FUNCTION_NAME("contextMenus.remove") |
62 }; | 76 }; |
63 | 77 |
64 class RemoveAllContextMenusFunction : public ExtensionContextMenuFunction { | 78 class RemoveAllContextMenusFunction : public ExtensionContextMenuFunction { |
65 ~RemoveAllContextMenusFunction() {} | 79 ~RemoveAllContextMenusFunction() {} |
66 virtual bool RunImpl(); | 80 virtual bool RunImpl(); |
67 DECLARE_EXTENSION_FUNCTION_NAME("contextMenus.removeAll") | 81 DECLARE_EXTENSION_FUNCTION_NAME("contextMenus.removeAll") |
68 }; | 82 }; |
69 | 83 |
70 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_CONTEXT_MENU_API_H__ | 84 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_CONTEXT_MENU_API_H__ |
OLD | NEW |