Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(121)

Side by Side Diff: chrome/browser/instant/instant_controller.cc

Issue 7210020: Added prerendering to omnibox. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rename update_instant_ and refactor conditionals. Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 {
sky 2011/06/20 20:53:49 combine else and if, eg: else if (previw_condition
dominich 2011/06/20 21:02:36 Done.
176 if (preview_condition == PREVIEW_CONDITION_INSTANT_SEARCH_ONLY) {
177 // Start Prerender of this page instead.
178 CommandLine* cl = CommandLine::ForCurrentProcess();
179 if (cl->HasSwitch(switches::kPrerenderFromOmnibox)) {
180 prerender::PrerenderManager* prerender_manager =
181 tab_contents_->profile()->GetPrerenderManager();
182 if (prerender_manager)
183 prerender_manager->AddPrerenderWithNoTag(match.destination_url);
184 }
185 }
186
171 DestroyPreviewContentsAndLeaveActive(); 187 DestroyPreviewContentsAndLeaveActive();
172 return; 188 return;
173 } 189 }
174 190
175 if (!loader_manager_.get()) 191 if (!loader_manager_.get())
176 loader_manager_.reset(new InstantLoaderManager(this)); 192 loader_manager_.reset(new InstantLoaderManager(this));
177 193
178 if (!is_active_) { 194 if (!is_active_) {
179 is_active_ = true; 195 is_active_ = true;
180 delegate_->PrepareForInstant(); 196 delegate_->PrepareForInstant();
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 show_timer_.Stop(); 670 show_timer_.Stop();
655 if (!new_loader->http_status_ok()) { 671 if (!new_loader->http_status_ok()) {
656 show_timer_.Start( 672 show_timer_.Start(
657 base::TimeDelta::FromMilliseconds(kShowDelayMS), 673 base::TimeDelta::FromMilliseconds(kShowDelayMS),
658 this, &InstantController::ShowTimerFired); 674 this, &InstantController::ShowTimerFired);
659 } 675 }
660 } 676 }
661 UpdateDisplayableLoader(); 677 UpdateDisplayableLoader();
662 } 678 }
663 679
664 bool InstantController::ShouldShowPreviewFor(const AutocompleteMatch& match, 680 InstantController::PreviewCondition InstantController::ShouldShowPreviewFor(
665 const TemplateURL** template_url) { 681 const AutocompleteMatch& match, const TemplateURL** template_url) {
666 const TemplateURL* t_url = GetTemplateURL(match); 682 const TemplateURL* t_url = GetTemplateURL(match);
667 if (t_url) { 683 if (t_url) {
668 if (!t_url->id() || 684 if (!t_url->id() ||
669 !t_url->instant_url() || 685 !t_url->instant_url() ||
670 IsBlacklistedFromInstant(t_url->id()) || 686 IsBlacklistedFromInstant(t_url->id()) ||
671 !t_url->instant_url()->SupportsReplacement()) { 687 !t_url->instant_url()->SupportsReplacement()) {
672 // To avoid extra load on other search engines we only enable previews if 688 // To avoid extra load on other search engines we only enable previews if
673 // they support the instant API. 689 // they support the instant API.
674 return false; 690 return PREVIEW_CONDITION_INVALID_TEMPLATE_URL;
675 } 691 }
676 } 692 }
677 *template_url = t_url; 693 *template_url = t_url;
678 694
679 if (match.destination_url.SchemeIs(chrome::kJavaScriptScheme)) 695 if (match.destination_url.SchemeIs(chrome::kJavaScriptScheme))
680 return false; 696 return PREVIEW_CONDITION_JAVASCRIPT_SCHEME;
681 697
682 // Extension keywords don't have a real destionation URL. 698 // Extension keywords don't have a real destination URL.
683 if (match.template_url && match.template_url->IsExtensionKeyword()) 699 if (match.template_url && match.template_url->IsExtensionKeyword())
684 return false; 700 return PREVIEW_CONDITION_EXTENSION_KEYWORD;
685 701
686 // Was the host blacklisted? 702 // Was the host blacklisted?
687 if (host_blacklist_ && host_blacklist_->count(match.destination_url.host())) 703 if (host_blacklist_ && host_blacklist_->count(match.destination_url.host()))
688 return false; 704 return PREVIEW_CONDITION_BLACKLISTED;
689 705
690 const CommandLine* cl = CommandLine::ForCurrentProcess(); 706 const CommandLine* cl = CommandLine::ForCurrentProcess();
691 if (cl->HasSwitch(switches::kRestrictInstantToSearch) && 707 if (cl->HasSwitch(switches::kRestrictInstantToSearch) &&
692 match.type != AutocompleteMatch::SEARCH_WHAT_YOU_TYPED && 708 match.type != AutocompleteMatch::SEARCH_WHAT_YOU_TYPED &&
693 match.type != AutocompleteMatch::SEARCH_HISTORY && 709 match.type != AutocompleteMatch::SEARCH_HISTORY &&
694 match.type != AutocompleteMatch::SEARCH_SUGGEST && 710 match.type != AutocompleteMatch::SEARCH_SUGGEST &&
695 match.type != AutocompleteMatch::SEARCH_OTHER_ENGINE) { 711 match.type != AutocompleteMatch::SEARCH_OTHER_ENGINE) {
696 return false; 712 return PREVIEW_CONDITION_INSTANT_SEARCH_ONLY;
697 } 713 }
698 714
699 return true; 715 return PREVIEW_CONDITION_SUCCESS;
700 } 716 }
701 717
702 void InstantController::BlacklistFromInstant(TemplateURLID id) { 718 void InstantController::BlacklistFromInstant(TemplateURLID id) {
703 blacklisted_ids_.insert(id); 719 blacklisted_ids_.insert(id);
704 } 720 }
705 721
706 bool InstantController::IsBlacklistedFromInstant(TemplateURLID id) { 722 bool InstantController::IsBlacklistedFromInstant(TemplateURLID id) {
707 return blacklisted_ids_.count(id) > 0; 723 return blacklisted_ids_.count(id) > 0;
708 } 724 }
709 725
(...skipping 19 matching lines...) Expand all
729 const TemplateURL* template_url = match.template_url; 745 const TemplateURL* template_url = match.template_url;
730 if (match.type == AutocompleteMatch::SEARCH_WHAT_YOU_TYPED || 746 if (match.type == AutocompleteMatch::SEARCH_WHAT_YOU_TYPED ||
731 match.type == AutocompleteMatch::SEARCH_HISTORY || 747 match.type == AutocompleteMatch::SEARCH_HISTORY ||
732 match.type == AutocompleteMatch::SEARCH_SUGGEST) { 748 match.type == AutocompleteMatch::SEARCH_SUGGEST) {
733 TemplateURLService* model = TemplateURLServiceFactory::GetForProfile( 749 TemplateURLService* model = TemplateURLServiceFactory::GetForProfile(
734 tab_contents_->profile()); 750 tab_contents_->profile());
735 template_url = model ? model->GetDefaultSearchProvider() : NULL; 751 template_url = model ? model->GetDefaultSearchProvider() : NULL;
736 } 752 }
737 return template_url; 753 return template_url;
738 } 754 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698