| 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_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 Loading... |
| 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.webview_instance_id = params->instance_id; |
| 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()); |
| 100 item_id.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()); |
| 126 id.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 bool success = true; |
| 136 MenuItem* item = menu_manager->GetItemById(id); |
| 137 // Ensure one extension can't remove another's menu items. |
| 138 if (!item || item->extension_id() != extension_id()) { |
| 139 error_ = ErrorUtils::FormatErrorMessage( |
| 140 context_menus_api_helpers::kCannotFindItemError, |
| 141 context_menus_api_helpers::GetIDString(id)); |
| 142 success = false; |
| 143 } else if (!menu_manager->RemoveContextMenuItem(id)) { |
| 144 success = false; |
| 145 } |
| 146 |
| 147 SendResponse(success); |
| 148 return success; |
| 113 } | 149 } |
| 114 | 150 |
| 115 bool WebviewContextMenusRemoveAllFunction::RunImpl() { | 151 bool WebviewContextMenusRemoveAllFunction::RunImpl() { |
| 116 scoped_ptr<webview::ContextMenusRemoveAll::Params> params( | 152 scoped_ptr<webview::ContextMenusRemoveAll::Params> params( |
| 117 webview::ContextMenusRemoveAll::Params::Create(*args_)); | 153 webview::ContextMenusRemoveAll::Params::Create(*args_)); |
| 118 EXTENSION_FUNCTION_VALIDATE(params.get()); | 154 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 119 | 155 |
| 120 // TODO(lazyboy): Implement. | 156 MenuManager* menu_manager = |
| 121 SendResponse(false); | 157 MenuManager::Get(Profile::FromBrowserContext(browser_context())); |
| 122 return false; | 158 |
| 159 int webview_instance_id = params->instance_id; |
| 160 menu_manager->RemoveAllWebviewContextItems(GetExtension()->id(), |
| 161 webview_instance_id); |
| 162 SendResponse(true); |
| 163 return true; |
| 123 } | 164 } |
| 124 | 165 |
| 125 WebviewClearDataFunction::WebviewClearDataFunction() | 166 WebviewClearDataFunction::WebviewClearDataFunction() |
| 126 : remove_mask_(0), bad_message_(false) {} | 167 : remove_mask_(0), bad_message_(false) {} |
| 127 | 168 |
| 128 WebviewClearDataFunction::~WebviewClearDataFunction() {} | 169 WebviewClearDataFunction::~WebviewClearDataFunction() {} |
| 129 | 170 |
| 130 // Parses the |dataToRemove| argument to generate the remove mask. Sets | 171 // Parses the |dataToRemove| argument to generate the remove mask. Sets |
| 131 // |bad_message_| (like EXTENSION_FUNCTION_VALIDATE would if this were a bool | 172 // |bad_message_| (like EXTENSION_FUNCTION_VALIDATE would if this were a bool |
| 132 // method) if 'dataToRemove' is not present. | 173 // method) if 'dataToRemove' is not present. |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 | 528 |
| 488 WebviewTerminateFunction::~WebviewTerminateFunction() { | 529 WebviewTerminateFunction::~WebviewTerminateFunction() { |
| 489 } | 530 } |
| 490 | 531 |
| 491 bool WebviewTerminateFunction::RunImplSafe(WebViewGuest* guest) { | 532 bool WebviewTerminateFunction::RunImplSafe(WebViewGuest* guest) { |
| 492 guest->Terminate(); | 533 guest->Terminate(); |
| 493 return true; | 534 return true; |
| 494 } | 535 } |
| 495 | 536 |
| 496 } // namespace extensions | 537 } // namespace extensions |
| OLD | NEW |