| 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 "chrome/browser/ui/omnibox/omnibox_edit_model.h" | 5 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
| (...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 GoogleURLTracker::GoogleURLSearchCommitted(profile_); | 631 GoogleURLTracker::GoogleURLSearchCommitted(profile_); |
| 632 | 632 |
| 633 view_->OpenMatch(match, disposition, alternate_nav_url, | 633 view_->OpenMatch(match, disposition, alternate_nav_url, |
| 634 OmniboxPopupModel::kNoMatch); | 634 OmniboxPopupModel::kNoMatch); |
| 635 } | 635 } |
| 636 | 636 |
| 637 void OmniboxEditModel::OpenMatch(const AutocompleteMatch& match, | 637 void OmniboxEditModel::OpenMatch(const AutocompleteMatch& match, |
| 638 WindowOpenDisposition disposition, | 638 WindowOpenDisposition disposition, |
| 639 const GURL& alternate_nav_url, | 639 const GURL& alternate_nav_url, |
| 640 size_t index) { | 640 size_t index) { |
| 641 const string16& user_text = |
| 642 user_input_in_progress_ ? user_text_ : permanent_text_; |
| 643 scoped_ptr<OmniboxNavigationObserver> observer( |
| 644 new OmniboxNavigationObserver(profile_, user_text, match, |
| 645 alternate_nav_url)); |
| 646 |
| 641 // We only care about cases where there is a selection (i.e. the popup is | 647 // We only care about cases where there is a selection (i.e. the popup is |
| 642 // open). | 648 // open). |
| 643 if (popup_model()->IsOpen()) { | 649 if (popup_model()->IsOpen()) { |
| 644 const base::TimeTicks& now(base::TimeTicks::Now()); | 650 const base::TimeTicks& now(base::TimeTicks::Now()); |
| 645 base::TimeDelta elapsed_time_since_user_first_modified_omnibox( | 651 base::TimeDelta elapsed_time_since_user_first_modified_omnibox( |
| 646 now - time_user_first_modified_omnibox_); | 652 now - time_user_first_modified_omnibox_); |
| 647 base::TimeDelta elapsed_time_since_last_change_to_default_match( | 653 base::TimeDelta elapsed_time_since_last_change_to_default_match( |
| 648 now - autocomplete_controller()->last_time_default_match_changed()); | 654 now - autocomplete_controller()->last_time_default_match_changed()); |
| 649 // These elapsed times don't really make sense for ZeroSuggest matches | 655 // These elapsed times don't really make sense for ZeroSuggest matches |
| 650 // (because the user does not modify the omnibox for ZeroSuggest), so for | 656 // (because the user does not modify the omnibox for ZeroSuggest), so for |
| 651 // those we set the elapsed times to something that will be ignored by | 657 // those we set the elapsed times to something that will be ignored by |
| 652 // metrics_log.cc. | 658 // metrics_log.cc. |
| 653 if (match.provider && | 659 if (match.provider && |
| 654 match.provider->type() == AutocompleteProvider::TYPE_ZERO_SUGGEST) { | 660 match.provider->type() == AutocompleteProvider::TYPE_ZERO_SUGGEST) { |
| 655 elapsed_time_since_user_first_modified_omnibox = | 661 elapsed_time_since_user_first_modified_omnibox = |
| 656 base::TimeDelta::FromMilliseconds(-1); | 662 base::TimeDelta::FromMilliseconds(-1); |
| 657 elapsed_time_since_last_change_to_default_match = | 663 elapsed_time_since_last_change_to_default_match = |
| 658 base::TimeDelta::FromMilliseconds(-1); | 664 base::TimeDelta::FromMilliseconds(-1); |
| 659 } | 665 } |
| 660 OmniboxLog log( | 666 OmniboxLog log( |
| 661 autocomplete_controller()->input().text(), | 667 user_text, |
| 662 just_deleted_text_, | 668 just_deleted_text_, |
| 663 autocomplete_controller()->input().type(), | 669 autocomplete_controller()->input().type(), |
| 664 popup_model()->selected_line(), | 670 popup_model()->selected_line(), |
| 665 -1, // don't yet know tab ID; set later if appropriate | 671 -1, // don't yet know tab ID; set later if appropriate |
| 666 ClassifyPage(), | 672 ClassifyPage(), |
| 667 elapsed_time_since_user_first_modified_omnibox, | 673 elapsed_time_since_user_first_modified_omnibox, |
| 668 match.inline_autocompletion.length(), | 674 match.inline_autocompletion.length(), |
| 669 elapsed_time_since_last_change_to_default_match, | 675 elapsed_time_since_last_change_to_default_match, |
| 670 result()); | 676 result()); |
| 671 | 677 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 if (template_url) { | 711 if (template_url) { |
| 706 if (match.transition == content::PAGE_TRANSITION_KEYWORD) { | 712 if (match.transition == content::PAGE_TRANSITION_KEYWORD) { |
| 707 // The user is using a non-substituting keyword or is explicitly in | 713 // The user is using a non-substituting keyword or is explicitly in |
| 708 // keyword mode. | 714 // keyword mode. |
| 709 const AutocompleteMatch& match = (index == OmniboxPopupModel::kNoMatch) ? | 715 const AutocompleteMatch& match = (index == OmniboxPopupModel::kNoMatch) ? |
| 710 CurrentMatch(NULL) : result().match_at(index); | 716 CurrentMatch(NULL) : result().match_at(index); |
| 711 | 717 |
| 712 // Don't increment usage count for extension keywords. | 718 // Don't increment usage count for extension keywords. |
| 713 if (delegate_->ProcessExtensionKeyword(template_url, match, | 719 if (delegate_->ProcessExtensionKeyword(template_url, match, |
| 714 disposition)) { | 720 disposition)) { |
| 721 observer->OnSuccessfulNavigation(); |
| 715 if (disposition != NEW_BACKGROUND_TAB) | 722 if (disposition != NEW_BACKGROUND_TAB) |
| 716 view_->RevertAll(); | 723 view_->RevertAll(); |
| 717 return; | 724 return; |
| 718 } | 725 } |
| 719 | 726 |
| 720 content::RecordAction(content::UserMetricsAction("AcceptedKeyword")); | 727 content::RecordAction(content::UserMetricsAction("AcceptedKeyword")); |
| 721 TemplateURLServiceFactory::GetForProfile(profile_)->IncrementUsageCount( | 728 TemplateURLServiceFactory::GetForProfile(profile_)->IncrementUsageCount( |
| 722 template_url); | 729 template_url); |
| 723 } else { | 730 } else { |
| 724 DCHECK_EQ(content::PAGE_TRANSITION_GENERATED, match.transition); | 731 DCHECK_EQ(content::PAGE_TRANSITION_GENERATED, match.transition); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 744 // Get the current text before we call RevertAll() which will clear it. | 751 // Get the current text before we call RevertAll() which will clear it. |
| 745 string16 current_text = GetViewText(); | 752 string16 current_text = GetViewText(); |
| 746 | 753 |
| 747 if (disposition != NEW_BACKGROUND_TAB) { | 754 if (disposition != NEW_BACKGROUND_TAB) { |
| 748 base::AutoReset<bool> tmp(&in_revert_, true); | 755 base::AutoReset<bool> tmp(&in_revert_, true); |
| 749 view_->RevertAll(); // Revert the box to its unedited state. | 756 view_->RevertAll(); // Revert the box to its unedited state. |
| 750 } | 757 } |
| 751 | 758 |
| 752 if (match.type == AutocompleteMatchType::EXTENSION_APP) { | 759 if (match.type == AutocompleteMatchType::EXTENSION_APP) { |
| 753 ExtensionAppProvider::LaunchAppFromOmnibox(match, profile_, disposition); | 760 ExtensionAppProvider::LaunchAppFromOmnibox(match, profile_, disposition); |
| 761 observer->OnSuccessfulNavigation(); |
| 754 } else { | 762 } else { |
| 755 base::TimeDelta query_formulation_time = | 763 base::TimeDelta query_formulation_time = |
| 756 base::TimeTicks::Now() - time_user_first_modified_omnibox_; | 764 base::TimeTicks::Now() - time_user_first_modified_omnibox_; |
| 757 const GURL destination_url = autocomplete_controller()-> | 765 const GURL destination_url = autocomplete_controller()-> |
| 758 GetDestinationURL(match, query_formulation_time); | 766 GetDestinationURL(match, query_formulation_time); |
| 759 | 767 |
| 760 RecordPercentageMatchHistogram( | 768 RecordPercentageMatchHistogram( |
| 761 permanent_text_, current_text, | 769 permanent_text_, current_text, |
| 762 controller_->GetToolbarModel()->WouldPerformSearchTermReplacement( | 770 controller_->GetToolbarModel()->WouldPerformSearchTermReplacement( |
| 763 false), | 771 false), |
| 764 match.transition); | 772 match.transition); |
| 765 | 773 |
| 766 // Track whether the destination URL sends us to a search results page | 774 // Track whether the destination URL sends us to a search results page |
| 767 // using the default search provider. | 775 // using the default search provider. |
| 768 if (TemplateURLServiceFactory::GetForProfile(profile_)-> | 776 if (TemplateURLServiceFactory::GetForProfile(profile_)-> |
| 769 IsSearchResultsPageFromDefaultSearchProvider(destination_url)) { | 777 IsSearchResultsPageFromDefaultSearchProvider(destination_url)) { |
| 770 content::RecordAction( | 778 content::RecordAction( |
| 771 content::UserMetricsAction("OmniboxDestinationURLIsSearchOnDSP")); | 779 content::UserMetricsAction("OmniboxDestinationURLIsSearchOnDSP")); |
| 772 } | 780 } |
| 773 | 781 |
| 774 if (destination_url.is_valid()) { | 782 if (destination_url.is_valid()) { |
| 775 // The OmniboxNavigationObserver will listen for the pending navigation | |
| 776 // notification that will be issued as a result of the "open URL." | |
| 777 scoped_ptr<OmniboxNavigationObserver> observer( | |
| 778 new OmniboxNavigationObserver(alternate_nav_url)); | |
| 779 // This calls RevertAll again. | 783 // This calls RevertAll again. |
| 780 base::AutoReset<bool> tmp(&in_revert_, true); | 784 base::AutoReset<bool> tmp(&in_revert_, true); |
| 781 controller_->OnAutocompleteAccept( | 785 controller_->OnAutocompleteAccept( |
| 782 destination_url, disposition, | 786 destination_url, disposition, |
| 783 content::PageTransitionFromInt( | 787 content::PageTransitionFromInt( |
| 784 match.transition | content::PAGE_TRANSITION_FROM_ADDRESS_BAR)); | 788 match.transition | content::PAGE_TRANSITION_FROM_ADDRESS_BAR)); |
| 785 if (observer->load_state() != OmniboxNavigationObserver::LOAD_NOT_SEEN) | 789 if (observer->load_state() != OmniboxNavigationObserver::LOAD_NOT_SEEN) |
| 786 ignore_result(observer.release()); // The observer will delete itself. | 790 ignore_result(observer.release()); // The observer will delete itself. |
| 787 } | 791 } |
| 788 } | 792 } |
| (...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1379 instant->OmniboxFocusChanged(state, reason, NULL); | 1383 instant->OmniboxFocusChanged(state, reason, NULL); |
| 1380 | 1384 |
| 1381 // Update state and notify view if the omnibox has focus and the caret | 1385 // Update state and notify view if the omnibox has focus and the caret |
| 1382 // visibility changed. | 1386 // visibility changed. |
| 1383 const bool was_caret_visible = is_caret_visible(); | 1387 const bool was_caret_visible = is_caret_visible(); |
| 1384 focus_state_ = state; | 1388 focus_state_ = state; |
| 1385 if (focus_state_ != OMNIBOX_FOCUS_NONE && | 1389 if (focus_state_ != OMNIBOX_FOCUS_NONE && |
| 1386 is_caret_visible() != was_caret_visible) | 1390 is_caret_visible() != was_caret_visible) |
| 1387 view_->ApplyCaretVisibility(); | 1391 view_->ApplyCaretVisibility(); |
| 1388 } | 1392 } |
| OLD | NEW |