| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_UI_SEARCH_SEARCH_H_ | |
| 6 #define CHROME_BROWSER_UI_SEARCH_SEARCH_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include <utility> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/basictypes.h" | |
| 13 #include "base/string16.h" | |
| 14 | |
| 15 class GURL; | |
| 16 class PrefRegistrySyncable; | |
| 17 class Profile; | |
| 18 class TemplateURL; | |
| 19 class TemplateURLRef; | |
| 20 | |
| 21 namespace content { | |
| 22 class NavigationEntry; | |
| 23 class WebContents; | |
| 24 } | |
| 25 | |
| 26 namespace chrome { | |
| 27 namespace search { | |
| 28 | |
| 29 // The key used to store search terms data in the NavigationEntry to be later | |
| 30 // displayed in the omnibox. With the context of the user's exact query, | |
| 31 // InstantController sets the correct search terms to be displayed. | |
| 32 extern const char kInstantExtendedSearchTermsKey[]; | |
| 33 | |
| 34 // The URL for the local omnibox popup (rendered in a WebContents). | |
| 35 extern const char kLocalOmniboxPopupURL[]; | |
| 36 | |
| 37 // Returns whether the Instant Extended API is enabled. | |
| 38 bool IsInstantExtendedAPIEnabled(); | |
| 39 | |
| 40 // Returns the value to pass to the &espv CGI parameter when loading the | |
| 41 // embedded search page from the user's default search provider. Will be | |
| 42 // 0 if the Instant Extended API is not enabled. | |
| 43 uint64 EmbeddedSearchPageVersion(); | |
| 44 | |
| 45 // Returns whether query extraction is enabled. | |
| 46 bool IsQueryExtractionEnabled(); | |
| 47 | |
| 48 // Returns the search terms attached to a specific NavigationEntry, or empty | |
| 49 // string otherwise. Does not consider IsQueryExtractionEnabled(), so most | |
| 50 // callers should use GetSearchTerms() below instead. | |
| 51 string16 GetSearchTermsFromNavigationEntry( | |
| 52 const content::NavigationEntry* entry); | |
| 53 | |
| 54 // Returns search terms if this WebContents is a search results page. It looks | |
| 55 // in the visible NavigationEntry first, to see if search terms have already | |
| 56 // been extracted. Failing that, it tries to extract search terms from the URL. | |
| 57 // Returns a blank string if search terms were not found, or if search terms | |
| 58 // extraction is disabled for this WebContents or profile. | |
| 59 string16 GetSearchTerms(const content::WebContents* contents); | |
| 60 | |
| 61 // Returns true if |url| should be rendered in the Instant renderer process. | |
| 62 bool ShouldAssignURLToInstantRenderer(const GURL& url, Profile* profile); | |
| 63 | |
| 64 // Returns true if the visible entry of |contents| is a New Tab Page rendered | |
| 65 // by Instant. A page that matches the search or Instant URL of the default | |
| 66 // search provider but does not have any search terms is considered an Instant | |
| 67 // New Tab Page. | |
| 68 bool IsInstantNTP(const content::WebContents* contents); | |
| 69 | |
| 70 // Same as IsInstantNTP but uses |nav_entry| to determine the URL for the page | |
| 71 // instead of using the visible entry. | |
| 72 bool NavEntryIsInstantNTP(const content::WebContents* contents, | |
| 73 const content::NavigationEntry* nav_entry); | |
| 74 | |
| 75 // Registers Instant-related user preferences. Called at startup. | |
| 76 void RegisterUserPrefs(PrefRegistrySyncable* registry); | |
| 77 | |
| 78 // Returns prefs::kInstantExtendedEnabled in extended mode; | |
| 79 // prefs::kInstantEnabled otherwise. | |
| 80 const char* GetInstantPrefName(); | |
| 81 | |
| 82 // Returns whether the Instant pref (as per GetInstantPrefName()) is enabled. | |
| 83 bool IsInstantPrefEnabled(Profile* profile); | |
| 84 | |
| 85 // Sets the default value of prefs::kInstantExtendedEnabled, based on field | |
| 86 // trials and the current value of prefs::kInstantEnabled. | |
| 87 void SetInstantExtendedPrefDefault(Profile* profile); | |
| 88 | |
| 89 // Returns the Instant URL of the default search engine. Returns an empty GURL | |
| 90 // if the engine doesn't have an Instant URL, or if it shouldn't be used (say | |
| 91 // because it doesn't satisfy the requirements for extended mode or if Instant | |
| 92 // is disabled through preferences). Callers must check that the returned URL is | |
| 93 // valid before using it. | |
| 94 // NOTE: This method expands the default search engine's instant_url template, | |
| 95 // so it shouldn't be called from SearchTermsData or other such code that would | |
| 96 // lead to an infinite recursion. | |
| 97 GURL GetInstantURL(Profile* profile); | |
| 98 | |
| 99 // Instant (loading a remote server page and talking to it using the searchbox | |
| 100 // API) is considered enabled if there's a valid Instant URL that can be used, | |
| 101 // so this simply returns whether GetInstantURL() is a valid URL. | |
| 102 // NOTE: This method expands the default search engine's instant_ur templatel, | |
| 103 // so it shouldn't be called from SearchTermsData or other such code that would | |
| 104 // lead to an infinite recursion. | |
| 105 bool IsInstantEnabled(Profile* profile); | |
| 106 | |
| 107 // ----------------------------------------------------- | |
| 108 // The following APIs are exposed for use in tests only. | |
| 109 // ----------------------------------------------------- | |
| 110 | |
| 111 // Forces the Instant Extended API to be enabled for tests. | |
| 112 void EnableInstantExtendedAPIForTesting(); | |
| 113 | |
| 114 // Forces query extraction to be enabled for tests. | |
| 115 void EnableQueryExtractionForTesting(); | |
| 116 | |
| 117 // Type for a collection of experiment configuration parameters. | |
| 118 typedef std::vector<std::pair<std::string, std::string> > FieldTrialFlags; | |
| 119 | |
| 120 // Given a field trial group name, parses out the group number and configuration | |
| 121 // flags. On success, |flags| will be filled with the field trial flags. |flags| | |
| 122 // must not be NULL. If not NULL, |group_number| will receive the experiment | |
| 123 // group number. | |
| 124 // Returns true iff field trial info was successfully parsed out of | |
| 125 // |group_name|. | |
| 126 // Exposed for testing only. | |
| 127 bool GetFieldTrialInfo(const std::string& group_name, | |
| 128 FieldTrialFlags* flags, | |
| 129 uint64* group_number); | |
| 130 | |
| 131 // Given a FieldTrialFlags object, returns the string value of the provided | |
| 132 // flag. | |
| 133 // Exposed for testing only. | |
| 134 std::string GetStringValueForFlagWithDefault(const std::string& flag, | |
| 135 const std::string& default_value, | |
| 136 const FieldTrialFlags& flags); | |
| 137 | |
| 138 // Given a FieldTrialFlags object, returns the uint64 value of the provided | |
| 139 // flag. | |
| 140 // Exposed for testing only. | |
| 141 uint64 GetUInt64ValueForFlagWithDefault(const std::string& flag, | |
| 142 uint64 default_value, | |
| 143 const FieldTrialFlags& flags); | |
| 144 | |
| 145 // Given a FieldTrialFlags object, returns the bool value of the provided flag. | |
| 146 // Exposed for testing only. | |
| 147 bool GetBoolValueForFlagWithDefault(const std::string& flag, | |
| 148 bool default_value, | |
| 149 const FieldTrialFlags& flags); | |
| 150 | |
| 151 // Coerces the commandline Instant URL to look like a template URL, so that we | |
| 152 // can extract search terms from it. Exposed for testing only. | |
| 153 GURL CoerceCommandLineURLToTemplateURL(const GURL& instant_url, | |
| 154 const TemplateURLRef& ref); | |
| 155 | |
| 156 } // namespace search | |
| 157 } // namespace chrome | |
| 158 | |
| 159 #endif // CHROME_BROWSER_UI_SEARCH_SEARCH_H_ | |
| OLD | NEW |