Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: chrome/browser/ui/search/instant_page.h

Issue 16035020: Move instant support to SearchTabHelper. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed nits Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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_PAGE_H_ 5 #ifndef CHROME_BROWSER_UI_SEARCH_INSTANT_PAGE_H_
6 #define CHROME_BROWSER_UI_SEARCH_INSTANT_PAGE_H_ 6 #define CHROME_BROWSER_UI_SEARCH_INSTANT_PAGE_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
13 #include "base/strings/string16.h" 13 #include "base/strings/string16.h"
14 #include "chrome/browser/ui/search/search_model_observer.h"
14 #include "chrome/common/instant_types.h" 15 #include "chrome/common/instant_types.h"
15 #include "chrome/common/omnibox_focus_state.h" 16 #include "chrome/common/omnibox_focus_state.h"
16 #include "content/public/browser/web_contents_observer.h" 17 #include "content/public/browser/web_contents_observer.h"
17 #include "content/public/common/page_transition_types.h" 18 #include "content/public/common/page_transition_types.h"
18 19
19 class GURL; 20 class GURL;
20 21
21 namespace content { 22 namespace content {
22 struct FrameNavigateParams; 23 struct FrameNavigateParams;
23 struct LoadCommittedDetails; 24 struct LoadCommittedDetails;
24 class WebContents; 25 class WebContents;
25 } 26 }
26 27
27 namespace gfx { 28 namespace gfx {
28 class Rect; 29 class Rect;
29 } 30 }
30 31
31 // InstantPage is used to exchange messages with a page that implements the 32 // InstantPage is used to exchange messages with a page that implements the
32 // Instant/Embedded Search API (http://dev.chromium.org/embeddedsearch). 33 // Instant/Embedded Search API (http://dev.chromium.org/embeddedsearch).
33 // InstantPage is not used directly but via one of its derived classes: 34 // InstantPage is not used directly but via one of its derived classes:
34 // InstantOverlay, InstantNTP and InstantTab. 35 // InstantOverlay, InstantNTP and InstantTab.
35 class InstantPage : public content::WebContentsObserver { 36 class InstantPage : public content::WebContentsObserver,
37 public SearchModelObserver {
36 public: 38 public:
37 // InstantPage calls its delegate in response to messages received from the 39 // InstantPage calls its delegate in response to messages received from the
38 // page. Each method is called with the |contents| corresponding to the page 40 // page. Each method is called with the |contents| corresponding to the page
39 // we are observing. 41 // we are observing.
40 class Delegate { 42 class Delegate {
41 public: 43 public:
42 // Called when a RenderView is created, so that state can be initialized. 44 // Called when a RenderView is created, so that state can be initialized.
43 virtual void InstantPageRenderViewCreated( 45 virtual void InstantPageRenderViewCreated(
44 const content::WebContents* contents) = 0; 46 const content::WebContents* contents) = 0;
45 47
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 // Returns the Instant URL that was loaded for this page. Returns the empty 114 // Returns the Instant URL that was loaded for this page. Returns the empty
113 // string if no URL was explicitly loaded as is the case for InstantTab. 115 // string if no URL was explicitly loaded as is the case for InstantTab.
114 virtual const std::string& instant_url() const; 116 virtual const std::string& instant_url() const;
115 117
116 // Returns true if the page is known to support the Instant API. This starts 118 // Returns true if the page is known to support the Instant API. This starts
117 // out false, and is set to true whenever we get any message from the page. 119 // out false, and is set to true whenever we get any message from the page.
118 // Once true, it never becomes false (the page isn't expected to drop API 120 // Once true, it never becomes false (the page isn't expected to drop API
119 // support suddenly). 121 // support suddenly).
120 virtual bool supports_instant() const; 122 virtual bool supports_instant() const;
121 123
122 // True if Instant support has been tested and determined for this page at
123 // least once. Note that Instant support may change in the future.
124 bool instant_support_determined() const {
125 return instant_support_determined_;
126 }
127
128 // Returns true if the page is the local NTP (i.e. its URL is 124 // Returns true if the page is the local NTP (i.e. its URL is
129 // chrome::kChromeSearchLocalNTPURL). 125 // chrome::kChromeSearchLocalNTPURL).
130 virtual bool IsLocal() const; 126 virtual bool IsLocal() const;
131 127
132 // Tells the page that the user typed |text| into the omnibox. If |verbatim| 128 // Tells the page that the user typed |text| into the omnibox. If |verbatim|
133 // is false, the page predicts the query the user means to type and fetches 129 // is false, the page predicts the query the user means to type and fetches
134 // results for the prediction. If |verbatim| is true, |text| is taken as the 130 // results for the prediction. If |verbatim| is true, |text| is taken as the
135 // exact query (no prediction is made). |selection_start| and |selection_end| 131 // exact query (no prediction is made). |selection_start| and |selection_end|
136 // mark the inline autocompleted portion (i.e., blue highlighted text). The 132 // mark the inline autocompleted portion (i.e., blue highlighted text). The
137 // omnibox caret (cursor) is at |selection_end|. 133 // omnibox caret (cursor) is at |selection_end|.
(...skipping 14 matching lines...) Expand all
152 // by the omnibox dropdown. 148 // by the omnibox dropdown.
153 void SetPopupBounds(const gfx::Rect& bounds); 149 void SetPopupBounds(const gfx::Rect& bounds);
154 150
155 // Tells the page the bounds of the omnibox (in screen coordinates). This is 151 // Tells the page the bounds of the omnibox (in screen coordinates). This is
156 // used by the page to align text or assets properly with the omnibox. 152 // used by the page to align text or assets properly with the omnibox.
157 void SetOmniboxBounds(const gfx::Rect& bounds); 153 void SetOmniboxBounds(const gfx::Rect& bounds);
158 154
159 // Tells the page about the font information. 155 // Tells the page about the font information.
160 void InitializeFonts(); 156 void InitializeFonts();
161 157
162 // Tells the renderer to determine if the page supports the Instant API, which
163 // results in a call to InstantSupportDetermined() when the reply is received.
164 void DetermineIfPageSupportsInstant();
165
166 // Tells the page about the available autocomplete results. 158 // Tells the page about the available autocomplete results.
167 void SendAutocompleteResults( 159 void SendAutocompleteResults(
168 const std::vector<InstantAutocompleteResult>& results); 160 const std::vector<InstantAutocompleteResult>& results);
169 161
170 // Tells the page that the user pressed Up or Down in the omnibox. |count| is 162 // Tells the page that the user pressed Up or Down in the omnibox. |count| is
171 // a repeat count, negative for moving up, positive for moving down. 163 // a repeat count, negative for moving up, positive for moving down.
172 void UpOrDownKeyPressed(int count); 164 void UpOrDownKeyPressed(int count);
173 165
174 // Tells the page that the user pressed Esc key in the omnibox. 166 // Tells the page that the user pressed Esc key in the omnibox.
175 void EscKeyPressed(); 167 void EscKeyPressed();
(...skipping 21 matching lines...) Expand all
197 // Tells the page about new Most Visited data. 189 // Tells the page about new Most Visited data.
198 void SendMostVisitedItems( 190 void SendMostVisitedItems(
199 const std::vector<InstantMostVisitedItem>& items); 191 const std::vector<InstantMostVisitedItem>& items);
200 192
201 // Tells the page to toggle voice search. 193 // Tells the page to toggle voice search.
202 void ToggleVoiceSearch(); 194 void ToggleVoiceSearch();
203 195
204 protected: 196 protected:
205 InstantPage(Delegate* delegate, const std::string& instant_url); 197 InstantPage(Delegate* delegate, const std::string& instant_url);
206 198
207 // Sets |contents| as the page to communicate with. |contents| may be NULL, 199 // Sets |web_contents| as the page to communicate with. |web_contents| may be
208 // which effectively stops all communication. 200 // NULL, which effectively stops all communication.
209 void SetContents(content::WebContents* contents); 201 void SetContents(content::WebContents* web_contents);
210 202
211 Delegate* delegate() const { return delegate_; } 203 Delegate* delegate() const { return delegate_; }
212 204
213 // These functions are called before processing messages received from the 205 // These functions are called before processing messages received from the
214 // page. By default, all messages are handled, but any derived classes may 206 // page. By default, all messages are handled, but any derived classes may
215 // choose to ignore some or all of the received messages by overriding these 207 // choose to ignore some or all of the received messages by overriding these
216 // methods. 208 // methods.
217 virtual bool ShouldProcessRenderViewCreated(); 209 virtual bool ShouldProcessRenderViewCreated();
218 virtual bool ShouldProcessRenderViewGone(); 210 virtual bool ShouldProcessRenderViewGone();
219 virtual bool ShouldProcessAboutToNavigateMainFrame(); 211 virtual bool ShouldProcessAboutToNavigateMainFrame();
(...skipping 13 matching lines...) Expand all
233 FRIEND_TEST_ALL_PREFIXES(InstantPageTest, 225 FRIEND_TEST_ALL_PREFIXES(InstantPageTest,
234 DispatchRequestToUndoAllMostVisitedDeletions); 226 DispatchRequestToUndoAllMostVisitedDeletions);
235 FRIEND_TEST_ALL_PREFIXES(InstantPageTest, 227 FRIEND_TEST_ALL_PREFIXES(InstantPageTest,
236 IgnoreMessageIfThePageIsNotActive); 228 IgnoreMessageIfThePageIsNotActive);
237 FRIEND_TEST_ALL_PREFIXES(InstantPageTest, 229 FRIEND_TEST_ALL_PREFIXES(InstantPageTest,
238 IgnoreMessageReceivedFromThePage); 230 IgnoreMessageReceivedFromThePage);
239 231
240 // Overridden from content::WebContentsObserver: 232 // Overridden from content::WebContentsObserver:
241 virtual void RenderViewCreated( 233 virtual void RenderViewCreated(
242 content::RenderViewHost* render_view_host) OVERRIDE; 234 content::RenderViewHost* render_view_host) OVERRIDE;
243 virtual void DidFinishLoad(
244 int64 frame_id,
245 const GURL& validated_url,
246 bool is_main_frame,
247 content::RenderViewHost* render_view_host) OVERRIDE;
248 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 235 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
249 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE; 236 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE;
250 virtual void DidCommitProvisionalLoadForFrame( 237 virtual void DidCommitProvisionalLoadForFrame(
251 int64 frame_id, 238 int64 frame_id,
252 bool is_main_frame, 239 bool is_main_frame,
253 const GURL& url, 240 const GURL& url,
254 content::PageTransition transition_type, 241 content::PageTransition transition_type,
255 content::RenderViewHost* render_view_host) OVERRIDE; 242 content::RenderViewHost* render_view_host) OVERRIDE;
256 virtual void DidNavigateMainFrame( 243 virtual void DidNavigateMainFrame(
257 const content::LoadCommittedDetails& details, 244 const content::LoadCommittedDetails& details,
258 const content::FrameNavigateParams& params) OVERRIDE; 245 const content::FrameNavigateParams& params) OVERRIDE;
259 virtual void DidFailProvisionalLoad( 246 virtual void DidFailProvisionalLoad(
260 int64 frame_id, 247 int64 frame_id,
261 bool is_main_frame, 248 bool is_main_frame,
262 const GURL& validated_url, 249 const GURL& validated_url,
263 int error_code, 250 int error_code,
264 const string16& error_description, 251 const string16& error_description,
265 content::RenderViewHost* render_view_host) OVERRIDE; 252 content::RenderViewHost* render_view_host) OVERRIDE;
266 253
254 // Overridden from SearchModelObserver:
255 virtual void ModelChanged(const SearchModel::State& old_state,
256 const SearchModel::State& new_state) OVERRIDE;
257
258 // Update the status of Instant support.
259 void InstantSupportDetermined(bool supports_instant);
260
267 void OnSetSuggestions(int page_id, 261 void OnSetSuggestions(int page_id,
268 const std::vector<InstantSuggestion>& suggestions); 262 const std::vector<InstantSuggestion>& suggestions);
269 void OnInstantSupportDetermined(int page_id, bool supports_instant);
270 void OnShowInstantOverlay(int page_id, 263 void OnShowInstantOverlay(int page_id,
271 int height, 264 int height,
272 InstantSizeUnits units); 265 InstantSizeUnits units);
273 void OnFocusOmnibox(int page_id, OmniboxFocusState state); 266 void OnFocusOmnibox(int page_id, OmniboxFocusState state);
274 void OnSearchBoxNavigate(int page_id, 267 void OnSearchBoxNavigate(int page_id,
275 const GURL& url, 268 const GURL& url,
276 content::PageTransition transition, 269 content::PageTransition transition,
277 WindowOpenDisposition disposition, 270 WindowOpenDisposition disposition,
278 bool is_search_type); 271 bool is_search_type);
279 void OnDeleteMostVisitedItem(int page_id, const GURL& url); 272 void OnDeleteMostVisitedItem(int page_id, const GURL& url);
280 void OnUndoMostVisitedDeletion(int page_id, const GURL& url); 273 void OnUndoMostVisitedDeletion(int page_id, const GURL& url);
281 void OnUndoAllMostVisitedDeletions(int page_id); 274 void OnUndoAllMostVisitedDeletions(int page_id);
282 275
276 void ClearContents();
277
283 Delegate* const delegate_; 278 Delegate* const delegate_;
284 const std::string instant_url_; 279 const std::string instant_url_;
285 bool supports_instant_;
286 bool instant_support_determined_;
287 280
288 DISALLOW_COPY_AND_ASSIGN(InstantPage); 281 DISALLOW_COPY_AND_ASSIGN(InstantPage);
289 }; 282 };
290 283
291 #endif // CHROME_BROWSER_UI_SEARCH_INSTANT_PAGE_H_ 284 #endif // CHROME_BROWSER_UI_SEARCH_INSTANT_PAGE_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/search/instant_extended_interactive_uitest.cc ('k') | chrome/browser/ui/search/instant_page.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698