OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/template_url.h" | 5 #include "chrome/browser/template_url.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/rlz/rlz.h" | 10 #include "chrome/browser/rlz/rlz.h" |
11 #include "chrome/browser/google_url_tracker.h" | 11 #include "chrome/browser/google_url_tracker.h" |
12 #include "chrome/browser/template_url_model.h" | 12 #include "chrome/browser/template_url_model.h" |
13 #include "chrome/common/gfx/favicon_size.h" | 13 #include "chrome/common/gfx/favicon_size.h" |
| 14 #include "chrome/common/l10n_util.h" |
14 #include "net/base/escape.h" | 15 #include "net/base/escape.h" |
15 | 16 |
16 // The TemplateURLRef has any number of terms that need to be replaced. Each of | 17 // The TemplateURLRef has any number of terms that need to be replaced. Each of |
17 // the terms is enclosed in braces. If the character preceeding the final | 18 // the terms is enclosed in braces. If the character preceeding the final |
18 // brace is a ?, it indicates the term is optional and can be replaced with | 19 // brace is a ?, it indicates the term is optional and can be replaced with |
19 // an empty string. | 20 // an empty string. |
20 static const wchar_t kStartParameter = '{'; | 21 static const wchar_t kStartParameter = '{'; |
21 static const wchar_t kEndParameter = '}'; | 22 static const wchar_t kEndParameter = '}'; |
22 static const wchar_t kOptional = '?'; | 23 static const wchar_t kOptional = '?'; |
23 | 24 |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 int page_offset) { | 497 int page_offset) { |
497 suggestions_url_.Set(suggestions_url, index_offset, page_offset); | 498 suggestions_url_.Set(suggestions_url, index_offset, page_offset); |
498 } | 499 } |
499 | 500 |
500 void TemplateURL::SetURL(const std::wstring& url, | 501 void TemplateURL::SetURL(const std::wstring& url, |
501 int index_offset, | 502 int index_offset, |
502 int page_offset) { | 503 int page_offset) { |
503 url_.Set(url, index_offset, page_offset); | 504 url_.Set(url, index_offset, page_offset); |
504 } | 505 } |
505 | 506 |
| 507 void TemplateURL::set_keyword(const std::wstring& keyword) { |
| 508 // Case sensitive keyword matching is confusing. As such, we force all |
| 509 // keywords to be lower case. |
| 510 keyword_ = l10n_util::ToLower(keyword); |
| 511 autogenerate_keyword_ = false; |
| 512 } |
| 513 |
506 const std::wstring& TemplateURL::keyword() const { | 514 const std::wstring& TemplateURL::keyword() const { |
507 if (autogenerate_keyword_ && keyword_.empty()) { | 515 if (autogenerate_keyword_ && keyword_.empty()) { |
508 // Generate a keyword and cache it. | 516 // Generate a keyword and cache it. |
509 keyword_ = TemplateURLModel::GenerateKeyword( | 517 keyword_ = TemplateURLModel::GenerateKeyword( |
510 TemplateURLModel::GenerateSearchURL(this).GetWithEmptyPath(), true); | 518 TemplateURLModel::GenerateSearchURL(this).GetWithEmptyPath(), true); |
511 } | 519 } |
512 return keyword_; | 520 return keyword_; |
513 } | 521 } |
514 | 522 |
515 bool TemplateURL::ShowInDefaultList() const { | 523 bool TemplateURL::ShowInDefaultList() const { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 return GURL(); | 555 return GURL(); |
548 } | 556 } |
549 | 557 |
550 void TemplateURL::InvalidateCachedValues() const { | 558 void TemplateURL::InvalidateCachedValues() const { |
551 url_.InvalidateCachedValues(); | 559 url_.InvalidateCachedValues(); |
552 suggestions_url_.InvalidateCachedValues(); | 560 suggestions_url_.InvalidateCachedValues(); |
553 if (autogenerate_keyword_) | 561 if (autogenerate_keyword_) |
554 keyword_.clear(); | 562 keyword_.clear(); |
555 } | 563 } |
556 | 564 |
OLD | NEW |