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_UI_SEARCH_INSTANT_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_UI_SEARCH_INSTANT_CONTROLLER_H_ |
6 #define CHROME_BROWSER_UI_SEARCH_INSTANT_CONTROLLER_H_ | 6 #define CHROME_BROWSER_UI_SEARCH_INSTANT_CONTROLLER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <list> | 10 #include <list> |
11 #include <memory> | 11 #include <memory> |
12 #include <string> | 12 #include <string> |
13 #include <utility> | 13 #include <utility> |
14 | 14 |
15 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/strings/string16.h" | 17 #include "base/strings/string16.h" |
18 #include "chrome/browser/ui/search/instant_page.h" | 18 #include "chrome/browser/ui/search/instant_tab.h" |
19 #include "chrome/common/search/search_types.h" | 19 #include "chrome/common/search/search_types.h" |
20 | 20 |
21 class BrowserInstantController; | 21 class BrowserInstantController; |
22 class GURL; | 22 class GURL; |
23 class InstantService; | 23 class InstantService; |
24 class InstantTab; | |
25 class Profile; | 24 class Profile; |
26 struct EmbeddedSearchRequestParams; | 25 struct EmbeddedSearchRequestParams; |
27 | 26 |
28 namespace content { | 27 namespace content { |
29 class WebContents; | 28 class WebContents; |
30 } | 29 } |
31 | 30 |
32 // InstantController drives Chrome Instant, i.e., the browser implementation of | 31 // InstantController drives Chrome Instant, i.e., the browser implementation of |
33 // the Embedded Search API (see http://dev.chromium.org/embeddedsearch). | 32 // the Embedded Search API (see http://dev.chromium.org/embeddedsearch). |
34 // | 33 // |
35 // In extended mode, InstantController maintains and coordinates an InstantTab | 34 // In extended mode, InstantController maintains and coordinates an InstantTab. |
36 // instance of InstantPage. An InstantTab instance points to the currently | 35 // An InstantTab instance points to the currently active tab, if it supports the |
37 // active tab, if it supports the Embedded Search API. InstantTab is backed by a | 36 // Embedded Search API. InstantTab is backed by a WebContents and it does not |
38 // WebContents and it does not own that WebContents. | 37 // own that WebContents. |
39 // | 38 // |
40 // InstantController is owned by Browser via BrowserInstantController. | 39 // InstantController is owned by Browser via BrowserInstantController. |
41 class InstantController : public InstantPage::Delegate { | 40 class InstantController : public InstantTab::Delegate { |
42 public: | 41 public: |
43 explicit InstantController(BrowserInstantController* browser); | 42 explicit InstantController(BrowserInstantController* browser); |
44 ~InstantController() override; | 43 ~InstantController() override; |
45 | 44 |
46 // Called if the browser is navigating to a search URL for |search_terms| with | 45 // Called if the browser is navigating to a search URL for |search_terms| with |
47 // search-term-replacement enabled. If |instant_tab_| can be used to process | 46 // search-term-replacement enabled. If |instant_tab_| can be used to process |
48 // the search, this does so and returns true. Else, returns false. | 47 // the search, this does so and returns true. Else, returns false. |
49 bool SubmitQuery(const base::string16& search_terms, | 48 bool SubmitQuery(const base::string16& search_terms, |
50 const EmbeddedSearchRequestParams& params); | 49 const EmbeddedSearchRequestParams& params); |
51 | 50 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, KeyboardTogglesVoiceSearch); | 96 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, KeyboardTogglesVoiceSearch); |
98 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, HomeButtonAffectsMargin); | 97 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, HomeButtonAffectsMargin); |
99 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, SearchReusesInstantTab); | 98 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, SearchReusesInstantTab); |
100 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, | 99 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, |
101 SearchDoesntReuseInstantTabWithoutSupport); | 100 SearchDoesntReuseInstantTabWithoutSupport); |
102 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, | 101 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, |
103 TypedSearchURLDoesntReuseInstantTab); | 102 TypedSearchURLDoesntReuseInstantTab); |
104 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, | 103 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, |
105 DispatchMVChangeEventWhileNavigatingBackToNTP); | 104 DispatchMVChangeEventWhileNavigatingBackToNTP); |
106 | 105 |
107 // Overridden from InstantPage::Delegate: | 106 // Overridden from InstantTab::Delegate: |
108 // TODO(shishir): We assume that the WebContent's current RenderViewHost is | 107 // TODO(shishir): We assume that the WebContent's current RenderViewHost is |
109 // the RenderViewHost being created which is not always true. Fix this. | 108 // the RenderViewHost being created which is not always true. Fix this. |
110 void InstantSupportDetermined(const content::WebContents* contents, | 109 void InstantSupportDetermined(const content::WebContents* contents, |
111 bool supports_instant) override; | 110 bool supports_instant) override; |
112 void InstantPageAboutToNavigateMainFrame(const content::WebContents* contents, | 111 void InstantTabAboutToNavigateMainFrame(const content::WebContents* contents, |
113 const GURL& url) override; | 112 const GURL& url) override; |
114 | 113 |
115 // If the active tab is an Instant search results page, sets |instant_tab_| to | 114 // If the active tab is an Instant search results page, sets |instant_tab_| to |
116 // point to it. Else, deletes any existing |instant_tab_|. | 115 // point to it. Else, deletes any existing |instant_tab_|. |
117 void ResetInstantTab(); | 116 void ResetInstantTab(); |
118 | 117 |
119 // Sends theme info and most visited items to the Instant tab. | 118 // Sends theme info and most visited items to the Instant tab. |
120 void UpdateInfoForInstantTab(); | 119 void UpdateInfoForInstantTab(); |
121 | 120 |
122 // Returns the InstantService for the browser profile. | 121 // Returns the InstantService for the browser profile. |
123 InstantService* GetInstantService() const; | 122 InstantService* GetInstantService() const; |
124 | 123 |
125 BrowserInstantController* const browser_; | 124 BrowserInstantController* const browser_; |
126 | 125 |
127 // The instance of InstantPage maintained by InstantController. | 126 // The instance of InstantTab maintained by InstantController. |
128 std::unique_ptr<InstantTab> instant_tab_; | 127 std::unique_ptr<InstantTab> instant_tab_; |
129 | 128 |
130 // The search model mode for the active tab. | 129 // The search model mode for the active tab. |
131 SearchMode search_mode_; | 130 SearchMode search_mode_; |
132 | 131 |
133 // List of events and their timestamps, useful in debugging Instant behaviour. | 132 // List of events and their timestamps, useful in debugging Instant behaviour. |
134 mutable std::list<std::pair<int64_t, std::string>> debug_events_; | 133 mutable std::list<std::pair<int64_t, std::string>> debug_events_; |
135 | 134 |
136 DISALLOW_COPY_AND_ASSIGN(InstantController); | 135 DISALLOW_COPY_AND_ASSIGN(InstantController); |
137 }; | 136 }; |
138 | 137 |
139 #endif // CHROME_BROWSER_UI_SEARCH_INSTANT_CONTROLLER_H_ | 138 #endif // CHROME_BROWSER_UI_SEARCH_INSTANT_CONTROLLER_H_ |
OLD | NEW |