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 protected: |
| 54 virtual ~Delegate(); |
| 55 }; |
| 56 |
| 57 // Doesn't take ownership of |delegate|. |
| 58 explicit InstantClient(Delegate* delegate); |
| 59 virtual ~InstantClient(); |
| 60 |
| 61 // Sets |contents| as the page to communicate with. |contents| can be NULL, |
| 62 // which effectively stops all communication. |
| 63 void SetContents(content::WebContents* contents); |
| 64 |
| 65 // Tells the page that the user typed |text| into the omnibox. If |verbatim| |
| 66 // is false, the page predicts the query the user means to type and fetches |
| 67 // results for the prediction. If |verbatim| is true, |text| is taken as the |
| 68 // exact query (no prediction is made). |
| 69 void Update(const string16& text, |
| 70 size_t selection_start, |
| 71 size_t selection_end, |
| 72 bool verbatim); |
| 73 |
| 74 // Tells the page that the user pressed Enter in the omnibox. |
| 75 void Submit(const string16& text); |
| 76 |
| 77 // Tells the page that the user clicked on it. Nothing is being cancelled; the |
| 78 // poor choice of name merely reflects the IPC of the same (poor) name. |
| 79 void Cancel(const string16& text); |
| 80 |
| 81 // Tells the page the bounds of the omnibox dropdown (in screen coordinates). |
| 82 // This is used by the page to offset the results to avoid them being covered |
| 83 // by the omnibox dropdown. |
| 84 void SetOmniboxBounds(const gfx::Rect& bounds); |
| 85 |
| 86 // Tells the renderer to determine if the page supports the Instant API, which |
| 87 // results in a call to InstantSupportDetermined() when the reply is received. |
| 88 void DetermineIfPageSupportsInstant(); |
| 89 |
| 90 // Tells the page about the available autocomplete results. |
| 91 void SendAutocompleteResults( |
| 92 const std::vector<InstantAutocompleteResult>& results); |
| 93 |
| 94 // Tells the page that the user pressed Up or Down in the omnibox. |count| is |
| 95 // a repeat count, negative for moving up, positive for moving down. |
| 96 void UpOrDownKeyPressed(int count); |
| 97 |
| 98 // Tells the page that the active tab's search mode has changed. |
| 99 void SearchModeChanged(const chrome::search::Mode& mode); |
| 100 |
| 101 // Tells the page about the current theme background. |
| 102 void SendThemeBackgroundInfo(const ThemeBackgroundInfo& theme_info); |
| 103 |
| 104 // Tells the page about the current theme area height. |
| 105 void SendThemeAreaHeight(int height); |
| 106 |
| 107 // Tells the page whether it is allowed to display Instant results. |
| 108 void SetDisplayInstantResults(bool display_instant_results); |
| 109 |
| 110 private: |
| 111 // Overridden from content::WebContentsObserver: |
| 112 virtual void DidFinishLoad( |
| 113 int64 frame_id, |
| 114 const GURL& validated_url, |
| 115 bool is_main_frame, |
| 116 content::RenderViewHost* render_view_host) OVERRIDE; |
| 117 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 118 |
| 119 void SetSuggestions(int page_id, |
| 120 const std::vector<InstantSuggestion>& suggestions); |
| 121 void InstantSupportDetermined(int page_id, bool result); |
| 122 void ShowInstantPreview(int page_id, |
| 123 InstantShownReason reason, |
| 124 int height, |
| 125 InstantSizeUnits units); |
| 126 |
| 127 Delegate* const delegate_; |
| 128 |
| 129 DISALLOW_COPY_AND_ASSIGN(InstantClient); |
| 130 }; |
| 131 |
| 132 #endif // CHROME_BROWSER_INSTANT_INSTANT_CLIENT_H_ |
OLD | NEW |