Skip to content

Commit

Permalink
Use BigString to avoid soft message size limits
Browse files Browse the repository at this point in the history
This replaces several uses of string or String16 with BigString or
BigString16, respectively, in order to avoid hitting soft message size
limits on messages which may carry especially large strings.

Fixed: 1141991,1141994,1141998
Change-Id: I8d0b4a4c81adeeb22ea8069bebee6885bbec2a2f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2496032
Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
Reviewed-by: Sam McNally <sammc@chromium.org>
Commit-Queue: Ken Rockot <rockot@google.com>
Cr-Commit-Position: refs/heads/master@{#820995}
  • Loading branch information
krockot authored and Commit Bot committed Oct 27, 2020
1 parent 051e11e commit c73e50a
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 11 deletions.
3 changes: 2 additions & 1 deletion content/browser/renderer_host/drop_data_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <utility>
#include <vector>

#include "base/containers/span.h"
#include "base/files/file_path.h"
#include "base/strings/utf_string_conversions.h"
#include "content/browser/file_system_access/native_file_system_manager_impl.h"
Expand Down Expand Up @@ -147,7 +148,7 @@ DropData DragDataToDropData(const blink::mojom::DragData& drag_data) {
DCHECK(result.file_contents.empty());

const blink::mojom::DragItemBinaryPtr& binary_item = item->get_binary();
std::vector<uint8_t> contents = binary_item->data;
base::span<const uint8_t> contents = base::make_span(binary_item->data);
result.file_contents.assign(contents.begin(), contents.end());
result.file_contents_source_url = binary_item->source_url;
result.file_contents_filename_extension =
Expand Down
2 changes: 1 addition & 1 deletion mojo/public/cpp/base/big_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class COMPONENT_EXPORT(MOJO_BASE) BigBufferView {
static BigBufferView CreateInvalidForTest();

private:
BigBuffer::StorageType storage_type_;
BigBuffer::StorageType storage_type_ = BigBuffer::StorageType::kBytes;
base::span<const uint8_t> bytes_;
base::Optional<internal::BigBufferSharedMemoryRegion> shared_memory_;

Expand Down
3 changes: 2 additions & 1 deletion third_party/blink/public/mojom/clipboard/clipboard.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module blink.mojom;

import "mojo/public/mojom/base/string16.mojom";
import "mojo/public/mojom/base/big_buffer.mojom";
import "mojo/public/mojom/base/big_string.mojom";
import "skia/public/mojom/bitmap.mojom";
import "url/mojom/url.mojom";

Expand Down Expand Up @@ -55,7 +56,7 @@ interface ClipboardHost {
ReadSvg(ClipboardBuffer buffer) => (mojo_base.mojom.BigString16 result);

[Sync]
ReadRtf(ClipboardBuffer buffer) => (string result);
ReadRtf(ClipboardBuffer buffer) => (mojo_base.mojom.BigString result);

[Sync]
ReadImage(ClipboardBuffer buffer) => (skia.mojom.Bitmap? image);
Expand Down
2 changes: 1 addition & 1 deletion third_party/blink/public/mojom/frame/frame.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ interface LocalFrameHost {
// Notification that the text selection has changed.
// Note: The second parameter is the character based offset of the
// base::string16 text in the document.
TextSelectionChanged(mojo_base.mojom.String16 text,
TextSelectionChanged(mojo_base.mojom.BigString16 text,
uint32 offset,
gfx.mojom.Range range);

Expand Down
5 changes: 3 additions & 2 deletions third_party/blink/public/mojom/page/drag.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
module blink.mojom;

import "mojo/public/mojom/base/file_path.mojom";
import "mojo/public/mojom/base/big_buffer.mojom";
import "mojo/public/mojom/base/string16.mojom";
import "services/network/public/mojom/referrer_policy.mojom";
import "ui/base/dragdrop/mojom/drag_drop_types.mojom";
Expand Down Expand Up @@ -44,7 +45,7 @@ struct DragItemString {
string string_type;
// Depending of the value of `string_type`, it contains the dragged link,
// text, HTML markup or any other data.
mojo_base.mojom.String16 string_data;
mojo_base.mojom.BigString16 string_data;

// Title associated with a link. Only valid when string_type == "text/uri-list".
mojo_base.mojom.String16? title;
Expand All @@ -64,7 +65,7 @@ struct DragItemFile {
// Only used when dragging images out of Blink.
struct DragItemBinary {
// Image data.
array<uint8> data;
mojo_base.mojom.BigBuffer data;
url.mojom.Url source_url;
mojo_base.mojom.FilePath filename_extension;
// Content-Disposition response header.
Expand Down
15 changes: 12 additions & 3 deletions third_party/blink/renderer/platform/mojo/drag_mojom_traits.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

#include "third_party/blink/renderer/platform/mojo/drag_mojom_traits.h"

#include "base/containers/span.h"
#include "base/files/file_path.h"
#include "base/memory/scoped_refptr.h"
#include "base/notreached.h"
#include "base/optional.h"
#include "base/strings/string16.h"
#include "mojo/public/cpp/bindings/interface_ptr.h"
#include "mojo/public/cpp/base/big_buffer.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "services/network/public/mojom/referrer_policy.mojom-shared.h"
#include "third_party/blink/public/mojom/file_system_access/native_file_system_drag_drop_token.mojom-blink.h"
#include "third_party/blink/public/platform/file_path_conversion.h"
Expand Down Expand Up @@ -112,10 +114,17 @@ bool StructTraits<
}

// static
blink::WebVector<uint8_t> StructTraits<
mojo_base::BigBuffer StructTraits<
blink::mojom::DragItemBinaryDataView,
blink::WebDragData::Item>::data(const blink::WebDragData::Item& item) {
return item.binary_data.Copy();
mojo_base::BigBuffer buffer(item.binary_data.size());
item.binary_data.ForEachSegment([&buffer](const char* segment,
size_t segment_size,
size_t segment_offset) {
std::copy(segment, segment + segment_size, buffer.data() + segment_offset);
return true;
});
return buffer;
}

// static
Expand Down
3 changes: 2 additions & 1 deletion third_party/blink/renderer/platform/mojo/drag_mojom_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <string>

#include "mojo/public/cpp/base/big_buffer.h"
#include "mojo/public/cpp/base/file_path_mojom_traits.h"
#include "mojo/public/cpp/bindings/array_traits_web_vector.h"
#include "mojo/public/cpp/bindings/string_traits_wtf.h"
Expand Down Expand Up @@ -61,7 +62,7 @@ struct StructTraits<blink::mojom::DragItemFileDataView,
template <>
struct StructTraits<blink::mojom::DragItemBinaryDataView,
blink::WebDragData::Item> {
static blink::WebVector<uint8_t> data(const blink::WebDragData::Item& item);
static mojo_base::BigBuffer data(const blink::WebDragData::Item& item);
static blink::KURL source_url(const blink::WebDragData::Item& item);
static base::FilePath filename_extension(
const blink::WebDragData::Item& item);
Expand Down
2 changes: 1 addition & 1 deletion ui/base/ime/mojom/text_input_state.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct TextInputState {
uint32 flags;

// The value of input field.
mojo_base.mojom.String16? value;
mojo_base.mojom.BigString16? value;

// The current selection range, or the caret position if nothing is selected.
gfx.mojom.Range selection;
Expand Down

0 comments on commit c73e50a

Please sign in to comment.