OLD | NEW |
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 #ifndef CHROME_BROWSER_SEARCH_SEARCH_H_ | 5 #ifndef CHROME_BROWSER_SEARCH_SEARCH_H_ |
6 #define CHROME_BROWSER_SEARCH_SEARCH_H_ | 6 #define CHROME_BROWSER_SEARCH_SEARCH_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
13 #include "chrome/browser/ui/search/search_model.h" | 13 #include "chrome/browser/ui/search/search_model.h" |
14 | 14 |
15 class GURL; | 15 class GURL; |
16 class Profile; | 16 class Profile; |
17 class TemplateURL; | |
18 class TemplateURLRef; | |
19 | 17 |
20 namespace content { | 18 namespace content { |
21 class BrowserContext; | 19 class BrowserContext; |
22 class NavigationEntry; | 20 class NavigationEntry; |
23 class WebContents; | 21 class WebContents; |
24 } | 22 } |
25 | 23 |
26 namespace user_prefs { | 24 namespace user_prefs { |
27 class PrefRegistrySyncable; | 25 class PrefRegistrySyncable; |
28 } | 26 } |
29 | 27 |
30 namespace search { | 28 namespace search { |
31 | 29 |
32 // For reporting Cacheable NTP navigations. | 30 // For reporting Cacheable NTP navigations. |
33 enum CacheableNTPLoad { | 31 enum CacheableNTPLoad { |
34 CACHEABLE_NTP_LOAD_FAILED = 0, | 32 CACHEABLE_NTP_LOAD_FAILED = 0, |
35 CACHEABLE_NTP_LOAD_SUCCEEDED = 1, | 33 CACHEABLE_NTP_LOAD_SUCCEEDED = 1, |
36 CACHEABLE_NTP_LOAD_MAX = 2 | 34 CACHEABLE_NTP_LOAD_MAX = 2 |
37 }; | 35 }; |
38 | 36 |
39 // Returns whether the suggest is enabled for the given |profile|. | 37 // Returns whether the suggest is enabled for the given |profile|. |
40 bool IsSuggestPrefEnabled(Profile* profile); | 38 bool IsSuggestPrefEnabled(Profile* profile); |
41 | 39 |
42 // Extracts and returns search terms from |url|. Does not consider Instant | 40 // Extracts and returns search terms from |url|. |
43 // support state of the page and does not check for a privileged process, so | |
44 // most callers should use GetSearchTerms() below instead. | |
45 base::string16 ExtractSearchTermsFromURL(Profile* profile, const GURL& url); | 41 base::string16 ExtractSearchTermsFromURL(Profile* profile, const GURL& url); |
46 | 42 |
47 // Returns true if it is okay to extract search terms from |url|. |url| must | 43 // Returns true if it is okay to extract search terms from |url|. |url| must |
48 // have a secure scheme and must contain the search terms replacement key for | 44 // have a secure scheme and must contain the search terms replacement key for |
49 // the default search provider. | 45 // the default search provider. |
50 bool IsQueryExtractionAllowedForURL(Profile* profile, const GURL& url); | 46 bool IsQueryExtractionAllowedForURL(Profile* profile, const GURL& url); |
51 | 47 |
52 // Returns the search terms attached to a specific NavigationEntry, or empty | |
53 // string otherwise. Does not check Instant support, so most callers should use | |
54 // GetSearchTerms() below instead. | |
55 base::string16 GetSearchTermsFromNavigationEntry( | |
56 const content::NavigationEntry* entry); | |
57 | |
58 // Returns search terms if this WebContents is a search results page. It looks | |
59 // in the visible NavigationEntry first, to see if search terms have already | |
60 // been extracted. Failing that, it tries to extract search terms from the URL. | |
61 // | |
62 // Returns a blank string if search terms were not found, or if search terms | |
63 // extraction is disabled for this WebContents or profile, or if |contents| | |
64 // does not support Instant. | |
65 base::string16 GetSearchTerms(const content::WebContents* contents); | |
66 | |
67 // Returns true if |url| should be rendered in the Instant renderer process. | 48 // Returns true if |url| should be rendered in the Instant renderer process. |
68 bool ShouldAssignURLToInstantRenderer(const GURL& url, Profile* profile); | 49 bool ShouldAssignURLToInstantRenderer(const GURL& url, Profile* profile); |
69 | 50 |
70 // Returns true if |contents| is rendered inside the Instant process for | 51 // Returns true if |contents| is rendered inside the Instant process for |
71 // |profile|. | 52 // |profile|. |
72 bool IsRenderedInInstantProcess(const content::WebContents* contents, | 53 bool IsRenderedInInstantProcess(const content::WebContents* contents, |
73 Profile* profile); | 54 Profile* profile); |
74 | 55 |
75 // Returns true if the Instant |url| should use process per site. | 56 // Returns true if the Instant |url| should use process per site. |
76 bool ShouldUseProcessPerSiteForInstantURL(const GURL& url, Profile* profile); | 57 bool ShouldUseProcessPerSiteForInstantURL(const GURL& url, Profile* profile); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 // Rewrites |url| to the actual NTP URL to use if | 122 // Rewrites |url| to the actual NTP URL to use if |
142 // 1. |url| is "chrome://newtab", | 123 // 1. |url| is "chrome://newtab", |
143 // 2. InstantExtended is enabled, and | 124 // 2. InstantExtended is enabled, and |
144 // 3. |browser_context| doesn't correspond to an incognito profile. | 125 // 3. |browser_context| doesn't correspond to an incognito profile. |
145 bool HandleNewTabURLRewrite(GURL* url, | 126 bool HandleNewTabURLRewrite(GURL* url, |
146 content::BrowserContext* browser_context); | 127 content::BrowserContext* browser_context); |
147 // Reverses the operation from HandleNewTabURLRewrite. | 128 // Reverses the operation from HandleNewTabURLRewrite. |
148 bool HandleNewTabURLReverseRewrite(GURL* url, | 129 bool HandleNewTabURLReverseRewrite(GURL* url, |
149 content::BrowserContext* browser_context); | 130 content::BrowserContext* browser_context); |
150 | 131 |
151 // Sets the Instant support |state| in the navigation |entry|. | |
152 void SetInstantSupportStateInNavigationEntry(InstantSupportState state, | |
153 content::NavigationEntry* entry); | |
154 | |
155 // Returns the Instant support state attached to the NavigationEntry, or | |
156 // INSTANT_SUPPORT_UNKNOWN otherwise. | |
157 InstantSupportState GetInstantSupportStateFromNavigationEntry( | |
158 const content::NavigationEntry& entry); | |
159 | |
160 // ----------------------------------------------------- | 132 // ----------------------------------------------------- |
161 // The following APIs are exposed for use in tests only. | 133 // The following APIs are exposed for use in tests only. |
162 // ----------------------------------------------------- | 134 // ----------------------------------------------------- |
163 | 135 |
164 // Returns the Cacheable New Tab Page URL for the given |profile|. | 136 // Returns the Cacheable New Tab Page URL for the given |profile|. |
165 GURL GetNewTabPageURL(Profile* profile); | 137 GURL GetNewTabPageURL(Profile* profile); |
166 | 138 |
167 } // namespace search | 139 } // namespace search |
168 | 140 |
169 #endif // CHROME_BROWSER_SEARCH_SEARCH_H_ | 141 #endif // CHROME_BROWSER_SEARCH_SEARCH_H_ |
OLD | NEW |