| OLD | NEW |
| 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" |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 output->SetBoolean(item_prefix + ".from_previous", it->from_previous); | 132 output->SetBoolean(item_prefix + ".from_previous", it->from_previous); |
| 133 for (AutocompleteMatch::AdditionalInfo::const_iterator j = | 133 for (AutocompleteMatch::AdditionalInfo::const_iterator j = |
| 134 it->additional_info.begin(); j != it->additional_info.end(); ++j) { | 134 it->additional_info.begin(); j != it->additional_info.end(); ++j) { |
| 135 output->SetString(item_prefix + ".additional_info." + j->first, | 135 output->SetString(item_prefix + ".additional_info." + j->first, |
| 136 j->second); | 136 j->second); |
| 137 } | 137 } |
| 138 } | 138 } |
| 139 output->SetInteger(prefix + ".num_items", i); | 139 output->SetInteger(prefix + ".num_items", i); |
| 140 } | 140 } |
| 141 | 141 |
| 142 void OmniboxUIHandler::StartOmniboxQuery( | 142 void OmniboxUIHandler::StartOmniboxQuery(const base::ListValue* input) { |
| 143 const base::ListValue* three_element_input_string) { | 143 DCHECK_EQ(4u, input->GetSize()); |
| 144 DCHECK_EQ(3u, three_element_input_string->GetSize()); | |
| 145 string16 input_string; | 144 string16 input_string; |
| 146 bool return_val = three_element_input_string->GetString(0, &input_string); | 145 bool return_val = input->GetString(0, &input_string); |
| 147 DCHECK(return_val); | |
| 148 bool prevent_inline_autocomplete; | |
| 149 return_val = | |
| 150 three_element_input_string->GetBoolean(1, &prevent_inline_autocomplete); | |
| 151 DCHECK(return_val); | 146 DCHECK(return_val); |
| 152 int cursor_position_int; | 147 int cursor_position_int; |
| 153 return_val = three_element_input_string->GetInteger(2, &cursor_position_int); | 148 return_val = input->GetInteger(1, &cursor_position_int); |
| 154 DCHECK(return_val); | 149 DCHECK(return_val); |
| 155 size_t cursor_position = cursor_position_int; | 150 size_t cursor_position = cursor_position_int; |
| 151 bool prevent_inline_autocomplete; |
| 152 return_val = input->GetBoolean(2, &prevent_inline_autocomplete); |
| 153 DCHECK(return_val); |
| 154 bool prefer_keyword; |
| 155 return_val = input->GetBoolean(3, &prefer_keyword); |
| 156 DCHECK(return_val); |
| 156 string16 empty_string; | 157 string16 empty_string; |
| 157 // Reset the controller. If we don't do this, then the | 158 // Reset the controller. If we don't do this, then the |
| 158 // AutocompleteController might inappropriately set its |minimal_changes| | 159 // AutocompleteController might inappropriately set its |minimal_changes| |
| 159 // variable (or something else) and some providers will short-circuit | 160 // variable (or something else) and some providers will short-circuit |
| 160 // important logic and return stale results. In short, we want the | 161 // important logic and return stale results. In short, we want the |
| 161 // actual results to not depend on the state of the previous request. | 162 // actual results to not depend on the state of the previous request. |
| 162 ResetController(); | 163 ResetController(); |
| 163 time_omnibox_started_ = base::Time::Now(); | 164 time_omnibox_started_ = base::Time::Now(); |
| 164 controller_->Start(AutocompleteInput( | 165 controller_->Start(AutocompleteInput( |
| 165 input_string, | 166 input_string, |
| 166 cursor_position, | 167 cursor_position, |
| 167 empty_string, // user's desired tld (top-level domain) | 168 empty_string, // user's desired tld (top-level domain) |
| 168 prevent_inline_autocomplete, | 169 prevent_inline_autocomplete, |
| 169 false, // no preferred keyword provider | 170 prefer_keyword, |
| 170 true, // allow exact keyword matches | 171 true, // allow exact keyword matches |
| 171 AutocompleteInput::ALL_MATCHES)); // want all matches | 172 AutocompleteInput::ALL_MATCHES)); // want all matches |
| 172 } | 173 } |
| 173 | 174 |
| 174 void OmniboxUIHandler::ResetController() { | 175 void OmniboxUIHandler::ResetController() { |
| 175 controller_.reset(new AutocompleteController(profile_, this, | 176 controller_.reset(new AutocompleteController(profile_, this, |
| 176 chrome::search::IsInstantExtendedAPIEnabled(profile_) ? | 177 chrome::search::IsInstantExtendedAPIEnabled(profile_) ? |
| 177 AutocompleteClassifier::kInstantExtendedOmniboxProviders : | 178 AutocompleteClassifier::kInstantExtendedOmniboxProviders : |
| 178 AutocompleteClassifier::kDefaultOmniboxProviders)); | 179 AutocompleteClassifier::kDefaultOmniboxProviders)); |
| 179 } | 180 } |
| OLD | NEW |