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> | |
| 9 #include <map> | |
| 10 #include <string> | |
| 11 #include <utility> | |
| 12 #include <vector> | 8 #include <vector> |
| 13 | 9 |
| 14 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 15 #include "base/gtest_prod_util.h" | |
| 16 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/string16.h" | 12 #include "base/string16.h" |
| 18 #include "base/time.h" | |
| 19 #include "base/timer.h" | |
| 20 #include "chrome/browser/history/history_types.h" | |
| 21 #include "chrome/browser/instant/instant_commit_type.h" | 13 #include "chrome/browser/instant/instant_commit_type.h" |
| 22 #include "chrome/browser/instant/instant_model.h" | |
| 23 #include "chrome/browser/instant/instant_page.h" | 14 #include "chrome/browser/instant/instant_page.h" |
| 24 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" | 15 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" |
| 25 #include "chrome/common/instant_types.h" | |
| 26 #include "chrome/common/search_types.h" | |
| 27 #include "content/public/browser/notification_observer.h" | |
| 28 #include "content/public/browser/notification_registrar.h" | |
| 29 #include "content/public/common/page_transition_types.h" | |
| 30 #include "googleurl/src/gurl.h" | |
| 31 #include "ui/base/window_open_disposition.h" | |
| 32 #include "ui/gfx/native_widget_types.h" | 16 #include "ui/gfx/native_widget_types.h" |
| 33 #include "ui/gfx/rect.h" | |
| 34 | 17 |
| 35 struct AutocompleteMatch; | 18 struct AutocompleteMatch; |
| 36 class AutocompleteProvider; | 19 class AutocompleteProvider; |
| 37 class InstantNTP; | 20 class InstantModel; |
| 38 class InstantOverlay; | 21 class InstantModelObserver; |
| 39 class InstantTab; | 22 class Profile; |
| 40 class TemplateURL; | |
| 41 | 23 |
| 42 namespace chrome { | 24 namespace chrome { |
| 43 class BrowserInstantController; | 25 class BrowserInstantController; |
| 44 } | 26 } |
| 45 | 27 |
| 28 namespace chrome { | |
| 29 namespace search { | |
| 30 struct Mode; | |
| 31 } | |
| 32 } | |
| 33 | |
| 46 namespace content { | 34 namespace content { |
| 47 class WebContents; | 35 class WebContents; |
| 48 } | 36 } |
| 49 | 37 |
| 50 // Macro used for logging debug events. |message| should be a std::string. | 38 namespace gfx { |
| 51 #define LOG_INSTANT_DEBUG_EVENT(controller, message) \ | 39 class Rect; |
| 52 controller->LogDebugEvent(message) | 40 } |
| 53 | 41 |
| 54 // InstantController drives Chrome Instant, i.e., the browser implementation of | 42 // InstantController drives Chrome Instant, i.e., the browser implementation of |
| 55 // the Embedded Search API (see http://dev.chromium.org/embeddedsearch). | 43 // the Embedded Search API (see http://dev.chromium.org/embeddedsearch). |
| 56 // | 44 // |
| 57 // In extended mode, InstantController maintains and coordinates three | 45 // There are two concrete modes of operation: Regular (InstantControllerImpl) |
| 58 // instances of InstantPage: | 46 // and Extended (InstantControllerExtendedImpl). |
| 59 // (1) An InstantOverlay instance that is used to show search suggestions and | |
| 60 // results in an overlay over a non-search page. | |
| 61 // (2) An InstantNTP instance which is a preloaded search page that will be | |
| 62 // swapped-in the next time the user navigates to the New Tab Page. It is | |
| 63 // never shown to the user in an uncommitted state. | |
| 64 // (3) An InstantTab instance which points to the currently active tab, if it | |
| 65 // supports the Embedded Search API. | |
| 66 // | 47 // |
| 67 // All three are backed by a WebContents. InstantOverlay and InstantNTP own | 48 // In both modes, InstantController can show an overlay WebContents as the user |
| 68 // their corresponding WebContents; InstantTab does not. In non-extended mode, | 49 // types in the omnibox. In extended mode, InstantController can also use the |
| 69 // only an InstantOverlay instance is kept. | 50 // current active tab to drive the display of search suggestions and results. |
| 70 // | 51 // |
| 71 // InstantController is owned by Browser via BrowserInstantController. | 52 // InstantController is owned by Browser via BrowserInstantController. |
| 72 class InstantController : public InstantPage::Delegate, | 53 class InstantController : public InstantPage::Delegate { |
| 73 public content::NotificationObserver { | |
| 74 public: | 54 public: |
| 75 InstantController(chrome::BrowserInstantController* browser, | 55 static scoped_ptr<InstantController> GetInstance( |
|
samarth
2013/03/01 17:59:53
GetInstance makes me think of singletons. How abo
samarth
2013/03/01 17:59:53
Also comments here.
sreeram
2013/03/07 18:18:46
Done.
sreeram
2013/03/07 18:18:46
Done. Create() along with the scoped_ptr<> return
samarth
2013/03/11 19:03:24
Not sure what I had in mind when I wrote that :) A
| |
| 76 bool extended_enabled); | 56 chrome::BrowserInstantController* browser, |
| 57 Profile* profile); | |
| 58 | |
| 59 InstantController(); | |
| 77 virtual ~InstantController(); | 60 virtual ~InstantController(); |
| 78 | 61 |
| 79 // Invoked as the user types into the omnibox. |user_text| is what the user | 62 // -------------------------------------------------------------------------- |
| 80 // has typed. |full_text| is what the omnibox is showing. These may differ if | 63 // The OmniboxEditModel delivers the following events as the user interacts |
| 81 // the user typed only some text, and the rest was inline autocompleted. If | 64 // with the omnibox. |
| 82 // |verbatim| is true, search results are shown for the exact omnibox text, | |
| 83 // rather than the best guess as to what the user means. Returns true if the | |
| 84 // update is accepted (i.e., if |match| is a search rather than a URL). | |
| 85 // |is_keyword_search| is true if keyword searching is in effect. | |
| 86 bool Update(const AutocompleteMatch& match, | |
| 87 const string16& user_text, | |
| 88 const string16& full_text, | |
| 89 size_t selection_start, | |
| 90 size_t selection_end, | |
| 91 bool verbatim, | |
| 92 bool user_input_in_progress, | |
| 93 bool omnibox_popup_is_open, | |
| 94 bool escape_pressed, | |
| 95 bool is_keyword_search); | |
| 96 | 65 |
| 97 // Releases and returns the NTP WebContents. May be NULL. Loads a new | 66 // Called in most cases where the omnibox text has changed. |
| 98 // WebContents for the NTP. | 67 virtual bool Update(const AutocompleteMatch& match, |
| 99 scoped_ptr<content::WebContents> ReleaseNTPContents() WARN_UNUSED_RESULT; | 68 const string16& user_text, |
| 69 const string16& full_text, | |
| 70 size_t selection_start, | |
| 71 size_t selection_end, | |
| 72 bool verbatim, | |
| 73 bool user_input_in_progress, | |
| 74 bool omnibox_popup_is_open, | |
| 75 bool escape_pressed) = 0; | |
| 100 | 76 |
| 101 // Sets the bounds of the omnibox popup, in screen coordinates. | 77 // Called when the autocomplete system has new results for the current text. |
| 102 void SetPopupBounds(const gfx::Rect& bounds); | 78 virtual void HandleAutocompleteResults( |
| 79 const std::vector<AutocompleteProvider*>& providers) = 0; | |
| 103 | 80 |
| 104 // Sets the stored start-edge margin and width of the omnibox. | 81 // Called when the user wants to traverse the suggestions list. |count| is |
| 105 void SetOmniboxBounds(const gfx::Rect& bounds); | 82 // positive to indicate moving down, negative for moving up. |
| 83 virtual bool OnUpOrDownKeyPressed(int count) = 0; | |
| 106 | 84 |
| 107 // Send autocomplete results from |providers| to the preview page. | 85 // Called when the user hits Escape after traversing the suggestions list. |
| 108 void HandleAutocompleteResults( | 86 virtual void OnCancel(const AutocompleteMatch& match, |
| 109 const std::vector<AutocompleteProvider*>& providers); | 87 const string16& full_text) = 0; |
| 110 | 88 |
| 111 // Called when the user presses up or down. |count| is a repeat count, | 89 // -------------------------------------------------------------------------- |
| 112 // negative for moving up, positive for moving down. Returns true if Instant | 90 // Methods dealing with the overlay, its model and the NTP. |
| 113 // handled the key press. | |
| 114 bool OnUpOrDownKeyPressed(int count); | |
| 115 | 91 |
| 116 // Called when the user has arrowed into the suggestions but wants to cancel, | 92 virtual const InstantModel* model() const = 0; |
| 117 // typically by pressing ESC. The omnibox text is expected to have been | |
| 118 // reverted to |full_text| by the OmniboxEditModel prior to calling this. | |
| 119 // |match| is the match reverted to. | |
| 120 void OnCancel(const AutocompleteMatch& match, | |
| 121 const string16& full_text); | |
| 122 | 93 |
| 123 // The preview WebContents. May be NULL. InstantController retains ownership. | 94 virtual bool IsOverlayingSearchResults() const = 0; |
|
samarth
2013/03/01 17:59:53
Search-and-replace fail? :)
How about IsOverlaySh
sreeram
2013/03/07 18:18:46
Sorry, this ship has sailed. I don't think it's un
| |
| 124 content::WebContents* GetPreviewContents() const; | |
| 125 | 95 |
| 126 // Returns true if the Instant overlay is showing a search results preview. | 96 virtual content::WebContents* GetOverlayContents() const = 0; |
| 127 bool IsPreviewingSearchResults() const; | |
| 128 | 97 |
| 129 // If the preview is showing search results, commits the preview, calling | 98 virtual bool CommitIfPossible(InstantCommitType type) = 0; |
| 130 // CommitInstant() on the browser, and returns true. Else, returns false. | |
| 131 bool CommitIfPossible(InstantCommitType type); | |
| 132 | 99 |
| 133 // Called to indicate that the omnibox focus state changed with the given | 100 virtual scoped_ptr<content::WebContents> ReleaseNTPContents() = 0; |
| 134 // |reason|. If |focus_state| is FOCUS_NONE, |view_gaining_focus| is set to | |
| 135 // the view gaining focus. | |
| 136 void OmniboxFocusChanged(OmniboxFocusState focus_state, | |
| 137 OmniboxFocusChangeReason reason, | |
| 138 gfx::NativeView view_gaining_focus); | |
| 139 | 101 |
| 140 // The search mode in the active tab has changed. Pass the message down to | 102 virtual void AddModelObserver(InstantModelObserver* observer) = 0; |
| 141 // the overlay which will notify the renderer. Create |instant_tab_| if the | |
| 142 // |new_mode| reflects an Instant search results page. | |
| 143 void SearchModeChanged(const chrome::search::Mode& old_mode, | |
| 144 const chrome::search::Mode& new_mode); | |
| 145 | 103 |
| 146 // The user switched tabs. Hide the preview. Create |instant_tab_| if the | 104 virtual void RemoveModelObserver(InstantModelObserver* observer) = 0; |
| 147 // newly active tab is an Instant search results page. | |
| 148 void ActiveTabChanged(); | |
| 149 | 105 |
| 150 // The user is about to switch tabs. Commit the preview if needed. | 106 // -------------------------------------------------------------------------- |
| 151 void TabDeactivated(content::WebContents* contents); | 107 // Information about the omnibox and bookmark bar. |
| 152 | 108 |
| 153 // Sets whether Instant should show result previews. |use_local_preview_only| | 109 virtual void SetPopupBounds(const gfx::Rect& bounds) = 0; |
| 154 // will force the use of kLocalOmniboxPopupURL as the Instant URL and is only | |
| 155 // applicable if |extended_enabled_| is true. | |
| 156 void SetInstantEnabled(bool instant_enabled, bool use_local_preview_only); | |
| 157 | 110 |
| 158 // The theme has changed. Pass the message to the preview page. | 111 virtual void SetOmniboxBounds(const gfx::Rect& bounds) = 0; |
| 159 void ThemeChanged(const ThemeBackgroundInfo& theme_info); | |
| 160 | 112 |
| 161 // Called when someone else swapped in a different contents in the |overlay_|. | 113 virtual void BookmarkBarStateChanged(bool is_detached) = 0; |
| 162 void SwappedOverlayContents(); | |
| 163 | 114 |
| 164 // Called when contents for |overlay_| received focus. | 115 // -------------------------------------------------------------------------- |
| 165 void FocusedOverlayContents(); | 116 // Events sent as the user stops (or starts) interacting with the omnibox. |
| 166 | 117 |
| 167 // Called when the |overlay_| might be stale. If it's actually stale, and the | 118 virtual void OmniboxFocusChanged(OmniboxFocusState state, |
| 168 // omnibox doesn't have focus, and the preview isn't showing, the |overlay_| | 119 OmniboxFocusChangeReason reason, |
| 169 // is deleted and recreated. Else the refresh is skipped. | 120 gfx::NativeView view_gaining_focus) = 0; |
| 170 void ReloadOverlayIfStale(); | |
| 171 | 121 |
| 172 // Adds a new event to |debug_events_| and also DVLOG's it. Ensures that | 122 virtual void TabDeactivated(content::WebContents* contents) = 0; |
| 173 // |debug_events_| doesn't get too large. | |
| 174 void LogDebugEvent(const std::string& info) const; | |
| 175 | 123 |
| 176 // See comments for |debug_events_| below. | 124 virtual void SearchModeChanged(const chrome::search::Mode& old_mode, |
| 177 const std::list<std::pair<int64, std::string> >& debug_events() { | 125 const chrome::search::Mode& new_mode) = 0; |
| 178 return debug_events_; | |
| 179 } | |
| 180 | 126 |
| 181 // Returns the transition type of the last AutocompleteMatch passed to Update. | 127 virtual void ActiveTabChanged() = 0; |
| 182 content::PageTransition last_transition_type() const { | |
| 183 return last_transition_type_; | |
| 184 } | |
| 185 | 128 |
| 186 // Non-const for Add/RemoveObserver only. Other model changes should only | 129 // -------------------------------------------------------------------------- |
| 187 // happen through the InstantController interface. | 130 // Calls from InstantOverlay. Not for general use. |
| 188 InstantModel* model() { return &model_; } | 131 |
| 132 virtual void SwappedOverlayContents() = 0; | |
| 133 | |
| 134 virtual void FocusedOverlayContents() = 0; | |
| 189 | 135 |
| 190 private: | 136 private: |
| 191 FRIEND_TEST_ALL_PREFIXES(InstantTest, OmniboxFocusLoadsInstant); | |
| 192 FRIEND_TEST_ALL_PREFIXES(InstantTest, SetWithTemplateURL); | |
| 193 FRIEND_TEST_ALL_PREFIXES(InstantTest, NonInstantSearchProvider); | |
| 194 FRIEND_TEST_ALL_PREFIXES(InstantTest, InstantOverlayRefresh); | |
| 195 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, ExtendedModeIsOn); | |
| 196 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, MostVisited); | |
| 197 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, OmniboxFocusLoadsInstant); | |
| 198 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, | |
| 199 OmniboxTextUponFocusedCommittedSERP); | |
| 200 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, | |
| 201 MiddleClickOnSuggestionOpensInNewTab); | |
| 202 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, NTPIsPreloaded); | |
| 203 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, PreloadedNTPIsUsedInNewTab); | |
| 204 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, PreloadedNTPIsUsedInSameTab); | |
| 205 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, ProcessIsolation); | |
| 206 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, UnrelatedSiteInstance); | |
| 207 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, | |
| 208 OmniboxCommitsWhenShownFullHeight); | |
| 209 | |
| 210 // Overridden from content::NotificationObserver: | |
| 211 virtual void Observe(int type, | |
| 212 const content::NotificationSource& source, | |
| 213 const content::NotificationDetails& details) OVERRIDE; | |
| 214 | |
| 215 // Overridden from InstantPage::Delegate: | |
| 216 // TODO(shishir): We assume that the WebContent's current RenderViewHost is | |
| 217 // the RenderViewHost being created which is not always true. Fix this. | |
| 218 virtual void InstantPageRenderViewCreated( | |
| 219 const content::WebContents* contents) OVERRIDE; | |
| 220 virtual void InstantSupportDetermined( | |
| 221 const content::WebContents* contents, | |
| 222 bool supports_instant) OVERRIDE; | |
| 223 virtual void InstantPageRenderViewGone( | |
| 224 const content::WebContents* contents) OVERRIDE; | |
| 225 virtual void InstantPageAboutToNavigateMainFrame( | |
| 226 const content::WebContents* contents, | |
| 227 const GURL& url) OVERRIDE; | |
| 228 virtual void SetSuggestions( | |
| 229 const content::WebContents* contents, | |
| 230 const std::vector<InstantSuggestion>& suggestions) OVERRIDE; | |
| 231 virtual void ShowInstantOverlay( | |
| 232 const content::WebContents* contents, | |
| 233 InstantShownReason reason, | |
| 234 int height, | |
| 235 InstantSizeUnits units) OVERRIDE; | |
| 236 virtual void StartCapturingKeyStrokes( | |
| 237 const content::WebContents* contents) OVERRIDE; | |
| 238 virtual void StopCapturingKeyStrokes(content::WebContents* contents) OVERRIDE; | |
| 239 virtual void NavigateToURL( | |
| 240 const content::WebContents* contents, | |
| 241 const GURL& url, | |
| 242 content::PageTransition transition, | |
| 243 WindowOpenDisposition disposition) OVERRIDE; | |
| 244 | |
| 245 // Invoked by the InstantLoader when the instant page wants to delete a | |
| 246 // Most Visited item. | |
| 247 virtual void DeleteMostVisitedItem(const GURL& url) OVERRIDE; | |
| 248 | |
| 249 // Invoked by the InstantLoader when the instant page wants to undo a | |
| 250 // Most Visited deletion. | |
| 251 virtual void UndoMostVisitedDeletion(const GURL& url) OVERRIDE; | |
| 252 | |
| 253 // Invoked by the InstantLoader when the instant page wants to undo all | |
| 254 // Most Visited deletions. | |
| 255 virtual void UndoAllMostVisitedDeletions() OVERRIDE; | |
| 256 | |
| 257 // Helper for OmniboxFocusChanged. Commit or discard the preview. | |
| 258 void OmniboxLostFocus(gfx::NativeView view_gaining_focus); | |
| 259 | |
| 260 // Creates a new NTP, using the instant_url property of the default | |
| 261 // TemplateURL. | |
| 262 void ResetNTP(); | |
| 263 | |
| 264 // Ensures that |overlay_| uses the Instant URL returned by GetInstantURL(), | |
| 265 // creating a new overlay if necessary. In extended mode, will fallback to | |
| 266 // using the kLocalOmniboxPopupURL as the Instant URL in case GetInstantURL() | |
| 267 // returns false. Returns true if an Instant URL could be determined. | |
| 268 // For |ignore_blacklist| look at comments in |GetInstantURL|. | |
| 269 bool EnsureOverlayIsCurrent(bool ignore_blacklist); | |
| 270 | |
| 271 // Recreates the |overlay_| with |instant_url|. Note that |overlay_| is | |
| 272 // deleted in this call. | |
| 273 void CreateOverlay(const std::string& instant_url, | |
| 274 const content::WebContents* active_tab); | |
| 275 | |
| 276 // If the |overlay_| being used is in fallback mode, it will be switched back | |
| 277 // to the remote overlay if the overlay is not showing and the omnibox does | |
| 278 // not have focus. | |
| 279 void MaybeSwitchToRemoteOverlay(); | |
| 280 | |
| 281 // If the active tab is an Instant search results page, sets |instant_tab_| to | |
| 282 // point to it. Else, deletes any existing |instant_tab_|. | |
| 283 void ResetInstantTab(); | |
| 284 | |
| 285 // Hide the preview. Also sends an onchange event (with blank query) to the | |
| 286 // preview, telling it to clear out results for any old queries. | |
| 287 void HideOverlay(); | |
| 288 | |
| 289 // Like HideOverlay(), but doesn't call OnStaleOverlay(). Use HideOverlay() | |
| 290 // unless you are going to call overlay_.reset() yourself subsequently. | |
| 291 void HideInternal(); | |
| 292 | |
| 293 // Counterpart to HideOverlay(). Asks the |browser_| to display the preview | |
| 294 // with the given |height| in |units|. | |
| 295 void ShowOverlay(InstantShownReason reason, | |
| 296 int height, | |
| 297 InstantSizeUnits units); | |
| 298 | |
| 299 // Send the omnibox popup bounds to the page. | |
| 300 void SendPopupBoundsToPage(); | |
| 301 | |
| 302 // Determines the Instant URL based on a number of factors: | |
| 303 // If |extended_enabled_|: | |
| 304 // - If |use_local_preview_only_| is true return kLocalOmniboxPopupURL, else | |
| 305 // - If the Instant URL is specified by command line, returns it, else | |
| 306 // - If the default Instant URL is present returns it. | |
| 307 // If !|extended_enabled_|: | |
| 308 // - If the Instant URL is specified by command line, returns it, else | |
| 309 // - If the default Instant URL is present returns it. | |
| 310 // | |
| 311 // If |ignore_blacklist| is set to true, Instant URLs are not filtered through | |
| 312 // the blacklist. | |
| 313 // | |
| 314 // Returns true if a valid Instant URL could be found that is not blacklisted. | |
| 315 bool GetInstantURL(Profile* profile, | |
| 316 bool ignore_blacklist, | |
| 317 std::string* instant_url) const; | |
| 318 | |
| 319 // Adds the URL for the page to the blacklist. Deletes the contents held and | |
| 320 // recreates a new page. | |
| 321 void BlacklistAndResetOverlay(); | |
| 322 void BlacklistAndResetNTP(); | |
| 323 | |
| 324 // Removes |url| from the blacklist. | |
| 325 void RemoveFromBlacklist(const std::string& url); | |
| 326 | |
| 327 InstantOverlay* overlay() const { return overlay_.get(); } | |
| 328 InstantTab* instant_tab() const { return instant_tab_.get(); } | |
| 329 InstantNTP* ntp() const { return ntp_.get(); } | |
| 330 | |
| 331 // Begin listening to change notifications from TopSites and fire off an | |
| 332 // initial request for most visited items. | |
| 333 void StartListeningToMostVisitedChanges(); | |
| 334 | |
| 335 // Fire off an async request for most visited items to the TopNav code. | |
| 336 void RequestMostVisitedItems(); | |
| 337 | |
| 338 // Called when we get new most visited items from the TopNav code, | |
| 339 // registered as an async callback. Parses them and sends them to the | |
| 340 // renderer via SendMostVisitedItems. | |
| 341 void OnMostVisitedItemsReceived(const history::MostVisitedURLList& data); | |
| 342 | |
| 343 // Sends a collection of MostVisitedItems to the renderer process via | |
| 344 // the appropriate InstantPage subclass. | |
| 345 void SendMostVisitedItems(const std::vector<MostVisitedItem>& items); | |
| 346 | |
| 347 chrome::BrowserInstantController* const browser_; | |
| 348 | |
| 349 // Whether the extended API and regular API are enabled. If both are false, | |
| 350 // Instant is effectively disabled. | |
| 351 const bool extended_enabled_; | |
| 352 bool instant_enabled_; | |
| 353 | |
| 354 // If true, the instant URL is set to kLocalOmniboxPopupURL. | |
| 355 bool use_local_preview_only_; | |
| 356 | |
| 357 // The state of the preview page, i.e., the page owned by |overlay_|. Ignored | |
| 358 // if |instant_tab_| is in use. | |
| 359 InstantModel model_; | |
| 360 | |
| 361 // The three instances of InstantPage maintained by InstantController as | |
| 362 // described above. All three may be non-NULL in extended mode. If | |
| 363 // |instant_tab_| is not NULL, then |overlay_| is guaranteed to be hidden and | |
| 364 // messages will be sent to |instant_tab_| instead. | |
| 365 // | |
| 366 // In non-extended mode, only |overlay_| is ever non-NULL. | |
| 367 scoped_ptr<InstantOverlay> overlay_; | |
| 368 scoped_ptr<InstantNTP> ntp_; | |
| 369 scoped_ptr<InstantTab> instant_tab_; | |
| 370 | |
| 371 // The most recent full_text passed to Update(). If empty, we'll not accept | |
| 372 // search suggestions from |overlay_| or |instant_tab_|. | |
| 373 string16 last_omnibox_text_; | |
| 374 | |
| 375 // True if the last Update() had an inline autocompletion. Used only to make | |
| 376 // sure that we don't accidentally suggest gray text suggestion in that case. | |
| 377 bool last_omnibox_text_has_inline_autocompletion_; | |
| 378 | |
| 379 // The most recent verbatim passed to Update(). Used only to ensure that we | |
| 380 // don't accidentally suggest an inline autocompletion. | |
| 381 bool last_verbatim_; | |
| 382 | |
| 383 // The most recent suggestion received from the page, minus any prefix that | |
| 384 // the user has typed. | |
| 385 InstantSuggestion last_suggestion_; | |
| 386 | |
| 387 // See comments on the getter above. | |
| 388 content::PageTransition last_transition_type_; | |
| 389 | |
| 390 // True if the last match passed to Update() was a search (versus a URL). | |
| 391 // Used to ensure that the preview page is committable. | |
| 392 bool last_match_was_search_; | |
| 393 | |
| 394 // Omnibox focus state. | |
| 395 OmniboxFocusState omnibox_focus_state_; | |
| 396 | |
| 397 // The search model mode for the active tab. | |
| 398 chrome::search::Mode search_mode_; | |
| 399 | |
| 400 // Current omnibox popup bounds. | |
| 401 gfx::Rect popup_bounds_; | |
| 402 | |
| 403 // Last popup bounds passed to the page. | |
| 404 gfx::Rect last_popup_bounds_; | |
| 405 | |
| 406 // The start-edge margin and width of the omnibox, used by the page to align | |
| 407 // its suggestions with the omnibox. | |
| 408 gfx::Rect omnibox_bounds_; | |
| 409 | |
| 410 // Timer used to update the bounds of the omnibox popup. | |
| 411 base::OneShotTimer<InstantController> update_bounds_timer_; | |
| 412 | |
| 413 // For each key K => value N, the map says that we found that the search | |
| 414 // engine identified by Instant URL K didn't support the Instant API, or | |
| 415 // caused RenderView crashes in each of the last N times that we loaded it. | |
| 416 // If an Instant URL isn't present in the map at all or has a value 0, | |
| 417 // it means that search engine supports the Instant API (or we assume it does, | |
| 418 // since we haven't determined it doesn't) and it did not cause a crash. | |
| 419 std::map<std::string, int> blacklisted_urls_; | |
| 420 | |
| 421 // Search terms extraction (for autocomplete history matches) doesn't work | |
| 422 // on Instant URLs. So, whenever the user commits an Instant search, we add | |
| 423 // an equivalent non-Instant search URL to history, so that the search shows | |
| 424 // up in autocomplete history matches. | |
| 425 // TODO(sreeram): Remove when http://crbug.com/155373 is fixed. | |
| 426 GURL url_for_history_; | |
| 427 | |
| 428 // The timestamp at which query editing began. This value is used when the | |
| 429 // preview is showed and cleared when the preview is hidden. | |
| 430 base::Time first_interaction_time_; | |
| 431 | |
| 432 // Whether to allow the preview to show search suggestions. In general, the | |
| 433 // preview is allowed to show search suggestions whenever |search_mode_| is | |
| 434 // MODE_SEARCH_SUGGESTIONS, except in those cases where this is false. | |
| 435 bool allow_preview_to_show_search_suggestions_; | |
| 436 | |
| 437 // List of events and their timestamps, useful in debugging Instant behaviour. | |
| 438 mutable std::list<std::pair<int64, std::string> > debug_events_; | |
| 439 | |
| 440 // Used for Top Sites async retrieval. | |
| 441 base::WeakPtrFactory<InstantController> weak_ptr_factory_; | |
| 442 | |
| 443 // Used to get notifications about Most Visted changes. | |
| 444 content::NotificationRegistrar registrar_; | |
| 445 | |
| 446 DISALLOW_COPY_AND_ASSIGN(InstantController); | 137 DISALLOW_COPY_AND_ASSIGN(InstantController); |
| 447 }; | 138 }; |
| 448 | 139 |
| 449 #endif // CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_ | 140 #endif // CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_ |
| OLD | NEW |