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

Side by Side Diff: chrome/browser/extensions/extension_context_menu_api.cc

Issue 4090011: Fix bug with context menus in incognito mode. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: manifest fix Created 10 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_context_menu_browsertest.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 (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 #include "chrome/browser/extensions/extension_context_menu_api.h" 5 #include "chrome/browser/extensions/extension_context_menu_api.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 &target_url_patterns)) 167 &target_url_patterns))
168 return false; 168 return false;
169 169
170 if (!target_url_patterns.is_empty()) { 170 if (!target_url_patterns.is_empty()) {
171 item->set_target_url_patterns(target_url_patterns); 171 item->set_target_url_patterns(target_url_patterns);
172 } 172 }
173 173
174 return true; 174 return true;
175 } 175 }
176 176
177
178 bool ExtensionContextMenuFunction::GetParent( 177 bool ExtensionContextMenuFunction::GetParent(
179 const DictionaryValue& properties, 178 const DictionaryValue& properties,
180 const ExtensionMenuManager& manager, 179 const ExtensionMenuManager& manager,
181 ExtensionMenuItem** result) { 180 ExtensionMenuItem** result) {
182 if (!properties.HasKey(kParentIdKey)) 181 if (!properties.HasKey(kParentIdKey))
183 return true; 182 return true;
184 ExtensionMenuItem::Id parent_id(extension_id(), 0); 183 ExtensionMenuItem::Id parent_id(profile(), extension_id(), 0);
185 if (properties.HasKey(kParentIdKey) && 184 if (properties.HasKey(kParentIdKey) &&
186 !properties.GetInteger(kParentIdKey, &parent_id.second)) 185 !properties.GetInteger(kParentIdKey, &parent_id.uid))
187 return false; 186 return false;
188 187
189 ExtensionMenuItem* parent = manager.GetItemById(parent_id); 188 ExtensionMenuItem* parent = manager.GetItemById(parent_id);
190 if (!parent) { 189 if (!parent) {
191 error_ = "Cannot find menu item with id " + 190 error_ = "Cannot find menu item with id " +
192 base::IntToString(parent_id.second); 191 base::IntToString(parent_id.uid);
193 return false; 192 return false;
194 } 193 }
195 if (parent->type() != ExtensionMenuItem::NORMAL) { 194 if (parent->type() != ExtensionMenuItem::NORMAL) {
196 error_ = kParentsMustBeNormalError; 195 error_ = kParentsMustBeNormalError;
197 return false; 196 return false;
198 } 197 }
199 *result = parent; 198 *result = parent;
200 return true; 199 return true;
201 } 200 }
202 201
203 bool CreateContextMenuFunction::RunImpl() { 202 bool CreateContextMenuFunction::RunImpl() {
204 DictionaryValue* properties; 203 DictionaryValue* properties;
205 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &properties)); 204 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &properties));
206 EXTENSION_FUNCTION_VALIDATE(properties != NULL); 205 EXTENSION_FUNCTION_VALIDATE(properties != NULL);
207 206
208 ExtensionMenuItem::Id id(extension_id(), 0); 207 ExtensionMenuItem::Id id(profile(), extension_id(), 0);
209 EXTENSION_FUNCTION_VALIDATE(properties->GetInteger(kGeneratedIdKey, 208 EXTENSION_FUNCTION_VALIDATE(properties->GetInteger(kGeneratedIdKey,
210 &id.second)); 209 &id.uid));
211 std::string title; 210 std::string title;
212 if (properties->HasKey(kTitleKey) && 211 if (properties->HasKey(kTitleKey) &&
213 !properties->GetString(kTitleKey, &title)) 212 !properties->GetString(kTitleKey, &title))
214 return false; 213 return false;
215 214
216 ExtensionMenuManager* menu_manager = 215 ExtensionMenuManager* menu_manager =
217 profile()->GetExtensionsService()->menu_manager(); 216 profile()->GetExtensionsService()->menu_manager();
218 217
219 ExtensionMenuItem::ContextList contexts(ExtensionMenuItem::PAGE); 218 ExtensionMenuItem::ContextList contexts(ExtensionMenuItem::PAGE);
220 if (!ParseContexts(*properties, kContextsKey, &contexts)) 219 if (!ParseContexts(*properties, kContextsKey, &contexts))
(...skipping 13 matching lines...) Expand all
234 return false; 233 return false;
235 234
236 scoped_ptr<ExtensionMenuItem> item( 235 scoped_ptr<ExtensionMenuItem> item(
237 new ExtensionMenuItem(id, title, checked, type, contexts)); 236 new ExtensionMenuItem(id, title, checked, type, contexts));
238 237
239 if (!SetURLPatterns(*properties, item.get())) 238 if (!SetURLPatterns(*properties, item.get()))
240 return false; 239 return false;
241 240
242 bool success = true; 241 bool success = true;
243 if (properties->HasKey(kParentIdKey)) { 242 if (properties->HasKey(kParentIdKey)) {
244 ExtensionMenuItem::Id parent_id(extension_id(), 0); 243 ExtensionMenuItem::Id parent_id(profile(), extension_id(), 0);
245 EXTENSION_FUNCTION_VALIDATE(properties->GetInteger(kParentIdKey, 244 EXTENSION_FUNCTION_VALIDATE(properties->GetInteger(kParentIdKey,
246 &parent_id.second)); 245 &parent_id.uid));
247 ExtensionMenuItem* parent = menu_manager->GetItemById(parent_id); 246 ExtensionMenuItem* parent = menu_manager->GetItemById(parent_id);
248 if (!parent) { 247 if (!parent) {
249 error_ = ExtensionErrorUtils::FormatErrorMessage( 248 error_ = ExtensionErrorUtils::FormatErrorMessage(
250 kCannotFindItemError, base::IntToString(parent_id.second)); 249 kCannotFindItemError, base::IntToString(parent_id.uid));
251 return false; 250 return false;
252 } 251 }
253 if (parent->type() != ExtensionMenuItem::NORMAL) { 252 if (parent->type() != ExtensionMenuItem::NORMAL) {
254 error_ = kParentsMustBeNormalError; 253 error_ = kParentsMustBeNormalError;
255 return false; 254 return false;
256 } 255 }
257 success = menu_manager->AddChildItem(parent_id, item.release()); 256 success = menu_manager->AddChildItem(parent_id, item.release());
258 } else { 257 } else {
259 success = menu_manager->AddContextItem(GetExtension(), item.release()); 258 success = menu_manager->AddContextItem(GetExtension(), item.release());
260 } 259 }
261 260
262 if (!success) 261 if (!success)
263 return false; 262 return false;
264 263
265 return true; 264 return true;
266 } 265 }
267 266
268 bool UpdateContextMenuFunction::RunImpl() { 267 bool UpdateContextMenuFunction::RunImpl() {
269 ExtensionMenuItem::Id item_id(extension_id(), 0); 268 ExtensionMenuItem::Id item_id(profile(), extension_id(), 0);
270 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &item_id.second)); 269 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &item_id.uid));
271 270
272 ExtensionsService* service = profile()->GetExtensionsService(); 271 ExtensionsService* service = profile()->GetExtensionsService();
273 ExtensionMenuManager* manager = service->menu_manager(); 272 ExtensionMenuManager* manager = service->menu_manager();
274 ExtensionMenuItem* item = manager->GetItemById(item_id); 273 ExtensionMenuItem* item = manager->GetItemById(item_id);
275 if (!item || item->extension_id() != extension_id()) { 274 if (!item || item->extension_id() != extension_id()) {
276 error_ = ExtensionErrorUtils::FormatErrorMessage( 275 error_ = ExtensionErrorUtils::FormatErrorMessage(
277 kCannotFindItemError, base::IntToString(item_id.second)); 276 kCannotFindItemError, base::IntToString(item_id.uid));
278 return false; 277 return false;
279 } 278 }
280 279
281 DictionaryValue *properties = NULL; 280 DictionaryValue *properties = NULL;
282 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &properties)); 281 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &properties));
283 EXTENSION_FUNCTION_VALIDATE(properties != NULL); 282 EXTENSION_FUNCTION_VALIDATE(properties != NULL);
284 283
285 ExtensionMenuManager* menu_manager = 284 ExtensionMenuManager* menu_manager =
286 profile()->GetExtensionsService()->menu_manager(); 285 profile()->GetExtensionsService()->menu_manager();
287 286
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 if (parent && !menu_manager->ChangeParent(item->id(), &parent->id())) 325 if (parent && !menu_manager->ChangeParent(item->id(), &parent->id()))
327 return false; 326 return false;
328 327
329 if (!SetURLPatterns(*properties, item)) 328 if (!SetURLPatterns(*properties, item))
330 return false; 329 return false;
331 330
332 return true; 331 return true;
333 } 332 }
334 333
335 bool RemoveContextMenuFunction::RunImpl() { 334 bool RemoveContextMenuFunction::RunImpl() {
336 ExtensionMenuItem::Id id(extension_id(), 0); 335 ExtensionMenuItem::Id id(profile(), extension_id(), 0);
337 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &id.second)); 336 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &id.uid));
338 ExtensionsService* service = profile()->GetExtensionsService(); 337 ExtensionsService* service = profile()->GetExtensionsService();
339 ExtensionMenuManager* manager = service->menu_manager(); 338 ExtensionMenuManager* manager = service->menu_manager();
340 339
341 ExtensionMenuItem* item = manager->GetItemById(id); 340 ExtensionMenuItem* item = manager->GetItemById(id);
342 // Ensure one extension can't remove another's menu items. 341 // Ensure one extension can't remove another's menu items.
343 if (!item || item->extension_id() != extension_id()) { 342 if (!item || item->extension_id() != extension_id()) {
344 error_ = ExtensionErrorUtils::FormatErrorMessage( 343 error_ = ExtensionErrorUtils::FormatErrorMessage(
345 kCannotFindItemError, base::IntToString(id.second)); 344 kCannotFindItemError, base::IntToString(id.uid));
346 return false; 345 return false;
347 } 346 }
348 347
349 return manager->RemoveContextMenuItem(id); 348 return manager->RemoveContextMenuItem(id);
350 } 349 }
351 350
352 bool RemoveAllContextMenusFunction::RunImpl() { 351 bool RemoveAllContextMenusFunction::RunImpl() {
353 ExtensionsService* service = profile()->GetExtensionsService(); 352 ExtensionsService* service = profile()->GetExtensionsService();
354 ExtensionMenuManager* manager = service->menu_manager(); 353 ExtensionMenuManager* manager = service->menu_manager();
355 manager->RemoveAllContextItems(extension_id()); 354 manager->RemoveAllContextItems(extension_id());
356 return true; 355 return true;
357 } 356 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_context_menu_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698