Chromium Code Reviews| 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/ui/search/instant_controller.h" | 5 #include "chrome/browser/ui/search/instant_controller.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 261 UTF16ToUTF8(user_text).c_str(), UTF16ToUTF8(full_text).c_str(), | 261 UTF16ToUTF8(user_text).c_str(), UTF16ToUTF8(full_text).c_str(), |
| 262 static_cast<int>(selection_start), static_cast<int>(selection_end), | 262 static_cast<int>(selection_start), static_cast<int>(selection_end), |
| 263 verbatim, user_input_in_progress, omnibox_popup_is_open, escape_pressed, | 263 verbatim, user_input_in_progress, omnibox_popup_is_open, escape_pressed, |
| 264 is_keyword_search)); | 264 is_keyword_search)); |
| 265 | 265 |
| 266 // TODO(dhollowa): Complete keyword match UI. For now just hide suggestions. | 266 // TODO(dhollowa): Complete keyword match UI. For now just hide suggestions. |
| 267 // http://crbug.com/153932. Note, this early escape is happens prior to the | 267 // http://crbug.com/153932. Note, this early escape is happens prior to the |
| 268 // DCHECKs below because |user_text| and |full_text| have different semantics | 268 // DCHECKs below because |user_text| and |full_text| have different semantics |
| 269 // when keyword search is in effect. | 269 // when keyword search is in effect. |
| 270 if (is_keyword_search) { | 270 if (is_keyword_search) { |
| 271 if (UseInstantTabToShowSuggestions()) | 271 if (instant_tab_) |
| 272 instant_tab_->Update(string16(), 0, 0, true); | 272 instant_tab_->Update(string16(), 0, 0, true); |
| 273 else | 273 else |
| 274 HideOverlay(); | 274 HideOverlay(); |
| 275 last_match_was_search_ = false; | 275 last_match_was_search_ = false; |
| 276 return false; | 276 return false; |
| 277 } | 277 } |
| 278 | 278 |
| 279 // Ignore spurious updates when the omnibox is blurred; otherwise click | 279 // Ignore spurious updates when the omnibox is blurred; otherwise click |
| 280 // targets on the page may vanish before a click event arrives. | 280 // targets on the page may vanish before a click event arrives. |
| 281 if (omnibox_focus_state_ == OMNIBOX_FOCUS_NONE) | 281 if (omnibox_focus_state_ == OMNIBOX_FOCUS_NONE) |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 // In non extended mode, Instant is disabled for URLs and keyword mode. | 314 // In non extended mode, Instant is disabled for URLs and keyword mode. |
| 315 if (!extended_enabled_ && | 315 if (!extended_enabled_ && |
| 316 (!last_match_was_search_ || | 316 (!last_match_was_search_ || |
| 317 match.type == AutocompleteMatch::SEARCH_OTHER_ENGINE)) { | 317 match.type == AutocompleteMatch::SEARCH_OTHER_ENGINE)) { |
| 318 HideOverlay(); | 318 HideOverlay(); |
| 319 return false; | 319 return false; |
| 320 } | 320 } |
| 321 | 321 |
| 322 // If we have an |instant_tab_| use it, else ensure we have an overlay that is | 322 // If we have an |instant_tab_| use it, else ensure we have an overlay that is |
| 323 // current or is using the local overlay. | 323 // current or is using the local overlay. |
| 324 if (!UseInstantTabToShowSuggestions() && | 324 if (!instant_tab_ && !(overlay_ && overlay_->IsLocal()) && |
| 325 !(overlay_ && overlay_->IsLocalOverlay()) && | |
| 326 !EnsureOverlayIsCurrent(false)) { | 325 !EnsureOverlayIsCurrent(false)) { |
| 327 HideOverlay(); | 326 HideOverlay(); |
| 328 return false; | 327 return false; |
| 329 } | 328 } |
| 330 | 329 |
| 331 if (extended_enabled_) { | 330 if (extended_enabled_) { |
| 332 if (!omnibox_popup_is_open) { | 331 if (!omnibox_popup_is_open) { |
| 333 if (!user_input_in_progress) { | 332 if (!user_input_in_progress) { |
| 334 // If the user isn't typing and the omnibox popup is closed, it means a | 333 // If the user isn't typing and the omnibox popup is closed, it means a |
| 335 // regular navigation, tab-switch or the user hitting Escape. | 334 // regular navigation, tab-switch or the user hitting Escape. |
| 336 if (UseInstantTabToShowSuggestions()) { | 335 if (instant_tab_) { |
| 337 // The user is on a search results page. It may be showing results for | 336 // The user is on a search results page. It may be showing results for |
| 338 // a partial query the user typed before they hit Escape. Send the | 337 // a partial query the user typed before they hit Escape. Send the |
| 339 // omnibox text to the page to restore the original results. | 338 // omnibox text to the page to restore the original results. |
| 340 // | 339 // |
| 341 // In a tab switch, |instant_tab_| won't have updated yet, so it may | 340 // In a tab switch, |instant_tab_| won't have updated yet, so it may |
| 342 // be pointing to the previous tab (which was a search results page). | 341 // be pointing to the previous tab (which was a search results page). |
| 343 // Ensure we don't send the omnibox text to a random webpage (the new | 342 // Ensure we don't send the omnibox text to a random webpage (the new |
| 344 // tab), by comparing the old and new WebContents. | 343 // tab), by comparing the old and new WebContents. |
| 345 if (escape_pressed && | 344 if (escape_pressed && |
| 346 instant_tab_->contents() == browser_->GetActiveWebContents()) { | 345 instant_tab_->contents() == browser_->GetActiveWebContents()) { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 359 // If |full_text| is empty, the user is on the NTP. The overlay may | 358 // If |full_text| is empty, the user is on the NTP. The overlay may |
| 360 // be showing custom NTP content; hide only if that's not the case. | 359 // be showing custom NTP content; hide only if that's not the case. |
| 361 HideOverlay(); | 360 HideOverlay(); |
| 362 } | 361 } |
| 363 } else if (full_text.empty()) { | 362 } else if (full_text.empty()) { |
| 364 // The user is typing, and backspaced away all omnibox text. Clear | 363 // The user is typing, and backspaced away all omnibox text. Clear |
| 365 // |last_omnibox_text_| so that we don't attempt to set suggestions. | 364 // |last_omnibox_text_| so that we don't attempt to set suggestions. |
| 366 last_omnibox_text_.clear(); | 365 last_omnibox_text_.clear(); |
| 367 last_user_text_.clear(); | 366 last_user_text_.clear(); |
| 368 last_suggestion_ = InstantSuggestion(); | 367 last_suggestion_ = InstantSuggestion(); |
| 369 if (UseInstantTabToShowSuggestions()) { | 368 if (instant_tab_) { |
| 370 // On a search results page, tell it to clear old results. | 369 // On a search results page, tell it to clear old results. |
| 371 instant_tab_->Update(string16(), 0, 0, true); | 370 instant_tab_->Update(string16(), 0, 0, true); |
| 372 } else if (search_mode_.is_origin_ntp()) { | 371 } else if (search_mode_.is_origin_ntp()) { |
| 373 // On the NTP, tell the overlay to clear old results. Don't hide the | 372 // On the NTP, tell the overlay to clear old results. Don't hide the |
| 374 // overlay so it can show a blank page or logo if it wants. | 373 // overlay so it can show a blank page or logo if it wants. |
| 375 overlay_->Update(string16(), 0, 0, true); | 374 overlay_->Update(string16(), 0, 0, true); |
| 376 } else { | 375 } else { |
| 377 HideOverlay(); | 376 HideOverlay(); |
| 378 } | 377 } |
| 379 } else { | 378 } else { |
| 380 // The user switched to a tab with partial text already in the omnibox. | 379 // The user switched to a tab with partial text already in the omnibox. |
| 381 HideOverlay(); | 380 HideOverlay(); |
| 382 | 381 |
| 383 // The new tab may or may not be a search results page; we don't know | 382 // The new tab may or may not be a search results page; we don't know |
| 384 // since SearchModeChanged() hasn't been called yet. If it later turns | 383 // since SearchModeChanged() hasn't been called yet. If it later turns |
| 385 // out to be, we should store |full_text| now, so that if the user hits | 384 // out to be, we should store |full_text| now, so that if the user hits |
| 386 // Enter, we'll send the correct query to instant_tab_->Submit(). If the | 385 // Enter, we'll send the correct query to instant_tab_->Submit(). If the |
| 387 // partial text is not a query (|last_match_was_search_| is false), we | 386 // partial text is not a query (|last_match_was_search_| is false), we |
| 388 // won't Submit(), so no need to worry about that. | 387 // won't Submit(), so no need to worry about that. |
| 389 last_omnibox_text_ = full_text; | 388 last_omnibox_text_ = full_text; |
| 390 last_user_text_ = user_text; | 389 last_user_text_ = user_text; |
| 391 last_suggestion_ = InstantSuggestion(); | 390 last_suggestion_ = InstantSuggestion(); |
| 392 } | 391 } |
| 393 return false; | 392 return false; |
| 394 } else if (full_text.empty()) { | 393 } else if (full_text.empty()) { |
| 395 // The user typed a solitary "?". Same as the backspace case above. | 394 // The user typed a solitary "?". Same as the backspace case above. |
| 396 last_omnibox_text_.clear(); | 395 last_omnibox_text_.clear(); |
| 397 last_user_text_.clear(); | 396 last_user_text_.clear(); |
| 398 last_suggestion_ = InstantSuggestion(); | 397 last_suggestion_ = InstantSuggestion(); |
| 399 if (UseInstantTabToShowSuggestions()) | 398 if (instant_tab_) |
| 400 instant_tab_->Update(string16(), 0, 0, true); | 399 instant_tab_->Update(string16(), 0, 0, true); |
| 401 else if (search_mode_.is_origin_ntp()) | 400 else if (search_mode_.is_origin_ntp()) |
| 402 overlay_->Update(string16(), 0, 0, true); | 401 overlay_->Update(string16(), 0, 0, true); |
| 403 else | 402 else |
| 404 HideOverlay(); | 403 HideOverlay(); |
| 405 return false; | 404 return false; |
| 406 } | 405 } |
| 407 } else if (!omnibox_popup_is_open || full_text.empty()) { | 406 } else if (!omnibox_popup_is_open || full_text.empty()) { |
| 408 // In the non-extended case, hide the overlay as long as the user isn't | 407 // In the non-extended case, hide the overlay as long as the user isn't |
| 409 // actively typing a non-empty query. | 408 // actively typing a non-empty query. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 444 last_verbatim_ = verbatim; | 443 last_verbatim_ = verbatim; |
| 445 | 444 |
| 446 last_transition_type_ = match.transition; | 445 last_transition_type_ = match.transition; |
| 447 url_for_history_ = match.destination_url; | 446 url_for_history_ = match.destination_url; |
| 448 | 447 |
| 449 // Allow search suggestions. In extended mode, SearchModeChanged() will set | 448 // Allow search suggestions. In extended mode, SearchModeChanged() will set |
| 450 // this, but it's not called in non-extended mode, so fake it. | 449 // this, but it's not called in non-extended mode, so fake it. |
| 451 if (!extended_enabled_) | 450 if (!extended_enabled_) |
| 452 search_mode_.mode = SearchMode::MODE_SEARCH_SUGGESTIONS; | 451 search_mode_.mode = SearchMode::MODE_SEARCH_SUGGESTIONS; |
| 453 | 452 |
| 454 if (UseInstantTabToShowSuggestions()) { | 453 if (instant_tab_) { |
| 455 // If we have an |instant_tab_| but it doesn't support Instant yet, sever | 454 // If we have an |instant_tab_| but it doesn't support Instant yet, sever |
| 456 // the connection to it so we use the overlay instead. This ensures that the | 455 // the connection to it so we use the overlay instead. This ensures that the |
| 457 // user interaction will be responsive and handles cases where | 456 // user interaction will be responsive and handles cases where |
| 458 // |instant_tab_| never responds about whether it supports Instant. | 457 // |instant_tab_| never responds about whether it supports Instant. |
| 459 if (instant_tab_->supports_instant()) | 458 if (instant_tab_->supports_instant()) |
| 460 instant_tab_->Update(user_text, selection_start, selection_end, verbatim); | 459 instant_tab_->Update(user_text, selection_start, selection_end, verbatim); |
| 461 else | 460 else |
| 462 instant_tab_.reset(); | 461 instant_tab_.reset(); |
| 463 } | 462 } |
| 464 | 463 |
| 465 if (!UseInstantTabToShowSuggestions()) { | 464 if (!instant_tab_) { |
| 466 if (first_interaction_time_.is_null()) | 465 if (first_interaction_time_.is_null()) |
| 467 first_interaction_time_ = base::Time::Now(); | 466 first_interaction_time_ = base::Time::Now(); |
| 468 allow_overlay_to_show_search_suggestions_ = true; | 467 allow_overlay_to_show_search_suggestions_ = true; |
| 469 | 468 |
| 470 // For extended mode, if the loader is not ready at this point, switch over | 469 // For extended mode, if the loader is not ready at this point, switch over |
| 471 // to a backup loader. | 470 // to a backup loader. |
| 472 if (extended_enabled_ && !overlay_->supports_instant() && | 471 if (extended_enabled_ && !overlay_->supports_instant() && |
| 473 !overlay_->IsLocalOverlay() && browser_->GetActiveWebContents()) { | 472 !overlay_->IsLocal() && browser_->GetActiveWebContents()) { |
| 474 CreateOverlay(chrome::kChromeSearchLocalOmniboxPopupURL, | 473 CreateOverlay(chrome::GetLocalInstantURL(browser_->profile()).spec(), |
| 475 browser_->GetActiveWebContents()); | 474 browser_->GetActiveWebContents()); |
| 476 } | 475 } |
| 477 | 476 |
| 478 overlay_->Update(extended_enabled_ ? user_text : full_text, | 477 overlay_->Update(extended_enabled_ ? user_text : full_text, |
| 479 selection_start, selection_end, verbatim); | 478 selection_start, selection_end, verbatim); |
| 480 } | 479 } |
| 481 | 480 |
| 482 content::NotificationService::current()->Notify( | 481 content::NotificationService::current()->Notify( |
| 483 chrome::NOTIFICATION_INSTANT_CONTROLLER_UPDATED, | 482 chrome::NOTIFICATION_INSTANT_CONTROLLER_UPDATED, |
| 484 content::Source<InstantController>(this), | 483 content::Source<InstantController>(this), |
| 485 content::NotificationService::NoDetails()); | 484 content::NotificationService::NoDetails()); |
| 486 | 485 |
| 487 // We don't have new suggestions yet, but we can either reuse the existing | 486 // We don't have new suggestions yet, but we can either reuse the existing |
| 488 // suggestion or reset the existing "gray text". | 487 // suggestion or reset the existing "gray text". |
| 489 browser_->SetInstantSuggestion(last_suggestion_); | 488 browser_->SetInstantSuggestion(last_suggestion_); |
| 490 | 489 |
| 491 return true; | 490 return true; |
| 492 } | 491 } |
| 493 | 492 |
| 494 scoped_ptr<content::WebContents> InstantController::ReleaseNTPContents() { | 493 scoped_ptr<content::WebContents> InstantController::ReleaseNTPContents() { |
| 495 if (!extended_enabled_ || !browser_->profile() || | 494 if (!extended_enabled_ || !browser_->profile() || |
| 496 browser_->profile()->IsOffTheRecord()) | 495 browser_->profile()->IsOffTheRecord()) |
| 497 return scoped_ptr<content::WebContents>(NULL); | 496 return scoped_ptr<content::WebContents>(NULL); |
| 498 | 497 |
| 499 LOG_INSTANT_DEBUG_EVENT(this, "ReleaseNTPContents"); | 498 LOG_INSTANT_DEBUG_EVENT(this, "ReleaseNTPContents"); |
| 500 | 499 |
| 501 // Switch to the local NTP unless we're already using one. | 500 // TODO(jeremycho): Add tests for this logic. |
| 502 if (!ntp_ || (ShouldSwitchToLocalNTP() && !ntp_->IsLocalNTP())) | 501 if (ShouldSwitchToLocalNTP()) |
| 503 ResetNTP(false, true); | 502 ResetNTP(false, true); |
| 504 | 503 |
| 505 scoped_ptr<content::WebContents> ntp_contents = ntp_->ReleaseContents(); | 504 scoped_ptr<content::WebContents> ntp_contents = ntp_->ReleaseContents(); |
| 506 | 505 |
| 507 if (!use_local_page_only_) { | 506 if (!use_local_page_only_) { |
| 508 // Preload a new Instant NTP, unless using the local NTP which is not | 507 // Preload a new Instant NTP, unless using the local NTP which is not |
| 509 // preloaded to conserve memory. | 508 // preloaded to conserve memory. |
| 510 // | 509 // |
| 511 // Since this corresponds to a user action, give the remote page another | 510 // Since this corresponds to a user action, give the remote page another |
| 512 // try, even if it's blacklisted. We don't want to blacklist pages for the | 511 // try, even if it's blacklisted. We don't want to blacklist pages for the |
| 513 // duration of a Browser object (for some people, that's effectively | 512 // duration of a Browser object (for some people, that's effectively |
| 514 // "forever"). | 513 // "forever"). |
| 515 ResetNTP(true, false); | 514 ResetNTP(true, false); |
| 515 } else { | |
| 516 ntp_.reset(); | |
| 516 } | 517 } |
| 517 return ntp_contents.Pass(); | 518 return ntp_contents.Pass(); |
| 518 } | 519 } |
| 519 | 520 |
| 520 // TODO(tonyg): This method only fires when the omnibox bounds change. It also | 521 // TODO(tonyg): This method only fires when the omnibox bounds change. It also |
| 521 // needs to fire when the overlay bounds change (e.g.: open/close info bar). | 522 // needs to fire when the overlay bounds change (e.g.: open/close info bar). |
| 522 void InstantController::SetPopupBounds(const gfx::Rect& bounds) { | 523 void InstantController::SetPopupBounds(const gfx::Rect& bounds) { |
| 523 if (!extended_enabled_ && !instant_enabled_) | 524 if (!extended_enabled_ && !instant_enabled_) |
| 524 return; | 525 return; |
| 525 | 526 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 562 // as it stops autocomplete. Ignore these. | 563 // as it stops autocomplete. Ignore these. |
| 563 if (omnibox_focus_state_ == OMNIBOX_FOCUS_NONE) | 564 if (omnibox_focus_state_ == OMNIBOX_FOCUS_NONE) |
| 564 return; | 565 return; |
| 565 | 566 |
| 566 DVLOG(1) << "AutocompleteResults:"; | 567 DVLOG(1) << "AutocompleteResults:"; |
| 567 std::vector<InstantAutocompleteResult> results; | 568 std::vector<InstantAutocompleteResult> results; |
| 568 for (ACProviders::const_iterator provider = providers.begin(); | 569 for (ACProviders::const_iterator provider = providers.begin(); |
| 569 provider != providers.end(); ++provider) { | 570 provider != providers.end(); ++provider) { |
| 570 const bool from_search_provider = | 571 const bool from_search_provider = |
| 571 (*provider)->type() == AutocompleteProvider::TYPE_SEARCH; | 572 (*provider)->type() == AutocompleteProvider::TYPE_SEARCH; |
| 572 // Unless we are talking to the local overlay, skip SearchProvider, since | 573 const bool using_local_page = |
| 573 // it only echoes suggestions. | 574 (instant_tab_ && instant_tab_->IsLocal()) || overlay_->IsLocal(); |
|
sreeram
2013/04/19 17:12:42
Not quite right. You need:
(instant_tab_ && in
jeremycho
2013/04/19 19:55:07
Done.
| |
| 574 if (from_search_provider && | 575 // Unless we are talking to a local page, skip SearchProvider, since it only |
| 575 (UseInstantTabToShowSuggestions() || !overlay_->IsLocalOverlay())) | 576 // echoes suggestions. |
| 577 if (from_search_provider && !using_local_page) | |
| 576 continue; | 578 continue; |
| 577 // Only send autocomplete results when all the providers are done. Skip | 579 // Only send autocomplete results when all the providers are done. Skip |
| 578 // this check for the SearchProvider, since it isn't done until the page | 580 // this check for the SearchProvider, since it isn't done until the page |
| 579 // calls SetSuggestions (causing SearchProvider::FinalizeInstantQuery() to | 581 // calls SetSuggestions (causing SearchProvider::FinalizeInstantQuery() to |
| 580 // be called), which makes it a chicken-and-egg thing. | 582 // be called), which makes it a chicken-and-egg thing. |
| 581 if (!from_search_provider && !(*provider)->done()) { | 583 if (!from_search_provider && !(*provider)->done()) { |
| 582 DVLOG(1) << "Waiting for " << (*provider)->GetName(); | 584 DVLOG(1) << "Waiting for " << (*provider)->GetName(); |
| 583 return; | 585 return; |
| 584 } | 586 } |
| 585 for (ACMatches::const_iterator match = (*provider)->matches().begin(); | 587 for (ACMatches::const_iterator match = (*provider)->matches().begin(); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 597 << result.provider << " " << result.destination_url << " '" | 599 << result.provider << " " << result.destination_url << " '" |
| 598 << result.description << "' '" << result.search_query << "' " | 600 << result.description << "' '" << result.search_query << "' " |
| 599 << result.transition; | 601 << result.transition; |
| 600 results.push_back(result); | 602 results.push_back(result); |
| 601 } | 603 } |
| 602 } | 604 } |
| 603 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( | 605 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( |
| 604 "HandleAutocompleteResults: total_results=%d", | 606 "HandleAutocompleteResults: total_results=%d", |
| 605 static_cast<int>(results.size()))); | 607 static_cast<int>(results.size()))); |
| 606 | 608 |
| 607 if (UseInstantTabToShowSuggestions()) | 609 if (instant_tab_) |
| 608 instant_tab_->SendAutocompleteResults(results); | 610 instant_tab_->SendAutocompleteResults(results); |
| 609 else | 611 else |
| 610 overlay_->SendAutocompleteResults(results); | 612 overlay_->SendAutocompleteResults(results); |
| 611 } | 613 } |
| 612 | 614 |
| 613 bool InstantController::OnUpOrDownKeyPressed(int count) { | 615 bool InstantController::OnUpOrDownKeyPressed(int count) { |
| 614 if (!extended_enabled_) | 616 if (!extended_enabled_) |
| 615 return false; | 617 return false; |
| 616 | 618 |
| 617 if (!instant_tab_ && !overlay_) | 619 if (!instant_tab_ && !overlay_) |
| 618 return false; | 620 return false; |
| 619 | 621 |
| 620 if (UseInstantTabToShowSuggestions()) | 622 if (instant_tab_) |
| 621 instant_tab_->UpOrDownKeyPressed(count); | 623 instant_tab_->UpOrDownKeyPressed(count); |
| 622 else | 624 else |
| 623 overlay_->UpOrDownKeyPressed(count); | 625 overlay_->UpOrDownKeyPressed(count); |
| 624 | 626 |
| 625 return true; | 627 return true; |
| 626 } | 628 } |
| 627 | 629 |
| 628 void InstantController::OnCancel(const AutocompleteMatch& match, | 630 void InstantController::OnCancel(const AutocompleteMatch& match, |
| 629 const string16& user_text, | 631 const string16& user_text, |
| 630 const string16& full_text) { | 632 const string16& full_text) { |
| 631 if (!extended_enabled_) | 633 if (!extended_enabled_) |
| 632 return; | 634 return; |
| 633 | 635 |
| 634 if (!instant_tab_ && !overlay_) | 636 if (!instant_tab_ && !overlay_) |
| 635 return; | 637 return; |
| 636 | 638 |
| 637 // We manually reset the state here since the JS is not expected to do it. | 639 // We manually reset the state here since the JS is not expected to do it. |
| 638 // TODO(sreeram): Handle the case where user_text is now a URL | 640 // TODO(sreeram): Handle the case where user_text is now a URL |
| 639 last_match_was_search_ = AutocompleteMatch::IsSearchType(match.type) && | 641 last_match_was_search_ = AutocompleteMatch::IsSearchType(match.type) && |
| 640 !full_text.empty(); | 642 !full_text.empty(); |
| 641 last_omnibox_text_ = full_text; | 643 last_omnibox_text_ = full_text; |
| 642 last_user_text_ = user_text; | 644 last_user_text_ = user_text; |
| 643 last_suggestion_ = InstantSuggestion(); | 645 last_suggestion_ = InstantSuggestion(); |
| 644 | 646 |
| 645 // Say |full_text| is "amazon.com" and |user_text| is "ama". This means the | 647 // Say |full_text| is "amazon.com" and |user_text| is "ama". This means the |
| 646 // inline autocompletion is "zon.com"; so the selection should span from | 648 // inline autocompletion is "zon.com"; so the selection should span from |
| 647 // user_text.size() to full_text.size(). The selection bounds are inverted | 649 // user_text.size() to full_text.size(). The selection bounds are inverted |
| 648 // because the caret is at the end of |user_text|, not |full_text|. | 650 // because the caret is at the end of |user_text|, not |full_text|. |
| 649 if (UseInstantTabToShowSuggestions()) { | 651 if (instant_tab_) { |
| 650 instant_tab_->CancelSelection(user_text, full_text.size(), user_text.size(), | 652 instant_tab_->CancelSelection(user_text, full_text.size(), user_text.size(), |
| 651 last_verbatim_); | 653 last_verbatim_); |
| 652 } else { | 654 } else { |
| 653 overlay_->CancelSelection(user_text, full_text.size(), user_text.size(), | 655 overlay_->CancelSelection(user_text, full_text.size(), user_text.size(), |
| 654 last_verbatim_); | 656 last_verbatim_); |
| 655 } | 657 } |
| 656 } | 658 } |
| 657 | 659 |
| 658 void InstantController::OmniboxNavigateToURL() { | 660 void InstantController::OmniboxNavigateToURL() { |
| 659 if (!extended_enabled_) | 661 if (!extended_enabled_) |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 678 return false; | 680 return false; |
| 679 | 681 |
| 680 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( | 682 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( |
| 681 "CommitIfPossible: type=%d last_omnibox_text_='%s' " | 683 "CommitIfPossible: type=%d last_omnibox_text_='%s' " |
| 682 "last_match_was_search_=%d instant_tab_=%d", type, | 684 "last_match_was_search_=%d instant_tab_=%d", type, |
| 683 UTF16ToUTF8(last_omnibox_text_).c_str(), last_match_was_search_, | 685 UTF16ToUTF8(last_omnibox_text_).c_str(), last_match_was_search_, |
| 684 instant_tab_ != NULL)); | 686 instant_tab_ != NULL)); |
| 685 | 687 |
| 686 // If we are on an already committed search results page, send a submit event | 688 // If we are on an already committed search results page, send a submit event |
| 687 // to the page, but otherwise, nothing else to do. | 689 // to the page, but otherwise, nothing else to do. |
| 688 if (UseInstantTabToShowSuggestions()) { | 690 if (instant_tab_) { |
| 689 if (type == INSTANT_COMMIT_PRESSED_ENTER && | 691 if (type == INSTANT_COMMIT_PRESSED_ENTER && |
| 692 !instant_tab_->IsLocal() && | |
| 690 (last_match_was_search_ || | 693 (last_match_was_search_ || |
| 691 last_suggestion_.behavior == INSTANT_COMPLETE_NEVER)) { | 694 last_suggestion_.behavior == INSTANT_COMPLETE_NEVER)) { |
| 692 last_suggestion_.text.clear(); | 695 last_suggestion_.text.clear(); |
| 693 instant_tab_->Submit(last_omnibox_text_); | 696 instant_tab_->Submit(last_omnibox_text_); |
| 694 instant_tab_->contents()->GetView()->Focus(); | 697 instant_tab_->contents()->GetView()->Focus(); |
| 695 EnsureSearchTermsAreSet(instant_tab_->contents(), last_omnibox_text_); | 698 EnsureSearchTermsAreSet(instant_tab_->contents(), last_omnibox_text_); |
| 696 return true; | 699 return true; |
| 697 } | 700 } |
| 698 return false; | 701 return false; |
| 699 } | 702 } |
| 700 | 703 |
| 701 // If the overlay is not showing at all, don't commit it. | 704 // If the overlay is not showing at all, don't commit it. |
| 702 if (!model_.mode().is_search_suggestions()) | 705 if (!model_.mode().is_search_suggestions()) |
| 703 return false; | 706 return false; |
| 704 | 707 |
| 705 // If the overlay is showing at full height (with results), commit it. | 708 // If the overlay is showing at full height (with results), commit it. |
| 706 // If it's showing at parial height, commit if it's navigating. | 709 // If it's showing at parial height, commit if it's navigating. |
| 707 if (!IsOverlayingSearchResults() && type != INSTANT_COMMIT_NAVIGATED) | 710 if (!IsOverlayingSearchResults() && type != INSTANT_COMMIT_NAVIGATED) |
| 708 return false; | 711 return false; |
| 709 | 712 |
| 710 // There may re-entrance here, from the call to browser_->CommitInstant below, | 713 // There may re-entrance here, from the call to browser_->CommitInstant below, |
| 711 // which can cause a TabDeactivated notification which gets back here. | 714 // which can cause a TabDeactivated notification which gets back here. |
| 712 // In this case, overlay_->ReleaseContents() was called already. | 715 // In this case, overlay_->ReleaseContents() was called already. |
| 713 if (!GetOverlayContents()) | 716 if (!GetOverlayContents()) |
| 714 return false; | 717 return false; |
| 715 | 718 |
| 716 // Never commit the local overlay. | 719 // Never commit the local overlay. |
| 717 if (overlay_->IsLocalOverlay()) | 720 if (overlay_->IsLocal()) |
| 718 return false; | 721 return false; |
| 719 | 722 |
| 720 if (type == INSTANT_COMMIT_FOCUS_LOST) { | 723 if (type == INSTANT_COMMIT_FOCUS_LOST) { |
| 721 // Extended mode doesn't need or use the Cancel message. | 724 // Extended mode doesn't need or use the Cancel message. |
| 722 if (!extended_enabled_) | 725 if (!extended_enabled_) |
| 723 overlay_->Cancel(last_omnibox_text_); | 726 overlay_->Cancel(last_omnibox_text_); |
| 724 } else if (type != INSTANT_COMMIT_NAVIGATED) { | 727 } else if (type != INSTANT_COMMIT_NAVIGATED) { |
| 725 overlay_->Submit(last_omnibox_text_); | 728 overlay_->Submit(last_omnibox_text_); |
| 726 } | 729 } |
| 727 | 730 |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 946 #if defined(USE_AURA) | 949 #if defined(USE_AURA) |
| 947 // On aura the omnibox only receives a focus lost if we initiate the focus | 950 // On aura the omnibox only receives a focus lost if we initiate the focus |
| 948 // change. This does that. | 951 // change. This does that. |
| 949 if (!model_.mode().is_default()) | 952 if (!model_.mode().is_default()) |
| 950 browser_->InstantOverlayFocused(); | 953 browser_->InstantOverlayFocused(); |
| 951 #endif | 954 #endif |
| 952 } | 955 } |
| 953 | 956 |
| 954 void InstantController::ReloadOverlayIfStale() { | 957 void InstantController::ReloadOverlayIfStale() { |
| 955 // The local overlay is never stale. | 958 // The local overlay is never stale. |
| 956 if (overlay_ && overlay_->IsLocalOverlay()) | 959 if (overlay_ && overlay_->IsLocal()) |
| 957 return; | 960 return; |
| 958 | 961 |
| 959 // If the overlay is showing or the omnibox has focus, don't delete the | 962 // If the overlay is showing or the omnibox has focus, don't delete the |
| 960 // overlay. It will get refreshed the next time the overlay is hidden or the | 963 // overlay. It will get refreshed the next time the overlay is hidden or the |
| 961 // omnibox loses focus. | 964 // omnibox loses focus. |
| 962 if ((!overlay_ || overlay_->is_stale()) && | 965 if ((!overlay_ || overlay_->is_stale()) && |
| 963 omnibox_focus_state_ == OMNIBOX_FOCUS_NONE && | 966 omnibox_focus_state_ == OMNIBOX_FOCUS_NONE && |
| 964 model_.mode().is_default()) { | 967 model_.mode().is_default()) { |
| 965 overlay_.reset(); | 968 overlay_.reset(); |
| 966 EnsureOverlayIsCurrent(false); | 969 EnsureOverlayIsCurrent(false); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1136 } | 1139 } |
| 1137 | 1140 |
| 1138 void InstantController::SetSuggestions( | 1141 void InstantController::SetSuggestions( |
| 1139 const content::WebContents* contents, | 1142 const content::WebContents* contents, |
| 1140 const std::vector<InstantSuggestion>& suggestions) { | 1143 const std::vector<InstantSuggestion>& suggestions) { |
| 1141 LOG_INSTANT_DEBUG_EVENT(this, "SetSuggestions"); | 1144 LOG_INSTANT_DEBUG_EVENT(this, "SetSuggestions"); |
| 1142 | 1145 |
| 1143 // Ignore if the message is from an unexpected source. | 1146 // Ignore if the message is from an unexpected source. |
| 1144 if (IsContentsFrom(ntp(), contents)) | 1147 if (IsContentsFrom(ntp(), contents)) |
| 1145 return; | 1148 return; |
| 1146 if (UseInstantTabToShowSuggestions() && | 1149 if (instant_tab_ && !IsContentsFrom(instant_tab(), contents)) |
| 1147 !IsContentsFrom(instant_tab(), contents)) | |
| 1148 return; | 1150 return; |
| 1149 if (IsContentsFrom(overlay(), contents) && | 1151 if (IsContentsFrom(overlay(), contents) && |
| 1150 !allow_overlay_to_show_search_suggestions_) | 1152 !allow_overlay_to_show_search_suggestions_) |
| 1151 return; | 1153 return; |
| 1152 | 1154 |
| 1153 InstantSuggestion suggestion; | 1155 InstantSuggestion suggestion; |
| 1154 if (!suggestions.empty()) | 1156 if (!suggestions.empty()) |
| 1155 suggestion = suggestions[0]; | 1157 suggestion = suggestions[0]; |
| 1156 | 1158 |
| 1157 // TODO(samarth): allow InstantTabs to call SetSuggestions() from the NTP once | 1159 // TODO(samarth): allow InstantTabs to call SetSuggestions() from the NTP once |
| 1158 // that is better supported. | 1160 // that is better supported. |
| 1159 bool can_use_instant_tab = UseInstantTabToShowSuggestions() && | 1161 bool can_use_instant_tab = instant_tab_ && search_mode_.is_search(); |
| 1160 search_mode_.is_search(); | |
| 1161 bool can_use_overlay = search_mode_.is_search_suggestions() && | 1162 bool can_use_overlay = search_mode_.is_search_suggestions() && |
| 1162 !last_omnibox_text_.empty(); | 1163 !last_omnibox_text_.empty(); |
| 1163 if (!can_use_instant_tab && !can_use_overlay) | 1164 if (!can_use_instant_tab && !can_use_overlay) |
| 1164 return; | 1165 return; |
| 1165 | 1166 |
| 1166 if (suggestion.behavior == INSTANT_COMPLETE_REPLACE) { | 1167 if (suggestion.behavior == INSTANT_COMPLETE_REPLACE) { |
| 1167 // We don't get an Update() when changing the omnibox due to a REPLACE | 1168 // We don't get an Update() when changing the omnibox due to a REPLACE |
| 1168 // suggestion (so that we don't inadvertently cause the overlay to change | 1169 // suggestion (so that we don't inadvertently cause the overlay to change |
| 1169 // what it's showing, as the user arrows up/down through the page-provided | 1170 // what it's showing, as the user arrows up/down through the page-provided |
| 1170 // suggestions). So, update these state variables here. | 1171 // suggestions). So, update these state variables here. |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1285 else if (!IsViewInContents(GetViewGainingFocus(view_gaining_focus), | 1286 else if (!IsViewInContents(GetViewGainingFocus(view_gaining_focus), |
| 1286 overlay_->contents())) | 1287 overlay_->contents())) |
| 1287 HideOverlay(); | 1288 HideOverlay(); |
| 1288 #endif | 1289 #endif |
| 1289 } | 1290 } |
| 1290 | 1291 |
| 1291 void InstantController::ResetNTP(bool ignore_blacklist, bool use_local_ntp) { | 1292 void InstantController::ResetNTP(bool ignore_blacklist, bool use_local_ntp) { |
| 1292 std::string instant_url; | 1293 std::string instant_url; |
| 1293 if (use_local_ntp || | 1294 if (use_local_ntp || |
| 1294 !GetInstantURL(browser_->profile(), ignore_blacklist, &instant_url)) | 1295 !GetInstantURL(browser_->profile(), ignore_blacklist, &instant_url)) |
| 1295 instant_url = chrome::kChromeSearchLocalNtpUrl; | 1296 instant_url = chrome::GetLocalInstantURL(browser_->profile()).spec(); |
| 1296 ntp_.reset(new InstantNTP(this, instant_url)); | 1297 ntp_.reset(new InstantNTP(this, instant_url)); |
| 1297 ntp_->InitContents(browser_->profile(), browser_->GetActiveWebContents(), | 1298 ntp_->InitContents(browser_->profile(), browser_->GetActiveWebContents(), |
| 1298 base::Bind(&InstantController::ResetNTP, | 1299 base::Bind(&InstantController::ResetNTP, |
| 1299 base::Unretained(this), false, false)); | 1300 base::Unretained(this), false, false)); |
| 1300 } | 1301 } |
| 1301 | 1302 |
| 1302 bool InstantController::EnsureOverlayIsCurrent(bool ignore_blacklist) { | 1303 bool InstantController::EnsureOverlayIsCurrent(bool ignore_blacklist) { |
| 1303 // If there's no active tab, the browser is closing. | 1304 // If there's no active tab, the browser is closing. |
| 1304 const content::WebContents* active_tab = browser_->GetActiveWebContents(); | 1305 const content::WebContents* active_tab = browser_->GetActiveWebContents(); |
| 1305 if (!active_tab) | 1306 if (!active_tab) |
| 1306 return false; | 1307 return false; |
| 1307 | 1308 |
| 1308 Profile* profile = Profile::FromBrowserContext( | 1309 Profile* profile = Profile::FromBrowserContext( |
| 1309 active_tab->GetBrowserContext()); | 1310 active_tab->GetBrowserContext()); |
| 1310 std::string instant_url; | 1311 std::string instant_url; |
| 1311 if (!GetInstantURL(profile, ignore_blacklist, &instant_url)) { | 1312 if (!GetInstantURL(profile, ignore_blacklist, &instant_url)) { |
| 1312 // If we are in extended mode, fallback to the local overlay. | 1313 // If we are in extended mode, fallback to the local overlay. |
| 1313 if (extended_enabled_) | 1314 if (extended_enabled_) |
| 1314 instant_url = chrome::kChromeSearchLocalOmniboxPopupURL; | 1315 instant_url = chrome::GetLocalInstantURL(browser_->profile()).spec(); |
| 1315 else | 1316 else |
| 1316 return false; | 1317 return false; |
| 1317 } | 1318 } |
| 1318 | 1319 |
| 1319 if (!overlay_ || overlay_->instant_url() != instant_url) | 1320 if (!overlay_ || overlay_->instant_url() != instant_url) |
| 1320 CreateOverlay(instant_url, active_tab); | 1321 CreateOverlay(instant_url, active_tab); |
| 1321 | 1322 |
| 1322 return true; | 1323 return true; |
| 1323 } | 1324 } |
| 1324 | 1325 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1386 // Send a message asking the overlay to clear out old results. | 1387 // Send a message asking the overlay to clear out old results. |
| 1387 overlay_->Update(string16(), 0, 0, true); | 1388 overlay_->Update(string16(), 0, 0, true); |
| 1388 } | 1389 } |
| 1389 | 1390 |
| 1390 // Clear the first interaction timestamp for later use. | 1391 // Clear the first interaction timestamp for later use. |
| 1391 first_interaction_time_ = base::Time(); | 1392 first_interaction_time_ = base::Time(); |
| 1392 } | 1393 } |
| 1393 | 1394 |
| 1394 void InstantController::ShowOverlay(int height, InstantSizeUnits units) { | 1395 void InstantController::ShowOverlay(int height, InstantSizeUnits units) { |
| 1395 // If we are on a committed search results page, the |overlay_| is not in use. | 1396 // If we are on a committed search results page, the |overlay_| is not in use. |
| 1396 if (UseInstantTabToShowSuggestions()) | 1397 if (instant_tab_) |
| 1397 return; | 1398 return; |
| 1398 | 1399 |
| 1399 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( | 1400 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( |
| 1400 "Show: height=%d units=%d", height, units)); | 1401 "Show: height=%d units=%d", height, units)); |
| 1401 | 1402 |
| 1402 // Must have updated omnibox after the last HideOverlay() to show suggestions. | 1403 // Must have updated omnibox after the last HideOverlay() to show suggestions. |
| 1403 if (!allow_overlay_to_show_search_suggestions_) | 1404 if (!allow_overlay_to_show_search_suggestions_) |
| 1404 return; | 1405 return; |
| 1405 | 1406 |
| 1406 // The page is trying to hide itself. Hide explicitly (i.e., don't use | 1407 // The page is trying to hide itself. Hide explicitly (i.e., don't use |
| 1407 // HideOverlay()) so that it can change its mind. | 1408 // HideOverlay()) so that it can change its mind. |
| 1408 if (height == 0) { | 1409 if (height == 0) { |
| 1409 model_.SetOverlayState(SearchMode(), 0, INSTANT_SIZE_PERCENT); | 1410 model_.SetOverlayState(SearchMode(), 0, INSTANT_SIZE_PERCENT); |
| 1410 return; | 1411 return; |
| 1411 } | 1412 } |
| 1412 | 1413 |
| 1413 // If the overlay is being shown for the first time since the user started | 1414 // If the overlay is being shown for the first time since the user started |
| 1414 // typing, record a histogram value. | 1415 // typing, record a histogram value. |
| 1415 if (!first_interaction_time_.is_null() && model_.mode().is_default()) { | 1416 if (!first_interaction_time_.is_null() && model_.mode().is_default()) { |
| 1416 base::TimeDelta delta = base::Time::Now() - first_interaction_time_; | 1417 base::TimeDelta delta = base::Time::Now() - first_interaction_time_; |
| 1417 UMA_HISTOGRAM_TIMES("Instant.TimeToFirstShow", delta); | 1418 UMA_HISTOGRAM_TIMES("Instant.TimeToFirstShow", delta); |
| 1418 } | 1419 } |
| 1419 | 1420 |
| 1420 // Show at 100% height except in the following cases: | 1421 // Show at 100% height except in the following cases: |
| 1421 // - The local overlay (omnibox popup) is being loaded. | 1422 // - The local overlay (omnibox popup) is being loaded. |
| 1422 // - Instant is disabled. The page needs to be able to show only a dropdown. | 1423 // - Instant is disabled. The page needs to be able to show only a dropdown. |
| 1423 // - The page is over a website other than search or an NTP, and is not | 1424 // - The page is over a website other than search or an NTP, and is not |
| 1424 // already showing at 100% height. | 1425 // already showing at 100% height. |
| 1425 if (overlay_->IsLocalOverlay() || !instant_enabled_ || | 1426 if (overlay_->IsLocal() || !instant_enabled_ || |
| 1426 (search_mode_.is_origin_default() && !IsFullHeight(model_))) | 1427 (search_mode_.is_origin_default() && !IsFullHeight(model_))) |
| 1427 model_.SetOverlayState(search_mode_, height, units); | 1428 model_.SetOverlayState(search_mode_, height, units); |
| 1428 else | 1429 else |
| 1429 model_.SetOverlayState(search_mode_, 100, INSTANT_SIZE_PERCENT); | 1430 model_.SetOverlayState(search_mode_, 100, INSTANT_SIZE_PERCENT); |
| 1430 | 1431 |
| 1431 // If the overlay is being shown at full height and the omnibox is not | 1432 // If the overlay is being shown at full height and the omnibox is not |
| 1432 // focused, commit right away. | 1433 // focused, commit right away. |
| 1433 if (IsFullHeight(model_) && omnibox_focus_state_ == OMNIBOX_FOCUS_NONE) | 1434 if (IsFullHeight(model_) && omnibox_focus_state_ == OMNIBOX_FOCUS_NONE) |
| 1434 CommitIfPossible(INSTANT_COMMIT_FOCUS_LOST); | 1435 CommitIfPossible(INSTANT_COMMIT_FOCUS_LOST); |
| 1435 } | 1436 } |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1631 // suggest 'nstant'. Otherwise, the user text really isn't a prefix, so | 1632 // suggest 'nstant'. Otherwise, the user text really isn't a prefix, so |
| 1632 // suggest nothing. | 1633 // suggest nothing. |
| 1633 // TODO(samarth|jered): revisit this logic. http://crbug.com/196572. | 1634 // TODO(samarth|jered): revisit this logic. http://crbug.com/196572. |
| 1634 return true; | 1635 return true; |
| 1635 } | 1636 } |
| 1636 } | 1637 } |
| 1637 | 1638 |
| 1638 return false; | 1639 return false; |
| 1639 } | 1640 } |
| 1640 | 1641 |
| 1641 bool InstantController::UseInstantTabToShowSuggestions() const { | 1642 bool InstantController::ShouldSwitchToLocalNTP() const { |
| 1642 return instant_tab_ && !instant_tab_->IsLocalNTP(); | 1643 if (!ntp_) |
| 1643 } | 1644 return true; |
| 1644 | 1645 |
| 1645 bool InstantController::ShouldSwitchToLocalNTP() const { | 1646 // Don't switch if already using the correct local NTP. |
| 1647 if (ntp_->instant_url() == chrome::GetLocalInstantURL( | |
| 1648 browser_->profile()).spec()) { | |
|
sreeram
2013/04/19 17:12:42
We never preload the local NTP. So why would this
samarth
2013/04/19 17:20:37
We only skip preloading when local_only_ is set. S
sreeram
2013/04/19 17:25:29
Yeah, we should just never preload either ntp_ or
samarth
2013/04/19 18:30:03
I'd rather do that separately too, unless you feel
sreeram
2013/04/19 18:31:57
No prob. Let me know when the other comments have
jeremycho
2013/04/19 19:55:07
Comments addressed.
On 2013/04/19 18:31:57, sreera
| |
| 1649 return false; | |
| 1650 } | |
| 1651 | |
| 1646 // If there is no Instant URL or the NTP is stale, switch. | 1652 // If there is no Instant URL or the NTP is stale, switch. |
| 1647 std::string instant_url; | 1653 std::string instant_url; |
| 1648 if (!GetInstantURL(browser_->profile(), false, &instant_url) || | 1654 if (!GetInstantURL(browser_->profile(), false, &instant_url) || |
| 1649 !chrome::MatchesOriginAndPath(GURL(ntp_->instant_url()), | 1655 !chrome::MatchesOriginAndPath(GURL(ntp_->instant_url()), |
| 1650 GURL(instant_url))) { | 1656 GURL(instant_url))) { |
| 1651 return true; | 1657 return true; |
| 1652 } | 1658 } |
| 1653 | 1659 |
| 1654 if (ntp_->supports_instant()) | 1660 if (ntp_->supports_instant()) |
| 1655 return false; | 1661 return false; |
| 1656 | 1662 |
| 1657 // If this is not window startup, switch. | 1663 // If this is not window startup, switch. |
| 1658 // TODO(shishir): This is not completely reliable. Find a better way to detect | 1664 // TODO(shishir): This is not completely reliable. Find a better way to detect |
| 1659 // startup time. | 1665 // startup time. |
| 1660 if (browser_->GetActiveWebContents()) | 1666 if (browser_->GetActiveWebContents()) |
| 1661 return true; | 1667 return true; |
| 1662 | 1668 |
| 1663 return chrome::IsAggressiveLocalNTPFallbackEnabled(); | 1669 return chrome::IsAggressiveLocalNTPFallbackEnabled(); |
| 1664 } | 1670 } |
| OLD | NEW |