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

Side by Side Diff: chrome/browser/ui/webui/omnibox/omnibox_ui_handler.cc

Issue 232023004: Ensures the autocomplete_controller input is saved and restored when changing tabs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed broken browser test. Created 6 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
« no previous file with comments | « chrome/browser/ui/webui/omnibox/omnibox_ui_handler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/webui/omnibox/omnibox_ui_handler.h" 5 #include "chrome/browser/ui/webui/omnibox/omnibox_ui_handler.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/bind.h" 10 #include "base/bind.h"
11 #include "base/strings/string16.h" 11 #include "base/strings/string16.h"
12 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "chrome/browser/autocomplete/autocomplete_classifier.h" 16 #include "chrome/browser/autocomplete/autocomplete_classifier.h"
17 #include "chrome/browser/autocomplete/autocomplete_controller.h" 17 #include "chrome/browser/autocomplete/autocomplete_controller.h"
18 #include "chrome/browser/autocomplete/autocomplete_input.h"
19 #include "chrome/browser/autocomplete/autocomplete_match.h" 18 #include "chrome/browser/autocomplete/autocomplete_match.h"
20 #include "chrome/browser/autocomplete/autocomplete_provider.h" 19 #include "chrome/browser/autocomplete/autocomplete_provider.h"
21 #include "chrome/browser/history/history_service.h" 20 #include "chrome/browser/history/history_service.h"
22 #include "chrome/browser/history/history_service_factory.h" 21 #include "chrome/browser/history/history_service_factory.h"
23 #include "chrome/browser/history/url_database.h" 22 #include "chrome/browser/history/url_database.h"
24 #include "chrome/browser/search/search.h" 23 #include "chrome/browser/search/search.h"
25 #include "chrome/browser/search_engines/template_url.h" 24 #include "chrome/browser/search_engines/template_url.h"
26 #include "content/public/browser/web_ui.h" 25 #include "content/public/browser/web_ui.h"
27 26
28 OmniboxUIHandler::OmniboxUIHandler(Profile* profile): profile_(profile) { 27 OmniboxUIHandler::OmniboxUIHandler(Profile* profile): profile_(profile) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 // } 72 // }
74 // } 73 // }
75 // For reference, the javascript code that unpacks this object and 74 // For reference, the javascript code that unpacks this object and
76 // displays it is in chrome/browser/resources/omnibox.js 75 // displays it is in chrome/browser/resources/omnibox.js
77 void OmniboxUIHandler::OnResultChanged(bool default_match_changed) { 76 void OmniboxUIHandler::OnResultChanged(bool default_match_changed) {
78 base::DictionaryValue result_to_output; 77 base::DictionaryValue result_to_output;
79 // Fill in general information. 78 // Fill in general information.
80 result_to_output.SetBoolean("done", controller_->done()); 79 result_to_output.SetBoolean("done", controller_->done());
81 result_to_output.SetInteger("time_since_omnibox_started_ms", 80 result_to_output.SetInteger("time_since_omnibox_started_ms",
82 (base::Time::Now() - time_omnibox_started_).InMilliseconds()); 81 (base::Time::Now() - time_omnibox_started_).InMilliseconds());
83 const base::string16& host = controller_->input().text().substr( 82 const base::string16& host = input_.text().substr(
84 controller_->input().parts().host.begin, 83 input_.parts().host.begin,
85 controller_->input().parts().host.len); 84 input_.parts().host.len);
86 result_to_output.SetString("host", host); 85 result_to_output.SetString("host", host);
87 bool is_typed_host; 86 bool is_typed_host;
88 if (LookupIsTypedHost(host, &is_typed_host)) { 87 if (LookupIsTypedHost(host, &is_typed_host)) {
89 // If we successfully looked up whether the host part of the omnibox 88 // If we successfully looked up whether the host part of the omnibox
90 // input (this interprets the input as a host plus optional path) as 89 // input (this interprets the input as a host plus optional path) as
91 // a typed host, then record this information in the output. 90 // a typed host, then record this information in the output.
92 result_to_output.SetBoolean("is_typed_host", is_typed_host); 91 result_to_output.SetBoolean("is_typed_host", is_typed_host);
93 } 92 }
94 // Fill in the merged/combined results the controller has provided. 93 // Fill in the merged/combined results the controller has provided.
95 AddResultToDictionary("combined_results", controller_->result().begin(), 94 AddResultToDictionary("combined_results", controller_->result().begin(),
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 int current_page_classification; 190 int current_page_classification;
192 return_val = input->GetInteger(4, &current_page_classification); 191 return_val = input->GetInteger(4, &current_page_classification);
193 DCHECK(return_val); 192 DCHECK(return_val);
194 // Reset the controller. If we don't do this, then the 193 // Reset the controller. If we don't do this, then the
195 // AutocompleteController might inappropriately set its |minimal_changes| 194 // AutocompleteController might inappropriately set its |minimal_changes|
196 // variable (or something else) and some providers will short-circuit 195 // variable (or something else) and some providers will short-circuit
197 // important logic and return stale results. In short, we want the 196 // important logic and return stale results. In short, we want the
198 // actual results to not depend on the state of the previous request. 197 // actual results to not depend on the state of the previous request.
199 ResetController(); 198 ResetController();
200 time_omnibox_started_ = base::Time::Now(); 199 time_omnibox_started_ = base::Time::Now();
201 controller_->Start(AutocompleteInput( 200 input_ = AutocompleteInput(
202 input_string, 201 input_string,
203 cursor_position, 202 cursor_position,
204 base::string16(), // user's desired tld (top-level domain) 203 base::string16(), // user's desired tld (top-level domain)
205 GURL(), 204 GURL(),
206 static_cast<AutocompleteInput::PageClassification>( 205 static_cast<AutocompleteInput::PageClassification>(
207 current_page_classification), 206 current_page_classification),
208 prevent_inline_autocomplete, 207 prevent_inline_autocomplete,
209 prefer_keyword, 208 prefer_keyword,
210 true, // allow exact keyword matches 209 true, // allow exact keyword matches
211 true)); // want all matches 210 true);
211 controller_->Start(input_); // want all matches
212 } 212 }
213 213
214 void OmniboxUIHandler::ResetController() { 214 void OmniboxUIHandler::ResetController() {
215 controller_.reset(new AutocompleteController(profile_, this, 215 controller_.reset(new AutocompleteController(profile_, this,
216 AutocompleteClassifier::kDefaultOmniboxProviders)); 216 AutocompleteClassifier::kDefaultOmniboxProviders));
217 } 217 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/omnibox/omnibox_ui_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698