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

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

Issue 7558014: Add a URL param to indicate group selection in Instant field trial. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed @pkasting's comments Created 9 years, 4 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/keyword_provider.h" 5 #include "chrome/browser/autocomplete/keyword_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/string16.h" 10 #include "base/string16.h"
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 312
313 if (remaining_start < input.length()) 313 if (remaining_start < input.length())
314 remaining_input->assign(input.begin() + remaining_start, input.end()); 314 remaining_input->assign(input.begin() + remaining_start, input.end());
315 315
316 // Return first token as keyword. 316 // Return first token as keyword.
317 return input.substr(0, first_white); 317 return input.substr(0, first_white);
318 } 318 }
319 319
320 // static 320 // static
321 void KeywordProvider::FillInURLAndContents( 321 void KeywordProvider::FillInURLAndContents(
322 Profile* profile,
322 const string16& remaining_input, 323 const string16& remaining_input,
323 const TemplateURL* element, 324 const TemplateURL* element,
324 AutocompleteMatch* match) { 325 AutocompleteMatch* match) {
325 DCHECK(!element->short_name().empty()); 326 DCHECK(!element->short_name().empty());
326 DCHECK(element->url()); 327 DCHECK(element->url());
327 DCHECK(element->url()->IsValid()); 328 DCHECK(element->url()->IsValid());
328 int message_id = element->IsExtensionKeyword() ? 329 int message_id = element->IsExtensionKeyword() ?
329 IDS_EXTENSION_KEYWORD_COMMAND : IDS_KEYWORD_SEARCH; 330 IDS_EXTENSION_KEYWORD_COMMAND : IDS_KEYWORD_SEARCH;
330 if (remaining_input.empty()) { 331 if (remaining_input.empty()) {
331 // Allow extension keyword providers to accept empty string input. This is 332 // Allow extension keyword providers to accept empty string input. This is
(...skipping 15 matching lines...) Expand all
347 AutocompleteMatch::ClassifyLocationInString(0, match->contents.length(), 348 AutocompleteMatch::ClassifyLocationInString(0, match->contents.length(),
348 match->contents.length(), ACMatchClassification::NONE, 349 match->contents.length(), ACMatchClassification::NONE,
349 &match->contents_class); 350 &match->contents_class);
350 } 351 }
351 } else { 352 } else {
352 // Create destination URL by escaping user input and substituting into 353 // Create destination URL by escaping user input and substituting into
353 // keyword template URL. The escaping here handles whitespace in user 354 // keyword template URL. The escaping here handles whitespace in user
354 // input, but we rely on later canonicalization functions to do more 355 // input, but we rely on later canonicalization functions to do more
355 // fixup to make the URL valid if necessary. 356 // fixup to make the URL valid if necessary.
356 DCHECK(element->url()->SupportsReplacement()); 357 DCHECK(element->url()->SupportsReplacement());
357 match->destination_url = GURL(element->url()->ReplaceSearchTerms( 358 match->destination_url = GURL(element->url()->
358 *element, remaining_input, 359 ReplaceSearchTermsUsingProfile(profile, *element, remaining_input,
359 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); 360 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16()));
360 std::vector<size_t> content_param_offsets; 361 std::vector<size_t> content_param_offsets;
361 match->contents.assign(l10n_util::GetStringFUTF16(message_id, 362 match->contents.assign(l10n_util::GetStringFUTF16(message_id,
362 element->short_name(), 363 element->short_name(),
363 remaining_input, 364 remaining_input,
364 &content_param_offsets)); 365 &content_param_offsets));
365 if (content_param_offsets.size() == 2) { 366 if (content_param_offsets.size() == 2) {
366 AutocompleteMatch::ClassifyLocationInString(content_param_offsets[1], 367 AutocompleteMatch::ClassifyLocationInString(content_param_offsets[1],
367 remaining_input.length(), match->contents.length(), 368 remaining_input.length(), match->contents.length(),
368 ACMatchClassification::NONE, &match->contents_class); 369 ACMatchClassification::NONE, &match->contents_class);
369 } else { 370 } else {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 result.fill_into_edit.append(remaining_input); 424 result.fill_into_edit.append(remaining_input);
424 // If we wanted to set |result.inline_autocomplete_offset| correctly, we'd 425 // If we wanted to set |result.inline_autocomplete_offset| correctly, we'd
425 // need CleanUserInputKeyword() to return the amount of adjustment it's made 426 // need CleanUserInputKeyword() to return the amount of adjustment it's made
426 // to the user's input. Because right now inexact keyword matches can't score 427 // to the user's input. Because right now inexact keyword matches can't score
427 // more highly than a "what you typed" match from one of the other providers, 428 // more highly than a "what you typed" match from one of the other providers,
428 // we just don't bother to do this, and leave inline autocompletion off. 429 // we just don't bother to do this, and leave inline autocompletion off.
429 result.inline_autocomplete_offset = string16::npos; 430 result.inline_autocomplete_offset = string16::npos;
430 431
431 // Create destination URL and popup entry content by substituting user input 432 // Create destination URL and popup entry content by substituting user input
432 // into keyword templates. 433 // into keyword templates.
433 FillInURLAndContents(remaining_input, element, &result); 434 FillInURLAndContents(profile_, remaining_input, element, &result);
434 435
435 if (supports_replacement) 436 if (supports_replacement)
436 result.template_url = element; 437 result.template_url = element;
437 result.transition = PageTransition::KEYWORD; 438 result.transition = PageTransition::KEYWORD;
438 439
439 return result; 440 return result;
440 } 441 }
441 442
442 void KeywordProvider::Observe(int type, 443 void KeywordProvider::Observe(int type,
443 const NotificationSource& source, 444 const NotificationSource& source,
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 } 531 }
531 532
532 void KeywordProvider::MaybeEndExtensionKeywordMode() { 533 void KeywordProvider::MaybeEndExtensionKeywordMode() {
533 if (!current_keyword_extension_id_.empty()) { 534 if (!current_keyword_extension_id_.empty()) {
534 ExtensionOmniboxEventRouter::OnInputCancelled( 535 ExtensionOmniboxEventRouter::OnInputCancelled(
535 profile_, current_keyword_extension_id_); 536 profile_, current_keyword_extension_id_);
536 537
537 current_keyword_extension_id_.clear(); 538 current_keyword_extension_id_.clear();
538 } 539 }
539 } 540 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/keyword_provider.h ('k') | chrome/browser/autocomplete/search_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698