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

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

Issue 14911005: Move instant support to SearchTabHelper. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed review comments Created 7 years, 7 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/string16.h" 12 #include "base/string16.h"
13 #include "chrome/browser/ui/search/search_model_observer.h"
13 #include "chrome/common/instant_types.h" 14 #include "chrome/common/instant_types.h"
14 #include "chrome/common/omnibox_focus_state.h" 15 #include "chrome/common/omnibox_focus_state.h"
15 #include "content/public/browser/web_contents_observer.h" 16 #include "content/public/browser/web_contents_observer.h"
16 #include "content/public/common/page_transition_types.h" 17 #include "content/public/common/page_transition_types.h"
17 18
18 class GURL; 19 class GURL;
19 20
20 namespace content { 21 namespace content {
21 struct FrameNavigateParams; 22 struct FrameNavigateParams;
22 struct LoadCommittedDetails; 23 struct LoadCommittedDetails;
23 class WebContents; 24 class WebContents;
24 } 25 }
25 26
26 namespace gfx { 27 namespace gfx {
27 class Rect; 28 class Rect;
28 } 29 }
29 30
30 // InstantPage is used to exchange messages with a page that implements the 31 // InstantPage is used to exchange messages with a page that implements the
31 // Instant/Embedded Search API (http://dev.chromium.org/embeddedsearch). 32 // Instant/Embedded Search API (http://dev.chromium.org/embeddedsearch).
32 // InstantPage is not used directly but via one of its derived classes: 33 // InstantPage is not used directly but via one of its derived classes:
33 // InstantOverlay, InstantNTP and InstantTab. 34 // InstantOverlay, InstantNTP and InstantTab.
34 class InstantPage : public content::WebContentsObserver { 35 class InstantPage : public content::WebContentsObserver,
36 public SearchModelObserver {
35 public: 37 public:
36 // InstantPage calls its delegate in response to messages received from the 38 // InstantPage calls its delegate in response to messages received from the
37 // page. Each method is called with the |contents| corresponding to the page 39 // page. Each method is called with the |contents| corresponding to the page
38 // we are observing. 40 // we are observing.
39 class Delegate { 41 class Delegate {
40 public: 42 public:
41 // Called when a RenderView is created, so that state can be initialized. 43 // Called when a RenderView is created, so that state can be initialized.
42 virtual void InstantPageRenderViewCreated( 44 virtual void InstantPageRenderViewCreated(
43 const content::WebContents* contents) = 0; 45 const content::WebContents* contents) = 0;
44 46
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 // Returns the Instant URL that was loaded for this page. Returns the empty 110 // Returns the Instant URL that was loaded for this page. Returns the empty
109 // string if no URL was explicitly loaded as is the case for InstantTab. 111 // string if no URL was explicitly loaded as is the case for InstantTab.
110 const std::string& instant_url() const { return instant_url_; } 112 const std::string& instant_url() const { return instant_url_; }
111 113
112 // Returns true if the page is known to support the Instant API. This starts 114 // Returns true if the page is known to support the Instant API. This starts
113 // out false, and is set to true whenever we get any message from the page. 115 // out false, and is set to true whenever we get any message from the page.
114 // Once true, it never becomes false (the page isn't expected to drop API 116 // Once true, it never becomes false (the page isn't expected to drop API
115 // support suddenly). 117 // support suddenly).
116 bool supports_instant() const { return supports_instant_; } 118 bool supports_instant() const { return supports_instant_; }
117 119
118 // True if Instant support has been tested and determined for this page at
119 // least once. Note that Instant support may change in the future.
120 bool instant_support_determined() const {
121 return instant_support_determined_;
122 }
123
124 // Returns true if the page is the local NTP (i.e. its URL is 120 // Returns true if the page is the local NTP (i.e. its URL is
125 // chrome::kChromeSearchLocalNTPURL). 121 // chrome::kChromeSearchLocalNTPURL).
126 bool IsLocal() const; 122 bool IsLocal() const;
127 123
128 // Tells the page that the user typed |text| into the omnibox. If |verbatim| 124 // Tells the page that the user typed |text| into the omnibox. If |verbatim|
129 // is false, the page predicts the query the user means to type and fetches 125 // is false, the page predicts the query the user means to type and fetches
130 // results for the prediction. If |verbatim| is true, |text| is taken as the 126 // results for the prediction. If |verbatim| is true, |text| is taken as the
131 // exact query (no prediction is made). |selection_start| and |selection_end| 127 // exact query (no prediction is made). |selection_start| and |selection_end|
132 // mark the inline autocompleted portion (i.e., blue highlighted text). The 128 // mark the inline autocompleted portion (i.e., blue highlighted text). The
133 // omnibox caret (cursor) is at |selection_end|. 129 // omnibox caret (cursor) is at |selection_end|.
(...skipping 14 matching lines...) Expand all
148 // by the omnibox dropdown. 144 // by the omnibox dropdown.
149 void SetPopupBounds(const gfx::Rect& bounds); 145 void SetPopupBounds(const gfx::Rect& bounds);
150 146
151 // Tells the page the bounds of the omnibox (in screen coordinates). This is 147 // Tells the page the bounds of the omnibox (in screen coordinates). This is
152 // used by the page to align text or assets properly with the omnibox. 148 // used by the page to align text or assets properly with the omnibox.
153 void SetOmniboxBounds(const gfx::Rect& bounds); 149 void SetOmniboxBounds(const gfx::Rect& bounds);
154 150
155 // Tells the page about the font information. 151 // Tells the page about the font information.
156 void InitializeFonts(); 152 void InitializeFonts();
157 153
158 // Tells the renderer to determine if the page supports the Instant API, which
159 // results in a call to InstantSupportDetermined() when the reply is received.
160 void DetermineIfPageSupportsInstant();
161
162 // Tells the page about the available autocomplete results. 154 // Tells the page about the available autocomplete results.
163 void SendAutocompleteResults( 155 void SendAutocompleteResults(
164 const std::vector<InstantAutocompleteResult>& results); 156 const std::vector<InstantAutocompleteResult>& results);
165 157
166 // Tells the page that the user pressed Up or Down in the omnibox. |count| is 158 // Tells the page that the user pressed Up or Down in the omnibox. |count| is
167 // a repeat count, negative for moving up, positive for moving down. 159 // a repeat count, negative for moving up, positive for moving down.
168 void UpOrDownKeyPressed(int count); 160 void UpOrDownKeyPressed(int count);
169 161
170 // Tells the page that the user pressed Esc key in the omnibox. 162 // Tells the page that the user pressed Esc key in the omnibox.
171 void EscKeyPressed(); 163 void EscKeyPressed();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 virtual bool ShouldProcessAboutToNavigateMainFrame(); 201 virtual bool ShouldProcessAboutToNavigateMainFrame();
210 virtual bool ShouldProcessSetSuggestions(); 202 virtual bool ShouldProcessSetSuggestions();
211 virtual bool ShouldProcessShowInstantOverlay(); 203 virtual bool ShouldProcessShowInstantOverlay();
212 virtual bool ShouldProcessFocusOmnibox(); 204 virtual bool ShouldProcessFocusOmnibox();
213 virtual bool ShouldProcessNavigateToURL(); 205 virtual bool ShouldProcessNavigateToURL();
214 206
215 private: 207 private:
216 // Overridden from content::WebContentsObserver: 208 // Overridden from content::WebContentsObserver:
217 virtual void RenderViewCreated( 209 virtual void RenderViewCreated(
218 content::RenderViewHost* render_view_host) OVERRIDE; 210 content::RenderViewHost* render_view_host) OVERRIDE;
219 virtual void DidFinishLoad(
220 int64 frame_id,
221 const GURL& validated_url,
222 bool is_main_frame,
223 content::RenderViewHost* render_view_host) OVERRIDE;
224 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 211 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
225 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE; 212 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE;
226 virtual void DidCommitProvisionalLoadForFrame( 213 virtual void DidCommitProvisionalLoadForFrame(
227 int64 frame_id, 214 int64 frame_id,
228 bool is_main_frame, 215 bool is_main_frame,
229 const GURL& url, 216 const GURL& url,
230 content::PageTransition transition_type, 217 content::PageTransition transition_type,
231 content::RenderViewHost* render_view_host) OVERRIDE; 218 content::RenderViewHost* render_view_host) OVERRIDE;
232 virtual void DidNavigateMainFrame( 219 virtual void DidNavigateMainFrame(
233 const content::LoadCommittedDetails& details, 220 const content::LoadCommittedDetails& details,
234 const content::FrameNavigateParams& params) OVERRIDE; 221 const content::FrameNavigateParams& params) OVERRIDE;
235 virtual void DidFailProvisionalLoad( 222 virtual void DidFailProvisionalLoad(
236 int64 frame_id, 223 int64 frame_id,
237 bool is_main_frame, 224 bool is_main_frame,
238 const GURL& validated_url, 225 const GURL& validated_url,
239 int error_code, 226 int error_code,
240 const string16& error_description, 227 const string16& error_description,
241 content::RenderViewHost* render_view_host) OVERRIDE; 228 content::RenderViewHost* render_view_host) OVERRIDE;
242 229
230 // Overridden from SearchModelObserver:
231 virtual void ModelChanged(const SearchModel::State& old_state,
232 const SearchModel::State& new_state) OVERRIDE;
233
234 // Helper to look up the SearchModel for this page.
235 SearchModel* GetSearchModel();
236
237 // Update the status of Instant support.
238 void SetSupportsInstant(bool supports_instant);
239
243 void OnSetSuggestions(int page_id, 240 void OnSetSuggestions(int page_id,
244 const std::vector<InstantSuggestion>& suggestions); 241 const std::vector<InstantSuggestion>& suggestions);
245 void OnInstantSupportDetermined(int page_id, bool supports_instant);
246 void OnShowInstantOverlay(int page_id, 242 void OnShowInstantOverlay(int page_id,
247 int height, 243 int height,
248 InstantSizeUnits units); 244 InstantSizeUnits units);
249 void OnFocusOmnibox(int page_id, OmniboxFocusState state); 245 void OnFocusOmnibox(int page_id, OmniboxFocusState state);
250 void OnSearchBoxNavigate(int page_id, 246 void OnSearchBoxNavigate(int page_id,
251 const GURL& url, 247 const GURL& url,
252 content::PageTransition transition, 248 content::PageTransition transition,
253 WindowOpenDisposition disposition); 249 WindowOpenDisposition disposition);
254 void OnDeleteMostVisitedItem(InstantRestrictedID most_visited_item_id); 250 void OnDeleteMostVisitedItem(InstantRestrictedID most_visited_item_id);
255 void OnUndoMostVisitedDeletion(InstantRestrictedID most_visited_item_id); 251 void OnUndoMostVisitedDeletion(InstantRestrictedID most_visited_item_id);
256 void OnUndoAllMostVisitedDeletions(); 252 void OnUndoAllMostVisitedDeletions();
257 253
258 Delegate* const delegate_; 254 Delegate* const delegate_;
259 const std::string instant_url_; 255 const std::string instant_url_;
260 bool supports_instant_; 256 bool supports_instant_;
261 bool instant_support_determined_;
262 257
263 DISALLOW_COPY_AND_ASSIGN(InstantPage); 258 DISALLOW_COPY_AND_ASSIGN(InstantPage);
264 }; 259 };
265 260
266 #endif // CHROME_BROWSER_UI_SEARCH_INSTANT_PAGE_H_ 261 #endif // CHROME_BROWSER_UI_SEARCH_INSTANT_PAGE_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/search/instant_page.cc » ('j') | chrome/browser/ui/search/search_model_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698