| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/browser_instant_controller.h" | 5 #include "chrome/browser/ui/browser_instant_controller.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "chrome/browser/infobars/infobar_service.h" | 8 #include "chrome/browser/infobars/infobar_service.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/search/instant_service.h" | 10 #include "chrome/browser/search/instant_service.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 if (disposition == NEW_BACKGROUND_TAB || disposition == NEW_WINDOW || | 68 if (disposition == NEW_BACKGROUND_TAB || disposition == NEW_WINDOW || |
| 69 disposition == NEW_FOREGROUND_TAB) | 69 disposition == NEW_FOREGROUND_TAB) |
| 70 return false; | 70 return false; |
| 71 | 71 |
| 72 // The omnibox currently doesn't use other dispositions, so we don't attempt | 72 // The omnibox currently doesn't use other dispositions, so we don't attempt |
| 73 // to handle them. If you hit this DCHECK file a bug and I'll (sky) add | 73 // to handle them. If you hit this DCHECK file a bug and I'll (sky) add |
| 74 // support for the new disposition. | 74 // support for the new disposition. |
| 75 DCHECK(disposition == CURRENT_TAB) << disposition; | 75 DCHECK(disposition == CURRENT_TAB) << disposition; |
| 76 | 76 |
| 77 const base::string16& search_terms = | 77 const base::string16& search_terms = |
| 78 chrome::ExtractSearchTermsFromURL(profile(), url); | 78 search::ExtractSearchTermsFromURL(profile(), url); |
| 79 EmbeddedSearchRequestParams request_params(url); | 79 EmbeddedSearchRequestParams request_params(url); |
| 80 if (search_terms.empty()) | 80 if (search_terms.empty()) |
| 81 return false; | 81 return false; |
| 82 | 82 |
| 83 InstantSearchPrerenderer* prerenderer = | 83 InstantSearchPrerenderer* prerenderer = |
| 84 GetInstantSearchPrerenderer(profile()); | 84 GetInstantSearchPrerenderer(profile()); |
| 85 if (prerenderer) { | 85 if (prerenderer) { |
| 86 if (prerenderer->CanCommitQuery(GetActiveWebContents(), search_terms)) { | 86 if (prerenderer->CanCommitQuery(GetActiveWebContents(), search_terms)) { |
| 87 // Submit query to render the prefetched results. Browser will swap the | 87 // Submit query to render the prefetched results. Browser will swap the |
| 88 // prerendered contents with the active tab contents. | 88 // prerendered contents with the active tab contents. |
| 89 prerenderer->Commit(search_terms, request_params); | 89 prerenderer->Commit(search_terms, request_params); |
| 90 return false; | 90 return false; |
| 91 } else { | 91 } else { |
| 92 prerenderer->Cancel(); | 92 prerenderer->Cancel(); |
| 93 } | 93 } |
| 94 } | 94 } |
| 95 | 95 |
| 96 // If we will not be replacing search terms from this URL, don't send to | 96 // If we will not be replacing search terms from this URL, don't send to |
| 97 // InstantController. | 97 // InstantController. |
| 98 if (!chrome::IsQueryExtractionAllowedForURL(profile(), url)) | 98 if (!search::IsQueryExtractionAllowedForURL(profile(), url)) |
| 99 return false; | 99 return false; |
| 100 return instant_.SubmitQuery(search_terms, request_params); | 100 return instant_.SubmitQuery(search_terms, request_params); |
| 101 } | 101 } |
| 102 | 102 |
| 103 Profile* BrowserInstantController::profile() const { | 103 Profile* BrowserInstantController::profile() const { |
| 104 return browser_->profile(); | 104 return browser_->profile(); |
| 105 } | 105 } |
| 106 | 106 |
| 107 content::WebContents* BrowserInstantController::GetActiveWebContents() const { | 107 content::WebContents* BrowserInstantController::GetActiveWebContents() const { |
| 108 return browser_->tab_strip_model()->GetActiveWebContents(); | 108 return browser_->tab_strip_model()->GetActiveWebContents(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 // Send new search URLs to the renderer. | 159 // Send new search URLs to the renderer. |
| 160 content::RenderProcessHost* rph = contents->GetRenderProcessHost(); | 160 content::RenderProcessHost* rph = contents->GetRenderProcessHost(); |
| 161 instant_service->SendSearchURLsToRenderer(rph); | 161 instant_service->SendSearchURLsToRenderer(rph); |
| 162 | 162 |
| 163 if (!instant_service->IsInstantProcess(rph->GetID())) | 163 if (!instant_service->IsInstantProcess(rph->GetID())) |
| 164 continue; | 164 continue; |
| 165 | 165 |
| 166 if (google_base_url_domain_changed && | 166 if (google_base_url_domain_changed && |
| 167 SearchTabHelper::FromWebContents(contents)->model()->mode().is_ntp()) { | 167 SearchTabHelper::FromWebContents(contents)->model()->mode().is_ntp()) { |
| 168 // Replace the server NTP with the local NTP. | 168 // Replace the server NTP with the local NTP. |
| 169 content::NavigationController::LoadURLParams | 169 content::NavigationController::LoadURLParams params( |
| 170 params(chrome::GetLocalInstantURL(profile())); | 170 search::GetLocalInstantURL(profile())); |
| 171 params.should_replace_current_entry = true; | 171 params.should_replace_current_entry = true; |
| 172 params.referrer = content::Referrer(); | 172 params.referrer = content::Referrer(); |
| 173 params.transition_type = ui::PAGE_TRANSITION_RELOAD; | 173 params.transition_type = ui::PAGE_TRANSITION_RELOAD; |
| 174 contents->GetController().LoadURLWithParams(params); | 174 contents->GetController().LoadURLWithParams(params); |
| 175 } else { | 175 } else { |
| 176 // Reload the contents to ensure that it gets assigned to a | 176 // Reload the contents to ensure that it gets assigned to a |
| 177 // non-priviledged renderer. | 177 // non-priviledged renderer. |
| 178 contents->GetController().Reload(false); | 178 contents->GetController().Reload(false); |
| 179 | 179 |
| 180 // As the reload was not triggered by the user we don't want to close any | 180 // As the reload was not triggered by the user we don't want to close any |
| 181 // infobars. We have to tell the InfoBarService after the reload, | 181 // infobars. We have to tell the InfoBarService after the reload, |
| 182 // otherwise it would ignore this call when | 182 // otherwise it would ignore this call when |
| 183 // WebContentsObserver::DidStartNavigationToPendingEntry is invoked. | 183 // WebContentsObserver::DidStartNavigationToPendingEntry is invoked. |
| 184 InfoBarService::FromWebContents(contents)->set_ignore_next_reload(); | 184 InfoBarService::FromWebContents(contents)->set_ignore_next_reload(); |
| 185 } | 185 } |
| 186 } | 186 } |
| 187 } | 187 } |
| OLD | NEW |