| 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_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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "chrome/browser/extensions/extension_function.h" | 9 #include "chrome/browser/extensions/extension_function.h" |
| 10 #include "chrome/browser/extensions/extension_menu_manager.h" | 10 #include "chrome/browser/extensions/extension_menu_manager.h" |
| 11 #include "chrome/common/extensions/url_pattern_set.h" | 11 #include "chrome/common/extensions/url_pattern_set.h" |
| 12 | 12 |
| 13 class ExtensionMenuItem; | 13 class ExtensionMenuItem; |
| 14 | 14 |
| 15 namespace base { | 15 namespace base { |
| 16 class DictionaryValue; | 16 class DictionaryValue; |
| 17 } | 17 } |
| 18 | 18 |
| 19 class ExtensionContextMenuFunction : public SyncExtensionFunction { | 19 class ExtensionContextMenuFunction : public SyncExtensionFunction { |
| 20 public: | 20 protected: |
| 21 virtual ~ExtensionContextMenuFunction() {} | 21 virtual ~ExtensionContextMenuFunction() {} |
| 22 | 22 |
| 23 protected: | |
| 24 // Helper function to read and parse a list of menu item contexts. | 23 // Helper function to read and parse a list of menu item contexts. |
| 25 bool ParseContexts(const base::DictionaryValue& properties, | 24 bool ParseContexts(const base::DictionaryValue& properties, |
| 26 const char* key, | 25 const char* key, |
| 27 ExtensionMenuItem::ContextList* result); | 26 ExtensionMenuItem::ContextList* result); |
| 28 | 27 |
| 29 // Looks in properties for the "type" key, and reads the value in |result|. On | 28 // 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 | 29 // 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 | 30 // not present, |result| is set to |default_value| and the return value is |
| 32 // true. | 31 // true. |
| 33 bool ParseType(const base::DictionaryValue& properties, | 32 bool ParseType(const base::DictionaryValue& properties, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 56 // on error, with an explanation written into error_. Note that if the | 55 // on error, with an explanation written into error_. Note that if the |
| 57 // parentId key is not in properties, this will return true and leave |result| | 56 // parentId key is not in properties, this will return true and leave |result| |
| 58 // unset. Also, it is considered an error if the item found has a type other | 57 // unset. Also, it is considered an error if the item found has a type other |
| 59 // than NORMAL. | 58 // than NORMAL. |
| 60 bool GetParent(const base::DictionaryValue& properties, | 59 bool GetParent(const base::DictionaryValue& properties, |
| 61 const ExtensionMenuManager& manager, | 60 const ExtensionMenuManager& manager, |
| 62 ExtensionMenuItem** result); | 61 ExtensionMenuItem** result); |
| 63 }; | 62 }; |
| 64 | 63 |
| 65 class CreateContextMenuFunction : public ExtensionContextMenuFunction { | 64 class CreateContextMenuFunction : public ExtensionContextMenuFunction { |
| 65 public: |
| 66 DECLARE_EXTENSION_FUNCTION_NAME("contextMenus.create") |
| 67 |
| 68 protected: |
| 66 virtual ~CreateContextMenuFunction() {} | 69 virtual ~CreateContextMenuFunction() {} |
| 70 |
| 71 // ExtensionFunction: |
| 67 virtual bool RunImpl() OVERRIDE; | 72 virtual bool RunImpl() OVERRIDE; |
| 68 DECLARE_EXTENSION_FUNCTION_NAME("contextMenus.create") | |
| 69 }; | 73 }; |
| 70 | 74 |
| 71 class UpdateContextMenuFunction : public ExtensionContextMenuFunction { | 75 class UpdateContextMenuFunction : public ExtensionContextMenuFunction { |
| 76 public: |
| 77 DECLARE_EXTENSION_FUNCTION_NAME("contextMenus.update") |
| 78 |
| 79 protected: |
| 72 virtual ~UpdateContextMenuFunction() {} | 80 virtual ~UpdateContextMenuFunction() {} |
| 81 |
| 82 // ExtensionFunction: |
| 73 virtual bool RunImpl() OVERRIDE; | 83 virtual bool RunImpl() OVERRIDE; |
| 74 DECLARE_EXTENSION_FUNCTION_NAME("contextMenus.update") | |
| 75 }; | 84 }; |
| 76 | 85 |
| 77 class RemoveContextMenuFunction : public ExtensionContextMenuFunction { | 86 class RemoveContextMenuFunction : public ExtensionContextMenuFunction { |
| 87 public: |
| 88 DECLARE_EXTENSION_FUNCTION_NAME("contextMenus.remove") |
| 89 |
| 90 protected: |
| 78 virtual ~RemoveContextMenuFunction() {} | 91 virtual ~RemoveContextMenuFunction() {} |
| 92 |
| 93 // ExtensionFunction: |
| 79 virtual bool RunImpl() OVERRIDE; | 94 virtual bool RunImpl() OVERRIDE; |
| 80 DECLARE_EXTENSION_FUNCTION_NAME("contextMenus.remove") | |
| 81 }; | 95 }; |
| 82 | 96 |
| 83 class RemoveAllContextMenusFunction : public ExtensionContextMenuFunction { | 97 class RemoveAllContextMenusFunction : public ExtensionContextMenuFunction { |
| 98 public: |
| 99 DECLARE_EXTENSION_FUNCTION_NAME("contextMenus.removeAll") |
| 100 |
| 101 protected: |
| 84 virtual ~RemoveAllContextMenusFunction() {} | 102 virtual ~RemoveAllContextMenusFunction() {} |
| 103 |
| 104 // ExtensionFunction: |
| 85 virtual bool RunImpl() OVERRIDE; | 105 virtual bool RunImpl() OVERRIDE; |
| 86 DECLARE_EXTENSION_FUNCTION_NAME("contextMenus.removeAll") | |
| 87 }; | 106 }; |
| 88 | 107 |
| 89 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_CONTEXT_MENU_API_H__ | 108 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_CONTEXT_MENU_API_H__ |
| OLD | NEW |