| 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 "base/rand_util.h" | 10 #include "base/rand_util.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" | 25 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" |
| 26 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 26 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 27 #include "chrome/common/chrome_notification_types.h" | 27 #include "chrome/common/chrome_notification_types.h" |
| 28 #include "chrome/common/chrome_switches.h" | 28 #include "chrome/common/chrome_switches.h" |
| 29 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
| 30 #include "chrome/common/url_constants.h" | 30 #include "chrome/common/url_constants.h" |
| 31 #include "content/browser/renderer_host/render_widget_host_view.h" | 31 #include "content/browser/renderer_host/render_widget_host_view.h" |
| 32 #include "content/browser/tab_contents/tab_contents.h" | 32 #include "content/browser/tab_contents/tab_contents.h" |
| 33 #include "content/common/notification_service.h" | 33 #include "content/common/notification_service.h" |
| 34 | 34 |
| 35 namespace { |
| 36 |
| 35 // Number of ms to delay between loading urls. | 37 // Number of ms to delay between loading urls. |
| 36 static const int kUpdateDelayMS = 200; | 38 const int kUpdateDelayMS = 200; |
| 37 | 39 |
| 38 // Amount of time we delay before showing pages that have a non-200 status. | 40 // Amount of time we delay before showing pages that have a non-200 status. |
| 39 static const int kShowDelayMS = 800; | 41 const int kShowDelayMS = 800; |
| 42 |
| 43 bool IsBlacklistedUrl(const GURL& url) { |
| 44 for (int i = 0; i < chrome::kNumberOfChromeDebugURLs; ++i) { |
| 45 if (url == GURL(chrome::kChromeDebugURLs[i])) |
| 46 return true; |
| 47 } |
| 48 return false; |
| 49 } |
| 50 |
| 51 } |
| 40 | 52 |
| 41 // static | 53 // static |
| 42 InstantController::HostBlacklist* InstantController::host_blacklist_ = NULL; | 54 InstantController::HostBlacklist* InstantController::host_blacklist_ = NULL; |
| 43 | 55 |
| 44 InstantController::InstantController(Profile* profile, | 56 InstantController::InstantController(Profile* profile, |
| 45 InstantDelegate* delegate) | 57 InstantDelegate* delegate) |
| 46 : delegate_(delegate), | 58 : delegate_(delegate), |
| 47 tab_contents_(NULL), | 59 tab_contents_(NULL), |
| 48 is_active_(false), | 60 is_active_(false), |
| 49 displayable_loader_(NULL), | 61 displayable_loader_(NULL), |
| (...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 | 719 |
| 708 if (match.destination_url.SchemeIs(chrome::kJavaScriptScheme)) | 720 if (match.destination_url.SchemeIs(chrome::kJavaScriptScheme)) |
| 709 return PREVIEW_CONDITION_JAVASCRIPT_SCHEME; | 721 return PREVIEW_CONDITION_JAVASCRIPT_SCHEME; |
| 710 | 722 |
| 711 // Extension keywords don't have a real destination URL. | 723 // Extension keywords don't have a real destination URL. |
| 712 if (match.template_url && match.template_url->IsExtensionKeyword()) | 724 if (match.template_url && match.template_url->IsExtensionKeyword()) |
| 713 return PREVIEW_CONDITION_EXTENSION_KEYWORD; | 725 return PREVIEW_CONDITION_EXTENSION_KEYWORD; |
| 714 | 726 |
| 715 // Was the host blacklisted? | 727 // Was the host blacklisted? |
| 716 if (host_blacklist_ && host_blacklist_->count(match.destination_url.host())) | 728 if (host_blacklist_ && host_blacklist_->count(match.destination_url.host())) |
| 717 return PREVIEW_CONDITION_BLACKLISTED; | 729 return PREVIEW_CONDITION_BLACKLISTED_HOST; |
| 730 |
| 731 // Was the URL blacklisted? |
| 732 if (IsBlacklistedUrl(match.destination_url)) |
| 733 return PREVIEW_CONDITION_BLACKLISTED_URL; |
| 718 | 734 |
| 719 const CommandLine* cl = CommandLine::ForCurrentProcess(); | 735 const CommandLine* cl = CommandLine::ForCurrentProcess(); |
| 720 if ((cl->HasSwitch(switches::kRestrictInstantToSearch) || | 736 if ((cl->HasSwitch(switches::kRestrictInstantToSearch) || |
| 721 InstantFieldTrial::IsExperimentGroup(tab_contents_->profile())) && | 737 InstantFieldTrial::IsExperimentGroup(tab_contents_->profile())) && |
| 722 match.type != AutocompleteMatch::SEARCH_WHAT_YOU_TYPED && | 738 match.type != AutocompleteMatch::SEARCH_WHAT_YOU_TYPED && |
| 723 match.type != AutocompleteMatch::SEARCH_HISTORY && | 739 match.type != AutocompleteMatch::SEARCH_HISTORY && |
| 724 match.type != AutocompleteMatch::SEARCH_SUGGEST && | 740 match.type != AutocompleteMatch::SEARCH_SUGGEST && |
| 725 match.type != AutocompleteMatch::SEARCH_OTHER_ENGINE) { | 741 match.type != AutocompleteMatch::SEARCH_OTHER_ENGINE) { |
| 726 return PREVIEW_CONDITION_INSTANT_SEARCH_ONLY; | 742 return PREVIEW_CONDITION_INSTANT_SEARCH_ONLY; |
| 727 } | 743 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 746 if (destroy_factory_.empty()) { | 762 if (destroy_factory_.empty()) { |
| 747 MessageLoop::current()->PostTask( | 763 MessageLoop::current()->PostTask( |
| 748 FROM_HERE, destroy_factory_.NewRunnableMethod( | 764 FROM_HERE, destroy_factory_.NewRunnableMethod( |
| 749 &InstantController::DestroyLoaders)); | 765 &InstantController::DestroyLoaders)); |
| 750 } | 766 } |
| 751 } | 767 } |
| 752 | 768 |
| 753 void InstantController::DestroyLoaders() { | 769 void InstantController::DestroyLoaders() { |
| 754 loaders_to_destroy_.reset(); | 770 loaders_to_destroy_.reset(); |
| 755 } | 771 } |
| OLD | NEW |