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

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

Issue 11555033: Adding local html page used in Instant Extended mode when instant is disabled or unavailable. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Addressing comments from estade, dhollowa and samarth. 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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 139
140 return false; 140 return false;
141 } 141 }
142 142
143 bool IsFullHeight(const InstantModel& model) { 143 bool IsFullHeight(const InstantModel& model) {
144 return model.height() == 100 && model.height_units() == INSTANT_SIZE_PERCENT; 144 return model.height() == 100 && model.height_units() == INSTANT_SIZE_PERCENT;
145 } 145 }
146 146
147 } // namespace 147 } // namespace
148 148
149 const char* InstantController::kLocalOmniboxPopupURL =
sky 2012/12/13 23:39:02 For static we put // static on the previous line.
Shishir 2012/12/14 00:03:15 Done.
150 "chrome://local-omnibox-popup/local-omnibox-popup.html";
151
149 InstantController::InstantController(chrome::BrowserInstantController* browser, 152 InstantController::InstantController(chrome::BrowserInstantController* browser,
150 bool extended_enabled) 153 bool extended_enabled,
154 bool use_local_preview_only)
151 : browser_(browser), 155 : browser_(browser),
152 extended_enabled_(extended_enabled), 156 extended_enabled_(extended_enabled),
153 instant_enabled_(false), 157 instant_enabled_(false),
158 use_local_preview_only_(use_local_preview_only),
154 model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 159 model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
155 last_omnibox_text_has_inline_autocompletion_(false), 160 last_omnibox_text_has_inline_autocompletion_(false),
156 last_verbatim_(false), 161 last_verbatim_(false),
157 last_transition_type_(content::PAGE_TRANSITION_LINK), 162 last_transition_type_(content::PAGE_TRANSITION_LINK),
158 last_match_was_search_(false), 163 last_match_was_search_(false),
159 omnibox_focus_state_(OMNIBOX_FOCUS_NONE), 164 omnibox_focus_state_(OMNIBOX_FOCUS_NONE),
160 allow_preview_to_show_search_suggestions_(false) { 165 allow_preview_to_show_search_suggestions_(false) {
161 } 166 }
162 167
163 InstantController::~InstantController() { 168 InstantController::~InstantController() {
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 instant_tab_->Submit(last_omnibox_text_); 449 instant_tab_->Submit(last_omnibox_text_);
445 instant_tab_->contents()->Focus(); 450 instant_tab_->contents()->Focus();
446 return true; 451 return true;
447 } 452 }
448 return false; 453 return false;
449 } 454 }
450 455
451 if (!IsPreviewingSearchResults() && type != INSTANT_COMMIT_NAVIGATED) 456 if (!IsPreviewingSearchResults() && type != INSTANT_COMMIT_NAVIGATED)
452 return false; 457 return false;
453 458
459 // Never commit the local omnibox.
460 if (loader_->IsUsingLocalPreview())
461 return false;
462
454 if (type == INSTANT_COMMIT_FOCUS_LOST) 463 if (type == INSTANT_COMMIT_FOCUS_LOST)
455 loader_->Cancel(last_omnibox_text_); 464 loader_->Cancel(last_omnibox_text_);
456 else if (type != INSTANT_COMMIT_NAVIGATED && 465 else if (type != INSTANT_COMMIT_NAVIGATED &&
457 type != INSTANT_COMMIT_CLICKED_QUERY_SUGGESTION) 466 type != INSTANT_COMMIT_CLICKED_QUERY_SUGGESTION)
458 loader_->Submit(last_omnibox_text_); 467 loader_->Submit(last_omnibox_text_);
459 468
460 content::WebContents* preview = loader_->ReleaseContents(); 469 content::WebContents* preview = loader_->ReleaseContents();
461 470
462 if (extended_enabled_) { 471 if (extended_enabled_) {
463 // Consider what's happening: 472 // Consider what's happening:
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 #else 843 #else
835 if (IsViewInContents(GetViewGainingFocus(view_gaining_focus), 844 if (IsViewInContents(GetViewGainingFocus(view_gaining_focus),
836 loader_->contents())) 845 loader_->contents()))
837 CommitIfPossible(INSTANT_COMMIT_FOCUS_LOST); 846 CommitIfPossible(INSTANT_COMMIT_FOCUS_LOST);
838 else 847 else
839 HideLoader(); 848 HideLoader();
840 #endif 849 #endif
841 } 850 }
842 851
843 bool InstantController::ResetLoader(const TemplateURL* template_url, 852 bool InstantController::ResetLoader(const TemplateURL* template_url,
844 const content::WebContents* active_tab) { 853 const content::WebContents* active_tab,
854 bool fallback_to_local) {
845 std::string instant_url; 855 std::string instant_url;
846 if (!GetInstantURL(template_url, &instant_url)) 856 if (!GetInstantURL(template_url, &instant_url)) {
847 return false; 857 if (!fallback_to_local || !extended_enabled_)
858 return false;
859
860 // If we are in extended mode, fallback to the local popup.
861 instant_url = kLocalOmniboxPopupURL;
862 }
848 863
849 if (loader_ && loader_->instant_url() == instant_url) 864 if (loader_ && loader_->instant_url() == instant_url)
850 return true; 865 return true;
851 866
852 HideInternal(); 867 HideInternal();
853 loader_.reset(new InstantLoader(this, instant_url)); 868 loader_.reset(new InstantLoader(this, instant_url));
854 loader_->InitContents(active_tab); 869 loader_->InitContents(active_tab);
855 870
856 // Ensure the searchbox API has the correct initial state. 871 // Ensure the searchbox API has the correct initial state.
857 if (extended_enabled_) { 872 if (extended_enabled_) {
(...skipping 14 matching lines...) Expand all
872 bool InstantController::CreateDefaultLoader() { 887 bool InstantController::CreateDefaultLoader() {
873 // If there's no active tab, the browser is closing. 888 // If there's no active tab, the browser is closing.
874 const content::WebContents* active_tab = browser_->GetActiveWebContents(); 889 const content::WebContents* active_tab = browser_->GetActiveWebContents();
875 if (!active_tab) 890 if (!active_tab)
876 return false; 891 return false;
877 892
878 const TemplateURL* template_url = TemplateURLServiceFactory::GetForProfile( 893 const TemplateURL* template_url = TemplateURLServiceFactory::GetForProfile(
879 Profile::FromBrowserContext(active_tab->GetBrowserContext()))-> 894 Profile::FromBrowserContext(active_tab->GetBrowserContext()))->
880 GetDefaultSearchProvider(); 895 GetDefaultSearchProvider();
881 896
882 return ResetLoader(template_url, active_tab); 897 return ResetLoader(template_url, active_tab, true);
883 } 898 }
884 899
885 void InstantController::OnStaleLoader() { 900 void InstantController::OnStaleLoader() {
901 // The local popup is never stale.
902 if (loader_ && loader_->IsUsingLocalPreview())
903 return;
904
886 // If the preview is showing or the omnibox has focus, don't delete the 905 // If the preview is showing or the omnibox has focus, don't delete the
887 // loader. It will get refreshed the next time the preview is hidden or the 906 // loader. It will get refreshed the next time the preview is hidden or the
888 // omnibox loses focus. 907 // omnibox loses focus.
889 if (!stale_loader_timer_.IsRunning() && 908 if (!stale_loader_timer_.IsRunning() &&
890 omnibox_focus_state_ == OMNIBOX_FOCUS_NONE && 909 omnibox_focus_state_ == OMNIBOX_FOCUS_NONE &&
891 model_.mode().is_default()) { 910 model_.mode().is_default()) {
892 loader_.reset(); 911 loader_.reset();
893 CreateDefaultLoader(); 912 CreateDefaultLoader();
894 } 913 }
895 } 914 }
(...skipping 20 matching lines...) Expand all
916 // of |match|, we shouldn't use the committed tab. 935 // of |match|, we shouldn't use the committed tab.
917 if (instant_tab_) 936 if (instant_tab_)
918 return true; 937 return true;
919 938
920 // If there's no active tab, the browser is closing. 939 // If there's no active tab, the browser is closing.
921 const content::WebContents* active_tab = browser_->GetActiveWebContents(); 940 const content::WebContents* active_tab = browser_->GetActiveWebContents();
922 if (!active_tab) 941 if (!active_tab)
923 return false; 942 return false;
924 943
925 // Try to create a loader for the instant_url in the TemplateURL of |match|. 944 // Try to create a loader for the instant_url in the TemplateURL of |match|.
945 // Do not fallback to the local preview because if the keyword specific
946 // instant URL fails, we want to first try the default instant URL which
947 // happens in the CreateDefaultLoader call below.
926 const TemplateURL* template_url = match.GetTemplateURL( 948 const TemplateURL* template_url = match.GetTemplateURL(
927 Profile::FromBrowserContext(active_tab->GetBrowserContext()), false); 949 Profile::FromBrowserContext(active_tab->GetBrowserContext()), false);
928 if (ResetLoader(template_url, active_tab)) 950 if (ResetLoader(template_url, active_tab, false))
929 return true; 951 return true;
930 952
931 // In non-extended mode, stop if we couldn't get a loader for the |match|. 953 // In non-extended mode, stop if we couldn't get a loader for the |match|.
932 if (!extended_enabled_) 954 if (!extended_enabled_)
933 return false; 955 return false;
934 956
935 // If the match is a query, it is for a non-Instant search engine; stop. 957 // If the match is a query, it is for a non-Instant search engine; stop.
936 if (last_match_was_search_) 958 if (last_match_was_search_)
937 return false; 959 return false;
938 960
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 } 1014 }
993 1015
994 // If the preview is being shown for the first time since the user started 1016 // If the preview is being shown for the first time since the user started
995 // typing, record a histogram value. 1017 // typing, record a histogram value.
996 if (!first_interaction_time_.is_null() && model_.mode().is_default()) { 1018 if (!first_interaction_time_.is_null() && model_.mode().is_default()) {
997 base::TimeDelta delta = base::Time::Now() - first_interaction_time_; 1019 base::TimeDelta delta = base::Time::Now() - first_interaction_time_;
998 UMA_HISTOGRAM_TIMES("Instant.TimeToFirstShow", delta); 1020 UMA_HISTOGRAM_TIMES("Instant.TimeToFirstShow", delta);
999 } 1021 }
1000 1022
1001 // Show at 100% height except in the following cases: 1023 // Show at 100% height except in the following cases:
1024 // - The local omnibox popup is being loaded.
1002 // - Instant is disabled. The page needs to be able to show only a dropdown. 1025 // - Instant is disabled. The page needs to be able to show only a dropdown.
1003 // - The page wants to show custom NTP content. 1026 // - The page wants to show custom NTP content.
1004 // - The page is over a website other than search or an NTP, and is not 1027 // - The page is over a website other than search or an NTP, and is not
1005 // already showing at 100% height. 1028 // already showing at 100% height.
1006 if (!instant_enabled_ || reason == INSTANT_SHOWN_CUSTOM_NTP_CONTENT || 1029 if (loader_->IsUsingLocalPreview() || !instant_enabled_ ||
1030 reason == INSTANT_SHOWN_CUSTOM_NTP_CONTENT ||
1007 (search_mode_.is_origin_default() && !IsFullHeight(model_))) 1031 (search_mode_.is_origin_default() && !IsFullHeight(model_)))
1008 model_.SetPreviewState(search_mode_, height, units); 1032 model_.SetPreviewState(search_mode_, height, units);
1009 else 1033 else
1010 model_.SetPreviewState(search_mode_, 100, INSTANT_SIZE_PERCENT); 1034 model_.SetPreviewState(search_mode_, 100, INSTANT_SIZE_PERCENT);
1011 1035
1012 // If the user clicked on a query suggestion, also go ahead and commit the 1036 // If the user clicked on a query suggestion, also go ahead and commit the
1013 // overlay. This is necessary because if the overlay was partially visible 1037 // overlay. This is necessary because if the overlay was partially visible
1014 // when the suggestion was clicked, the click itself would not commit the 1038 // when the suggestion was clicked, the click itself would not commit the
1015 // overlay (because we're not full height). 1039 // overlay (because we're not full height).
1016 if (reason == INSTANT_SHOWN_CLICKED_QUERY_SUGGESTION) 1040 if (reason == INSTANT_SHOWN_CLICKED_QUERY_SUGGESTION)
(...skipping 22 matching lines...) Expand all
1039 // Mac fullscreen mode, the omnibox is fully enclosed by the preview bounds). 1063 // Mac fullscreen mode, the omnibox is fully enclosed by the preview bounds).
1040 DCHECK_LE(0, intersection.x()); 1064 DCHECK_LE(0, intersection.x());
1041 DCHECK_LE(0, intersection.width()); 1065 DCHECK_LE(0, intersection.width());
1042 DCHECK_LE(0, intersection.height()); 1066 DCHECK_LE(0, intersection.height());
1043 1067
1044 loader_->SetOmniboxBounds(intersection); 1068 loader_->SetOmniboxBounds(intersection);
1045 } 1069 }
1046 1070
1047 bool InstantController::GetInstantURL(const TemplateURL* template_url, 1071 bool InstantController::GetInstantURL(const TemplateURL* template_url,
1048 std::string* instant_url) const { 1072 std::string* instant_url) const {
1073 if (extended_enabled_ && use_local_preview_only_) {
1074 *instant_url = kLocalOmniboxPopupURL;
1075 return true;
1076 }
1077
1049 CommandLine* command_line = CommandLine::ForCurrentProcess(); 1078 CommandLine* command_line = CommandLine::ForCurrentProcess();
1050 if (command_line->HasSwitch(switches::kInstantURL)) { 1079 if (command_line->HasSwitch(switches::kInstantURL)) {
1051 *instant_url = command_line->GetSwitchValueASCII(switches::kInstantURL); 1080 *instant_url = command_line->GetSwitchValueASCII(switches::kInstantURL);
1052 return template_url != NULL; 1081 return template_url != NULL;
1053 } 1082 }
1054 1083
1055 if (!template_url) 1084 if (!template_url)
1056 return false; 1085 return false;
1057 1086
1058 const TemplateURLRef& instant_url_ref = template_url->instant_url_ref(); 1087 const TemplateURLRef& instant_url_ref = template_url->instant_url_ref();
(...skipping 29 matching lines...) Expand all
1088 } 1117 }
1089 1118
1090 std::map<std::string, int>::const_iterator iter = 1119 std::map<std::string, int>::const_iterator iter =
1091 blacklisted_urls_.find(*instant_url); 1120 blacklisted_urls_.find(*instant_url);
1092 if (iter != blacklisted_urls_.end() && 1121 if (iter != blacklisted_urls_.end() &&
1093 iter->second > kMaxInstantSupportFailures) 1122 iter->second > kMaxInstantSupportFailures)
1094 return false; 1123 return false;
1095 1124
1096 return true; 1125 return true;
1097 } 1126 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698