Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(458)

Side by Side Diff: chrome/browser/android/contextualsearch/contextual_search_delegate.cc

Issue 2440843002: [Contextual Search] Pipe basic quick action data from C++ to Java (Closed)
Patch Set: [Contextual Search] Pipe basic quick action data from C++ to Java Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/android/contextualsearch/contextual_search_delegate.h" 5 #include "chrome/browser/android/contextualsearch/contextual_search_delegate.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/base64.h" 10 #include "base/base64.h"
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 std::string alternate_term; 165 std::string alternate_term;
166 std::string mid; 166 std::string mid;
167 std::string prevent_preload; 167 std::string prevent_preload;
168 int mention_start = 0; 168 int mention_start = 0;
169 int mention_end = 0; 169 int mention_end = 0;
170 int start_adjust = 0; 170 int start_adjust = 0;
171 int end_adjust = 0; 171 int end_adjust = 0;
172 std::string context_language; 172 std::string context_language;
173 std::string thumbnail_url = ""; 173 std::string thumbnail_url = "";
174 std::string caption = ""; 174 std::string caption = "";
175 std::string quick_action_uri = "";
176 std::string quick_action_category = "";
175 177
176 DecodeSearchTermFromJsonResponse( 178 DecodeSearchTermFromJsonResponse(
177 json_string, &search_term, &display_text, &alternate_term, &mid, 179 json_string, &search_term, &display_text, &alternate_term, &mid,
178 &prevent_preload, &mention_start, &mention_end, &context_language, 180 &prevent_preload, &mention_start, &mention_end, &context_language,
179 &thumbnail_url, &caption); 181 &thumbnail_url, &caption, &quick_action_uri, &quick_action_category);
180 if (mention_start != 0 || mention_end != 0) { 182 if (mention_start != 0 || mention_end != 0) {
181 // Sanity check that our selection is non-zero and it is less than 183 // Sanity check that our selection is non-zero and it is less than
182 // 100 characters as that would make contextual search bar hide. 184 // 100 characters as that would make contextual search bar hide.
183 // We also check that there is at least one character overlap between 185 // We also check that there is at least one character overlap between
184 // the new and old selection. 186 // the new and old selection.
185 if (mention_start >= mention_end || 187 if (mention_start >= mention_end ||
186 (mention_end - mention_start) > kContextualSearchMaxSelection || 188 (mention_end - mention_start) > kContextualSearchMaxSelection ||
187 mention_end <= context_->start_offset || 189 mention_end <= context_->start_offset ||
188 mention_start >= context_->end_offset) { 190 mention_start >= context_->end_offset) {
189 start_adjust = 0; 191 start_adjust = 0;
190 end_adjust = 0; 192 end_adjust = 0;
191 } else { 193 } else {
192 start_adjust = mention_start - context_->start_offset; 194 start_adjust = mention_start - context_->start_offset;
193 end_adjust = mention_end - context_->end_offset; 195 end_adjust = mention_end - context_->end_offset;
194 } 196 }
195 } 197 }
196 bool is_invalid = response_code == net::URLFetcher::RESPONSE_CODE_INVALID; 198 bool is_invalid = response_code == net::URLFetcher::RESPONSE_CODE_INVALID;
197 return std::unique_ptr<ResolvedSearchTerm>(new ResolvedSearchTerm( 199 return std::unique_ptr<ResolvedSearchTerm>(new ResolvedSearchTerm(
198 is_invalid, response_code, search_term, display_text, alternate_term, mid, 200 is_invalid, response_code, search_term, display_text, alternate_term, mid,
199 prevent_preload == kDoPreventPreloadValue, start_adjust, end_adjust, 201 prevent_preload == kDoPreventPreloadValue, start_adjust, end_adjust,
200 context_language, thumbnail_url, caption)); 202 context_language, thumbnail_url, caption, quick_action_uri,
203 quick_action_category));
201 } 204 }
202 205
203 std::string ContextualSearchDelegate::BuildRequestUrl(std::string selection) { 206 std::string ContextualSearchDelegate::BuildRequestUrl(std::string selection) {
204 // TODO(donnd): Confirm this is the right way to handle TemplateURL fails. 207 // TODO(donnd): Confirm this is the right way to handle TemplateURL fails.
205 if (!template_url_service_ || 208 if (!template_url_service_ ||
206 !template_url_service_->GetDefaultSearchProvider()) { 209 !template_url_service_->GetDefaultSearchProvider()) {
207 return std::string(); 210 return std::string();
208 } 211 }
209 212
210 std::string selected_text(net::EscapeQueryParamValue(selection, true)); 213 std::string selected_text(net::EscapeQueryParamValue(selection, true));
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 const std::string& response, 446 const std::string& response,
444 std::string* search_term, 447 std::string* search_term,
445 std::string* display_text, 448 std::string* display_text,
446 std::string* alternate_term, 449 std::string* alternate_term,
447 std::string* mid, 450 std::string* mid,
448 std::string* prevent_preload, 451 std::string* prevent_preload,
449 int* mention_start, 452 int* mention_start,
450 int* mention_end, 453 int* mention_end,
451 std::string* lang, 454 std::string* lang,
452 std::string* thumbnail_url, 455 std::string* thumbnail_url,
453 std::string* caption) { 456 std::string* caption,
457 std::string* quick_action_uri,
458 std::string* quick_action_category) {
454 bool contains_xssi_escape = 459 bool contains_xssi_escape =
455 base::StartsWith(response, kXssiEscape, base::CompareCase::SENSITIVE); 460 base::StartsWith(response, kXssiEscape, base::CompareCase::SENSITIVE);
456 const std::string& proper_json = 461 const std::string& proper_json =
457 contains_xssi_escape ? response.substr(sizeof(kXssiEscape) - 1) 462 contains_xssi_escape ? response.substr(sizeof(kXssiEscape) - 1)
458 : response; 463 : response;
459 JSONStringValueDeserializer deserializer(proper_json); 464 JSONStringValueDeserializer deserializer(proper_json);
460 std::unique_ptr<base::Value> root = 465 std::unique_ptr<base::Value> root =
461 deserializer.Deserialize(nullptr, nullptr); 466 deserializer.Deserialize(nullptr, nullptr);
462 const std::unique_ptr<base::DictionaryValue> dict = 467 const std::unique_ptr<base::DictionaryValue> dict =
463 base::DictionaryValue::From(std::move(root)); 468 base::DictionaryValue::From(std::move(root));
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 bool contextual_cards_backend_responded = true; 513 bool contextual_cards_backend_responded = true;
509 dict->GetBoolean("coca_responded", &contextual_cards_backend_responded); 514 dict->GetBoolean("coca_responded", &contextual_cards_backend_responded);
510 if (!contextual_cards_backend_responded) { 515 if (!contextual_cards_backend_responded) {
511 DVLOG(0) << ""; 516 DVLOG(0) << "";
512 DVLOG(0) << "!!! CONTEXTUAL SEARCH WARNING !!!"; 517 DVLOG(0) << "!!! CONTEXTUAL SEARCH WARNING !!!";
513 DVLOG(0) 518 DVLOG(0)
514 << "The Contextual Cards backend did not respond to this " 519 << "The Contextual Cards backend did not respond to this "
515 "request!!! The backend server may not be configured or is down."; 520 "request!!! The backend server may not be configured or is down.";
516 DVLOG(0) << ""; 521 DVLOG(0) << "";
517 } 522 }
523
524 // TODO(donnd): parse information about quick action uri and category.
Theresa 2016/10/20 23:03:52 Donn, is it okay if I assign this TODO to you?
Donn Denman 2016/10/20 23:30:19 Sure!
518 } 525 }
519 } 526 }
520 527
521 // Extract the Start/End of the mentions in the surrounding text 528 // Extract the Start/End of the mentions in the surrounding text
522 // for selection-expansion. 529 // for selection-expansion.
523 void ContextualSearchDelegate::ExtractMentionsStartEnd( 530 void ContextualSearchDelegate::ExtractMentionsStartEnd(
524 const base::ListValue& mentions_list, 531 const base::ListValue& mentions_list,
525 int* startResult, 532 int* startResult,
526 int* endResult) { 533 int* endResult) {
527 int int_value; 534 int int_value;
(...skipping 23 matching lines...) Expand all
551 end_offset -= trim; 558 end_offset -= trim;
552 } 559 }
553 if (result_text.length() > end_offset + padding_each_side_pinned) { 560 if (result_text.length() > end_offset + padding_each_side_pinned) {
554 // Trim the end. 561 // Trim the end.
555 result_text = result_text.substr(0, end_offset + padding_each_side_pinned); 562 result_text = result_text.substr(0, end_offset + padding_each_side_pinned);
556 } 563 }
557 *start = start_offset; 564 *start = start_offset;
558 *end = end_offset; 565 *end = end_offset;
559 return result_text; 566 return result_text;
560 } 567 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698