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

Side by Side Diff: chrome/browser/extensions/api/web_view/chrome_web_view_internal_api.cc

Issue 1181263007: WebView context menu cleanup. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added comment. Created 5 years, 5 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 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 #include "chrome/browser/extensions/api/web_view/chrome_web_view_internal_api.h" 5 #include "chrome/browser/extensions/api/web_view/chrome_web_view_internal_api.h"
6 6
7 #include "chrome/browser/extensions/api/context_menus/context_menus_api.h" 7 #include "chrome/browser/extensions/api/context_menus/context_menus_api.h"
8 #include "chrome/browser/extensions/api/context_menus/context_menus_api_helpers. h" 8 #include "chrome/browser/extensions/api/context_menus/context_menus_api_helpers. h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/common/extensions/api/chrome_web_view_internal.h" 10 #include "chrome/common/extensions/api/chrome_web_view_internal.h"
11 #include "content/public/browser/render_process_host.h"
11 #include "extensions/common/error_utils.h" 12 #include "extensions/common/error_utils.h"
12 13
13 namespace helpers = extensions::context_menus_api_helpers; 14 namespace helpers = extensions::context_menus_api_helpers;
14 namespace webview = extensions::api::chrome_web_view_internal; 15 namespace webview = extensions::api::chrome_web_view_internal;
15 16
16 namespace extensions { 17 namespace extensions {
17 18
18 // TODO(lazyboy): Add checks similar to 19 // TODO(lazyboy): Add checks similar to
19 // WebViewInternalExtensionFunction::RunAsyncSafe(WebViewGuest*). 20 // WebViewInternalExtensionFunction::RunAsyncSafe(WebViewGuest*).
20 bool ChromeWebViewInternalContextMenusCreateFunction::RunAsync() { 21 bool ChromeWebViewInternalContextMenusCreateFunction::RunAsync() {
21 scoped_ptr<webview::ContextMenusCreate::Params> params( 22 scoped_ptr<webview::ContextMenusCreate::Params> params(
22 webview::ContextMenusCreate::Params::Create(*args_)); 23 webview::ContextMenusCreate::Params::Create(*args_));
23 EXTENSION_FUNCTION_VALIDATE(params.get()); 24 EXTENSION_FUNCTION_VALIDATE(params.get());
24 25
25 MenuItem::Id id( 26 MenuItem::Id id(
26 Profile::FromBrowserContext(browser_context())->IsOffTheRecord(), 27 Profile::FromBrowserContext(browser_context())->IsOffTheRecord(),
27 MenuItem::ExtensionKey(extension_id(), params->instance_id)); 28 MenuItem::ExtensionKey(
29 extension_id(),
30 GetSenderWebContents()->GetRenderProcessHost()->GetID(),
31 params->instance_id));
28 32
29 if (params->create_properties.id.get()) { 33 if (params->create_properties.id.get()) {
30 id.string_uid = *params->create_properties.id; 34 id.string_uid = *params->create_properties.id;
31 } else { 35 } else {
32 // The Generated Id is added by web_view_internal_custom_bindings.js. 36 // The Generated Id is added by web_view_internal_custom_bindings.js.
33 base::DictionaryValue* properties = NULL; 37 base::DictionaryValue* properties = NULL;
34 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &properties)); 38 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &properties));
35 EXTENSION_FUNCTION_VALIDATE( 39 EXTENSION_FUNCTION_VALIDATE(
36 properties->GetInteger(helpers::kGeneratedIdKey, &id.uid)); 40 properties->GetInteger(helpers::kGeneratedIdKey, &id.uid));
37 } 41 }
(...skipping 10 matching lines...) Expand all
48 } 52 }
49 53
50 bool ChromeWebViewInternalContextMenusUpdateFunction::RunAsync() { 54 bool ChromeWebViewInternalContextMenusUpdateFunction::RunAsync() {
51 scoped_ptr<webview::ContextMenusUpdate::Params> params( 55 scoped_ptr<webview::ContextMenusUpdate::Params> params(
52 webview::ContextMenusUpdate::Params::Create(*args_)); 56 webview::ContextMenusUpdate::Params::Create(*args_));
53 EXTENSION_FUNCTION_VALIDATE(params.get()); 57 EXTENSION_FUNCTION_VALIDATE(params.get());
54 58
55 Profile* profile = Profile::FromBrowserContext(browser_context()); 59 Profile* profile = Profile::FromBrowserContext(browser_context());
56 MenuItem::Id item_id( 60 MenuItem::Id item_id(
57 profile->IsOffTheRecord(), 61 profile->IsOffTheRecord(),
58 MenuItem::ExtensionKey(extension_id(), params->instance_id)); 62 MenuItem::ExtensionKey(
63 extension_id(),
64 GetSenderWebContents()->GetRenderProcessHost()->GetID(),
65 params->instance_id));
59 66
60 if (params->id.as_string) 67 if (params->id.as_string)
61 item_id.string_uid = *params->id.as_string; 68 item_id.string_uid = *params->id.as_string;
62 else if (params->id.as_integer) 69 else if (params->id.as_integer)
63 item_id.uid = *params->id.as_integer; 70 item_id.uid = *params->id.as_integer;
64 else 71 else
65 NOTREACHED(); 72 NOTREACHED();
66 73
67 bool success = extensions::context_menus_api_helpers::UpdateMenuItem( 74 bool success = extensions::context_menus_api_helpers::UpdateMenuItem(
68 params->update_properties, profile, extension(), item_id, &error_); 75 params->update_properties, profile, extension(), item_id, &error_);
69 SendResponse(success); 76 SendResponse(success);
70 return success; 77 return success;
71 } 78 }
72 79
73 bool ChromeWebViewInternalContextMenusRemoveFunction::RunAsync() { 80 bool ChromeWebViewInternalContextMenusRemoveFunction::RunAsync() {
74 scoped_ptr<webview::ContextMenusRemove::Params> params( 81 scoped_ptr<webview::ContextMenusRemove::Params> params(
75 webview::ContextMenusRemove::Params::Create(*args_)); 82 webview::ContextMenusRemove::Params::Create(*args_));
76 EXTENSION_FUNCTION_VALIDATE(params.get()); 83 EXTENSION_FUNCTION_VALIDATE(params.get());
77 84
78 MenuManager* menu_manager = 85 MenuManager* menu_manager =
79 MenuManager::Get(Profile::FromBrowserContext(browser_context())); 86 MenuManager::Get(Profile::FromBrowserContext(browser_context()));
80 87
81 MenuItem::Id id( 88 MenuItem::Id id(
82 Profile::FromBrowserContext(browser_context())->IsOffTheRecord(), 89 Profile::FromBrowserContext(browser_context())->IsOffTheRecord(),
83 MenuItem::ExtensionKey(extension_id(), params->instance_id)); 90 MenuItem::ExtensionKey(
91 extension_id(),
92 GetSenderWebContents()->GetRenderProcessHost()->GetID(),
93 params->instance_id));
84 94
85 if (params->menu_item_id.as_string) { 95 if (params->menu_item_id.as_string) {
86 id.string_uid = *params->menu_item_id.as_string; 96 id.string_uid = *params->menu_item_id.as_string;
87 } else if (params->menu_item_id.as_integer) { 97 } else if (params->menu_item_id.as_integer) {
88 id.uid = *params->menu_item_id.as_integer; 98 id.uid = *params->menu_item_id.as_integer;
89 } else { 99 } else {
90 NOTREACHED(); 100 NOTREACHED();
91 } 101 }
92 102
93 bool success = true; 103 bool success = true;
(...skipping 12 matching lines...) Expand all
106 return success; 116 return success;
107 } 117 }
108 118
109 bool ChromeWebViewInternalContextMenusRemoveAllFunction::RunAsync() { 119 bool ChromeWebViewInternalContextMenusRemoveAllFunction::RunAsync() {
110 scoped_ptr<webview::ContextMenusRemoveAll::Params> params( 120 scoped_ptr<webview::ContextMenusRemoveAll::Params> params(
111 webview::ContextMenusRemoveAll::Params::Create(*args_)); 121 webview::ContextMenusRemoveAll::Params::Create(*args_));
112 EXTENSION_FUNCTION_VALIDATE(params.get()); 122 EXTENSION_FUNCTION_VALIDATE(params.get());
113 123
114 MenuManager* menu_manager = 124 MenuManager* menu_manager =
115 MenuManager::Get(Profile::FromBrowserContext(browser_context())); 125 MenuManager::Get(Profile::FromBrowserContext(browser_context()));
126 menu_manager->RemoveAllContextItems(MenuItem::ExtensionKey(
127 extension_id(),
128 GetSenderWebContents()->GetRenderProcessHost()->GetID(),
129 params->instance_id));
116 130
117 int webview_instance_id = params->instance_id;
118 menu_manager->RemoveAllContextItems(
119 MenuItem::ExtensionKey(extension()->id(), webview_instance_id));
120 SendResponse(true); 131 SendResponse(true);
121 return true; 132 return true;
122 } 133 }
123 134
124 ChromeWebViewInternalShowContextMenuFunction:: 135 ChromeWebViewInternalShowContextMenuFunction::
125 ChromeWebViewInternalShowContextMenuFunction() { 136 ChromeWebViewInternalShowContextMenuFunction() {
126 } 137 }
127 138
128 ChromeWebViewInternalShowContextMenuFunction:: 139 ChromeWebViewInternalShowContextMenuFunction::
129 ~ChromeWebViewInternalShowContextMenuFunction() { 140 ~ChromeWebViewInternalShowContextMenuFunction() {
130 } 141 }
131 142
132 bool ChromeWebViewInternalShowContextMenuFunction::RunAsyncSafe( 143 bool ChromeWebViewInternalShowContextMenuFunction::RunAsyncSafe(
133 WebViewGuest* guest) { 144 WebViewGuest* guest) {
134 scoped_ptr<webview::ShowContextMenu::Params> params( 145 scoped_ptr<webview::ShowContextMenu::Params> params(
135 webview::ShowContextMenu::Params::Create(*args_)); 146 webview::ShowContextMenu::Params::Create(*args_));
136 EXTENSION_FUNCTION_VALIDATE(params.get()); 147 EXTENSION_FUNCTION_VALIDATE(params.get());
137 148
138 // TODO(lazyboy): Actually implement filtering menu items, we pass NULL for 149 // TODO(lazyboy): Actually implement filtering menu items, we pass NULL for
139 // now. 150 // now.
140 guest->ShowContextMenu(params->request_id, NULL); 151 guest->ShowContextMenu(params->request_id, NULL);
141 152
142 SendResponse(true); 153 SendResponse(true);
143 return true; 154 return true;
144 } 155 }
145 156
146 } // namespace extensions 157 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/apps/guest_view/web_view_browsertest.cc ('k') | chrome/browser/extensions/chrome_extensions_browser_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698