| OLD | NEW |
| 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.h" |
| 10 #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" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 WebViewGuest* guest = WebViewGuest::From( | 52 WebViewGuest* guest = WebViewGuest::From( |
| 53 render_view_host()->GetProcess()->GetID(), instance_id); | 53 render_view_host()->GetProcess()->GetID(), instance_id); |
| 54 if (!guest) | 54 if (!guest) |
| 55 return false; | 55 return false; |
| 56 | 56 |
| 57 return RunImplSafe(guest); | 57 return RunImplSafe(guest); |
| 58 } | 58 } |
| 59 | 59 |
| 60 // TODO(lazyboy): Add checks similar to | 60 // TODO(lazyboy): Add checks similar to |
| 61 // WebviewExtensionFunction::RunImplSafe(WebViewGuest*). | 61 // WebviewExtensionFunction::RunImplSafe(WebViewGuest*). |
| 62 bool WebviewContextMenusCreateFunction::RunImpl() { | 62 bool WebviewContextMenusCreateFunction::RunSync() { |
| 63 scoped_ptr<webview::ContextMenusCreate::Params> params( | 63 scoped_ptr<webview::ContextMenusCreate::Params> params( |
| 64 webview::ContextMenusCreate::Params::Create(*args_)); | 64 webview::ContextMenusCreate::Params::Create(*args_)); |
| 65 EXTENSION_FUNCTION_VALIDATE(params.get()); | 65 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 66 | 66 |
| 67 MenuItem::Id id( | 67 MenuItem::Id id( |
| 68 Profile::FromBrowserContext(browser_context())->IsOffTheRecord(), | 68 Profile::FromBrowserContext(browser_context())->IsOffTheRecord(), |
| 69 MenuItem::ExtensionKey(extension_id(), params->instance_id)); | 69 MenuItem::ExtensionKey(extension_id(), params->instance_id)); |
| 70 | 70 |
| 71 if (params->create_properties.id.get()) { | 71 if (params->create_properties.id.get()) { |
| 72 id.string_uid = *params->create_properties.id; | 72 id.string_uid = *params->create_properties.id; |
| 73 } else { | 73 } else { |
| 74 // The Generated Id is added by webview_custom_bindings.js. | 74 // The Generated Id is added by webview_custom_bindings.js. |
| 75 base::DictionaryValue* properties = NULL; | 75 base::DictionaryValue* properties = NULL; |
| 76 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &properties)); | 76 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &properties)); |
| 77 EXTENSION_FUNCTION_VALIDATE( | 77 EXTENSION_FUNCTION_VALIDATE( |
| 78 properties->GetInteger(helpers::kGeneratedIdKey, &id.uid)); | 78 properties->GetInteger(helpers::kGeneratedIdKey, &id.uid)); |
| 79 } | 79 } |
| 80 | 80 |
| 81 bool success = extensions::context_menus_api_helpers::CreateMenuItem( | 81 bool success = extensions::context_menus_api_helpers::CreateMenuItem( |
| 82 params->create_properties, | 82 params->create_properties, |
| 83 Profile::FromBrowserContext(browser_context()), | 83 Profile::FromBrowserContext(browser_context()), |
| 84 GetExtension(), | 84 GetExtension(), |
| 85 id, | 85 id, |
| 86 &error_); | 86 &error_); |
| 87 | 87 |
| 88 SendResponse(success); | 88 SendResponse(success); |
| 89 return success; | 89 return success; |
| 90 } | 90 } |
| 91 | 91 |
| 92 bool WebviewContextMenusUpdateFunction::RunImpl() { | 92 bool WebviewContextMenusUpdateFunction::RunSync() { |
| 93 scoped_ptr<webview::ContextMenusUpdate::Params> params( | 93 scoped_ptr<webview::ContextMenusUpdate::Params> params( |
| 94 webview::ContextMenusUpdate::Params::Create(*args_)); | 94 webview::ContextMenusUpdate::Params::Create(*args_)); |
| 95 EXTENSION_FUNCTION_VALIDATE(params.get()); | 95 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 96 | 96 |
| 97 Profile* profile = Profile::FromBrowserContext(browser_context()); | 97 Profile* profile = Profile::FromBrowserContext(browser_context()); |
| 98 MenuItem::Id item_id( | 98 MenuItem::Id item_id( |
| 99 profile->IsOffTheRecord(), | 99 profile->IsOffTheRecord(), |
| 100 MenuItem::ExtensionKey(extension_id(), params->instance_id)); | 100 MenuItem::ExtensionKey(extension_id(), params->instance_id)); |
| 101 | 101 |
| 102 if (params->id.as_string) | 102 if (params->id.as_string) |
| 103 item_id.string_uid = *params->id.as_string; | 103 item_id.string_uid = *params->id.as_string; |
| 104 else if (params->id.as_integer) | 104 else if (params->id.as_integer) |
| 105 item_id.uid = *params->id.as_integer; | 105 item_id.uid = *params->id.as_integer; |
| 106 else | 106 else |
| 107 NOTREACHED(); | 107 NOTREACHED(); |
| 108 | 108 |
| 109 bool success = extensions::context_menus_api_helpers::UpdateMenuItem( | 109 bool success = extensions::context_menus_api_helpers::UpdateMenuItem( |
| 110 params->update_properties, profile, GetExtension(), item_id, &error_); | 110 params->update_properties, profile, GetExtension(), item_id, &error_); |
| 111 SendResponse(success); | 111 SendResponse(success); |
| 112 return success; | 112 return success; |
| 113 } | 113 } |
| 114 | 114 |
| 115 bool WebviewContextMenusRemoveFunction::RunImpl() { | 115 bool WebviewContextMenusRemoveFunction::RunSync() { |
| 116 scoped_ptr<webview::ContextMenusRemove::Params> params( | 116 scoped_ptr<webview::ContextMenusRemove::Params> params( |
| 117 webview::ContextMenusRemove::Params::Create(*args_)); | 117 webview::ContextMenusRemove::Params::Create(*args_)); |
| 118 EXTENSION_FUNCTION_VALIDATE(params.get()); | 118 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 119 | 119 |
| 120 MenuManager* menu_manager = | 120 MenuManager* menu_manager = |
| 121 MenuManager::Get(Profile::FromBrowserContext(browser_context())); | 121 MenuManager::Get(Profile::FromBrowserContext(browser_context())); |
| 122 | 122 |
| 123 MenuItem::Id id( | 123 MenuItem::Id id( |
| 124 Profile::FromBrowserContext(browser_context())->IsOffTheRecord(), | 124 Profile::FromBrowserContext(browser_context())->IsOffTheRecord(), |
| 125 MenuItem::ExtensionKey(extension_id(), params->instance_id)); | 125 MenuItem::ExtensionKey(extension_id(), params->instance_id)); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 141 context_menus_api_helpers::GetIDString(id)); | 141 context_menus_api_helpers::GetIDString(id)); |
| 142 success = false; | 142 success = false; |
| 143 } else if (!menu_manager->RemoveContextMenuItem(id)) { | 143 } else if (!menu_manager->RemoveContextMenuItem(id)) { |
| 144 success = false; | 144 success = false; |
| 145 } | 145 } |
| 146 | 146 |
| 147 SendResponse(success); | 147 SendResponse(success); |
| 148 return success; | 148 return success; |
| 149 } | 149 } |
| 150 | 150 |
| 151 bool WebviewContextMenusRemoveAllFunction::RunImpl() { | 151 bool WebviewContextMenusRemoveAllFunction::RunSync() { |
| 152 scoped_ptr<webview::ContextMenusRemoveAll::Params> params( | 152 scoped_ptr<webview::ContextMenusRemoveAll::Params> params( |
| 153 webview::ContextMenusRemoveAll::Params::Create(*args_)); | 153 webview::ContextMenusRemoveAll::Params::Create(*args_)); |
| 154 EXTENSION_FUNCTION_VALIDATE(params.get()); | 154 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 155 | 155 |
| 156 MenuManager* menu_manager = | 156 MenuManager* menu_manager = |
| 157 MenuManager::Get(Profile::FromBrowserContext(browser_context())); | 157 MenuManager::Get(Profile::FromBrowserContext(browser_context())); |
| 158 | 158 |
| 159 int webview_instance_id = params->instance_id; | 159 int webview_instance_id = params->instance_id; |
| 160 menu_manager->RemoveAllContextItems( | 160 menu_manager->RemoveAllContextItems( |
| 161 MenuItem::ExtensionKey(GetExtension()->id(), webview_instance_id)); | 161 MenuItem::ExtensionKey(GetExtension()->id(), webview_instance_id)); |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 | 539 |
| 540 WebviewTerminateFunction::~WebviewTerminateFunction() { | 540 WebviewTerminateFunction::~WebviewTerminateFunction() { |
| 541 } | 541 } |
| 542 | 542 |
| 543 bool WebviewTerminateFunction::RunImplSafe(WebViewGuest* guest) { | 543 bool WebviewTerminateFunction::RunImplSafe(WebViewGuest* guest) { |
| 544 guest->Terminate(); | 544 guest->Terminate(); |
| 545 return true; | 545 return true; |
| 546 } | 546 } |
| 547 | 547 |
| 548 } // namespace extensions | 548 } // namespace extensions |
| OLD | NEW |