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

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

Issue 2152703002: Cleanup in SearchTabHelper (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
« no previous file with comments | « chrome/browser/ui/search/search_tab_helper.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/search_tab_helper.h" 5 #include "chrome/browser/ui/search/search_tab_helper.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <set> 8 #include <set>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 Profile::FromBrowserContext(web_contents_->GetBrowserContext())); 164 Profile::FromBrowserContext(web_contents_->GetBrowserContext()));
165 if (instant_service_) 165 if (instant_service_)
166 instant_service_->AddObserver(this); 166 instant_service_->AddObserver(this);
167 } 167 }
168 168
169 SearchTabHelper::~SearchTabHelper() { 169 SearchTabHelper::~SearchTabHelper() {
170 if (instant_service_) 170 if (instant_service_)
171 instant_service_->RemoveObserver(this); 171 instant_service_->RemoveObserver(this);
172 } 172 }
173 173
174 void SearchTabHelper::InitForPreloadedNTP() {
175 UpdateMode(true, true);
176 }
177
178 void SearchTabHelper::OmniboxInputStateChanged() { 174 void SearchTabHelper::OmniboxInputStateChanged() {
179 if (!is_search_enabled_) 175 if (!is_search_enabled_)
180 return; 176 return;
181 177
182 UpdateMode(false, false); 178 UpdateMode(false);
183 } 179 }
184 180
185 void SearchTabHelper::OmniboxFocusChanged(OmniboxFocusState state, 181 void SearchTabHelper::OmniboxFocusChanged(OmniboxFocusState state,
186 OmniboxFocusChangeReason reason) { 182 OmniboxFocusChangeReason reason) {
187 content::NotificationService::current()->Notify( 183 content::NotificationService::current()->Notify(
188 chrome::NOTIFICATION_OMNIBOX_FOCUS_CHANGED, 184 chrome::NOTIFICATION_OMNIBOX_FOCUS_CHANGED,
189 content::Source<SearchTabHelper>(this), 185 content::Source<SearchTabHelper>(this),
190 content::NotificationService::NoDetails()); 186 content::NotificationService::NoDetails());
191 187
192 ipc_router_.OmniboxFocusChanged(state, reason); 188 ipc_router_.OmniboxFocusChanged(state, reason);
(...skipping 19 matching lines...) Expand all
212 web_contents_->GetController().GetDefaultSessionStorageNamespace(), 208 web_contents_->GetController().GetDefaultSessionStorageNamespace(),
213 web_contents_->GetContainerBounds().size()); 209 web_contents_->GetContainerBounds().size());
214 } 210 }
215 } 211 }
216 } 212 }
217 213
218 void SearchTabHelper::NavigationEntryUpdated() { 214 void SearchTabHelper::NavigationEntryUpdated() {
219 if (!is_search_enabled_) 215 if (!is_search_enabled_)
220 return; 216 return;
221 217
222 UpdateMode(false, false); 218 UpdateMode(false);
223 }
224
225 void SearchTabHelper::InstantSupportChanged(bool instant_support) {
226 if (!is_search_enabled_)
227 return;
228
229 InstantSupportState new_state = instant_support ? INSTANT_SUPPORT_YES :
230 INSTANT_SUPPORT_NO;
231
232 model_.SetInstantSupportState(new_state);
233
234 content::NavigationEntry* entry =
235 web_contents_->GetController().GetLastCommittedEntry();
236 if (entry) {
237 search::SetInstantSupportStateInNavigationEntry(new_state, entry);
238 if (delegate_ && !instant_support)
239 delegate_->OnWebContentsInstantSupportDisabled(web_contents_);
240 }
241 } 219 }
242 220
243 bool SearchTabHelper::SupportsInstant() const { 221 bool SearchTabHelper::SupportsInstant() const {
244 return model_.instant_support() == INSTANT_SUPPORT_YES; 222 return model_.instant_support() == INSTANT_SUPPORT_YES;
245 } 223 }
246 224
247 void SearchTabHelper::SetSuggestionToPrefetch( 225 void SearchTabHelper::SetSuggestionToPrefetch(
248 const InstantSuggestion& suggestion) { 226 const InstantSuggestion& suggestion) {
249 ipc_router_.SetSuggestionToPrefetch(suggestion); 227 ipc_router_.SetSuggestionToPrefetch(suggestion);
250 } 228 }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 if (!is_search_enabled_) 317 if (!is_search_enabled_)
340 return; 318 return;
341 319
342 if (!load_details.is_main_frame) 320 if (!load_details.is_main_frame)
343 return; 321 return;
344 322
345 if (search::ShouldAssignURLToInstantRenderer(web_contents_->GetURL(), 323 if (search::ShouldAssignURLToInstantRenderer(web_contents_->GetURL(),
346 profile())) 324 profile()))
347 ipc_router_.SetDisplayInstantResults(); 325 ipc_router_.SetDisplayInstantResults();
348 326
349 UpdateMode(true, false); 327 UpdateMode(true);
350 328
351 content::NavigationEntry* entry = 329 content::NavigationEntry* entry =
352 web_contents_->GetController().GetVisibleEntry(); 330 web_contents_->GetController().GetVisibleEntry();
353 DCHECK(entry); 331 DCHECK(entry);
354 332
355 // Already determined the instant support state for this page, do not reset 333 // Already determined the instant support state for this page, do not reset
356 // the instant support state. 334 // the instant support state.
357 if (load_details.is_in_page) { 335 if (load_details.is_in_page) {
358 // When an "in-page" navigation happens, we will not receive a 336 // When an "in-page" navigation happens, we will not receive a
359 // DidFinishLoad() event. Therefore, we will not determine the Instant 337 // DidFinishLoad() event. Therefore, we will not determine the Instant
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 manager->GetAuthenticatedAccountInfo().email)); 486 manager->GetAuthenticatedAccountInfo().email));
509 } else { 487 } else {
510 ipc_router_.SendChromeIdentityCheckResult(identity, false); 488 ipc_router_.SendChromeIdentityCheckResult(identity, false);
511 } 489 }
512 } 490 }
513 491
514 void SearchTabHelper::OnHistorySyncCheck() { 492 void SearchTabHelper::OnHistorySyncCheck() {
515 ipc_router_.SendHistorySyncCheckResult(IsHistorySyncEnabled(profile())); 493 ipc_router_.SendHistorySyncCheckResult(IsHistorySyncEnabled(profile()));
516 } 494 }
517 495
518 void SearchTabHelper::UpdateMode(bool update_origin, bool is_preloaded_ntp) { 496 void SearchTabHelper::InstantSupportChanged(bool instant_support) {
497 if (!is_search_enabled_)
498 return;
499
500 InstantSupportState new_state = instant_support ? INSTANT_SUPPORT_YES :
501 INSTANT_SUPPORT_NO;
502
503 model_.SetInstantSupportState(new_state);
504
505 content::NavigationEntry* entry =
506 web_contents_->GetController().GetLastCommittedEntry();
507 if (entry) {
508 search::SetInstantSupportStateInNavigationEntry(new_state, entry);
509 if (delegate_ && !instant_support)
510 delegate_->OnWebContentsInstantSupportDisabled(web_contents_);
511 }
512 }
513
514 void SearchTabHelper::UpdateMode(bool update_origin) {
519 SearchMode::Type type = SearchMode::MODE_DEFAULT; 515 SearchMode::Type type = SearchMode::MODE_DEFAULT;
520 SearchMode::Origin origin = SearchMode::ORIGIN_DEFAULT; 516 SearchMode::Origin origin = SearchMode::ORIGIN_DEFAULT;
521 if (IsNTP(web_contents_) || is_preloaded_ntp) { 517 if (IsNTP(web_contents_)) {
522 type = SearchMode::MODE_NTP; 518 type = SearchMode::MODE_NTP;
523 origin = SearchMode::ORIGIN_NTP; 519 origin = SearchMode::ORIGIN_NTP;
524 } else if (IsSearchResults(web_contents_)) { 520 } else if (IsSearchResults(web_contents_)) {
525 type = SearchMode::MODE_SEARCH_RESULTS; 521 type = SearchMode::MODE_SEARCH_RESULTS;
526 origin = SearchMode::ORIGIN_SEARCH; 522 origin = SearchMode::ORIGIN_SEARCH;
527 } 523 }
528 if (!update_origin) 524 if (!update_origin)
529 origin = model_.mode().origin; 525 origin = model_.mode().origin;
530 526
531 OmniboxView* omnibox = GetOmniboxView(); 527 OmniboxView* omnibox = GetOmniboxView();
(...skipping 28 matching lines...) Expand all
560 556
561 bool SearchTabHelper::IsInputInProgress() const { 557 bool SearchTabHelper::IsInputInProgress() const {
562 OmniboxView* omnibox = GetOmniboxView(); 558 OmniboxView* omnibox = GetOmniboxView();
563 return !model_.mode().is_ntp() && omnibox && 559 return !model_.mode().is_ntp() && omnibox &&
564 omnibox->model()->focus_state() == OMNIBOX_FOCUS_VISIBLE; 560 omnibox->model()->focus_state() == OMNIBOX_FOCUS_VISIBLE;
565 } 561 }
566 562
567 OmniboxView* SearchTabHelper::GetOmniboxView() const { 563 OmniboxView* SearchTabHelper::GetOmniboxView() const {
568 return delegate_ ? delegate_->GetOmniboxView() : NULL; 564 return delegate_ ? delegate_->GetOmniboxView() : NULL;
569 } 565 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/search/search_tab_helper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698