Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 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_INSTANT_CONTROLLER_H_ |
| 6 | #define CHROME_BROWSER_UI_SEARCH_INSTANT_CONTROLLER_H_ |
| 7 | |
| 8 | #include <list> |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 9 | #include <string> |
| 10 | #include <utility> |
| 11 | #include <vector> |
| 12 | |
| 13 | #include "base/basictypes.h" |
| 14 | #include "base/gtest_prod_util.h" |
| 15 | #include "base/memory/scoped_ptr.h" |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 16 | #include "base/strings/string16.h" |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 17 | #include "chrome/browser/search/instant_service_observer.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 18 | #include "chrome/browser/ui/search/instant_page.h" |
| 19 | #include "chrome/common/instant_types.h" |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 20 | #include "chrome/common/omnibox_focus_state.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 21 | #include "chrome/common/search_types.h" |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame^] | 22 | #include "content/public/common/page_transition_types.h" |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 23 | #include "net/base/network_change_notifier.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 24 | #include "ui/base/window_open_disposition.h" |
| 25 | #include "ui/gfx/native_widget_types.h" |
| 26 | #include "ui/gfx/rect.h" |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame^] | 27 | #include "url/gurl.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 28 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 29 | class BrowserInstantController; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 30 | class InstantNTP; |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 31 | class InstantService; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 32 | class InstantTab; |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 33 | class Profile; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 34 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 35 | namespace content { |
| 36 | class WebContents; |
| 37 | } |
| 38 | |
| 39 | // Macro used for logging debug events. |message| should be a std::string. |
| 40 | #define LOG_INSTANT_DEBUG_EVENT(controller, message) \ |
| 41 | controller->LogDebugEvent(message) |
| 42 | |
| 43 | // InstantController drives Chrome Instant, i.e., the browser implementation of |
| 44 | // the Embedded Search API (see http://dev.chromium.org/embeddedsearch). |
| 45 | // |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 46 | // In extended mode, InstantController maintains and coordinates two |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 47 | // instances of InstantPage: |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 48 | // (1) An InstantNTP instance which is a preloaded search page that will be |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 49 | // swapped-in the next time the user navigates to the New Tab Page. It is |
| 50 | // never shown to the user in an uncommitted state. |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 51 | // (2) An InstantTab instance which points to the currently active tab, if it |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 52 | // supports the Embedded Search API. |
| 53 | // |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 54 | // Both are backed by a WebContents. InstantNTP owns its WebContents and |
| 55 | // InstantTab does not. |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 56 | // |
| 57 | // InstantController is owned by Browser via BrowserInstantController. |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 58 | class InstantController : public InstantPage::Delegate, |
| 59 | public InstantServiceObserver { |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 60 | public: |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 61 | InstantController(BrowserInstantController* browser, |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 62 | bool extended_enabled); |
| 63 | virtual ~InstantController(); |
| 64 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 65 | // Releases and returns the NTP WebContents. May be NULL. Loads a new |
| 66 | // WebContents for the NTP. |
| 67 | scoped_ptr<content::WebContents> ReleaseNTPContents() WARN_UNUSED_RESULT; |
| 68 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 69 | // Sets the stored start-edge margin and width of the omnibox. |
| 70 | void SetOmniboxBounds(const gfx::Rect& bounds); |
| 71 | |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 72 | // Called when the default search provider changes. Resets InstantNTP. |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 73 | void OnDefaultSearchProviderChanged(); |
| 74 | |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 75 | // Notifies |instant_Tab_| to toggle voice search. |
| 76 | void ToggleVoiceSearch(); |
| 77 | |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 78 | // The ntp WebContents. May be NULL. InstantController retains ownership. |
| 79 | content::WebContents* GetNTPContents() const; |
| 80 | |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 81 | // Called if the browser is navigating to a search URL for |search_terms| with |
| 82 | // search-term-replacement enabled. If |instant_tab_| can be used to process |
| 83 | // the search, this does so and returns true. Else, returns false. |
| 84 | bool SubmitQuery(const string16& search_terms); |
| 85 | |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 86 | // If the network status changes, try to reset NTP and Overlay. |
| 87 | void OnNetworkChanged(net::NetworkChangeNotifier::ConnectionType type); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 88 | |
| 89 | // Called to indicate that the omnibox focus state changed with the given |
| 90 | // |reason|. If |focus_state| is FOCUS_NONE, |view_gaining_focus| is set to |
| 91 | // the view gaining focus. |
| 92 | void OmniboxFocusChanged(OmniboxFocusState focus_state, |
| 93 | OmniboxFocusChangeReason reason, |
| 94 | gfx::NativeView view_gaining_focus); |
| 95 | |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 96 | // The search mode in the active tab has changed. Bind |instant_tab_| if the |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 97 | // |new_mode| reflects an Instant search results page. |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 98 | void SearchModeChanged(const SearchMode& old_mode, |
| 99 | const SearchMode& new_mode); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 100 | |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 101 | // The user switched tabs. Bind |instant_tab_| if the newly active tab is an |
| 102 | // Instant search results page. |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 103 | void ActiveTabChanged(); |
| 104 | |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 105 | // The user is about to switch tabs. |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 106 | void TabDeactivated(content::WebContents* contents); |
| 107 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 108 | // Adds a new event to |debug_events_| and also DVLOG's it. Ensures that |
| 109 | // |debug_events_| doesn't get too large. |
| 110 | void LogDebugEvent(const std::string& info) const; |
| 111 | |
| 112 | // Resets list of debug events. |
| 113 | void ClearDebugEvents(); |
| 114 | |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 115 | // Loads a new NTP to replace |ntp_|. |
| 116 | void ReloadStaleNTP(); |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 117 | |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 118 | // Returns the correct Instant URL to use from the following possibilities: |
| 119 | // o The default search engine's Instant URL |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 120 | // o The local page (see GetLocalInstantURL()) |
| 121 | // Returns empty string if no valid Instant URL is available (this is only |
| 122 | // possible in non-extended mode where we don't have a local page fall-back). |
| 123 | virtual std::string GetInstantURL() const; |
| 124 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 125 | // See comments for |debug_events_| below. |
| 126 | const std::list<std::pair<int64, std::string> >& debug_events() { |
| 127 | return debug_events_; |
| 128 | } |
| 129 | |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 130 | // Used by BrowserInstantController to notify InstantController about the |
| 131 | // instant support change event for the active web contents. |
| 132 | void InstantSupportChanged(InstantSupportState instant_support); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 133 | |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 134 | protected: |
| 135 | // Accessors are made protected for testing purposes. |
| 136 | virtual bool extended_enabled() const; |
| 137 | |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 138 | virtual InstantTab* instant_tab() const; |
| 139 | virtual InstantNTP* ntp() const; |
| 140 | |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 141 | virtual Profile* profile() const; |
| 142 | |
| 143 | // Returns true if Javascript is enabled and false otherwise. |
| 144 | virtual bool IsJavascriptEnabled() const; |
| 145 | |
| 146 | // Returns true if the browser is in startup. |
| 147 | virtual bool InStartup() const; |
| 148 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 149 | private: |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 150 | friend class InstantExtendedManualTest; |
Torne (Richard Coles) | b2df76e | 2013-05-13 16:52:09 +0100 | [diff] [blame] | 151 | friend class InstantTestBase; |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 152 | #define UNIT_F(test) FRIEND_TEST_ALL_PREFIXES(InstantControllerTest, test) |
| 153 | UNIT_F(DoesNotSwitchToLocalNTPIfOnCurrentNTP); |
| 154 | UNIT_F(DoesNotSwitchToLocalNTPIfOnLocalNTP); |
| 155 | UNIT_F(IsJavascriptEnabled); |
| 156 | UNIT_F(IsJavascriptEnabledChecksContentSettings); |
| 157 | UNIT_F(IsJavascriptEnabledChecksPrefs); |
| 158 | UNIT_F(PrefersRemoteNTPOnStartup); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 159 | UNIT_F(SwitchesToLocalNTPIfJSDisabled); |
| 160 | UNIT_F(SwitchesToLocalNTPIfNoInstantSupport); |
| 161 | UNIT_F(SwitchesToLocalNTPIfNoNTPReady); |
| 162 | UNIT_F(SwitchesToLocalNTPIfPathBad); |
| 163 | #undef UNIT_F |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 164 | FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, ExtendedModeIsOn); |
| 165 | FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, MostVisited); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 166 | FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, NTPIsPreloaded); |
| 167 | FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, PreloadedNTPIsUsedInNewTab); |
| 168 | FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, PreloadedNTPIsUsedInSameTab); |
| 169 | FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, PreloadedNTPForWrongProvider); |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame^] | 170 | FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, PreloadedNTPRenderProcessGone); |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 171 | FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, |
| 172 | PreloadedNTPDoesntSupportInstant); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 173 | FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, ProcessIsolation); |
| 174 | FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, UnrelatedSiteInstance); |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 175 | FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, OnDefaultSearchProviderChanged); |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 176 | FRIEND_TEST_ALL_PREFIXES(InstantExtendedNetworkTest, |
| 177 | NTPReactsToNetworkChanges); |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 178 | FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, |
| 179 | AcceptingURLSearchDoesNotNavigate); |
| 180 | FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, AcceptingJSSearchDoesNotRunJS); |
| 181 | FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, |
| 182 | ReloadSearchAfterBackReloadsCorrectQuery); |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 183 | FRIEND_TEST_ALL_PREFIXES(InstantExtendedFirstTabTest, |
| 184 | RedirectToLocalOnLoadFailure); |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 185 | FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, KeyboardTogglesVoiceSearch); |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 186 | FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, HomeButtonAffectsMargin); |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 187 | FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, SearchReusesInstantTab); |
| 188 | FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, |
| 189 | SearchDoesntReuseInstantTabWithoutSupport); |
| 190 | FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, |
| 191 | TypedSearchURLDoesntReuseInstantTab); |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 192 | FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, |
| 193 | DispatchMVChangeEventWhileNavigatingBackToNTP); |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 194 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 195 | // Overridden from InstantPage::Delegate: |
| 196 | // TODO(shishir): We assume that the WebContent's current RenderViewHost is |
| 197 | // the RenderViewHost being created which is not always true. Fix this. |
| 198 | virtual void InstantPageRenderViewCreated( |
| 199 | const content::WebContents* contents) OVERRIDE; |
| 200 | virtual void InstantSupportDetermined( |
| 201 | const content::WebContents* contents, |
| 202 | bool supports_instant) OVERRIDE; |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame^] | 203 | virtual void InstantPageRenderProcessGone( |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 204 | const content::WebContents* contents) OVERRIDE; |
| 205 | virtual void InstantPageAboutToNavigateMainFrame( |
| 206 | const content::WebContents* contents, |
| 207 | const GURL& url) OVERRIDE; |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 208 | virtual void FocusOmnibox(const content::WebContents* contents, |
| 209 | OmniboxFocusState state) OVERRIDE; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 210 | virtual void NavigateToURL( |
| 211 | const content::WebContents* contents, |
| 212 | const GURL& url, |
| 213 | content::PageTransition transition, |
Torne (Richard Coles) | a93a17c | 2013-05-15 11:34:50 +0100 | [diff] [blame] | 214 | WindowOpenDisposition disposition, |
| 215 | bool is_search_type) OVERRIDE; |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 216 | virtual void InstantPageLoadFailed(content::WebContents* contents) OVERRIDE; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 217 | |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 218 | // Overridden from InstantServiceObserver: |
| 219 | virtual void ThemeInfoChanged(const ThemeBackgroundInfo& theme_info) OVERRIDE; |
| 220 | virtual void MostVisitedItemsChanged( |
| 221 | const std::vector<InstantMostVisitedItem>& items) OVERRIDE; |
| 222 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 223 | // Invoked by the InstantLoader when the Instant page wants to delete a |
| 224 | // Most Visited item. |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 225 | virtual void DeleteMostVisitedItem(const GURL& url) OVERRIDE; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 226 | |
| 227 | // Invoked by the InstantLoader when the Instant page wants to undo a |
| 228 | // Most Visited deletion. |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 229 | virtual void UndoMostVisitedDeletion(const GURL& url) OVERRIDE; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 230 | |
| 231 | // Invoked by the InstantLoader when the Instant page wants to undo all |
| 232 | // Most Visited deletions. |
| 233 | virtual void UndoAllMostVisitedDeletions() OVERRIDE; |
| 234 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 235 | // Helper function to navigate the given contents to the local fallback |
| 236 | // Instant URL and trim the history correctly. |
| 237 | void RedirectToLocalNTP(content::WebContents* contents); |
| 238 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 239 | // Helper for OmniboxFocusChanged. Commit or discard the overlay. |
| 240 | void OmniboxLostFocus(gfx::NativeView view_gaining_focus); |
| 241 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 242 | // Returns the local Instant URL. (Just a convenience wrapper around |
| 243 | // chrome::GetLocalInstantURL.) |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 244 | virtual std::string GetLocalInstantURL() const; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 245 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 246 | // Returns true if |page| has an up-to-date Instant URL and supports Instant. |
| 247 | // Note that local URLs will not pass this check. |
| 248 | bool PageIsCurrent(const InstantPage* page) const; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 249 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 250 | // Recreates |ntp_| using |instant_url|. |
| 251 | void ResetNTP(const std::string& instant_url); |
| 252 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 253 | // Returns true if we should switch to using the local NTP. |
| 254 | bool ShouldSwitchToLocalNTP() const; |
| 255 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 256 | // If the active tab is an Instant search results page, sets |instant_tab_| to |
| 257 | // point to it. Else, deletes any existing |instant_tab_|. |
| 258 | void ResetInstantTab(); |
| 259 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 260 | // Sends theme info, omnibox bounds, font info, etc. down to the Instant tab. |
| 261 | void UpdateInfoForInstantTab(); |
| 262 | |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 263 | // Returns whether input is in progress, i.e. if the omnibox has focus and the |
| 264 | // active tab is in mode SEARCH_SUGGESTIONS. |
| 265 | bool IsInputInProgress() const; |
| 266 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 267 | // Returns true if the local page is being used. |
| 268 | bool UsingLocalPage() const; |
| 269 | |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 270 | // Returns the InstantService for the browser profile. |
| 271 | InstantService* GetInstantService() const; |
Torne (Richard Coles) | b2df76e | 2013-05-13 16:52:09 +0100 | [diff] [blame] | 272 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 273 | BrowserInstantController* const browser_; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 274 | |
| 275 | // Whether the extended API and regular API are enabled. If both are false, |
| 276 | // Instant is effectively disabled. |
| 277 | const bool extended_enabled_; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 278 | |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 279 | // The instances of InstantPage maintained by InstantController. |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 280 | scoped_ptr<InstantNTP> ntp_; |
| 281 | scoped_ptr<InstantTab> instant_tab_; |
| 282 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 283 | // Omnibox focus state. |
| 284 | OmniboxFocusState omnibox_focus_state_; |
| 285 | |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 286 | // The reason for the most recent omnibox focus change. |
| 287 | OmniboxFocusChangeReason omnibox_focus_change_reason_; |
| 288 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 289 | // The search model mode for the active tab. |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 290 | SearchMode search_mode_; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 291 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 292 | // The start-edge margin and width of the omnibox, used by the page to align |
| 293 | // its suggestions with the omnibox. |
| 294 | gfx::Rect omnibox_bounds_; |
| 295 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 296 | // List of events and their timestamps, useful in debugging Instant behaviour. |
| 297 | mutable std::list<std::pair<int64, std::string> > debug_events_; |
| 298 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 299 | DISALLOW_COPY_AND_ASSIGN(InstantController); |
| 300 | }; |
| 301 | |
| 302 | #endif // CHROME_BROWSER_UI_SEARCH_INSTANT_CONTROLLER_H_ |