OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
11 #include "chrome/browser/autocomplete/autocomplete_match.h" | 11 #include "chrome/browser/autocomplete/autocomplete_match.h" |
12 #include "chrome/browser/instant/instant_delegate.h" | 12 #include "chrome/browser/instant/instant_delegate.h" |
13 #include "chrome/browser/instant/instant_loader.h" | 13 #include "chrome/browser/instant/instant_loader.h" |
14 #include "chrome/browser/instant/instant_loader_manager.h" | 14 #include "chrome/browser/instant/instant_loader_manager.h" |
15 #include "chrome/browser/instant/promo_counter.h" | 15 #include "chrome/browser/instant/promo_counter.h" |
16 #include "chrome/browser/platform_util.h" | 16 #include "chrome/browser/platform_util.h" |
17 #include "chrome/browser/prefs/pref_service.h" | 17 #include "chrome/browser/prefs/pref_service.h" |
| 18 #include "chrome/browser/prerender/prerender_manager.h" |
18 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/search_engines/template_url.h" | 20 #include "chrome/browser/search_engines/template_url.h" |
20 #include "chrome/browser/search_engines/template_url_service.h" | 21 #include "chrome/browser/search_engines/template_url_service.h" |
21 #include "chrome/browser/search_engines/template_url_service_factory.h" | 22 #include "chrome/browser/search_engines/template_url_service_factory.h" |
22 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" | 23 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" |
23 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 24 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
24 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
25 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
26 #include "chrome/common/url_constants.h" | 27 #include "chrome/common/url_constants.h" |
27 #include "content/browser/renderer_host/render_widget_host_view.h" | 28 #include "content/browser/renderer_host/render_widget_host_view.h" |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 commit_on_mouse_up_ = false; | 161 commit_on_mouse_up_ = false; |
161 last_transition_type_ = match.transition; | 162 last_transition_type_ = match.transition; |
162 const TemplateURL* template_url = NULL; | 163 const TemplateURL* template_url = NULL; |
163 | 164 |
164 if (url.is_empty() || !url.is_valid()) { | 165 if (url.is_empty() || !url.is_valid()) { |
165 // Assume we were invoked with GURL() and should destroy all. | 166 // Assume we were invoked with GURL() and should destroy all. |
166 DestroyPreviewContents(); | 167 DestroyPreviewContents(); |
167 return; | 168 return; |
168 } | 169 } |
169 | 170 |
170 if (!ShouldShowPreviewFor(match, &template_url)) { | 171 PreviewCondition preview_condition = GetPreviewConditionFor(match, |
| 172 &template_url); |
| 173 if (preview_condition == PREVIEW_CONDITION_SUCCESS) { |
| 174 // Do nothing if we should show it. |
| 175 } else if (preview_condition == PREVIEW_CONDITION_INSTANT_SEARCH_ONLY) { |
| 176 // Start Prerender of this page instead. |
| 177 prerender::PrerenderManager* prerender_manager = |
| 178 tab_contents_->profile()->GetPrerenderManager(); |
| 179 if (prerender_manager) { |
| 180 prerender_manager->AddPrerender(prerender::ORIGIN_OMNIBOX, |
| 181 match.destination_url); |
| 182 } |
| 183 |
| 184 DestroyPreviewContentsAndLeaveActive(); |
| 185 return; |
| 186 } else { |
| 187 // Just destroy the preview and cancel the update. |
171 DestroyPreviewContentsAndLeaveActive(); | 188 DestroyPreviewContentsAndLeaveActive(); |
172 return; | 189 return; |
173 } | 190 } |
174 | 191 |
175 if (!loader_manager_.get()) | 192 if (!loader_manager_.get()) |
176 loader_manager_.reset(new InstantLoaderManager(this)); | 193 loader_manager_.reset(new InstantLoaderManager(this)); |
177 | 194 |
178 if (!is_active_) { | 195 if (!is_active_) { |
179 is_active_ = true; | 196 is_active_ = true; |
180 delegate_->PrepareForInstant(); | 197 delegate_->PrepareForInstant(); |
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 show_timer_.Stop(); | 671 show_timer_.Stop(); |
655 if (!new_loader->http_status_ok()) { | 672 if (!new_loader->http_status_ok()) { |
656 show_timer_.Start( | 673 show_timer_.Start( |
657 base::TimeDelta::FromMilliseconds(kShowDelayMS), | 674 base::TimeDelta::FromMilliseconds(kShowDelayMS), |
658 this, &InstantController::ShowTimerFired); | 675 this, &InstantController::ShowTimerFired); |
659 } | 676 } |
660 } | 677 } |
661 UpdateDisplayableLoader(); | 678 UpdateDisplayableLoader(); |
662 } | 679 } |
663 | 680 |
664 bool InstantController::ShouldShowPreviewFor(const AutocompleteMatch& match, | 681 InstantController::PreviewCondition InstantController::GetPreviewConditionFor( |
665 const TemplateURL** template_url) { | 682 const AutocompleteMatch& match, const TemplateURL** template_url) { |
666 const TemplateURL* t_url = GetTemplateURL(match); | 683 const TemplateURL* t_url = GetTemplateURL(match); |
667 if (t_url) { | 684 if (t_url) { |
668 if (!t_url->id() || | 685 if (!t_url->id() || |
669 !t_url->instant_url() || | 686 !t_url->instant_url() || |
670 IsBlacklistedFromInstant(t_url->id()) || | 687 IsBlacklistedFromInstant(t_url->id()) || |
671 !t_url->instant_url()->SupportsReplacement()) { | 688 !t_url->instant_url()->SupportsReplacement()) { |
672 // To avoid extra load on other search engines we only enable previews if | 689 // To avoid extra load on other search engines we only enable previews if |
673 // they support the instant API. | 690 // they support the instant API. |
674 return false; | 691 return PREVIEW_CONDITION_INVALID_TEMPLATE_URL; |
675 } | 692 } |
676 } | 693 } |
677 *template_url = t_url; | 694 *template_url = t_url; |
678 | 695 |
679 if (match.destination_url.SchemeIs(chrome::kJavaScriptScheme)) | 696 if (match.destination_url.SchemeIs(chrome::kJavaScriptScheme)) |
680 return false; | 697 return PREVIEW_CONDITION_JAVASCRIPT_SCHEME; |
681 | 698 |
682 // Extension keywords don't have a real destionation URL. | 699 // Extension keywords don't have a real destination URL. |
683 if (match.template_url && match.template_url->IsExtensionKeyword()) | 700 if (match.template_url && match.template_url->IsExtensionKeyword()) |
684 return false; | 701 return PREVIEW_CONDITION_EXTENSION_KEYWORD; |
685 | 702 |
686 // Was the host blacklisted? | 703 // Was the host blacklisted? |
687 if (host_blacklist_ && host_blacklist_->count(match.destination_url.host())) | 704 if (host_blacklist_ && host_blacklist_->count(match.destination_url.host())) |
688 return false; | 705 return PREVIEW_CONDITION_BLACKLISTED; |
689 | 706 |
690 const CommandLine* cl = CommandLine::ForCurrentProcess(); | 707 const CommandLine* cl = CommandLine::ForCurrentProcess(); |
691 if (cl->HasSwitch(switches::kRestrictInstantToSearch) && | 708 if (cl->HasSwitch(switches::kRestrictInstantToSearch) && |
692 match.type != AutocompleteMatch::SEARCH_WHAT_YOU_TYPED && | 709 match.type != AutocompleteMatch::SEARCH_WHAT_YOU_TYPED && |
693 match.type != AutocompleteMatch::SEARCH_HISTORY && | 710 match.type != AutocompleteMatch::SEARCH_HISTORY && |
694 match.type != AutocompleteMatch::SEARCH_SUGGEST && | 711 match.type != AutocompleteMatch::SEARCH_SUGGEST && |
695 match.type != AutocompleteMatch::SEARCH_OTHER_ENGINE) { | 712 match.type != AutocompleteMatch::SEARCH_OTHER_ENGINE) { |
696 return false; | 713 return PREVIEW_CONDITION_INSTANT_SEARCH_ONLY; |
697 } | 714 } |
698 | 715 |
699 return true; | 716 return PREVIEW_CONDITION_SUCCESS; |
700 } | 717 } |
701 | 718 |
702 void InstantController::BlacklistFromInstant(TemplateURLID id) { | 719 void InstantController::BlacklistFromInstant(TemplateURLID id) { |
703 blacklisted_ids_.insert(id); | 720 blacklisted_ids_.insert(id); |
704 } | 721 } |
705 | 722 |
706 bool InstantController::IsBlacklistedFromInstant(TemplateURLID id) { | 723 bool InstantController::IsBlacklistedFromInstant(TemplateURLID id) { |
707 return blacklisted_ids_.count(id) > 0; | 724 return blacklisted_ids_.count(id) > 0; |
708 } | 725 } |
709 | 726 |
(...skipping 19 matching lines...) Expand all Loading... |
729 const TemplateURL* template_url = match.template_url; | 746 const TemplateURL* template_url = match.template_url; |
730 if (match.type == AutocompleteMatch::SEARCH_WHAT_YOU_TYPED || | 747 if (match.type == AutocompleteMatch::SEARCH_WHAT_YOU_TYPED || |
731 match.type == AutocompleteMatch::SEARCH_HISTORY || | 748 match.type == AutocompleteMatch::SEARCH_HISTORY || |
732 match.type == AutocompleteMatch::SEARCH_SUGGEST) { | 749 match.type == AutocompleteMatch::SEARCH_SUGGEST) { |
733 TemplateURLService* model = TemplateURLServiceFactory::GetForProfile( | 750 TemplateURLService* model = TemplateURLServiceFactory::GetForProfile( |
734 tab_contents_->profile()); | 751 tab_contents_->profile()); |
735 template_url = model ? model->GetDefaultSearchProvider() : NULL; | 752 template_url = model ? model->GetDefaultSearchProvider() : NULL; |
736 } | 753 } |
737 return template_url; | 754 return template_url; |
738 } | 755 } |
OLD | NEW |