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