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

Side by Side Diff: chrome/browser/autocomplete/search_provider.cc

Issue 10908044: Refuse invalid SearchProvider and OSDD suggest URLs; etc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Bail on invalid TemplateURLRefs in searching and OSDD parsing. Created 8 years, 3 months 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/autocomplete/search_provider.h" 5 #include "chrome/browser/autocomplete/search_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 // Sort in descending relevance order. 305 // Sort in descending relevance order.
306 return a.relevance() > b.relevance(); 306 return a.relevance() > b.relevance();
307 } 307 }
308 }; 308 };
309 309
310 void SearchProvider::Run() { 310 void SearchProvider::Run() {
311 // Start a new request with the current input. 311 // Start a new request with the current input.
312 DCHECK(!done_); 312 DCHECK(!done_);
313 suggest_results_pending_ = 0; 313 suggest_results_pending_ = 0;
314 time_suggest_request_sent_ = base::TimeTicks::Now(); 314 time_suggest_request_sent_ = base::TimeTicks::Now();
315 const TemplateURL* default_url = providers_.GetDefaultProviderURL(); 315
316 if (default_url && !default_url->suggestions_url().empty()) { 316 default_fetcher_.reset(CreateSuggestFetcher(kDefaultProviderURLFetcherID,
317 suggest_results_pending_++; 317 providers_.GetDefaultProviderURL(), input_.text()));
318 LogOmniboxSuggestRequest(REQUEST_SENT); 318 keyword_fetcher_.reset(CreateSuggestFetcher(kKeywordProviderURLFetcherID,
319 default_fetcher_.reset(CreateSuggestFetcher(kDefaultProviderURLFetcherID, 319 providers_.GetKeywordProviderURL(), keyword_input_text_));
320 default_url->suggestions_url_ref(), input_.text()));
321 }
322 const TemplateURL* keyword_url = providers_.GetKeywordProviderURL();
323 if (keyword_url && !keyword_url->suggestions_url().empty()) {
324 suggest_results_pending_++;
325 LogOmniboxSuggestRequest(REQUEST_SENT);
326 keyword_fetcher_.reset(CreateSuggestFetcher(kKeywordProviderURLFetcherID,
327 keyword_url->suggestions_url_ref(), keyword_input_text_));
328 }
329 320
330 // Both the above can fail if the providers have been modified or deleted 321 // Both the above can fail if the providers have been modified or deleted
331 // since the query began. 322 // since the query began.
332 if (suggest_results_pending_ == 0) { 323 if (suggest_results_pending_ == 0) {
333 UpdateDone(); 324 UpdateDone();
334 // We only need to update the listener if we're actually done. 325 // We only need to update the listener if we're actually done.
335 if (done_) 326 if (done_)
336 listener_->OnProviderUpdate(false); 327 listener_->OnProviderUpdate(false);
337 } 328 }
338 } 329 }
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 void SearchProvider::ApplyCalculatedNavigationRelevance(NavigationResults* list, 625 void SearchProvider::ApplyCalculatedNavigationRelevance(NavigationResults* list,
635 bool is_keyword) { 626 bool is_keyword) {
636 for (size_t i = 0; i < list->size(); ++i) { 627 for (size_t i = 0; i < list->size(); ++i) {
637 (*list)[i].set_relevance(CalculateRelevanceForNavigation(is_keyword) + 628 (*list)[i].set_relevance(CalculateRelevanceForNavigation(is_keyword) +
638 (list->size() - i - 1)); 629 (list->size() - i - 1));
639 } 630 }
640 } 631 }
641 632
642 net::URLFetcher* SearchProvider::CreateSuggestFetcher( 633 net::URLFetcher* SearchProvider::CreateSuggestFetcher(
643 int id, 634 int id,
644 const TemplateURLRef& suggestions_url, 635 const TemplateURL* template_url,
645 const string16& text) { 636 const string16& text) {
646 DCHECK(suggestions_url.SupportsReplacement()); 637 if (!template_url || template_url->suggestions_url().empty() ||
647 net::URLFetcher* fetcher = net::URLFetcher::Create(id, 638 !template_url->suggestions_url_ref().IsValid())
Peter Kasting 2012/09/05 23:31:27 You don't need to check IsValid(); if it fails, Re
msw 2012/09/06 20:02:29 Done.
648 GURL(suggestions_url.ReplaceSearchTerms( 639 return NULL;
649 TemplateURLRef::SearchTermsArgs(text))), 640
650 net::URLFetcher::GET, this); 641 // Bail if the suggestion URL is invalid with the given replacements.
642 GURL suggest_url(template_url->suggestions_url_ref().ReplaceSearchTerms(
643 TemplateURLRef::SearchTermsArgs(text)));
Peter Kasting 2012/09/05 23:31:27 Nit: Indent 4 from beginning of line
msw 2012/09/06 20:02:29 Done.
644 if (!suggest_url.is_valid())
645 return NULL;
646
647 suggest_results_pending_++;
648 LogOmniboxSuggestRequest(REQUEST_SENT);
649
650 net::URLFetcher* fetcher =
651 net::URLFetcher::Create(id, suggest_url, net::URLFetcher::GET, this);
651 fetcher->SetRequestContext(profile_->GetRequestContext()); 652 fetcher->SetRequestContext(profile_->GetRequestContext());
652 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES); 653 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES);
653 fetcher->Start(); 654 fetcher->Start();
654 return fetcher; 655 return fetcher;
655 } 656 }
656 657
657 bool SearchProvider::ParseSuggestResults(Value* root_val, bool is_keyword) { 658 bool SearchProvider::ParseSuggestResults(Value* root_val, bool is_keyword) {
658 // TODO(pkasting): Fix |have_suggest_results_|; see http://crbug.com/130631 659 // TODO(pkasting): Fix |have_suggest_results_|; see http://crbug.com/130631
659 have_suggest_results_ = false; 660 have_suggest_results_ = false;
660 661
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after
1231 ACMatchClassification::NONE, &match.description_class); 1232 ACMatchClassification::NONE, &match.description_class);
1232 return match; 1233 return match;
1233 } 1234 }
1234 1235
1235 void SearchProvider::UpdateDone() { 1236 void SearchProvider::UpdateDone() {
1236 // We're done when the timer isn't running, there are no suggest queries 1237 // We're done when the timer isn't running, there are no suggest queries
1237 // pending, and we're not waiting on instant. 1238 // pending, and we're not waiting on instant.
1238 done_ = (!timer_.IsRunning() && (suggest_results_pending_ == 0) && 1239 done_ = (!timer_.IsRunning() && (suggest_results_pending_ == 0) &&
1239 (instant_finalized_ || !InstantController::IsEnabled(profile_))); 1240 (instant_finalized_ || !InstantController::IsEnabled(profile_)));
1240 } 1241 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698