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

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

Issue 2852693002: Remove DetermineIfPageSupportsInstant and all its plumbing (Closed)
Patch Set: rebase Created 3 years, 7 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/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/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 // We can't use WebContents::GetURL() because that uses the active entry, 67 // We can't use WebContents::GetURL() because that uses the active entry,
68 // whereas we want the visible entry. 68 // whereas we want the visible entry.
69 const content::NavigationEntry* entry = 69 const content::NavigationEntry* entry =
70 contents->GetController().GetVisibleEntry(); 70 contents->GetController().GetVisibleEntry();
71 if (entry && entry->GetVirtualURL() == chrome::kChromeUINewTabURL) 71 if (entry && entry->GetVirtualURL() == chrome::kChromeUINewTabURL)
72 return true; 72 return true;
73 73
74 return search::IsInstantNTP(contents); 74 return search::IsInstantNTP(contents);
75 } 75 }
76 76
77 bool IsLocal(const content::WebContents* contents) {
78 if (!contents)
79 return false;
80 const content::NavigationEntry* entry =
81 contents->GetController().GetVisibleEntry();
82 return entry && entry->GetURL() == chrome::kChromeSearchLocalNtpUrl;
83 }
84
85 // Returns true if |contents| are rendered inside an Instant process. 77 // Returns true if |contents| are rendered inside an Instant process.
86 bool InInstantProcess(Profile* profile, 78 bool InInstantProcess(Profile* profile,
87 const content::WebContents* contents) { 79 const content::WebContents* contents) {
88 if (!profile || !contents) 80 if (!profile || !contents)
89 return false; 81 return false;
90 82
91 InstantService* instant_service = 83 InstantService* instant_service =
92 InstantServiceFactory::GetForProfile(profile); 84 InstantServiceFactory::GetForProfile(profile);
93 return instant_service && 85 return instant_service &&
94 instant_service->IsInstantProcess( 86 instant_service->IsInstantProcess(
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 entry, l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE)); 284 entry, l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE));
293 } 285 }
294 } 286 }
295 287
296 void SearchTabHelper::DidFinishLoad(content::RenderFrameHost* render_frame_host, 288 void SearchTabHelper::DidFinishLoad(content::RenderFrameHost* render_frame_host,
297 const GURL& /* validated_url */) { 289 const GURL& /* validated_url */) {
298 if (!render_frame_host->GetParent()) { 290 if (!render_frame_host->GetParent()) {
299 if (search::IsInstantNTP(web_contents_)) 291 if (search::IsInstantNTP(web_contents_))
300 RecordNewTabLoadTime(web_contents_); 292 RecordNewTabLoadTime(web_contents_);
301 293
302 DetermineIfPageSupportsInstant(); 294 InstantSupportChanged(InInstantProcess(profile(), web_contents_));
303 } 295 }
304 } 296 }
305 297
306 void SearchTabHelper::NavigationEntryCommitted( 298 void SearchTabHelper::NavigationEntryCommitted(
307 const content::LoadCommittedDetails& load_details) { 299 const content::LoadCommittedDetails& load_details) {
308 if (!is_search_enabled_) 300 if (!is_search_enabled_)
309 return; 301 return;
310 302
311 if (!load_details.is_main_frame) 303 if (!load_details.is_main_frame)
312 return; 304 return;
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 if (omnibox_view && omnibox_view->model()->user_input_in_progress()) 484 if (omnibox_view && omnibox_view->model()->user_input_in_progress())
493 type = SearchMode::MODE_SEARCH_SUGGESTIONS; 485 type = SearchMode::MODE_SEARCH_SUGGESTIONS;
494 486
495 SearchMode old_mode(model_.mode()); 487 SearchMode old_mode(model_.mode());
496 model_.SetMode(SearchMode(type, origin)); 488 model_.SetMode(SearchMode(type, origin));
497 if (old_mode.is_ntp() != model_.mode().is_ntp()) { 489 if (old_mode.is_ntp() != model_.mode().is_ntp()) {
498 ipc_router_.SetInputInProgress(IsInputInProgress()); 490 ipc_router_.SetInputInProgress(IsInputInProgress());
499 } 491 }
500 } 492 }
501 493
502 void SearchTabHelper::DetermineIfPageSupportsInstant() {
503 if (!InInstantProcess(profile(), web_contents_)) {
504 // The page is not in the Instant process. This page does not support
505 // instant. If we send an IPC message to a page that is not in the Instant
506 // process, it will never receive it and will never respond. Therefore,
507 // return immediately.
508 InstantSupportChanged(false);
509 } else if (IsLocal(web_contents_)) {
510 // Local pages always support Instant.
511 InstantSupportChanged(true);
512 } else {
513 ipc_router_.DetermineIfPageSupportsInstant();
514 }
515 }
516
517 const OmniboxView* SearchTabHelper::GetOmniboxView() const { 494 const OmniboxView* SearchTabHelper::GetOmniboxView() const {
518 #if defined(OS_ANDROID) 495 #if defined(OS_ANDROID)
519 return nullptr; 496 return nullptr;
520 #else 497 #else
521 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); 498 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_);
522 if (!browser) 499 if (!browser)
523 return nullptr; 500 return nullptr;
524 501
525 return browser->window()->GetLocationBar()->GetOmniboxView(); 502 return browser->window()->GetLocationBar()->GetOmniboxView();
526 #endif // OS_ANDROID 503 #endif // OS_ANDROID
527 } 504 }
528 505
529 OmniboxView* SearchTabHelper::GetOmniboxView() { 506 OmniboxView* SearchTabHelper::GetOmniboxView() {
530 return const_cast<OmniboxView*>( 507 return const_cast<OmniboxView*>(
531 const_cast<const SearchTabHelper*>(this)->GetOmniboxView()); 508 const_cast<const SearchTabHelper*>(this)->GetOmniboxView());
532 } 509 }
533 510
534 Profile* SearchTabHelper::profile() const { 511 Profile* SearchTabHelper::profile() const {
535 return Profile::FromBrowserContext(web_contents_->GetBrowserContext()); 512 return Profile::FromBrowserContext(web_contents_->GetBrowserContext());
536 } 513 }
537 514
538 bool SearchTabHelper::IsInputInProgress() const { 515 bool SearchTabHelper::IsInputInProgress() const {
539 if (model_.mode().is_ntp()) 516 if (model_.mode().is_ntp())
540 return false; 517 return false;
541 const OmniboxView* omnibox_view = GetOmniboxView(); 518 const OmniboxView* omnibox_view = GetOmniboxView();
542 return omnibox_view && 519 return omnibox_view &&
543 omnibox_view->model()->focus_state() == OMNIBOX_FOCUS_VISIBLE; 520 omnibox_view->model()->focus_state() == OMNIBOX_FOCUS_VISIBLE;
544 } 521 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/search/search_tab_helper.h ('k') | chrome/browser/ui/search/search_tab_helper_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698