| 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 "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 GetSenderWebContents()->GetRenderProcessHost()->GetID(), |
| 30 params->instance_id)); |
| 28 | 31 |
| 29 if (params->create_properties.id.get()) { | 32 if (params->create_properties.id.get()) { |
| 30 id.string_uid = *params->create_properties.id; | 33 id.string_uid = *params->create_properties.id; |
| 31 } else { | 34 } else { |
| 32 // The Generated Id is added by web_view_internal_custom_bindings.js. | 35 // The Generated Id is added by web_view_internal_custom_bindings.js. |
| 33 base::DictionaryValue* properties = NULL; | 36 base::DictionaryValue* properties = NULL; |
| 34 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &properties)); | 37 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &properties)); |
| 35 EXTENSION_FUNCTION_VALIDATE( | 38 EXTENSION_FUNCTION_VALIDATE( |
| 36 properties->GetInteger(helpers::kGeneratedIdKey, &id.uid)); | 39 properties->GetInteger(helpers::kGeneratedIdKey, &id.uid)); |
| 37 } | 40 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 48 } | 51 } |
| 49 | 52 |
| 50 bool ChromeWebViewInternalContextMenusUpdateFunction::RunAsync() { | 53 bool ChromeWebViewInternalContextMenusUpdateFunction::RunAsync() { |
| 51 scoped_ptr<webview::ContextMenusUpdate::Params> params( | 54 scoped_ptr<webview::ContextMenusUpdate::Params> params( |
| 52 webview::ContextMenusUpdate::Params::Create(*args_)); | 55 webview::ContextMenusUpdate::Params::Create(*args_)); |
| 53 EXTENSION_FUNCTION_VALIDATE(params.get()); | 56 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 54 | 57 |
| 55 Profile* profile = Profile::FromBrowserContext(browser_context()); | 58 Profile* profile = Profile::FromBrowserContext(browser_context()); |
| 56 MenuItem::Id item_id( | 59 MenuItem::Id item_id( |
| 57 profile->IsOffTheRecord(), | 60 profile->IsOffTheRecord(), |
| 58 MenuItem::ExtensionKey(extension_id(), params->instance_id)); | 61 MenuItem::ExtensionKey( |
| 62 GetSenderWebContents()->GetRenderProcessHost()->GetID(), |
| 63 params->instance_id)); |
| 59 | 64 |
| 60 if (params->id.as_string) | 65 if (params->id.as_string) |
| 61 item_id.string_uid = *params->id.as_string; | 66 item_id.string_uid = *params->id.as_string; |
| 62 else if (params->id.as_integer) | 67 else if (params->id.as_integer) |
| 63 item_id.uid = *params->id.as_integer; | 68 item_id.uid = *params->id.as_integer; |
| 64 else | 69 else |
| 65 NOTREACHED(); | 70 NOTREACHED(); |
| 66 | 71 |
| 67 bool success = extensions::context_menus_api_helpers::UpdateMenuItem( | 72 bool success = extensions::context_menus_api_helpers::UpdateMenuItem( |
| 68 params->update_properties, profile, extension(), item_id, &error_); | 73 params->update_properties, profile, extension(), item_id, &error_); |
| 69 SendResponse(success); | 74 SendResponse(success); |
| 70 return success; | 75 return success; |
| 71 } | 76 } |
| 72 | 77 |
| 73 bool ChromeWebViewInternalContextMenusRemoveFunction::RunAsync() { | 78 bool ChromeWebViewInternalContextMenusRemoveFunction::RunAsync() { |
| 74 scoped_ptr<webview::ContextMenusRemove::Params> params( | 79 scoped_ptr<webview::ContextMenusRemove::Params> params( |
| 75 webview::ContextMenusRemove::Params::Create(*args_)); | 80 webview::ContextMenusRemove::Params::Create(*args_)); |
| 76 EXTENSION_FUNCTION_VALIDATE(params.get()); | 81 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 77 | 82 |
| 78 MenuManager* menu_manager = | 83 MenuManager* menu_manager = |
| 79 MenuManager::Get(Profile::FromBrowserContext(browser_context())); | 84 MenuManager::Get(Profile::FromBrowserContext(browser_context())); |
| 80 | 85 |
| 81 MenuItem::Id id( | 86 MenuItem::Id id( |
| 82 Profile::FromBrowserContext(browser_context())->IsOffTheRecord(), | 87 Profile::FromBrowserContext(browser_context())->IsOffTheRecord(), |
| 83 MenuItem::ExtensionKey(extension_id(), params->instance_id)); | 88 MenuItem::ExtensionKey( |
| 89 GetSenderWebContents()->GetRenderProcessHost()->GetID(), |
| 90 params->instance_id)); |
| 84 | 91 |
| 85 if (params->menu_item_id.as_string) { | 92 if (params->menu_item_id.as_string) { |
| 86 id.string_uid = *params->menu_item_id.as_string; | 93 id.string_uid = *params->menu_item_id.as_string; |
| 87 } else if (params->menu_item_id.as_integer) { | 94 } else if (params->menu_item_id.as_integer) { |
| 88 id.uid = *params->menu_item_id.as_integer; | 95 id.uid = *params->menu_item_id.as_integer; |
| 89 } else { | 96 } else { |
| 90 NOTREACHED(); | 97 NOTREACHED(); |
| 91 } | 98 } |
| 92 | 99 |
| 93 bool success = true; | 100 bool success = true; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 106 return success; | 113 return success; |
| 107 } | 114 } |
| 108 | 115 |
| 109 bool ChromeWebViewInternalContextMenusRemoveAllFunction::RunAsync() { | 116 bool ChromeWebViewInternalContextMenusRemoveAllFunction::RunAsync() { |
| 110 scoped_ptr<webview::ContextMenusRemoveAll::Params> params( | 117 scoped_ptr<webview::ContextMenusRemoveAll::Params> params( |
| 111 webview::ContextMenusRemoveAll::Params::Create(*args_)); | 118 webview::ContextMenusRemoveAll::Params::Create(*args_)); |
| 112 EXTENSION_FUNCTION_VALIDATE(params.get()); | 119 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 113 | 120 |
| 114 MenuManager* menu_manager = | 121 MenuManager* menu_manager = |
| 115 MenuManager::Get(Profile::FromBrowserContext(browser_context())); | 122 MenuManager::Get(Profile::FromBrowserContext(browser_context())); |
| 123 menu_manager->RemoveAllContextItems(MenuItem::ExtensionKey( |
| 124 GetSenderWebContents()->GetRenderProcessHost()->GetID(), |
| 125 params->instance_id)); |
| 116 | 126 |
| 117 int webview_instance_id = params->instance_id; | |
| 118 menu_manager->RemoveAllContextItems( | |
| 119 MenuItem::ExtensionKey(extension()->id(), webview_instance_id)); | |
| 120 SendResponse(true); | 127 SendResponse(true); |
| 121 return true; | 128 return true; |
| 122 } | 129 } |
| 123 | 130 |
| 124 ChromeWebViewInternalShowContextMenuFunction:: | 131 ChromeWebViewInternalShowContextMenuFunction:: |
| 125 ChromeWebViewInternalShowContextMenuFunction() { | 132 ChromeWebViewInternalShowContextMenuFunction() { |
| 126 } | 133 } |
| 127 | 134 |
| 128 ChromeWebViewInternalShowContextMenuFunction:: | 135 ChromeWebViewInternalShowContextMenuFunction:: |
| 129 ~ChromeWebViewInternalShowContextMenuFunction() { | 136 ~ChromeWebViewInternalShowContextMenuFunction() { |
| 130 } | 137 } |
| 131 | 138 |
| 132 bool ChromeWebViewInternalShowContextMenuFunction::RunAsyncSafe( | 139 bool ChromeWebViewInternalShowContextMenuFunction::RunAsyncSafe( |
| 133 WebViewGuest* guest) { | 140 WebViewGuest* guest) { |
| 134 scoped_ptr<webview::ShowContextMenu::Params> params( | 141 scoped_ptr<webview::ShowContextMenu::Params> params( |
| 135 webview::ShowContextMenu::Params::Create(*args_)); | 142 webview::ShowContextMenu::Params::Create(*args_)); |
| 136 EXTENSION_FUNCTION_VALIDATE(params.get()); | 143 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 137 | 144 |
| 138 // TODO(lazyboy): Actually implement filtering menu items, we pass NULL for | 145 // TODO(lazyboy): Actually implement filtering menu items, we pass NULL for |
| 139 // now. | 146 // now. |
| 140 guest->ShowContextMenu(params->request_id, NULL); | 147 guest->ShowContextMenu(params->request_id, NULL); |
| 141 | 148 |
| 142 SendResponse(true); | 149 SendResponse(true); |
| 143 return true; | 150 return true; |
| 144 } | 151 } |
| 145 | 152 |
| 146 } // namespace extensions | 153 } // namespace extensions |
| OLD | NEW |