Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(314)

Side by Side Diff: chrome/browser/ui/search/instant_controller.cc

Issue 2269933002: Instant cleanup: remove MODE_SEARCH_RESULTS and ORIGIN_SEARCH (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove_url_replacement
Patch Set: review Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
18 #include "chrome/browser/ui/browser_instant_controller.h" 17 #include "chrome/browser/ui/browser_instant_controller.h"
19 #include "chrome/browser/ui/search/instant_tab.h"
20 #include "chrome/browser/ui/search/search_tab_helper.h"
21 #include "components/sessions/core/serialized_navigation_entry.h"
22 #include "content/public/browser/navigation_controller.h"
23 #include "content/public/browser/navigation_entry.h"
24 #include "content/public/browser/notification_service.h" 18 #include "content/public/browser/notification_service.h"
25 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
26 #include "url/gurl.h" 20 #include "url/gurl.h"
27 21
28 namespace { 22 namespace {
29 23
30 bool IsContentsFrom(const InstantTab* page, 24 bool IsContentsFrom(const InstantTab* page,
31 const content::WebContents* contents) { 25 const content::WebContents* contents) {
32 return page && (page->web_contents() == contents); 26 return page && (page->web_contents() == contents);
33 } 27 }
34 28
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 29 } // namespace
59 30
60 InstantController::InstantController(BrowserInstantController* browser) 31 InstantController::InstantController(BrowserInstantController* browser)
61 : browser_(browser) { 32 : browser_(browser) {
62 } 33 }
63 34
64 InstantController::~InstantController() { 35 InstantController::~InstantController() {
65 } 36 }
66 37
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, 38 void InstantController::SearchModeChanged(const SearchMode& old_mode,
86 const SearchMode& new_mode) { 39 const SearchMode& new_mode) {
87 LogDebugEvent(base::StringPrintf( 40 LogDebugEvent(base::StringPrintf(
88 "SearchModeChanged: [origin:mode] %d:%d to %d:%d", old_mode.origin, 41 "SearchModeChanged: [origin:mode] %d:%d to %d:%d", old_mode.origin,
89 old_mode.mode, new_mode.origin, new_mode.mode)); 42 old_mode.mode, new_mode.origin, new_mode.mode));
90 43
91 search_mode_ = new_mode; 44 search_mode_ = new_mode;
92 ResetInstantTab(); 45 ResetInstantTab();
93 } 46 }
94 47
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 if (instant_service) { 120 if (instant_service) {
168 instant_service->UpdateThemeInfo(); 121 instant_service->UpdateThemeInfo();
169 instant_service->UpdateMostVisitedItemsInfo(); 122 instant_service->UpdateMostVisitedItemsInfo();
170 } 123 }
171 } 124 }
172 } 125 }
173 126
174 InstantService* InstantController::GetInstantService() const { 127 InstantService* InstantController::GetInstantService() const {
175 return InstantServiceFactory::GetForProfile(browser_->profile()); 128 return InstantServiceFactory::GetForProfile(browser_->profile());
176 } 129 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/search/instant_controller.h ('k') | chrome/browser/ui/search/search_delegate_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698