| 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 = ShouldShowPreviewFor(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 CommandLine* cl = CommandLine::ForCurrentProcess(); |
| 178 if (cl->HasSwitch(switches::kPrerenderFromOmnibox)) { |
| 179 prerender::PrerenderManager* prerender_manager = |
| 180 tab_contents_->profile()->GetPrerenderManager(); |
| 181 if (prerender_manager) |
| 182 prerender_manager->AddPrerenderWithNoTag(match.destination_url); |
| 183 } |
| 184 |
| 185 DestroyPreviewContentsAndLeaveActive(); |
| 186 return; |
| 187 } else { |
| 188 // Just destroy the preview and cancel the update. |
| 171 DestroyPreviewContentsAndLeaveActive(); | 189 DestroyPreviewContentsAndLeaveActive(); |
| 172 return; | 190 return; |
| 173 } | 191 } |
| 174 | 192 |
| 175 if (!loader_manager_.get()) | 193 if (!loader_manager_.get()) |
| 176 loader_manager_.reset(new InstantLoaderManager(this)); | 194 loader_manager_.reset(new InstantLoaderManager(this)); |
| 177 | 195 |
| 178 if (!is_active_) { | 196 if (!is_active_) { |
| 179 is_active_ = true; | 197 is_active_ = true; |
| 180 delegate_->PrepareForInstant(); | 198 delegate_->PrepareForInstant(); |
| (...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 654 show_timer_.Stop(); | 672 show_timer_.Stop(); |
| 655 if (!new_loader->http_status_ok()) { | 673 if (!new_loader->http_status_ok()) { |
| 656 show_timer_.Start( | 674 show_timer_.Start( |
| 657 base::TimeDelta::FromMilliseconds(kShowDelayMS), | 675 base::TimeDelta::FromMilliseconds(kShowDelayMS), |
| 658 this, &InstantController::ShowTimerFired); | 676 this, &InstantController::ShowTimerFired); |
| 659 } | 677 } |
| 660 } | 678 } |
| 661 UpdateDisplayableLoader(); | 679 UpdateDisplayableLoader(); |
| 662 } | 680 } |
| 663 | 681 |
| 664 bool InstantController::ShouldShowPreviewFor(const AutocompleteMatch& match, | 682 InstantController::PreviewCondition InstantController::ShouldShowPreviewFor( |
| 665 const TemplateURL** template_url) { | 683 const AutocompleteMatch& match, const TemplateURL** template_url) { |
| 666 const TemplateURL* t_url = GetTemplateURL(match); | 684 const TemplateURL* t_url = GetTemplateURL(match); |
| 667 if (t_url) { | 685 if (t_url) { |
| 668 if (!t_url->id() || | 686 if (!t_url->id() || |
| 669 !t_url->instant_url() || | 687 !t_url->instant_url() || |
| 670 IsBlacklistedFromInstant(t_url->id()) || | 688 IsBlacklistedFromInstant(t_url->id()) || |
| 671 !t_url->instant_url()->SupportsReplacement()) { | 689 !t_url->instant_url()->SupportsReplacement()) { |
| 672 // To avoid extra load on other search engines we only enable previews if | 690 // To avoid extra load on other search engines we only enable previews if |
| 673 // they support the instant API. | 691 // they support the instant API. |
| 674 return false; | 692 return PREVIEW_CONDITION_INVALID_TEMPLATE_URL; |
| 675 } | 693 } |
| 676 } | 694 } |
| 677 *template_url = t_url; | 695 *template_url = t_url; |
| 678 | 696 |
| 679 if (match.destination_url.SchemeIs(chrome::kJavaScriptScheme)) | 697 if (match.destination_url.SchemeIs(chrome::kJavaScriptScheme)) |
| 680 return false; | 698 return PREVIEW_CONDITION_JAVASCRIPT_SCHEME; |
| 681 | 699 |
| 682 // Extension keywords don't have a real destionation URL. | 700 // Extension keywords don't have a real destination URL. |
| 683 if (match.template_url && match.template_url->IsExtensionKeyword()) | 701 if (match.template_url && match.template_url->IsExtensionKeyword()) |
| 684 return false; | 702 return PREVIEW_CONDITION_EXTENSION_KEYWORD; |
| 685 | 703 |
| 686 // Was the host blacklisted? | 704 // Was the host blacklisted? |
| 687 if (host_blacklist_ && host_blacklist_->count(match.destination_url.host())) | 705 if (host_blacklist_ && host_blacklist_->count(match.destination_url.host())) |
| 688 return false; | 706 return PREVIEW_CONDITION_BLACKLISTED; |
| 689 | 707 |
| 690 const CommandLine* cl = CommandLine::ForCurrentProcess(); | 708 const CommandLine* cl = CommandLine::ForCurrentProcess(); |
| 691 if (cl->HasSwitch(switches::kRestrictInstantToSearch) && | 709 if (cl->HasSwitch(switches::kRestrictInstantToSearch) && |
| 692 match.type != AutocompleteMatch::SEARCH_WHAT_YOU_TYPED && | 710 match.type != AutocompleteMatch::SEARCH_WHAT_YOU_TYPED && |
| 693 match.type != AutocompleteMatch::SEARCH_HISTORY && | 711 match.type != AutocompleteMatch::SEARCH_HISTORY && |
| 694 match.type != AutocompleteMatch::SEARCH_SUGGEST && | 712 match.type != AutocompleteMatch::SEARCH_SUGGEST && |
| 695 match.type != AutocompleteMatch::SEARCH_OTHER_ENGINE) { | 713 match.type != AutocompleteMatch::SEARCH_OTHER_ENGINE) { |
| 696 return false; | 714 return PREVIEW_CONDITION_INSTANT_SEARCH_ONLY; |
| 697 } | 715 } |
| 698 | 716 |
| 699 return true; | 717 return PREVIEW_CONDITION_SUCCESS; |
| 700 } | 718 } |
| 701 | 719 |
| 702 void InstantController::BlacklistFromInstant(TemplateURLID id) { | 720 void InstantController::BlacklistFromInstant(TemplateURLID id) { |
| 703 blacklisted_ids_.insert(id); | 721 blacklisted_ids_.insert(id); |
| 704 } | 722 } |
| 705 | 723 |
| 706 bool InstantController::IsBlacklistedFromInstant(TemplateURLID id) { | 724 bool InstantController::IsBlacklistedFromInstant(TemplateURLID id) { |
| 707 return blacklisted_ids_.count(id) > 0; | 725 return blacklisted_ids_.count(id) > 0; |
| 708 } | 726 } |
| 709 | 727 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 729 const TemplateURL* template_url = match.template_url; | 747 const TemplateURL* template_url = match.template_url; |
| 730 if (match.type == AutocompleteMatch::SEARCH_WHAT_YOU_TYPED || | 748 if (match.type == AutocompleteMatch::SEARCH_WHAT_YOU_TYPED || |
| 731 match.type == AutocompleteMatch::SEARCH_HISTORY || | 749 match.type == AutocompleteMatch::SEARCH_HISTORY || |
| 732 match.type == AutocompleteMatch::SEARCH_SUGGEST) { | 750 match.type == AutocompleteMatch::SEARCH_SUGGEST) { |
| 733 TemplateURLService* model = TemplateURLServiceFactory::GetForProfile( | 751 TemplateURLService* model = TemplateURLServiceFactory::GetForProfile( |
| 734 tab_contents_->profile()); | 752 tab_contents_->profile()); |
| 735 template_url = model ? model->GetDefaultSearchProvider() : NULL; | 753 template_url = model ? model->GetDefaultSearchProvider() : NULL; |
| 736 } | 754 } |
| 737 return template_url; | 755 return template_url; |
| 738 } | 756 } |
| OLD | NEW |