| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ui/search/instant_search_prerenderer.h" | 5 #include "chrome/browser/ui/search/instant_search_prerenderer.h" |
| 6 | 6 |
| 7 #include "chrome/browser/autocomplete/autocomplete_match.h" | 7 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 8 #include "chrome/browser/prerender/prerender_handle.h" | 8 #include "chrome/browser/prerender/prerender_handle.h" |
| 9 #include "chrome/browser/prerender/prerender_manager.h" | 9 #include "chrome/browser/prerender/prerender_manager.h" |
| 10 #include "chrome/browser/prerender/prerender_manager_factory.h" | 10 #include "chrome/browser/prerender/prerender_manager_factory.h" |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 } | 116 } |
| 117 | 117 |
| 118 // InstantSearchPrerenderer can commit query to the prerendered page only if | 118 // InstantSearchPrerenderer can commit query to the prerendered page only if |
| 119 // the underlying |source| page doesn't support Instant search. | 119 // the underlying |source| page doesn't support Instant search. |
| 120 return !PageSupportsInstantSearch(source); | 120 return !PageSupportsInstantSearch(source); |
| 121 } | 121 } |
| 122 | 122 |
| 123 bool InstantSearchPrerenderer::UsePrerenderedPage( | 123 bool InstantSearchPrerenderer::UsePrerenderedPage( |
| 124 const GURL& url, | 124 const GURL& url, |
| 125 chrome::NavigateParams* params) { | 125 chrome::NavigateParams* params) { |
| 126 base::string16 search_terms = chrome::GetSearchTermsFromURL(profile_, url); | 126 base::string16 search_terms = |
| 127 chrome::ExtractSearchTermsFromURL(profile_, url); |
| 127 prerender::PrerenderManager* prerender_manager = | 128 prerender::PrerenderManager* prerender_manager = |
| 128 prerender::PrerenderManagerFactory::GetForProfile(profile_); | 129 prerender::PrerenderManagerFactory::GetForProfile(profile_); |
| 129 if (search_terms.empty() || !params->target_contents || | 130 if (search_terms.empty() || !params->target_contents || |
| 130 !prerender_contents() || !prerender_manager || | 131 !prerender_contents() || !prerender_manager || |
| 131 !QueryMatchesPrefetch(search_terms)) { | 132 !QueryMatchesPrefetch(search_terms)) { |
| 132 Cancel(); | 133 Cancel(); |
| 133 return false; | 134 return false; |
| 134 } | 135 } |
| 135 | 136 |
| 136 bool success = prerender_manager->MaybeUsePrerenderedPage( | 137 bool success = prerender_manager->MaybeUsePrerenderedPage( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 149 return (prerender_handle_ && prerender_handle_->contents()) ? | 150 return (prerender_handle_ && prerender_handle_->contents()) ? |
| 150 prerender_handle_->contents()->prerender_contents() : NULL; | 151 prerender_handle_->contents()->prerender_contents() : NULL; |
| 151 } | 152 } |
| 152 | 153 |
| 153 bool InstantSearchPrerenderer::QueryMatchesPrefetch( | 154 bool InstantSearchPrerenderer::QueryMatchesPrefetch( |
| 154 const base::string16& query) const { | 155 const base::string16& query) const { |
| 155 if (chrome::ShouldReuseInstantSearchBasePage()) | 156 if (chrome::ShouldReuseInstantSearchBasePage()) |
| 156 return true; | 157 return true; |
| 157 return last_instant_suggestion_.text == query; | 158 return last_instant_suggestion_.text == query; |
| 158 } | 159 } |
| OLD | NEW |