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

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

Issue 11824050: InstantExtended: Committed NTP (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update Created 7 years, 11 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 2012 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_CLIENT_H_
6 #define CHROME_BROWSER_INSTANT_INSTANT_CLIENT_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
16 namespace chrome {
17 namespace search {
18 struct Mode;
19 }
20 }
21
22 namespace content {
23 class WebContents;
24 }
25
26 namespace gfx {
27 class Rect;
28 }
29
30 // InstantClient is used to exchange messages between its delegate and a page
31 // that supports the Instant API (http://dev.chromium.org/searchbox).
32 class InstantClient : public content::WebContentsObserver {
33 public:
34 // When InstantClient receives messages from the page, it calls the following
35 // methods on its delegate.
36 class Delegate {
37 public:
38 // Called when the page has suggestions. Usually in response to Change(),
39 // SendAutocompleteResults() or UpOrDownKeyPressed().
40 virtual void SetSuggestions(
41 const std::vector<InstantSuggestion>& suggestions) = 0;
42
43 // Called upon determination of Instant API support. Usually in response to
44 // SetContents() or when the page first finishes loading.
45 virtual void InstantSupportDetermined(bool supports_instant) = 0;
46
47 // Called when the page wants to be shown. Usually in response to Change(),
48 // SendAutocompleteResults() or SearchModeChanged().
49 virtual void ShowInstantPreview(InstantShownReason reason,
50 int height,
51 InstantSizeUnits units) = 0;
52
53 // Called when the page wants the browser to start capturing user key
54 // strokes.
55 virtual void StartCapturingKeyStrokes() = 0;
56
57 // Called when the page wants the browser to stop capturing user key
58 // strokes.
59 virtual void StopCapturingKeyStrokes() = 0;
60
61 // Called when the underlying RenderView crashes.
62 virtual void RenderViewGone() = 0;
63
64 // Called when the page is about to navigate.
65 virtual void AboutToNavigateMainFrame(const GURL& url) = 0;
66
67 // Called when the SearchBox wants to navigate to the specified URL.
68 virtual void NavigateToURL(const GURL& url,
69 content::PageTransition transition) = 0;
70
71 protected:
72 virtual ~Delegate();
73 };
74
75 // Doesn't take ownership of |delegate|.
76 explicit InstantClient(Delegate* delegate);
77 virtual ~InstantClient();
78
79 // Sets |contents| as the page to communicate with. |contents| can be NULL,
80 // which effectively stops all communication.
81 void SetContents(content::WebContents* contents);
82
83 // Tells the page that the user typed |text| into the omnibox. If |verbatim|
84 // is false, the page predicts the query the user means to type and fetches
85 // results for the prediction. If |verbatim| is true, |text| is taken as the
86 // exact query (no prediction is made).
87 void Update(const string16& text,
88 size_t selection_start,
89 size_t selection_end,
90 bool verbatim);
91
92 // Tells the page that the user pressed Enter in the omnibox.
93 void Submit(const string16& text);
94
95 // Tells the page that the user clicked on it. Nothing is being cancelled; the
96 // poor choice of name merely reflects the IPC of the same (poor) name.
97 void Cancel(const string16& text);
98
99 // Tells the page the bounds of the omnibox dropdown (in screen coordinates).
100 // This is used by the page to offset the results to avoid them being covered
101 // by the omnibox dropdown.
102 void SetPopupBounds(const gfx::Rect& bounds);
103
104 // Tells the page what size start and end margins to use.
105 void SetMarginSize(const int start, const int end);
106
107 // Tells the renderer to determine if the page supports the Instant API, which
108 // results in a call to InstantSupportDetermined() when the reply is received.
109 void DetermineIfPageSupportsInstant();
110
111 // Tells the page about the available autocomplete results.
112 void SendAutocompleteResults(
113 const std::vector<InstantAutocompleteResult>& results);
114
115 // Tells the page that the user pressed Up or Down in the omnibox. |count| is
116 // a repeat count, negative for moving up, positive for moving down.
117 void UpOrDownKeyPressed(int count);
118
119 // Tells the page that the active tab's search mode has changed.
120 void SearchModeChanged(const chrome::search::Mode& mode);
121
122 // Tells the page about the current theme background.
123 void SendThemeBackgroundInfo(const ThemeBackgroundInfo& theme_info);
124
125 // Tells the page about the current theme area height.
126 void SendThemeAreaHeight(int height);
127
128 // Tells the page whether it is allowed to display Instant results.
129 void SetDisplayInstantResults(bool display_instant_results);
130
131 // Tells the page whether the browser is capturing user key strokes.
132 void KeyCaptureChanged(bool is_key_capture_enabled);
133
134 private:
135 // Overridden from content::WebContentsObserver:
136 virtual void DidFinishLoad(
137 int64 frame_id,
138 const GURL& validated_url,
139 bool is_main_frame,
140 content::RenderViewHost* render_view_host) OVERRIDE;
141 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
142 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE;
143 virtual void DidCommitProvisionalLoadForFrame(
144 int64 frame_id,
145 bool is_main_frame,
146 const GURL& url,
147 content::PageTransition transition_type,
148 content::RenderViewHost* render_view_host) OVERRIDE;
149
150 void SetSuggestions(int page_id,
151 const std::vector<InstantSuggestion>& suggestions);
152 void InstantSupportDetermined(int page_id, bool result);
153 void ShowInstantPreview(int page_id,
154 InstantShownReason reason,
155 int height,
156 InstantSizeUnits units);
157 void StartCapturingKeyStrokes(int page_id);
158 void StopCapturingKeyStrokes(int page_id);
159 void SearchBoxNavigate(int page_id, const GURL& url,
160 content::PageTransition transition);
161
162 Delegate* const delegate_;
163
164 DISALLOW_COPY_AND_ASSIGN(InstantClient);
165 };
166
167 #endif // CHROME_BROWSER_INSTANT_INSTANT_CLIENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698