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

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: Address comment. 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
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/debug/stack_trace.h"
sreeram 2013/01/25 18:17:29 Remove this before submitting.
Jered 2013/01/25 19:27:18 Done.
8 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
9 #include "base/string_util.h" 10 #include "base/string_util.h"
10 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/autocomplete/autocomplete_provider.h" 12 #include "chrome/browser/autocomplete/autocomplete_provider.h"
12 #include "chrome/browser/google/google_util.h" 13 #include "chrome/browser/google/google_util.h"
13 #include "chrome/browser/history/history.h" 14 #include "chrome/browser/history/history.h"
14 #include "chrome/browser/history/history_service_factory.h" 15 #include "chrome/browser/history/history_service_factory.h"
15 #include "chrome/browser/history/history_tab_helper.h" 16 #include "chrome/browser/history/history_tab_helper.h"
16 #include "chrome/browser/instant/instant_loader.h" 17 #include "chrome/browser/instant/instant_loader.h"
17 #include "chrome/browser/instant/instant_tab.h" 18 #include "chrome/browser/instant/instant_tab.h"
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 instant_enabled_(false), 174 instant_enabled_(false),
174 use_local_preview_only_(use_local_preview_only), 175 use_local_preview_only_(use_local_preview_only),
175 model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 176 model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
176 last_omnibox_text_has_inline_autocompletion_(false), 177 last_omnibox_text_has_inline_autocompletion_(false),
177 last_verbatim_(false), 178 last_verbatim_(false),
178 last_transition_type_(content::PAGE_TRANSITION_LINK), 179 last_transition_type_(content::PAGE_TRANSITION_LINK),
179 last_match_was_search_(false), 180 last_match_was_search_(false),
180 omnibox_focus_state_(OMNIBOX_FOCUS_NONE), 181 omnibox_focus_state_(OMNIBOX_FOCUS_NONE),
181 start_margin_(0), 182 start_margin_(0),
182 end_margin_(0), 183 end_margin_(0),
183 allow_preview_to_show_search_suggestions_(false) { 184 allow_preview_to_show_search_suggestions_(false),
185 instant_set_transient_entry_(false) {
184 } 186 }
185 187
186 InstantController::~InstantController() { 188 InstantController::~InstantController() {
187 } 189 }
188 190
189 bool InstantController::Update(const AutocompleteMatch& match, 191 bool InstantController::Update(const AutocompleteMatch& match,
190 const string16& user_text, 192 const string16& user_text,
191 const string16& full_text, 193 const string16& full_text,
192 size_t selection_start, 194 size_t selection_start,
193 size_t selection_end, 195 size_t selection_end,
(...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 904
903 // Commit the navigation if either: 905 // Commit the navigation if either:
904 // - The page is in NTP mode (so it could only navigate on a user click) or 906 // - The page is in NTP mode (so it could only navigate on a user click) or
905 // - The page is not in NTP mode and we are navigating to a URL with a 907 // - The page is not in NTP mode and we are navigating to a URL with a
906 // different host or path than the instant URL. This enables the instant 908 // different host or path than the instant URL. This enables the instant
907 // page when it is showing search results to change the query parameters 909 // page when it is showing search results to change the query parameters
908 // and fragments of the URL without it navigating. 910 // and fragments of the URL without it navigating.
909 if (model_.mode().is_ntp() || 911 if (model_.mode().is_ntp() ||
910 (url.host() != instant_url.host() || url.path() != instant_url.path())) { 912 (url.host() != instant_url.host() || url.path() != instant_url.path())) {
911 CommitIfPossible(INSTANT_COMMIT_NAVIGATED); 913 CommitIfPossible(INSTANT_COMMIT_NAVIGATED);
914 } else {
915 UpdateTransientHistoryEntry(url);
912 } 916 }
913 } 917 }
914 918
915 void InstantController::OmniboxLostFocus(gfx::NativeView view_gaining_focus) { 919 void InstantController::OmniboxLostFocus(gfx::NativeView view_gaining_focus) {
916 // If the preview is showing custom NTP content, don't hide it, commit it 920 // If the preview is showing custom NTP content, don't hide it, commit it
917 // (no matter where the user clicked) or try to recreate it. 921 // (no matter where the user clicked) or try to recreate it.
918 if (model_.mode().is_ntp()) 922 if (model_.mode().is_ntp())
919 return; 923 return;
920 924
921 // If the preview is not showing at all, recreate it if it's stale. 925 // If the preview is not showing at all, recreate it if it's stale.
(...skipping 159 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 active_tab->GetController().AddTransientEntry(new_transient_entry);
1174 instant_set_transient_entry_ = true;
1175 }
1176
1177 void InstantController::ResetTransientHistoryEntry() {
1178 content::NavigationEntry* old_transient_entry = transient_entry_.release();
1179 if (old_transient_entry) {
1180 content::WebContents* active_tab = browser_->GetActiveWebContents();
1181 active_tab->GetController().AddTransientEntry(old_transient_entry);
1182 chrome::search::SearchTabHelper::FromWebContents(active_tab)->
1183 NavigationEntryUpdated();
1184 }
1185 instant_set_transient_entry_ = false;
1186 }
1187
1188 void InstantController::UpdateTransientHistoryEntry(const GURL& url) {
1189 // URL should update so that if the user presses reload, we reload the page
1190 // for the current query, but title remains unchanged so it doesn't flicker.
1191 if (instant_set_transient_entry_) {
1192 content::WebContents* active_tab = browser_->GetActiveWebContents();
1193 content::NavigationEntry* transient_entry =
1194 active_tab->GetController().GetTransientEntry();
1195 transient_entry->SetURL(url);
1196 transient_entry->SetVirtualURL(url);
1197 }
1148 } 1198 }
1149 1199
1150 void InstantController::SendPopupBoundsToPage() { 1200 void InstantController::SendPopupBoundsToPage() {
1151 if (last_popup_bounds_ == popup_bounds_ || !loader_ || 1201 if (last_popup_bounds_ == popup_bounds_ || !loader_ ||
1152 loader_->is_pointer_down_from_activate()) 1202 loader_->is_pointer_down_from_activate())
1153 return; 1203 return;
1154 1204
1155 last_popup_bounds_ = popup_bounds_; 1205 last_popup_bounds_ = popup_bounds_;
1156 gfx::Rect preview_bounds = browser_->GetInstantBounds(); 1206 gfx::Rect preview_bounds = browser_->GetInstantBounds();
1157 gfx::Rect intersection = gfx::IntersectRects(popup_bounds_, preview_bounds); 1207 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 = 1286 std::map<std::string, int>::const_iterator iter =
1237 blacklisted_urls_.find(*instant_url); 1287 blacklisted_urls_.find(*instant_url);
1238 if (iter != blacklisted_urls_.end() && 1288 if (iter != blacklisted_urls_.end() &&
1239 iter->second > kMaxInstantSupportFailures) { 1289 iter->second > kMaxInstantSupportFailures) {
1240 RecordEventHistogram(INSTANT_CONTROLLER_EVENT_URL_BLOCKED_BY_BLACKLIST); 1290 RecordEventHistogram(INSTANT_CONTROLLER_EVENT_URL_BLOCKED_BY_BLACKLIST);
1241 return false; 1291 return false;
1242 } 1292 }
1243 1293
1244 return true; 1294 return true;
1245 } 1295 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698