1 // Copyright 2014 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 #include "chrome/browser/extensions/api/context_menus/context_menus_api_helpers.h" 6 7 #include "base/strings/string_number_conversions.h" 8 9 namespace extensions { 10 namespace context_menus_api_helpers { 11 12 const char kActionNotAllowedError[] = 13 "Only extensions are allowed to use action contexts"; 14 const char kCannotFindItemError[] = "Cannot find menu item with id *"; 15 const char kCheckedError[] = 16 "Only items with type \"radio\" or \"checkbox\" can be checked"; 17 const char kDuplicateIDError[] = 18 "Cannot create item with duplicate id *"; 19 const char kGeneratedIdKey[] = "generatedId"; 20 const char kLauncherNotAllowedError[] = 21 "Only packaged apps are allowed to use 'launcher' context"; 22 const char kOnclickDisallowedError[] = "Extensions using event pages cannot " 23 "pass an onclick parameter to chrome.contextMenus.create. Instead, use " 24 "the chrome.contextMenus.onClicked event."; 25 const char kParentsMustBeNormalError[] = 26 "Parent items must have type \"normal\""; 27 const char kTitleNeededError[] = 28 "All menu items except for separators must have a title"; 29 30 31 std::string GetIDString(const MenuItem::Id& id) { 32 if (id.uid == 0) 33 return id.string_uid; 34 else 35 return base::IntToString(id.uid); 36 } 37 38 MenuItem* GetParent(MenuItem::Id parent_id, 39 const MenuManager* menu_manager, 40 std::string* error) { 41 MenuItem* parent = menu_manager->GetItemById(parent_id); 42 if (!parent) { 43 *error = ErrorUtils::FormatErrorMessage( 44 kCannotFindItemError, GetIDString(parent_id)); 45 return NULL; 46 } 47 if (parent->type() != MenuItem::NORMAL) { 48 *error = kParentsMustBeNormalError; 49 return NULL; 50 } 51 return parent; 52 } 53 54 } // namespace context_menus_api_helpers 55 } // namespace extensions 56