OLD | NEW |
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/autocomplete_edit.h" | 5 #include "chrome/browser/autocomplete/autocomplete_edit.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 bool AutocompleteEditModel::CurrentTextIsURL() const { | 312 bool AutocompleteEditModel::CurrentTextIsURL() const { |
313 // If !user_input_in_progress_, the permanent text is showing, which should | 313 // If !user_input_in_progress_, the permanent text is showing, which should |
314 // always be a URL, so no further checking is needed. By avoiding checking in | 314 // always be a URL, so no further checking is needed. By avoiding checking in |
315 // this case, we avoid calling into the autocomplete providers, and thus | 315 // this case, we avoid calling into the autocomplete providers, and thus |
316 // initializing the history system, as long as possible, which speeds startup. | 316 // initializing the history system, as long as possible, which speeds startup. |
317 if (!user_input_in_progress_) | 317 if (!user_input_in_progress_) |
318 return true; | 318 return true; |
319 | 319 |
320 AutocompleteMatch match; | 320 AutocompleteMatch match; |
321 GetInfoForCurrentText(&match, NULL); | 321 GetInfoForCurrentText(&match, NULL); |
322 return match.transition == PageTransition::TYPED; | 322 return match.transition == content::PAGE_TRANSITION_TYPED; |
323 } | 323 } |
324 | 324 |
325 AutocompleteMatch::Type AutocompleteEditModel::CurrentTextType() const { | 325 AutocompleteMatch::Type AutocompleteEditModel::CurrentTextType() const { |
326 AutocompleteMatch match; | 326 AutocompleteMatch match; |
327 GetInfoForCurrentText(&match, NULL); | 327 GetInfoForCurrentText(&match, NULL); |
328 return match.type; | 328 return match.type; |
329 } | 329 } |
330 | 330 |
331 void AutocompleteEditModel::AdjustTextForCopy(int sel_min, | 331 void AutocompleteEditModel::AdjustTextForCopy(int sel_min, |
332 bool is_all_selected, | 332 bool is_all_selected, |
(...skipping 14 matching lines...) Expand all Loading... |
347 *write_url = true; | 347 *write_url = true; |
348 return; | 348 return; |
349 } | 349 } |
350 | 350 |
351 // We can't use CurrentTextIsURL() or GetDataForURLExport() because right now | 351 // We can't use CurrentTextIsURL() or GetDataForURLExport() because right now |
352 // the user is probably holding down control to cause the copy, which will | 352 // the user is probably holding down control to cause the copy, which will |
353 // screw up our calculation of the desired_tld. | 353 // screw up our calculation of the desired_tld. |
354 AutocompleteMatch match; | 354 AutocompleteMatch match; |
355 profile_->GetAutocompleteClassifier()->Classify(*text, string16(), | 355 profile_->GetAutocompleteClassifier()->Classify(*text, string16(), |
356 KeywordIsSelected(), true, &match, NULL); | 356 KeywordIsSelected(), true, &match, NULL); |
357 if (match.transition != PageTransition::TYPED) | 357 if (match.transition != content::PAGE_TRANSITION_TYPED) |
358 return; | 358 return; |
359 *url = match.destination_url; | 359 *url = match.destination_url; |
360 | 360 |
361 // Prefix the text with 'http://' if the text doesn't start with 'http://', | 361 // Prefix the text with 'http://' if the text doesn't start with 'http://', |
362 // the text parses as a url with a scheme of http, the user selected the | 362 // the text parses as a url with a scheme of http, the user selected the |
363 // entire host, and the user hasn't edited the host or manually removed the | 363 // entire host, and the user hasn't edited the host or manually removed the |
364 // scheme. | 364 // scheme. |
365 GURL perm_url(PermanentURL()); | 365 GURL perm_url(PermanentURL()); |
366 if (perm_url.SchemeIs(chrome::kHttpScheme) && | 366 if (perm_url.SchemeIs(chrome::kHttpScheme) && |
367 url->SchemeIs(chrome::kHttpScheme) && perm_url.host() == url->host()) { | 367 url->SchemeIs(chrome::kHttpScheme) && perm_url.host() == url->host()) { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 void AutocompleteEditModel::AcceptInput(WindowOpenDisposition disposition, | 441 void AutocompleteEditModel::AcceptInput(WindowOpenDisposition disposition, |
442 bool for_drop) { | 442 bool for_drop) { |
443 // Get the URL and transition type for the selected entry. | 443 // Get the URL and transition type for the selected entry. |
444 AutocompleteMatch match; | 444 AutocompleteMatch match; |
445 GURL alternate_nav_url; | 445 GURL alternate_nav_url; |
446 GetInfoForCurrentText(&match, &alternate_nav_url); | 446 GetInfoForCurrentText(&match, &alternate_nav_url); |
447 | 447 |
448 if (!match.destination_url.is_valid()) | 448 if (!match.destination_url.is_valid()) |
449 return; | 449 return; |
450 | 450 |
451 if ((match.transition == PageTransition::TYPED) && (match.destination_url == | 451 if ((match.transition == content::PAGE_TRANSITION_TYPED) && |
452 URLFixerUpper::FixupURL(UTF16ToUTF8(permanent_text_), std::string()))) { | 452 (match.destination_url == |
| 453 URLFixerUpper::FixupURL(UTF16ToUTF8(permanent_text_), std::string()))) { |
453 // When the user hit enter on the existing permanent URL, treat it like a | 454 // When the user hit enter on the existing permanent URL, treat it like a |
454 // reload for scoring purposes. We could detect this by just checking | 455 // reload for scoring purposes. We could detect this by just checking |
455 // user_input_in_progress_, but it seems better to treat "edits" that end | 456 // user_input_in_progress_, but it seems better to treat "edits" that end |
456 // up leaving the URL unchanged (e.g. deleting the last character and then | 457 // up leaving the URL unchanged (e.g. deleting the last character and then |
457 // retyping it) as reloads too. We exclude non-TYPED transitions because if | 458 // retyping it) as reloads too. We exclude non-TYPED transitions because if |
458 // the transition is GENERATED, the user input something that looked | 459 // the transition is GENERATED, the user input something that looked |
459 // different from the current URL, even if it wound up at the same place | 460 // different from the current URL, even if it wound up at the same place |
460 // (e.g. manually retyping the same search query), and it seems wrong to | 461 // (e.g. manually retyping the same search query), and it seems wrong to |
461 // treat this as a reload. | 462 // treat this as a reload. |
462 match.transition = PageTransition::RELOAD; | 463 match.transition = content::PAGE_TRANSITION_RELOAD; |
463 } else if (for_drop || ((paste_state_ != NONE) && | 464 } else if (for_drop || ((paste_state_ != NONE) && |
464 match.is_history_what_you_typed_match)) { | 465 match.is_history_what_you_typed_match)) { |
465 // When the user pasted in a URL and hit enter, score it like a link click | 466 // When the user pasted in a URL and hit enter, score it like a link click |
466 // rather than a normal typed URL, so it doesn't get inline autocompleted | 467 // rather than a normal typed URL, so it doesn't get inline autocompleted |
467 // as aggressively later. | 468 // as aggressively later. |
468 match.transition = PageTransition::LINK; | 469 match.transition = content::PAGE_TRANSITION_LINK; |
469 } | 470 } |
470 | 471 |
471 if (match.template_url && match.template_url->url() && | 472 if (match.template_url && match.template_url->url() && |
472 match.template_url->url()->HasGoogleBaseURLs()) { | 473 match.template_url->url()->HasGoogleBaseURLs()) { |
473 GoogleURLTracker::GoogleURLSearchCommitted(); | 474 GoogleURLTracker::GoogleURLSearchCommitted(); |
474 #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) | 475 #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) |
475 // TODO(pastarmovj): Remove these metrics once we have proven that (close | 476 // TODO(pastarmovj): Remove these metrics once we have proven that (close |
476 // to) none searches that should have RLZ are sent out without one. | 477 // to) none searches that should have RLZ are sent out without one. |
477 match.template_url->url()->CollectRLZMetrics(); | 478 match.template_url->url()->CollectRLZMetrics(); |
478 #endif | 479 #endif |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 profile_, match.template_url->GetExtensionId(), | 526 profile_, match.template_url->GetExtensionId(), |
526 UTF16ToUTF8(match.fill_into_edit.substr(prefix_length))); | 527 UTF16ToUTF8(match.fill_into_edit.substr(prefix_length))); |
527 view_->RevertAll(); | 528 view_->RevertAll(); |
528 return; | 529 return; |
529 } | 530 } |
530 | 531 |
531 if (template_url) { | 532 if (template_url) { |
532 UserMetrics::RecordAction(UserMetricsAction("AcceptedKeyword")); | 533 UserMetrics::RecordAction(UserMetricsAction("AcceptedKeyword")); |
533 template_url_service->IncrementUsageCount(template_url); | 534 template_url_service->IncrementUsageCount(template_url); |
534 | 535 |
535 if (match.transition == PageTransition::KEYWORD || | 536 if (match.transition == content::PAGE_TRANSITION_KEYWORD || |
536 match.transition == PageTransition::KEYWORD_GENERATED) { | 537 match.transition == content::PAGE_TRANSITION_KEYWORD_GENERATED) { |
537 // NOTE: Non-prepopulated engines will all have ID 0, which is fine as | 538 // NOTE: Non-prepopulated engines will all have ID 0, which is fine as |
538 // the prepopulate IDs start at 1. Distribution-specific engines will | 539 // the prepopulate IDs start at 1. Distribution-specific engines will |
539 // all have IDs above the maximum, and will be automatically lumped | 540 // all have IDs above the maximum, and will be automatically lumped |
540 // together in an "overflow" bucket in the histogram. | 541 // together in an "overflow" bucket in the histogram. |
541 UMA_HISTOGRAM_ENUMERATION( | 542 UMA_HISTOGRAM_ENUMERATION( |
542 "Omnibox.SearchEngine", template_url->prepopulate_id(), | 543 "Omnibox.SearchEngine", template_url->prepopulate_id(), |
543 TemplateURLPrepopulateData::kMaxPrepopulatedEngineID); | 544 TemplateURLPrepopulateData::kMaxPrepopulatedEngineID); |
544 } | 545 } |
545 } | 546 } |
546 | 547 |
547 // NOTE: We purposefully don't increment the usage count of the default | 548 // NOTE: We purposefully don't increment the usage count of the default |
548 // search engine, if applicable; see comments in template_url.h. | 549 // search engine, if applicable; see comments in template_url.h. |
549 } | 550 } |
550 | 551 |
551 if (match.transition == PageTransition::GENERATED && match.template_url) { | 552 if (match.transition == content::PAGE_TRANSITION_GENERATED && |
| 553 match.template_url) { |
552 // See comment above. | 554 // See comment above. |
553 UMA_HISTOGRAM_ENUMERATION( | 555 UMA_HISTOGRAM_ENUMERATION( |
554 "Omnibox.SearchEngine", match.template_url->prepopulate_id(), | 556 "Omnibox.SearchEngine", match.template_url->prepopulate_id(), |
555 TemplateURLPrepopulateData::kMaxPrepopulatedEngineID); | 557 TemplateURLPrepopulateData::kMaxPrepopulatedEngineID); |
556 } | 558 } |
557 | 559 |
558 if (disposition != NEW_BACKGROUND_TAB) { | 560 if (disposition != NEW_BACKGROUND_TAB) { |
559 in_revert_ = true; | 561 in_revert_ = true; |
560 view_->RevertAll(); // Revert the box to its unedited state | 562 view_->RevertAll(); // Revert the box to its unedited state |
561 } | 563 } |
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1054 // static | 1056 // static |
1055 bool AutocompleteEditModel::IsSpaceCharForAcceptingKeyword(wchar_t c) { | 1057 bool AutocompleteEditModel::IsSpaceCharForAcceptingKeyword(wchar_t c) { |
1056 switch (c) { | 1058 switch (c) { |
1057 case 0x0020: // Space | 1059 case 0x0020: // Space |
1058 case 0x3000: // Ideographic Space | 1060 case 0x3000: // Ideographic Space |
1059 return true; | 1061 return true; |
1060 default: | 1062 default: |
1061 return false; | 1063 return false; |
1062 } | 1064 } |
1063 } | 1065 } |
OLD | NEW |