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

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

Issue 2134133002: Introduce search::IsInstantNTPURL (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/search/search.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/search/search.h" 5 #include "chrome/browser/search/search.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/metrics/field_trial.h" 10 #include "base/metrics/field_trial.h"
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 404
405 bool NavEntryIsInstantNTP(const content::WebContents* contents, 405 bool NavEntryIsInstantNTP(const content::WebContents* contents,
406 const content::NavigationEntry* entry) { 406 const content::NavigationEntry* entry) {
407 if (!contents || !entry || !IsInstantExtendedAPIEnabled()) 407 if (!contents || !entry || !IsInstantExtendedAPIEnabled())
408 return false; 408 return false;
409 409
410 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); 410 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
411 if (!IsRenderedInInstantProcess(contents, profile)) 411 if (!IsRenderedInInstantProcess(contents, profile))
412 return false; 412 return false;
413 413
414 if (entry->GetURL() == GURL(chrome::kChromeSearchLocalNtpUrl)) 414 return IsInstantNTPURL(entry->GetURL(), profile);
415 }
416
417 bool IsInstantNTPURL(const GURL& url, Profile* profile) {
418 if (!IsInstantExtendedAPIEnabled())
419 return false;
420
421 if (url == GURL(chrome::kChromeSearchLocalNtpUrl))
415 return true; 422 return true;
416 423
417 GURL new_tab_url(GetNewTabPageURL(profile)); 424 GURL new_tab_url(GetNewTabPageURL(profile));
418 return new_tab_url.is_valid() && 425 return new_tab_url.is_valid() && MatchesOriginAndPath(url, new_tab_url);
419 MatchesOriginAndPath(entry->GetURL(), new_tab_url);
420 } 426 }
421 427
422 bool IsSuggestPrefEnabled(Profile* profile) { 428 bool IsSuggestPrefEnabled(Profile* profile) {
423 return profile && !profile->IsOffTheRecord() && profile->GetPrefs() && 429 return profile && !profile->IsOffTheRecord() && profile->GetPrefs() &&
424 profile->GetPrefs()->GetBoolean(prefs::kSearchSuggestEnabled); 430 profile->GetPrefs()->GetBoolean(prefs::kSearchSuggestEnabled);
425 } 431 }
426 432
427 GURL GetInstantURL(Profile* profile, bool force_instant_results) { 433 GURL GetInstantURL(Profile* profile, bool force_instant_results) {
428 if (!IsInstantExtendedAPIEnabled() || !IsSuggestPrefEnabled(profile)) 434 if (!IsInstantExtendedAPIEnabled() || !IsSuggestPrefEnabled(profile))
429 return GURL(); 435 return GURL();
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 bool HandleNewTabURLReverseRewrite(GURL* url, 562 bool HandleNewTabURLReverseRewrite(GURL* url,
557 content::BrowserContext* browser_context) { 563 content::BrowserContext* browser_context) {
558 if (!IsInstantExtendedAPIEnabled()) 564 if (!IsInstantExtendedAPIEnabled())
559 return false; 565 return false;
560 566
561 // Do nothing in incognito. 567 // Do nothing in incognito.
562 Profile* profile = Profile::FromBrowserContext(browser_context); 568 Profile* profile = Profile::FromBrowserContext(browser_context);
563 if (profile && profile->IsOffTheRecord()) 569 if (profile && profile->IsOffTheRecord())
564 return false; 570 return false;
565 571
566 if (MatchesOriginAndPath(GURL(chrome::kChromeSearchLocalNtpUrl), *url)) { 572 if (IsInstantNTPURL(*url, profile)) {
567 *url = GURL(chrome::kChromeUINewTabURL); 573 *url = GURL(chrome::kChromeUINewTabURL);
568 return true; 574 return true;
569 } 575 }
570
571 GURL new_tab_url(GetNewTabPageURL(profile));
572 if (new_tab_url.is_valid() && MatchesOriginAndPath(new_tab_url, *url)) {
573 *url = GURL(chrome::kChromeUINewTabURL);
574 return true;
575 }
576 576
577 return false; 577 return false;
578 } 578 }
579 579
580 void SetInstantSupportStateInNavigationEntry(InstantSupportState state, 580 void SetInstantSupportStateInNavigationEntry(InstantSupportState state,
581 content::NavigationEntry* entry) { 581 content::NavigationEntry* entry) {
582 if (!entry) 582 if (!entry)
583 return; 583 return;
584 584
585 entry->SetExtraData(kInstantSupportStateKey, 585 entry->SetExtraData(kInstantSupportStateKey,
(...skipping 21 matching lines...) Expand all
607 kUseAltInstantURL, false, flags); 607 kUseAltInstantURL, false, flags);
608 } 608 }
609 609
610 bool ShouldUseSearchPathForInstant() { 610 bool ShouldUseSearchPathForInstant() {
611 FieldTrialFlags flags; 611 FieldTrialFlags flags;
612 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( 612 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault(
613 kUseSearchPathForInstant, false, flags); 613 kUseSearchPathForInstant, false, flags);
614 } 614 }
615 615
616 } // namespace search 616 } // namespace search
OLDNEW
« no previous file with comments | « chrome/browser/search/search.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698