Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / ui / search / search_ipc_router.h
blob22db1726ffe40d653b533fbf4077ed225944c945
1 // Copyright 2013 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.
5 #ifndef CHROME_BROWSER_UI_SEARCH_SEARCH_IPC_ROUTER_H_
6 #define CHROME_BROWSER_UI_SEARCH_SEARCH_IPC_ROUTER_H_
8 #include <vector>
10 #include "base/gtest_prod_util.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "chrome/common/instant_types.h"
13 #include "chrome/common/ntp_logging_events.h"
14 #include "chrome/common/omnibox_focus_state.h"
15 #include "content/public/browser/web_contents_observer.h"
16 #include "ui/base/window_open_disposition.h"
18 class GURL;
20 namespace content {
21 class WebContents;
24 class SearchIPCRouterTest;
26 // SearchIPCRouter is responsible for receiving and sending IPC messages between
27 // the browser and the Instant page.
28 class SearchIPCRouter : public content::WebContentsObserver {
29 public:
30 // SearchIPCRouter calls its delegate in response to messages received from
31 // the page.
32 class Delegate {
33 public:
34 // Called upon determination of Instant API support in response to the page
35 // load event.
36 virtual void OnInstantSupportDetermined(bool supports_instant) = 0;
38 // Called upon determination of voice search API support.
39 virtual void OnSetVoiceSearchSupport(bool supports_voice_search) = 0;
41 // Called when the page wants the omnibox to be focused. |state| specifies
42 // the omnibox focus state.
43 virtual void FocusOmnibox(OmniboxFocusState state) = 0;
45 // Called when the page wants to navigate to |url|. Usually used by the
46 // page to navigate to privileged destinations (e.g. chrome:// URLs) or to
47 // navigate to URLs that are hidden from the page using Restricted IDs (rid
48 // in the API).
49 virtual void NavigateToURL(const GURL& url,
50 WindowOpenDisposition disposition,
51 bool is_most_visited_item_url) = 0;
53 // Called when the SearchBox wants to delete a Most Visited item.
54 virtual void OnDeleteMostVisitedItem(const GURL& url) = 0;
56 // Called when the SearchBox wants to undo a Most Visited deletion.
57 virtual void OnUndoMostVisitedDeletion(const GURL& url) = 0;
59 // Called when the SearchBox wants to undo all Most Visited deletions.
60 virtual void OnUndoAllMostVisitedDeletions() = 0;
62 // Called to signal that an event has occurred on the New Tab Page.
63 virtual void OnLogEvent(NTPLoggingEventType event) = 0;
65 // Called to log an impression from a given provider on the New Tab Page.
66 virtual void OnLogMostVisitedImpression(int position,
67 const base::string16& provider) = 0;
69 // Called to log a navigation from a given provider on the New Tab Page.
70 virtual void OnLogMostVisitedNavigation(int position,
71 const base::string16& provider) = 0;
73 // Called when the page wants to paste the |text| (or the clipboard contents
74 // if the |text| is empty) into the omnibox.
75 virtual void PasteIntoOmnibox(const base::string16& text) = 0;
77 // Called when the SearchBox wants to verify the signed-in Chrome identity
78 // against the provided |identity|. Will make a round-trip to the browser
79 // and eventually return the result through SendChromeIdentityCheckResult.
80 virtual void OnChromeIdentityCheck(const base::string16& identity) = 0;
83 // An interface to be implemented by consumers of SearchIPCRouter objects to
84 // decide whether to process the message received from the page, and vice
85 // versa (decide whether to send messages to the page).
86 class Policy {
87 public:
88 virtual ~Policy() {}
90 // SearchIPCRouter calls these functions before sending/receiving messages
91 // to/from the page.
92 virtual bool ShouldProcessSetVoiceSearchSupport() = 0;
93 virtual bool ShouldProcessFocusOmnibox(bool is_active_tab) = 0;
94 virtual bool ShouldProcessNavigateToURL(bool is_active_tab) = 0;
95 virtual bool ShouldProcessDeleteMostVisitedItem() = 0;
96 virtual bool ShouldProcessUndoMostVisitedDeletion() = 0;
97 virtual bool ShouldProcessUndoAllMostVisitedDeletions() = 0;
98 virtual bool ShouldProcessLogEvent() = 0;
99 virtual bool ShouldProcessPasteIntoOmnibox(bool is_active_tab) = 0;
100 virtual bool ShouldProcessChromeIdentityCheck() = 0;
101 virtual bool ShouldSendSetPromoInformation() = 0;
102 virtual bool ShouldSendSetDisplayInstantResults() = 0;
103 virtual bool ShouldSendSetSuggestionToPrefetch() = 0;
104 virtual bool ShouldSendSetOmniboxStartMargin() = 0;
105 virtual bool ShouldSendSetInputInProgress(bool is_active_tab) = 0;
106 virtual bool ShouldSendOmniboxFocusChanged() = 0;
107 virtual bool ShouldSendMostVisitedItems() = 0;
108 virtual bool ShouldSendThemeBackgroundInfo() = 0;
109 virtual bool ShouldSendToggleVoiceSearch() = 0;
110 virtual bool ShouldSubmitQuery() = 0;
113 SearchIPCRouter(content::WebContents* web_contents, Delegate* delegate,
114 scoped_ptr<Policy> policy);
115 virtual ~SearchIPCRouter();
117 // Tells the renderer to determine if the page supports the Instant API, which
118 // results in a call to OnInstantSupportDetermined() when the reply is
119 // received.
120 void DetermineIfPageSupportsInstant();
122 // Tells the renderer about the result of the Chrome identity check.
123 void SendChromeIdentityCheckResult(const base::string16& identity,
124 bool identity_match);
126 // Tells the renderer information it needs to display promos.
127 void SetPromoInformation(bool is_app_launcher_enabled);
129 // Tells the renderer whether to display the Instant results.
130 void SetDisplayInstantResults();
132 // Tells the page the suggestion to be prefetched if any.
133 void SetSuggestionToPrefetch(const InstantSuggestion& suggestion);
135 // Tells the page the left margin of the omnibox. This is used by the page to
136 // align text or assets properly with the omnibox.
137 void SetOmniboxStartMargin(int start_margin);
139 // Tells the page that user input started or stopped.
140 void SetInputInProgress(bool input_in_progress);
142 // Tells the page that the omnibox focus has changed.
143 void OmniboxFocusChanged(OmniboxFocusState state,
144 OmniboxFocusChangeReason reason);
146 // Tells the renderer about the most visited items.
147 void SendMostVisitedItems(const std::vector<InstantMostVisitedItem>& items);
149 // Tells the renderer about the current theme background.
150 void SendThemeBackgroundInfo(const ThemeBackgroundInfo& theme_info);
152 // Tells the page to toggle voice search.
153 void ToggleVoiceSearch();
155 // Tells the page that the user pressed Enter in the omnibox.
156 void Submit(const base::string16& text);
158 // Called when the tab corresponding to |this| instance is activated.
159 void OnTabActivated();
161 // Called when the tab corresponding to |this| instance is deactivated.
162 void OnTabDeactivated();
164 private:
165 friend class SearchIPCRouterPolicyTest;
166 friend class SearchIPCRouterTest;
167 FRIEND_TEST_ALL_PREFIXES(SearchTabHelperTest,
168 DetermineIfPageSupportsInstant_Local);
169 FRIEND_TEST_ALL_PREFIXES(SearchTabHelperTest,
170 DetermineIfPageSupportsInstant_NonLocal);
171 FRIEND_TEST_ALL_PREFIXES(SearchTabHelperTest,
172 PageURLDoesntBelongToInstantRenderer);
173 FRIEND_TEST_ALL_PREFIXES(SearchIPCRouterTest,
174 IgnoreMessageIfThePageIsNotActive);
175 FRIEND_TEST_ALL_PREFIXES(SearchIPCRouterTest,
176 DoNotSendSetDisplayInstantResultsMsg);
177 FRIEND_TEST_ALL_PREFIXES(SearchIPCRouterTest, HandleTabChangedEvents);
179 // Overridden from contents::WebContentsObserver:
180 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
182 void OnInstantSupportDetermined(int page_id, bool supports_instant) const;
183 void OnVoiceSearchSupportDetermined(int page_id,
184 bool supports_voice_search) const;
185 void OnFocusOmnibox(int page_id, OmniboxFocusState state) const;
186 void OnSearchBoxNavigate(int page_id,
187 const GURL& url,
188 WindowOpenDisposition disposition,
189 bool is_most_visited_item_url) const;
190 void OnDeleteMostVisitedItem(int page_id, const GURL& url) const;
191 void OnUndoMostVisitedDeletion(int page_id, const GURL& url) const;
192 void OnUndoAllMostVisitedDeletions(int page_id) const;
193 void OnLogEvent(int page_id, NTPLoggingEventType event) const;
194 void OnLogMostVisitedImpression(int page_id,
195 int position,
196 const base::string16& provider) const;
197 void OnLogMostVisitedNavigation(int page_id,
198 int position,
199 const base::string16& provider) const;
200 void OnPasteAndOpenDropDown(int page_id, const base::string16& text) const;
201 void OnChromeIdentityCheck(int page_id, const base::string16& identity) const;
203 // Used by unit tests to set a fake delegate.
204 void set_delegate(Delegate* delegate);
206 // Used by unit tests.
207 void set_policy(scoped_ptr<Policy> policy);
209 // Used by unit tests.
210 Policy* policy() const { return policy_.get(); }
212 Delegate* delegate_;
213 scoped_ptr<Policy> policy_;
215 // Set to true, when the tab corresponding to |this| instance is active.
216 bool is_active_tab_;
218 DISALLOW_COPY_AND_ASSIGN(SearchIPCRouter);
221 #endif // CHROME_BROWSER_UI_SEARCH_SEARCH_IPC_ROUTER_H_