| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/search_engines/template_url.h" | 5 #include "chrome/browser/search_engines/template_url.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/i18n/icu_string_conversions.h" | 8 #include "base/i18n/icu_string_conversions.h" |
| 9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 // Used if the parameter kOutputEncodingParameter is required. | 71 // Used if the parameter kOutputEncodingParameter is required. |
| 72 static const char kOutputEncodingType[] = "UTF-8"; | 72 static const char kOutputEncodingType[] = "UTF-8"; |
| 73 | 73 |
| 74 // static | 74 // static |
| 75 std::string* TemplateURLRef::google_base_url_ = NULL; | 75 std::string* TemplateURLRef::google_base_url_ = NULL; |
| 76 | 76 |
| 77 TemplateURLRef::TemplateURLRef() { | 77 TemplateURLRef::TemplateURLRef() { |
| 78 Set(std::string(), 0, 0); | 78 Set(std::string(), 0, 0); |
| 79 } | 79 } |
| 80 | 80 |
| 81 TemplateURLRef::TemplateURLRef(const std::string& url, |
| 82 int index_offset, |
| 83 int page_offset) |
| 84 : url_(url), |
| 85 index_offset_(index_offset), |
| 86 page_offset_(page_offset), |
| 87 parsed_(false), |
| 88 valid_(false), |
| 89 supports_replacements_(false) { |
| 90 } |
| 91 |
| 81 void TemplateURLRef::Set(const std::string& url, | 92 void TemplateURLRef::Set(const std::string& url, |
| 82 int index_offset, | 93 int index_offset, |
| 83 int page_offset) { | 94 int page_offset) { |
| 84 url_ = url; | 95 url_ = url; |
| 85 index_offset_ = index_offset; | 96 index_offset_ = index_offset; |
| 86 page_offset_ = page_offset; | 97 page_offset_ = page_offset; |
| 87 InvalidateCachedValues(); | 98 InvalidateCachedValues(); |
| 88 } | 99 } |
| 89 | 100 |
| 101 TemplateURLRef::~TemplateURLRef() { |
| 102 } |
| 103 |
| 90 bool TemplateURLRef::ParseParameter(size_t start, | 104 bool TemplateURLRef::ParseParameter(size_t start, |
| 91 size_t end, | 105 size_t end, |
| 92 std::string* url, | 106 std::string* url, |
| 93 Replacements* replacements) const { | 107 Replacements* replacements) const { |
| 94 DCHECK(start != std::string::npos && | 108 DCHECK(start != std::string::npos && |
| 95 end != std::string::npos && end > start); | 109 end != std::string::npos && end > start); |
| 96 size_t length = end - start - 1; | 110 size_t length = end - start - 1; |
| 97 bool optional = false; | 111 bool optional = false; |
| 98 if ((*url)[end - 1] == kOptional) { | 112 if ((*url)[end - 1] == kOptional) { |
| 99 optional = true; | 113 optional = true; |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 rep.ClearQuery(); | 545 rep.ClearQuery(); |
| 532 rep.ClearRef(); | 546 rep.ClearRef(); |
| 533 return url.ReplaceComponents(rep); | 547 return url.ReplaceComponents(rep); |
| 534 } | 548 } |
| 535 | 549 |
| 536 // static | 550 // static |
| 537 bool TemplateURL::SupportsReplacement(const TemplateURL* turl) { | 551 bool TemplateURL::SupportsReplacement(const TemplateURL* turl) { |
| 538 return turl && turl->url() && turl->url()->SupportsReplacement(); | 552 return turl && turl->url() && turl->url()->SupportsReplacement(); |
| 539 } | 553 } |
| 540 | 554 |
| 555 TemplateURL::TemplateURL() |
| 556 : autogenerate_keyword_(false), |
| 557 keyword_generated_(false), |
| 558 show_in_default_list_(false), |
| 559 safe_for_autoreplace_(false), |
| 560 id_(0), |
| 561 date_created_(base::Time::Now()), |
| 562 usage_count_(0), |
| 563 search_engine_type_(TemplateURLPrepopulateData::SEARCH_ENGINE_OTHER), |
| 564 logo_id_(0), |
| 565 prepopulate_id_(0) { |
| 566 } |
| 567 |
| 568 TemplateURL::~TemplateURL() { |
| 569 } |
| 570 |
| 541 std::wstring TemplateURL::AdjustedShortNameForLocaleDirection() const { | 571 std::wstring TemplateURL::AdjustedShortNameForLocaleDirection() const { |
| 542 std::wstring bidi_safe_short_name; | 572 std::wstring bidi_safe_short_name; |
| 543 if (base::i18n::AdjustStringForLocaleDirection(short_name_, | 573 if (base::i18n::AdjustStringForLocaleDirection(short_name_, |
| 544 &bidi_safe_short_name)) | 574 &bidi_safe_short_name)) |
| 545 return bidi_safe_short_name; | 575 return bidi_safe_short_name; |
| 546 return short_name_; | 576 return short_name_; |
| 547 } | 577 } |
| 548 | 578 |
| 549 void TemplateURL::SetSuggestionsURL(const std::string& suggestions_url, | 579 void TemplateURL::SetSuggestionsURL(const std::string& suggestions_url, |
| 550 int index_offset, | 580 int index_offset, |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 } | 650 } |
| 621 | 651 |
| 622 std::string TemplateURL::GetExtensionId() const { | 652 std::string TemplateURL::GetExtensionId() const { |
| 623 DCHECK(IsExtensionKeyword()); | 653 DCHECK(IsExtensionKeyword()); |
| 624 return GURL(url_.url()).host(); | 654 return GURL(url_.url()).host(); |
| 625 } | 655 } |
| 626 | 656 |
| 627 bool TemplateURL::IsExtensionKeyword() const { | 657 bool TemplateURL::IsExtensionKeyword() const { |
| 628 return GURL(url_.url()).SchemeIs(chrome::kExtensionScheme); | 658 return GURL(url_.url()).SchemeIs(chrome::kExtensionScheme); |
| 629 } | 659 } |
| OLD | NEW |