Chromium Code Reviews| 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 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 672 // To avoid extra load on other search engines we only enable previews if | 673 // To avoid extra load on other search engines we only enable previews if |
| 673 // they support the instant API. | 674 // they support the instant API. |
| 674 return false; | 675 return false; |
| 675 } | 676 } |
| 676 } | 677 } |
| 677 *template_url = t_url; | 678 *template_url = t_url; |
| 678 | 679 |
| 679 if (match.destination_url.SchemeIs(chrome::kJavaScriptScheme)) | 680 if (match.destination_url.SchemeIs(chrome::kJavaScriptScheme)) |
| 680 return false; | 681 return false; |
| 681 | 682 |
| 682 // Extension keywords don't have a real destionation URL. | 683 // Extension keywords don't have a real destination URL. |
| 683 if (match.template_url && match.template_url->IsExtensionKeyword()) | 684 if (match.template_url && match.template_url->IsExtensionKeyword()) |
| 684 return false; | 685 return false; |
| 685 | 686 |
| 686 // Was the host blacklisted? | 687 // Was the host blacklisted? |
| 687 if (host_blacklist_ && host_blacklist_->count(match.destination_url.host())) | 688 if (host_blacklist_ && host_blacklist_->count(match.destination_url.host())) |
| 688 return false; | 689 return false; |
| 689 | 690 |
| 690 const CommandLine* cl = CommandLine::ForCurrentProcess(); | 691 const CommandLine* cl = CommandLine::ForCurrentProcess(); |
| 691 if (cl->HasSwitch(switches::kRestrictInstantToSearch) && | 692 if (cl->HasSwitch(switches::kRestrictInstantToSearch) && |
| 692 match.type != AutocompleteMatch::SEARCH_WHAT_YOU_TYPED && | 693 match.type != AutocompleteMatch::SEARCH_WHAT_YOU_TYPED && |
| 693 match.type != AutocompleteMatch::SEARCH_HISTORY && | 694 match.type != AutocompleteMatch::SEARCH_HISTORY && |
| 694 match.type != AutocompleteMatch::SEARCH_SUGGEST && | 695 match.type != AutocompleteMatch::SEARCH_SUGGEST && |
| 695 match.type != AutocompleteMatch::SEARCH_OTHER_ENGINE) { | 696 match.type != AutocompleteMatch::SEARCH_OTHER_ENGINE) { |
| 697 // Start Prerender of this page instead. | |
| 698 CommandLine* cl = CommandLine::ForCurrentProcess(); | |
|
sky
2011/06/20 19:29:24
I don't like that this method has a side effect. C
dominich
2011/06/20 20:48:40
Done.
| |
| 699 if (cl->HasSwitch(switches::kPrerenderFromOmnibox)) { | |
| 700 prerender::PrerenderManager* prerender_manager = | |
| 701 tab_contents_->profile()->GetPrerenderManager(); | |
| 702 if (prerender_manager) | |
| 703 prerender_manager->AddPrerenderWithNoTag(match.destination_url); | |
| 704 } | |
| 696 return false; | 705 return false; |
| 697 } | 706 } |
| 698 | 707 |
| 699 return true; | 708 return true; |
| 700 } | 709 } |
| 701 | 710 |
| 702 void InstantController::BlacklistFromInstant(TemplateURLID id) { | 711 void InstantController::BlacklistFromInstant(TemplateURLID id) { |
| 703 blacklisted_ids_.insert(id); | 712 blacklisted_ids_.insert(id); |
| 704 } | 713 } |
| 705 | 714 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 729 const TemplateURL* template_url = match.template_url; | 738 const TemplateURL* template_url = match.template_url; |
| 730 if (match.type == AutocompleteMatch::SEARCH_WHAT_YOU_TYPED || | 739 if (match.type == AutocompleteMatch::SEARCH_WHAT_YOU_TYPED || |
| 731 match.type == AutocompleteMatch::SEARCH_HISTORY || | 740 match.type == AutocompleteMatch::SEARCH_HISTORY || |
| 732 match.type == AutocompleteMatch::SEARCH_SUGGEST) { | 741 match.type == AutocompleteMatch::SEARCH_SUGGEST) { |
| 733 TemplateURLService* model = TemplateURLServiceFactory::GetForProfile( | 742 TemplateURLService* model = TemplateURLServiceFactory::GetForProfile( |
| 734 tab_contents_->profile()); | 743 tab_contents_->profile()); |
| 735 template_url = model ? model->GetDefaultSearchProvider() : NULL; | 744 template_url = model ? model->GetDefaultSearchProvider() : NULL; |
| 736 } | 745 } |
| 737 return template_url; | 746 return template_url; |
| 738 } | 747 } |
| OLD | NEW |