OLD | NEW |
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 "content/public/browser/render_process_host.h" |
12 #include "extensions/common/error_utils.h" | 12 #include "extensions/common/error_utils.h" |
13 | 13 |
14 namespace helpers = extensions::context_menus_api_helpers; | 14 namespace helpers = extensions::context_menus_api_helpers; |
15 namespace webview = extensions::api::chrome_web_view_internal; | 15 namespace webview = extensions::api::chrome_web_view_internal; |
16 | 16 |
17 namespace extensions { | 17 namespace extensions { |
18 | 18 |
19 // TODO(lazyboy): Add checks similar to | 19 // TODO(lazyboy): Add checks similar to |
20 // WebViewInternalExtensionFunction::RunAsyncSafe(WebViewGuest*). | 20 // WebViewInternalExtensionFunction::RunAsyncSafe(WebViewGuest*). |
21 bool ChromeWebViewInternalContextMenusCreateFunction::RunAsync() { | 21 bool ChromeWebViewInternalContextMenusCreateFunction::RunAsync() { |
22 scoped_ptr<webview::ContextMenusCreate::Params> params( | 22 std::unique_ptr<webview::ContextMenusCreate::Params> params( |
23 webview::ContextMenusCreate::Params::Create(*args_)); | 23 webview::ContextMenusCreate::Params::Create(*args_)); |
24 EXTENSION_FUNCTION_VALIDATE(params.get()); | 24 EXTENSION_FUNCTION_VALIDATE(params.get()); |
25 | 25 |
26 MenuItem::Id id( | 26 MenuItem::Id id( |
27 Profile::FromBrowserContext(browser_context())->IsOffTheRecord(), | 27 Profile::FromBrowserContext(browser_context())->IsOffTheRecord(), |
28 MenuItem::ExtensionKey( | 28 MenuItem::ExtensionKey( |
29 extension_id(), | 29 extension_id(), |
30 GetSenderWebContents()->GetRenderProcessHost()->GetID(), | 30 GetSenderWebContents()->GetRenderProcessHost()->GetID(), |
31 params->instance_id)); | 31 params->instance_id)); |
32 | 32 |
(...skipping 12 matching lines...) Expand all Loading... |
45 Profile::FromBrowserContext(browser_context()), | 45 Profile::FromBrowserContext(browser_context()), |
46 extension(), | 46 extension(), |
47 id, | 47 id, |
48 &error_); | 48 &error_); |
49 | 49 |
50 SendResponse(success); | 50 SendResponse(success); |
51 return success; | 51 return success; |
52 } | 52 } |
53 | 53 |
54 bool ChromeWebViewInternalContextMenusUpdateFunction::RunAsync() { | 54 bool ChromeWebViewInternalContextMenusUpdateFunction::RunAsync() { |
55 scoped_ptr<webview::ContextMenusUpdate::Params> params( | 55 std::unique_ptr<webview::ContextMenusUpdate::Params> params( |
56 webview::ContextMenusUpdate::Params::Create(*args_)); | 56 webview::ContextMenusUpdate::Params::Create(*args_)); |
57 EXTENSION_FUNCTION_VALIDATE(params.get()); | 57 EXTENSION_FUNCTION_VALIDATE(params.get()); |
58 | 58 |
59 Profile* profile = Profile::FromBrowserContext(browser_context()); | 59 Profile* profile = Profile::FromBrowserContext(browser_context()); |
60 MenuItem::Id item_id( | 60 MenuItem::Id item_id( |
61 profile->IsOffTheRecord(), | 61 profile->IsOffTheRecord(), |
62 MenuItem::ExtensionKey( | 62 MenuItem::ExtensionKey( |
63 extension_id(), | 63 extension_id(), |
64 GetSenderWebContents()->GetRenderProcessHost()->GetID(), | 64 GetSenderWebContents()->GetRenderProcessHost()->GetID(), |
65 params->instance_id)); | 65 params->instance_id)); |
66 | 66 |
67 if (params->id.as_string) | 67 if (params->id.as_string) |
68 item_id.string_uid = *params->id.as_string; | 68 item_id.string_uid = *params->id.as_string; |
69 else if (params->id.as_integer) | 69 else if (params->id.as_integer) |
70 item_id.uid = *params->id.as_integer; | 70 item_id.uid = *params->id.as_integer; |
71 else | 71 else |
72 NOTREACHED(); | 72 NOTREACHED(); |
73 | 73 |
74 bool success = extensions::context_menus_api_helpers::UpdateMenuItem( | 74 bool success = extensions::context_menus_api_helpers::UpdateMenuItem( |
75 params->update_properties, profile, extension(), item_id, &error_); | 75 params->update_properties, profile, extension(), item_id, &error_); |
76 SendResponse(success); | 76 SendResponse(success); |
77 return success; | 77 return success; |
78 } | 78 } |
79 | 79 |
80 bool ChromeWebViewInternalContextMenusRemoveFunction::RunAsync() { | 80 bool ChromeWebViewInternalContextMenusRemoveFunction::RunAsync() { |
81 scoped_ptr<webview::ContextMenusRemove::Params> params( | 81 std::unique_ptr<webview::ContextMenusRemove::Params> params( |
82 webview::ContextMenusRemove::Params::Create(*args_)); | 82 webview::ContextMenusRemove::Params::Create(*args_)); |
83 EXTENSION_FUNCTION_VALIDATE(params.get()); | 83 EXTENSION_FUNCTION_VALIDATE(params.get()); |
84 | 84 |
85 MenuManager* menu_manager = | 85 MenuManager* menu_manager = |
86 MenuManager::Get(Profile::FromBrowserContext(browser_context())); | 86 MenuManager::Get(Profile::FromBrowserContext(browser_context())); |
87 | 87 |
88 MenuItem::Id id( | 88 MenuItem::Id id( |
89 Profile::FromBrowserContext(browser_context())->IsOffTheRecord(), | 89 Profile::FromBrowserContext(browser_context())->IsOffTheRecord(), |
90 MenuItem::ExtensionKey( | 90 MenuItem::ExtensionKey( |
91 extension_id(), | 91 extension_id(), |
(...skipping 18 matching lines...) Expand all Loading... |
110 success = false; | 110 success = false; |
111 } else if (!menu_manager->RemoveContextMenuItem(id)) { | 111 } else if (!menu_manager->RemoveContextMenuItem(id)) { |
112 success = false; | 112 success = false; |
113 } | 113 } |
114 | 114 |
115 SendResponse(success); | 115 SendResponse(success); |
116 return success; | 116 return success; |
117 } | 117 } |
118 | 118 |
119 bool ChromeWebViewInternalContextMenusRemoveAllFunction::RunAsync() { | 119 bool ChromeWebViewInternalContextMenusRemoveAllFunction::RunAsync() { |
120 scoped_ptr<webview::ContextMenusRemoveAll::Params> params( | 120 std::unique_ptr<webview::ContextMenusRemoveAll::Params> params( |
121 webview::ContextMenusRemoveAll::Params::Create(*args_)); | 121 webview::ContextMenusRemoveAll::Params::Create(*args_)); |
122 EXTENSION_FUNCTION_VALIDATE(params.get()); | 122 EXTENSION_FUNCTION_VALIDATE(params.get()); |
123 | 123 |
124 MenuManager* menu_manager = | 124 MenuManager* menu_manager = |
125 MenuManager::Get(Profile::FromBrowserContext(browser_context())); | 125 MenuManager::Get(Profile::FromBrowserContext(browser_context())); |
126 menu_manager->RemoveAllContextItems(MenuItem::ExtensionKey( | 126 menu_manager->RemoveAllContextItems(MenuItem::ExtensionKey( |
127 extension_id(), | 127 extension_id(), |
128 GetSenderWebContents()->GetRenderProcessHost()->GetID(), | 128 GetSenderWebContents()->GetRenderProcessHost()->GetID(), |
129 params->instance_id)); | 129 params->instance_id)); |
130 | 130 |
131 SendResponse(true); | 131 SendResponse(true); |
132 return true; | 132 return true; |
133 } | 133 } |
134 | 134 |
135 ChromeWebViewInternalShowContextMenuFunction:: | 135 ChromeWebViewInternalShowContextMenuFunction:: |
136 ChromeWebViewInternalShowContextMenuFunction() { | 136 ChromeWebViewInternalShowContextMenuFunction() { |
137 } | 137 } |
138 | 138 |
139 ChromeWebViewInternalShowContextMenuFunction:: | 139 ChromeWebViewInternalShowContextMenuFunction:: |
140 ~ChromeWebViewInternalShowContextMenuFunction() { | 140 ~ChromeWebViewInternalShowContextMenuFunction() { |
141 } | 141 } |
142 | 142 |
143 bool ChromeWebViewInternalShowContextMenuFunction::RunAsyncSafe( | 143 bool ChromeWebViewInternalShowContextMenuFunction::RunAsyncSafe( |
144 WebViewGuest* guest) { | 144 WebViewGuest* guest) { |
145 scoped_ptr<webview::ShowContextMenu::Params> params( | 145 std::unique_ptr<webview::ShowContextMenu::Params> params( |
146 webview::ShowContextMenu::Params::Create(*args_)); | 146 webview::ShowContextMenu::Params::Create(*args_)); |
147 EXTENSION_FUNCTION_VALIDATE(params.get()); | 147 EXTENSION_FUNCTION_VALIDATE(params.get()); |
148 | 148 |
149 // TODO(lazyboy): Actually implement filtering menu items. | 149 // TODO(lazyboy): Actually implement filtering menu items. |
150 guest->ShowContextMenu(params->request_id); | 150 guest->ShowContextMenu(params->request_id); |
151 | 151 |
152 SendResponse(true); | 152 SendResponse(true); |
153 return true; | 153 return true; |
154 } | 154 } |
155 | 155 |
156 } // namespace extensions | 156 } // namespace extensions |
OLD | NEW |