Chromium Code Reviews| 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_INSTANT_INSTANT_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_ |
| 6 #define CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_ | 6 #define CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <utility> | 11 #include <utility> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
| 15 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
| 16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/string16.h" | 17 #include "base/string16.h" |
| 18 #include "base/time.h" | 18 #include "base/time.h" |
| 19 #include "base/timer.h" | 19 #include "base/timer.h" |
| 20 #include "chrome/browser/instant/instant_commit_type.h" | 20 #include "chrome/browser/instant/instant_commit_type.h" |
| 21 #include "chrome/browser/instant/instant_model.h" | 21 #include "chrome/browser/instant/instant_model.h" |
| 22 #include "chrome/browser/instant/instant_page.h" | |
| 22 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" | 23 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" |
| 23 #include "chrome/common/instant_types.h" | 24 #include "chrome/common/instant_types.h" |
| 24 #include "chrome/common/search_types.h" | 25 #include "chrome/common/search_types.h" |
| 25 #include "content/public/common/page_transition_types.h" | 26 #include "content/public/common/page_transition_types.h" |
| 26 #include "googleurl/src/gurl.h" | 27 #include "googleurl/src/gurl.h" |
| 27 #include "ui/gfx/native_widget_types.h" | 28 #include "ui/gfx/native_widget_types.h" |
| 28 #include "ui/gfx/rect.h" | 29 #include "ui/gfx/rect.h" |
| 29 | 30 |
| 30 struct AutocompleteMatch; | 31 struct AutocompleteMatch; |
| 31 class AutocompleteProvider; | 32 class AutocompleteProvider; |
| 32 class InstantLoader; | 33 class InstantNTP; |
| 34 class InstantOverlay; | |
| 33 class InstantTab; | 35 class InstantTab; |
| 34 class TemplateURL; | 36 class TemplateURL; |
| 35 | 37 |
| 36 namespace chrome { | 38 namespace chrome { |
| 37 class BrowserInstantController; | 39 class BrowserInstantController; |
| 38 } | 40 } |
| 39 | 41 |
| 40 namespace content { | 42 namespace content { |
| 41 class WebContents; | 43 class WebContents; |
| 42 } | 44 } |
| 43 | 45 |
| 44 // Macro used for logging debug events. |message| should be a std::string. | 46 // Macro used for logging debug events. |message| should be a std::string. |
| 45 #define LOG_INSTANT_DEBUG_EVENT(controller, message) \ | 47 #define LOG_INSTANT_DEBUG_EVENT(controller, message) \ |
| 46 controller->LogDebugEvent(message) | 48 controller->LogDebugEvent(message) |
| 47 | 49 |
| 48 // InstantController maintains a WebContents that is intended to give a preview | 50 // InstantController drives Chrome Instant, i.e., the browser implementation of |
| 49 // of search suggestions and results. InstantController is owned by Browser via | 51 // the Embedded Search API (see http://dev.chromium.org/embeddedsearch). It |
| 50 // BrowserInstantController. | 52 // maintains a WebContents used to show search suggestions and results in an |
|
dhollowa
2013/01/29 02:37:53
The wording makes it sound like there are two web-
samarth
2013/01/29 05:42:01
Moved some of the comments from below into here.
| |
| 51 class InstantController { | 53 // overlay and a WebContents used for the New Tab Page. InstantController is |
| 54 // owned by Browser via BrowserInstantController. | |
| 55 class InstantController : public InstantPage::Delegate { | |
| 52 public: | 56 public: |
| 53 // The URL for the local omnibox popup. | 57 // The URL for the local omnibox popup. |
| 54 static const char* kLocalOmniboxPopupURL; | 58 static const char* kLocalOmniboxPopupURL; |
| 55 | 59 |
| 56 // |use_local_preview_only| will force the use of kLocalOmniboxPopupURL as the | 60 // |use_local_preview_only| will force the use of kLocalOmniboxPopupURL as the |
| 57 // instant URL and is only applicable if |extended_enabled| is true. | 61 // instant URL and is only applicable if |extended_enabled| is true. |
| 58 InstantController(chrome::BrowserInstantController* browser, | 62 InstantController(chrome::BrowserInstantController* browser, |
| 59 bool extended_enabled, | 63 bool extended_enabled, |
| 60 bool use_local_preview_only); | 64 bool use_local_preview_only); |
| 61 ~InstantController(); | 65 ~InstantController(); |
| 62 | 66 |
| 63 // Invoked as the user types into the omnibox. |user_text| is what the user | 67 // Invoked as the user types into the omnibox. |user_text| is what the user |
| 64 // has typed. |full_text| is what the omnibox is showing. These may differ if | 68 // has typed. |full_text| is what the omnibox is showing. These may differ if |
| 65 // the user typed only some text, and the rest was inline autocompleted. If | 69 // the user typed only some text, and the rest was inline autocompleted. If |
| 66 // |verbatim| is true, search results are shown for the exact omnibox text, | 70 // |verbatim| is true, search results are shown for the exact omnibox text, |
| 67 // rather than the best guess as to what the user means. Returns true if the | 71 // rather than the best guess as to what the user means. Returns true if the |
| 68 // update is accepted (i.e., if |match| is a search rather than a URL). | 72 // update is accepted (i.e., if |match| is a search rather than a URL). |
| 69 // |is_keyword_search| is true if keyword searching is in effect. | 73 // |is_keyword_search| is true if keyword searching is in effect. |
| 70 bool Update(const AutocompleteMatch& match, | 74 bool Update(const AutocompleteMatch& match, |
| 71 const string16& user_text, | 75 const string16& user_text, |
| 72 const string16& full_text, | 76 const string16& full_text, |
| 73 size_t selection_start, | 77 size_t selection_start, |
| 74 size_t selection_end, | 78 size_t selection_end, |
| 75 bool verbatim, | 79 bool verbatim, |
| 76 bool user_input_in_progress, | 80 bool user_input_in_progress, |
| 77 bool omnibox_popup_is_open, | 81 bool omnibox_popup_is_open, |
| 78 bool escape_pressed, | 82 bool escape_pressed, |
| 79 bool is_keyword_search); | 83 bool is_keyword_search); |
| 80 | 84 |
| 85 // Releases and returns the NTP WebContents. May be NULL. Loads a new | |
| 86 // WebContents for the NTP. | |
| 87 scoped_ptr<content::WebContents> ReleaseNTPContents() WARN_UNUSED_RESULT; | |
| 88 | |
| 81 // Sets the bounds of the omnibox popup, in screen coordinates. | 89 // Sets the bounds of the omnibox popup, in screen coordinates. |
| 82 void SetPopupBounds(const gfx::Rect& bounds); | 90 void SetPopupBounds(const gfx::Rect& bounds); |
| 83 | 91 |
| 84 // Sets the start and end margins of the omnibox text area. | 92 // Sets the start and end margins of the omnibox text area. |
| 85 void SetMarginSize(int start, int end); | 93 void SetMarginSize(int start, int end); |
| 86 | 94 |
| 87 // Send autocomplete results from |providers| to the preview page. | 95 // Send autocomplete results from |providers| to the preview page. |
| 88 void HandleAutocompleteResults( | 96 void HandleAutocompleteResults( |
| 89 const std::vector<AutocompleteProvider*>& providers); | 97 const std::vector<AutocompleteProvider*>& providers); |
| 90 | 98 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 104 bool CommitIfPossible(InstantCommitType type); | 112 bool CommitIfPossible(InstantCommitType type); |
| 105 | 113 |
| 106 // Called to indicate that the omnibox focus state changed with the given | 114 // Called to indicate that the omnibox focus state changed with the given |
| 107 // |reason|. If |focus_state| is FOCUS_NONE, |view_gaining_focus| is set to | 115 // |reason|. If |focus_state| is FOCUS_NONE, |view_gaining_focus| is set to |
| 108 // the view gaining focus. | 116 // the view gaining focus. |
| 109 void OmniboxFocusChanged(OmniboxFocusState focus_state, | 117 void OmniboxFocusChanged(OmniboxFocusState focus_state, |
| 110 OmniboxFocusChangeReason reason, | 118 OmniboxFocusChangeReason reason, |
| 111 gfx::NativeView view_gaining_focus); | 119 gfx::NativeView view_gaining_focus); |
| 112 | 120 |
| 113 // The search mode in the active tab has changed. Pass the message down to | 121 // The search mode in the active tab has changed. Pass the message down to |
| 114 // the loader which will notify the renderer. Create |instant_tab_| if the | 122 // the overlay which will notify the renderer. Create |instant_tab_| if the |
| 115 // |new_mode| reflects an Instant search results page. | 123 // |new_mode| reflects an Instant search results page. |
| 116 void SearchModeChanged(const chrome::search::Mode& old_mode, | 124 void SearchModeChanged(const chrome::search::Mode& old_mode, |
| 117 const chrome::search::Mode& new_mode); | 125 const chrome::search::Mode& new_mode); |
| 118 | 126 |
| 119 // The user switched tabs. Hide the preview. Create |instant_tab_| if the | 127 // The user switched tabs. Hide the preview. Create |instant_tab_| if the |
| 120 // newly active tab is an Instant search results page. | 128 // newly active tab is an Instant search results page. |
| 121 void ActiveTabChanged(); | 129 void ActiveTabChanged(); |
| 122 | 130 |
| 123 // The user is about to switch tabs. Commit the preview if needed. | 131 // The user is about to switch tabs. Commit the preview if needed. |
| 124 void TabDeactivated(content::WebContents* contents); | 132 void TabDeactivated(content::WebContents* contents); |
| 125 | 133 |
| 126 // Sets whether Instant should show result previews. | 134 // Sets whether Instant should show result previews. |
| 127 void SetInstantEnabled(bool instant_enabled); | 135 void SetInstantEnabled(bool instant_enabled); |
| 128 | 136 |
| 129 // The theme has changed. Pass the message to the preview page. | 137 // The theme has changed. Pass the message to the preview page. |
| 130 void ThemeChanged(const ThemeBackgroundInfo& theme_info); | 138 void ThemeChanged(const ThemeBackgroundInfo& theme_info); |
| 131 | 139 |
| 132 // The theme area height has changed. Pass the message to the preview page. | 140 // The theme area height has changed. Pass the message to the preview page. |
| 133 void ThemeAreaHeightChanged(int height); | 141 void ThemeAreaHeightChanged(int height); |
| 134 | 142 |
| 135 // Returns the transition type of the last AutocompleteMatch passed to Update. | 143 // Called when someone else swapped in a different contents in the |overlay_|. |
| 136 content::PageTransition last_transition_type() const { | 144 void SwappedOverlayContents(); |
|
dhollowa
2013/01/29 02:37:53
To keep terminology straight, how about renaming I
samarth
2013/01/29 05:42:01
Done.
| |
| 137 return last_transition_type_; | |
| 138 } | |
| 139 | 145 |
| 140 const InstantModel* model() const { return &model_; } | 146 // Called when contents for |overlay_| received focus. |
| 147 void FocusedOverlayContents(); | |
| 141 | 148 |
| 142 // Invoked by the page when it has suggested text. | 149 // Called when the |overlay_| might be stale. If it's actually stale, and the |
| 143 void SetSuggestions(const content::WebContents* contents, | 150 // omnibox doesn't have focus, and the preview isn't showing, the |overlay_| |
| 144 const std::vector<InstantSuggestion>& suggestions); | 151 // is deleted and recreated. Else the refresh is skipped. |
| 145 | 152 void HandleStaleOverlay(); |
|
dhollowa
2013/01/29 02:37:53
This is not always about being stale (in the tempo
samarth
2013/01/29 05:42:01
How about ReloadOverlayIfStale?
| |
| 146 // Invoked by the page when its support for the Instant API is determined. | |
| 147 void InstantSupportDetermined(const content::WebContents* contents, | |
| 148 bool supports_instant); | |
| 149 | |
| 150 // Invoked by InstantLoader to request that the preview be shown. | |
| 151 void ShowInstantPreview(InstantShownReason reason, | |
| 152 int height, | |
| 153 InstantSizeUnits units); | |
| 154 | |
| 155 // Invoked by InstantLoader to request the browser to start capturing user key | |
| 156 // strokes. | |
| 157 void StartCapturingKeyStrokes(); | |
| 158 | |
| 159 // Invoked by InstantLoader to request the browser to stop capturing user key | |
| 160 // strokes. | |
| 161 void StopCapturingKeyStrokes(); | |
| 162 | |
| 163 // Invoked by InstantLoader when it has swapped a different WebContents into | |
| 164 // the preview, usually because a prerendered page was navigated to. | |
| 165 void SwappedWebContents(); | |
| 166 | |
| 167 // Invoked by InstantLoader when the preview gains focus, usually due to the | |
| 168 // user clicking on it. | |
| 169 void InstantLoaderContentsFocused(); | |
| 170 | |
| 171 // Invoked by the InstantLoader when its RenderView crashes. | |
| 172 void InstantLoaderRenderViewGone(); | |
| 173 | |
| 174 // Invoked by InstantLoader when the instant page is about to navigate. | |
| 175 void InstantLoaderAboutToNavigateMainFrame(const GURL& url); | |
| 176 | |
| 177 // Invoked by the InstantLoader when the instant page wants to navigate to | |
| 178 // the speicfied URL. | |
| 179 void NavigateToURL(const GURL& url, content::PageTransition transition); | |
| 180 | 153 |
| 181 // Adds a new event to |debug_events_| and also DVLOG's it. Ensures that | 154 // Adds a new event to |debug_events_| and also DVLOG's it. Ensures that |
| 182 // |debug_events_| doesn't get too large. | 155 // |debug_events_| doesn't get too large. |
| 183 void LogDebugEvent(const std::string& info) const; | 156 void LogDebugEvent(const std::string& info) const; |
| 184 | 157 |
| 185 // See comments for |debug_events_| below. | 158 // See comments for |debug_events_| below. |
| 186 const std::list<std::pair<int64, std::string> >& debug_events() { | 159 const std::list<std::pair<int64, std::string> >& debug_events() { |
| 187 return debug_events_; | 160 return debug_events_; |
| 188 } | 161 } |
| 189 | 162 |
| 163 // Returns the transition type of the last AutocompleteMatch passed to Update. | |
| 164 content::PageTransition last_transition_type() const { | |
| 165 return last_transition_type_; | |
| 166 } | |
| 167 | |
| 168 const InstantModel* model() const { return &model_; } | |
| 169 | |
| 190 private: | 170 private: |
| 191 FRIEND_TEST_ALL_PREFIXES(InstantTest, OmniboxFocusLoadsInstant); | 171 FRIEND_TEST_ALL_PREFIXES(InstantTest, OmniboxFocusLoadsInstant); |
| 192 FRIEND_TEST_ALL_PREFIXES(InstantTest, SetWithTemplateURL); | 172 FRIEND_TEST_ALL_PREFIXES(InstantTest, SetWithTemplateURL); |
| 193 FRIEND_TEST_ALL_PREFIXES(InstantTest, NonInstantSearchProvider); | 173 FRIEND_TEST_ALL_PREFIXES(InstantTest, NonInstantSearchProvider); |
| 194 FRIEND_TEST_ALL_PREFIXES(InstantTest, InstantLoaderRefresh); | 174 FRIEND_TEST_ALL_PREFIXES(InstantTest, InstantOverlayRefresh); |
| 195 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, ExtendedModeIsOn); | 175 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, ExtendedModeIsOn); |
| 196 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, OmniboxFocusLoadsInstant); | 176 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, OmniboxFocusLoadsInstant); |
| 177 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, NTPIsPreloaded); | |
| 178 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, PreloadedNTPIsUsedInNewTab); | |
| 179 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, PreloadedNTPIsUsedInSameTab); | |
| 180 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, ProcessIsolation); | |
| 181 | |
| 182 // Overridden from InstantPage::Delegate: | |
| 183 virtual void InstantSupportDetermined( | |
| 184 const content::WebContents* contents, | |
| 185 bool supports_instant) OVERRIDE; | |
| 186 virtual void InstantPageRenderViewGone( | |
| 187 const content::WebContents* contents) OVERRIDE; | |
| 188 virtual void InstantPageAboutToNavigateMainFrame( | |
| 189 const content::WebContents* contents, | |
| 190 const GURL& url) OVERRIDE; | |
| 191 virtual void SetSuggestions( | |
| 192 const content::WebContents* contents, | |
| 193 const std::vector<InstantSuggestion>& suggestions) OVERRIDE; | |
| 194 virtual void ShowInstantPreview( | |
| 195 const content::WebContents* contents, | |
| 196 InstantShownReason reason, | |
| 197 int height, | |
| 198 InstantSizeUnits units) OVERRIDE; | |
| 199 virtual void StartCapturingKeyStrokes( | |
| 200 const content::WebContents* contents) OVERRIDE; | |
| 201 virtual void StopCapturingKeyStrokes(content::WebContents* contents) OVERRIDE; | |
| 202 virtual void NavigateToURL( | |
| 203 const content::WebContents* contents, | |
| 204 const GURL& url, | |
| 205 content::PageTransition transition) OVERRIDE; | |
| 197 | 206 |
| 198 // Helper for OmniboxFocusChanged. Commit or discard the preview. | 207 // Helper for OmniboxFocusChanged. Commit or discard the preview. |
| 199 void OmniboxLostFocus(gfx::NativeView view_gaining_focus); | 208 void OmniboxLostFocus(gfx::NativeView view_gaining_focus); |
| 200 | 209 |
| 201 // Ensures that |loader_| uses the Instant URL returned by GetInstantURL(), | 210 // Creates a new NTP, using the instant_url property of the default |
| 202 // creating a new loader if necessary. In extended mode, will fallback to | 211 // TemplateURL. |
| 212 void ResetNTP(); | |
| 213 | |
| 214 // Ensures that |overlay_| uses the Instant URL returned by GetInstantURL(), | |
| 215 // creating a new overlay if necessary. In extended mode, will fallback to | |
| 203 // using the kLocalOmniboxPopupURL as the Instant URL in case GetInstantURL() | 216 // using the kLocalOmniboxPopupURL as the Instant URL in case GetInstantURL() |
| 204 // returns false. Returns true if an Instant URL could be determined. | 217 // returns false. Returns true if an Instant URL could be determined. |
| 205 bool EnsureLoaderIsCurrent(); | 218 bool EnsureOverlayIsCurrent(); |
| 206 | 219 |
| 207 // Recreates the |loader_| with the input |instant_url|. The caller should | 220 // Recreates the |overlay_| with |instant_url|. The caller should ensure that |
|
dhollowa
2013/01/29 02:37:53
nit: This comment is overly specific - it can just
samarth
2013/01/29 05:42:01
Done.
| |
| 208 // ensure that the |loader_| is not already on the stack since it is deleted | 221 // the |overlay_| is not already on the stack since it is deleted in this |
| 209 // in this call. | 222 // call. |
| 210 void CreateLoader(const std::string& instant_url, | 223 void CreateOverlay(const std::string& instant_url, |
| 211 const content::WebContents* active_tab); | 224 const content::WebContents* active_tab); |
| 212 | |
| 213 // Called when the |loader_| might be stale. If it's actually stale, and the | |
| 214 // omnibox doesn't have focus, and the preview isn't showing, the |loader_| is | |
| 215 // deleted and recreated. Else the refresh is skipped. | |
| 216 void OnStaleLoader(); | |
| 217 | 225 |
| 218 // If the active tab is an Instant search results page, sets |instant_tab_| to | 226 // If the active tab is an Instant search results page, sets |instant_tab_| to |
| 219 // point to it. Else, deletes any existing |instant_tab_|. | 227 // point to it. Else, deletes any existing |instant_tab_|. |
| 220 void ResetInstantTab(); | 228 void ResetInstantTab(); |
| 221 | 229 |
| 222 // Hide the preview. Also sends an onchange event (with blank query) to the | 230 // Hide the preview. Also sends an onchange event (with blank query) to the |
| 223 // preview, telling it to clear out results for any old queries. | 231 // preview, telling it to clear out results for any old queries. |
| 224 void HideLoader(); | 232 void HideOverlay(); |
| 225 | 233 |
| 226 // Like HideLoader(), but doesn't call OnStaleLoader(). Use HideLoader() | 234 // Like HideOverlay(), but doesn't call OnStaleOverlay(). Use HideOverlay() |
| 227 // unless you are going to call loader_.reset() yourself subsequently. | 235 // unless you are going to call overlay_.reset() yourself subsequently. |
| 228 void HideInternal(); | 236 void HideInternal(); |
| 229 | 237 |
| 230 // Counterpart to HideLoader(). Asks the |browser_| to display the preview | 238 // Counterpart to HideOverlay(). Asks the |browser_| to display the preview |
| 231 // with the given |height|. | 239 // with the given |height| in |units|. |
| 232 void ShowLoader(InstantShownReason reason, | 240 void ShowOverlay(InstantShownReason reason, |
| 233 int height, | 241 int height, |
| 234 InstantSizeUnits units); | 242 InstantSizeUnits units); |
| 235 | 243 |
| 236 // Send the omnibox popup bounds to the page. | 244 // Send the omnibox popup bounds to the page. |
| 237 void SendPopupBoundsToPage(); | 245 void SendPopupBoundsToPage(); |
| 238 | 246 |
| 239 // Determines the Instant URL based on a number of factors: | 247 // Determines the Instant URL based on a number of factors: |
| 240 // If |extended_enabled_|: | 248 // If |extended_enabled_|: |
| 241 // - If |use_local_preview_only_| is true return kLocalOmniboxPopupURL, else | 249 // - If |use_local_preview_only_| is true return kLocalOmniboxPopupURL, else |
| 242 // - If the Instant URL is specified by command line, returns it, else | 250 // - If the Instant URL is specified by command line, returns it, else |
| 243 // - If the default Instant URL is present returns it. | 251 // - If the default Instant URL is present returns it. |
| 244 // If !|extended_enabled_|: | 252 // If !|extended_enabled_|: |
| 245 // - If the Instant URL is specified by command line, returns it, else | 253 // - If the Instant URL is specified by command line, returns it, else |
| 246 // - If the default Instant URL is present returns it. | 254 // - If the default Instant URL is present returns it. |
| 247 // | 255 // |
| 248 // Returns true if a valid Instant URL could be found that is not blacklisted. | 256 // Returns true if a valid Instant URL could be found that is not blacklisted. |
| 249 bool GetInstantURL(const content::WebContents* active_tab, | 257 bool GetInstantURL(Profile* profile, |
|
dhollowa
2013/01/29 02:37:53
nit: This will fit on one line now.
samarth
2013/01/29 05:42:01
Done.
| |
| 250 std::string* instant_url) const; | 258 std::string* instant_url) const; |
| 251 | 259 |
| 260 // Adds the URL for the page to the blacklist. Deletes the contents held and | |
| 261 // recreates a new page. | |
| 262 void BlacklistAndResetOverlay(); | |
| 263 void BlacklistAndResetNTP(); | |
| 264 | |
| 265 // Removes |url| from the blacklist. | |
| 266 void RemoveFromBlacklist(const std::string& url); | |
| 267 | |
| 252 chrome::BrowserInstantController* const browser_; | 268 chrome::BrowserInstantController* const browser_; |
| 253 | 269 |
| 254 // Whether the extended API and regular API are enabled. If both are false, | 270 // Whether the extended API and regular API are enabled. If both are false, |
| 255 // Instant is effectively disabled. | 271 // Instant is effectively disabled. |
| 256 const bool extended_enabled_; | 272 const bool extended_enabled_; |
| 257 bool instant_enabled_; | 273 bool instant_enabled_; |
| 258 | 274 |
| 259 // If true, the instant URL is set to kLocalOmniboxPopupURL. | 275 // If true, the instant URL is set to kLocalOmniboxPopupURL. |
| 260 const bool use_local_preview_only_; | 276 const bool use_local_preview_only_; |
| 261 | 277 |
| 262 // The state of the preview page, i.e., the page owned by |loader_|. Ignored | 278 // The state of the preview page, i.e., the page owned by |overlay_|. Ignored |
| 263 // if |instant_tab_| is in use. | 279 // if |instant_tab_| is in use. |
| 264 InstantModel model_; | 280 InstantModel model_; |
| 265 | 281 |
| 266 // The preview WebContents. | 282 // InstantController maintains 3 instances of InstantPage in extended mode: |
| 267 scoped_ptr<InstantLoader> loader_; | 283 // - |overlay_| is used to show search suggestions and results in an |
| 268 | 284 // overlay over a non-search page. |
| 269 // A committed WebContents that supports Instant. If non-NULL, the |loader_| | 285 // - |ntp_| is a preloaded search page that will be swapped-in the next |
| 270 // is guaranteed to be hidden and messages will be sent to this instead. | 286 // time the user navigates to the New Tab Page. It is never shown to the |
| 287 // user in an uncommitted state. | |
| 288 // - |instant_tab_| is the currently active tab, if it supports the Instant | |
| 289 // API. | |
| 290 // All three may be non-NULL. If |instant_tab_| is not NULL, then |overlay_| | |
| 291 // is guaranteed to be hidden and messages will be sent to |instant_tab_| | |
| 292 // instead. | |
| 293 // | |
| 294 // In non-extended mode, only |overlay_| is ever non-NULL. | |
| 295 scoped_ptr<InstantOverlay> overlay_; | |
| 296 scoped_ptr<InstantNTP> ntp_; | |
| 271 scoped_ptr<InstantTab> instant_tab_; | 297 scoped_ptr<InstantTab> instant_tab_; |
| 272 | 298 |
| 273 // The most recent full_text passed to Update(). If empty, we'll not accept | 299 // The most recent full_text passed to Update(). If empty, we'll not accept |
| 274 // search suggestions from |loader_| or |instant_tab_|. | 300 // search suggestions from |overlay_| or |instant_tab_|. |
| 275 string16 last_omnibox_text_; | 301 string16 last_omnibox_text_; |
| 276 | 302 |
| 277 // True if the last Update() had an inline autocompletion. Used only to make | 303 // True if the last Update() had an inline autocompletion. Used only to make |
| 278 // sure that we don't accidentally suggest gray text suggestion in that case. | 304 // sure that we don't accidentally suggest gray text suggestion in that case. |
| 279 bool last_omnibox_text_has_inline_autocompletion_; | 305 bool last_omnibox_text_has_inline_autocompletion_; |
| 280 | 306 |
| 281 // The most recent verbatim passed to Update(). Used only to ensure that we | 307 // The most recent verbatim passed to Update(). Used only to ensure that we |
| 282 // don't accidentally suggest an inline autocompletion. | 308 // don't accidentally suggest an inline autocompletion. |
| 283 bool last_verbatim_; | 309 bool last_verbatim_; |
| 284 | 310 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 307 | 333 |
| 308 // Size of the start-edge omnibox text area margin. | 334 // Size of the start-edge omnibox text area margin. |
| 309 int start_margin_; | 335 int start_margin_; |
| 310 | 336 |
| 311 // Size of the end-edge omnibox text area margin. | 337 // Size of the end-edge omnibox text area margin. |
| 312 int end_margin_; | 338 int end_margin_; |
| 313 | 339 |
| 314 // Timer used to update the bounds of the omnibox popup. | 340 // Timer used to update the bounds of the omnibox popup. |
| 315 base::OneShotTimer<InstantController> update_bounds_timer_; | 341 base::OneShotTimer<InstantController> update_bounds_timer_; |
| 316 | 342 |
| 317 // Timer used to ensure that the Instant page does not get too stale. | |
| 318 base::OneShotTimer<InstantController> stale_loader_timer_; | |
| 319 | |
| 320 // For each key K => value N, the map says that we found that the search | 343 // For each key K => value N, the map says that we found that the search |
| 321 // engine identified by Instant URL K didn't support the Instant API, or | 344 // engine identified by Instant URL K didn't support the Instant API, or |
| 322 // caused RenderView crashes in each of the last N times that we loaded it. | 345 // caused RenderView crashes in each of the last N times that we loaded it. |
| 323 // If an Instant URL isn't present in the map at all or has a value 0, | 346 // If an Instant URL isn't present in the map at all or has a value 0, |
| 324 // it means that search engine supports the Instant API (or we assume it does, | 347 // it means that search engine supports the Instant API (or we assume it does, |
| 325 // since we haven't determined it doesn't) and it did not cause a crash. | 348 // since we haven't determined it doesn't) and it did not cause a crash. |
| 326 std::map<std::string, int> blacklisted_urls_; | 349 std::map<std::string, int> blacklisted_urls_; |
| 327 | 350 |
| 328 // Search terms extraction (for autocomplete history matches) doesn't work | 351 // Search terms extraction (for autocomplete history matches) doesn't work |
| 329 // on Instant URLs. So, whenever the user commits an Instant search, we add | 352 // on Instant URLs. So, whenever the user commits an Instant search, we add |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 341 // MODE_SEARCH_SUGGESTIONS, except in those cases where this is false. | 364 // MODE_SEARCH_SUGGESTIONS, except in those cases where this is false. |
| 342 bool allow_preview_to_show_search_suggestions_; | 365 bool allow_preview_to_show_search_suggestions_; |
| 343 | 366 |
| 344 // List of events and their timestamps, useful in debugging Instant behaviour. | 367 // List of events and their timestamps, useful in debugging Instant behaviour. |
| 345 mutable std::list<std::pair<int64, std::string> > debug_events_; | 368 mutable std::list<std::pair<int64, std::string> > debug_events_; |
| 346 | 369 |
| 347 DISALLOW_COPY_AND_ASSIGN(InstantController); | 370 DISALLOW_COPY_AND_ASSIGN(InstantController); |
| 348 }; | 371 }; |
| 349 | 372 |
| 350 #endif // CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_ | 373 #endif // CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_ |
| OLD | NEW |