OLD | NEW |
| (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 // Called when a RenderView is created, so that state can be initialized. | |
72 virtual void RenderViewCreated() = 0; | |
73 | |
74 protected: | |
75 virtual ~Delegate(); | |
76 }; | |
77 | |
78 // Doesn't take ownership of |delegate|. | |
79 explicit InstantClient(Delegate* delegate); | |
80 virtual ~InstantClient(); | |
81 | |
82 // Sets |contents| as the page to communicate with. |contents| can be NULL, | |
83 // which effectively stops all communication. | |
84 void SetContents(content::WebContents* contents); | |
85 | |
86 // Tells the page that the user typed |text| into the omnibox. If |verbatim| | |
87 // is false, the page predicts the query the user means to type and fetches | |
88 // results for the prediction. If |verbatim| is true, |text| is taken as the | |
89 // exact query (no prediction is made). | |
90 void Update(const string16& text, | |
91 size_t selection_start, | |
92 size_t selection_end, | |
93 bool verbatim); | |
94 | |
95 // Tells the page that the user pressed Enter in the omnibox. | |
96 void Submit(const string16& text); | |
97 | |
98 // Tells the page that the user clicked on it. Nothing is being cancelled; the | |
99 // poor choice of name merely reflects the IPC of the same (poor) name. | |
100 void Cancel(const string16& text); | |
101 | |
102 // Tells the page the bounds of the omnibox dropdown (in screen coordinates). | |
103 // This is used by the page to offset the results to avoid them being covered | |
104 // by the omnibox dropdown. | |
105 void SetPopupBounds(const gfx::Rect& bounds); | |
106 | |
107 // Tells the page what size start and end margins to use. | |
108 void SetMarginSize(const int start, const int end); | |
109 | |
110 // Tells the page about the font information. | |
111 void InitializeFonts(); | |
112 | |
113 // Tells the renderer to determine if the page supports the Instant API, which | |
114 // results in a call to InstantSupportDetermined() when the reply is received. | |
115 void DetermineIfPageSupportsInstant(); | |
116 | |
117 // Tells the page about the available autocomplete results. | |
118 void SendAutocompleteResults( | |
119 const std::vector<InstantAutocompleteResult>& results); | |
120 | |
121 // Tells the page that the user pressed Up or Down in the omnibox. |count| is | |
122 // a repeat count, negative for moving up, positive for moving down. | |
123 void UpOrDownKeyPressed(int count); | |
124 | |
125 // Tells the page that the active tab's search mode has changed. | |
126 void SearchModeChanged(const chrome::search::Mode& mode); | |
127 | |
128 // Tells the page about the current theme background. | |
129 void SendThemeBackgroundInfo(const ThemeBackgroundInfo& theme_info); | |
130 | |
131 // Tells the page about the current theme area height. | |
132 void SendThemeAreaHeight(int height); | |
133 | |
134 // Tells the page whether it is allowed to display Instant results. | |
135 void SetDisplayInstantResults(bool display_instant_results); | |
136 | |
137 // Tells the page whether the browser is capturing user key strokes. | |
138 void KeyCaptureChanged(bool is_key_capture_enabled); | |
139 | |
140 private: | |
141 // Overridden from content::WebContentsObserver: | |
142 virtual void RenderViewCreated( | |
143 content::RenderViewHost* render_view_host) OVERRIDE; | |
144 virtual void DidFinishLoad( | |
145 int64 frame_id, | |
146 const GURL& validated_url, | |
147 bool is_main_frame, | |
148 content::RenderViewHost* render_view_host) OVERRIDE; | |
149 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | |
150 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE; | |
151 virtual void DidCommitProvisionalLoadForFrame( | |
152 int64 frame_id, | |
153 bool is_main_frame, | |
154 const GURL& url, | |
155 content::PageTransition transition_type, | |
156 content::RenderViewHost* render_view_host) OVERRIDE; | |
157 | |
158 void SetSuggestions(int page_id, | |
159 const std::vector<InstantSuggestion>& suggestions); | |
160 void InstantSupportDetermined(int page_id, bool result); | |
161 void ShowInstantPreview(int page_id, | |
162 InstantShownReason reason, | |
163 int height, | |
164 InstantSizeUnits units); | |
165 void StartCapturingKeyStrokes(int page_id); | |
166 void StopCapturingKeyStrokes(int page_id); | |
167 void SearchBoxNavigate(int page_id, const GURL& url, | |
168 content::PageTransition transition); | |
169 | |
170 Delegate* const delegate_; | |
171 | |
172 DISALLOW_COPY_AND_ASSIGN(InstantClient); | |
173 }; | |
174 | |
175 #endif // CHROME_BROWSER_INSTANT_INSTANT_CLIENT_H_ | |
OLD | NEW |