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

Side by Side Diff: chrome/browser/extensions/api/webview/webview_api.cc

Issue 186213003: <webview>: Context menu API implementation CL. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Put ExtensionKey into MenuItem::Id. 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/webview/webview_api.h" 5 #include "chrome/browser/extensions/api/webview/webview_api.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/extensions/api/browsing_data/browsing_data_api.h" 8 #include "chrome/browser/extensions/api/browsing_data/browsing_data_api.h"
9 #include "chrome/browser/extensions/api/context_menus/context_menus_api.h"
9 #include "chrome/browser/extensions/api/context_menus/context_menus_api_helpers. h" 10 #include "chrome/browser/extensions/api/context_menus/context_menus_api_helpers. h"
10 #include "chrome/browser/extensions/tab_helper.h" 11 #include "chrome/browser/extensions/tab_helper.h"
11 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/common/extensions/api/webview.h" 13 #include "chrome/common/extensions/api/webview.h"
13 #include "content/public/browser/render_process_host.h" 14 #include "content/public/browser/render_process_host.h"
14 #include "content/public/browser/render_view_host.h" 15 #include "content/public/browser/render_view_host.h"
15 #include "content/public/browser/storage_partition.h" 16 #include "content/public/browser/storage_partition.h"
16 #include "content/public/browser/web_contents.h" 17 #include "content/public/browser/web_contents.h"
17 #include "content/public/common/stop_find_action.h" 18 #include "content/public/common/stop_find_action.h"
18 #include "extensions/common/error_utils.h" 19 #include "extensions/common/error_utils.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 // TODO(lazyboy): Add checks similar to 60 // TODO(lazyboy): Add checks similar to
60 // WebviewExtensionFunction::RunImplSafe(WebViewGuest*). 61 // WebviewExtensionFunction::RunImplSafe(WebViewGuest*).
61 bool WebviewContextMenusCreateFunction::RunImpl() { 62 bool WebviewContextMenusCreateFunction::RunImpl() {
62 scoped_ptr<webview::ContextMenusCreate::Params> params( 63 scoped_ptr<webview::ContextMenusCreate::Params> params(
63 webview::ContextMenusCreate::Params::Create(*args_)); 64 webview::ContextMenusCreate::Params::Create(*args_));
64 EXTENSION_FUNCTION_VALIDATE(params.get()); 65 EXTENSION_FUNCTION_VALIDATE(params.get());
65 66
66 MenuItem::Id id( 67 MenuItem::Id id(
67 Profile::FromBrowserContext(browser_context())->IsOffTheRecord(), 68 Profile::FromBrowserContext(browser_context())->IsOffTheRecord(),
68 extension_id()); 69 extension_id());
70 id.extension_key.webview_instance_id = params->instance_id;
Fady Samuel 2014/03/05 17:54:10 MenuItem::Id should probably take in an ExtensionK
lazyboy 2014/03/05 18:27:59 Done.
lazyboy 2014/03/05 18:27:59 Done.
69 71
70 if (params->create_properties.id.get()) { 72 if (params->create_properties.id.get()) {
71 id.string_uid = *params->create_properties.id; 73 id.string_uid = *params->create_properties.id;
72 } else { 74 } else {
73 // The Generated Id is added by webview_custom_bindings.js. 75 // The Generated Id is added by webview_custom_bindings.js.
74 base::DictionaryValue* properties = NULL; 76 base::DictionaryValue* properties = NULL;
75 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &properties)); 77 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &properties));
76 EXTENSION_FUNCTION_VALIDATE( 78 EXTENSION_FUNCTION_VALIDATE(
77 properties->GetInteger(helpers::kGeneratedIdKey, &id.uid)); 79 properties->GetInteger(helpers::kGeneratedIdKey, &id.uid));
78 } 80 }
79 81
80 // TODO(lazyboy): Implement. 82 bool success = extensions::context_menus_api_helpers::CreateMenuItem(
81 SendResponse(false); 83 params->create_properties,
82 return false; 84 Profile::FromBrowserContext(browser_context()),
85 GetExtension(),
86 id,
87 &error_);
88
89 SendResponse(success);
90 return success;
83 } 91 }
84 92
85 bool WebviewContextMenusUpdateFunction::RunImpl() { 93 bool WebviewContextMenusUpdateFunction::RunImpl() {
86 scoped_ptr<webview::ContextMenusUpdate::Params> params( 94 scoped_ptr<webview::ContextMenusUpdate::Params> params(
87 webview::ContextMenusUpdate::Params::Create(*args_)); 95 webview::ContextMenusUpdate::Params::Create(*args_));
88 EXTENSION_FUNCTION_VALIDATE(params.get()); 96 EXTENSION_FUNCTION_VALIDATE(params.get());
89 97
90 Profile* profile = Profile::FromBrowserContext(browser_context()); 98 Profile* profile = Profile::FromBrowserContext(browser_context());
91 MenuItem::Id item_id(profile->IsOffTheRecord(), extension_id()); 99 MenuItem::Id item_id(profile->IsOffTheRecord(), extension_id());
Fady Samuel 2014/03/05 17:54:10 As above, MenuItem::Id should probably take in an
lazyboy 2014/03/05 18:27:59 Done.
100 item_id.extension_key.webview_instance_id = params->instance_id;
92 101
93 if (params->id.as_string) 102 if (params->id.as_string)
94 item_id.string_uid = *params->id.as_string; 103 item_id.string_uid = *params->id.as_string;
95 else if (params->id.as_integer) 104 else if (params->id.as_integer)
96 item_id.uid = *params->id.as_integer; 105 item_id.uid = *params->id.as_integer;
97 else 106 else
98 NOTREACHED(); 107 NOTREACHED();
99 108
100 // TODO(lazyboy): Implement. 109 bool success = extensions::context_menus_api_helpers::UpdateMenuItem(
101 SendResponse(false); 110 params->update_properties, profile, GetExtension(), item_id, &error_);
102 return false; 111 SendResponse(success);
112 return success;
103 } 113 }
104 114
105 bool WebviewContextMenusRemoveFunction::RunImpl() { 115 bool WebviewContextMenusRemoveFunction::RunImpl() {
106 scoped_ptr<webview::ContextMenusRemove::Params> params( 116 scoped_ptr<webview::ContextMenusRemove::Params> params(
107 webview::ContextMenusRemove::Params::Create(*args_)); 117 webview::ContextMenusRemove::Params::Create(*args_));
108 EXTENSION_FUNCTION_VALIDATE(params.get()); 118 EXTENSION_FUNCTION_VALIDATE(params.get());
109 119
110 // TODO(lazyboy): Implement. 120 MenuManager* menu_manager =
111 SendResponse(false); 121 MenuManager::Get(Profile::FromBrowserContext(browser_context()));
112 return false; 122
123 MenuItem::Id id(
124 Profile::FromBrowserContext(browser_context())->IsOffTheRecord(),
125 extension_id());
Fady Samuel 2014/03/05 17:54:10 As above, MenuItem::Id should probably take in an
lazyboy 2014/03/05 18:27:59 Done.
lazyboy 2014/03/05 18:27:59 Done.
126 id.extension_key.webview_instance_id = params->instance_id;
127
128 if (params->menu_item_id.as_string) {
129 id.string_uid = *params->menu_item_id.as_string;
130 } else if (params->menu_item_id.as_integer) {
131 id.uid = *params->menu_item_id.as_integer;
132 } else {
133 NOTREACHED();
134 }
135
136 bool success = true;
137 MenuItem* item = menu_manager->GetItemById(id);
138 // Ensure one extension can't remove another's menu items.
139 if (!item || item->extension_id() != extension_id()) {
Fady Samuel 2014/03/05 17:54:10 If item->extension() != extension_id() then we hav
lazyboy 2014/03/05 18:27:59 This is code from context_menus_api.cc and it was
140 error_ = ErrorUtils::FormatErrorMessage(
141 context_menus_api_helpers::kCannotFindItemError,
142 context_menus_api_helpers::GetIDString(id));
143 success = false;
144 } else if (!menu_manager->RemoveContextMenuItem(id)) {
145 success = false;
146 }
147
148 SendResponse(success);
149 return success;
113 } 150 }
114 151
115 bool WebviewContextMenusRemoveAllFunction::RunImpl() { 152 bool WebviewContextMenusRemoveAllFunction::RunImpl() {
116 scoped_ptr<webview::ContextMenusRemoveAll::Params> params( 153 scoped_ptr<webview::ContextMenusRemoveAll::Params> params(
117 webview::ContextMenusRemoveAll::Params::Create(*args_)); 154 webview::ContextMenusRemoveAll::Params::Create(*args_));
118 EXTENSION_FUNCTION_VALIDATE(params.get()); 155 EXTENSION_FUNCTION_VALIDATE(params.get());
119 156
120 // TODO(lazyboy): Implement. 157 MenuManager* menu_manager =
121 SendResponse(false); 158 MenuManager::Get(Profile::FromBrowserContext(browser_context()));
122 return false; 159
160 int webview_instance_id = params->instance_id;
161 menu_manager->RemoveAllContextItems(
162 MenuItem::ExtensionKey(GetExtension()->id(), webview_instance_id));
163 SendResponse(true);
164 return true;
123 } 165 }
124 166
125 WebviewClearDataFunction::WebviewClearDataFunction() 167 WebviewClearDataFunction::WebviewClearDataFunction()
126 : remove_mask_(0), bad_message_(false) {} 168 : remove_mask_(0), bad_message_(false) {}
127 169
128 WebviewClearDataFunction::~WebviewClearDataFunction() {} 170 WebviewClearDataFunction::~WebviewClearDataFunction() {}
129 171
130 // Parses the |dataToRemove| argument to generate the remove mask. Sets 172 // Parses the |dataToRemove| argument to generate the remove mask. Sets
131 // |bad_message_| (like EXTENSION_FUNCTION_VALIDATE would if this were a bool 173 // |bad_message_| (like EXTENSION_FUNCTION_VALIDATE would if this were a bool
132 // method) if 'dataToRemove' is not present. 174 // method) if 'dataToRemove' is not present.
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 529
488 WebviewTerminateFunction::~WebviewTerminateFunction() { 530 WebviewTerminateFunction::~WebviewTerminateFunction() {
489 } 531 }
490 532
491 bool WebviewTerminateFunction::RunImplSafe(WebViewGuest* guest) { 533 bool WebviewTerminateFunction::RunImplSafe(WebViewGuest* guest) {
492 guest->Terminate(); 534 guest->Terminate();
493 return true; 535 return true;
494 } 536 }
495 537
496 } // namespace extensions 538 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698