| 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 InstantPage; | |
| 24 class InstantService; | 23 class InstantService; |
| 24 class InstantTab; |
| 25 class Profile; | 25 class Profile; |
| 26 struct EmbeddedSearchRequestParams; | 26 struct EmbeddedSearchRequestParams; |
| 27 | 27 |
| 28 namespace content { | 28 namespace content { |
| 29 class WebContents; | 29 class WebContents; |
| 30 } | 30 } |
| 31 | 31 |
| 32 // InstantController drives Chrome Instant, i.e., the browser implementation of | 32 // InstantController drives Chrome Instant, i.e., the browser implementation of |
| 33 // the Embedded Search API (see http://dev.chromium.org/embeddedsearch). | 33 // the Embedded Search API (see http://dev.chromium.org/embeddedsearch). |
| 34 // | 34 // |
| 35 // In extended mode, InstantController maintains and coordinates an InstantTab | 35 // In extended mode, InstantController maintains and coordinates an InstantTab |
| 36 // instance of InstantPage. An InstantTab instance points to the currently | 36 // 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 | 37 // Embedded Search API. InstantTab is backed by a WebContents and it does not |
| 38 // WebContents and it does not own that WebContents. | 38 // own that WebContents. |
| 39 // | 39 // |
| 40 // InstantController is owned by Browser via BrowserInstantController. | 40 // InstantController is owned by Browser via BrowserInstantController. |
| 41 class InstantController : public InstantPage::Delegate { | 41 class InstantController : public InstantTab::Delegate { |
| 42 public: | 42 public: |
| 43 explicit InstantController(BrowserInstantController* browser); | 43 explicit InstantController(BrowserInstantController* browser); |
| 44 ~InstantController() override; | 44 ~InstantController() override; |
| 45 | 45 |
| 46 // Called if the browser is navigating to a search URL for |search_terms| with | 46 // 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 | 47 // search-term-replacement enabled. If |instant_tab_| can be used to process |
| 48 // the search, this does so and returns true. Else, returns false. | 48 // the search, this does so and returns true. Else, returns false. |
| 49 bool SubmitQuery(const base::string16& search_terms, | 49 bool SubmitQuery(const base::string16& search_terms, |
| 50 const EmbeddedSearchRequestParams& params); | 50 const EmbeddedSearchRequestParams& params); |
| 51 | 51 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 69 const std::list<std::pair<int64_t, std::string>>& debug_events() { | 69 const std::list<std::pair<int64_t, std::string>>& debug_events() { |
| 70 return debug_events_; | 70 return debug_events_; |
| 71 } | 71 } |
| 72 | 72 |
| 73 // Used by BrowserInstantController to notify InstantController about the | 73 // Used by BrowserInstantController to notify InstantController about the |
| 74 // instant support change event for the active web contents. | 74 // instant support change event for the active web contents. |
| 75 void InstantSupportChanged(InstantSupportState instant_support); | 75 void InstantSupportChanged(InstantSupportState instant_support); |
| 76 | 76 |
| 77 protected: | 77 protected: |
| 78 // Accessors are made protected for testing purposes. | 78 // Accessors are made protected for testing purposes. |
| 79 virtual InstantPage* instant_tab() const; | 79 virtual InstantTab* instant_tab() const; |
| 80 | 80 |
| 81 virtual Profile* profile() const; | 81 virtual Profile* profile() const; |
| 82 | 82 |
| 83 private: | 83 private: |
| 84 friend class InstantExtendedManualTest; | 84 friend class InstantExtendedManualTest; |
| 85 friend class InstantTestBase; | 85 friend class InstantTestBase; |
| 86 | 86 |
| 87 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, ExtendedModeIsOn); | 87 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, ExtendedModeIsOn); |
| 88 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, MostVisited); | 88 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, MostVisited); |
| 89 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, ProcessIsolation); | 89 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, ProcessIsolation); |
| 90 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, UnrelatedSiteInstance); | 90 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, UnrelatedSiteInstance); |
| 91 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, OnDefaultSearchProviderChanged); | 91 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, OnDefaultSearchProviderChanged); |
| 92 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, | 92 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, |
| 93 AcceptingURLSearchDoesNotNavigate); | 93 AcceptingURLSearchDoesNotNavigate); |
| 94 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, AcceptingJSSearchDoesNotRunJS); | 94 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, AcceptingJSSearchDoesNotRunJS); |
| 95 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, | 95 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, |
| 96 ReloadSearchAfterBackReloadsCorrectQuery); | 96 ReloadSearchAfterBackReloadsCorrectQuery); |
| 97 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, KeyboardTogglesVoiceSearch); | 97 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, KeyboardTogglesVoiceSearch); |
| 98 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, HomeButtonAffectsMargin); | 98 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, HomeButtonAffectsMargin); |
| 99 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, SearchReusesInstantTab); | 99 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, SearchReusesInstantTab); |
| 100 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, | 100 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, |
| 101 SearchDoesntReuseInstantTabWithoutSupport); | 101 SearchDoesntReuseInstantTabWithoutSupport); |
| 102 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, | 102 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, |
| 103 TypedSearchURLDoesntReuseInstantTab); | 103 TypedSearchURLDoesntReuseInstantTab); |
| 104 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, | 104 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, |
| 105 DispatchMVChangeEventWhileNavigatingBackToNTP); | 105 DispatchMVChangeEventWhileNavigatingBackToNTP); |
| 106 | 106 |
| 107 // Overridden from InstantPage::Delegate: | 107 // Overridden from InstantTab::Delegate: |
| 108 // TODO(shishir): We assume that the WebContent's current RenderViewHost is | 108 // TODO(shishir): We assume that the WebContent's current RenderViewHost is |
| 109 // the RenderViewHost being created which is not always true. Fix this. | 109 // the RenderViewHost being created which is not always true. Fix this. |
| 110 void InstantSupportDetermined(const content::WebContents* contents, | 110 void InstantSupportDetermined(const content::WebContents* contents, |
| 111 bool supports_instant) override; | 111 bool supports_instant) override; |
| 112 void InstantPageAboutToNavigateMainFrame(const content::WebContents* contents, | 112 void InstantTabAboutToNavigateMainFrame(const content::WebContents* contents, |
| 113 const GURL& url) override; | 113 const GURL& url) override; |
| 114 | 114 |
| 115 // If the active tab is an Instant search results page, sets |instant_tab_| to | 115 // If the active tab is an Instant search results page, sets |instant_tab_| to |
| 116 // point to it. Else, deletes any existing |instant_tab_|. | 116 // point to it. Else, deletes any existing |instant_tab_|. |
| 117 void ResetInstantTab(); | 117 void ResetInstantTab(); |
| 118 | 118 |
| 119 // Sends theme info and most visited items to the Instant tab. | 119 // Sends theme info and most visited items to the Instant tab. |
| 120 void UpdateInfoForInstantTab(); | 120 void UpdateInfoForInstantTab(); |
| 121 | 121 |
| 122 // Returns the InstantService for the browser profile. | 122 // Returns the InstantService for the browser profile. |
| 123 InstantService* GetInstantService() const; | 123 InstantService* GetInstantService() const; |
| 124 | 124 |
| 125 BrowserInstantController* const browser_; | 125 BrowserInstantController* const browser_; |
| 126 | 126 |
| 127 // The instance of InstantPage maintained by InstantController. | 127 // The instance of InstantTab maintained by InstantController. |
| 128 std::unique_ptr<InstantPage> instant_tab_; | 128 std::unique_ptr<InstantTab> instant_tab_; |
| 129 | 129 |
| 130 // The search model mode for the active tab. | 130 // The search model mode for the active tab. |
| 131 SearchMode search_mode_; | 131 SearchMode search_mode_; |
| 132 | 132 |
| 133 // List of events and their timestamps, useful in debugging Instant behaviour. | 133 // List of events and their timestamps, useful in debugging Instant behaviour. |
| 134 mutable std::list<std::pair<int64_t, std::string>> debug_events_; | 134 mutable std::list<std::pair<int64_t, std::string>> debug_events_; |
| 135 | 135 |
| 136 DISALLOW_COPY_AND_ASSIGN(InstantController); | 136 DISALLOW_COPY_AND_ASSIGN(InstantController); |
| 137 }; | 137 }; |
| 138 | 138 |
| 139 #endif // CHROME_BROWSER_UI_SEARCH_INSTANT_CONTROLLER_H_ | 139 #endif // CHROME_BROWSER_UI_SEARCH_INSTANT_CONTROLLER_H_ |
| OLD | NEW |