Chromium Code Reviews| Index: extensions/browser/api/clipboard/clipboard_api.cc |
| diff --git a/extensions/browser/api/clipboard/clipboard_api.cc b/extensions/browser/api/clipboard/clipboard_api.cc |
| index ef7373b821cc50d80cd1cfa1222657623846b78b..4976fa62e9c653f8e74bd97c38522ab8f325232e 100644 |
| --- a/extensions/browser/api/clipboard/clipboard_api.cc |
| +++ b/extensions/browser/api/clipboard/clipboard_api.cc |
| @@ -8,6 +8,7 @@ |
| #include "base/lazy_instance.h" |
| #include "base/memory/ptr_util.h" |
| +#include "base/strings/string_util.h" |
| #include "base/values.h" |
| #include "extensions/browser/api/extensions_api_client.h" |
| #include "extensions/browser/event_router.h" |
| @@ -54,8 +55,17 @@ ExtensionFunction::ResponseAction ClipboardSetImageDataFunction::Run() { |
| std::unique_ptr<clipboard::SetImageData::Params> params( |
| clipboard::SetImageData::Params::Create(*args_)); |
| EXTENSION_FUNCTION_VALIDATE(params); |
| + |
| + // Fill in the omitted additiona data items with empty data. |
|
Devlin
2017/05/17 16:08:44
typo: additional
jennyz
2017/05/18 23:33:49
Done.
|
| + if (!params->additional_items.get()) |
|
Devlin
2017/05/17 16:08:44
no need for .get()
jennyz
2017/05/18 23:33:49
Done.
|
| + params->additional_items.reset(new AdditionalDataItemList()); |
| + |
| + if (!IsAdditionalItemsParamValid(*(params->additional_items))) { |
| + return RespondNow(Error("Unsupported additional_items parameter data.")); |
|
Devlin
2017/05/17 16:08:44
additionalItems
jennyz
2017/05/18 23:33:49
Done.
|
| + } |
| + |
| ExtensionsAPIClient::Get()->SaveImageDataToClipboard( |
| - params->image_data, params->type, |
| + params->image_data, params->type, std::move(params->additional_items), |
| base::Bind(&ClipboardSetImageDataFunction::OnSaveImageDataSuccess, this), |
| base::Bind(&ClipboardSetImageDataFunction::OnSaveImageDataError, this)); |
| return RespondLater(); |
| @@ -70,4 +80,29 @@ void ClipboardSetImageDataFunction::OnSaveImageDataError( |
| Respond(Error(error)); |
| } |
| +bool ClipboardSetImageDataFunction::IsAdditionalItemsParamValid( |
| + const AdditionalDataItemList& items) { |
| + // Limit the maximum text/html data length to 2MB. |
| + const size_t max_item_data_bytes = 2097152; |
| + |
| + bool has_text_plain = false; |
| + bool has_text_html = false; |
| + for (const clipboard::AdditionalDataItem& item : items) { |
| + if (item.type == clipboard::DATA_ITEM_TYPE_TEXT_PLAIN) { |
|
Devlin
2017/05/17 16:08:44
use a switch statement
jennyz
2017/05/18 23:33:49
Done.
|
| + if (has_text_plain) |
| + return false; |
| + has_text_plain = true; |
| + } |
| + if (item.type == clipboard::DATA_ITEM_TYPE_TEXT_HTML) { |
| + if (has_text_html) |
| + return false; |
| + has_text_html = true; |
| + } |
| + // Check maximum length of the string data. |
| + if (item.data.length() > max_item_data_bytes) |
| + return false; |
| + } |
| + return true; |
| +} |
| + |
| } // namespace extensions |