Chromium Code Reviews| 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/search/instant_controller.h" | 5 #include "chrome/browser/ui/search/instant_controller.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "base/threading/thread_task_runner_handle.h" | 12 #include "base/threading/thread_task_runner_handle.h" |
| 13 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/search/instant_service.h" | 15 #include "chrome/browser/search/instant_service.h" |
| 16 #include "chrome/browser/search/instant_service_factory.h" | 16 #include "chrome/browser/search/instant_service_factory.h" |
| 17 #include "chrome/browser/search/search.h" | 17 #include "chrome/browser/search/search.h" |
| 18 #include "chrome/browser/ui/browser_instant_controller.h" | 18 #include "chrome/browser/ui/browser_instant_controller.h" |
| 19 #include "chrome/browser/ui/search/instant_tab.h" | 19 #include "chrome/browser/ui/search/instant_tab.h" |
| 20 #include "chrome/browser/ui/search/search_tab_helper.h" | 20 #include "chrome/browser/ui/search/search_tab_helper.h" |
| 21 #include "components/sessions/core/serialized_navigation_entry.h" | 21 #include "components/sessions/core/serialized_navigation_entry.h" |
| 22 #include "content/public/browser/navigation_controller.h" | 22 #include "content/public/browser/navigation_controller.h" |
|
Peter Kasting
2016/09/02 20:40:59
I think this #include is dead. Please check all o
Marc Treib
2016/09/05 12:11:16
Done.
| |
| 23 #include "content/public/browser/navigation_entry.h" | 23 #include "content/public/browser/navigation_entry.h" |
| 24 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
| 25 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
| 26 #include "url/gurl.h" | 26 #include "url/gurl.h" |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 bool IsContentsFrom(const InstantTab* page, | 30 bool IsContentsFrom(const InstantTab* page, |
| 31 const content::WebContents* contents) { | 31 const content::WebContents* contents) { |
| 32 return page && (page->web_contents() == contents); | 32 return page && (page->web_contents() == contents); |
| 33 } | 33 } |
| 34 | 34 |
| 35 // Adds a transient NavigationEntry to the supplied |contents|'s | |
| 36 // NavigationController if the page's URL has not already been updated with the | |
| 37 // supplied |search_terms|. | |
| 38 // TODO(treib): Is it safe to completely remove this? crbug.com/627747 | |
| 39 void EnsureSearchTermsAreSet(content::WebContents* contents, | |
| 40 const base::string16& search_terms) { | |
| 41 content::NavigationController* controller = &contents->GetController(); | |
| 42 | |
| 43 // If search terms are already correct or there is already a transient entry | |
| 44 // (there shouldn't be), bail out early. | |
| 45 if (search_terms.empty() || controller->GetTransientEntry()) | |
| 46 return; | |
| 47 | |
| 48 const content::NavigationEntry* entry = controller->GetLastCommittedEntry(); | |
| 49 std::unique_ptr<content::NavigationEntry> transient = | |
| 50 controller->CreateNavigationEntry( | |
| 51 entry->GetURL(), entry->GetReferrer(), entry->GetTransitionType(), | |
| 52 false, std::string(), contents->GetBrowserContext()); | |
| 53 controller->SetTransientEntry(std::move(transient)); | |
| 54 | |
| 55 SearchTabHelper::FromWebContents(contents)->NavigationEntryUpdated(); | |
| 56 } | |
| 57 | |
| 58 } // namespace | 35 } // namespace |
| 59 | 36 |
| 60 InstantController::InstantController(BrowserInstantController* browser) | 37 InstantController::InstantController(BrowserInstantController* browser) |
| 61 : browser_(browser) { | 38 : browser_(browser) { |
| 62 } | 39 } |
| 63 | 40 |
| 64 InstantController::~InstantController() { | 41 InstantController::~InstantController() { |
| 65 } | 42 } |
| 66 | 43 |
| 67 bool InstantController::SubmitQuery(const base::string16& search_terms, | |
| 68 const EmbeddedSearchRequestParams& params) { | |
| 69 if (!instant_tab_ || !instant_tab_->web_contents()) | |
| 70 return false; | |
| 71 | |
| 72 SearchTabHelper* search_tab = | |
| 73 SearchTabHelper::FromWebContents(instant_tab_->web_contents()); | |
| 74 if (!search_tab->SupportsInstant() || !search_mode_.is_origin_search()) | |
| 75 return false; | |
| 76 | |
| 77 // Use |instant_tab_| to run the query if we're already on a search results | |
| 78 // page. (NOTE: in particular, we do not send the query to NTPs.) | |
| 79 search_tab->Submit(search_terms, params); | |
| 80 instant_tab_->web_contents()->Focus(); | |
| 81 EnsureSearchTermsAreSet(instant_tab_->web_contents(), search_terms); | |
| 82 return true; | |
| 83 } | |
| 84 | |
| 85 void InstantController::SearchModeChanged(const SearchMode& old_mode, | 44 void InstantController::SearchModeChanged(const SearchMode& old_mode, |
| 86 const SearchMode& new_mode) { | 45 const SearchMode& new_mode) { |
| 87 LogDebugEvent(base::StringPrintf( | 46 LogDebugEvent(base::StringPrintf( |
| 88 "SearchModeChanged: [origin:mode] %d:%d to %d:%d", old_mode.origin, | 47 "SearchModeChanged: [origin:mode] %d:%d to %d:%d", old_mode.origin, |
| 89 old_mode.mode, new_mode.origin, new_mode.mode)); | 48 old_mode.mode, new_mode.origin, new_mode.mode)); |
| 90 | 49 |
| 91 search_mode_ = new_mode; | 50 search_mode_ = new_mode; |
| 92 ResetInstantTab(); | 51 ResetInstantTab(); |
| 93 } | 52 } |
| 94 | 53 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 167 if (instant_service) { | 126 if (instant_service) { |
| 168 instant_service->UpdateThemeInfo(); | 127 instant_service->UpdateThemeInfo(); |
| 169 instant_service->UpdateMostVisitedItemsInfo(); | 128 instant_service->UpdateMostVisitedItemsInfo(); |
| 170 } | 129 } |
| 171 } | 130 } |
| 172 } | 131 } |
| 173 | 132 |
| 174 InstantService* InstantController::GetInstantService() const { | 133 InstantService* InstantController::GetInstantService() const { |
| 175 return InstantServiceFactory::GetForProfile(browser_->profile()); | 134 return InstantServiceFactory::GetForProfile(browser_->profile()); |
| 176 } | 135 } |
| OLD | NEW |