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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/omnibox/omnibox_controller.cc
diff --git a/chrome/browser/ui/omnibox/omnibox_controller.cc b/chrome/browser/ui/omnibox/omnibox_controller.cc
index bac50dab7dc48e60370b76901047a5a99ee6a9e5..8e7435cd4e8bcba6886e1d716e2369764b557ee0 100644
--- a/chrome/browser/ui/omnibox/omnibox_controller.cc
+++ b/chrome/browser/ui/omnibox/omnibox_controller.cc
@@ -4,15 +4,31 @@
#include "chrome/browser/ui/omnibox/omnibox_controller.h"
+#include "base/metrics/histogram.h"
#include "chrome/browser/autocomplete/autocomplete_classifier.h"
#include "chrome/browser/autocomplete/autocomplete_controller.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
+#include "chrome/browser/net/predictor.h"
+#include "chrome/browser/predictors/autocomplete_action_predictor.h"
+#include "chrome/browser/prerender/prerender_field_trial.h"
+#include "chrome/browser/prerender/prerender_manager.h"
+#include "chrome/browser/prerender/prerender_manager_factory.h"
+#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search/search.h"
+#include "chrome/browser/ui/omnibox/omnibox_edit_controller.h"
#include "chrome/browser/ui/omnibox/omnibox_edit_model.h"
+#include "chrome/browser/ui/omnibox/omnibox_popup_model.h"
+#include "chrome/browser/ui/omnibox/omnibox_popup_view.h"
+#include "chrome/browser/ui/search/instant_controller.h"
+#include "extensions/common/constants.h"
+
+using predictors::AutocompleteActionPredictor;
OmniboxController::OmniboxController(
OmniboxEditModel* omnibox_edit_model,
Profile* profile)
- : omnibox_edit_model_(omnibox_edit_model) {
+ : omnibox_edit_model_(omnibox_edit_model),
+ profile_(profile) {
// Use a restricted subset of the autocomplete providers if we're using the
// Instant Extended API, as it doesn't support them all.
autocomplete_controller_.reset(new AutocompleteController(profile, this,
@@ -25,5 +41,103 @@ OmniboxController::~OmniboxController() {
}
void OmniboxController::OnResultChanged(bool default_match_changed) {
- omnibox_edit_model_->OnResultChanged(default_match_changed);
+ const bool was_open = popup_->IsOpen();
+ if (default_match_changed) {
+ string16 inline_autocomplete_text;
+ string16 keyword;
+ bool is_keyword_hint = false;
+ const AutocompleteResult& result = this->result();
+ const AutocompleteResult::const_iterator match(result.default_match());
+ if (match != result.end()) {
+ if ((match->inline_autocomplete_offset != string16::npos) &&
+ (match->inline_autocomplete_offset <
+ match->fill_into_edit.length())) {
+ inline_autocomplete_text =
+ match->fill_into_edit.substr(match->inline_autocomplete_offset);
+ }
+
+ if (!prerender::IsOmniboxEnabled(profile_))
+ DoPreconnect(*match);
+
+ // We could prefetch the alternate nav URL, if any, but because there
+ // can be many of these as a user types an initial series of characters,
+ // the OS DNS cache could suffer eviction problems for minimal gain.
+
+ match->GetKeywordUIState(profile_, &keyword, &is_keyword_hint);
+ }
+
+ popup_->OnResultChanged();
+ omnibox_edit_model_->OnPopupDataChanged(inline_autocomplete_text, NULL,
+ keyword, is_keyword_hint);
+ } else {
+ popup_->OnResultChanged();
+ }
+
+ if (popup_->IsOpen()) {
Mathieu 2013/04/24 16:45:56 I've never liked this method name in the context o
+ omnibox_edit_model_->OnPopupBoundsChanged(
+ popup_->view()->GetTargetBounds());
+
+ InstantController* instant =
+ omnibox_edit_model_->controller()->GetInstant();
+ if (instant && !omnibox_edit_model_->in_revert()) {
+ instant->HandleAutocompleteResults(
+ *autocomplete_controller()->providers());
+ }
+ } else if (was_open) {
+ // Accepts the temporary text as the user text, because it makes little
+ // sense to have temporary text when the popup is closed.
+ omnibox_edit_model_->AcceptTemporaryTextAsUserText();
+ }
+}
+
+void OmniboxController::ClearPopupKeywordMode() const {
+ if (popup_->IsOpen() &&
+ popup_->selected_line_state() == OmniboxPopupModel::KEYWORD)
+ popup_->SetSelectedLineState(OmniboxPopupModel::NORMAL);
+}
+
+void OmniboxController::InfoForCurrentSelection(AutocompleteMatch* match,
+ GURL* alternate_nav_url) const {
+ DCHECK(match != NULL);
+ const AutocompleteResult& result = autocomplete_controller_->result();
+ if (!autocomplete_controller_->done()) {
+ // It's technically possible for |result| to be empty if no provider returns
+ // a synchronous result but the query has not completed synchronously;
+ // pratically, however, that should never actually happen.
+ if (result.empty())
+ return;
+ // The user cannot have manually selected a match, or the query would have
+ // stopped. So the default match must be the desired selection.
+ *match = *result.default_match();
+ } else {
+ CHECK(popup_->IsOpen());
+ // If there are no results, the popup should be closed (so we should have
+ // failed the CHECK above), and URLsForDefaultMatch() should have been
+ // called instead.
+ CHECK(!result.empty());
+ CHECK(popup_->selected_line() < result.size());
+ *match = result.match_at(popup_->selected_line());
+ }
+ if (alternate_nav_url && popup_->manually_selected_match().empty())
+ *alternate_nav_url = result.alternate_nav_url();
+}
+
+const AutocompleteResult& OmniboxController::result() const {
+ return autocomplete_controller_->result();
+}
+
+void OmniboxController::DoPreconnect(const AutocompleteMatch& match) {
+ if (!match.destination_url.SchemeIs(extensions::kExtensionScheme)) {
+ // Warm up DNS Prefetch cache, or preconnect to a search service.
+ UMA_HISTOGRAM_ENUMERATION("Autocomplete.MatchType", match.type,
+ AutocompleteMatch::NUM_TYPES);
+ if (profile_->GetNetworkPredictor()) {
+ profile_->GetNetworkPredictor()->AnticipateOmniboxUrl(
+ match.destination_url,
+ AutocompleteActionPredictor::IsPreconnectable(match));
+ }
+ // We could prefetch the alternate nav URL, if any, but because there
+ // can be many of these as a user types an initial series of characters,
+ // the OS DNS cache could suffer eviction problems for minimal gain.
+ }
}
« 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