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/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "chrome/browser/autocomplete/autocomplete_provider.h" | 11 #include "chrome/browser/autocomplete/autocomplete_provider.h" |
12 #include "chrome/browser/google/google_util.h" | 12 #include "chrome/browser/google/google_util.h" |
13 #include "chrome/browser/history/history.h" | 13 #include "chrome/browser/history/history.h" |
14 #include "chrome/browser/history/history_service_factory.h" | 14 #include "chrome/browser/history/history_service_factory.h" |
15 #include "chrome/browser/history/history_tab_helper.h" | 15 #include "chrome/browser/history/history_tab_helper.h" |
16 #include "chrome/browser/instant/instant_loader.h" | 16 #include "chrome/browser/instant/instant_ntp.h" |
| 17 #include "chrome/browser/instant/instant_overlay.h" |
17 #include "chrome/browser/instant/instant_tab.h" | 18 #include "chrome/browser/instant/instant_tab.h" |
18 #include "chrome/browser/platform_util.h" | 19 #include "chrome/browser/platform_util.h" |
19 #include "chrome/browser/search_engines/template_url_service.h" | 20 #include "chrome/browser/search_engines/template_url_service.h" |
20 #include "chrome/browser/search_engines/template_url_service_factory.h" | 21 #include "chrome/browser/search_engines/template_url_service_factory.h" |
21 #include "chrome/browser/ui/browser_instant_controller.h" | 22 #include "chrome/browser/ui/browser_instant_controller.h" |
22 #include "chrome/browser/ui/search/search_tab_helper.h" | 23 #include "chrome/browser/ui/search/search_tab_helper.h" |
23 #include "chrome/common/chrome_notification_types.h" | 24 #include "chrome/common/chrome_notification_types.h" |
24 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
25 #include "content/public/browser/navigation_entry.h" | 26 #include "content/public/browser/navigation_entry.h" |
26 #include "content/public/browser/notification_service.h" | 27 #include "content/public/browser/notification_service.h" |
(...skipping 12 matching lines...) Expand all Loading... |
39 // page about the new omnibox bounds, in cases where the bounds shrink. This is | 40 // page about the new omnibox bounds, in cases where the bounds shrink. This is |
40 // to avoid the page jumping up/down very fast in response to bounds changes. | 41 // to avoid the page jumping up/down very fast in response to bounds changes. |
41 const int kUpdateBoundsDelayMS = 1000; | 42 const int kUpdateBoundsDelayMS = 1000; |
42 | 43 |
43 // The maximum number of times we'll load a non-Instant-supporting search engine | 44 // The maximum number of times we'll load a non-Instant-supporting search engine |
44 // before we give up and blacklist it for the rest of the browsing session. | 45 // before we give up and blacklist it for the rest of the browsing session. |
45 const int kMaxInstantSupportFailures = 10; | 46 const int kMaxInstantSupportFailures = 10; |
46 | 47 |
47 // If an Instant page has not been used in these many milliseconds, it is | 48 // If an Instant page has not been used in these many milliseconds, it is |
48 // reloaded so that the page does not become stale. | 49 // reloaded so that the page does not become stale. |
49 const int kStaleLoaderTimeoutMS = 3 * 3600 * 1000; | 50 const int kStalePageTimeoutMS = 3 * 3600 * 1000; |
50 | 51 |
51 // For reporting events of interest. | 52 // For reporting events of interest. |
52 enum InstantControllerEvent { | 53 enum InstantControllerEvent { |
53 INSTANT_CONTROLLER_EVENT_URL_ADDED_TO_BLACKLIST = 0, | 54 INSTANT_CONTROLLER_EVENT_URL_ADDED_TO_BLACKLIST = 0, |
54 INSTANT_CONTROLLER_EVENT_URL_REMOVED_FROM_BLACKLIST = 1, | 55 INSTANT_CONTROLLER_EVENT_URL_REMOVED_FROM_BLACKLIST = 1, |
55 INSTANT_CONTROLLER_EVENT_URL_BLOCKED_BY_BLACKLIST = 2, | 56 INSTANT_CONTROLLER_EVENT_URL_BLOCKED_BY_BLACKLIST = 2, |
56 INSTANT_CONTROLLER_EVENT_MAX = 3, | 57 INSTANT_CONTROLLER_EVENT_MAX = 3, |
57 }; | 58 }; |
58 | 59 |
59 void RecordEventHistogram(InstantControllerEvent event) { | 60 void RecordEventHistogram(InstantControllerEvent event) { |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 << is_keyword_search; | 209 << is_keyword_search; |
209 | 210 |
210 // TODO(dhollowa): Complete keyword match UI. For now just hide suggestions. | 211 // TODO(dhollowa): Complete keyword match UI. For now just hide suggestions. |
211 // http://crbug.com/153932. Note, this early escape is happens prior to the | 212 // http://crbug.com/153932. Note, this early escape is happens prior to the |
212 // DCHECKs below because |user_text| and |full_text| have different semantics | 213 // DCHECKs below because |user_text| and |full_text| have different semantics |
213 // when keyword search is in effect. | 214 // when keyword search is in effect. |
214 if (is_keyword_search) { | 215 if (is_keyword_search) { |
215 if (instant_tab_) | 216 if (instant_tab_) |
216 instant_tab_->Update(string16(), 0, 0, true); | 217 instant_tab_->Update(string16(), 0, 0, true); |
217 else | 218 else |
218 HideLoader(); | 219 HideOverlay(); |
219 last_match_was_search_ = false; | 220 last_match_was_search_ = false; |
220 return false; | 221 return false; |
221 } | 222 } |
222 | 223 |
223 // If the popup is open, the user has to be typing. | 224 // If the popup is open, the user has to be typing. |
224 DCHECK(!omnibox_popup_is_open || user_input_in_progress); | 225 DCHECK(!omnibox_popup_is_open || user_input_in_progress); |
225 | 226 |
226 // If the popup is closed, there should be no inline autocompletion. | 227 // If the popup is closed, there should be no inline autocompletion. |
227 DCHECK(omnibox_popup_is_open || user_text.empty() || user_text == full_text) | 228 DCHECK(omnibox_popup_is_open || user_text.empty() || user_text == full_text) |
228 << user_text << "|" << full_text; | 229 << user_text << "|" << full_text; |
229 | 230 |
230 // If there's no text in the omnibox, the user can't have typed any. | 231 // If there's no text in the omnibox, the user can't have typed any. |
231 DCHECK(!full_text.empty() || user_text.empty()) << user_text; | 232 DCHECK(!full_text.empty() || user_text.empty()) << user_text; |
232 | 233 |
233 // If the user isn't typing, and the popup is closed, there can't be any | 234 // If the user isn't typing, and the popup is closed, there can't be any |
234 // user-typed text. | 235 // user-typed text. |
235 DCHECK(user_input_in_progress || omnibox_popup_is_open || user_text.empty()) | 236 DCHECK(user_input_in_progress || omnibox_popup_is_open || user_text.empty()) |
236 << user_text; | 237 << user_text; |
237 | 238 |
238 // The preview is being clicked and will commit soon. Don't change anything. | 239 // The preview is being clicked and will commit soon. Don't change anything. |
239 // TODO(sreeram): Add a browser test for this. | 240 // TODO(sreeram): Add a browser test for this. |
240 if (loader_ && loader_->is_pointer_down_from_activate()) | 241 if (overlay_ && overlay_->is_pointer_down_from_activate()) |
241 return false; | 242 return false; |
242 | 243 |
243 // In non-extended mode, SearchModeChanged() is never called, so fake it. The | 244 // In non-extended mode, SearchModeChanged() is never called, so fake it. The |
244 // mode is set to "disallow suggestions" here, so that if one of the early | 245 // mode is set to "disallow suggestions" here, so that if one of the early |
245 // "return false" conditions is hit, suggestions will be disallowed. If the | 246 // "return false" conditions is hit, suggestions will be disallowed. If the |
246 // query is sent to the loader, the mode is set to "allow" further below. | 247 // query is sent to the overlay, the mode is set to "allow" further below. |
247 if (!extended_enabled_) | 248 if (!extended_enabled_) |
248 search_mode_.mode = chrome::search::Mode::MODE_DEFAULT; | 249 search_mode_.mode = chrome::search::Mode::MODE_DEFAULT; |
249 | 250 |
250 last_match_was_search_ = AutocompleteMatch::IsSearchType(match.type) && | 251 last_match_was_search_ = AutocompleteMatch::IsSearchType(match.type) && |
251 !user_text.empty(); | 252 !user_text.empty(); |
252 | 253 |
253 if (!ResetLoaderForMatch(match)) { | 254 if (!ResetOverlayForMatch(match)) { |
254 HideLoader(); | 255 HideOverlay(); |
255 return false; | 256 return false; |
256 } | 257 } |
257 | 258 |
258 if (extended_enabled_) { | 259 if (extended_enabled_) { |
259 if (!omnibox_popup_is_open) { | 260 if (!omnibox_popup_is_open) { |
260 if (!user_input_in_progress) { | 261 if (!user_input_in_progress) { |
261 // If the user isn't typing and the omnibox popup is closed, it means a | 262 // If the user isn't typing and the omnibox popup is closed, it means a |
262 // regular navigation, tab-switch or the user hitting Escape. | 263 // regular navigation, tab-switch or the user hitting Escape. |
263 if (instant_tab_) { | 264 if (instant_tab_) { |
264 // The user is on a search results page. It may be showing results for | 265 // The user is on a search results page. It may be showing results for |
265 // a partial query the user typed before they hit Escape. Send the | 266 // a partial query the user typed before they hit Escape. Send the |
266 // omnibox text to the page to restore the original results. | 267 // omnibox text to the page to restore the original results. |
267 // | 268 // |
268 // In a tab switch, |instant_tab_| won't have updated yet, so it may | 269 // In a tab switch, |instant_tab_| won't have updated yet, so it may |
269 // be pointing to the previous tab (which was a search results page). | 270 // be pointing to the previous tab (which was a search results page). |
270 // Ensure we don't send the omnibox text to a random webpage (the new | 271 // Ensure we don't send the omnibox text to a random webpage (the new |
271 // tab), by comparing the old and new WebContents. | 272 // tab), by comparing the old and new WebContents. |
272 if (escape_pressed && | 273 if (escape_pressed && |
273 instant_tab_->contents() == browser_->GetActiveWebContents()) { | 274 instant_tab_->contents() == browser_->GetActiveWebContents()) { |
274 instant_tab_->Submit(full_text); | 275 instant_tab_->Submit(full_text); |
275 } | 276 } |
276 } else if (!full_text.empty()) { | 277 } else if (!full_text.empty()) { |
277 // If |full_text| is empty, the user is on the NTP. The preview may | 278 // If |full_text| is empty, the user is on the NTP. The preview may |
278 // be showing custom NTP content; hide only if that's not the case. | 279 // be showing custom NTP content; hide only if that's not the case. |
279 HideLoader(); | 280 HideOverlay(); |
280 } | 281 } |
281 } else if (full_text.empty()) { | 282 } else if (full_text.empty()) { |
282 // The user is typing, and backspaced away all omnibox text. Clear | 283 // The user is typing, and backspaced away all omnibox text. Clear |
283 // |last_omnibox_text_| so that we don't attempt to set suggestions. | 284 // |last_omnibox_text_| so that we don't attempt to set suggestions. |
284 last_omnibox_text_.clear(); | 285 last_omnibox_text_.clear(); |
285 last_suggestion_ = InstantSuggestion(); | 286 last_suggestion_ = InstantSuggestion(); |
286 if (instant_tab_) { | 287 if (instant_tab_) { |
287 // On a search results page, tell it to clear old results. | 288 // On a search results page, tell it to clear old results. |
288 instant_tab_->Update(string16(), 0, 0, true); | 289 instant_tab_->Update(string16(), 0, 0, true); |
289 } else if (search_mode_.is_origin_ntp()) { | 290 } else if (search_mode_.is_origin_ntp()) { |
290 // On the NTP, tell the preview to clear old results. Don't hide the | 291 // On the NTP, tell the preview to clear old results. Don't hide the |
291 // preview so it can show a blank page or logo if it wants. | 292 // preview so it can show a blank page or logo if it wants. |
292 loader_->Update(string16(), 0, 0, true); | 293 overlay_->Update(string16(), 0, 0, true); |
293 } else { | 294 } else { |
294 HideLoader(); | 295 HideOverlay(); |
295 } | 296 } |
296 } else { | 297 } else { |
297 // The user switched to a tab with partial text already in the omnibox. | 298 // The user switched to a tab with partial text already in the omnibox. |
298 HideLoader(); | 299 HideOverlay(); |
299 | 300 |
300 // The new tab may or may not be a search results page; we don't know | 301 // The new tab may or may not be a search results page; we don't know |
301 // since SearchModeChanged() hasn't been called yet. If it later turns | 302 // since SearchModeChanged() hasn't been called yet. If it later turns |
302 // out to be, we should store |full_text| now, so that if the user hits | 303 // out to be, we should store |full_text| now, so that if the user hits |
303 // Enter, we'll send the correct query to instant_tab_->Submit(). If the | 304 // Enter, we'll send the correct query to instant_tab_->Submit(). If the |
304 // partial text is not a query (|last_match_was_search_| is false), we | 305 // partial text is not a query (|last_match_was_search_| is false), we |
305 // won't Submit(), so no need to worry about that. | 306 // won't Submit(), so no need to worry about that. |
306 last_omnibox_text_ = full_text; | 307 last_omnibox_text_ = full_text; |
307 last_suggestion_ = InstantSuggestion(); | 308 last_suggestion_ = InstantSuggestion(); |
308 } | 309 } |
309 return false; | 310 return false; |
310 } else if (full_text.empty()) { | 311 } else if (full_text.empty()) { |
311 // The user typed a solitary "?". Same as the backspace case above. | 312 // The user typed a solitary "?". Same as the backspace case above. |
312 last_omnibox_text_.clear(); | 313 last_omnibox_text_.clear(); |
313 last_suggestion_ = InstantSuggestion(); | 314 last_suggestion_ = InstantSuggestion(); |
314 if (instant_tab_) | 315 if (instant_tab_) |
315 instant_tab_->Update(string16(), 0, 0, true); | 316 instant_tab_->Update(string16(), 0, 0, true); |
316 else if (search_mode_.is_origin_ntp()) | 317 else if (search_mode_.is_origin_ntp()) |
317 loader_->Update(string16(), 0, 0, true); | 318 overlay_->Update(string16(), 0, 0, true); |
318 else | 319 else |
319 HideLoader(); | 320 HideOverlay(); |
320 return false; | 321 return false; |
321 } | 322 } |
322 } else if (!omnibox_popup_is_open || full_text.empty()) { | 323 } else if (!omnibox_popup_is_open || full_text.empty()) { |
323 // In the non-extended case, hide the preview as long as the user isn't | 324 // In the non-extended case, hide the preview as long as the user isn't |
324 // actively typing a non-empty query. | 325 // actively typing a non-empty query. |
325 HideLoader(); | 326 HideOverlay(); |
326 return false; | 327 return false; |
327 } | 328 } |
328 | 329 |
329 last_omnibox_text_has_inline_autocompletion_ = user_text != full_text; | 330 last_omnibox_text_has_inline_autocompletion_ = user_text != full_text; |
330 | 331 |
331 // If the user continues typing the same query as the suggested text is | 332 // If the user continues typing the same query as the suggested text is |
332 // showing, reuse the suggestion (but only for INSTANT_COMPLETE_NEVER). | 333 // showing, reuse the suggestion (but only for INSTANT_COMPLETE_NEVER). |
333 bool reused_suggestion = false; | 334 bool reused_suggestion = false; |
334 if (last_suggestion_.behavior == INSTANT_COMPLETE_NEVER && | 335 if (last_suggestion_.behavior == INSTANT_COMPLETE_NEVER && |
335 !last_omnibox_text_has_inline_autocompletion_) { | 336 !last_omnibox_text_has_inline_autocompletion_) { |
(...skipping 28 matching lines...) Expand all Loading... |
364 // this, but it's not called in non-extended mode, so fake it. | 365 // this, but it's not called in non-extended mode, so fake it. |
365 if (!extended_enabled_) | 366 if (!extended_enabled_) |
366 search_mode_.mode = chrome::search::Mode::MODE_SEARCH_SUGGESTIONS; | 367 search_mode_.mode = chrome::search::Mode::MODE_SEARCH_SUGGESTIONS; |
367 | 368 |
368 if (instant_tab_) { | 369 if (instant_tab_) { |
369 instant_tab_->Update(user_text, selection_start, selection_end, verbatim); | 370 instant_tab_->Update(user_text, selection_start, selection_end, verbatim); |
370 } else { | 371 } else { |
371 if (first_interaction_time_.is_null()) | 372 if (first_interaction_time_.is_null()) |
372 first_interaction_time_ = base::Time::Now(); | 373 first_interaction_time_ = base::Time::Now(); |
373 allow_preview_to_show_search_suggestions_ = true; | 374 allow_preview_to_show_search_suggestions_ = true; |
374 loader_->Update(extended_enabled_ ? user_text : full_text, | 375 overlay_->Update(extended_enabled_ ? user_text : full_text, |
375 selection_start, selection_end, verbatim); | 376 selection_start, selection_end, verbatim); |
376 } | 377 } |
377 | 378 |
378 content::NotificationService::current()->Notify( | 379 content::NotificationService::current()->Notify( |
379 chrome::NOTIFICATION_INSTANT_CONTROLLER_UPDATED, | 380 chrome::NOTIFICATION_INSTANT_CONTROLLER_UPDATED, |
380 content::Source<InstantController>(this), | 381 content::Source<InstantController>(this), |
381 content::NotificationService::NoDetails()); | 382 content::NotificationService::NoDetails()); |
382 | 383 |
383 // We don't have new suggestions yet, but we can either reuse the existing | 384 // We don't have new suggestions yet, but we can either reuse the existing |
384 // suggestion or reset the existing "gray text". | 385 // suggestion or reset the existing "gray text". |
385 browser_->SetInstantSuggestion(last_suggestion_); | 386 browser_->SetInstantSuggestion(last_suggestion_); |
386 | 387 |
387 // Though we may have handled a URL match above, we return false here, so that | 388 // Though we may have handled a URL match above, we return false here, so that |
388 // omnibox prerendering can kick in. TODO(sreeram): Remove this (and always | 389 // omnibox prerendering can kick in. TODO(sreeram): Remove this (and always |
389 // return true) once we are able to commit URLs as well. | 390 // return true) once we are able to commit URLs as well. |
390 return last_match_was_search_; | 391 return last_match_was_search_; |
391 } | 392 } |
392 | 393 |
| 394 content::WebContents* InstantController::ReleaseNTPContents() { |
| 395 if (!extended_enabled_ || !ntp_) |
| 396 return NULL; |
| 397 |
| 398 content::WebContents* ntp_contents = ntp_->ReleaseContents(); |
| 399 ntp_.reset(); |
| 400 ResetNTP(); |
| 401 return ntp_contents; |
| 402 } |
| 403 |
393 // TODO(tonyg): This method only fires when the omnibox bounds change. It also | 404 // TODO(tonyg): This method only fires when the omnibox bounds change. It also |
394 // needs to fire when the preview bounds change (e.g.: open/close info bar). | 405 // needs to fire when the preview bounds change (e.g.: open/close info bar). |
395 void InstantController::SetPopupBounds(const gfx::Rect& bounds) { | 406 void InstantController::SetPopupBounds(const gfx::Rect& bounds) { |
396 if (!extended_enabled_ && !instant_enabled_) | 407 if (!extended_enabled_ && !instant_enabled_) |
397 return; | 408 return; |
398 | 409 |
399 if (popup_bounds_ == bounds) | 410 if (popup_bounds_ == bounds) |
400 return; | 411 return; |
401 | 412 |
402 popup_bounds_ = bounds; | 413 popup_bounds_ = bounds; |
403 if (popup_bounds_.height() > last_popup_bounds_.height()) { | 414 if (popup_bounds_.height() > last_popup_bounds_.height()) { |
404 update_bounds_timer_.Stop(); | 415 update_bounds_timer_.Stop(); |
405 SendPopupBoundsToPage(); | 416 SendPopupBoundsToPage(); |
406 } else if (!update_bounds_timer_.IsRunning()) { | 417 } else if (!update_bounds_timer_.IsRunning()) { |
407 update_bounds_timer_.Start(FROM_HERE, | 418 update_bounds_timer_.Start(FROM_HERE, |
408 base::TimeDelta::FromMilliseconds(kUpdateBoundsDelayMS), this, | 419 base::TimeDelta::FromMilliseconds(kUpdateBoundsDelayMS), this, |
409 &InstantController::SendPopupBoundsToPage); | 420 &InstantController::SendPopupBoundsToPage); |
410 } | 421 } |
411 } | 422 } |
412 | 423 |
413 void InstantController::SetMarginSize(int start, int end) { | 424 void InstantController::SetMarginSize(int start, int end) { |
414 if (!extended_enabled_ || (start_margin_ == start && end_margin_ == end)) | 425 if (!extended_enabled_ || (start_margin_ == start && end_margin_ == end)) |
415 return; | 426 return; |
416 | 427 |
417 start_margin_ = start; | 428 start_margin_ = start; |
418 end_margin_ = end; | 429 end_margin_ = end; |
419 if (loader_) | 430 if (overlay_) |
420 loader_->SetMarginSize(start_margin_, end_margin_); | 431 overlay_->SetMarginSize(start_margin_, end_margin_); |
| 432 if (ntp_) |
| 433 ntp_->SetMarginSize(start_margin_, end_margin_); |
421 if (instant_tab_) | 434 if (instant_tab_) |
422 instant_tab_->SetMarginSize(start_margin_, end_margin_); | 435 instant_tab_->SetMarginSize(start_margin_, end_margin_); |
423 } | 436 } |
424 | 437 |
425 void InstantController::HandleAutocompleteResults( | 438 void InstantController::HandleAutocompleteResults( |
426 const std::vector<AutocompleteProvider*>& providers) { | 439 const std::vector<AutocompleteProvider*>& providers) { |
427 if (!extended_enabled_) | 440 if (!extended_enabled_) |
428 return; | 441 return; |
429 | 442 |
430 if (!instant_tab_ && !loader_) | 443 if (!instant_tab_ && !overlay_) |
431 return; | 444 return; |
432 | 445 |
433 DVLOG(1) << "AutocompleteResults:"; | 446 DVLOG(1) << "AutocompleteResults:"; |
434 std::vector<InstantAutocompleteResult> results; | 447 std::vector<InstantAutocompleteResult> results; |
435 for (ACProviders::const_iterator provider = providers.begin(); | 448 for (ACProviders::const_iterator provider = providers.begin(); |
436 provider != providers.end(); ++provider) { | 449 provider != providers.end(); ++provider) { |
437 for (ACMatches::const_iterator match = (*provider)->matches().begin(); | 450 for (ACMatches::const_iterator match = (*provider)->matches().begin(); |
438 match != (*provider)->matches().end(); ++match) { | 451 match != (*provider)->matches().end(); ++match) { |
439 InstantAutocompleteResult result; | 452 InstantAutocompleteResult result; |
440 result.provider = UTF8ToUTF16((*provider)->GetName()); | 453 result.provider = UTF8ToUTF16((*provider)->GetName()); |
441 result.type = UTF8ToUTF16(AutocompleteMatch::TypeToString(match->type)); | 454 result.type = UTF8ToUTF16(AutocompleteMatch::TypeToString(match->type)); |
442 result.description = match->description; | 455 result.description = match->description; |
443 result.destination_url = UTF8ToUTF16(match->destination_url.spec()); | 456 result.destination_url = UTF8ToUTF16(match->destination_url.spec()); |
444 result.transition = match->transition; | 457 result.transition = match->transition; |
445 result.relevance = match->relevance; | 458 result.relevance = match->relevance; |
446 DVLOG(1) << " " << result.relevance << " " << result.type << " " | 459 DVLOG(1) << " " << result.relevance << " " << result.type << " " |
447 << result.provider << " " << result.destination_url << " '" | 460 << result.provider << " " << result.destination_url << " '" |
448 << result.description << "' " << result.transition; | 461 << result.description << "' " << result.transition; |
449 results.push_back(result); | 462 results.push_back(result); |
450 } | 463 } |
451 } | 464 } |
452 | 465 |
453 if (instant_tab_) | 466 if (instant_tab_) |
454 instant_tab_->SendAutocompleteResults(results); | 467 instant_tab_->SendAutocompleteResults(results); |
455 else | 468 else |
456 loader_->SendAutocompleteResults(results); | 469 overlay_->SendAutocompleteResults(results); |
457 } | 470 } |
458 | 471 |
459 bool InstantController::OnUpOrDownKeyPressed(int count) { | 472 bool InstantController::OnUpOrDownKeyPressed(int count) { |
460 if (!extended_enabled_) | 473 if (!extended_enabled_) |
461 return false; | 474 return false; |
462 | 475 |
463 if (!instant_tab_ && !loader_) | 476 if (!instant_tab_ && !overlay_) |
464 return false; | 477 return false; |
465 | 478 |
466 if (instant_tab_) | 479 if (instant_tab_) |
467 instant_tab_->UpOrDownKeyPressed(count); | 480 instant_tab_->UpOrDownKeyPressed(count); |
468 else | 481 else |
469 loader_->UpOrDownKeyPressed(count); | 482 overlay_->UpOrDownKeyPressed(count); |
470 | 483 |
471 return true; | 484 return true; |
472 } | 485 } |
473 | 486 |
474 content::WebContents* InstantController::GetPreviewContents() const { | 487 content::WebContents* InstantController::GetPreviewContents() const { |
475 return loader_ ? loader_->contents() : NULL; | 488 return overlay_ ? overlay_->contents() : NULL; |
476 } | 489 } |
477 | 490 |
478 bool InstantController::IsPreviewingSearchResults() const { | 491 bool InstantController::IsPreviewingSearchResults() const { |
479 return model_.mode().is_search_suggestions() && last_match_was_search_ && | 492 return model_.mode().is_search_suggestions() && last_match_was_search_ && |
480 IsFullHeight(model_); | 493 IsFullHeight(model_); |
481 } | 494 } |
482 | 495 |
483 bool InstantController::CommitIfPossible(InstantCommitType type) { | 496 bool InstantController::CommitIfPossible(InstantCommitType type) { |
484 if (!extended_enabled_ && !instant_enabled_) | 497 if (!extended_enabled_ && !instant_enabled_) |
485 return false; | 498 return false; |
(...skipping 11 matching lines...) Expand all Loading... |
497 return true; | 510 return true; |
498 } | 511 } |
499 return false; | 512 return false; |
500 } | 513 } |
501 | 514 |
502 if (!IsPreviewingSearchResults() && type != INSTANT_COMMIT_NAVIGATED) | 515 if (!IsPreviewingSearchResults() && type != INSTANT_COMMIT_NAVIGATED) |
503 return false; | 516 return false; |
504 | 517 |
505 // There may re-entrance here, from the call to browser_->CommitInstant below, | 518 // There may re-entrance here, from the call to browser_->CommitInstant below, |
506 // which can cause a TabDeactivated notification which gets back here. | 519 // which can cause a TabDeactivated notification which gets back here. |
507 // In this case, loader_->ReleaseContents() was called already. | 520 // In this case, overlay_->ReleaseContents() was called already. |
508 if (!GetPreviewContents()) | 521 if (!GetPreviewContents()) |
509 return false; | 522 return false; |
510 | 523 |
511 // Never commit the local omnibox. | 524 // Never commit the local omnibox. |
512 if (loader_->IsUsingLocalPreview()) | 525 if (overlay_->IsUsingLocalPreview()) |
513 return false; | 526 return false; |
514 | 527 |
515 if (type == INSTANT_COMMIT_FOCUS_LOST) | 528 if (type == INSTANT_COMMIT_FOCUS_LOST) |
516 loader_->Cancel(last_omnibox_text_); | 529 overlay_->Cancel(last_omnibox_text_); |
517 else if (type != INSTANT_COMMIT_NAVIGATED && | 530 else if (type != INSTANT_COMMIT_NAVIGATED && |
518 type != INSTANT_COMMIT_CLICKED_QUERY_SUGGESTION) | 531 type != INSTANT_COMMIT_CLICKED_QUERY_SUGGESTION) |
519 loader_->Submit(last_omnibox_text_); | 532 overlay_->Submit(last_omnibox_text_); |
520 | 533 |
521 content::WebContents* preview = loader_->ReleaseContents(); | 534 content::WebContents* preview = overlay_->ReleaseContents(); |
522 | 535 |
523 if (extended_enabled_) { | 536 if (extended_enabled_) { |
524 // Consider what's happening: | 537 // Consider what's happening: |
525 // 1. The user has typed a query in the omnibox and committed it (either | 538 // 1. The user has typed a query in the omnibox and committed it (either |
526 // by pressing Enter or clicking on the preview). | 539 // by pressing Enter or clicking on the preview). |
527 // 2. We commit the preview to the tab strip, and tell the page. | 540 // 2. We commit the preview to the tab strip, and tell the page. |
528 // 3. The page will update the URL hash fragment with the query terms. | 541 // 3. The page will update the URL hash fragment with the query terms. |
529 // After steps 1 and 3, the omnibox will show the query terms. However, if | 542 // After steps 1 and 3, the omnibox will show the query terms. However, if |
530 // the URL we are committing at step 2 doesn't already have query terms, it | 543 // the URL we are committing at step 2 doesn't already have query terms, it |
531 // will flash for a brief moment as a plain URL. So, avoid that flicker by | 544 // will flash for a brief moment as a plain URL. So, avoid that flicker by |
(...skipping 17 matching lines...) Expand all Loading... |
549 net::EscapeQueryParamValue(query, true))); | 562 net::EscapeQueryParamValue(query, true))); |
550 chrome::search::SearchTabHelper::FromWebContents(preview)-> | 563 chrome::search::SearchTabHelper::FromWebContents(preview)-> |
551 NavigationEntryUpdated(); | 564 NavigationEntryUpdated(); |
552 } | 565 } |
553 } | 566 } |
554 | 567 |
555 // If the preview page has navigated since the last Update(), we need to add | 568 // If the preview page has navigated since the last Update(), we need to add |
556 // the navigation to history ourselves. Else, the page will navigate after | 569 // the navigation to history ourselves. Else, the page will navigate after |
557 // commit, and it will be added to history in the usual manner. | 570 // commit, and it will be added to history in the usual manner. |
558 const history::HistoryAddPageArgs& last_navigation = | 571 const history::HistoryAddPageArgs& last_navigation = |
559 loader_->last_navigation(); | 572 overlay_->last_navigation(); |
560 if (!last_navigation.url.is_empty()) { | 573 if (!last_navigation.url.is_empty()) { |
561 content::NavigationEntry* entry = preview->GetController().GetActiveEntry(); | 574 content::NavigationEntry* entry = preview->GetController().GetActiveEntry(); |
562 | 575 |
563 // The last navigation should be the same as the active entry if the loader | 576 // The last navigation should be the same as the active entry if the overlay |
564 // is in search mode. During navigation, the active entry could have | 577 // is in search mode. During navigation, the active entry could have |
565 // changed since DidCommitProvisionalLoadForFrame is called after the entry | 578 // changed since DidCommitProvisionalLoadForFrame is called after the entry |
566 // is changed. | 579 // is changed. |
567 // TODO(shishir): Should we commit the last navigation for | 580 // TODO(shishir): Should we commit the last navigation for |
568 // INSTANT_COMMIT_NAVIGATED. | 581 // INSTANT_COMMIT_NAVIGATED. |
569 DCHECK(type == INSTANT_COMMIT_NAVIGATED || | 582 DCHECK(type == INSTANT_COMMIT_NAVIGATED || |
570 last_navigation.url == entry->GetURL()); | 583 last_navigation.url == entry->GetURL()); |
571 | 584 |
572 // Add the page to history. | 585 // Add the page to history. |
573 HistoryTabHelper* history_tab_helper = | 586 HistoryTabHelper* history_tab_helper = |
(...skipping 25 matching lines...) Expand all Loading... |
599 } | 612 } |
600 | 613 |
601 // Browser takes ownership of the preview. | 614 // Browser takes ownership of the preview. |
602 browser_->CommitInstant(preview, type == INSTANT_COMMIT_PRESSED_ALT_ENTER); | 615 browser_->CommitInstant(preview, type == INSTANT_COMMIT_PRESSED_ALT_ENTER); |
603 | 616 |
604 content::NotificationService::current()->Notify( | 617 content::NotificationService::current()->Notify( |
605 chrome::NOTIFICATION_INSTANT_COMMITTED, | 618 chrome::NOTIFICATION_INSTANT_COMMITTED, |
606 content::Source<content::WebContents>(preview), | 619 content::Source<content::WebContents>(preview), |
607 content::NotificationService::NoDetails()); | 620 content::NotificationService::NoDetails()); |
608 | 621 |
609 // Hide explicitly. See comments in HideLoader() for why. | 622 // Hide explicitly. See comments in HideOverlay() for why. |
610 model_.SetPreviewState(chrome::search::Mode(), 0, INSTANT_SIZE_PERCENT); | 623 model_.SetPreviewState(chrome::search::Mode(), 0, INSTANT_SIZE_PERCENT); |
611 | 624 |
612 // Delay deletion as we could've gotten here from an InstantLoader method. | 625 // Delay deletion as we could've gotten here from an InstantOverlay method. |
613 MessageLoop::current()->DeleteSoon(FROM_HERE, loader_.release()); | 626 MessageLoop::current()->DeleteSoon(FROM_HERE, overlay_.release()); |
614 | 627 |
615 // Try to create another loader immediately so that it is ready for the next | 628 // Try to create another overlay immediately so that it is ready for the next |
616 // user interaction. | 629 // user interaction. |
617 CreateDefaultLoader(); | 630 CreateDefaultOverlay(); |
618 | 631 |
619 return true; | 632 return true; |
620 } | 633 } |
621 | 634 |
622 void InstantController::OmniboxFocusChanged( | 635 void InstantController::OmniboxFocusChanged( |
623 OmniboxFocusState state, | 636 OmniboxFocusState state, |
624 OmniboxFocusChangeReason reason, | 637 OmniboxFocusChangeReason reason, |
625 gfx::NativeView view_gaining_focus) { | 638 gfx::NativeView view_gaining_focus) { |
626 DVLOG(1) << "OmniboxFocusChanged: " << omnibox_focus_state_ << " to " | 639 DVLOG(1) << "OmniboxFocusChanged: " << omnibox_focus_state_ << " to " |
627 << state << " for reason " << reason; | 640 << state << " for reason " << reason; |
628 | 641 |
629 OmniboxFocusState old_focus_state = omnibox_focus_state_; | 642 OmniboxFocusState old_focus_state = omnibox_focus_state_; |
630 omnibox_focus_state_ = state; | 643 omnibox_focus_state_ = state; |
631 if (!extended_enabled_ && !instant_enabled_) | 644 if (!extended_enabled_ && !instant_enabled_) |
632 return; | 645 return; |
633 | 646 |
634 // Tell the page if the key capture mode changed unless the focus state | 647 // Tell the page if the key capture mode changed unless the focus state |
635 // changed because of TYPING. This is because in that case, the browser hasn't | 648 // changed because of TYPING. This is because in that case, the browser hasn't |
636 // really stopped capturing key strokes. | 649 // really stopped capturing key strokes. |
637 // | 650 // |
638 // (More practically, if we don't do this check, the page would receive | 651 // (More practically, if we don't do this check, the page would receive |
639 // onkeycapturechange before the corresponding onchange, and the page would | 652 // onkeycapturechange before the corresponding onchange, and the page would |
640 // have no way of telling whether the keycapturechange happened because of | 653 // have no way of telling whether the keycapturechange happened because of |
641 // some actual user action or just because they started typing.) | 654 // some actual user action or just because they started typing.) |
642 if (extended_enabled_ && GetPreviewContents() && | 655 if (extended_enabled_ && GetPreviewContents() && |
643 reason != OMNIBOX_FOCUS_CHANGE_TYPING) | 656 reason != OMNIBOX_FOCUS_CHANGE_TYPING) { |
644 loader_->KeyCaptureChanged(omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE); | 657 const bool is_key_capture_enabled = |
| 658 omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE; |
| 659 if (overlay_) |
| 660 overlay_->KeyCaptureChanged(is_key_capture_enabled); |
| 661 if (instant_tab_) |
| 662 instant_tab_->KeyCaptureChanged(is_key_capture_enabled); |
| 663 } |
645 | 664 |
646 // If focus went from outside the omnibox to the omnibox, preload the default | 665 // If focus went from outside the omnibox to the omnibox, preload the default |
647 // search engine, in anticipation of the user typing a query. If the reverse | 666 // search engine, in anticipation of the user typing a query. If the reverse |
648 // happened, commit or discard the preview. | 667 // happened, commit or discard the preview. |
649 if (state != OMNIBOX_FOCUS_NONE && old_focus_state == OMNIBOX_FOCUS_NONE) | 668 if (state != OMNIBOX_FOCUS_NONE && old_focus_state == OMNIBOX_FOCUS_NONE) |
650 CreateDefaultLoader(); | 669 CreateDefaultOverlay(); |
651 else if (state == OMNIBOX_FOCUS_NONE && old_focus_state != OMNIBOX_FOCUS_NONE) | 670 else if (state == OMNIBOX_FOCUS_NONE && old_focus_state != OMNIBOX_FOCUS_NONE) |
652 OmniboxLostFocus(view_gaining_focus); | 671 OmniboxLostFocus(view_gaining_focus); |
653 } | 672 } |
654 | 673 |
655 void InstantController::SearchModeChanged( | 674 void InstantController::SearchModeChanged( |
656 const chrome::search::Mode& old_mode, | 675 const chrome::search::Mode& old_mode, |
657 const chrome::search::Mode& new_mode) { | 676 const chrome::search::Mode& new_mode) { |
658 if (!extended_enabled_) | 677 if (!extended_enabled_) |
659 return; | 678 return; |
660 | 679 |
661 DVLOG(1) << "SearchModeChanged: [origin:mode] " << old_mode.origin << ":" | 680 DVLOG(1) << "SearchModeChanged: [origin:mode] " << old_mode.origin << ":" |
662 << old_mode.mode << " to " << new_mode.origin << ":" | 681 << old_mode.mode << " to " << new_mode.origin << ":" |
663 << new_mode.mode; | 682 << new_mode.mode; |
664 | 683 |
665 search_mode_ = new_mode; | 684 search_mode_ = new_mode; |
666 if (!new_mode.is_search_suggestions()) | 685 if (!new_mode.is_search_suggestions()) |
667 HideLoader(); | 686 HideOverlay(); |
668 | 687 |
669 if (loader_) | 688 if (overlay_) |
670 loader_->SearchModeChanged(new_mode); | 689 overlay_->SearchModeChanged(new_mode); |
671 | 690 |
672 ResetInstantTab(); | 691 ResetInstantTab(); |
673 } | 692 } |
674 | 693 |
675 void InstantController::ActiveTabChanged() { | 694 void InstantController::ActiveTabChanged() { |
676 if (!extended_enabled_ && !instant_enabled_) | 695 if (!extended_enabled_ && !instant_enabled_) |
677 return; | 696 return; |
678 | 697 |
679 DVLOG(1) << "ActiveTabChanged"; | 698 DVLOG(1) << "ActiveTabChanged"; |
680 | 699 |
681 // When switching tabs, always hide the preview, except if it's showing NTP | 700 // When switching tabs, always hide the preview. |
682 // content, and the new tab is also an NTP. | 701 HideOverlay(); |
683 if (!search_mode_.is_ntp() || !model_.mode().is_ntp()) | |
684 HideLoader(); | |
685 | 702 |
686 if (extended_enabled_) | 703 if (extended_enabled_) |
687 ResetInstantTab(); | 704 ResetInstantTab(); |
688 } | 705 } |
689 | 706 |
690 void InstantController::TabDeactivated(content::WebContents* contents) { | 707 void InstantController::TabDeactivated(content::WebContents* contents) { |
691 DVLOG(1) << "TabDeactivated"; | 708 DVLOG(1) << "TabDeactivated"; |
692 if (extended_enabled_ && !contents->IsBeingDestroyed()) | 709 if (extended_enabled_ && !contents->IsBeingDestroyed()) |
693 CommitIfPossible(INSTANT_COMMIT_FOCUS_LOST); | 710 CommitIfPossible(INSTANT_COMMIT_FOCUS_LOST); |
694 } | 711 } |
695 | 712 |
696 void InstantController::SetInstantEnabled(bool instant_enabled) { | 713 void InstantController::SetInstantEnabled(bool instant_enabled) { |
697 DVLOG(1) << "SetInstantEnabled: " << instant_enabled; | 714 DVLOG(1) << "SetInstantEnabled: " << instant_enabled; |
698 instant_enabled_ = instant_enabled; | 715 instant_enabled_ = instant_enabled; |
699 HideInternal(); | 716 HideInternal(); |
700 loader_.reset(); | 717 overlay_.reset(); |
701 if (extended_enabled_ || instant_enabled_) | 718 if (extended_enabled_ || instant_enabled_) |
702 CreateDefaultLoader(); | 719 CreateDefaultOverlay(); |
| 720 if (extended_enabled_) |
| 721 ResetNTP(); |
703 if (instant_tab_) | 722 if (instant_tab_) |
704 instant_tab_->SetDisplayInstantResults(instant_enabled_); | 723 instant_tab_->SetDisplayInstantResults(instant_enabled_); |
705 } | 724 } |
706 | 725 |
707 void InstantController::ThemeChanged(const ThemeBackgroundInfo& theme_info) { | 726 void InstantController::ThemeChanged(const ThemeBackgroundInfo& theme_info) { |
708 if (!extended_enabled_) | 727 if (!extended_enabled_) |
709 return; | 728 return; |
710 | 729 |
711 if (loader_) | 730 if (overlay_) |
712 loader_->SendThemeBackgroundInfo(theme_info); | 731 overlay_->SendThemeBackgroundInfo(theme_info); |
| 732 if (ntp_) |
| 733 ntp_->SendThemeBackgroundInfo(theme_info); |
713 } | 734 } |
714 | 735 |
715 void InstantController::ThemeAreaHeightChanged(int height) { | 736 void InstantController::ThemeAreaHeightChanged(int height) { |
716 if (!extended_enabled_) | 737 if (!extended_enabled_) |
717 return; | 738 return; |
718 | 739 |
719 if (loader_) | 740 if (overlay_) |
720 loader_->SendThemeAreaHeight(height); | 741 overlay_->SendThemeAreaHeight(height); |
| 742 if (ntp_) |
| 743 ntp_->SendThemeAreaHeight(height); |
721 } | 744 } |
722 | 745 |
723 void InstantController::SetSuggestions( | 746 void InstantController::SetSuggestions( |
724 const content::WebContents* contents, | 747 const content::WebContents* contents, |
725 const std::vector<InstantSuggestion>& suggestions) { | 748 const std::vector<InstantSuggestion>& suggestions) { |
726 DVLOG(1) << "SetSuggestions"; | 749 DVLOG(1) << "SetSuggestions"; |
727 | 750 |
728 // Ignore if the message is from an unexpected source. | 751 // Ignore if the message is from an unexpected source. |
729 if (instant_tab_) { | 752 if (instant_tab_) { |
730 if (instant_tab_->contents() != contents) | 753 if (instant_tab_->contents() != contents) |
731 return; | 754 return; |
732 } else if (!loader_ || loader_->contents() != contents || | 755 } else if (!overlay_ || overlay_->contents() != contents || |
733 !allow_preview_to_show_search_suggestions_) { | 756 !allow_preview_to_show_search_suggestions_) { |
734 return; | 757 return; |
735 } | 758 } |
736 | 759 |
737 InstantSuggestion suggestion; | 760 InstantSuggestion suggestion; |
738 if (!suggestions.empty()) | 761 if (!suggestions.empty()) |
739 suggestion = suggestions[0]; | 762 suggestion = suggestions[0]; |
740 | 763 |
741 if (instant_tab_ && search_mode_.is_search_results() && | 764 if (instant_tab_ && search_mode_.is_search_results() && |
742 suggestion.behavior == INSTANT_COMPLETE_REPLACE) { | 765 suggestion.behavior == INSTANT_COMPLETE_REPLACE) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
802 last_suggestion_ = suggestion; | 825 last_suggestion_ = suggestion; |
803 DVLOG(1) << "SetInstantSuggestion: text='" << suggestion.text << "'" | 826 DVLOG(1) << "SetInstantSuggestion: text='" << suggestion.text << "'" |
804 << " behavior=" << suggestion.behavior << " type=" | 827 << " behavior=" << suggestion.behavior << " type=" |
805 << suggestion.type; | 828 << suggestion.type; |
806 browser_->SetInstantSuggestion(suggestion); | 829 browser_->SetInstantSuggestion(suggestion); |
807 } else { | 830 } else { |
808 last_suggestion_ = InstantSuggestion(); | 831 last_suggestion_ = InstantSuggestion(); |
809 } | 832 } |
810 } | 833 } |
811 | 834 |
812 // Extended mode pages will call ShowLoader() when they are ready. | 835 // Extended mode pages will call ShowOverlay() when they are ready. |
813 if (!extended_enabled_) | 836 if (!extended_enabled_) |
814 ShowLoader(INSTANT_SHOWN_QUERY_SUGGESTIONS, 100, INSTANT_SIZE_PERCENT); | 837 ShowOverlay(INSTANT_SHOWN_QUERY_SUGGESTIONS, 100, INSTANT_SIZE_PERCENT); |
815 } | 838 } |
816 | 839 |
817 void InstantController::InstantSupportDetermined( | 840 void InstantController::InstantSupportDetermined( |
818 const content::WebContents* contents, | 841 const content::WebContents* contents, |
819 bool supports_instant) { | 842 bool supports_instant) { |
820 if (instant_tab_ && instant_tab_->contents() == contents) { | 843 if (instant_tab_ && instant_tab_->contents() == contents) { |
821 if (!supports_instant) | 844 if (!supports_instant) |
822 MessageLoop::current()->DeleteSoon(FROM_HERE, instant_tab_.release()); | 845 MessageLoop::current()->DeleteSoon(FROM_HERE, instant_tab_.release()); |
823 return; | 846 return; |
824 } | 847 } |
825 | 848 |
826 if (loader_ && loader_->contents() == contents) { | 849 if (ntp_ && ntp_->contents() == contents) { |
827 if (supports_instant) { | 850 if (supports_instant) { |
828 if (blacklisted_urls_.erase(loader_->instant_url())) { | 851 if (blacklisted_urls_.erase(ntp_->instant_url())) { |
829 RecordEventHistogram( | 852 RecordEventHistogram( |
830 INSTANT_CONTROLLER_EVENT_URL_REMOVED_FROM_BLACKLIST); | 853 INSTANT_CONTROLLER_EVENT_URL_REMOVED_FROM_BLACKLIST); |
831 } | 854 } |
832 } else { | 855 } else { |
833 ++blacklisted_urls_[loader_->instant_url()]; | 856 ++blacklisted_urls_[ntp_->instant_url()]; |
| 857 RecordEventHistogram(INSTANT_CONTROLLER_EVENT_URL_ADDED_TO_BLACKLIST); |
| 858 delete ntp_->ReleaseContents(); |
| 859 MessageLoop::current()->DeleteSoon(FROM_HERE, ntp_.release()); |
| 860 ResetNTP(); |
| 861 } |
| 862 } |
| 863 |
| 864 if (overlay_ && overlay_->contents() == contents) { |
| 865 if (supports_instant) { |
| 866 if (blacklisted_urls_.erase(overlay_->instant_url())) { |
| 867 RecordEventHistogram( |
| 868 INSTANT_CONTROLLER_EVENT_URL_REMOVED_FROM_BLACKLIST); |
| 869 } |
| 870 } else { |
| 871 ++blacklisted_urls_[overlay_->instant_url()]; |
834 RecordEventHistogram(INSTANT_CONTROLLER_EVENT_URL_ADDED_TO_BLACKLIST); | 872 RecordEventHistogram(INSTANT_CONTROLLER_EVENT_URL_ADDED_TO_BLACKLIST); |
835 HideInternal(); | 873 HideInternal(); |
836 delete loader_->ReleaseContents(); | 874 delete overlay_->ReleaseContents(); |
837 MessageLoop::current()->DeleteSoon(FROM_HERE, loader_.release()); | 875 MessageLoop::current()->DeleteSoon(FROM_HERE, overlay_.release()); |
838 CreateDefaultLoader(); | 876 CreateDefaultOverlay(); |
839 } | 877 } |
840 content::NotificationService::current()->Notify( | 878 content::NotificationService::current()->Notify( |
841 chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED, | 879 chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED, |
842 content::Source<InstantController>(this), | 880 content::Source<InstantController>(this), |
843 content::NotificationService::NoDetails()); | 881 content::NotificationService::NoDetails()); |
844 } | 882 } |
845 } | 883 } |
846 | 884 |
847 void InstantController::ShowInstantPreview(InstantShownReason reason, | 885 void InstantController::ShowInstantPreview(InstantShownReason reason, |
848 int height, | 886 int height, |
849 InstantSizeUnits units) { | 887 InstantSizeUnits units) { |
850 if (extended_enabled_) | 888 if (extended_enabled_) |
851 ShowLoader(reason, height, units); | 889 ShowOverlay(reason, height, units); |
852 } | 890 } |
853 | 891 |
854 void InstantController::StartCapturingKeyStrokes() { | 892 void InstantController::StartCapturingKeyStrokes( |
855 // Ignore unless the loader is active and on the NTP. | 893 content::WebContents* contents) { |
856 if (extended_enabled_ && !instant_tab_ && model_.mode().is_ntp()) | 894 if (!extended_enabled_) |
| 895 return; |
| 896 |
| 897 // Only honor the call if it comes from an active InstantTab or from an |
| 898 // InstantOverlay that is being shown. |
| 899 if ((instant_tab_ && instant_tab_->contents() == contents) || |
| 900 (overlay_ && overlay_->contents() == contents && |
| 901 !model_.mode().is_default())) { |
857 browser_->FocusOmniboxInvisibly(); | 902 browser_->FocusOmniboxInvisibly(); |
| 903 } |
858 } | 904 } |
859 | 905 |
860 void InstantController::StopCapturingKeyStrokes() { | 906 void InstantController::StopCapturingKeyStrokes( |
861 // Ignore unless the loader is active and on the NTP, and the omnibox has | 907 content::WebContents* contents) { |
862 // invisible focus. | 908 // Nothing to do if omnibox doesn't have invisible focus. |
863 if (extended_enabled_ && !instant_tab_ && model_.mode().is_ntp() && | 909 if (!extended_enabled_ || omnibox_focus_state_ != OMNIBOX_FOCUS_INVISIBLE) |
864 omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE) | 910 return; |
865 loader_->contents()->Focus(); | 911 |
| 912 // Only honor the call if it comes from an active InstantTab or from an |
| 913 // InstantOverlay that is being shown. |
| 914 if ((instant_tab_ && instant_tab_->contents() == contents) || |
| 915 (overlay_ && overlay_->contents() == contents && |
| 916 !model_.mode().is_default())) { |
| 917 contents->Focus(); |
| 918 } |
866 } | 919 } |
867 | 920 |
868 void InstantController::SwappedWebContents() { | 921 void InstantController::SwappedOverlayWebContents() { |
869 model_.SetPreviewContents(GetPreviewContents()); | 922 model_.SetPreviewContents(GetPreviewContents()); |
870 } | 923 } |
871 | 924 |
872 void InstantController::InstantLoaderContentsFocused() { | 925 void InstantController::InstantOverlayContentsFocused() { |
873 #if defined(USE_AURA) | 926 #if defined(USE_AURA) |
874 // On aura the omnibox only receives a focus lost if we initiate the focus | 927 // On aura the omnibox only receives a focus lost if we initiate the focus |
875 // change. This does that. | 928 // change. This does that. |
876 if (!model_.mode().is_default()) | 929 if (!model_.mode().is_default()) |
877 browser_->InstantPreviewFocused(); | 930 browser_->InstantPreviewFocused(); |
878 #endif | 931 #endif |
879 } | 932 } |
880 | 933 |
881 void InstantController::InstantLoaderRenderViewGone() { | 934 void InstantController::InstantOverlayRenderViewGone() { |
882 ++blacklisted_urls_[loader_->instant_url()]; | 935 ++blacklisted_urls_[overlay_->instant_url()]; |
883 HideInternal(); | 936 HideInternal(); |
884 delete loader_->ReleaseContents(); | 937 delete overlay_->ReleaseContents(); |
885 // Delay deletion as we have gotten here from an InstantLoader method. | 938 // Delay deletion as we have gotten here from an InstantOverlay method. |
886 MessageLoop::current()->DeleteSoon(FROM_HERE, loader_.release()); | 939 MessageLoop::current()->DeleteSoon(FROM_HERE, overlay_.release()); |
887 CreateDefaultLoader(); | 940 CreateDefaultOverlay(); |
888 } | 941 } |
889 | 942 |
890 void InstantController::InstantLoaderAboutToNavigateMainFrame(const GURL& url) { | 943 void InstantController::InstantNTPRenderViewGone() { |
| 944 ++blacklisted_urls_[ntp_->instant_url()]; |
| 945 delete ntp_->ReleaseContents(); |
| 946 // Delay deletion as we have gotten here from an InstantNTP method. |
| 947 MessageLoop::current()->DeleteSoon(FROM_HERE, ntp_.release()); |
| 948 ResetNTP(); |
| 949 } |
| 950 |
| 951 void InstantController::InstantOverlayAboutToNavigateMainFrame( |
| 952 const GURL& url) { |
891 // If the page does not yet support instant, we allow redirects and other | 953 // If the page does not yet support instant, we allow redirects and other |
892 // navigations to go through since the instant URL can redirect - e.g. to | 954 // navigations to go through since the instant URL can redirect - e.g. to |
893 // country specific pages. | 955 // country specific pages. |
894 if (!loader_->supports_instant()) | 956 if (!overlay_->supports_instant()) |
895 return; | 957 return; |
896 | 958 |
897 GURL instant_url(loader_->instant_url()); | 959 GURL instant_url(overlay_->instant_url()); |
898 | 960 |
899 // If we are navigating to the instant URL, do nothing. | 961 // If we are navigating to the instant URL, do nothing. |
900 if (url == instant_url) | 962 if (url == instant_url) |
901 return; | 963 return; |
902 | 964 |
903 // Commit the navigation if either: | 965 // Commit the navigation if either: |
904 // - The page is in NTP mode (so it could only navigate on a user click) or | 966 // - 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 | 967 // - 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 | 968 // 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 | 969 // page when it is showing search results to change the query parameters |
908 // and fragments of the URL without it navigating. | 970 // and fragments of the URL without it navigating. |
909 if (model_.mode().is_ntp() || | 971 if (model_.mode().is_ntp() || |
910 (url.host() != instant_url.host() || url.path() != instant_url.path())) { | 972 (url.host() != instant_url.host() || url.path() != instant_url.path())) { |
911 CommitIfPossible(INSTANT_COMMIT_NAVIGATED); | 973 CommitIfPossible(INSTANT_COMMIT_NAVIGATED); |
912 } | 974 } |
913 } | 975 } |
914 | 976 |
915 void InstantController::OmniboxLostFocus(gfx::NativeView view_gaining_focus) { | 977 void InstantController::OmniboxLostFocus(gfx::NativeView view_gaining_focus) { |
916 // If the preview is showing custom NTP content, don't hide it, commit it | 978 // 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. | 979 // (no matter where the user clicked) or try to recreate it. |
918 if (model_.mode().is_ntp()) | 980 if (model_.mode().is_ntp()) |
919 return; | 981 return; |
920 | 982 |
921 // If the preview is not showing at all, recreate it if it's stale. | 983 // If the preview is not showing at all, recreate it if it's stale. |
922 if (model_.mode().is_default()) { | 984 if (model_.mode().is_default()) { |
923 OnStaleLoader(); | 985 OnStaleOverlay(); |
924 return; | 986 return; |
925 } | 987 } |
926 | 988 |
927 // The preview is showing search suggestions. If GetPreviewContents() is NULL, | 989 // The preview is showing search suggestions. If GetPreviewContents() is NULL, |
928 // we are in the commit path. Don't do anything. | 990 // we are in the commit path. Don't do anything. |
929 if (!GetPreviewContents()) | 991 if (!GetPreviewContents()) |
930 return; | 992 return; |
931 | 993 |
932 #if defined(OS_MACOSX) | 994 #if defined(OS_MACOSX) |
933 // TODO(sreeram): See if Mac really needs this special treatment. | 995 // TODO(sreeram): See if Mac really needs this special treatment. |
934 if (!loader_->is_pointer_down_from_activate()) | 996 if (!overlay_->is_pointer_down_from_activate()) |
935 HideLoader(); | 997 HideOverlay(); |
936 #else | 998 #else |
937 if (IsViewInContents(GetViewGainingFocus(view_gaining_focus), | 999 if (IsViewInContents(GetViewGainingFocus(view_gaining_focus), |
938 loader_->contents())) | 1000 overlay_->contents())) |
939 CommitIfPossible(INSTANT_COMMIT_FOCUS_LOST); | 1001 CommitIfPossible(INSTANT_COMMIT_FOCUS_LOST); |
940 else | 1002 else |
941 HideLoader(); | 1003 HideOverlay(); |
942 #endif | 1004 #endif |
943 } | 1005 } |
944 | 1006 |
945 void InstantController::NavigateToURL(const GURL& url, | 1007 void InstantController::NavigateToURL(const GURL& url, |
946 content::PageTransition transition) { | 1008 content::PageTransition transition) { |
947 if (!extended_enabled_) | 1009 if (!extended_enabled_) |
948 return; | 1010 return; |
949 if (loader_) | 1011 if (overlay_) |
950 HideLoader(); | 1012 HideOverlay(); |
951 browser_->OpenURLInCurrentTab(url, transition); | 1013 browser_->OpenURLInCurrentTab(url, transition); |
952 } | 1014 } |
953 | 1015 |
954 bool InstantController::ResetLoader(const TemplateURL* template_url, | 1016 bool InstantController::ResetOverlay(const TemplateURL* template_url, |
955 const content::WebContents* active_tab, | 1017 const content::WebContents* active_tab, |
956 bool fallback_to_local) { | 1018 bool fallback_to_local) { |
957 std::string instant_url; | 1019 std::string instant_url; |
958 if (!GetInstantURL(template_url, &instant_url)) { | 1020 if (!GetInstantURL(template_url, &instant_url)) { |
959 if (!fallback_to_local || !extended_enabled_) | 1021 if (!fallback_to_local || !extended_enabled_) |
960 return false; | 1022 return false; |
961 | 1023 |
962 // If we are in extended mode, fallback to the local popup. | 1024 // If we are in extended mode, fallback to the local popup. |
963 instant_url = kLocalOmniboxPopupURL; | 1025 instant_url = kLocalOmniboxPopupURL; |
964 } | 1026 } |
965 | 1027 |
966 if (loader_ && loader_->instant_url() == instant_url) | 1028 if (overlay_ && overlay_->instant_url() == instant_url) |
967 return true; | 1029 return true; |
968 | 1030 |
969 HideInternal(); | 1031 HideInternal(); |
970 loader_.reset(new InstantLoader(this, instant_url)); | 1032 overlay_.reset(new InstantOverlay(this, instant_url)); |
971 loader_->InitContents(active_tab); | 1033 overlay_->InitContents(browser_->profile(), active_tab); |
972 | 1034 |
973 // Ensure the searchbox API has the correct initial state. | 1035 // Ensure the searchbox API has the correct initial state. |
974 if (extended_enabled_) { | 1036 if (extended_enabled_) { |
975 browser_->UpdateThemeInfoForPreview(); | 1037 browser_->UpdateThemeInfoForPreview(); |
976 loader_->SetDisplayInstantResults(instant_enabled_); | 1038 overlay_->SetDisplayInstantResults(instant_enabled_); |
977 loader_->SearchModeChanged(search_mode_); | 1039 overlay_->SearchModeChanged(search_mode_); |
978 loader_->KeyCaptureChanged(omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE); | 1040 overlay_->KeyCaptureChanged( |
979 loader_->SetMarginSize(start_margin_, end_margin_); | 1041 omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE); |
| 1042 overlay_->SetMarginSize(start_margin_, end_margin_); |
980 } | 1043 } |
981 | 1044 |
982 // Restart the stale loader timer. | 1045 // Restart the stale overlay timer. |
983 stale_loader_timer_.Start(FROM_HERE, | 1046 stale_overlay_timer_.Start(FROM_HERE, |
984 base::TimeDelta::FromMilliseconds(kStaleLoaderTimeoutMS), this, | 1047 base::TimeDelta::FromMilliseconds(kStalePageTimeoutMS), this, |
985 &InstantController::OnStaleLoader); | 1048 &InstantController::OnStaleOverlay); |
986 | 1049 |
987 return true; | 1050 return true; |
988 } | 1051 } |
989 | 1052 |
990 bool InstantController::CreateDefaultLoader() { | 1053 bool InstantController::ResetNTP() { |
991 // If there's no active tab, the browser is closing. | 1054 const TemplateURL* template_url = TemplateURLServiceFactory::GetForProfile( |
| 1055 browser_->profile())->GetDefaultSearchProvider(); |
| 1056 std::string instant_url; |
| 1057 if (!GetInstantURL(template_url, &instant_url)) |
| 1058 return false; |
| 1059 |
| 1060 ntp_.reset(new InstantNTP(this, instant_url)); |
| 1061 ntp_->InitContents(browser_->profile(), browser_->GetActiveWebContents()); |
| 1062 |
| 1063 // Ensure the searchbox API has the correct initial state. |
| 1064 if (extended_enabled_) { |
| 1065 browser_->UpdateThemeInfoForPreview(); |
| 1066 ntp_->SetDisplayInstantResults(instant_enabled_); |
| 1067 ntp_->SetMarginSize(start_margin_, end_margin_); |
| 1068 } |
| 1069 |
| 1070 // Restart the stale NTP timer. |
| 1071 stale_ntp_timer_.Start(FROM_HERE, |
| 1072 base::TimeDelta::FromMilliseconds(kStalePageTimeoutMS), this, |
| 1073 &InstantController::OnStaleNTP); |
| 1074 |
| 1075 return true; |
| 1076 } |
| 1077 |
| 1078 bool InstantController::CreateDefaultOverlay() { |
| 1079 // If there's no active tab, the browser is opening or closing. |
992 const content::WebContents* active_tab = browser_->GetActiveWebContents(); | 1080 const content::WebContents* active_tab = browser_->GetActiveWebContents(); |
993 if (!active_tab) | 1081 if (!active_tab) |
994 return false; | 1082 return false; |
995 | 1083 |
996 const TemplateURL* template_url = TemplateURLServiceFactory::GetForProfile( | 1084 const TemplateURL* template_url = TemplateURLServiceFactory::GetForProfile( |
997 Profile::FromBrowserContext(active_tab->GetBrowserContext()))-> | 1085 Profile::FromBrowserContext(active_tab->GetBrowserContext()))-> |
998 GetDefaultSearchProvider(); | 1086 GetDefaultSearchProvider(); |
999 | 1087 |
1000 return ResetLoader(template_url, active_tab, true); | 1088 return ResetOverlay(template_url, active_tab, true); |
1001 } | 1089 } |
1002 | 1090 |
1003 void InstantController::OnStaleLoader() { | 1091 void InstantController::OnStaleOverlay() { |
1004 // The local popup is never stale. | 1092 // The local popup is never stale. |
1005 if (loader_ && loader_->IsUsingLocalPreview()) | 1093 if (overlay_ && overlay_->IsUsingLocalPreview()) |
1006 return; | 1094 return; |
1007 | 1095 |
1008 // If the preview is showing or the omnibox has focus, don't delete the | 1096 // If the preview is showing or the omnibox has focus, don't delete the |
1009 // loader. It will get refreshed the next time the preview is hidden or the | 1097 // overlay. It will get refreshed the next time the preview is hidden or the |
1010 // omnibox loses focus. | 1098 // omnibox loses focus. |
1011 if (!stale_loader_timer_.IsRunning() && | 1099 if (!stale_overlay_timer_.IsRunning() && |
1012 omnibox_focus_state_ == OMNIBOX_FOCUS_NONE && | 1100 omnibox_focus_state_ == OMNIBOX_FOCUS_NONE && |
1013 model_.mode().is_default()) { | 1101 model_.mode().is_default()) { |
1014 loader_.reset(); | 1102 overlay_.reset(); |
1015 CreateDefaultLoader(); | 1103 CreateDefaultOverlay(); |
| 1104 } |
| 1105 } |
| 1106 |
| 1107 void InstantController::OnStaleNTP() { |
| 1108 if (!stale_ntp_timer_.IsRunning()) { |
| 1109 ntp_.reset(); |
| 1110 ResetNTP(); |
1016 } | 1111 } |
1017 } | 1112 } |
1018 | 1113 |
1019 void InstantController::ResetInstantTab() { | 1114 void InstantController::ResetInstantTab() { |
1020 // Do not wire up the InstantTab if instant should only use local previews, to | 1115 // Do not wire up the InstantTab if instant should only use local previews, to |
1021 // prevent it from sending data to the page. | 1116 // prevent it from sending data to the page. |
1022 if (search_mode_.is_origin_search() && !use_local_preview_only_) { | 1117 if (!search_mode_.is_origin_default() && !use_local_preview_only_) { |
1023 content::WebContents* active_tab = browser_->GetActiveWebContents(); | 1118 content::WebContents* active_tab = browser_->GetActiveWebContents(); |
1024 if (!instant_tab_ || active_tab != instant_tab_->contents()) { | 1119 if (!instant_tab_ || active_tab != instant_tab_->contents()) { |
1025 instant_tab_.reset(new InstantTab(this, active_tab)); | 1120 instant_tab_.reset(new InstantTab(this, active_tab)); |
1026 instant_tab_->Init(); | 1121 instant_tab_->Init(); |
1027 instant_tab_->SetDisplayInstantResults(instant_enabled_); | 1122 instant_tab_->SetDisplayInstantResults(instant_enabled_); |
1028 instant_tab_->SetMarginSize(start_margin_, end_margin_); | 1123 instant_tab_->SetMarginSize(start_margin_, end_margin_); |
| 1124 instant_tab_->KeyCaptureChanged( |
| 1125 omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE); |
1029 } | 1126 } |
1030 | 1127 |
1031 // Hide the |loader_| since we are now using |instant_tab_| instead. | 1128 // Hide the |overlay_| since we are now using |instant_tab_| instead. |
1032 HideLoader(); | 1129 HideOverlay(); |
1033 } else { | 1130 } else { |
1034 instant_tab_.reset(); | 1131 instant_tab_.reset(); |
1035 } | 1132 } |
1036 } | 1133 } |
1037 | 1134 |
1038 bool InstantController::ResetLoaderForMatch(const AutocompleteMatch& match) { | 1135 bool InstantController::ResetOverlayForMatch(const AutocompleteMatch& match) { |
1039 // If we are on a search results page, we'll use that instead of a loader. | 1136 // If we are on a search results page, we'll use that instead of a overlay. |
1040 // TODO(sreeram): If |instant_tab_|'s URL is not the same as the instant_url | 1137 // TODO(sreeram): If |instant_tab_|'s URL is not the same as the instant_url |
1041 // of |match|, we shouldn't use the committed tab. | 1138 // of |match|, we shouldn't use the committed tab. |
1042 if (instant_tab_) | 1139 if (instant_tab_) |
1043 return true; | 1140 return true; |
1044 | 1141 |
1045 // If there's no active tab, the browser is closing. | 1142 // If there's no active tab, the browser is closing. |
1046 const content::WebContents* active_tab = browser_->GetActiveWebContents(); | 1143 const content::WebContents* active_tab = browser_->GetActiveWebContents(); |
1047 if (!active_tab) | 1144 if (!active_tab) |
1048 return false; | 1145 return false; |
1049 | 1146 |
1050 // Try to create a loader for the instant_url in the TemplateURL of |match|. | 1147 // Try to create a overlay for the instant_url in the TemplateURL of |match|. |
1051 // Do not fallback to the local preview because if the keyword specific | 1148 // Do not fallback to the local preview because if the keyword specific |
1052 // instant URL fails, we want to first try the default instant URL which | 1149 // instant URL fails, we want to first try the default instant URL which |
1053 // happens in the CreateDefaultLoader call below. | 1150 // happens in the CreateDefaultOverlay call below. |
1054 const TemplateURL* template_url = match.GetTemplateURL( | 1151 const TemplateURL* template_url = match.GetTemplateURL( |
1055 Profile::FromBrowserContext(active_tab->GetBrowserContext()), false); | 1152 Profile::FromBrowserContext(active_tab->GetBrowserContext()), false); |
1056 if (ResetLoader(template_url, active_tab, false)) | 1153 if (ResetOverlay(template_url, active_tab, false)) |
1057 return true; | 1154 return true; |
1058 | 1155 |
1059 // In non-extended mode, stop if we couldn't get a loader for the |match|. | 1156 // In non-extended mode, stop if we couldn't get a overlay for the |match|. |
1060 if (!extended_enabled_) | 1157 if (!extended_enabled_) |
1061 return false; | 1158 return false; |
1062 | 1159 |
1063 // If the match is a query, it is for a non-Instant search engine; stop. | 1160 // If the match is a query, it is for a non-Instant search engine; stop. |
1064 if (last_match_was_search_) | 1161 if (last_match_was_search_) |
1065 return false; | 1162 return false; |
1066 | 1163 |
1067 // The match is a URL, or a blank query. Try the default search engine. | 1164 // The match is a URL, or a blank query. Try the default search engine. |
1068 return CreateDefaultLoader(); | 1165 return CreateDefaultOverlay(); |
1069 } | 1166 } |
1070 | 1167 |
1071 void InstantController::HideLoader() { | 1168 void InstantController::HideOverlay() { |
1072 HideInternal(); | 1169 HideInternal(); |
1073 OnStaleLoader(); | 1170 OnStaleOverlay(); |
1074 } | 1171 } |
1075 | 1172 |
1076 void InstantController::HideInternal() { | 1173 void InstantController::HideInternal() { |
1077 DVLOG(1) << "Hide"; | 1174 DVLOG(1) << "Hide"; |
1078 | 1175 |
1079 // If GetPreviewContents() returns NULL, either we're already in the desired | 1176 // If GetPreviewContents() returns NULL, either we're already in the desired |
1080 // MODE_DEFAULT state, or we're in the commit path. For the latter, don't | 1177 // MODE_DEFAULT state, or we're in the commit path. For the latter, don't |
1081 // change the state just yet; else we may hide the preview unnecessarily. | 1178 // 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. | 1179 // Instead, the state will be set correctly after the commit is done. |
1083 if (GetPreviewContents()) { | 1180 if (GetPreviewContents()) { |
1084 model_.SetPreviewState(chrome::search::Mode(), 0, INSTANT_SIZE_PERCENT); | 1181 model_.SetPreviewState(chrome::search::Mode(), 0, INSTANT_SIZE_PERCENT); |
1085 allow_preview_to_show_search_suggestions_ = false; | 1182 allow_preview_to_show_search_suggestions_ = false; |
1086 | 1183 |
1087 // Send a message asking the preview to clear out old results. | 1184 // Send a message asking the preview to clear out old results. |
1088 loader_->Update(string16(), 0, 0, true); | 1185 overlay_->Update(string16(), 0, 0, true); |
1089 } | 1186 } |
1090 | 1187 |
1091 // Clear the first interaction timestamp for later use. | 1188 // Clear the first interaction timestamp for later use. |
1092 first_interaction_time_ = base::Time(); | 1189 first_interaction_time_ = base::Time(); |
1093 } | 1190 } |
1094 | 1191 |
1095 void InstantController::ShowLoader(InstantShownReason reason, | 1192 void InstantController::ShowOverlay(InstantShownReason reason, |
1096 int height, | 1193 int height, |
1097 InstantSizeUnits units) { | 1194 InstantSizeUnits units) { |
1098 // If we are on a committed search results page, the |loader_| is not in use. | 1195 // If we are on a committed search results page, the |overlay_| is not in use. |
1099 if (instant_tab_) | 1196 if (instant_tab_) |
1100 return; | 1197 return; |
1101 | 1198 |
1102 DVLOG(1) << "Show: reason=" << reason << " height=" << height << " units=" | 1199 DVLOG(1) << "Show: reason=" << reason << " height=" << height << " units=" |
1103 << units; | 1200 << units; |
1104 | 1201 |
1105 // Must be on NTP to show NTP content. | 1202 // INSTANT_SHOWN_CUSTOM_NTP_CONTENT is no longer supported. |
1106 if (reason == INSTANT_SHOWN_CUSTOM_NTP_CONTENT && !search_mode_.is_ntp()) | 1203 // TODO(samarth): remove once the server has been updated. |
| 1204 if (reason == INSTANT_SHOWN_CUSTOM_NTP_CONTENT) |
1107 return; | 1205 return; |
1108 | 1206 |
1109 // Must have updated omnibox after the last HideLoader() to show suggestions. | 1207 // Must have updated omnibox after the last HideOverlay() to show suggestions. |
1110 if ((reason == INSTANT_SHOWN_QUERY_SUGGESTIONS || | 1208 if ((reason == INSTANT_SHOWN_QUERY_SUGGESTIONS || |
1111 reason == INSTANT_SHOWN_CLICKED_QUERY_SUGGESTION) && | 1209 reason == INSTANT_SHOWN_CLICKED_QUERY_SUGGESTION) && |
1112 !allow_preview_to_show_search_suggestions_) | 1210 !allow_preview_to_show_search_suggestions_) |
1113 return; | 1211 return; |
1114 | 1212 |
1115 // The page is trying to hide itself. Hide explicitly (i.e., don't use | 1213 // The page is trying to hide itself. Hide explicitly (i.e., don't use |
1116 // HideLoader()) so that it can change its mind. | 1214 // HideOverlay()) so that it can change its mind. |
1117 if (height == 0) { | 1215 if (height == 0) { |
1118 model_.SetPreviewState(chrome::search::Mode(), 0, INSTANT_SIZE_PERCENT); | 1216 model_.SetPreviewState(chrome::search::Mode(), 0, INSTANT_SIZE_PERCENT); |
1119 return; | 1217 return; |
1120 } | 1218 } |
1121 | 1219 |
1122 // If the preview is being shown for the first time since the user started | 1220 // If the preview is being shown for the first time since the user started |
1123 // typing, record a histogram value. | 1221 // typing, record a histogram value. |
1124 if (!first_interaction_time_.is_null() && model_.mode().is_default()) { | 1222 if (!first_interaction_time_.is_null() && model_.mode().is_default()) { |
1125 base::TimeDelta delta = base::Time::Now() - first_interaction_time_; | 1223 base::TimeDelta delta = base::Time::Now() - first_interaction_time_; |
1126 UMA_HISTOGRAM_TIMES("Instant.TimeToFirstShow", delta); | 1224 UMA_HISTOGRAM_TIMES("Instant.TimeToFirstShow", delta); |
1127 } | 1225 } |
1128 | 1226 |
1129 // Show at 100% height except in the following cases: | 1227 // Show at 100% height except in the following cases: |
1130 // - The local omnibox popup is being loaded. | 1228 // - The local omnibox popup is being loaded. |
1131 // - Instant is disabled. The page needs to be able to show only a dropdown. | 1229 // - Instant is disabled. The page needs to be able to show only a dropdown. |
1132 // - The page wants to show custom NTP content. | 1230 // - The page wants to show custom NTP content. |
1133 // - The page is over a website other than search or an NTP, and is not | 1231 // - The page is over a website other than search or an NTP, and is not |
1134 // already showing at 100% height. | 1232 // already showing at 100% height. |
1135 if (loader_->IsUsingLocalPreview() || !instant_enabled_ || | 1233 if (overlay_->IsUsingLocalPreview() || !instant_enabled_ || |
1136 reason == INSTANT_SHOWN_CUSTOM_NTP_CONTENT || | 1234 reason == INSTANT_SHOWN_CUSTOM_NTP_CONTENT || |
1137 (search_mode_.is_origin_default() && !IsFullHeight(model_))) | 1235 (search_mode_.is_origin_default() && !IsFullHeight(model_))) |
1138 model_.SetPreviewState(search_mode_, height, units); | 1236 model_.SetPreviewState(search_mode_, height, units); |
1139 else | 1237 else |
1140 model_.SetPreviewState(search_mode_, 100, INSTANT_SIZE_PERCENT); | 1238 model_.SetPreviewState(search_mode_, 100, INSTANT_SIZE_PERCENT); |
1141 | 1239 |
1142 // If the user clicked on a query suggestion, also go ahead and commit the | 1240 // 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 | 1241 // overlay. This is necessary because if the overlay was partially visible |
1144 // when the suggestion was clicked, the click itself would not commit the | 1242 // when the suggestion was clicked, the click itself would not commit the |
1145 // overlay (because we're not full height). | 1243 // overlay (because we're not full height). |
1146 if (reason == INSTANT_SHOWN_CLICKED_QUERY_SUGGESTION) | 1244 if (reason == INSTANT_SHOWN_CLICKED_QUERY_SUGGESTION) |
1147 CommitIfPossible(INSTANT_COMMIT_CLICKED_QUERY_SUGGESTION); | 1245 CommitIfPossible(INSTANT_COMMIT_CLICKED_QUERY_SUGGESTION); |
1148 } | 1246 } |
1149 | 1247 |
1150 void InstantController::SendPopupBoundsToPage() { | 1248 void InstantController::SendPopupBoundsToPage() { |
1151 if (last_popup_bounds_ == popup_bounds_ || !loader_ || | 1249 if (last_popup_bounds_ == popup_bounds_ || !overlay_ || |
1152 loader_->is_pointer_down_from_activate()) | 1250 overlay_->is_pointer_down_from_activate()) |
1153 return; | 1251 return; |
1154 | 1252 |
1155 last_popup_bounds_ = popup_bounds_; | 1253 last_popup_bounds_ = popup_bounds_; |
1156 gfx::Rect preview_bounds = browser_->GetInstantBounds(); | 1254 gfx::Rect preview_bounds = browser_->GetInstantBounds(); |
1157 gfx::Rect intersection = gfx::IntersectRects(popup_bounds_, preview_bounds); | 1255 gfx::Rect intersection = gfx::IntersectRects(popup_bounds_, preview_bounds); |
1158 | 1256 |
1159 // Translate into window coordinates. | 1257 // Translate into window coordinates. |
1160 if (!intersection.IsEmpty()) { | 1258 if (!intersection.IsEmpty()) { |
1161 intersection.Offset(-preview_bounds.origin().x(), | 1259 intersection.Offset(-preview_bounds.origin().x(), |
1162 -preview_bounds.origin().y()); | 1260 -preview_bounds.origin().y()); |
1163 } | 1261 } |
1164 | 1262 |
1165 // In the current Chrome UI, these must always be true so they sanity check | 1263 // In the current Chrome UI, these must always be true so they sanity check |
1166 // the above operations. In a future UI, these may be removed or adjusted. | 1264 // the above operations. In a future UI, these may be removed or adjusted. |
1167 // There is no point in sanity-checking |intersection.y()| because the omnibox | 1265 // There is no point in sanity-checking |intersection.y()| because the omnibox |
1168 // can be placed anywhere vertically relative to the preview (for example, in | 1266 // can be placed anywhere vertically relative to the preview (for example, in |
1169 // Mac fullscreen mode, the omnibox is fully enclosed by the preview bounds). | 1267 // Mac fullscreen mode, the omnibox is fully enclosed by the preview bounds). |
1170 DCHECK_LE(0, intersection.x()); | 1268 DCHECK_LE(0, intersection.x()); |
1171 DCHECK_LE(0, intersection.width()); | 1269 DCHECK_LE(0, intersection.width()); |
1172 DCHECK_LE(0, intersection.height()); | 1270 DCHECK_LE(0, intersection.height()); |
1173 | 1271 |
1174 loader_->SetPopupBounds(intersection); | 1272 overlay_->SetPopupBounds(intersection); |
1175 } | 1273 } |
1176 | 1274 |
1177 bool InstantController::GetInstantURL(const TemplateURL* template_url, | 1275 bool InstantController::GetInstantURL(const TemplateURL* template_url, |
1178 std::string* instant_url) const { | 1276 std::string* instant_url) const { |
1179 if (extended_enabled_ && use_local_preview_only_) { | 1277 if (extended_enabled_ && use_local_preview_only_) { |
1180 *instant_url = kLocalOmniboxPopupURL; | 1278 *instant_url = kLocalOmniboxPopupURL; |
1181 return true; | 1279 return true; |
1182 } | 1280 } |
1183 | 1281 |
1184 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 1282 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1225 std::map<std::string, int>::const_iterator iter = | 1323 std::map<std::string, int>::const_iterator iter = |
1226 blacklisted_urls_.find(*instant_url); | 1324 blacklisted_urls_.find(*instant_url); |
1227 if (iter != blacklisted_urls_.end() && | 1325 if (iter != blacklisted_urls_.end() && |
1228 iter->second > kMaxInstantSupportFailures) { | 1326 iter->second > kMaxInstantSupportFailures) { |
1229 RecordEventHistogram(INSTANT_CONTROLLER_EVENT_URL_BLOCKED_BY_BLACKLIST); | 1327 RecordEventHistogram(INSTANT_CONTROLLER_EVENT_URL_BLOCKED_BY_BLACKLIST); |
1230 return false; | 1328 return false; |
1231 } | 1329 } |
1232 | 1330 |
1233 return true; | 1331 return true; |
1234 } | 1332 } |
OLD | NEW |