| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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_UI_SEARCH_SEARCH_H_ | 5 #ifndef CHROME_BROWSER_UI_SEARCH_SEARCH_H_ |
| 6 #define CHROME_BROWSER_UI_SEARCH_SEARCH_H_ | 6 #define CHROME_BROWSER_UI_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/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/string16.h" | 13 #include "base/string16.h" |
| 14 | 14 |
| 15 class GURL; | 15 class GURL; |
| 16 class Profile; | 16 class Profile; |
| 17 class TemplateURL; |
| 17 | 18 |
| 18 namespace content { | 19 namespace content { |
| 19 class NavigationEntry; | 20 class NavigationEntry; |
| 21 class WebContents; |
| 20 } | 22 } |
| 21 | 23 |
| 22 namespace chrome { | 24 namespace chrome { |
| 23 namespace search { | 25 namespace search { |
| 24 | 26 |
| 25 // The key used to store search terms data in the NavigationEntry to be later | 27 // The key used to store search terms data in the NavigationEntry to be later |
| 26 // displayed in the Omnibox. With the context of the user's exact query, | 28 // displayed in the omnibox. With the context of the user's exact query, |
| 27 // InstantController sets the correct search terms to be displayed. | 29 // InstantController sets the correct search terms to be displayed. |
| 28 extern const char kInstantExtendedSearchTermsKey[]; | 30 extern const char kInstantExtendedSearchTermsKey[]; |
| 29 | 31 |
| 32 // The URL for the local omnibox popup (rendered in a WebContents). |
| 33 extern const char kLocalOmniboxPopupURL[]; |
| 34 |
| 35 // The default value we should assign to the instant_extended.enabled pref. |
| 36 // As with other prefs, the default is used only when the user hasn't toggled |
| 37 // the pref explicitly. |
| 30 enum InstantExtendedDefault { | 38 enum InstantExtendedDefault { |
| 31 INSTANT_FORCE_ON, // Force the setting on if no other setting exists. | 39 INSTANT_DEFAULT_ON, // Default the pref to be enabled. |
| 32 INSTANT_USE_EXISTING, // Use same the value of the old instant.enabled pref. | 40 INSTANT_USE_EXISTING, // Use the current value of the instant.enabled pref. |
| 33 INSTANT_FORCE_OFF, // Force the setting off if no other setting exists. | 41 INSTANT_DEFAULT_OFF, // Default the pref to be disabled. |
| 34 }; | 42 }; |
| 35 | 43 |
| 36 // Returns an enum value indicating which mode to set the new | 44 // Returns an enum value indicating which mode to set the new |
| 37 // instant_extended.enabled pref to by default. | 45 // instant_extended.enabled pref to by default. |
| 38 InstantExtendedDefault GetInstantExtendedDefaultSetting(); | 46 InstantExtendedDefault GetInstantExtendedDefaultSetting(); |
| 39 | 47 |
| 40 // Returns whether the Instant extended API is enabled for the given |profile|. | 48 // Returns whether the Instant Extended API is enabled in this profile. |
| 41 // |profile| may not be NULL. | 49 bool IsInstantExtendedAPIEnabled(const Profile* profile); |
| 42 bool IsInstantExtendedAPIEnabled(Profile* profile); | |
| 43 | 50 |
| 44 // Returns the value to pass to the &espv cgi parameter when loading the | 51 // Returns the value to pass to the &espv CGI parameter when loading the |
| 45 // embedded search page from the user's default search provider. Will be | 52 // embedded search page from the user's default search provider. Will be |
| 46 // 0 if the Instant Extended API is not enabled. | 53 // 0 if the Instant Extended API is not enabled. |
| 47 uint64 EmbeddedSearchPageVersion(Profile* profile); | 54 uint64 EmbeddedSearchPageVersion(const Profile* profile); |
| 48 | 55 |
| 49 // Force the instant extended API to be enabled for tests. | 56 // Returns whether query extraction is enabled. |
| 50 void EnableInstantExtendedAPIForTesting(); | 57 bool IsQueryExtractionEnabled(const Profile* profile); |
| 51 | 58 |
| 52 // Returns whether query extraction is enabled. If | 59 // Returns the search terms attached to a specific NavigationEntry, or empty |
| 53 // |IsInstantExtendedAPIEnabled()| and the profile is not off the record, then | 60 // string otherwise. Does not consider IsQueryExtractionEnabled(), so most |
| 54 // this method will also return true. | 61 // callers should use GetSearchTerms() below instead. |
| 55 bool IsQueryExtractionEnabled(Profile* profile); | |
| 56 | |
| 57 // Force query extraction to be enabled for tests. | |
| 58 void EnableQueryExtractionForTesting(); | |
| 59 | |
| 60 // Return the search terms attached to a specific NavigationEntry, or empty | |
| 61 // string otherwise. | |
| 62 string16 GetSearchTermsFromNavigationEntry( | 62 string16 GetSearchTermsFromNavigationEntry( |
| 63 const content::NavigationEntry* entry); | 63 const content::NavigationEntry* entry); |
| 64 | 64 |
| 65 // Returns true if |url| has the same scheme, host, port and path as the | 65 // Returns search terms if this WebContents is a search results page. It looks |
| 66 // Instant URL set via --instant-url. | 66 // in the visible NavigationEntry first, to see if search terms have already |
| 67 bool IsForcedInstantURL(const GURL& url); | 67 // been extracted. Failing that, it tries to extract search terms from the URL. |
| 68 // Returns a blank string if search terms were not found, or if search terms |
| 69 // extraction is disabled for this WebContents or profile. |
| 70 string16 GetSearchTerms(const content::WebContents* contents); |
| 71 |
| 72 // Returns true if |url| should be rendered in the Instant renderer process. |
| 73 bool ShouldAssignURLToInstantRenderer(const GURL& url, Profile* profile); |
| 74 |
| 75 // ----------------------------------------------------- |
| 76 // The following APIs are exposed for use in tests only. |
| 77 // ----------------------------------------------------- |
| 78 |
| 79 // Forces the Instant Extended API to be enabled for tests. |
| 80 void EnableInstantExtendedAPIForTesting(); |
| 81 |
| 82 // Forces query extraction to be enabled for tests. |
| 83 void EnableQueryExtractionForTesting(); |
| 84 |
| 85 // Actually implements the logic for ShouldAssignURLToInstantRenderer(). |
| 86 // Exposed for testing only. |
| 87 bool ShouldAssignURLToInstantRendererImpl(const GURL& url, |
| 88 bool extended_api_enabled, |
| 89 TemplateURL* template_url); |
| 68 | 90 |
| 69 // Type for a collection of experiment configuration parameters. | 91 // Type for a collection of experiment configuration parameters. |
| 70 typedef std::vector<std::pair<std::string, std::string> > FieldTrialFlags; | 92 typedef std::vector<std::pair<std::string, std::string> > FieldTrialFlags; |
| 71 | 93 |
| 72 // Given a field trial group name, parses out the group number and configuration | 94 // Given a field trial group name, parses out the group number and configuration |
| 73 // flags. On success, |flags| will be filled with the field trial flags. |flags| | 95 // flags. On success, |flags| will be filled with the field trial flags. |flags| |
| 74 // must not be NULL. If not NULL, |group_number| will receive the experiment | 96 // must not be NULL. If not NULL, |group_number| will receive the experiment |
| 75 // group number. | 97 // group number. |
| 76 // Returns true iff field trial info was successfully parsed out of | 98 // Returns true iff field trial info was successfully parsed out of |
| 77 // |group_name|. | 99 // |group_name|. |
| 78 // Exposed for testing only. | 100 // Exposed for testing only. |
| 79 bool GetFieldTrialInfo(const std::string& group_name, | 101 bool GetFieldTrialInfo(const std::string& group_name, |
| 80 FieldTrialFlags* flags, | 102 FieldTrialFlags* flags, |
| 81 uint64* group_number); | 103 uint64* group_number); |
| 82 | 104 |
| 83 // Given a FieldTrialFlags object, returns the string value of the provided | 105 // Given a FieldTrialFlags object, returns the string value of the provided |
| 84 // flag. | 106 // flag. |
| 85 // Exposed for testing only. | 107 // Exposed for testing only. |
| 86 std::string GetStringValueForFlagWithDefault( | 108 std::string GetStringValueForFlagWithDefault(const std::string& flag, |
| 87 const std::string& flag, | 109 const std::string& default_value, |
| 88 const std::string& default_value, | 110 const FieldTrialFlags& flags); |
| 89 FieldTrialFlags& flags); | |
| 90 | 111 |
| 91 // Given a FieldTrialFlags object, returns the uint64 value of the provided | 112 // Given a FieldTrialFlags object, returns the uint64 value of the provided |
| 92 // flag. | 113 // flag. |
| 93 // Exposed for testing only. | 114 // Exposed for testing only. |
| 94 uint64 GetUInt64ValueForFlagWithDefault( | 115 uint64 GetUInt64ValueForFlagWithDefault(const std::string& flag, |
| 95 const std::string& flag, uint64 default_value, FieldTrialFlags& flags); | 116 uint64 default_value, |
| 117 const FieldTrialFlags& flags); |
| 96 | 118 |
| 97 // Given a FieldTrialFlags object, returns the bool value of the provided flag. | 119 // Given a FieldTrialFlags object, returns the bool value of the provided flag. |
| 98 // Exposed for testing only. | 120 // Exposed for testing only. |
| 99 bool GetBoolValueForFlagWithDefault( | 121 bool GetBoolValueForFlagWithDefault(const std::string& flag, |
| 100 const std::string& flag, bool default_value, FieldTrialFlags& flags); | 122 bool default_value, |
| 123 const FieldTrialFlags& flags); |
| 101 | 124 |
| 102 } // namespace search | 125 } // namespace search |
| 103 } // namespace chrome | 126 } // namespace chrome |
| 104 | 127 |
| 105 #endif // CHROME_BROWSER_UI_SEARCH_SEARCH_H_ | 128 #endif // CHROME_BROWSER_UI_SEARCH_SEARCH_H_ |
| OLD | NEW |