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

Side by Side Diff: chrome/browser/ui/omnibox/omnibox_controller.cc

Issue 14358005: Omnibox refactor, moved OnResultChanged to OmniboxController (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_controller.h" 5 #include "chrome/browser/ui/omnibox/omnibox_controller.h"
6 6
7 #include "base/metrics/histogram.h"
7 #include "chrome/browser/autocomplete/autocomplete_classifier.h" 8 #include "chrome/browser/autocomplete/autocomplete_classifier.h"
8 #include "chrome/browser/autocomplete/autocomplete_controller.h" 9 #include "chrome/browser/autocomplete/autocomplete_controller.h"
10 #include "chrome/browser/autocomplete/autocomplete_match.h"
11 #include "chrome/browser/net/predictor.h"
12 #include "chrome/browser/predictors/autocomplete_action_predictor.h"
13 #include "chrome/browser/prerender/prerender_field_trial.h"
14 #include "chrome/browser/prerender/prerender_manager.h"
15 #include "chrome/browser/prerender/prerender_manager_factory.h"
16 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/search/search.h" 17 #include "chrome/browser/search/search.h"
18 #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h"
10 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" 19 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h"
20 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h"
21 #include "chrome/browser/ui/omnibox/omnibox_popup_view.h"
22 #include "chrome/browser/ui/search/instant_controller.h"
23 #include "extensions/common/constants.h"
24
25 using predictors::AutocompleteActionPredictor;
11 26
12 OmniboxController::OmniboxController( 27 OmniboxController::OmniboxController(
13 OmniboxEditModel* omnibox_edit_model, 28 OmniboxEditModel* omnibox_edit_model,
14 Profile* profile) 29 Profile* profile)
15 : omnibox_edit_model_(omnibox_edit_model) { 30 : omnibox_edit_model_(omnibox_edit_model),
31 profile_(profile) {
16 // Use a restricted subset of the autocomplete providers if we're using the 32 // Use a restricted subset of the autocomplete providers if we're using the
17 // Instant Extended API, as it doesn't support them all. 33 // Instant Extended API, as it doesn't support them all.
18 autocomplete_controller_.reset(new AutocompleteController(profile, this, 34 autocomplete_controller_.reset(new AutocompleteController(profile, this,
19 chrome::IsInstantExtendedAPIEnabled() ? 35 chrome::IsInstantExtendedAPIEnabled() ?
20 AutocompleteClassifier::kInstantExtendedOmniboxProviders : 36 AutocompleteClassifier::kInstantExtendedOmniboxProviders :
21 AutocompleteClassifier::kDefaultOmniboxProviders)); 37 AutocompleteClassifier::kDefaultOmniboxProviders));
22 } 38 }
23 39
24 OmniboxController::~OmniboxController() { 40 OmniboxController::~OmniboxController() {
25 } 41 }
26 42
27 void OmniboxController::OnResultChanged(bool default_match_changed) { 43 void OmniboxController::OnResultChanged(bool default_match_changed) {
28 omnibox_edit_model_->OnResultChanged(default_match_changed); 44 const bool was_open = popup_->IsOpen();
45 if (default_match_changed) {
46 string16 inline_autocomplete_text;
47 string16 keyword;
48 bool is_keyword_hint = false;
49 const AutocompleteResult& result = this->result();
50 const AutocompleteResult::const_iterator match(result.default_match());
51 if (match != result.end()) {
52 if ((match->inline_autocomplete_offset != string16::npos) &&
53 (match->inline_autocomplete_offset <
54 match->fill_into_edit.length())) {
55 inline_autocomplete_text =
56 match->fill_into_edit.substr(match->inline_autocomplete_offset);
57 }
58
59 if (!prerender::IsOmniboxEnabled(profile_))
60 DoPreconnect(*match);
61
62 // We could prefetch the alternate nav URL, if any, but because there
63 // can be many of these as a user types an initial series of characters,
64 // the OS DNS cache could suffer eviction problems for minimal gain.
65
66 match->GetKeywordUIState(profile_, &keyword, &is_keyword_hint);
67 }
68
69 popup_->OnResultChanged();
70 omnibox_edit_model_->OnPopupDataChanged(inline_autocomplete_text, NULL,
71 keyword, is_keyword_hint);
72 } else {
73 popup_->OnResultChanged();
74 }
75
76 if (popup_->IsOpen()) {
Mathieu 2013/04/24 16:45:56 I've never liked this method name in the context o
77 omnibox_edit_model_->OnPopupBoundsChanged(
78 popup_->view()->GetTargetBounds());
79
80 InstantController* instant =
81 omnibox_edit_model_->controller()->GetInstant();
82 if (instant && !omnibox_edit_model_->in_revert()) {
83 instant->HandleAutocompleteResults(
84 *autocomplete_controller()->providers());
85 }
86 } else if (was_open) {
87 // Accepts the temporary text as the user text, because it makes little
88 // sense to have temporary text when the popup is closed.
89 omnibox_edit_model_->AcceptTemporaryTextAsUserText();
90 }
29 } 91 }
92
93 void OmniboxController::ClearPopupKeywordMode() const {
94 if (popup_->IsOpen() &&
95 popup_->selected_line_state() == OmniboxPopupModel::KEYWORD)
96 popup_->SetSelectedLineState(OmniboxPopupModel::NORMAL);
97 }
98
99 void OmniboxController::InfoForCurrentSelection(AutocompleteMatch* match,
100 GURL* alternate_nav_url) const {
101 DCHECK(match != NULL);
102 const AutocompleteResult& result = autocomplete_controller_->result();
103 if (!autocomplete_controller_->done()) {
104 // It's technically possible for |result| to be empty if no provider returns
105 // a synchronous result but the query has not completed synchronously;
106 // pratically, however, that should never actually happen.
107 if (result.empty())
108 return;
109 // The user cannot have manually selected a match, or the query would have
110 // stopped. So the default match must be the desired selection.
111 *match = *result.default_match();
112 } else {
113 CHECK(popup_->IsOpen());
114 // If there are no results, the popup should be closed (so we should have
115 // failed the CHECK above), and URLsForDefaultMatch() should have been
116 // called instead.
117 CHECK(!result.empty());
118 CHECK(popup_->selected_line() < result.size());
119 *match = result.match_at(popup_->selected_line());
120 }
121 if (alternate_nav_url && popup_->manually_selected_match().empty())
122 *alternate_nav_url = result.alternate_nav_url();
123 }
124
125 const AutocompleteResult& OmniboxController::result() const {
126 return autocomplete_controller_->result();
127 }
128
129 void OmniboxController::DoPreconnect(const AutocompleteMatch& match) {
130 if (!match.destination_url.SchemeIs(extensions::kExtensionScheme)) {
131 // Warm up DNS Prefetch cache, or preconnect to a search service.
132 UMA_HISTOGRAM_ENUMERATION("Autocomplete.MatchType", match.type,
133 AutocompleteMatch::NUM_TYPES);
134 if (profile_->GetNetworkPredictor()) {
135 profile_->GetNetworkPredictor()->AnticipateOmniboxUrl(
136 match.destination_url,
137 AutocompleteActionPredictor::IsPreconnectable(match));
138 }
139 // We could prefetch the alternate nav URL, if any, but because there
140 // can be many of these as a user types an initial series of characters,
141 // the OS DNS cache could suffer eviction problems for minimal gain.
142 }
143 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/omnibox/omnibox_controller.h ('k') | chrome/browser/ui/omnibox/omnibox_edit_model.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698