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/renderer/searchbox/searchbox.h" | 5 #include "chrome/renderer/searchbox/searchbox.h" |
6 | 6 |
7 #include "base/metrics/field_trial.h" | 7 #include "base/metrics/field_trial.h" |
8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 selection_start_ = selection_start; | 223 selection_start_ = selection_start; |
224 selection_end_ = selection_end; | 224 selection_end_ = selection_end; |
225 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { | 225 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
226 DVLOG(1) << render_view() << " OnChange"; | 226 DVLOG(1) << render_view() << " OnChange"; |
227 extensions_v8::SearchBoxExtension::DispatchChange( | 227 extensions_v8::SearchBoxExtension::DispatchChange( |
228 render_view()->GetWebView()->mainFrame()); | 228 render_view()->GetWebView()->mainFrame()); |
229 } | 229 } |
230 } | 230 } |
231 | 231 |
232 void SearchBox::OnSubmit(const string16& query) { | 232 void SearchBox::OnSubmit(const string16& query) { |
233 query_ = query; | 233 // Submit() is called when the user hits Enter to commit the omnibox text. |
234 verbatim_ = true; | 234 // If |query| is non-blank, the user committed a search. If it's blank, the |
235 selection_start_ = selection_end_ = query_.size(); | 235 // omnibox text was a URL, and the user is navigating to it, in which case |
| 236 // we shouldn't update the |query_| or associated state. |
| 237 if (!query.empty()) { |
| 238 query_ = query; |
| 239 verbatim_ = true; |
| 240 selection_start_ = selection_end_ = query_.size(); |
| 241 } |
| 242 |
236 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { | 243 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
237 DVLOG(1) << render_view() << " OnSubmit"; | 244 DVLOG(1) << render_view() << " OnSubmit"; |
238 extensions_v8::SearchBoxExtension::DispatchSubmit( | 245 extensions_v8::SearchBoxExtension::DispatchSubmit( |
239 render_view()->GetWebView()->mainFrame()); | 246 render_view()->GetWebView()->mainFrame()); |
240 } | 247 } |
241 Reset(); | 248 |
| 249 if (!query.empty()) |
| 250 Reset(); |
242 } | 251 } |
243 | 252 |
244 void SearchBox::OnCancel(const string16& query) { | 253 void SearchBox::OnCancel(const string16& query) { |
245 query_ = query; | 254 query_ = query; |
246 verbatim_ = true; | 255 verbatim_ = true; |
247 selection_start_ = selection_end_ = query_.size(); | 256 selection_start_ = selection_end_ = query_.size(); |
248 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { | 257 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
249 DVLOG(1) << render_view() << " OnCancel"; | 258 DVLOG(1) << render_view() << " OnCancel"; |
250 extensions_v8::SearchBoxExtension::DispatchCancel( | 259 extensions_v8::SearchBoxExtension::DispatchCancel( |
251 render_view()->GetWebView()->mainFrame()); | 260 render_view()->GetWebView()->mainFrame()); |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 std::string trial_flags = | 510 std::string trial_flags = |
502 base::FieldTrialList::FindFullName(kInstantExtendedFieldTrialName); | 511 base::FieldTrialList::FindFullName(kInstantExtendedFieldTrialName); |
503 std::vector<std::string> flags; | 512 std::vector<std::string> flags; |
504 Tokenize(trial_flags, " ", &flags); | 513 Tokenize(trial_flags, " ", &flags); |
505 for (size_t i = 0; i < flags.size(); ++i) { | 514 for (size_t i = 0; i < flags.size(); ++i) { |
506 if (flags[i] == kIframesEnabledFlagWithValue) | 515 if (flags[i] == kIframesEnabledFlagWithValue) |
507 return true; | 516 return true; |
508 } | 517 } |
509 return false; | 518 return false; |
510 } | 519 } |
OLD | NEW |