diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-07 20:56:20 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-07 20:56:20 +0000 |
commit | 0cc0a246f3ef08594bb6184ba45c8742dc6c0e99 (patch) | |
tree | 89b52b1cfb0adbeaf0f65298cfcd0d5396bafe77 /chrome/browser/instant | |
parent | 9bcdced7fe51e35fe578d925403ec2dfbd7a0b26 (diff) | |
download | chromium_src-0cc0a246f3ef08594bb6184ba45c8742dc6c0e99.zip chromium_src-0cc0a246f3ef08594bb6184ba45c8742dc6c0e99.tar.gz chromium_src-0cc0a246f3ef08594bb6184ba45c8742dc6c0e99.tar.bz2 |
Disables instant preview for search engines that don't support the
instant API.
BUG=65590
TEST=Turn on instant, switch to a search engine other than google and
make sure you don't see any instant results.
Review URL: http://codereview.chromium.org/5599005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68514 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/instant')
-rw-r--r-- | chrome/browser/instant/instant_controller.cc | 30 | ||||
-rw-r--r-- | chrome/browser/instant/instant_controller.h | 10 |
2 files changed, 25 insertions, 15 deletions
diff --git a/chrome/browser/instant/instant_controller.cc b/chrome/browser/instant/instant_controller.cc index ebbd4b0..02872b4 100644 --- a/chrome/browser/instant/instant_controller.cc +++ b/chrome/browser/instant/instant_controller.cc @@ -146,12 +146,13 @@ void InstantController::Update(TabContentsWrapper* tab_contents, DestroyPreviewContents(); const GURL& url = match.destination_url; - tab_contents_ = tab_contents; commit_on_mouse_up_ = false; last_transition_type_ = match.transition; + const TemplateURL* template_url = NULL; - if (url.is_empty() || !url.is_valid() || !ShouldShowPreviewFor(match)) { + if (url.is_empty() || !url.is_valid() || + !ShouldShowPreviewFor(match, &template_url)) { DestroyPreviewContents(); return; } @@ -162,7 +163,6 @@ void InstantController::Update(TabContentsWrapper* tab_contents, if (!is_active_) delegate_->PrepareForInstant(); - const TemplateURL* template_url = GetTemplateURL(match); TemplateURLID template_url_id = template_url ? template_url->id() : 0; // Verbatim only makes sense if the search engines supports instant. bool real_verbatim = template_url_id ? verbatim : false; @@ -450,7 +450,21 @@ void InstantController::UpdateLoader(const TemplateURL* template_url, delegate_->ShowInstant(new_loader->preview_contents()); } -bool InstantController::ShouldShowPreviewFor(const AutocompleteMatch& match) { +bool InstantController::ShouldShowPreviewFor(const AutocompleteMatch& match, + const TemplateURL** template_url) { + const TemplateURL* t_url = GetTemplateURL(match); + if (t_url) { + if (!t_url->id() || + !t_url->instant_url() || + IsBlacklistedFromInstant(t_url->id()) || + !t_url->instant_url()->SupportsReplacement()) { + // To avoid extra load on other search engines we only enable previews if + // they support the instant API. + return false; + } + } + *template_url = t_url; + if (match.destination_url.SchemeIs(chrome::kJavaScriptScheme)) return false; @@ -492,13 +506,7 @@ const TemplateURL* InstantController::GetTemplateURL( TemplateURLModel* model = tab_contents_->profile()->GetTemplateURLModel(); template_url = model ? model->GetDefaultSearchProvider() : NULL; } - if (template_url && template_url->id() && - template_url->instant_url() && - !IsBlacklistedFromInstant(template_url->id()) && - template_url->instant_url()->SupportsReplacement()) { - return template_url; - } - return NULL; + return template_url; } // static diff --git a/chrome/browser/instant/instant_controller.h b/chrome/browser/instant/instant_controller.h index 09951da..912f1aa 100644 --- a/chrome/browser/instant/instant_controller.h +++ b/chrome/browser/instant/instant_controller.h @@ -192,8 +192,10 @@ class InstantController : public InstantLoaderDelegate { bool verbatim, string16* suggested_text); - // Returns true if we should show preview for |match|. - bool ShouldShowPreviewFor(const AutocompleteMatch& match); + // Returns true if a preview should be shown for |match|. If |match| has + // a TemplateURL that supports the instant API it is set in |template_url|. + bool ShouldShowPreviewFor(const AutocompleteMatch& match, + const TemplateURL** template_url); // Marks the specified search engine id as not supporting instant. void BlacklistFromInstant(TemplateURLID id); @@ -205,8 +207,8 @@ class InstantController : public InstantLoaderDelegate { // Clears the set of search engines blacklisted. void ClearBlacklist(); - // Returns the TemplateURL to use for the specified AutocompleteMatch, or NULL - // if non TemplateURL should be used. + // Returns the TemplateURL to use for the specified AutocompleteMatch, or + // NULL if there is no TemplateURL for |match|. const TemplateURL* GetTemplateURL(const AutocompleteMatch& match); // If instant is enabled for the specified profile the type of instant is set |