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 { | |
sky
2012/12/03 22:22:23
The style guide says classes like this should be i
sreeram
2012/12/04 08:10:52
Right. However, all the implementors of this inter
| |
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 | |
54 // Doesn't take ownership of |delegate|. | |
55 explicit InstantClient(Delegate* delegate); | |
56 virtual ~InstantClient(); | |
sky
2012/12/03 22:22:23
Does this need to be virtual?
sreeram
2012/12/04 08:10:52
No. But without it, the clang style plugin or some
| |
57 | |
58 // Sets |contents| as the page to communicate with. |contents| can be NULL, | |
59 // which effectively stops all communication. | |
60 void SetContents(content::WebContents* contents); | |
61 | |
62 // Tells the page that the user typed |text| into the omnibox. If |verbatim| | |
63 // is false, the page predicts the query the user means to type and fetches | |
64 // results for the prediction. If |verbatim| is true, |text| is taken as the | |
65 // exact query (no prediction is made). | |
66 void Update(const string16& text, bool verbatim); | |
67 | |
68 // Tells the page that the user pressed Enter in the omnibox. | |
69 void Submit(const string16& text); | |
70 | |
71 // Tells the page that the user clicked on it. | |
samarth
2012/12/03 19:46:03
A little more explanation please. Otherwise the co
sreeram
2012/12/04 08:10:52
Done.
| |
72 void Cancel(const string16& text); | |
73 | |
74 // Tells the page the bounds of the omnibox dropdown (in screen coordinates). | |
75 // This is used by the page to offset the results to avoid them being covered | |
76 // by the omnibox dropdown. | |
77 void SetOmniboxBounds(const gfx::Rect& bounds); | |
78 | |
79 // Tells the renderer to determine if the page supports the Instant API, which | |
80 // results in a call to InstantSupportDetermined() when the reply is received. | |
81 void DetermineIfPageSupportsInstant(); | |
82 | |
83 // Tells the page about the available autocomplete results. | |
84 void SendAutocompleteResults( | |
85 const std::vector<InstantAutocompleteResult>& results); | |
86 | |
87 // Tells the page that the user pressed Up or Down in the omnibox. |count| is | |
88 // a repeat count, negative for moving up, positive for moving down. | |
89 void UpOrDownKeyPressed(int count); | |
90 | |
91 // Tells the page that the active tab's search mode has changed. | |
92 void SearchModeChanged(const chrome::search::Mode& mode); | |
93 | |
94 // Tells the page about the current theme background. | |
95 void SendThemeBackgroundInfo(const ThemeBackgroundInfo& theme_info); | |
96 | |
97 // Tells the page about the current theme area height. | |
98 void SendThemeAreaHeight(int height); | |
99 | |
100 private: | |
101 // Overridden from content::WebContentsObserver: | |
102 virtual void DidFinishLoad( | |
103 int64 frame_id, | |
104 const GURL& validated_url, | |
105 bool is_main_frame, | |
106 content::RenderViewHost* render_view_host) OVERRIDE; | |
107 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | |
108 | |
109 void SetSuggestions(int page_id, | |
110 const std::vector<InstantSuggestion>& suggestions); | |
111 void InstantSupportDetermined(int page_id, bool result); | |
112 void ShowInstantPreview(int page_id, | |
113 InstantShownReason reason, | |
114 int height, | |
115 InstantSizeUnits units); | |
116 | |
117 Delegate* const delegate_; | |
118 | |
119 DISALLOW_COPY_AND_ASSIGN(InstantClient); | |
120 }; | |
121 | |
122 #endif // CHROME_BROWSER_INSTANT_INSTANT_CLIENT_H_ | |
OLD | NEW |