Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / search / search.h
blob54356417b359afb77dcbf0dced71b21035fe71d2
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_SEARCH_SEARCH_H_
6 #define CHROME_BROWSER_SEARCH_SEARCH_H_
8 #include <string>
9 #include <utility>
10 #include <vector>
12 #include "base/basictypes.h"
13 #include "base/strings/string16.h"
14 #include "chrome/browser/ui/search/search_model.h"
16 class GURL;
17 class Profile;
18 class TemplateURL;
19 class TemplateURLRef;
21 namespace content {
22 class BrowserContext;
23 class NavigationEntry;
24 class WebContents;
27 namespace user_prefs {
28 class PrefRegistrySyncable;
31 namespace search {
33 // For reporting Cacheable NTP navigations.
34 enum CacheableNTPLoad {
35 CACHEABLE_NTP_LOAD_FAILED = 0,
36 CACHEABLE_NTP_LOAD_SUCCEEDED = 1,
37 CACHEABLE_NTP_LOAD_MAX = 2
40 enum OptInState {
41 // The user has not manually opted in/out of InstantExtended.
42 INSTANT_EXTENDED_NOT_SET,
43 // The user has opted-in to InstantExtended.
44 INSTANT_EXTENDED_OPT_IN,
45 // The user has opted-out of InstantExtended.
46 INSTANT_EXTENDED_OPT_OUT,
47 INSTANT_EXTENDED_OPT_IN_STATE_ENUM_COUNT,
50 // Returns whether the suggest is enabled for the given |profile|.
51 bool IsSuggestPrefEnabled(Profile* profile);
53 // Extracts and returns search terms from |url|. Does not consider
54 // IsQueryExtractionEnabled() and Instant support state of the page and does
55 // not check for a privileged process, so most callers should use
56 // GetSearchTerms() below instead.
57 base::string16 ExtractSearchTermsFromURL(Profile* profile, const GURL& url);
59 // Returns true if it is okay to extract search terms from |url|. |url| must
60 // have a secure scheme and must contain the search terms replacement key for
61 // the default search provider.
62 bool IsQueryExtractionAllowedForURL(Profile* profile, const GURL& url);
64 // Returns the search terms attached to a specific NavigationEntry, or empty
65 // string otherwise. Does not consider IsQueryExtractionEnabled() and does not
66 // check Instant support, so most callers should use GetSearchTerms() below
67 // instead.
68 base::string16 GetSearchTermsFromNavigationEntry(
69 const content::NavigationEntry* entry);
71 // Returns search terms if this WebContents is a search results page. It looks
72 // in the visible NavigationEntry first, to see if search terms have already
73 // been extracted. Failing that, it tries to extract search terms from the URL.
75 // Returns a blank string if search terms were not found, or if search terms
76 // extraction is disabled for this WebContents or profile, or if |contents|
77 // does not support Instant.
78 base::string16 GetSearchTerms(const content::WebContents* contents);
80 // Returns true if |url| should be rendered in the Instant renderer process.
81 bool ShouldAssignURLToInstantRenderer(const GURL& url, Profile* profile);
83 // Returns true if |contents| is rendered inside the Instant process for
84 // |profile|.
85 bool IsRenderedInInstantProcess(const content::WebContents* contents,
86 Profile* profile);
88 // Returns true if the Instant |url| should use process per site.
89 bool ShouldUseProcessPerSiteForInstantURL(const GURL& url, Profile* profile);
91 // Returns true if |url| corresponds to a New Tab page (it can be either an
92 // Instant Extended NTP or a non-extended NTP).
93 bool IsNTPURL(const GURL& url, Profile* profile);
95 // Returns true if the visible entry of |contents| is a New Tab Page rendered
96 // by Instant. A page that matches the search or Instant URL of the default
97 // search provider but does not have any search terms is considered an Instant
98 // New Tab Page.
99 bool IsInstantNTP(const content::WebContents* contents);
101 // Same as IsInstantNTP but uses |nav_entry| to determine the URL for the page
102 // instead of using the visible entry.
103 bool NavEntryIsInstantNTP(const content::WebContents* contents,
104 const content::NavigationEntry* nav_entry);
106 // Returns the Instant URL of the default search engine. Returns an empty GURL
107 // if the engine doesn't have an Instant URL, or if it shouldn't be used (say
108 // because it doesn't satisfy the requirements for extended mode or if Instant
109 // is disabled through preferences). Callers must check that the returned URL is
110 // valid before using it. |force_instant_results| forces a search page to update
111 // results incrementally even if that is otherwise disabled by google.com
112 // preferences.
113 // NOTE: This method expands the default search engine's instant_url template,
114 // so it shouldn't be called from SearchTermsData or other such code that would
115 // lead to an infinite recursion.
116 GURL GetInstantURL(Profile* profile, bool force_instant_results);
118 // Returns URLs associated with the default search engine for |profile|.
119 std::vector<GURL> GetSearchURLs(Profile* profile);
121 // Returns the default search engine base page URL to prefetch search results.
122 // Returns an empty URL if 'prefetch_results' flag is set to false in field
123 // trials.
124 GURL GetSearchResultPrefetchBaseURL(Profile* profile);
126 // Returns true if 'prerender_instant_url_on_omnibox_focus' flag is enabled in
127 // field trials to prerender Instant search base page when the omnibox is
128 // focused.
129 bool ShouldPrerenderInstantUrlOnOmniboxFocus();
131 // Returns the Local Instant URL of the New Tab Page.
132 // TODO(kmadhusu): Remove this function and update the call sites.
133 GURL GetLocalInstantURL(Profile* profile);
135 // Returns true if the local new tab page should show a Google logo and search
136 // box for users whose default search provider is Google, or false if not.
137 bool ShouldShowGoogleLocalNTP();
139 // Transforms the input |url| into its "effective URL". The returned URL
140 // facilitates grouping process-per-site. The |url| is transformed, for
141 // example, from
143 // https://www.google.com/search?espv=1&q=tractors
145 // to the privileged URL
147 // chrome-search://www.google.com/search?espv=1&q=tractors
149 // Notice the scheme change.
151 // If the input is already a privileged URL then that same URL is returned.
153 // If |url| is that of the online NTP, its host is replaced with "online-ntp".
154 // This forces the NTP and search results pages to have different SiteIntances,
155 // and hence different processes.
156 GURL GetEffectiveURLForInstant(const GURL& url, Profile* profile);
158 // Rewrites |url| if
159 // 1. |url| is kChromeUINewTabURL,
160 // 2. InstantExtended is enabled, and
161 // 3. The --instant-new-tab-url switch is set to a valid URL.
162 // |url| is rewritten to the value of --instant-new-tab-url.
163 bool HandleNewTabURLRewrite(GURL* url,
164 content::BrowserContext* browser_context);
165 // Reverses the operation from HandleNewTabURLRewrite.
166 bool HandleNewTabURLReverseRewrite(GURL* url,
167 content::BrowserContext* browser_context);
169 // Sets the Instant support |state| in the navigation |entry|.
170 void SetInstantSupportStateInNavigationEntry(InstantSupportState state,
171 content::NavigationEntry* entry);
173 // Returns the Instant support state attached to the NavigationEntry, or
174 // INSTANT_SUPPORT_UNKNOWN otherwise.
175 InstantSupportState GetInstantSupportStateFromNavigationEntry(
176 const content::NavigationEntry& entry);
178 // Returns true if the field trial flag is enabled to prefetch results on SRP.
179 bool ShouldPrefetchSearchResultsOnSRP();
181 // -----------------------------------------------------
182 // The following APIs are exposed for use in tests only.
183 // -----------------------------------------------------
185 // Returns the Cacheable New Tab Page URL for the given |profile|.
186 GURL GetNewTabPageURL(Profile* profile);
188 // Returns true if 'use_alternate_instant_url' flag is set to true in field
189 // trials to use an alternate Instant search base page URL for prefetching
190 // search results. This allows experimentation of Instant search.
191 bool ShouldUseAltInstantURL();
193 // Returns true if 'use_search_path_for_instant' flag is set to true in field
194 // trials to use an '/search' path in an alternate Instant search base page URL
195 // for prefetching search results. This allows experimentation of Instant
196 // search.
197 bool ShouldUseSearchPathForInstant();
199 } // namespace search
201 #endif // CHROME_BROWSER_SEARCH_SEARCH_H_