| Index: chrome/browser/android/contextualsearch/contextual_search_delegate.cc
|
| diff --git a/chrome/browser/android/contextualsearch/contextual_search_delegate.cc b/chrome/browser/android/contextualsearch/contextual_search_delegate.cc
|
| index 4b477892f3fd7c9cd0068cd0f24871ac7becf5c6..b60620119b94bcdc5e91b2635e70c7341154c914 100644
|
| --- a/chrome/browser/android/contextualsearch/contextual_search_delegate.cc
|
| +++ b/chrome/browser/android/contextualsearch/contextual_search_delegate.cc
|
| @@ -310,34 +310,28 @@ void ContextualSearchDelegate::SaveSurroundingText(
|
| int start_offset,
|
| int end_offset) {
|
| DCHECK(context_ != nullptr);
|
| - // Sometimes the surroundings are 0, 0, '', so fall back on the selection.
|
| + // Sometimes the surroundings are 0, 0, '', so exit in that case.
|
| // See crbug.com/393100.
|
| - bool use_selection = false;
|
| - if (start_offset == 0 && end_offset == 0 && surrounding_text.length() == 0) {
|
| - use_selection = true;
|
| - end_offset = context_->GetOriginalSelectedText().length();
|
| - }
|
| - const base::string16& surrounding_text_or_selection(
|
| - use_selection ? base::UTF8ToUTF16(context_->GetOriginalSelectedText())
|
| - : surrounding_text);
|
| + if (start_offset == 0 && end_offset == 0 && surrounding_text.length() == 0)
|
| + return;
|
|
|
| // Pin the start and end offsets to ensure they point within the string.
|
| - int surrounding_length = surrounding_text_or_selection.length();
|
| + int surrounding_length = surrounding_text.length();
|
| start_offset = std::min(surrounding_length, std::max(0, start_offset));
|
| end_offset = std::min(surrounding_length, std::max(0, end_offset));
|
|
|
| context_->SetSelectionSurroundings(start_offset, end_offset,
|
| - surrounding_text_or_selection);
|
| + surrounding_text);
|
|
|
| // Call the Icing callback with a shortened copy of the surroundings.
|
| int icing_surrounding_size = field_trial_->GetIcingSurroundingSize();
|
| - size_t selection_start = start_offset;
|
| - size_t selection_end = end_offset;
|
| - if (icing_surrounding_size >= 0 && selection_start <= selection_end) {
|
| + if (icing_surrounding_size >= 0 && start_offset <= end_offset) {
|
| + size_t selection_start = start_offset;
|
| + size_t selection_end = end_offset;
|
| int icing_padding_each_side = icing_surrounding_size / 2;
|
| - base::string16 icing_surrounding_text = SurroundingTextForIcing(
|
| - surrounding_text_or_selection, icing_padding_each_side,
|
| - &selection_start, &selection_end);
|
| + base::string16 icing_surrounding_text =
|
| + SurroundingTextForIcing(surrounding_text, icing_padding_each_side,
|
| + &selection_start, &selection_end);
|
| if (selection_start <= selection_end)
|
| icing_callback_.Run(context_->GetBasePageEncoding(),
|
| icing_surrounding_text, selection_start,
|
|
|