| 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 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 // the value of the given parameters. | 420 // the value of the given parameters. |
| 421 void ContextualSearchDelegate::DecodeSearchTermFromJsonResponse( | 421 void ContextualSearchDelegate::DecodeSearchTermFromJsonResponse( |
| 422 const std::string& response, | 422 const std::string& response, |
| 423 std::string* search_term, | 423 std::string* search_term, |
| 424 std::string* display_text, | 424 std::string* display_text, |
| 425 std::string* alternate_term, | 425 std::string* alternate_term, |
| 426 std::string* prevent_preload, | 426 std::string* prevent_preload, |
| 427 int* mention_start, | 427 int* mention_start, |
| 428 int* mention_end, | 428 int* mention_end, |
| 429 std::string* lang) { | 429 std::string* lang) { |
| 430 bool contains_xssi_escape = response.find(kXssiEscape) == 0; | 430 bool contains_xssi_escape = |
| 431 base::StartsWith(response, kXssiEscape, base::CompareCase::SENSITIVE); |
| 431 const std::string& proper_json = | 432 const std::string& proper_json = |
| 432 contains_xssi_escape ? response.substr(strlen(kXssiEscape)) : response; | 433 contains_xssi_escape ? response.substr(strlen(kXssiEscape)) : response; |
| 433 JSONStringValueDeserializer deserializer(proper_json); | 434 JSONStringValueDeserializer deserializer(proper_json); |
| 434 std::unique_ptr<base::Value> root = deserializer.Deserialize(NULL, NULL); | 435 std::unique_ptr<base::Value> root = deserializer.Deserialize(NULL, NULL); |
| 435 | 436 |
| 436 if (root.get() != NULL && root->IsType(base::Value::TYPE_DICTIONARY)) { | 437 if (root.get() != NULL && root->IsType(base::Value::TYPE_DICTIONARY)) { |
| 437 base::DictionaryValue* dict = | 438 base::DictionaryValue* dict = |
| 438 static_cast<base::DictionaryValue*>(root.get()); | 439 static_cast<base::DictionaryValue*>(root.get()); |
| 439 dict->GetString(kContextualSearchPreventPreload, prevent_preload); | 440 dict->GetString(kContextualSearchPreventPreload, prevent_preload); |
| 440 dict->GetString(kContextualSearchResponseSearchTermParam, search_term); | 441 dict->GetString(kContextualSearchResponseSearchTermParam, search_term); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 end_offset -= trim; | 502 end_offset -= trim; |
| 502 } | 503 } |
| 503 if (result_text.length() > end_offset + padding_each_side_pinned) { | 504 if (result_text.length() > end_offset + padding_each_side_pinned) { |
| 504 // Trim the end. | 505 // Trim the end. |
| 505 result_text = result_text.substr(0, end_offset + padding_each_side_pinned); | 506 result_text = result_text.substr(0, end_offset + padding_each_side_pinned); |
| 506 } | 507 } |
| 507 *start = start_offset; | 508 *start = start_offset; |
| 508 *end = end_offset; | 509 *end = end_offset; |
| 509 return result_text; | 510 return result_text; |
| 510 } | 511 } |
| OLD | NEW |