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

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: indent 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 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 418
419 content::WebContents* InstantController::GetPreviewContents() const { 419 content::WebContents* InstantController::GetPreviewContents() const {
420 return loader_ ? loader_->contents() : NULL; 420 return loader_ ? loader_->contents() : NULL;
421 } 421 }
422 422
423 bool InstantController::IsPreviewingSearchResults() const { 423 bool InstantController::IsPreviewingSearchResults() const {
424 return model_.mode().is_search_suggestions() && last_match_was_search_ && 424 return model_.mode().is_search_suggestions() && last_match_was_search_ &&
425 IsFullHeight(model_); 425 IsFullHeight(model_);
426 } 426 }
427 427
428 bool InstantController::IsInstantExtendedSearch() const {
429 return extended_enabled_ && instant_enabled_ && last_match_was_search_;
430 }
431
428 bool InstantController::CommitIfPossible(InstantCommitType type) { 432 bool InstantController::CommitIfPossible(InstantCommitType type) {
429 if (!extended_enabled_ && !instant_enabled_) 433 if (!extended_enabled_ && !instant_enabled_)
430 return false; 434 return false;
431 435
432 DVLOG(1) << "CommitIfPossible: type=" << type << " last_omnibox_text_='" 436 DVLOG(1) << "CommitIfPossible: type=" << type << " last_omnibox_text_='"
433 << last_omnibox_text_ << "' last_match_was_search_=" 437 << last_omnibox_text_ << "' last_match_was_search_="
434 << last_match_was_search_ << " instant_tab_=" << instant_tab_; 438 << last_match_was_search_ << " instant_tab_=" << instant_tab_;
435 439
436 // If we are on an already committed search results page, send a submit event 440 // If we are on an already committed search results page, send a submit event
437 // to the page, but otherwise, nothing else to do. 441 // to the page, but otherwise, nothing else to do.
(...skipping 10 matching lines...) Expand all
448 return false; 452 return false;
449 453
450 if (type == INSTANT_COMMIT_FOCUS_LOST) 454 if (type == INSTANT_COMMIT_FOCUS_LOST)
451 loader_->Cancel(last_omnibox_text_); 455 loader_->Cancel(last_omnibox_text_);
452 else if (type != INSTANT_COMMIT_NAVIGATED) 456 else if (type != INSTANT_COMMIT_NAVIGATED)
453 loader_->Submit(last_omnibox_text_); 457 loader_->Submit(last_omnibox_text_);
454 458
455 content::WebContents* preview = loader_->ReleaseContents(); 459 content::WebContents* preview = loader_->ReleaseContents();
456 460
457 if (extended_enabled_) { 461 if (extended_enabled_) {
458 // Consider what's happening: 462 string16 search_terms = last_omnibox_text_;
459 // 1. The user has typed a query in the omnibox and committed it (either 463 if (type == INSTANT_COMMIT_FOCUS_LOST &&
460 // by pressing Enter or clicking on the preview). 464 last_suggestion_.behavior == INSTANT_COMPLETE_NEVER) {
461 // 2. We commit the preview to the tab strip, and tell the page. 465 // User clicked on the preview, which makes a search based on the input +
462 // 3. The page will update the URL hash fragment with the query terms. 466 // gray text (i.e. |last_suggestion_.text|). Make sure the search terms
463 // After steps 1 and 3, the omnibox will show the query terms. However, if 467 // reflect this search.
464 // the URL we are committing at step 2 doesn't already have query terms, it 468 search_terms += last_suggestion_.text;
465 // will flash for a brief moment as a plain URL. So, avoid that flicker by
466 // pretending that the plain URL is actually the typed query terms.
467 // TODO(samarth,beaudoin): Instead of this hack, we should add a new field
468 // to NavigationEntry to keep track of what the correct query, if any, is.
469 content::NavigationEntry* entry =
470 preview->GetController().GetVisibleEntry();
471 std::string url = entry->GetVirtualURL().spec();
472 if (!google_util::IsInstantExtendedAPIGoogleSearchUrl(url) &&
473 google_util::IsGoogleDomainUrl(url, google_util::ALLOW_SUBDOMAIN,
474 google_util::ALLOW_NON_STANDARD_PORTS)) {
475 entry->SetVirtualURL(GURL(
476 url + "#q=" +
477 net::EscapeQueryParamValue(UTF16ToUTF8(last_omnibox_text_), true)));
478 chrome::search::SearchTabHelper::FromWebContents(preview)->
479 NavigationEntryUpdated();
480 } 469 }
470 preview->GetController().GetActiveEntry()->SetSearchTerms(search_terms);
471 chrome::search::SearchTabHelper::FromWebContents(preview)->
472 NavigationEntryUpdated();
481 } 473 }
482 474
483 // If the preview page has navigated since the last Update(), we need to add 475 // If the preview page has navigated since the last Update(), we need to add
484 // the navigation to history ourselves. Else, the page will navigate after 476 // the navigation to history ourselves. Else, the page will navigate after
485 // commit, and it will be added to history in the usual manner. 477 // commit, and it will be added to history in the usual manner.
486 const history::HistoryAddPageArgs& last_navigation = 478 const history::HistoryAddPageArgs& last_navigation =
487 loader_->last_navigation(); 479 loader_->last_navigation();
488 if (!last_navigation.url.is_empty()) { 480 if (!last_navigation.url.is_empty()) {
489 content::NavigationEntry* entry = preview->GetController().GetActiveEntry(); 481 content::NavigationEntry* entry = preview->GetController().GetActiveEntry();
490 482
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after
1075 } 1067 }
1076 1068
1077 std::map<std::string, int>::const_iterator iter = 1069 std::map<std::string, int>::const_iterator iter =
1078 blacklisted_urls_.find(*instant_url); 1070 blacklisted_urls_.find(*instant_url);
1079 if (iter != blacklisted_urls_.end() && 1071 if (iter != blacklisted_urls_.end() &&
1080 iter->second > kMaxInstantSupportFailures) 1072 iter->second > kMaxInstantSupportFailures)
1081 return false; 1073 return false;
1082 1074
1083 return true; 1075 return true;
1084 } 1076 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698