OLD | NEW |
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/stringprintf.h" | 10 #include "base/stringprintf.h" |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 instant_enabled_(false), | 176 instant_enabled_(false), |
177 use_local_preview_only_(true), | 177 use_local_preview_only_(true), |
178 model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 178 model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
179 last_omnibox_text_has_inline_autocompletion_(false), | 179 last_omnibox_text_has_inline_autocompletion_(false), |
180 last_verbatim_(false), | 180 last_verbatim_(false), |
181 last_transition_type_(content::PAGE_TRANSITION_LINK), | 181 last_transition_type_(content::PAGE_TRANSITION_LINK), |
182 last_match_was_search_(false), | 182 last_match_was_search_(false), |
183 omnibox_focus_state_(OMNIBOX_FOCUS_NONE), | 183 omnibox_focus_state_(OMNIBOX_FOCUS_NONE), |
184 start_margin_(0), | 184 start_margin_(0), |
185 end_margin_(0), | 185 end_margin_(0), |
186 allow_preview_to_show_search_suggestions_(false) { | 186 allow_preview_to_show_search_suggestions_(false), |
| 187 instant_set_transient_entry_(false) { |
187 } | 188 } |
188 | 189 |
189 InstantController::~InstantController() { | 190 InstantController::~InstantController() { |
190 } | 191 } |
191 | 192 |
192 bool InstantController::Update(const AutocompleteMatch& match, | 193 bool InstantController::Update(const AutocompleteMatch& match, |
193 const string16& user_text, | 194 const string16& user_text, |
194 const string16& full_text, | 195 const string16& full_text, |
195 size_t selection_start, | 196 size_t selection_start, |
196 size_t selection_end, | 197 size_t selection_end, |
(...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
926 | 927 |
927 // Commit the navigation if either: | 928 // Commit the navigation if either: |
928 // - The page is in NTP mode (so it could only navigate on a user click) or | 929 // - The page is in NTP mode (so it could only navigate on a user click) or |
929 // - The page is not in NTP mode and we are navigating to a URL with a | 930 // - The page is not in NTP mode and we are navigating to a URL with a |
930 // different host or path than the instant URL. This enables the instant | 931 // different host or path than the instant URL. This enables the instant |
931 // page when it is showing search results to change the query parameters | 932 // page when it is showing search results to change the query parameters |
932 // and fragments of the URL without it navigating. | 933 // and fragments of the URL without it navigating. |
933 if (model_.mode().is_ntp() || | 934 if (model_.mode().is_ntp() || |
934 (url.host() != instant_url.host() || url.path() != instant_url.path())) { | 935 (url.host() != instant_url.host() || url.path() != instant_url.path())) { |
935 CommitIfPossible(INSTANT_COMMIT_NAVIGATED); | 936 CommitIfPossible(INSTANT_COMMIT_NAVIGATED); |
| 937 } else { |
| 938 UpdateTransientHistoryEntry(url); |
936 } | 939 } |
937 } | 940 } |
938 | 941 |
939 void InstantController::SetSuggestions( | 942 void InstantController::SetSuggestions( |
940 const content::WebContents* contents, | 943 const content::WebContents* contents, |
941 const std::vector<InstantSuggestion>& suggestions) { | 944 const std::vector<InstantSuggestion>& suggestions) { |
942 LOG_INSTANT_DEBUG_EVENT(this, "SetSuggestions"); | 945 LOG_INSTANT_DEBUG_EVENT(this, "SetSuggestions"); |
943 | 946 |
944 // Ignore if the message is from an unexpected source. | 947 // Ignore if the message is from an unexpected source. |
945 if (IsContentsFrom(ntp(), contents)) | 948 if (IsContentsFrom(ntp(), contents)) |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1195 // change the state just yet; else we may hide the preview unnecessarily. | 1198 // change the state just yet; else we may hide the preview unnecessarily. |
1196 // Instead, the state will be set correctly after the commit is done. | 1199 // Instead, the state will be set correctly after the commit is done. |
1197 if (GetPreviewContents()) { | 1200 if (GetPreviewContents()) { |
1198 model_.SetPreviewState(chrome::search::Mode(), 0, INSTANT_SIZE_PERCENT); | 1201 model_.SetPreviewState(chrome::search::Mode(), 0, INSTANT_SIZE_PERCENT); |
1199 allow_preview_to_show_search_suggestions_ = false; | 1202 allow_preview_to_show_search_suggestions_ = false; |
1200 | 1203 |
1201 // Send a message asking the preview to clear out old results. | 1204 // Send a message asking the preview to clear out old results. |
1202 overlay_->Update(string16(), 0, 0, true); | 1205 overlay_->Update(string16(), 0, 0, true); |
1203 } | 1206 } |
1204 | 1207 |
| 1208 ResetTransientHistoryEntry(); |
| 1209 |
1205 // Clear the first interaction timestamp for later use. | 1210 // Clear the first interaction timestamp for later use. |
1206 first_interaction_time_ = base::Time(); | 1211 first_interaction_time_ = base::Time(); |
1207 } | 1212 } |
1208 | 1213 |
1209 void InstantController::ShowOverlay(InstantShownReason reason, | 1214 void InstantController::ShowOverlay(InstantShownReason reason, |
1210 int height, | 1215 int height, |
1211 InstantSizeUnits units) { | 1216 InstantSizeUnits units) { |
1212 // If we are on a committed search results page, the |overlay_| is not in use. | 1217 // If we are on a committed search results page, the |overlay_| is not in use. |
1213 if (instant_tab_) | 1218 if (instant_tab_) |
1214 return; | 1219 return; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1253 model_.SetPreviewState(search_mode_, height, units); | 1258 model_.SetPreviewState(search_mode_, height, units); |
1254 else | 1259 else |
1255 model_.SetPreviewState(search_mode_, 100, INSTANT_SIZE_PERCENT); | 1260 model_.SetPreviewState(search_mode_, 100, INSTANT_SIZE_PERCENT); |
1256 | 1261 |
1257 // If the user clicked on a query suggestion, also go ahead and commit the | 1262 // If the user clicked on a query suggestion, also go ahead and commit the |
1258 // overlay. This is necessary because if the overlay was partially visible | 1263 // overlay. This is necessary because if the overlay was partially visible |
1259 // when the suggestion was clicked, the click itself would not commit the | 1264 // when the suggestion was clicked, the click itself would not commit the |
1260 // overlay (because we're not full height). | 1265 // overlay (because we're not full height). |
1261 if (reason == INSTANT_SHOWN_CLICKED_QUERY_SUGGESTION) | 1266 if (reason == INSTANT_SHOWN_CLICKED_QUERY_SUGGESTION) |
1262 CommitIfPossible(INSTANT_COMMIT_CLICKED_QUERY_SUGGESTION); | 1267 CommitIfPossible(INSTANT_COMMIT_CLICKED_QUERY_SUGGESTION); |
| 1268 else if (extended_enabled_ && IsFullHeight(model_)) |
| 1269 SetTransientHistoryEntry(); |
| 1270 } |
| 1271 |
| 1272 void InstantController::SetTransientHistoryEntry() { |
| 1273 content::WebContents* active_tab = browser_->GetActiveWebContents(); |
| 1274 // If the active tab already has a transient entry, leave it alone. |
| 1275 if (active_tab->GetController().GetTransientEntry()) |
| 1276 return; |
| 1277 // The loader's base navigation entry should describe the search provider |
| 1278 // without reference to a specific query. The alternative, updating the query |
| 1279 // in the tab title as the user types, would be distracting. |
| 1280 const content::NavigationEntry* base_entry = |
| 1281 overlay_->base_navigation_entry(); |
| 1282 DCHECK(base_entry != NULL); |
| 1283 content::NavigationEntry* transient_entry = |
| 1284 content::NavigationEntry::Create(*base_entry); |
| 1285 active_tab->GetController().AddTransientEntry(transient_entry); |
| 1286 instant_set_transient_entry_ = true; |
| 1287 } |
| 1288 |
| 1289 void InstantController::UpdateTransientHistoryEntry(const GURL& url) { |
| 1290 // URL should update so that if the user presses reload, we reload the page |
| 1291 // for the current query, but title remains unchanged so it doesn't flicker. |
| 1292 if (instant_set_transient_entry_) { |
| 1293 content::WebContents* active_tab = browser_->GetActiveWebContents(); |
| 1294 content::NavigationEntry* transient_entry = |
| 1295 active_tab->GetController().GetTransientEntry(); |
| 1296 DCHECK(transient_entry != NULL); |
| 1297 transient_entry->SetURL(url); |
| 1298 transient_entry->SetVirtualURL(url); |
| 1299 } |
| 1300 } |
| 1301 |
| 1302 void InstantController::ResetTransientHistoryEntry() { |
| 1303 // NavigationController will discard the entry. |
| 1304 instant_set_transient_entry_ = false; |
1263 } | 1305 } |
1264 | 1306 |
1265 void InstantController::SendPopupBoundsToPage() { | 1307 void InstantController::SendPopupBoundsToPage() { |
1266 if (last_popup_bounds_ == popup_bounds_ || !overlay_ || | 1308 if (last_popup_bounds_ == popup_bounds_ || !overlay_ || |
1267 overlay_->is_pointer_down_from_activate()) | 1309 overlay_->is_pointer_down_from_activate()) |
1268 return; | 1310 return; |
1269 | 1311 |
1270 last_popup_bounds_ = popup_bounds_; | 1312 last_popup_bounds_ = popup_bounds_; |
1271 gfx::Rect preview_bounds = browser_->GetInstantBounds(); | 1313 gfx::Rect preview_bounds = browser_->GetInstantBounds(); |
1272 gfx::Rect intersection = gfx::IntersectRects(popup_bounds_, preview_bounds); | 1314 gfx::Rect intersection = gfx::IntersectRects(popup_bounds_, preview_bounds); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1398 delete overlay_->ReleaseContents().release(); | 1440 delete overlay_->ReleaseContents().release(); |
1399 MessageLoop::current()->DeleteSoon(FROM_HERE, overlay_.release()); | 1441 MessageLoop::current()->DeleteSoon(FROM_HERE, overlay_.release()); |
1400 EnsureOverlayIsCurrent(false); | 1442 EnsureOverlayIsCurrent(false); |
1401 } | 1443 } |
1402 | 1444 |
1403 void InstantController::RemoveFromBlacklist(const std::string& url) { | 1445 void InstantController::RemoveFromBlacklist(const std::string& url) { |
1404 if (blacklisted_urls_.erase(url)) { | 1446 if (blacklisted_urls_.erase(url)) { |
1405 RecordEventHistogram(INSTANT_CONTROLLER_EVENT_URL_REMOVED_FROM_BLACKLIST); | 1447 RecordEventHistogram(INSTANT_CONTROLLER_EVENT_URL_REMOVED_FROM_BLACKLIST); |
1406 } | 1448 } |
1407 } | 1449 } |
OLD | NEW |