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

Side by Side Diff: chrome/browser/instant/instant_page.h

Issue 11824050: InstantExtended: Committed NTP (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix test failures. Created 7 years, 10 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
OLDNEW
(Empty)
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.
4
5 #ifndef CHROME_BROWSER_INSTANT_INSTANT_PAGE_H_
6 #define CHROME_BROWSER_INSTANT_INSTANT_PAGE_H_
7
8 #include <vector>
9
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/string16.h"
13 #include "chrome/common/instant_types.h"
14 #include "content/public/browser/web_contents_observer.h"
15 #include "content/public/common/page_transition_types.h"
16
17 class GURL;
18
19 namespace chrome {
20 namespace search {
21 struct Mode;
22 }
23 }
24
25 namespace content {
26 class WebContents;
27 }
28
29 namespace gfx {
30 class Rect;
31 }
32
33 // InstantPage is used to exchange messages with a page that implements the
34 // Instant/Embedded Search API (http://dev.chromium.org/embeddedsearch).
35 // InstantPage is not used directly but via one of its derived classes:
36 // InstantOverlay, InstantNTP and InstantTab.
37 class InstantPage : public content::WebContentsObserver {
38 public:
39 // InstantPage calls its delegate in response to messages received from the
40 // page. Each method is called with the |contents| corresponding to the page
41 // we are observing.
42 class Delegate {
43 public:
44 // Called when a RenderView is created, so that state can be initialized.
45 virtual void InstantPageRenderViewCreated(
46 const content::WebContents* contents) = 0;
47
48 // Called upon determination of Instant API support. Either in response to
49 // the page loading or because we received some other message.
50 virtual void InstantSupportDetermined(const content::WebContents* contents,
51 bool supports_instant) = 0;
52
53 // Called when the underlying RenderView crashed.
54 virtual void InstantPageRenderViewGone(
55 const content::WebContents* contents) = 0;
56
57 // Called when the page is about to navigate to |url|.
58 virtual void InstantPageAboutToNavigateMainFrame(
59 const content::WebContents* contents,
60 const GURL& url) = 0;
61
62 // Called when the page has suggestions. Usually in response to Update(),
63 // SendAutocompleteResults() or UpOrDownKeyPressed().
64 virtual void SetSuggestions(
65 const content::WebContents* contents,
66 const std::vector<InstantSuggestion>& suggestions) = 0;
67
68 // Called when the page wants to be shown. Usually in response to Update(),
69 // SendAutocompleteResults() or SearchModeChanged().
70 virtual void ShowInstantPreview(const content::WebContents* contents,
71 InstantShownReason reason,
72 int height,
73 InstantSizeUnits units) = 0;
74
75 // Called when the page wants the omnibox to start capturing user key
76 // strokes. If this call is processed successfully, the omnibox will not
77 // look focused visibly but any user key strokes will go to the omnibox.
78 // Currently, this is implemented by focusing the omnibox invisibly.
79 virtual void StartCapturingKeyStrokes(
80 const content::WebContents* contents) = 0;
81
82 // Called when the page wants the omnibox to stop capturing user key
83 // strokes.
84 virtual void StopCapturingKeyStrokes(content::WebContents* contents) = 0;
85
86 // Called when the page wants to navigate to the specified URL. Usually
87 // used by the page to navigate to privileged destinations (e.g. chrome://
88 // URLs) or to navigate to URLs that are hidden from the page using
89 // Restricted IDs (rid in the API).
90 virtual void NavigateToURL(const content::WebContents* contents,
91 const GURL& url,
92 content::PageTransition transition) = 0;
93
94 protected:
95 virtual ~Delegate();
96 };
97
98 virtual ~InstantPage();
99
100 // The WebContents corresponding to the page we're talking to. May be NULL.
101 content::WebContents* contents() const { return contents_; }
102
103 // Returns true if the page is known to support the Instant API. This starts
104 // out false, and is set to true whenever we get any message from the page.
105 // Once true, it never becomes false (the page isn't expected to drop API
106 // support suddenly).
107 bool supports_instant() const { return supports_instant_; }
108
109 // Tells the page that the user typed |text| into the omnibox. If |verbatim|
110 // is false, the page predicts the query the user means to type and fetches
111 // results for the prediction. If |verbatim| is true, |text| is taken as the
112 // exact query (no prediction is made).
113 virtual void Update(const string16& text,
114 size_t selection_start,
115 size_t selection_end,
116 bool verbatim);
117
118 // Tells the page that the user pressed Enter in the omnibox.
119 void Submit(const string16& text);
120
121 // Tells the page that the user clicked on it. Nothing is being cancelled; the
122 // poor choice of name merely reflects the IPC of the same (poor) name.
123 void Cancel(const string16& text);
124
125 // Tells the page the bounds of the omnibox dropdown (in screen coordinates).
126 // This is used by the page to offset the results to avoid them being covered
127 // by the omnibox dropdown.
128 void SetPopupBounds(const gfx::Rect& bounds);
129
130 // Tells the page the start and end margins of the omnibox (in screen
131 // coordinates). This is used by the page to align text or assets properly
132 // with the omnibox.
133 void SetMarginSize(int start, int end);
134
135 // Tells the page about the font information.
136 void InitializeFonts();
137
138 // Tells the renderer to determine if the page supports the Instant API, which
139 // results in a call to InstantSupportDetermined() when the reply is received.
140 void DetermineIfPageSupportsInstant();
141
142 // Tells the page about the available autocomplete results.
143 void SendAutocompleteResults(
144 const std::vector<InstantAutocompleteResult>& results);
145
146 // Tells the page that the user pressed Up or Down in the omnibox. |count| is
147 // a repeat count, negative for moving up, positive for moving down.
148 void UpOrDownKeyPressed(int count);
149
150 // Tells the page that the active tab's search mode has changed.
151 void SearchModeChanged(const chrome::search::Mode& mode);
152
153 // Tells the page about the current theme background.
154 void SendThemeBackgroundInfo(const ThemeBackgroundInfo& theme_info);
155
156 // Tells the page about the current theme area height.
157 void SendThemeAreaHeight(int height);
158
159 // Tells the page whether it is allowed to display Instant results.
160 void SetDisplayInstantResults(bool display_instant_results);
161
162 // Tells the page whether the browser is capturing user key strokes.
163 void KeyCaptureChanged(bool is_key_capture_enabled);
164
165 protected:
166 explicit InstantPage(Delegate* delegate);
167
168 // Sets |contents| as the page to communicate with. |contents| may be NULL,
169 // which effectively stops all communication.
170 void SetContents(content::WebContents* contents);
171
172 Delegate* delegate() const { return delegate_; }
173
174 // These functions are called before processing messages received from the
175 // page. By default, all messages are handled, but any derived classes may
176 // choose to ingore some or all of the received messages by overriding these
177 // methods.
178 virtual bool ShouldProcessRenderViewCreated();
179 virtual bool ShouldProcessRenderViewGone();
180 virtual bool ShouldProcessAboutToNavigateMainFrame();
181 virtual bool ShouldProcessSetSuggestions();
182 virtual bool ShouldProcessShowInstantPreview();
183 virtual bool ShouldProcessStartCapturingKeyStrokes();
184 virtual bool ShouldProcessStopCapturingKeyStrokes();
185 virtual bool ShouldProcessNavigateToURL();
sreeram 2013/02/07 18:22:46 It might be nice to flip the default from true to
samarth 2013/02/07 22:11:55 Yeah, that's much nicer. Done.
186
187 private:
188 // Overridden from content::WebContentsObserver:
189 virtual void RenderViewCreated(
190 content::RenderViewHost* render_view_host) OVERRIDE;
191 virtual void DidFinishLoad(
192 int64 frame_id,
193 const GURL& validated_url,
194 bool is_main_frame,
195 content::RenderViewHost* render_view_host) OVERRIDE;
196 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
197 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE;
198 virtual void DidCommitProvisionalLoadForFrame(
199 int64 frame_id,
200 bool is_main_frame,
201 const GURL& url,
202 content::PageTransition transition_type,
203 content::RenderViewHost* render_view_host) OVERRIDE;
204
205 void OnSetSuggestions(int page_id,
206 const std::vector<InstantSuggestion>& suggestions);
207 void OnInstantSupportDetermined(int page_id, bool supports_instant);
208 void OnShowInstantPreview(int page_id,
209 InstantShownReason reason,
210 int height,
211 InstantSizeUnits units);
212 void OnStartCapturingKeyStrokes(int page_id);
213 void OnStopCapturingKeyStrokes(int page_id);
214 void OnSearchBoxNavigate(int page_id, const GURL& url,
215 content::PageTransition transition);
216
217 Delegate* const delegate_;
218 content::WebContents* contents_;
219 bool supports_instant_;
220
221 DISALLOW_COPY_AND_ASSIGN(InstantPage);
222 };
223
224 #endif // CHROME_BROWSER_INSTANT_INSTANT_PAGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698