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

Side by Side Diff: chrome/browser/ui/search/instant_controller.cc

Issue 17303003: InstantExtended: hook up InstantTab in incognito. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compile errors. Created 7 years, 6 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 | Annotate | Revision Log
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/ui/search/instant_controller.h" 5 #include "chrome/browser/ui/search/instant_controller.h"
6 6
7 #include <iterator> 7 #include <iterator>
8 8
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 last_omnibox_text_ = full_text; 332 last_omnibox_text_ = full_text;
333 last_match_was_search_ = AutocompleteMatch::IsSearchType(match.type) && 333 last_match_was_search_ = AutocompleteMatch::IsSearchType(match.type) &&
334 !user_text.empty(); 334 !user_text.empty();
335 335
336 // TODO(dhollowa): Complete keyword match UI. For now just hide suggestions. 336 // TODO(dhollowa): Complete keyword match UI. For now just hide suggestions.
337 // http://crbug.com/153932. Note, this early escape is happens prior to the 337 // http://crbug.com/153932. Note, this early escape is happens prior to the
338 // DCHECKs below because |user_text| and |full_text| have different semantics 338 // DCHECKs below because |user_text| and |full_text| have different semantics
339 // when keyword search is in effect. 339 // when keyword search is in effect.
340 if (is_keyword_search) { 340 if (is_keyword_search) {
341 if (UseTabForSuggestions()) 341 if (UseTabForSuggestions())
342 instant_tab_->Update(string16(), 0, 0, true); 342 instant_tab_->sender()->Update(string16(), 0, 0, true);
343 else 343 else
344 HideOverlay(); 344 HideOverlay();
345 last_match_was_search_ = false; 345 last_match_was_search_ = false;
346 last_suggestion_ = InstantSuggestion(); 346 last_suggestion_ = InstantSuggestion();
347 return false; 347 return false;
348 } 348 }
349 349
350 // Ignore spurious updates when the omnibox is blurred; otherwise click 350 // Ignore spurious updates when the omnibox is blurred; otherwise click
351 // targets on the page may vanish before a click event arrives. 351 // targets on the page may vanish before a click event arrives.
352 if (omnibox_focus_state_ == OMNIBOX_FOCUS_NONE) 352 if (omnibox_focus_state_ == OMNIBOX_FOCUS_NONE)
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 // be pointing to the previous tab (which was a search results page). 406 // be pointing to the previous tab (which was a search results page).
407 // Ensure we don't send the omnibox text to a random webpage (the new 407 // Ensure we don't send the omnibox text to a random webpage (the new
408 // tab), by comparing the old and new WebContents. 408 // tab), by comparing the old and new WebContents.
409 if (escape_pressed && 409 if (escape_pressed &&
410 instant_tab_->contents() == browser_->GetActiveWebContents()) { 410 instant_tab_->contents() == browser_->GetActiveWebContents()) {
411 // TODO(kmadhusu): If the |full_text| is not empty, send an 411 // TODO(kmadhusu): If the |full_text| is not empty, send an
412 // onkeypress(esc) to the Instant page. Do not call 412 // onkeypress(esc) to the Instant page. Do not call
413 // onsubmit(full_text). Fix. 413 // onsubmit(full_text). Fix.
414 if (full_text.empty()) { 414 if (full_text.empty()) {
415 // Call onchange("") to clear the query for the page. 415 // Call onchange("") to clear the query for the page.
416 instant_tab_->Update(string16(), 0, 0, true); 416 instant_tab_->sender()->Update(string16(), 0, 0, true);
417 instant_tab_->EscKeyPressed(); 417 instant_tab_->sender()->EscKeyPressed();
418 } else { 418 } else {
419 instant_tab_->Submit(full_text); 419 instant_tab_->sender()->Submit(full_text);
420 } 420 }
421 } 421 }
422 } else if (!full_text.empty()) { 422 } else if (!full_text.empty()) {
423 // If |full_text| is empty, the user is on the NTP. The overlay may 423 // If |full_text| is empty, the user is on the NTP. The overlay may
424 // be showing custom NTP content; hide only if that's not the case. 424 // be showing custom NTP content; hide only if that's not the case.
425 HideOverlay(); 425 HideOverlay();
426 } 426 }
427 } else if (full_text.empty()) { 427 } else if (full_text.empty()) {
428 // The user is typing, and backspaced away all omnibox text. Clear 428 // The user is typing, and backspaced away all omnibox text. Clear
429 // |last_omnibox_text_| so that we don't attempt to set suggestions. 429 // |last_omnibox_text_| so that we don't attempt to set suggestions.
430 last_omnibox_text_.clear(); 430 last_omnibox_text_.clear();
431 last_user_text_.clear(); 431 last_user_text_.clear();
432 last_suggestion_ = InstantSuggestion(); 432 last_suggestion_ = InstantSuggestion();
433 if (UseTabForSuggestions()) { 433 if (UseTabForSuggestions()) {
434 // On a search results page, tell it to clear old results. 434 // On a search results page, tell it to clear old results.
435 instant_tab_->Update(string16(), 0, 0, true); 435 instant_tab_->sender()->Update(string16(), 0, 0, true);
436 } else if (overlay_ && search_mode_.is_origin_ntp()) { 436 } else if (overlay_ && search_mode_.is_origin_ntp()) {
437 // On the NTP, tell the overlay to clear old results. Don't hide the 437 // On the NTP, tell the overlay to clear old results. Don't hide the
438 // overlay so it can show a blank page or logo if it wants. 438 // overlay so it can show a blank page or logo if it wants.
439 overlay_->Update(string16(), 0, 0, true); 439 overlay_->Update(string16(), 0, 0, true);
440 } else { 440 } else {
441 HideOverlay(); 441 HideOverlay();
442 } 442 }
443 } else { 443 } else {
444 // The user switched to a tab with partial text already in the omnibox. 444 // The user switched to a tab with partial text already in the omnibox.
445 HideOverlay(); 445 HideOverlay();
446 446
447 // The new tab may or may not be a search results page; we don't know 447 // The new tab may or may not be a search results page; we don't know
448 // since SearchModeChanged() hasn't been called yet. If it later turns 448 // since SearchModeChanged() hasn't been called yet. If it later turns
449 // out to be, we should store |full_text| now, so that if the user hits 449 // out to be, we should store |full_text| now, so that if the user hits
450 // Enter, we'll send the correct query to instant_tab_->Submit(). If the 450 // Enter, we'll send the correct query to
451 // partial text is not a query (|last_match_was_search_| is false), we 451 // instant_tab_->sender()->Submit(). If the partial text is not a query
452 // won't Submit(), so no need to worry about that. 452 // (|last_match_was_search_| is false), we won't Submit(), so no need to
453 // worry about that.
453 last_user_text_ = user_text; 454 last_user_text_ = user_text;
454 last_suggestion_ = InstantSuggestion(); 455 last_suggestion_ = InstantSuggestion();
455 } 456 }
456 return false; 457 return false;
457 } else if (full_text.empty()) { 458 } else if (full_text.empty()) {
458 // The user typed a solitary "?". Same as the backspace case above. 459 // The user typed a solitary "?". Same as the backspace case above.
459 last_omnibox_text_.clear(); 460 last_omnibox_text_.clear();
460 last_user_text_.clear(); 461 last_user_text_.clear();
461 last_suggestion_ = InstantSuggestion(); 462 last_suggestion_ = InstantSuggestion();
462 if (UseTabForSuggestions()) 463 if (UseTabForSuggestions())
463 instant_tab_->Update(string16(), 0, 0, true); 464 instant_tab_->sender()->Update(string16(), 0, 0, true);
464 else if (overlay_ && search_mode_.is_origin_ntp()) 465 else if (overlay_ && search_mode_.is_origin_ntp())
465 overlay_->Update(string16(), 0, 0, true); 466 overlay_->Update(string16(), 0, 0, true);
466 else 467 else
467 HideOverlay(); 468 HideOverlay();
468 return false; 469 return false;
469 } 470 }
470 } else if (!omnibox_popup_is_open || full_text.empty()) { 471 } else if (!omnibox_popup_is_open || full_text.empty()) {
471 // In the non-extended case, hide the overlay as long as the user isn't 472 // In the non-extended case, hide the overlay as long as the user isn't
472 // actively typing a non-empty query. 473 // actively typing a non-empty query.
473 HideOverlay(); 474 HideOverlay();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 510
510 last_transition_type_ = match.transition; 511 last_transition_type_ = match.transition;
511 url_for_history_ = match.destination_url; 512 url_for_history_ = match.destination_url;
512 513
513 // Allow search suggestions. In extended mode, SearchModeChanged() will set 514 // Allow search suggestions. In extended mode, SearchModeChanged() will set
514 // this, but it's not called in non-extended mode, so fake it. 515 // this, but it's not called in non-extended mode, so fake it.
515 if (!extended_enabled()) 516 if (!extended_enabled())
516 search_mode_.mode = SearchMode::MODE_SEARCH_SUGGESTIONS; 517 search_mode_.mode = SearchMode::MODE_SEARCH_SUGGESTIONS;
517 518
518 if (UseTabForSuggestions()) { 519 if (UseTabForSuggestions()) {
519 instant_tab_->Update(user_text, selection_start, selection_end, verbatim); 520 instant_tab_->sender()->Update(user_text, selection_start,
521 selection_end, verbatim);
520 } else if (overlay_) { 522 } else if (overlay_) {
521 allow_overlay_to_show_search_suggestions_ = true; 523 allow_overlay_to_show_search_suggestions_ = true;
522 524
523 overlay_->Update(extended_enabled() ? user_text : full_text, 525 overlay_->Update(extended_enabled() ? user_text : full_text,
524 selection_start, selection_end, verbatim); 526 selection_start, selection_end, verbatim);
525 } 527 }
526 528
527 content::NotificationService::current()->Notify( 529 content::NotificationService::current()->Notify(
528 chrome::NOTIFICATION_INSTANT_CONTROLLER_UPDATED, 530 chrome::NOTIFICATION_INSTANT_CONTROLLER_UPDATED,
529 content::Source<InstantController>(this), 531 content::Source<InstantController>(this),
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 &InstantController::SendPopupBoundsToPage); 590 &InstantController::SendPopupBoundsToPage);
589 } 591 }
590 } 592 }
591 593
592 void InstantController::SetOmniboxBounds(const gfx::Rect& bounds) { 594 void InstantController::SetOmniboxBounds(const gfx::Rect& bounds) {
593 if (!extended_enabled() || omnibox_bounds_ == bounds) 595 if (!extended_enabled() || omnibox_bounds_ == bounds)
594 return; 596 return;
595 597
596 omnibox_bounds_ = bounds; 598 omnibox_bounds_ = bounds;
597 if (overlay_) 599 if (overlay_)
598 overlay_->SetOmniboxBounds(omnibox_bounds_); 600 overlay_->sender()->SetOmniboxBounds(omnibox_bounds_);
599 if (ntp_) 601 if (ntp_)
600 ntp_->SetOmniboxBounds(omnibox_bounds_); 602 ntp_->sender()->SetOmniboxBounds(omnibox_bounds_);
601 if (instant_tab_) 603 if (instant_tab_)
602 instant_tab_->SetOmniboxBounds(omnibox_bounds_); 604 instant_tab_->sender()->SetOmniboxBounds(omnibox_bounds_);
603 } 605 }
604 606
605 void InstantController::HandleAutocompleteResults( 607 void InstantController::HandleAutocompleteResults(
606 const std::vector<AutocompleteProvider*>& providers, 608 const std::vector<AutocompleteProvider*>& providers,
607 const AutocompleteResult& autocomplete_result) { 609 const AutocompleteResult& autocomplete_result) {
608 if (!extended_enabled()) 610 if (!extended_enabled())
609 return; 611 return;
610 612
611 if (!UseTabForSuggestions() && !overlay_) 613 if (!UseTabForSuggestions() && !overlay_)
612 return; 614 return;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 &result); 665 &result);
664 results.push_back(result); 666 results.push_back(result);
665 } 667 }
666 } 668 }
667 } 669 }
668 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( 670 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf(
669 "HandleAutocompleteResults: total_results=%d", 671 "HandleAutocompleteResults: total_results=%d",
670 static_cast<int>(results.size()))); 672 static_cast<int>(results.size())));
671 673
672 if (UseTabForSuggestions()) 674 if (UseTabForSuggestions())
673 instant_tab_->SendAutocompleteResults(results); 675 instant_tab_->sender()->SendAutocompleteResults(results);
674 else if (overlay_) 676 else if (overlay_)
675 overlay_->SendAutocompleteResults(results); 677 overlay_->sender()->SendAutocompleteResults(results);
676 678
677 content::NotificationService::current()->Notify( 679 content::NotificationService::current()->Notify(
678 chrome::NOTIFICATION_INSTANT_SENT_AUTOCOMPLETE_RESULTS, 680 chrome::NOTIFICATION_INSTANT_SENT_AUTOCOMPLETE_RESULTS,
679 content::Source<InstantController>(this), 681 content::Source<InstantController>(this),
680 content::NotificationService::NoDetails()); 682 content::NotificationService::NoDetails());
681 } 683 }
682 684
683 void InstantController::OnDefaultSearchProviderChanged() { 685 void InstantController::OnDefaultSearchProviderChanged() {
684 if (ntp_ && extended_enabled()) { 686 if (ntp_ && extended_enabled()) {
685 ntp_.reset(); 687 ntp_.reset();
(...skipping 13 matching lines...) Expand all
699 } 701 }
700 702
701 bool InstantController::OnUpOrDownKeyPressed(int count) { 703 bool InstantController::OnUpOrDownKeyPressed(int count) {
702 if (!extended_enabled()) 704 if (!extended_enabled())
703 return false; 705 return false;
704 706
705 if (!UseTabForSuggestions() && !overlay_) 707 if (!UseTabForSuggestions() && !overlay_)
706 return false; 708 return false;
707 709
708 if (UseTabForSuggestions()) 710 if (UseTabForSuggestions())
709 instant_tab_->UpOrDownKeyPressed(count); 711 instant_tab_->sender()->UpOrDownKeyPressed(count);
710 else if (overlay_) 712 else if (overlay_)
711 overlay_->UpOrDownKeyPressed(count); 713 overlay_->sender()->UpOrDownKeyPressed(count);
712 714
713 return true; 715 return true;
714 } 716 }
715 717
716 void InstantController::OnCancel(const AutocompleteMatch& match, 718 void InstantController::OnCancel(const AutocompleteMatch& match,
717 const string16& user_text, 719 const string16& user_text,
718 const string16& full_text) { 720 const string16& full_text) {
719 if (!extended_enabled()) 721 if (!extended_enabled())
720 return; 722 return;
721 723
722 if (!UseTabForSuggestions() && !overlay_) 724 if (!UseTabForSuggestions() && !overlay_)
723 return; 725 return;
724 726
725 // We manually reset the state here since the JS is not expected to do it. 727 // We manually reset the state here since the JS is not expected to do it.
726 // TODO(sreeram): Handle the case where user_text is now a URL 728 // TODO(sreeram): Handle the case where user_text is now a URL
727 last_match_was_search_ = AutocompleteMatch::IsSearchType(match.type) && 729 last_match_was_search_ = AutocompleteMatch::IsSearchType(match.type) &&
728 !full_text.empty(); 730 !full_text.empty();
729 last_omnibox_text_ = full_text; 731 last_omnibox_text_ = full_text;
730 last_user_text_ = user_text; 732 last_user_text_ = user_text;
731 last_suggestion_ = InstantSuggestion(); 733 last_suggestion_ = InstantSuggestion();
732 734
733 // Say |full_text| is "amazon.com" and |user_text| is "ama". This means the 735 // Say |full_text| is "amazon.com" and |user_text| is "ama". This means the
734 // inline autocompletion is "zon.com"; so the selection should span from 736 // inline autocompletion is "zon.com"; so the selection should span from
735 // user_text.size() to full_text.size(). The selection bounds are inverted 737 // user_text.size() to full_text.size(). The selection bounds are inverted
736 // because the caret is at the end of |user_text|, not |full_text|. 738 // because the caret is at the end of |user_text|, not |full_text|.
737 if (UseTabForSuggestions()) { 739 if (UseTabForSuggestions()) {
738 instant_tab_->CancelSelection(user_text, full_text.size(), user_text.size(), 740 instant_tab_->sender()->CancelSelection(user_text, full_text.size(),
739 last_verbatim_); 741 user_text.size(), last_verbatim_);
740 } else if (overlay_) { 742 } else if (overlay_) {
741 overlay_->CancelSelection(user_text, full_text.size(), user_text.size(), 743 overlay_->sender()->CancelSelection(user_text, full_text.size(),
742 last_verbatim_); 744 user_text.size(), last_verbatim_);
743 } 745 }
744 } 746 }
745 747
746 void InstantController::OmniboxNavigateToURL() { 748 void InstantController::OmniboxNavigateToURL() {
747 RecordNavigationHistogram(UsingLocalPage(), false, extended_enabled()); 749 RecordNavigationHistogram(UsingLocalPage(), false, extended_enabled());
748 if (!extended_enabled()) 750 if (!extended_enabled())
749 return; 751 return;
750 if (UseTabForSuggestions()) 752 if (UseTabForSuggestions())
751 instant_tab_->Submit(string16()); 753 instant_tab_->sender()->Submit(string16());
752 } 754 }
753 755
754 void InstantController::ToggleVoiceSearch() { 756 void InstantController::ToggleVoiceSearch() {
755 if (instant_tab_) 757 if (instant_tab_)
756 instant_tab_->ToggleVoiceSearch(); 758 instant_tab_->sender()->ToggleVoiceSearch();
757 } 759 }
758 760
759 void InstantController::InstantPageLoadFailed(content::WebContents* contents) { 761 void InstantController::InstantPageLoadFailed(content::WebContents* contents) {
760 if (!chrome::ShouldPreferRemoteNTPOnStartup() || !extended_enabled()) { 762 if (!chrome::ShouldPreferRemoteNTPOnStartup() || !extended_enabled()) {
761 // We only need to fall back on errors if we're showing the online page 763 // We only need to fall back on errors if we're showing the online page
762 // at startup, as otherwise we fall back correctly when trying to show 764 // at startup, as otherwise we fall back correctly when trying to show
763 // a page that hasn't yet indicated that it supports the InstantExtended 765 // a page that hasn't yet indicated that it supports the InstantExtended
764 // API. 766 // API.
765 return; 767 return;
766 } 768 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 return model_.mode().is_search_suggestions() && IsFullHeight(model_) && 811 return model_.mode().is_search_suggestions() && IsFullHeight(model_) &&
810 (last_match_was_search_ || 812 (last_match_was_search_ ||
811 last_suggestion_.behavior == INSTANT_COMPLETE_NEVER); 813 last_suggestion_.behavior == INSTANT_COMPLETE_NEVER);
812 } 814 }
813 815
814 bool InstantController::SubmitQuery(const string16& search_terms) { 816 bool InstantController::SubmitQuery(const string16& search_terms) {
815 if (extended_enabled() && instant_tab_ && instant_tab_->supports_instant() && 817 if (extended_enabled() && instant_tab_ && instant_tab_->supports_instant() &&
816 search_mode_.is_origin_search()) { 818 search_mode_.is_origin_search()) {
817 // Use |instant_tab_| to run the query if we're already on a search results 819 // Use |instant_tab_| to run the query if we're already on a search results
818 // page. (NOTE: in particular, we do not send the query to NTPs.) 820 // page. (NOTE: in particular, we do not send the query to NTPs.)
819 instant_tab_->Submit(search_terms); 821 instant_tab_->sender()->Submit(search_terms);
820 instant_tab_->contents()->GetView()->Focus(); 822 instant_tab_->contents()->GetView()->Focus();
821 EnsureSearchTermsAreSet(instant_tab_->contents(), search_terms); 823 EnsureSearchTermsAreSet(instant_tab_->contents(), search_terms);
822 return true; 824 return true;
823 } 825 }
824 return false; 826 return false;
825 } 827 }
826 828
827 bool InstantController::CommitIfPossible(InstantCommitType type) { 829 bool InstantController::CommitIfPossible(InstantCommitType type) {
828 if (!extended_enabled() && !instant_enabled_) 830 if (!extended_enabled() && !instant_enabled_)
829 return false; 831 return false;
830 832
831 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( 833 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf(
832 "CommitIfPossible: type=%d last_omnibox_text_='%s' " 834 "CommitIfPossible: type=%d last_omnibox_text_='%s' "
833 "last_match_was_search_=%d use_tab_for_suggestions=%d", type, 835 "last_match_was_search_=%d use_tab_for_suggestions=%d", type,
834 UTF16ToUTF8(last_omnibox_text_).c_str(), last_match_was_search_, 836 UTF16ToUTF8(last_omnibox_text_).c_str(), last_match_was_search_,
835 UseTabForSuggestions())); 837 UseTabForSuggestions()));
836 838
837 // If we are on an already committed search results page, send a submit event 839 // If we are on an already committed search results page, send a submit event
838 // to the page, but otherwise, nothing else to do. 840 // to the page, but otherwise, nothing else to do.
839 if (UseTabForSuggestions()) { 841 if (UseTabForSuggestions()) {
840 if (type == INSTANT_COMMIT_PRESSED_ENTER && 842 if (type == INSTANT_COMMIT_PRESSED_ENTER &&
841 !instant_tab_->IsLocal() && 843 !instant_tab_->IsLocal() &&
842 (last_match_was_search_ || 844 (last_match_was_search_ ||
843 last_suggestion_.behavior == INSTANT_COMPLETE_NEVER)) { 845 last_suggestion_.behavior == INSTANT_COMPLETE_NEVER)) {
844 last_suggestion_.text.clear(); 846 last_suggestion_.text.clear();
845 instant_tab_->Submit(last_omnibox_text_); 847 instant_tab_->sender()->Submit(last_omnibox_text_);
846 instant_tab_->contents()->GetView()->Focus(); 848 instant_tab_->contents()->GetView()->Focus();
847 EnsureSearchTermsAreSet(instant_tab_->contents(), last_omnibox_text_); 849 EnsureSearchTermsAreSet(instant_tab_->contents(), last_omnibox_text_);
848 return true; 850 return true;
849 } 851 }
850 return false; 852 return false;
851 } 853 }
852 854
853 if (!overlay_) 855 if (!overlay_)
854 return false; 856 return false;
855 857
(...skipping 12 matching lines...) Expand all
868 if (!GetOverlayContents()) 870 if (!GetOverlayContents())
869 return false; 871 return false;
870 872
871 // Never commit the local overlay. 873 // Never commit the local overlay.
872 if (overlay_->IsLocal()) 874 if (overlay_->IsLocal())
873 return false; 875 return false;
874 876
875 if (type == INSTANT_COMMIT_FOCUS_LOST) { 877 if (type == INSTANT_COMMIT_FOCUS_LOST) {
876 // Extended mode doesn't need or use the Cancel message. 878 // Extended mode doesn't need or use the Cancel message.
877 if (!extended_enabled()) 879 if (!extended_enabled())
878 overlay_->Cancel(last_omnibox_text_); 880 overlay_->sender()->Cancel(last_omnibox_text_);
879 } else if (type != INSTANT_COMMIT_NAVIGATED) { 881 } else if (type != INSTANT_COMMIT_NAVIGATED) {
880 overlay_->Submit(last_omnibox_text_); 882 overlay_->sender()->Submit(last_omnibox_text_);
881 } 883 }
882 884
883 // We expect the WebContents to be in a valid state (i.e., has a last 885 // We expect the WebContents to be in a valid state (i.e., has a last
884 // committed entry, no transient entry, and no existing pending entry). 886 // committed entry, no transient entry, and no existing pending entry).
885 scoped_ptr<content::WebContents> overlay = overlay_->ReleaseContents(); 887 scoped_ptr<content::WebContents> overlay = overlay_->ReleaseContents();
886 CHECK(overlay->GetController().CanPruneAllButVisible()); 888 CHECK(overlay->GetController().CanPruneAllButVisible());
887 889
888 // If the overlay page has navigated since the last Update(), we need to add 890 // If the overlay page has navigated since the last Update(), we need to add
889 // the navigation to history ourselves. Else, the page will navigate after 891 // the navigation to history ourselves. Else, the page will navigate after
890 // commit, and it will be added to history in the usual manner. 892 // commit, and it will be added to history in the usual manner.
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
982 "OmniboxFocusChanged: %d to %d for reason %d", omnibox_focus_state_, 984 "OmniboxFocusChanged: %d to %d for reason %d", omnibox_focus_state_,
983 state, reason)); 985 state, reason));
984 986
985 OmniboxFocusState old_focus_state = omnibox_focus_state_; 987 OmniboxFocusState old_focus_state = omnibox_focus_state_;
986 omnibox_focus_state_ = state; 988 omnibox_focus_state_ = state;
987 if (!extended_enabled() && !instant_enabled_) 989 if (!extended_enabled() && !instant_enabled_)
988 return; 990 return;
989 991
990 if (extended_enabled()) { 992 if (extended_enabled()) {
991 if (overlay_) 993 if (overlay_)
992 overlay_->FocusChanged(omnibox_focus_state_, reason); 994 overlay_->sender()->FocusChanged(omnibox_focus_state_, reason);
993 995
994 if (instant_tab_) { 996 if (instant_tab_) {
995 instant_tab_->FocusChanged(omnibox_focus_state_, reason); 997 instant_tab_->sender()->FocusChanged(omnibox_focus_state_, reason);
996 // Don't send oninputstart/oninputend updates in response to focus changes 998 // Don't send oninputstart/oninputend updates in response to focus changes
997 // if there's a navigation in progress. This prevents Chrome from sending 999 // if there's a navigation in progress. This prevents Chrome from sending
998 // a spurious oninputend when the user accepts a match in the omnibox. 1000 // a spurious oninputend when the user accepts a match in the omnibox.
999 if (instant_tab_->contents()->GetController().GetPendingEntry() == NULL) 1001 if (instant_tab_->contents()->GetController().GetPendingEntry() == NULL)
1000 instant_tab_->SetInputInProgress(IsInputInProgress()); 1002 instant_tab_->sender()->SetInputInProgress(IsInputInProgress());
1001 } 1003 }
1002 } 1004 }
1003 1005
1004 if (state == OMNIBOX_FOCUS_VISIBLE && old_focus_state == OMNIBOX_FOCUS_NONE) { 1006 if (state == OMNIBOX_FOCUS_VISIBLE && old_focus_state == OMNIBOX_FOCUS_NONE) {
1005 // If the user explicitly focused the omnibox, then create the overlay if 1007 // If the user explicitly focused the omnibox, then create the overlay if
1006 // it doesn't exist. If we're using a fallback overlay, try loading the 1008 // it doesn't exist. If we're using a fallback overlay, try loading the
1007 // remote overlay again. 1009 // remote overlay again.
1008 if (!overlay_ || (overlay_->IsLocal() && !use_local_page_only_)) 1010 if (!overlay_ || (overlay_->IsLocal() && !use_local_page_only_))
1009 ResetOverlay(GetInstantURL()); 1011 ResetOverlay(GetInstantURL());
1010 } else if (state == OMNIBOX_FOCUS_NONE && 1012 } else if (state == OMNIBOX_FOCUS_NONE &&
(...skipping 13 matching lines...) Expand all
1024 "SearchModeChanged: [origin:mode] %d:%d to %d:%d", old_mode.origin, 1026 "SearchModeChanged: [origin:mode] %d:%d to %d:%d", old_mode.origin,
1025 old_mode.mode, new_mode.origin, new_mode.mode)); 1027 old_mode.mode, new_mode.origin, new_mode.mode));
1026 1028
1027 search_mode_ = new_mode; 1029 search_mode_ = new_mode;
1028 if (!new_mode.is_search_suggestions()) 1030 if (!new_mode.is_search_suggestions())
1029 HideOverlay(); 1031 HideOverlay();
1030 1032
1031 ResetInstantTab(); 1033 ResetInstantTab();
1032 1034
1033 if (instant_tab_ && old_mode.is_ntp() != new_mode.is_ntp()) 1035 if (instant_tab_ && old_mode.is_ntp() != new_mode.is_ntp())
1034 instant_tab_->SetInputInProgress(IsInputInProgress()); 1036 instant_tab_->sender()->SetInputInProgress(IsInputInProgress());
1035 } 1037 }
1036 1038
1037 void InstantController::ActiveTabChanged() { 1039 void InstantController::ActiveTabChanged() {
1038 if (!extended_enabled() && !instant_enabled_) 1040 if (!extended_enabled() && !instant_enabled_)
1039 return; 1041 return;
1040 1042
1041 LOG_INSTANT_DEBUG_EVENT(this, "ActiveTabChanged"); 1043 LOG_INSTANT_DEBUG_EVENT(this, "ActiveTabChanged");
1042 1044
1043 // When switching tabs, always hide the overlay. 1045 // When switching tabs, always hide the overlay.
1044 HideOverlay(); 1046 HideOverlay();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1078 overlay_.reset(); 1080 overlay_.reset();
1079 if (extended_enabled() || instant_enabled_) 1081 if (extended_enabled() || instant_enabled_)
1080 ResetOverlay(GetInstantURL()); 1082 ResetOverlay(GetInstantURL());
1081 1083
1082 // Preload the Instant NTP. 1084 // Preload the Instant NTP.
1083 ntp_.reset(); 1085 ntp_.reset();
1084 if (extended_enabled() && preload_ntp_) 1086 if (extended_enabled() && preload_ntp_)
1085 ResetNTP(GetInstantURL()); 1087 ResetNTP(GetInstantURL());
1086 1088
1087 if (instant_tab_) 1089 if (instant_tab_)
1088 instant_tab_->SetDisplayInstantResults(instant_enabled_); 1090 instant_tab_->sender()->SetDisplayInstantResults(instant_enabled_);
1089 } 1091 }
1090 1092
1091 void InstantController::ThemeChanged(const ThemeBackgroundInfo& theme_info) { 1093 void InstantController::ThemeChanged(const ThemeBackgroundInfo& theme_info) {
1092 if (!extended_enabled()) 1094 if (!extended_enabled())
1093 return; 1095 return;
1094 1096
1095 if (overlay_) 1097 if (overlay_)
1096 overlay_->SendThemeBackgroundInfo(theme_info); 1098 overlay_->sender()->SendThemeBackgroundInfo(theme_info);
1097 if (ntp_) 1099 if (ntp_)
1098 ntp_->SendThemeBackgroundInfo(theme_info); 1100 ntp_->sender()->SendThemeBackgroundInfo(theme_info);
1099 if (instant_tab_) 1101 if (instant_tab_)
1100 instant_tab_->SendThemeBackgroundInfo(theme_info); 1102 instant_tab_->sender()->SendThemeBackgroundInfo(theme_info);
1101 } 1103 }
1102 1104
1103 void InstantController::SwappedOverlayContents() { 1105 void InstantController::SwappedOverlayContents() {
1104 model_.SetOverlayContents(GetOverlayContents()); 1106 model_.SetOverlayContents(GetOverlayContents());
1105 } 1107 }
1106 1108
1107 void InstantController::FocusedOverlayContents() { 1109 void InstantController::FocusedOverlayContents() {
1108 #if defined(USE_AURA) 1110 #if defined(USE_AURA)
1109 // On aura the omnibox only receives a focus lost if we initiate the focus 1111 // On aura the omnibox only receives a focus lost if we initiate the focus
1110 // change. This does that. 1112 // change. This does that.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1158 InstantServiceFactory::GetForProfile(profile()); 1160 InstantServiceFactory::GetForProfile(profile());
1159 if (!instant_service) 1161 if (!instant_service)
1160 return; 1162 return;
1161 1163
1162 std::vector<InstantMostVisitedItem> items; 1164 std::vector<InstantMostVisitedItem> items;
1163 instant_service->GetCurrentMostVisitedItems(&items); 1165 instant_service->GetCurrentMostVisitedItems(&items);
1164 1166
1165 if (overlay_ && GetOverlayContents() && 1167 if (overlay_ && GetOverlayContents() &&
1166 SearchTabHelper::FromWebContents(overlay_->contents())-> 1168 SearchTabHelper::FromWebContents(overlay_->contents())->
1167 UpdateLastKnownMostVisitedItems(items)) { 1169 UpdateLastKnownMostVisitedItems(items)) {
1168 overlay_->SendMostVisitedItems(items); 1170 overlay_->sender()->SendMostVisitedItems(items);
1169 } 1171 }
1170 1172
1171 if (ntp_ && ntp_->contents() && 1173 if (ntp_ && ntp_->contents() &&
1172 SearchTabHelper::FromWebContents(ntp_->contents())-> 1174 SearchTabHelper::FromWebContents(ntp_->contents())->
1173 UpdateLastKnownMostVisitedItems(items)) { 1175 UpdateLastKnownMostVisitedItems(items)) {
1174 ntp_->SendMostVisitedItems(items); 1176 ntp_->sender()->SendMostVisitedItems(items);
1175 } 1177 }
1176 1178
1177 if (instant_tab_ && instant_tab_->contents() && 1179 if (instant_tab_ && instant_tab_->contents() &&
1178 SearchTabHelper::FromWebContents(instant_tab_->contents())-> 1180 SearchTabHelper::FromWebContents(instant_tab_->contents())->
1179 UpdateLastKnownMostVisitedItems(items)) { 1181 UpdateLastKnownMostVisitedItems(items)) {
1180 instant_tab_->SendMostVisitedItems(items); 1182 instant_tab_->sender()->SendMostVisitedItems(items);
1181 } 1183 }
1182 1184
1183 content::NotificationService::current()->Notify( 1185 content::NotificationService::current()->Notify(
1184 chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS, 1186 chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS,
1185 content::Source<InstantController>(this), 1187 content::Source<InstantController>(this),
1186 content::NotificationService::NoDetails()); 1188 content::NotificationService::NoDetails());
1187 } 1189 }
1188 1190
1189 void InstantController::DeleteMostVisitedItem(const GURL& url) { 1191 void InstantController::DeleteMostVisitedItem(const GURL& url) {
1190 DCHECK(!url.is_empty()); 1192 DCHECK(!url.is_empty());
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1236 void InstantController::InstantPageRenderViewCreated( 1238 void InstantController::InstantPageRenderViewCreated(
1237 const content::WebContents* contents) { 1239 const content::WebContents* contents) {
1238 if (!extended_enabled()) 1240 if (!extended_enabled())
1239 return; 1241 return;
1240 1242
1241 // Update theme info so that the page picks it up. 1243 // Update theme info so that the page picks it up.
1242 browser_->UpdateThemeInfo(); 1244 browser_->UpdateThemeInfo();
1243 1245
1244 // Ensure the searchbox API has the correct initial state. 1246 // Ensure the searchbox API has the correct initial state.
1245 if (IsContentsFrom(overlay(), contents)) { 1247 if (IsContentsFrom(overlay(), contents)) {
1246 overlay_->SetDisplayInstantResults(instant_enabled_); 1248 overlay_->sender()->SetDisplayInstantResults(instant_enabled_);
1247 overlay_->FocusChanged(omnibox_focus_state_, omnibox_focus_change_reason_); 1249 overlay_->sender()->FocusChanged(omnibox_focus_state_,
1248 overlay_->SetOmniboxBounds(omnibox_bounds_); 1250 omnibox_focus_change_reason_);
1251 overlay_->sender()->SetOmniboxBounds(omnibox_bounds_);
1249 overlay_->InitializeFonts(); 1252 overlay_->InitializeFonts();
1250 } else if (IsContentsFrom(ntp(), contents)) { 1253 } else if (IsContentsFrom(ntp(), contents)) {
1251 ntp_->SetDisplayInstantResults(instant_enabled_); 1254 ntp_->sender()->SetDisplayInstantResults(instant_enabled_);
1252 ntp_->SetOmniboxBounds(omnibox_bounds_); 1255 ntp_->sender()->SetOmniboxBounds(omnibox_bounds_);
1253 ntp_->InitializeFonts(); 1256 ntp_->InitializeFonts();
1254 } else { 1257 } else {
1255 NOTREACHED(); 1258 NOTREACHED();
1256 } 1259 }
1257 UpdateMostVisitedItems(); 1260 UpdateMostVisitedItems();
1258 } 1261 }
1259 1262
1260 void InstantController::InstantSupportChanged( 1263 void InstantController::InstantSupportChanged(
1261 InstantSupportState instant_support) { 1264 InstantSupportState instant_support) {
1262 // Handle INSTANT_SUPPORT_YES here because InstantPage is not hooked up to the 1265 // Handle INSTANT_SUPPORT_YES here because InstantPage is not hooked up to the
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
1592 } 1595 }
1593 1596
1594 void InstantController::ResetNTP(const std::string& instant_url) { 1597 void InstantController::ResetNTP(const std::string& instant_url) {
1595 // Never load the Instant NTP if it is disabled. 1598 // Never load the Instant NTP if it is disabled.
1596 if (!chrome::ShouldShowInstantNTP()) 1599 if (!chrome::ShouldShowInstantNTP())
1597 return; 1600 return;
1598 1601
1599 // Instant NTP is only used in extended mode so we should always have a 1602 // Instant NTP is only used in extended mode so we should always have a
1600 // non-empty URL to use. 1603 // non-empty URL to use.
1601 DCHECK(!instant_url.empty()); 1604 DCHECK(!instant_url.empty());
1602 ntp_.reset(new InstantNTP(this, instant_url)); 1605 ntp_.reset(new InstantNTP(this, instant_url,
1606 browser_->profile()->IsOffTheRecord()));
1603 ntp_->InitContents(profile(), browser_->GetActiveWebContents(), 1607 ntp_->InitContents(profile(), browser_->GetActiveWebContents(),
1604 base::Bind(&InstantController::ReloadStaleNTP, 1608 base::Bind(&InstantController::ReloadStaleNTP,
1605 base::Unretained(this))); 1609 base::Unretained(this)));
1606 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( 1610 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf(
1607 "ResetNTP: instant_url='%s'", instant_url.c_str())); 1611 "ResetNTP: instant_url='%s'", instant_url.c_str()));
1608 } 1612 }
1609 1613
1610 void InstantController::ReloadStaleNTP() { 1614 void InstantController::ReloadStaleNTP() {
1611 ResetNTP(GetInstantURL()); 1615 ResetNTP(GetInstantURL());
1612 } 1616 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1654 return INSTANT_FALLBACK_NONE; 1658 return INSTANT_FALLBACK_NONE;
1655 1659
1656 bool page_is_current = PageIsCurrent(overlay()); 1660 bool page_is_current = PageIsCurrent(overlay());
1657 if (!page_is_current) 1661 if (!page_is_current)
1658 return DetermineFallbackReason(overlay(), GetInstantURL()); 1662 return DetermineFallbackReason(overlay(), GetInstantURL());
1659 1663
1660 return INSTANT_FALLBACK_NONE; 1664 return INSTANT_FALLBACK_NONE;
1661 } 1665 }
1662 1666
1663 void InstantController::ResetInstantTab() { 1667 void InstantController::ResetInstantTab() {
1664 // Do not wire up the InstantTab in Incognito, to prevent it from sending data 1668 if (!search_mode_.is_origin_default()) {
1665 // to the page.
1666 if (!search_mode_.is_origin_default() &&
1667 !browser_->profile()->IsOffTheRecord()) {
1668 content::WebContents* active_tab = browser_->GetActiveWebContents(); 1669 content::WebContents* active_tab = browser_->GetActiveWebContents();
1669 if (!instant_tab_ || active_tab != instant_tab_->contents()) { 1670 if (!instant_tab_ || active_tab != instant_tab_->contents()) {
1670 instant_tab_.reset(new InstantTab(this)); 1671 instant_tab_.reset(
1672 new InstantTab(this, browser_->profile()->IsOffTheRecord()));
1671 instant_tab_->Init(active_tab); 1673 instant_tab_->Init(active_tab);
1672 UpdateInfoForInstantTab(); 1674 UpdateInfoForInstantTab();
1673 use_tab_for_suggestions_ = true; 1675 use_tab_for_suggestions_ = true;
1674 } 1676 }
1675 1677
1676 // Hide the |overlay_| since we are now using |instant_tab_| instead. 1678 // Hide the |overlay_| since we are now using |instant_tab_| instead.
1677 HideOverlay(); 1679 HideOverlay();
1678 } else { 1680 } else {
1679 instant_tab_.reset(); 1681 instant_tab_.reset();
1680 } 1682 }
1681 } 1683 }
1682 1684
1683 void InstantController::UpdateInfoForInstantTab() { 1685 void InstantController::UpdateInfoForInstantTab() {
1684 if (instant_tab_) { 1686 if (instant_tab_) {
1685 browser_->UpdateThemeInfo(); 1687 browser_->UpdateThemeInfo();
1686 instant_tab_->SetDisplayInstantResults(instant_enabled_); 1688 instant_tab_->sender()->SetDisplayInstantResults(instant_enabled_);
1687 instant_tab_->SetOmniboxBounds(omnibox_bounds_); 1689 instant_tab_->sender()->SetOmniboxBounds(omnibox_bounds_);
1688 instant_tab_->InitializeFonts(); 1690 instant_tab_->InitializeFonts();
1689 UpdateMostVisitedItems(); 1691 UpdateMostVisitedItems();
1690 instant_tab_->FocusChanged(omnibox_focus_state_, 1692 instant_tab_->sender()->FocusChanged(omnibox_focus_state_,
1691 omnibox_focus_change_reason_); 1693 omnibox_focus_change_reason_);
1692 instant_tab_->SetInputInProgress(IsInputInProgress()); 1694 instant_tab_->sender()->SetInputInProgress(IsInputInProgress());
1693 } 1695 }
1694 } 1696 }
1695 1697
1696 bool InstantController::IsInputInProgress() const { 1698 bool InstantController::IsInputInProgress() const {
1697 return !search_mode_.is_ntp() && 1699 return !search_mode_.is_ntp() &&
1698 omnibox_focus_state_ == OMNIBOX_FOCUS_VISIBLE; 1700 omnibox_focus_state_ == OMNIBOX_FOCUS_VISIBLE;
1699 } 1701 }
1700 1702
1701 void InstantController::HideOverlay() { 1703 void InstantController::HideOverlay() {
1702 HideInternal(); 1704 HideInternal();
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1785 1787
1786 // In the current Chrome UI, these must always be true so they sanity check 1788 // In the current Chrome UI, these must always be true so they sanity check
1787 // the above operations. In a future UI, these may be removed or adjusted. 1789 // the above operations. In a future UI, these may be removed or adjusted.
1788 // There is no point in sanity-checking |intersection.y()| because the omnibox 1790 // There is no point in sanity-checking |intersection.y()| because the omnibox
1789 // can be placed anywhere vertically relative to the overlay (for example, in 1791 // can be placed anywhere vertically relative to the overlay (for example, in
1790 // Mac fullscreen mode, the omnibox is fully enclosed by the overlay bounds). 1792 // Mac fullscreen mode, the omnibox is fully enclosed by the overlay bounds).
1791 DCHECK_LE(0, intersection.x()); 1793 DCHECK_LE(0, intersection.x());
1792 DCHECK_LE(0, intersection.width()); 1794 DCHECK_LE(0, intersection.width());
1793 DCHECK_LE(0, intersection.height()); 1795 DCHECK_LE(0, intersection.height());
1794 1796
1795 overlay_->SetPopupBounds(intersection); 1797 overlay_->sender()->SetPopupBounds(intersection);
1796 } 1798 }
1797 1799
1798 1800
1799 1801
1800 bool InstantController::FixSuggestion(InstantSuggestion* suggestion) const { 1802 bool InstantController::FixSuggestion(InstantSuggestion* suggestion) const {
1801 // We only accept suggestions if the user has typed text. If the user is 1803 // We only accept suggestions if the user has typed text. If the user is
1802 // arrowing up/down (|last_user_text_| is empty), we reject suggestions. 1804 // arrowing up/down (|last_user_text_| is empty), we reject suggestions.
1803 if (last_user_text_.empty()) 1805 if (last_user_text_.empty())
1804 return false; 1806 return false;
1805 1807
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
1914 bool js_webkit_enabled = profile()->GetPrefs()->GetBoolean( 1916 bool js_webkit_enabled = profile()->GetPrefs()->GetBoolean(
1915 prefs::kWebKitJavascriptEnabled); 1917 prefs::kWebKitJavascriptEnabled);
1916 return js_content_enabled && js_webkit_enabled; 1918 return js_content_enabled && js_webkit_enabled;
1917 } 1919 }
1918 1920
1919 bool InstantController::InStartup() const { 1921 bool InstantController::InStartup() const {
1920 // TODO(shishir): This is not completely reliable. Find a better way to detect 1922 // TODO(shishir): This is not completely reliable. Find a better way to detect
1921 // startup time. 1923 // startup time.
1922 return !browser_->GetActiveWebContents(); 1924 return !browser_->GetActiveWebContents();
1923 } 1925 }
OLDNEW
« no previous file with comments | « chrome/browser/search/search_unittest.cc ('k') | chrome/browser/ui/search/instant_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698