Skip to content

Commit

Permalink
ozone/wayland: Avoid set_surrounding_text when text length exceeds li…
Browse files Browse the repository at this point in the history
…mit.

Due to the length limitation of wayland messages, we can not send text
longer than 4096 bytes in set_surrounding_text.
In the spec of text-input-unstable-v3, the max length is explicitly
specified as 4000 bytes.
https://github.com/wayland-project/wayland-protocols/blob/master/unstable/text-input/text-input-unstable-v3.xml#L141
Although we use v1 instead of v3, the semantics of set_surrounding_text
seems unchanged and I follow the 4000 bytes limit.

Bug: 1171936
Change-Id: I73aab9b94cb4d388f88ae97aa34653135c5574cb
Text: Pasting text longer than 5000 in Omnibox and text input in groups.google.com.
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2666657
Commit-Queue: Naoki Fukino <fukino@chromium.org>
Reviewed-by: Maksim Sisov <msisov@igalia.com>
Cr-Commit-Position: refs/heads/master@{#849640}
  • Loading branch information
Naoki Fukino authored and Chromium LUCI CQ committed Feb 2, 2021
1 parent 5ab228a commit f4891d0
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions ui/ozone/platform/wayland/host/zwp_text_input_wrapper_v1.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,21 @@ void ZWPTextInputWrapperV1::SetCursorRect(const gfx::Rect& rect) {
void ZWPTextInputWrapperV1::SetSurroundingText(
const base::string16& text,
const gfx::Range& selection_range) {
static constexpr size_t kWaylandMessageDataMaxLength = 4000;
const std::string text_utf8 = base::UTF16ToUTF8(text);
// The text length for set_surrounding_text can not be longer than the maximum
// length of wayland messages. The maximum length of the text is explicitly
// specified as 4000 in the protocol spec of text-input-unstable-v3.
// If the client is unware of the text around the cursor, we can skip sending
// set_surrounding_text requests. We fall back to this case when the text is
// too long.
// TODO(fukino): If the length of |text| doesn't fit into the 4000 bytes
// limitation, we should truncate the text and adjust indices of
// |selection_range| to make use of set_surrounding_text as much as possible.
// crbug.com/1173465.
if (text_utf8.size() > kWaylandMessageDataMaxLength)
return;

zwp_text_input_v1_set_surrounding_text(obj_.get(), text_utf8.c_str(),
selection_range.start(),
selection_range.end());
Expand Down

0 comments on commit f4891d0

Please sign in to comment.