OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "components/omnibox/browser/omnibox_edit_model.h" | 5 #include "components/omnibox/browser/omnibox_edit_model.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 } | 529 } |
530 | 530 |
531 void OmniboxEditModel::PasteAndGo(const base::string16& text) { | 531 void OmniboxEditModel::PasteAndGo(const base::string16& text) { |
532 DCHECK(CanPasteAndGo(text)); | 532 DCHECK(CanPasteAndGo(text)); |
533 UMA_HISTOGRAM_COUNTS("Omnibox.PasteAndGo", 1); | 533 UMA_HISTOGRAM_COUNTS("Omnibox.PasteAndGo", 1); |
534 | 534 |
535 view_->RevertAll(); | 535 view_->RevertAll(); |
536 AutocompleteMatch match; | 536 AutocompleteMatch match; |
537 GURL alternate_nav_url; | 537 GURL alternate_nav_url; |
538 ClassifyStringForPasteAndGo(text, &match, &alternate_nav_url); | 538 ClassifyStringForPasteAndGo(text, &match, &alternate_nav_url); |
539 view_->OpenMatch(match, CURRENT_TAB, alternate_nav_url, text, | 539 view_->OpenMatch(match, WindowOpenDisposition::CURRENT_TAB, alternate_nav_url, |
540 OmniboxPopupModel::kNoMatch); | 540 text, OmniboxPopupModel::kNoMatch); |
541 } | 541 } |
542 | 542 |
543 bool OmniboxEditModel::IsPasteAndSearch(const base::string16& text) const { | 543 bool OmniboxEditModel::IsPasteAndSearch(const base::string16& text) const { |
544 AutocompleteMatch match; | 544 AutocompleteMatch match; |
545 ClassifyStringForPasteAndGo(text, &match, nullptr); | 545 ClassifyStringForPasteAndGo(text, &match, nullptr); |
546 return AutocompleteMatch::IsSearchType(match.type); | 546 return AutocompleteMatch::IsSearchType(match.type); |
547 } | 547 } |
548 | 548 |
549 void OmniboxEditModel::AcceptInput(WindowOpenDisposition disposition, | 549 void OmniboxEditModel::AcceptInput(WindowOpenDisposition disposition, |
550 bool for_drop) { | 550 bool for_drop) { |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
701 base::string16::npos, | 701 base::string16::npos, |
702 elapsed_time_since_last_change_to_default_match, | 702 elapsed_time_since_last_change_to_default_match, |
703 dropdown_ignored ? fake_single_entry_result : result()); | 703 dropdown_ignored ? fake_single_entry_result : result()); |
704 DCHECK(dropdown_ignored || | 704 DCHECK(dropdown_ignored || |
705 (log.elapsed_time_since_user_first_modified_omnibox >= | 705 (log.elapsed_time_since_user_first_modified_omnibox >= |
706 log.elapsed_time_since_last_change_to_default_match)) | 706 log.elapsed_time_since_last_change_to_default_match)) |
707 << "We should've got the notification that the user modified the " | 707 << "We should've got the notification that the user modified the " |
708 << "omnibox text at same time or before the most recent time the " | 708 << "omnibox text at same time or before the most recent time the " |
709 << "default match changed."; | 709 << "default match changed."; |
710 | 710 |
711 if ((disposition == CURRENT_TAB) && client_->CurrentPageExists()) { | 711 if ((disposition == WindowOpenDisposition::CURRENT_TAB) && |
| 712 client_->CurrentPageExists()) { |
712 // If we know the destination is being opened in the current tab, | 713 // If we know the destination is being opened in the current tab, |
713 // we can easily get the tab ID. (If it's being opened in a new | 714 // we can easily get the tab ID. (If it's being opened in a new |
714 // tab, we don't know the tab ID yet.) | 715 // tab, we don't know the tab ID yet.) |
715 log.tab_id = client_->GetSessionID().id(); | 716 log.tab_id = client_->GetSessionID().id(); |
716 } | 717 } |
717 autocomplete_controller()->AddProvidersInfo(&log.providers_info); | 718 autocomplete_controller()->AddProvidersInfo(&log.providers_info); |
718 client_->OnURLOpenedFromOmnibox(&log); | 719 client_->OnURLOpenedFromOmnibox(&log); |
719 OmniboxEventGlobalTracker::GetInstance()->OnURLOpened(&log); | 720 OmniboxEventGlobalTracker::GetInstance()->OnURLOpened(&log); |
720 LOCAL_HISTOGRAM_BOOLEAN("Omnibox.EventCount", true); | 721 LOCAL_HISTOGRAM_BOOLEAN("Omnibox.EventCount", true); |
721 if (!last_omnibox_focus_.is_null()) { | 722 if (!last_omnibox_focus_.is_null()) { |
722 // Only record focus to open time when a focus actually happened (as | 723 // Only record focus to open time when a focus actually happened (as |
723 // opposed to, say, dragging a link onto the omnibox). | 724 // opposed to, say, dragging a link onto the omnibox). |
724 UMA_HISTOGRAM_TIMES(kFocusToOpenTimeHistogram, now - last_omnibox_focus_); | 725 UMA_HISTOGRAM_TIMES(kFocusToOpenTimeHistogram, now - last_omnibox_focus_); |
725 } | 726 } |
726 | 727 |
727 TemplateURLService* service = client_->GetTemplateURLService(); | 728 TemplateURLService* service = client_->GetTemplateURLService(); |
728 TemplateURL* template_url = match.GetTemplateURL(service, false); | 729 TemplateURL* template_url = match.GetTemplateURL(service, false); |
729 if (template_url) { | 730 if (template_url) { |
730 if (ui::PageTransitionTypeIncludingQualifiersIs( | 731 if (ui::PageTransitionTypeIncludingQualifiersIs( |
731 match.transition, ui::PAGE_TRANSITION_KEYWORD)) { | 732 match.transition, ui::PAGE_TRANSITION_KEYWORD)) { |
732 // The user is using a non-substituting keyword or is explicitly in | 733 // The user is using a non-substituting keyword or is explicitly in |
733 // keyword mode. | 734 // keyword mode. |
734 | 735 |
735 // Don't increment usage count for extension keywords. | 736 // Don't increment usage count for extension keywords. |
736 if (client_->ProcessExtensionKeyword(template_url, match, disposition, | 737 if (client_->ProcessExtensionKeyword(template_url, match, disposition, |
737 observer.get())) { | 738 observer.get())) { |
738 if (disposition != NEW_BACKGROUND_TAB) | 739 if (disposition != WindowOpenDisposition::NEW_BACKGROUND_TAB) |
739 view_->RevertAll(); | 740 view_->RevertAll(); |
740 return; | 741 return; |
741 } | 742 } |
742 | 743 |
743 base::RecordAction(base::UserMetricsAction("AcceptedKeyword")); | 744 base::RecordAction(base::UserMetricsAction("AcceptedKeyword")); |
744 client_->GetTemplateURLService()->IncrementUsageCount(template_url); | 745 client_->GetTemplateURLService()->IncrementUsageCount(template_url); |
745 } else { | 746 } else { |
746 DCHECK(ui::PageTransitionTypeIncludingQualifiersIs( | 747 DCHECK(ui::PageTransitionTypeIncludingQualifiersIs( |
747 match.transition, ui::PAGE_TRANSITION_GENERATED)); | 748 match.transition, ui::PAGE_TRANSITION_GENERATED)); |
748 // NOTE: We purposefully don't increment the usage count of the default | 749 // NOTE: We purposefully don't increment the usage count of the default |
749 // search engine here like we do for explicit keywords above; see comments | 750 // search engine here like we do for explicit keywords above; see comments |
750 // in template_url.h. | 751 // in template_url.h. |
751 } | 752 } |
752 | 753 |
753 SearchEngineType search_engine_type = match.destination_url.is_valid() ? | 754 SearchEngineType search_engine_type = match.destination_url.is_valid() ? |
754 TemplateURLPrepopulateData::GetEngineType(match.destination_url) : | 755 TemplateURLPrepopulateData::GetEngineType(match.destination_url) : |
755 SEARCH_ENGINE_OTHER; | 756 SEARCH_ENGINE_OTHER; |
756 UMA_HISTOGRAM_ENUMERATION("Omnibox.SearchEngineType", search_engine_type, | 757 UMA_HISTOGRAM_ENUMERATION("Omnibox.SearchEngineType", search_engine_type, |
757 SEARCH_ENGINE_MAX); | 758 SEARCH_ENGINE_MAX); |
758 } | 759 } |
759 | 760 |
760 // Get the current text before we call RevertAll() which will clear it. | 761 // Get the current text before we call RevertAll() which will clear it. |
761 base::string16 current_text = view_->GetText(); | 762 base::string16 current_text = view_->GetText(); |
762 | 763 |
763 if (disposition != NEW_BACKGROUND_TAB) { | 764 if (disposition != WindowOpenDisposition::NEW_BACKGROUND_TAB) { |
764 base::AutoReset<bool> tmp(&in_revert_, true); | 765 base::AutoReset<bool> tmp(&in_revert_, true); |
765 view_->RevertAll(); // Revert the box to its unedited state. | 766 view_->RevertAll(); // Revert the box to its unedited state. |
766 } | 767 } |
767 | 768 |
768 RecordPercentageMatchHistogram( | 769 RecordPercentageMatchHistogram( |
769 permanent_text_, current_text, match.transition, view_->GetWidth()); | 770 permanent_text_, current_text, match.transition, view_->GetWidth()); |
770 | 771 |
771 // Track whether the destination URL sends us to a search results page | 772 // Track whether the destination URL sends us to a search results page |
772 // using the default search provider. | 773 // using the default search provider. |
773 TemplateURLService* template_url_service = client_->GetTemplateURLService(); | 774 TemplateURLService* template_url_service = client_->GetTemplateURLService(); |
(...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1502 // Update state and notify view if the omnibox has focus and the caret | 1503 // Update state and notify view if the omnibox has focus and the caret |
1503 // visibility changed. | 1504 // visibility changed. |
1504 const bool was_caret_visible = is_caret_visible(); | 1505 const bool was_caret_visible = is_caret_visible(); |
1505 focus_state_ = state; | 1506 focus_state_ = state; |
1506 if (focus_state_ != OMNIBOX_FOCUS_NONE && | 1507 if (focus_state_ != OMNIBOX_FOCUS_NONE && |
1507 is_caret_visible() != was_caret_visible) | 1508 is_caret_visible() != was_caret_visible) |
1508 view_->ApplyCaretVisibility(); | 1509 view_->ApplyCaretVisibility(); |
1509 | 1510 |
1510 client_->OnFocusChanged(focus_state_, reason); | 1511 client_->OnFocusChanged(focus_state_, reason); |
1511 } | 1512 } |
OLD | NEW |