Chromium Code Reviews| 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 dd465e4f837b68e083f669c8fbfafbad32eee19c..adcc48cde3591fc9b84234ec60c7c4c0625c8b22 100644 |
| --- a/chrome/browser/android/contextualsearch/contextual_search_delegate.cc |
| +++ b/chrome/browser/android/contextualsearch/contextual_search_delegate.cc |
| @@ -41,6 +41,7 @@ const char kContextualSearchResponseSelectedTextParam[] = "selected_text"; |
| const char kContextualSearchResponseSearchTermParam[] = "search_term"; |
| const char kContextualSearchResponseResolvedTermParam[] = "resolved_term"; |
| const char kContextualSearchPreventPreload[] = "prevent_preload"; |
| +const char kContextualSearchMentions[] = "mentions"; |
| const char kContextualSearchServerEndpoint[] = "_/contextualsearch?"; |
| const int kContextualSearchRequestVersion = 2; |
| const char kContextualSearchResolverUrl[] = |
| @@ -142,6 +143,10 @@ void ContextualSearchDelegate::OnURLFetchComplete( |
| std::string display_text; |
| std::string alternate_term; |
| std::string prevent_preload; |
| + size_t mention_start = 0; |
| + size_t mention_end = 0; |
| + int start_adjust = 0; |
| + int end_adjust = 0; |
| if (source->GetStatus().is_success() && response_code == 200) { |
| std::string response; |
| @@ -149,13 +154,18 @@ void ContextualSearchDelegate::OnURLFetchComplete( |
| DCHECK(has_string_response); |
| if (has_string_response) { |
| DecodeSearchTermsFromJsonResponse(response, &search_term, &display_text, |
| - &alternate_term, &prevent_preload); |
| + &alternate_term, &prevent_preload, |
| + &mention_start, &mention_end); |
| + if (mention_start != 0 || mention_end != 0) { |
| + start_adjust = mention_start - context_->start_offset; |
| + end_adjust = mention_end - context_->end_offset; |
| + } |
| } |
| } |
| bool is_invalid = response_code == net::URLFetcher::RESPONSE_CODE_INVALID; |
| search_term_callback_.Run( |
| is_invalid, response_code, search_term, display_text, alternate_term, |
| - prevent_preload == kDoPreventPreloadValue); |
| + prevent_preload == kDoPreventPreloadValue, start_adjust, end_adjust); |
| // The ContextualSearchContext is consumed once the request has completed. |
| context_.reset(); |
| @@ -399,7 +409,9 @@ void ContextualSearchDelegate::DecodeSearchTermsFromJsonResponse( |
| std::string* search_term, |
| std::string* display_text, |
| std::string* alternate_term, |
| - std::string* prevent_preload) { |
| + std::string* prevent_preload, |
| + size_t* mention_start, |
| + size_t* mention_end) { |
| bool contains_xssi_escape = response.find(kXssiEscape) == 0; |
| const std::string& proper_json = |
| contains_xssi_escape ? response.substr(strlen(kXssiEscape)) : response; |
| @@ -416,6 +428,11 @@ void ContextualSearchDelegate::DecodeSearchTermsFromJsonResponse( |
| display_text)) { |
| *display_text = *search_term; |
| } |
| + // Extract mentions for seleciton-expansion |
| + base::ListValue* mentions_list; |
|
pedro (no code reviews)
2015/06/25 01:30:28
Does this represent multiple mentions. If so, are
|
| + dict->GetList(kContextualSearchMentions, &mentions_list); |
| + if (mentions_list != NULL && mentions_list->GetSize() >= 2) |
| + ExtractMentionsStartEnd(*mentions_list, mention_start, mention_end); |
| // If either the selected text or the resolved term is not the search term, |
| // use it as the alternate term. |
| std::string selected_text; |
| @@ -445,6 +462,19 @@ int ContextualSearchDelegate::GetSearchTermSurroundingSize() { |
| return kContextualSearchDefaultContentSize; |
| } |
| +// Extract the Start/End of the mentions in the surrounding text |
| +// for selection-expansion. |
| +void ContextualSearchDelegate::ExtractMentionsStartEnd( |
| + const base::ListValue& mentions_list, |
| + size_t* startResult, |
| + size_t* endResult) { |
| + int int_value; |
| + if (mentions_list.GetInteger(0, &int_value)) |
| + *startResult = int_value; |
| + if (mentions_list.GetInteger(1, &int_value)) |
| + *endResult = int_value; |
| +} |
| + |
| // Returns the size of the surroundings to be sent to Icing. |
| int ContextualSearchDelegate::GetIcingSurroundingSize() { |
| std::string param_string = variations::GetVariationParamValue( |