| Index: chrome/browser/ui/search/instant_page.cc
|
| diff --git a/chrome/browser/ui/search/instant_page.cc b/chrome/browser/ui/search/instant_page.cc
|
| index ce3fc9f81a55ba64f807a46f56915814a22f15b1..609d5a71d514e48b3bb74d84f939ec376c37fdaf 100644
|
| --- a/chrome/browser/ui/search/instant_page.cc
|
| +++ b/chrome/browser/ui/search/instant_page.cc
|
| @@ -5,6 +5,9 @@
|
| #include "chrome/browser/ui/search/instant_page.h"
|
|
|
| #include "base/utf_string_conversions.h"
|
| +#include "chrome/browser/search/search.h"
|
| +#include "chrome/browser/ui/search/search_model.h"
|
| +#include "chrome/browser/ui/search/search_tab_helper.h"
|
| #include "chrome/common/render_messages.h"
|
| #include "chrome/common/url_constants.h"
|
| #include "content/public/browser/navigation_controller.h"
|
| @@ -19,6 +22,8 @@ InstantPage::Delegate::~Delegate() {
|
| }
|
|
|
| InstantPage::~InstantPage() {
|
| + if (extended_enabled_ && contents())
|
| + GetSearchModel()->RemoveObserver(this);
|
| }
|
|
|
| bool InstantPage::IsLocal() const {
|
| @@ -121,12 +126,25 @@ void InstantPage::SendMostVisitedItems(
|
| InstantPage::InstantPage(Delegate* delegate, const std::string& instant_url)
|
| : delegate_(delegate),
|
| instant_url_(instant_url),
|
| + extended_enabled_(chrome::IsInstantExtendedAPIEnabled()),
|
| supports_instant_(false),
|
| instant_support_determined_(false) {
|
| }
|
|
|
| void InstantPage::SetContents(content::WebContents* contents) {
|
| + if (extended_enabled_ && web_contents())
|
| + GetSearchModel()->RemoveObserver(this);
|
| +
|
| Observe(contents);
|
| +
|
| + if (extended_enabled_ && contents) {
|
| + SearchModel* model = GetSearchModel();
|
| + model->AddObserver(this);
|
| +
|
| + // Already know whether the page supports instant.
|
| + if (model->instant_support() != INSTANT_SUPPORT_UNKNOWN)
|
| + SetSupportsInstant(model->instant_support() == INSTANT_SUPPORT_YES);
|
| + }
|
| }
|
|
|
| bool InstantPage::ShouldProcessRenderViewCreated() {
|
| @@ -167,7 +185,8 @@ void InstantPage::DidFinishLoad(
|
| const GURL& /* validated_url */,
|
| bool is_main_frame,
|
| content::RenderViewHost* /* render_view_host */) {
|
| - if (is_main_frame && !supports_instant_)
|
| + // For Instant Extended, SearchTabHelper keeps track of Instant support.
|
| + if (!extended_enabled_ && is_main_frame && !supports_instant_)
|
| DetermineIfPageSupportsInstant();
|
| }
|
|
|
| @@ -229,11 +248,35 @@ void InstantPage::DidFailProvisionalLoad(
|
| delegate_->InstantPageLoadFailed(contents());
|
| }
|
|
|
| +void InstantPage::ModelChanged(const SearchModel::State& old_state,
|
| + const SearchModel::State& new_state) {
|
| + if (old_state.instant_support != new_state.instant_support)
|
| + SetSupportsInstant(new_state.instant_support == INSTANT_SUPPORT_YES);
|
| +}
|
| +
|
| +SearchModel* InstantPage::GetSearchModel() {
|
| + return contents() ?
|
| + SearchTabHelper::FromWebContents(contents())->model() : NULL;
|
| +}
|
| +
|
| +void InstantPage::SetSupportsInstant(bool supports_instant) {
|
| + if (supports_instant_ == supports_instant)
|
| + return;
|
| +
|
| + supports_instant_ = supports_instant;
|
| + delegate_->InstantSupportDetermined(contents(), supports_instant);
|
| +
|
| + // If the page doesn't support Instant, stop listening to it.
|
| + if (!supports_instant)
|
| + SetContents(NULL);
|
| +}
|
| +
|
| void InstantPage::OnSetSuggestions(
|
| int page_id,
|
| const std::vector<InstantSuggestion>& suggestions) {
|
| if (contents()->IsActiveEntry(page_id)) {
|
| - OnInstantSupportDetermined(page_id, true);
|
| + SearchTabHelper::FromWebContents(contents())->
|
| + OnInstantSupportDeterminedMsgReceived(page_id, true);
|
| if (ShouldProcessSetSuggestions())
|
| delegate_->SetSuggestions(contents(), suggestions);
|
| }
|
| @@ -241,25 +284,19 @@ void InstantPage::OnSetSuggestions(
|
|
|
| void InstantPage::OnInstantSupportDetermined(int page_id,
|
| bool supports_instant) {
|
| - if (!contents()->IsActiveEntry(page_id) || supports_instant_) {
|
| - // Nothing to do if the page already supports Instant.
|
| - return;
|
| - }
|
| -
|
| - instant_support_determined_ = true;
|
| - supports_instant_ = supports_instant;
|
| - delegate_->InstantSupportDetermined(contents(), supports_instant);
|
| -
|
| - // If the page doesn't support Instant, stop listening to it.
|
| - if (!supports_instant)
|
| - Observe(NULL);
|
| + // TODO(kmadhusu): Get rid of this handler and the assoicated logic after
|
| + // committing crrev.com/14855014.
|
| + // For Instant Extended, SearchTabHelper keeps track of Instant support.
|
| + if (!extended_enabled_ && contents()->IsActiveEntry(page_id))
|
| + SetSupportsInstant(supports_instant);
|
| }
|
|
|
| void InstantPage::OnShowInstantOverlay(int page_id,
|
| int height,
|
| InstantSizeUnits units) {
|
| if (contents()->IsActiveEntry(page_id)) {
|
| - OnInstantSupportDetermined(page_id, true);
|
| + SearchTabHelper::FromWebContents(contents())->
|
| + OnInstantSupportDeterminedMsgReceived(page_id, true);
|
| if (ShouldProcessShowInstantOverlay())
|
| delegate_->ShowInstantOverlay(contents(), height, units);
|
| }
|
| @@ -267,7 +304,8 @@ void InstantPage::OnShowInstantOverlay(int page_id,
|
|
|
| void InstantPage::OnFocusOmnibox(int page_id, OmniboxFocusState state) {
|
| if (contents()->IsActiveEntry(page_id)) {
|
| - OnInstantSupportDetermined(page_id, true);
|
| + SearchTabHelper::FromWebContents(contents())->
|
| + OnInstantSupportDeterminedMsgReceived(page_id, true);
|
| if (ShouldProcessFocusOmnibox())
|
| delegate_->FocusOmnibox(contents(), state);
|
| }
|
| @@ -278,7 +316,8 @@ void InstantPage::OnSearchBoxNavigate(int page_id,
|
| content::PageTransition transition,
|
| WindowOpenDisposition disposition) {
|
| if (contents()->IsActiveEntry(page_id)) {
|
| - OnInstantSupportDetermined(page_id, true);
|
| + SearchTabHelper::FromWebContents(contents())->
|
| + OnInstantSupportDeterminedMsgReceived(page_id, true);
|
| if (ShouldProcessNavigateToURL())
|
| delegate_->NavigateToURL(contents(), url, transition, disposition);
|
| }
|
|
|