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

Side by Side Diff: chrome/browser/template_url.cc

Issue 14419: Porting in browser/webdata and template_url. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 12 years 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/browser.vcproj ('k') | chrome/browser/template_url_model.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 std::wstring parameter(url->substr(start + 1, length)); 95 std::wstring parameter(url->substr(start + 1, length));
96 // Remove the parameter from the string. 96 // Remove the parameter from the string.
97 url->erase(start, end - start + 1); 97 url->erase(start, end - start + 1);
98 if (parameter == kSearchTermsParameter) { 98 if (parameter == kSearchTermsParameter) {
99 replacements->push_back(Replacement(SEARCH_TERMS, static_cast<int>(start))); 99 replacements->push_back(Replacement(SEARCH_TERMS, static_cast<int>(start)));
100 } else if (parameter == kCountParameter) { 100 } else if (parameter == kCountParameter) {
101 if (!optional) 101 if (!optional)
102 url->insert(start, kDefaultCount); 102 url->insert(start, kDefaultCount);
103 } else if (parameter == kStartIndexParameter) { 103 } else if (parameter == kStartIndexParameter) {
104 if (!optional) { 104 if (!optional) {
105 wchar_t start_string[12]; 105 url->insert(start, IntToWString(index_offset_));
106 if (swprintf_s(start_string, L"%d", index_offset_) <= 0)
107 return false;
108 url->insert(start, start_string);
109 } 106 }
110 } else if (parameter == kStartPageParameter) { 107 } else if (parameter == kStartPageParameter) {
111 if (!optional) { 108 if (!optional) {
112 wchar_t start_string[12]; 109 url->insert(start, IntToWString(page_offset_));
113 if (swprintf_s(start_string, L"%d", page_offset_) <= 0)
114 return false;
115 url->insert(start, start_string);
116 } 110 }
117 } else if (parameter == kLanguageParameter) { 111 } else if (parameter == kLanguageParameter) {
118 replacements->push_back(Replacement(LANGUAGE, static_cast<int>(start))); 112 replacements->push_back(Replacement(LANGUAGE, static_cast<int>(start)));
119 } else if (parameter == kInputEncodingParameter) { 113 } else if (parameter == kInputEncodingParameter) {
120 replacements->push_back(Replacement(ENCODING, static_cast<int>(start))); 114 replacements->push_back(Replacement(ENCODING, static_cast<int>(start)));
121 } else if (parameter == kOutputEncodingParameter) { 115 } else if (parameter == kOutputEncodingParameter) {
122 if (!optional) 116 if (!optional)
123 url->insert(start, kOutputEncodingType); 117 url->insert(start, kOutputEncodingType);
124 } else if (parameter == kGoogleAcceptedSuggestionParameter) { 118 } else if (parameter == kGoogleAcceptedSuggestionParameter) {
125 replacements->push_back(Replacement(GOOGLE_ACCEPTED_SUGGESTION, 119 replacements->push_back(Replacement(GOOGLE_ACCEPTED_SUGGESTION,
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 } 194 }
201 195
202 void TemplateURLRef::ParseHostAndSearchTermKey() const { 196 void TemplateURLRef::ParseHostAndSearchTermKey() const {
203 std::wstring url_string = url_; 197 std::wstring url_string = url_;
204 ReplaceSubstringsAfterOffset(&url_string, 0, kGoogleBaseURLParameterFull, 198 ReplaceSubstringsAfterOffset(&url_string, 0, kGoogleBaseURLParameterFull,
205 GoogleBaseURLValue()); 199 GoogleBaseURLValue());
206 ReplaceSubstringsAfterOffset(&url_string, 0, 200 ReplaceSubstringsAfterOffset(&url_string, 0,
207 kGoogleBaseSuggestURLParameterFull, 201 kGoogleBaseSuggestURLParameterFull,
208 GoogleBaseSuggestURLValue()); 202 GoogleBaseSuggestURLValue());
209 203
210 GURL url(url_string); 204 GURL url(WideToUTF8(url_string));
211 if (!url.is_valid()) 205 if (!url.is_valid())
212 return; 206 return;
213 207
214 std::string query_string = url.query(); 208 std::string query_string = url.query();
215 if (query_string.empty()) 209 if (query_string.empty())
216 return; 210 return;
217 211
218 url_parse::Component query, key, value; 212 url_parse::Component query, key, value;
219 query.len = static_cast<int>(query_string.size()); 213 query.len = static_cast<int>(query_string.size());
220 while (url_parse::ExtractQueryKeyValue(query_string.c_str(), &query, &key, 214 while (url_parse::ExtractQueryKeyValue(query_string.c_str(), &query, &key,
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 440
447 // Returns the value to use for replacements of type GOOGLE_BASE_SUGGEST_URL. 441 // Returns the value to use for replacements of type GOOGLE_BASE_SUGGEST_URL.
448 // static 442 // static
449 std::wstring TemplateURLRef::GoogleBaseSuggestURLValue() { 443 std::wstring TemplateURLRef::GoogleBaseSuggestURLValue() {
450 // The suggest base URL we want at the end is something like 444 // The suggest base URL we want at the end is something like
451 // "http://clients1.google.TLD/complete/". The key bit we want from the 445 // "http://clients1.google.TLD/complete/". The key bit we want from the
452 // original Google base URL is the TLD. 446 // original Google base URL is the TLD.
453 447
454 // Start with the Google base URL. 448 // Start with the Google base URL.
455 const GURL base_url(google_base_url_ ? 449 const GURL base_url(google_base_url_ ?
456 GURL(*google_base_url_) : GoogleURLTracker::GoogleURL()); 450 GURL(WideToUTF8(*google_base_url_)) : GoogleURLTracker::GoogleURL());
457 DCHECK(base_url.is_valid()); 451 DCHECK(base_url.is_valid());
458 452
459 // Change "www." to "clients1." in the hostname. If no "www." was found, just 453 // Change "www." to "clients1." in the hostname. If no "www." was found, just
460 // prepend "clients1.". 454 // prepend "clients1.".
461 const std::string base_host(base_url.host()); 455 const std::string base_host(base_url.host());
462 GURL::Replacements repl; 456 GURL::Replacements repl;
463 const std::string suggest_host("clients1." + 457 const std::string suggest_host("clients1." +
464 (base_host.compare(0, 4, "www.") ? base_host : base_host.substr(4))); 458 (base_host.compare(0, 4, "www.") ? base_host : base_host.substr(4)));
465 repl.SetHostStr(suggest_host); 459 repl.SetHostStr(suggest_host);
466 460
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 return GURL(); 549 return GURL();
556 } 550 }
557 551
558 void TemplateURL::InvalidateCachedValues() const { 552 void TemplateURL::InvalidateCachedValues() const {
559 url_.InvalidateCachedValues(); 553 url_.InvalidateCachedValues();
560 suggestions_url_.InvalidateCachedValues(); 554 suggestions_url_.InvalidateCachedValues();
561 if (autogenerate_keyword_) 555 if (autogenerate_keyword_)
562 keyword_.clear(); 556 keyword_.clear();
563 } 557 }
564 558
OLDNEW
« no previous file with comments | « chrome/browser/browser.vcproj ('k') | chrome/browser/template_url_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698