| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/i18n/case_conversion.h" | 8 #include "base/i18n/case_conversion.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 active_tab_is_ntp_ = active_tab_is_ntp; | 521 active_tab_is_ntp_ = active_tab_is_ntp; |
| 522 if (GetPreviewContents()) { | 522 if (GetPreviewContents()) { |
| 523 loader_->OnActiveTabModeChanged(active_tab_is_ntp_); | 523 loader_->OnActiveTabModeChanged(active_tab_is_ntp_); |
| 524 // On navigation away from the NTP, hide custom content. | 524 // On navigation away from the NTP, hide custom content. |
| 525 if (!active_tab_is_ntp_ && | 525 if (!active_tab_is_ntp_ && |
| 526 model_.preview_state() == InstantModel::CUSTOM_NTP_CONTENT) | 526 model_.preview_state() == InstantModel::CUSTOM_NTP_CONTENT) |
| 527 Hide(); | 527 Hide(); |
| 528 } | 528 } |
| 529 } | 529 } |
| 530 | 530 |
| 531 void InstantController::OnThemeChanged(const ThemeBackgroundInfo& theme_info) { |
| 532 if (loader_.get()) |
| 533 loader_->SendThemeBackgroundInfo(theme_info); |
| 534 } |
| 535 |
| 536 void InstantController::OnThemeAreaHeightChanged(int height) { |
| 537 if (loader_.get()) |
| 538 loader_->SendThemeAreaHeight(height); |
| 539 } |
| 540 |
| 531 bool InstantController::commit_on_pointer_release() const { | 541 bool InstantController::commit_on_pointer_release() const { |
| 532 return GetPreviewContents() && loader_->IsPointerDownFromActivate(); | 542 return GetPreviewContents() && loader_->IsPointerDownFromActivate(); |
| 533 } | 543 } |
| 534 | 544 |
| 535 void InstantController::SetSuggestions( | 545 void InstantController::SetSuggestions( |
| 536 InstantLoader* loader, | 546 InstantLoader* loader, |
| 537 const std::vector<InstantSuggestion>& suggestions) { | 547 const std::vector<InstantSuggestion>& suggestions) { |
| 538 if (loader_ != loader || model_.preview_state() == InstantModel::NOT_READY) | 548 if (loader_ != loader || model_.preview_state() == InstantModel::NOT_READY) |
| 539 return; | 549 return; |
| 540 | 550 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 | 663 |
| 654 void InstantController::ResetLoader(const std::string& instant_url, | 664 void InstantController::ResetLoader(const std::string& instant_url, |
| 655 const TabContents* active_tab) { | 665 const TabContents* active_tab) { |
| 656 if (GetPreviewContents() && loader_->instant_url() != instant_url) | 666 if (GetPreviewContents() && loader_->instant_url() != instant_url) |
| 657 DeleteLoader(); | 667 DeleteLoader(); |
| 658 | 668 |
| 659 if (!GetPreviewContents()) { | 669 if (!GetPreviewContents()) { |
| 660 loader_.reset(new InstantLoader(this, instant_url, active_tab)); | 670 loader_.reset(new InstantLoader(this, instant_url, active_tab)); |
| 661 loader_->Init(); | 671 loader_->Init(); |
| 662 | 672 |
| 663 // Ensure the searchbox API has the correct focus state and context. | 673 // Ensure the searchbox API has the correct focus state, context and theme- |
| 674 // related info. |
| 664 if (is_omnibox_focused_) | 675 if (is_omnibox_focused_) |
| 665 loader_->OnAutocompleteGotFocus(); | 676 loader_->OnAutocompleteGotFocus(); |
| 666 else | 677 else |
| 667 loader_->OnAutocompleteLostFocus(); | 678 loader_->OnAutocompleteLostFocus(); |
| 668 loader_->OnActiveTabModeChanged(active_tab_is_ntp_); | 679 loader_->OnActiveTabModeChanged(active_tab_is_ntp_); |
| 680 browser_->UpdateThemeRelatedInfoForPreview(); |
| 669 | 681 |
| 670 // Reset the loader timer. | 682 // Reset the loader timer. |
| 671 stale_loader_timer_.Stop(); | 683 stale_loader_timer_.Stop(); |
| 672 stale_loader_timer_.Start( | 684 stale_loader_timer_.Start( |
| 673 FROM_HERE, | 685 FROM_HERE, |
| 674 base::TimeDelta::FromMilliseconds(kStaleLoaderTimeoutMS), this, | 686 base::TimeDelta::FromMilliseconds(kStaleLoaderTimeoutMS), this, |
| 675 &InstantController::OnStaleLoader); | 687 &InstantController::OnStaleLoader); |
| 676 } | 688 } |
| 677 } | 689 } |
| 678 | 690 |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 816 } | 828 } |
| 817 | 829 |
| 818 std::map<std::string, int>::const_iterator iter = | 830 std::map<std::string, int>::const_iterator iter = |
| 819 blacklisted_urls_.find(*instant_url); | 831 blacklisted_urls_.find(*instant_url); |
| 820 if (iter != blacklisted_urls_.end() && | 832 if (iter != blacklisted_urls_.end() && |
| 821 iter->second > kMaxInstantSupportFailures) | 833 iter->second > kMaxInstantSupportFailures) |
| 822 return false; | 834 return false; |
| 823 | 835 |
| 824 return true; | 836 return true; |
| 825 } | 837 } |
| OLD | NEW |