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

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

Issue 12001002: InstantExtended: Transient naventry for preview. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Save old transient entry; update URL. Created 7 years, 11 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
« no previous file with comments | « chrome/browser/instant/instant_controller.h ('k') | chrome/browser/instant/instant_loader.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 instant_enabled_(false), 173 instant_enabled_(false),
174 use_local_preview_only_(use_local_preview_only), 174 use_local_preview_only_(use_local_preview_only),
175 model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 175 model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
176 last_omnibox_text_has_inline_autocompletion_(false), 176 last_omnibox_text_has_inline_autocompletion_(false),
177 last_verbatim_(false), 177 last_verbatim_(false),
178 last_transition_type_(content::PAGE_TRANSITION_LINK), 178 last_transition_type_(content::PAGE_TRANSITION_LINK),
179 last_match_was_search_(false), 179 last_match_was_search_(false),
180 omnibox_focus_state_(OMNIBOX_FOCUS_NONE), 180 omnibox_focus_state_(OMNIBOX_FOCUS_NONE),
181 start_margin_(0), 181 start_margin_(0),
182 end_margin_(0), 182 end_margin_(0),
183 allow_preview_to_show_search_suggestions_(false) { 183 allow_preview_to_show_search_suggestions_(false),
184 instant_set_transient_entry_(false) {
184 } 185 }
185 186
186 InstantController::~InstantController() { 187 InstantController::~InstantController() {
187 } 188 }
188 189
189 bool InstantController::Update(const AutocompleteMatch& match, 190 bool InstantController::Update(const AutocompleteMatch& match,
190 const string16& user_text, 191 const string16& user_text,
191 const string16& full_text, 192 const string16& full_text,
192 size_t selection_start, 193 size_t selection_start,
193 size_t selection_end, 194 size_t selection_end,
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 } else if (StartsWith(full_text, last_omnibox_text_, false)) { 342 } else if (StartsWith(full_text, last_omnibox_text_, false)) {
342 // The user is typing forward. Normalize any added characters. 343 // The user is typing forward. Normalize any added characters.
343 reused_suggestion = NormalizeAndStripPrefix(&last_suggestion_.text, 344 reused_suggestion = NormalizeAndStripPrefix(&last_suggestion_.text,
344 string16(full_text, last_omnibox_text_.size())); 345 string16(full_text, last_omnibox_text_.size()));
345 } 346 }
346 } 347 }
347 if (!reused_suggestion) 348 if (!reused_suggestion)
348 last_suggestion_ = InstantSuggestion(); 349 last_suggestion_ = InstantSuggestion();
349 350
350 last_omnibox_text_ = full_text; 351 last_omnibox_text_ = full_text;
352 SetTransientHistoryEntry();
351 353
352 if (!extended_enabled_) { 354 if (!extended_enabled_) {
353 // In non-extended mode, the query is verbatim if there's any selection 355 // In non-extended mode, the query is verbatim if there's any selection
354 // (including inline autocompletion) or if the cursor is not at the end. 356 // (including inline autocompletion) or if the cursor is not at the end.
355 verbatim = verbatim || selection_start != selection_end || 357 verbatim = verbatim || selection_start != selection_end ||
356 selection_start != full_text.size(); 358 selection_start != full_text.size();
357 } 359 }
358 last_verbatim_ = verbatim; 360 last_verbatim_ = verbatim;
359 361
360 last_transition_type_ = match.transition; 362 last_transition_type_ = match.transition;
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 last_suggestion_ = suggestion; 804 last_suggestion_ = suggestion;
803 DVLOG(1) << "SetInstantSuggestion: text='" << suggestion.text << "'" 805 DVLOG(1) << "SetInstantSuggestion: text='" << suggestion.text << "'"
804 << " behavior=" << suggestion.behavior << " type=" 806 << " behavior=" << suggestion.behavior << " type="
805 << suggestion.type; 807 << suggestion.type;
806 browser_->SetInstantSuggestion(suggestion); 808 browser_->SetInstantSuggestion(suggestion);
807 } else { 809 } else {
808 last_suggestion_ = InstantSuggestion(); 810 last_suggestion_ = InstantSuggestion();
809 } 811 }
810 } 812 }
811 813
814 SetTransientHistoryEntry();
815
812 // Extended mode pages will call ShowLoader() when they are ready. 816 // Extended mode pages will call ShowLoader() when they are ready.
813 if (!extended_enabled_) 817 if (!extended_enabled_)
814 ShowLoader(INSTANT_SHOWN_QUERY_SUGGESTIONS, 100, INSTANT_SIZE_PERCENT); 818 ShowLoader(INSTANT_SHOWN_QUERY_SUGGESTIONS, 100, INSTANT_SIZE_PERCENT);
815 } 819 }
816 820
817 void InstantController::InstantSupportDetermined( 821 void InstantController::InstantSupportDetermined(
818 const content::WebContents* contents, 822 const content::WebContents* contents,
819 bool supports_instant) { 823 bool supports_instant) {
820 if (instant_tab_ && instant_tab_->contents() == contents) { 824 if (instant_tab_ && instant_tab_->contents() == contents) {
821 if (!supports_instant) 825 if (!supports_instant)
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
1081 // change the state just yet; else we may hide the preview unnecessarily. 1085 // change the state just yet; else we may hide the preview unnecessarily.
1082 // Instead, the state will be set correctly after the commit is done. 1086 // Instead, the state will be set correctly after the commit is done.
1083 if (GetPreviewContents()) { 1087 if (GetPreviewContents()) {
1084 model_.SetPreviewState(chrome::search::Mode(), 0, INSTANT_SIZE_PERCENT); 1088 model_.SetPreviewState(chrome::search::Mode(), 0, INSTANT_SIZE_PERCENT);
1085 allow_preview_to_show_search_suggestions_ = false; 1089 allow_preview_to_show_search_suggestions_ = false;
1086 1090
1087 // Send a message asking the preview to clear out old results. 1091 // Send a message asking the preview to clear out old results.
1088 loader_->Update(string16(), 0, 0, true); 1092 loader_->Update(string16(), 0, 0, true);
1089 } 1093 }
1090 1094
1095 ResetTransientHistoryEntry();
1096
1091 // Clear the first interaction timestamp for later use. 1097 // Clear the first interaction timestamp for later use.
1092 first_interaction_time_ = base::Time(); 1098 first_interaction_time_ = base::Time();
1093 } 1099 }
1094 1100
1095 void InstantController::ShowLoader(InstantShownReason reason, 1101 void InstantController::ShowLoader(InstantShownReason reason,
1096 int height, 1102 int height,
1097 InstantSizeUnits units) { 1103 InstantSizeUnits units) {
1098 // If we are on a committed search results page, the |loader_| is not in use. 1104 // If we are on a committed search results page, the |loader_| is not in use.
1099 if (instant_tab_) 1105 if (instant_tab_)
1100 return; 1106 return;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1138 model_.SetPreviewState(search_mode_, height, units); 1144 model_.SetPreviewState(search_mode_, height, units);
1139 else 1145 else
1140 model_.SetPreviewState(search_mode_, 100, INSTANT_SIZE_PERCENT); 1146 model_.SetPreviewState(search_mode_, 100, INSTANT_SIZE_PERCENT);
1141 1147
1142 // If the user clicked on a query suggestion, also go ahead and commit the 1148 // If the user clicked on a query suggestion, also go ahead and commit the
1143 // overlay. This is necessary because if the overlay was partially visible 1149 // overlay. This is necessary because if the overlay was partially visible
1144 // when the suggestion was clicked, the click itself would not commit the 1150 // when the suggestion was clicked, the click itself would not commit the
1145 // overlay (because we're not full height). 1151 // overlay (because we're not full height).
1146 if (reason == INSTANT_SHOWN_CLICKED_QUERY_SUGGESTION) 1152 if (reason == INSTANT_SHOWN_CLICKED_QUERY_SUGGESTION)
1147 CommitIfPossible(INSTANT_COMMIT_CLICKED_QUERY_SUGGESTION); 1153 CommitIfPossible(INSTANT_COMMIT_CLICKED_QUERY_SUGGESTION);
1154 else if (extended_enabled_ && IsFullHeight(model_))
1155 SetTransientHistoryEntry();
1156 }
1157
1158 void InstantController::SetTransientHistoryEntry() {
1159 content::WebContents* active_tab = browser_->GetActiveWebContents();
1160 // Save any transient entry already associated with the active tab.
1161 content::NavigationEntry* old_transient_entry =
1162 active_tab->GetController().GetTransientEntry();
1163 if (old_transient_entry && !instant_set_transient_entry_)
1164 transient_entry_.reset(
1165 content::NavigationEntry::Create(*old_transient_entry));
1166 // The loader's base navigation entry should describe the search provider
1167 // without reference to a specific query. The alternative, updating the query
1168 // in the tab title as the user types, would be distracting.
1169 const content::NavigationEntry* base_entry = loader_->base_navigation_entry();
1170 DCHECK(base_entry != NULL);
1171 content::NavigationEntry* new_transient_entry =
1172 content::NavigationEntry::Create(*base_entry);
1173 // The URL should update so that if the user presses reload, we reload the
1174 // page for the current query.
1175 const TemplateURL* template_url = TemplateURLServiceFactory::GetForProfile(
1176 Profile::FromBrowserContext(active_tab->GetBrowserContext()))->
1177 GetDefaultSearchProvider();
1178 const TemplateURLRef& url_ref = template_url->url_ref();
1179 DCHECK(url_ref.IsValid());
1180 TemplateURLRef::SearchTermsArgs search_terms(last_omnibox_text_ +
1181 last_suggestion_.text);
1182 std::string url = url_ref.ReplaceSearchTerms(search_terms);
1183 new_transient_entry->SetURL(GURL(url));
1184 new_transient_entry->SetVirtualURL(GURL(url));
1185 active_tab->GetController().AddTransientEntry(new_transient_entry);
1186 instant_set_transient_entry_ = true;
sreeram 2013/01/22 05:28:34 Wow. This is really hacky. Why do we need this? Ca
Jered 2013/01/23 21:52:07 Navigating after 3 seconds is a very Google-specif
1187 }
1188
1189 void InstantController::ResetTransientHistoryEntry() {
1190 content::NavigationEntry* old_transient_entry = transient_entry_.release();
1191 if (old_transient_entry) {
1192 DVLOG(1) << "ResetTransientHistoryEntry: restoring old transient entry";
1193 content::WebContents* active_tab = browser_->GetActiveWebContents();
1194 active_tab->GetController().AddTransientEntry(old_transient_entry);
1195 chrome::search::SearchTabHelper::FromWebContents(active_tab)->
1196 NavigationEntryUpdated();
1197 }
1198 instant_set_transient_entry_ = false;
1148 } 1199 }
1149 1200
1150 void InstantController::SendPopupBoundsToPage() { 1201 void InstantController::SendPopupBoundsToPage() {
1151 if (last_popup_bounds_ == popup_bounds_ || !loader_ || 1202 if (last_popup_bounds_ == popup_bounds_ || !loader_ ||
1152 loader_->is_pointer_down_from_activate()) 1203 loader_->is_pointer_down_from_activate())
1153 return; 1204 return;
1154 1205
1155 last_popup_bounds_ = popup_bounds_; 1206 last_popup_bounds_ = popup_bounds_;
1156 gfx::Rect preview_bounds = browser_->GetInstantBounds(); 1207 gfx::Rect preview_bounds = browser_->GetInstantBounds();
1157 gfx::Rect intersection = gfx::IntersectRects(popup_bounds_, preview_bounds); 1208 gfx::Rect intersection = gfx::IntersectRects(popup_bounds_, preview_bounds);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1236 std::map<std::string, int>::const_iterator iter = 1287 std::map<std::string, int>::const_iterator iter =
1237 blacklisted_urls_.find(*instant_url); 1288 blacklisted_urls_.find(*instant_url);
1238 if (iter != blacklisted_urls_.end() && 1289 if (iter != blacklisted_urls_.end() &&
1239 iter->second > kMaxInstantSupportFailures) { 1290 iter->second > kMaxInstantSupportFailures) {
1240 RecordEventHistogram(INSTANT_CONTROLLER_EVENT_URL_BLOCKED_BY_BLACKLIST); 1291 RecordEventHistogram(INSTANT_CONTROLLER_EVENT_URL_BLOCKED_BY_BLACKLIST);
1241 return false; 1292 return false;
1242 } 1293 }
1243 1294
1244 return true; 1295 return true;
1245 } 1296 }
OLDNEW
« no previous file with comments | « chrome/browser/instant/instant_controller.h ('k') | chrome/browser/instant/instant_loader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698