Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: chrome/browser/extensions/api/context_menus/context_menus_api_helpers.h

Issue 359493005: Extend contextMenus API to support browser/page actions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/extensions/api/context_menus/context_menus_api_helpers.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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 // Definition of helper functions for the ContextMenus API. 5 // Definition of helper functions for the ContextMenus API.
6 6
7 #ifndef CHROME_BROWSER_EXTENSIONS_API_CONTEXT_MENUS_CONTEXT_MENUS_API_HELPERS_H_ 7 #ifndef CHROME_BROWSER_EXTENSIONS_API_CONTEXT_MENUS_CONTEXT_MENUS_API_HELPERS_H_
8 #define CHROME_BROWSER_EXTENSIONS_API_CONTEXT_MENUS_CONTEXT_MENUS_API_HELPERS_H_ 8 #define CHROME_BROWSER_EXTENSIONS_API_CONTEXT_MENUS_CONTEXT_MENUS_API_HELPERS_H_
9 9
10 #include "chrome/browser/extensions/menu_manager.h" 10 #include "chrome/browser/extensions/menu_manager.h"
(...skipping 20 matching lines...) Expand all
31 parent_id->uid = *property.parent_id->as_integer; 31 parent_id->uid = *property.parent_id->as_integer;
32 else if (property.parent_id->as_string) 32 else if (property.parent_id->as_string)
33 parent_id->string_uid = *property.parent_id->as_string; 33 parent_id->string_uid = *property.parent_id->as_string;
34 else 34 else
35 NOTREACHED(); 35 NOTREACHED();
36 return parent_id.Pass(); 36 return parent_id.Pass();
37 } 37 }
38 38
39 } // namespace 39 } // namespace
40 40
41 extern const char kActionNotAllowedError[];
41 extern const char kCannotFindItemError[]; 42 extern const char kCannotFindItemError[];
42 extern const char kCheckedError[]; 43 extern const char kCheckedError[];
43 extern const char kDuplicateIDError[]; 44 extern const char kDuplicateIDError[];
44 extern const char kGeneratedIdKey[]; 45 extern const char kGeneratedIdKey[];
45 extern const char kLauncherNotAllowedError[]; 46 extern const char kLauncherNotAllowedError[];
46 extern const char kOnclickDisallowedError[]; 47 extern const char kOnclickDisallowedError[];
47 extern const char kParentsMustBeNormalError[]; 48 extern const char kParentsMustBeNormalError[];
48 extern const char kTitleNeededError[]; 49 extern const char kTitleNeededError[];
49 50
50 std::string GetIDString(const MenuItem::Id& id); 51 std::string GetIDString(const MenuItem::Id& id);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 case PropertyWithEnumT::CONTEXTS_TYPE_AUDIO: 83 case PropertyWithEnumT::CONTEXTS_TYPE_AUDIO:
83 contexts.Add(extensions::MenuItem::AUDIO); 84 contexts.Add(extensions::MenuItem::AUDIO);
84 break; 85 break;
85 case PropertyWithEnumT::CONTEXTS_TYPE_FRAME: 86 case PropertyWithEnumT::CONTEXTS_TYPE_FRAME:
86 contexts.Add(extensions::MenuItem::FRAME); 87 contexts.Add(extensions::MenuItem::FRAME);
87 break; 88 break;
88 case PropertyWithEnumT::CONTEXTS_TYPE_LAUNCHER: 89 case PropertyWithEnumT::CONTEXTS_TYPE_LAUNCHER:
89 // Not available for <webview>. 90 // Not available for <webview>.
90 contexts.Add(extensions::MenuItem::LAUNCHER); 91 contexts.Add(extensions::MenuItem::LAUNCHER);
91 break; 92 break;
93 case PropertyWithEnumT::CONTEXTS_TYPE_BROWSER_ACTION:
94 // Not available for <webview>.
95 contexts.Add(extensions::MenuItem::BROWSER_ACTION);
96 break;
97 case PropertyWithEnumT::CONTEXTS_TYPE_PAGE_ACTION:
98 // Not available for <webview>.
99 contexts.Add(extensions::MenuItem::PAGE_ACTION);
100 break;
92 case PropertyWithEnumT::CONTEXTS_TYPE_NONE: 101 case PropertyWithEnumT::CONTEXTS_TYPE_NONE:
93 NOTREACHED(); 102 NOTREACHED();
94 } 103 }
95 } 104 }
96 return contexts; 105 return contexts;
97 } 106 }
98 107
99 template<typename PropertyWithEnumT> 108 template<typename PropertyWithEnumT>
100 MenuItem::Type GetType(const PropertyWithEnumT& property, 109 MenuItem::Type GetType(const PropertyWithEnumT& property,
101 MenuItem::Type default_type) { 110 MenuItem::Type default_type) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 contexts.Add(MenuItem::PAGE); 153 contexts.Add(MenuItem::PAGE);
145 154
146 if (contexts.Contains(MenuItem::LAUNCHER)) { 155 if (contexts.Contains(MenuItem::LAUNCHER)) {
147 // Launcher item is not allowed for <webview>. 156 // Launcher item is not allowed for <webview>.
148 if (!extension->is_platform_app() || is_webview) { 157 if (!extension->is_platform_app() || is_webview) {
149 *error = kLauncherNotAllowedError; 158 *error = kLauncherNotAllowedError;
150 return false; 159 return false;
151 } 160 }
152 } 161 }
153 162
163 if (contexts.Contains(MenuItem::BROWSER_ACTION) ||
164 contexts.Contains(MenuItem::PAGE_ACTION)) {
165 // Action items are not allowed for <webview>.
166 if (!extension->is_extension() || is_webview) {
167 *error = kActionNotAllowedError;
168 return false;
169 }
170 }
171
154 // Title. 172 // Title.
155 std::string title; 173 std::string title;
156 if (create_properties.title.get()) 174 if (create_properties.title.get())
157 title = *create_properties.title; 175 title = *create_properties.title;
158 176
159 MenuItem::Type type = GetType(create_properties, MenuItem::NORMAL); 177 MenuItem::Type type = GetType(create_properties, MenuItem::NORMAL);
160 if (title.empty() && type != MenuItem::SEPARATOR) { 178 if (title.empty() && type != MenuItem::SEPARATOR) {
161 *error = kTitleNeededError; 179 *error = kTitleNeededError;
162 return false; 180 return false;
163 } 181 }
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 return false; 320 return false;
303 321
304 menu_manager->WriteToStorage(extension, item_id.extension_key); 322 menu_manager->WriteToStorage(extension, item_id.extension_key);
305 return true; 323 return true;
306 } 324 }
307 325
308 } // namespace context_menus_api_helpers 326 } // namespace context_menus_api_helpers
309 } // namespace extensions 327 } // namespace extensions
310 328
311 #endif // CHROME_BROWSER_EXTENSIONS_API_CONTEXT_MENUS_CONTEXT_MENUS_API_HELPERS _H_ 329 #endif // CHROME_BROWSER_EXTENSIONS_API_CONTEXT_MENUS_CONTEXT_MENUS_API_HELPERS _H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/api/context_menus/context_menus_api_helpers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698