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

Side by Side Diff: chrome/browser/instant/instant_controller.cc

Issue 11415292: [Search] No longer reverting omnibox text on instant search (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: session_types comment Created 8 years 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
OLDNEW
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/browser/instant/instant_controller.h" 5 #include "chrome/browser/instant/instant_controller.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 return false; 442 return false;
443 443
444 if (type == INSTANT_COMMIT_FOCUS_LOST) 444 if (type == INSTANT_COMMIT_FOCUS_LOST)
445 loader_->Cancel(last_omnibox_text_); 445 loader_->Cancel(last_omnibox_text_);
446 else 446 else
447 loader_->Submit(last_omnibox_text_); 447 loader_->Submit(last_omnibox_text_);
448 448
449 content::WebContents* preview = loader_->ReleaseContents(); 449 content::WebContents* preview = loader_->ReleaseContents();
450 450
451 if (extended_enabled_) { 451 if (extended_enabled_) {
452 // Consider what's happening: 452 string16 search_terms = last_omnibox_text_;
453 // 1. The user has typed a query in the omnibox and committed it (either 453 if (type == INSTANT_COMMIT_FOCUS_LOST &&
454 // by pressing Enter or clicking on the preview). 454 last_suggestion_.behavior == INSTANT_COMPLETE_NEVER)
455 // 2. We commit the preview to the tab strip, and tell the page. 455 search_terms += last_suggestion_.text;
Jered 2012/12/07 00:16:03 Indent.
Mathieu 2012/12/11 00:30:17 Done.
456 // 3. The page will update the URL hash fragment with the query terms. 456 preview->GetController().GetVisibleEntry()->SetSearchTerms(search_terms);
457 // After steps 1 and 3, the omnibox will show the query terms. However, if
458 // the URL we are committing at step 2 doesn't already have query terms, it
459 // will flash for a brief moment as a plain URL. So, avoid that flicker by
460 // pretending that the plain URL is actually the typed query terms.
461 // TODO(samarth,beaudoin): Instead of this hack, we should add a new field
462 // to NavigationEntry to keep track of what the correct query, if any, is.
463 content::NavigationEntry* entry =
464 preview->GetController().GetVisibleEntry();
465 std::string url = entry->GetVirtualURL().spec();
466 if (!google_util::IsInstantExtendedAPIGoogleSearchUrl(url) &&
467 google_util::IsGoogleDomainUrl(url, google_util::ALLOW_SUBDOMAIN,
468 google_util::ALLOW_NON_STANDARD_PORTS)) {
469 entry->SetVirtualURL(GURL(
470 url + "#q=" +
471 net::EscapeQueryParamValue(UTF16ToUTF8(last_omnibox_text_), true)));
472 chrome::search::SearchTabHelper::FromWebContents(preview)->
473 NavigationEntryUpdated();
474 }
475 } 457 }
476 458
477 // If the preview page has navigated since the last Update(), we need to add 459 // If the preview page has navigated since the last Update(), we need to add
478 // the navigation to history ourselves. Else, the page will navigate after 460 // the navigation to history ourselves. Else, the page will navigate after
479 // commit, and it will be added to history in the usual manner. 461 // commit, and it will be added to history in the usual manner.
480 const history::HistoryAddPageArgs& last_navigation = 462 const history::HistoryAddPageArgs& last_navigation =
481 loader_->last_navigation(); 463 loader_->last_navigation();
482 if (!last_navigation.url.is_empty()) { 464 if (!last_navigation.url.is_empty()) {
483 content::NavigationEntry* entry = preview->GetController().GetActiveEntry(); 465 content::NavigationEntry* entry = preview->GetController().GetActiveEntry();
484 DCHECK_EQ(last_navigation.url, entry->GetURL()); 466 DCHECK_EQ(last_navigation.url, entry->GetURL());
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after
1005 } 987 }
1006 988
1007 std::map<std::string, int>::const_iterator iter = 989 std::map<std::string, int>::const_iterator iter =
1008 blacklisted_urls_.find(*instant_url); 990 blacklisted_urls_.find(*instant_url);
1009 if (iter != blacklisted_urls_.end() && 991 if (iter != blacklisted_urls_.end() &&
1010 iter->second > kMaxInstantSupportFailures) 992 iter->second > kMaxInstantSupportFailures)
1011 return false; 993 return false;
1012 994
1013 return true; 995 return true;
1014 } 996 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698