OLD | NEW |
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 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 std::string* search_term, | 422 std::string* search_term, |
423 std::string* display_text, | 423 std::string* display_text, |
424 std::string* alternate_term, | 424 std::string* alternate_term, |
425 std::string* prevent_preload, | 425 std::string* prevent_preload, |
426 int* mention_start, | 426 int* mention_start, |
427 int* mention_end) { | 427 int* mention_end) { |
428 bool contains_xssi_escape = response.find(kXssiEscape) == 0; | 428 bool contains_xssi_escape = response.find(kXssiEscape) == 0; |
429 const std::string& proper_json = | 429 const std::string& proper_json = |
430 contains_xssi_escape ? response.substr(strlen(kXssiEscape)) : response; | 430 contains_xssi_escape ? response.substr(strlen(kXssiEscape)) : response; |
431 JSONStringValueDeserializer deserializer(proper_json); | 431 JSONStringValueDeserializer deserializer(proper_json); |
432 scoped_ptr<base::Value> root(deserializer.Deserialize(NULL, NULL)); | 432 scoped_ptr<base::Value> root = deserializer.Deserialize(NULL, NULL); |
433 | 433 |
434 if (root.get() != NULL && root->IsType(base::Value::TYPE_DICTIONARY)) { | 434 if (root.get() != NULL && root->IsType(base::Value::TYPE_DICTIONARY)) { |
435 base::DictionaryValue* dict = | 435 base::DictionaryValue* dict = |
436 static_cast<base::DictionaryValue*>(root.get()); | 436 static_cast<base::DictionaryValue*>(root.get()); |
437 dict->GetString(kContextualSearchPreventPreload, prevent_preload); | 437 dict->GetString(kContextualSearchPreventPreload, prevent_preload); |
438 dict->GetString(kContextualSearchResponseSearchTermParam, search_term); | 438 dict->GetString(kContextualSearchResponseSearchTermParam, search_term); |
439 // For the display_text, if not present fall back to the "search_term". | 439 // For the display_text, if not present fall back to the "search_term". |
440 if (!dict->GetString(kContextualSearchResponseDisplayTextParam, | 440 if (!dict->GetString(kContextualSearchResponseDisplayTextParam, |
441 display_text)) { | 441 display_text)) { |
442 *display_text = *search_term; | 442 *display_text = *search_term; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 end_offset -= trim; | 524 end_offset -= trim; |
525 } | 525 } |
526 if (result_text.length() > end_offset + padding_each_side_pinned) { | 526 if (result_text.length() > end_offset + padding_each_side_pinned) { |
527 // Trim the end. | 527 // Trim the end. |
528 result_text = result_text.substr(0, end_offset + padding_each_side_pinned); | 528 result_text = result_text.substr(0, end_offset + padding_each_side_pinned); |
529 } | 529 } |
530 *start = start_offset; | 530 *start = start_offset; |
531 *end = end_offset; | 531 *end = end_offset; |
532 return result_text; | 532 return result_text; |
533 } | 533 } |
OLD | NEW |