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

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

Issue 12520005: Move desktop-specific Instant bits to c/b/ui/search. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 7 years, 9 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 content {
20 class WebContents;
21 }
22
23 namespace gfx {
24 class Rect;
25 }
26
27 // InstantPage is used to exchange messages with a page that implements the
28 // Instant/Embedded Search API (http://dev.chromium.org/embeddedsearch).
29 // InstantPage is not used directly but via one of its derived classes:
30 // InstantOverlay, InstantNTP and InstantTab.
31 class InstantPage : public content::WebContentsObserver {
32 public:
33 // InstantPage calls its delegate in response to messages received from the
34 // page. Each method is called with the |contents| corresponding to the page
35 // we are observing.
36 class Delegate {
37 public:
38 // Called when a RenderView is created, so that state can be initialized.
39 virtual void InstantPageRenderViewCreated(
40 const content::WebContents* contents) = 0;
41
42 // Called upon determination of Instant API support. Either in response to
43 // the page loading or because we received some other message.
44 virtual void InstantSupportDetermined(const content::WebContents* contents,
45 bool supports_instant) = 0;
46
47 // Called when the underlying RenderView crashed.
48 virtual void InstantPageRenderViewGone(
49 const content::WebContents* contents) = 0;
50
51 // Called when the page is about to navigate to |url|.
52 virtual void InstantPageAboutToNavigateMainFrame(
53 const content::WebContents* contents,
54 const GURL& url) = 0;
55
56 // Called when the page has suggestions. Usually in response to Update(),
57 // SendAutocompleteResults() or UpOrDownKeyPressed().
58 virtual void SetSuggestions(
59 const content::WebContents* contents,
60 const std::vector<InstantSuggestion>& suggestions) = 0;
61
62 // Called when the page wants to be shown. Usually in response to Update()
63 // or SendAutocompleteResults().
64 virtual void ShowInstantOverlay(const content::WebContents* contents,
65 int height,
66 InstantSizeUnits units) = 0;
67
68 // Called when the page wants the omnibox to be focused.
69 virtual void FocusOmnibox(const content::WebContents* contents) = 0;
70
71 // Called when the page wants the omnibox to start capturing user key
72 // strokes. If this call is processed successfully, the omnibox will not
73 // look focused visibly but any user key strokes will go to the omnibox.
74 // Currently, this is implemented by focusing the omnibox invisibly.
75 virtual void StartCapturingKeyStrokes(
76 const content::WebContents* contents) = 0;
77
78 // Called when the page wants the omnibox to stop capturing user key
79 // strokes.
80 virtual void StopCapturingKeyStrokes(content::WebContents* contents) = 0;
81
82 // Called when the page wants to navigate to |url|. Usually used by the
83 // page to navigate to privileged destinations (e.g. chrome:// URLs) or to
84 // navigate to URLs that are hidden from the page using Restricted IDs (rid
85 // in the API).
86 virtual void NavigateToURL(const content::WebContents* contents,
87 const GURL& url,
88 content::PageTransition transition,
89 WindowOpenDisposition disposition) = 0;
90
91 // Called when the SearchBox wants to delete a Most Visited item.
92 virtual void DeleteMostVisitedItem(uint64 most_visited_item_id) = 0;
93
94 // Called when the SearchBox wants to undo a Most Visited deletion.
95 virtual void UndoMostVisitedDeletion(uint64 most_visited_item_id) = 0;
96
97 // Called when the SearchBox wants to undo all Most Visited deletions.
98 virtual void UndoAllMostVisitedDeletions() = 0;
99
100 protected:
101 virtual ~Delegate();
102 };
103
104 virtual ~InstantPage();
105
106 // The WebContents corresponding to the page we're talking to. May be NULL.
107 content::WebContents* contents() const { return web_contents(); }
108
109 // Returns true if the page is known to support the Instant API. This starts
110 // out false, and is set to true whenever we get any message from the page.
111 // Once true, it never becomes false (the page isn't expected to drop API
112 // support suddenly).
113 bool supports_instant() const { return supports_instant_; }
114
115 // Tells the page that the user typed |text| into the omnibox. If |verbatim|
116 // is false, the page predicts the query the user means to type and fetches
117 // results for the prediction. If |verbatim| is true, |text| is taken as the
118 // exact query (no prediction is made).
119 virtual void Update(const string16& text,
120 size_t selection_start,
121 size_t selection_end,
122 bool verbatim);
123
124 // Tells the page that the user pressed Enter in the omnibox.
125 void Submit(const string16& text);
126
127 // Tells the page that the user clicked on it. Nothing is being cancelled; the
128 // poor choice of name merely reflects the IPC of the same (poor) name.
129 void Cancel(const string16& text);
130
131 // Tells the page the bounds of the omnibox dropdown (in screen coordinates).
132 // This is used by the page to offset the results to avoid them being covered
133 // by the omnibox dropdown.
134 void SetPopupBounds(const gfx::Rect& bounds);
135
136 // Tells the page the bounds of the omnibox (in screen coordinates). This is
137 // used by the page to align text or assets properly with the omnibox.
138 void SetOmniboxBounds(const gfx::Rect& bounds);
139
140 // Tells the page about the font information.
141 void InitializeFonts();
142
143 // Grant renderer-side chrome-search: access rights for select origins.
144 void GrantChromeSearchAccessFromOrigin(const GURL& origin_url);
145
146 // Tells the renderer to determine if the page supports the Instant API, which
147 // results in a call to InstantSupportDetermined() when the reply is received.
148 void DetermineIfPageSupportsInstant();
149
150 // Tells the page about the available autocomplete results.
151 void SendAutocompleteResults(
152 const std::vector<InstantAutocompleteResult>& results);
153
154 // Tells the page that the user pressed Up or Down in the omnibox. |count| is
155 // a repeat count, negative for moving up, positive for moving down.
156 void UpOrDownKeyPressed(int count);
157
158 // Tells the page that the user pressed Esc in the omnibox after having
159 // arrowed down in the suggestions. The page should reset the selection to
160 // the first suggestion. |user_text| is what the omnibox has been reset to.
161 void CancelSelection(const string16& user_text);
162
163 // Tells the page about the current theme background.
164 void SendThemeBackgroundInfo(const ThemeBackgroundInfo& theme_info);
165
166 // Tells the page whether it is allowed to display Instant results.
167 void SetDisplayInstantResults(bool display_instant_results);
168
169 // Tells the page whether the browser is capturing user key strokes.
170 void KeyCaptureChanged(bool is_key_capture_enabled);
171
172 // Tells the page about new Most Visited data.
173 void SendMostVisitedItems(const std::vector<InstantMostVisitedItem>& items);
174
175 protected:
176 explicit InstantPage(Delegate* delegate);
177
178 // Sets |contents| as the page to communicate with. |contents| may be NULL,
179 // which effectively stops all communication.
180 void SetContents(content::WebContents* contents);
181
182 Delegate* delegate() const { return delegate_; }
183
184 // These functions are called before processing messages received from the
185 // page. By default, all messages are handled, but any derived classes may
186 // choose to ingore some or all of the received messages by overriding these
187 // methods.
188 virtual bool ShouldProcessRenderViewCreated();
189 virtual bool ShouldProcessRenderViewGone();
190 virtual bool ShouldProcessAboutToNavigateMainFrame();
191 virtual bool ShouldProcessSetSuggestions();
192 virtual bool ShouldProcessShowInstantOverlay();
193 virtual bool ShouldProcessFocusOmnibox();
194 virtual bool ShouldProcessStartCapturingKeyStrokes();
195 virtual bool ShouldProcessStopCapturingKeyStrokes();
196 virtual bool ShouldProcessNavigateToURL();
197
198 private:
199 // Overridden from content::WebContentsObserver:
200 virtual void RenderViewCreated(
201 content::RenderViewHost* render_view_host) OVERRIDE;
202 virtual void DidFinishLoad(
203 int64 frame_id,
204 const GURL& validated_url,
205 bool is_main_frame,
206 content::RenderViewHost* render_view_host) OVERRIDE;
207 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
208 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE;
209 virtual void DidCommitProvisionalLoadForFrame(
210 int64 frame_id,
211 bool is_main_frame,
212 const GURL& url,
213 content::PageTransition transition_type,
214 content::RenderViewHost* render_view_host) OVERRIDE;
215
216 void OnSetSuggestions(int page_id,
217 const std::vector<InstantSuggestion>& suggestions);
218 void OnInstantSupportDetermined(int page_id, bool supports_instant);
219 void OnShowInstantOverlay(int page_id,
220 int height,
221 InstantSizeUnits units);
222 void OnFocusOmnibox(int page_id);
223 void OnStartCapturingKeyStrokes(int page_id);
224 void OnStopCapturingKeyStrokes(int page_id);
225 void OnSearchBoxNavigate(int page_id,
226 const GURL& url,
227 content::PageTransition transition,
228 WindowOpenDisposition disposition);
229 void OnDeleteMostVisitedItem(uint64 most_visited_item_id);
230 void OnUndoMostVisitedDeletion(uint64 most_visited_item_id);
231 void OnUndoAllMostVisitedDeletions();
232
233 Delegate* const delegate_;
234 bool supports_instant_;
235
236 DISALLOW_COPY_AND_ASSIGN(InstantPage);
237 };
238
239 #endif // CHROME_BROWSER_INSTANT_INSTANT_PAGE_H_
OLDNEW
« no previous file with comments | « chrome/browser/instant/instant_overlay_model_observer.h ('k') | chrome/browser/instant/instant_page.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698