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

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

Issue 11413217: Instant API: tell page whether the browser is capturing key strokes. (Closed) Base URL: http://git.chromium.org/chromium/src.git@focus
Patch Set: Finish renaming. 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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 145
146 InstantController::InstantController(chrome::BrowserInstantController* browser, 146 InstantController::InstantController(chrome::BrowserInstantController* browser,
147 bool extended_enabled) 147 bool extended_enabled)
148 : browser_(browser), 148 : browser_(browser),
149 extended_enabled_(extended_enabled), 149 extended_enabled_(extended_enabled),
150 instant_enabled_(false), 150 instant_enabled_(false),
151 model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 151 model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
152 last_verbatim_(false), 152 last_verbatim_(false),
153 last_transition_type_(content::PAGE_TRANSITION_LINK), 153 last_transition_type_(content::PAGE_TRANSITION_LINK),
154 last_match_was_search_(false), 154 last_match_was_search_(false),
155 is_omnibox_focused_(false) { 155 omnibox_focus_state_(NONE) {
156 } 156 }
157 157
158 InstantController::~InstantController() { 158 InstantController::~InstantController() {
159 } 159 }
160 160
161 bool InstantController::Update(const AutocompleteMatch& match, 161 bool InstantController::Update(const AutocompleteMatch& match,
162 const string16& user_text, 162 const string16& user_text,
163 const string16& full_text, 163 const string16& full_text,
164 const bool verbatim, 164 const bool verbatim,
165 const bool user_input_in_progress, 165 const bool user_input_in_progress,
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 469
470 // Try to create another loader immediately so that it is ready for the next 470 // Try to create another loader immediately so that it is ready for the next
471 // user interaction. 471 // user interaction.
472 CreateDefaultLoader(); 472 CreateDefaultLoader();
473 473
474 return true; 474 return true;
475 } 475 }
476 476
477 void InstantController::OmniboxLostFocus(gfx::NativeView view_gaining_focus) { 477 void InstantController::OmniboxLostFocus(gfx::NativeView view_gaining_focus) {
478 DVLOG(1) << "OmniboxLostFocus"; 478 DVLOG(1) << "OmniboxLostFocus";
479 is_omnibox_focused_ = false; 479 omnibox_focus_state_ = NONE;
480 480
481 if (!extended_enabled_ && !instant_enabled_) 481 if (!extended_enabled_ && !instant_enabled_)
482 return; 482 return;
483 483
484 // If the preview isn't showing search suggestions, nothing to do. The check 484 // If the preview isn't showing search suggestions, nothing to do. The check
485 // for GetPreviewContents() (which normally is redundant, given IsCurrent()) 485 // for GetPreviewContents() (which normally is redundant, given IsCurrent())
486 // is to handle the case when we get here during a commit. 486 // is to handle the case when we get here during a commit.
487 if (!IsCurrent() || !GetPreviewContents()) { 487 if (!IsCurrent() || !GetPreviewContents()) {
488 OnStaleLoader(); 488 OnStaleLoader();
489 return; 489 return;
490 } 490 }
491 491
492 SendKeyCaptureModeToPage();
sreeram 2012/11/29 13:22:31 IsCurrent() returns false when on the NTP. Don't y
samarth 2012/11/29 17:28:21 Good catch. Fixed it so that the Send..() call is
492 #if defined(OS_MACOSX) 493 #if defined(OS_MACOSX)
493 if (!loader_->IsPointerDownFromActivate()) 494 if (!loader_->IsPointerDownFromActivate())
494 Hide(true); 495 Hide(true);
495 #else 496 #else
496 if (IsViewInContents(GetViewGainingFocus(view_gaining_focus), 497 if (IsViewInContents(GetViewGainingFocus(view_gaining_focus),
497 GetPreviewContents()->web_contents())) 498 GetPreviewContents()->web_contents()))
498 CommitIfCurrent(INSTANT_COMMIT_FOCUS_LOST); 499 CommitIfCurrent(INSTANT_COMMIT_FOCUS_LOST);
499 else 500 else
500 Hide(true); 501 Hide(true);
501 #endif 502 #endif
502 } 503 }
503 504
504 void InstantController::OmniboxGotFocus() { 505 void InstantController::OmniboxGotFocus(bool focus_is_visible) {
505 DVLOG(1) << "OmniboxGotFocus"; 506 DVLOG(1) << "OmniboxGotFocus";
506 is_omnibox_focused_ = true; 507 omnibox_focus_state_ = focus_is_visible ? VISIBLE : INVISIBLE;
507 508
508 if (!extended_enabled_ && !instant_enabled_) 509 if (!extended_enabled_ && !instant_enabled_)
509 return; 510 return;
510 511
512 SendKeyCaptureModeToPage();
513
511 if (!GetPreviewContents()) 514 if (!GetPreviewContents())
512 CreateDefaultLoader(); 515 CreateDefaultLoader();
513 } 516 }
514 517
515 void InstantController::SearchModeChanged( 518 void InstantController::SearchModeChanged(
516 const chrome::search::Mode& old_mode, 519 const chrome::search::Mode& old_mode,
517 const chrome::search::Mode& new_mode) { 520 const chrome::search::Mode& new_mode) {
518 if (!extended_enabled_) 521 if (!extended_enabled_)
519 return; 522 return;
520 523
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 if (!GetInstantURL(template_url, &instant_url)) 703 if (!GetInstantURL(template_url, &instant_url))
701 return false; 704 return false;
702 705
703 if (GetPreviewContents() && loader_->instant_url() != instant_url) 706 if (GetPreviewContents() && loader_->instant_url() != instant_url)
704 DeleteLoader(); 707 DeleteLoader();
705 708
706 if (!GetPreviewContents()) { 709 if (!GetPreviewContents()) {
707 loader_.reset(new InstantLoader(this, instant_url, active_tab)); 710 loader_.reset(new InstantLoader(this, instant_url, active_tab));
708 loader_->Init(); 711 loader_->Init();
709 712
710 // Ensure the searchbox API has the correct theme-related info and context. 713 // Ensure the searchbox API has correct state.
711 if (extended_enabled_) { 714 if (extended_enabled_) {
712 browser_->UpdateThemeInfoForPreview(); 715 browser_->UpdateThemeInfoForPreview();
713 loader_->SearchModeChanged(search_mode_); 716 loader_->SearchModeChanged(search_mode_);
717 SendKeyCaptureModeToPage();
714 } 718 }
715 719
716 // Reset the loader timer. 720 // Reset the loader timer.
717 stale_loader_timer_.Start( 721 stale_loader_timer_.Start(
718 FROM_HERE, 722 FROM_HERE,
719 base::TimeDelta::FromMilliseconds(kStaleLoaderTimeoutMS), this, 723 base::TimeDelta::FromMilliseconds(kStaleLoaderTimeoutMS), this,
720 &InstantController::OnStaleLoader); 724 &InstantController::OnStaleLoader);
721 } 725 }
722 726
723 return true; 727 return true;
724 } 728 }
725 729
726 bool InstantController::CreateDefaultLoader() { 730 bool InstantController::CreateDefaultLoader() {
727 // If there's no active tab, the browser is closing. 731 // If there's no active tab, the browser is closing.
728 const TabContents* active_tab = browser_->GetActiveTabContents(); 732 const TabContents* active_tab = browser_->GetActiveTabContents();
729 if (!active_tab) 733 if (!active_tab)
730 return false; 734 return false;
731 735
732 const TemplateURL* template_url = 736 const TemplateURL* template_url =
733 TemplateURLServiceFactory::GetForProfile(active_tab->profile())-> 737 TemplateURLServiceFactory::GetForProfile(active_tab->profile())->
734 GetDefaultSearchProvider(); 738 GetDefaultSearchProvider();
735 739
736 return ResetLoader(template_url, active_tab); 740 return ResetLoader(template_url, active_tab);
737 } 741 }
738 742
739 void InstantController::OnStaleLoader() { 743 void InstantController::OnStaleLoader() {
740 // If the preview is showing or the omnibox has focus, don't delete the 744 // If the preview is showing or the omnibox has focus, don't delete the
741 // loader. It will get refreshed the next time the preview is hidden or the 745 // loader. It will get refreshed the next time the preview is hidden or the
742 // omnibox loses focus. 746 // omnibox loses focus.
743 if (!stale_loader_timer_.IsRunning() && !is_omnibox_focused_ && 747 if (!stale_loader_timer_.IsRunning() && omnibox_focus_state_ == NONE &&
744 model_.mode().is_default()) { 748 model_.mode().is_default()) {
745 DeleteLoader(); 749 DeleteLoader();
746 CreateDefaultLoader(); 750 CreateDefaultLoader();
747 } 751 }
748 } 752 }
749 753
750 void InstantController::DeleteLoader() { 754 void InstantController::DeleteLoader() {
751 // Clear all state, except |last_transition_type_| as it's used during commit. 755 // Clear all state, except |last_transition_type_| as it's used during commit.
752 last_user_text_.clear(); 756 last_user_text_.clear();
753 last_full_text_.clear(); 757 last_full_text_.clear();
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 // There is no point in sanity-checking |intersection.y()| because the omnibox 847 // There is no point in sanity-checking |intersection.y()| because the omnibox
844 // can be placed anywhere vertically relative to the preview (for example, in 848 // can be placed anywhere vertically relative to the preview (for example, in
845 // Mac fullscreen mode, the omnibox is fully enclosed by the preview bounds). 849 // Mac fullscreen mode, the omnibox is fully enclosed by the preview bounds).
846 DCHECK_LE(0, intersection.x()); 850 DCHECK_LE(0, intersection.x());
847 DCHECK_LE(0, intersection.width()); 851 DCHECK_LE(0, intersection.width());
848 DCHECK_LE(0, intersection.height()); 852 DCHECK_LE(0, intersection.height());
849 853
850 loader_->SetOmniboxBounds(intersection); 854 loader_->SetOmniboxBounds(intersection);
851 } 855 }
852 856
857 void InstantController::SendKeyCaptureModeToPage() {
858 loader_->OnKeyCaptureChange(omnibox_focus_state_ == INVISIBLE);
sreeram 2012/11/29 13:22:31 You should guard this on these two clauses (either
samarth 2012/11/29 17:28:21 Added the checks here to be safe.
859 }
860
853 bool InstantController::GetInstantURL(const TemplateURL* template_url, 861 bool InstantController::GetInstantURL(const TemplateURL* template_url,
854 std::string* instant_url) const { 862 std::string* instant_url) const {
855 CommandLine* command_line = CommandLine::ForCurrentProcess(); 863 CommandLine* command_line = CommandLine::ForCurrentProcess();
856 if (command_line->HasSwitch(switches::kInstantURL)) { 864 if (command_line->HasSwitch(switches::kInstantURL)) {
857 *instant_url = command_line->GetSwitchValueASCII(switches::kInstantURL); 865 *instant_url = command_line->GetSwitchValueASCII(switches::kInstantURL);
858 return template_url != NULL; 866 return template_url != NULL;
859 } 867 }
860 868
861 if (!template_url) 869 if (!template_url)
862 return false; 870 return false;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
894 } 902 }
895 903
896 std::map<std::string, int>::const_iterator iter = 904 std::map<std::string, int>::const_iterator iter =
897 blacklisted_urls_.find(*instant_url); 905 blacklisted_urls_.find(*instant_url);
898 if (iter != blacklisted_urls_.end() && 906 if (iter != blacklisted_urls_.end() &&
899 iter->second > kMaxInstantSupportFailures) 907 iter->second > kMaxInstantSupportFailures)
900 return false; 908 return false;
901 909
902 return true; 910 return true;
903 } 911 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698