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

Side by Side Diff: chrome/browser/extensions/api/context_menus/context_menus_api.cc

Issue 186213003: <webview>: Context menu API implementation CL. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sync @tott Created 6 years, 9 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
OLDNEW
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 #include "chrome/browser/extensions/api/context_menus/context_menus_api.h" 5 #include "chrome/browser/extensions/api/context_menus/context_menus_api.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 15 matching lines...) Expand all
26 26
27 } // namespace 27 } // namespace
28 28
29 namespace extensions { 29 namespace extensions {
30 30
31 namespace Create = api::context_menus::Create; 31 namespace Create = api::context_menus::Create;
32 namespace Remove = api::context_menus::Remove; 32 namespace Remove = api::context_menus::Remove;
33 namespace Update = api::context_menus::Update; 33 namespace Update = api::context_menus::Update;
34 34
35 bool ContextMenusCreateFunction::RunImpl() { 35 bool ContextMenusCreateFunction::RunImpl() {
36 MenuItem::Id id(GetProfile()->IsOffTheRecord(), extension_id()); 36 MenuItem::Id id(GetProfile()->IsOffTheRecord(),
37 MenuItem::ExtensionKey(extension_id()));
37 scoped_ptr<Create::Params> params(Create::Params::Create(*args_)); 38 scoped_ptr<Create::Params> params(Create::Params::Create(*args_));
38 EXTENSION_FUNCTION_VALIDATE(params.get()); 39 EXTENSION_FUNCTION_VALIDATE(params.get());
39 40
40 if (params->create_properties.id.get()) { 41 if (params->create_properties.id.get()) {
41 id.string_uid = *params->create_properties.id; 42 id.string_uid = *params->create_properties.id;
42 } else { 43 } else {
43 if (BackgroundInfo::HasLazyBackgroundPage(GetExtension())) { 44 if (BackgroundInfo::HasLazyBackgroundPage(GetExtension())) {
44 error_ = kIdRequiredError; 45 error_ = kIdRequiredError;
45 return false; 46 return false;
46 } 47 }
47 48
48 // The Generated Id is added by context_menus_custom_bindings.js. 49 // The Generated Id is added by context_menus_custom_bindings.js.
49 base::DictionaryValue* properties = NULL; 50 base::DictionaryValue* properties = NULL;
50 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &properties)); 51 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &properties));
51 EXTENSION_FUNCTION_VALIDATE( 52 EXTENSION_FUNCTION_VALIDATE(
52 properties->GetInteger(helpers::kGeneratedIdKey, &id.uid)); 53 properties->GetInteger(helpers::kGeneratedIdKey, &id.uid));
53 } 54 }
54 55
55 return helpers::CreateMenuItem(params->create_properties, GetProfile(), 56 return helpers::CreateMenuItem(params->create_properties, GetProfile(),
56 GetExtension(), id, &error_); 57 GetExtension(), id, &error_);
57 } 58 }
58 59
59 bool ContextMenusUpdateFunction::RunImpl() { 60 bool ContextMenusUpdateFunction::RunImpl() {
60 MenuItem::Id item_id(GetProfile()->IsOffTheRecord(), extension_id()); 61 MenuItem::Id item_id(GetProfile()->IsOffTheRecord(),
62 MenuItem::ExtensionKey(extension_id()));
61 scoped_ptr<Update::Params> params(Update::Params::Create(*args_)); 63 scoped_ptr<Update::Params> params(Update::Params::Create(*args_));
62 64
63 EXTENSION_FUNCTION_VALIDATE(params.get()); 65 EXTENSION_FUNCTION_VALIDATE(params.get());
64 if (params->id.as_string) 66 if (params->id.as_string)
65 item_id.string_uid = *params->id.as_string; 67 item_id.string_uid = *params->id.as_string;
66 else if (params->id.as_integer) 68 else if (params->id.as_integer)
67 item_id.uid = *params->id.as_integer; 69 item_id.uid = *params->id.as_integer;
68 else 70 else
69 NOTREACHED(); 71 NOTREACHED();
70 72
71 return helpers::UpdateMenuItem(params->update_properties, GetProfile(), 73 return helpers::UpdateMenuItem(params->update_properties, GetProfile(),
72 GetExtension(), item_id, &error_); 74 GetExtension(), item_id, &error_);
73 } 75 }
74 76
75 bool ContextMenusRemoveFunction::RunImpl() { 77 bool ContextMenusRemoveFunction::RunImpl() {
76 scoped_ptr<Remove::Params> params(Remove::Params::Create(*args_)); 78 scoped_ptr<Remove::Params> params(Remove::Params::Create(*args_));
77 EXTENSION_FUNCTION_VALIDATE(params.get()); 79 EXTENSION_FUNCTION_VALIDATE(params.get());
78 80
79 MenuManager* manager = MenuManager::Get(GetProfile()); 81 MenuManager* manager = MenuManager::Get(GetProfile());
80 82
81 MenuItem::Id id(GetProfile()->IsOffTheRecord(), extension_id()); 83 MenuItem::Id id(GetProfile()->IsOffTheRecord(),
84 MenuItem::ExtensionKey(extension_id()));
82 if (params->menu_item_id.as_string) 85 if (params->menu_item_id.as_string)
83 id.string_uid = *params->menu_item_id.as_string; 86 id.string_uid = *params->menu_item_id.as_string;
84 else if (params->menu_item_id.as_integer) 87 else if (params->menu_item_id.as_integer)
85 id.uid = *params->menu_item_id.as_integer; 88 id.uid = *params->menu_item_id.as_integer;
86 else 89 else
87 NOTREACHED(); 90 NOTREACHED();
88 91
89 MenuItem* item = manager->GetItemById(id); 92 MenuItem* item = manager->GetItemById(id);
90 // Ensure one extension can't remove another's menu items. 93 // Ensure one extension can't remove another's menu items.
91 if (!item || item->extension_id() != extension_id()) { 94 if (!item || item->extension_id() != extension_id()) {
92 error_ = ErrorUtils::FormatErrorMessage( 95 error_ = ErrorUtils::FormatErrorMessage(
93 helpers::kCannotFindItemError, helpers::GetIDString(id)); 96 helpers::kCannotFindItemError, helpers::GetIDString(id));
94 return false; 97 return false;
95 } 98 }
96 99
97 if (!manager->RemoveContextMenuItem(id)) 100 if (!manager->RemoveContextMenuItem(id))
98 return false; 101 return false;
99 manager->WriteToStorage(GetExtension()); 102 manager->WriteToStorage(GetExtension(), id.extension_key);
100 return true; 103 return true;
101 } 104 }
102 105
103 bool ContextMenusRemoveAllFunction::RunImpl() { 106 bool ContextMenusRemoveAllFunction::RunImpl() {
104 MenuManager* manager = MenuManager::Get(GetProfile()); 107 MenuManager* manager = MenuManager::Get(GetProfile());
105 manager->RemoveAllContextItems(GetExtension()->id()); 108 manager->RemoveAllContextItems(MenuItem::ExtensionKey(GetExtension()->id()));
106 manager->WriteToStorage(GetExtension()); 109 manager->WriteToStorage(GetExtension(),
110 MenuItem::ExtensionKey(GetExtension()->id()));
107 return true; 111 return true;
108 } 112 }
109 113
110 } // namespace extensions 114 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/apps/web_view_browsertest.cc ('k') | chrome/browser/extensions/api/context_menus/context_menus_api_helpers.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698