Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 namespace chrome { | |
| 18 namespace search { | |
| 19 struct Mode; | |
| 20 } | |
| 21 } | |
| 22 | |
| 23 namespace content { | |
| 24 class WebContents; | |
| 25 } | |
| 26 | |
| 27 namespace gfx { | |
| 28 class Rect; | |
| 29 } | |
| 30 | |
| 31 class GURL; | |
|
sreeram
2013/01/29 13:35:42
Chrome style is to put unnamespaced declarations f
samarth
2013/01/31 16:24:57
Done.
| |
| 32 | |
| 33 // InstantPage is used to exchange messages with a page that implements the | |
| 34 // Instant/Embedded Search API (http://dev.chromium.org/embeddedsearch). | |
| 35 // InstantPage is not used directly but via one of its derived classes: | |
| 36 // InstantOverlay, InstantNTP and InstantTab. | |
| 37 class InstantPage : public content::WebContentsObserver { | |
| 38 public: | |
| 39 // InstantPage calls its delegate in response to messages received from the | |
| 40 // page. Each method is called with the |contents| corresponding to the page | |
| 41 // we are observing. | |
| 42 class Delegate { | |
| 43 public: | |
| 44 // Called upon determination of Instant API support. Either in response to | |
| 45 // the page loading or because we receivied some other message. | |
|
sreeram
2013/01/29 13:35:42
receivied -> received
samarth
2013/01/31 16:24:57
Done.
| |
| 46 virtual void InstantSupportDetermined(const content::WebContents* contents, | |
| 47 bool supports_instant) = 0; | |
| 48 | |
| 49 // Called when the underlying RenderView crashed. | |
| 50 virtual void InstantPageRenderViewGone( | |
| 51 const content::WebContents* contents) = 0; | |
| 52 | |
| 53 // Called when the page is about to navigate to |url|. | |
| 54 virtual void InstantPageAboutToNavigateMainFrame( | |
| 55 const content::WebContents* contents, | |
| 56 const GURL& url) = 0; | |
| 57 | |
| 58 // Called when the page has suggestions. Usually in response to Update(), | |
| 59 // SendAutocompleteResults() or UpOrDownKeyPressed(). | |
| 60 virtual void SetSuggestions( | |
| 61 const content::WebContents* contents, | |
| 62 const std::vector<InstantSuggestion>& suggestions) = 0; | |
| 63 | |
| 64 // Called when the page wants to be shown. Usually in response to Update(), | |
| 65 // SendAutocompleteResults() or SearchModeChanged(). | |
| 66 virtual void ShowInstantPreview(const content::WebContents* contents, | |
| 67 InstantShownReason reason, | |
| 68 int height, | |
| 69 InstantSizeUnits units) = 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 the specified URL. Usually | |
| 83 // used by the page to navigate to privileged destinations (e.g. chrome:// | |
| 84 // URLs) or to navigate to URLs that are hidden from the page using | |
| 85 // Restricted IDs (rid in the API). | |
| 86 virtual void NavigateToURL(const content::WebContents* contents, | |
| 87 const GURL& url, | |
| 88 content::PageTransition transition) = 0; | |
| 89 | |
| 90 protected: | |
| 91 virtual ~Delegate(); | |
| 92 }; | |
| 93 | |
| 94 virtual ~InstantPage(); | |
| 95 | |
| 96 // The WebContents corresponding to the page we're talking to. May be NULL. | |
| 97 content::WebContents* contents() const { return contents_; } | |
| 98 | |
| 99 // Returns true if the page is known to support the Instant API. This starts | |
| 100 // out false, and is set to true whenever we get any message from the page. | |
| 101 // Once true, it never becomes false (the page isn't expected to drop API | |
| 102 // support suddenly). | |
| 103 bool supports_instant() const { return supports_instant_; } | |
| 104 | |
| 105 // Tells the page that the user typed |text| into the omnibox. If |verbatim| | |
| 106 // is false, the page predicts the query the user means to type and fetches | |
| 107 // results for the prediction. If |verbatim| is true, |text| is taken as the | |
| 108 // exact query (no prediction is made). | |
| 109 virtual void Update(const string16& text, | |
| 110 size_t selection_start, | |
| 111 size_t selection_end, | |
| 112 bool verbatim); | |
| 113 | |
| 114 // Tells the page that the user pressed Enter in the omnibox. | |
| 115 void Submit(const string16& text); | |
| 116 | |
| 117 // Tells the page that the user clicked on it. Nothing is being cancelled; the | |
| 118 // poor choice of name merely reflects the IPC of the same (poor) name. | |
| 119 void Cancel(const string16& text); | |
| 120 | |
| 121 // Tells the page the bounds of the omnibox dropdown (in screen coordinates). | |
| 122 // This is used by the page to offset the results to avoid them being covered | |
| 123 // by the omnibox dropdown. | |
| 124 void SetPopupBounds(const gfx::Rect& bounds); | |
| 125 | |
| 126 // Tells the page the start and end margins of the omnibox (in screen | |
| 127 // coordinates). This is used by the page to align text or assets properly | |
| 128 // with the omnibox. | |
| 129 void SetMarginSize(int start, int end); | |
| 130 | |
| 131 // Tells the renderer to determine if the page supports the Instant API, which | |
| 132 // results in a call to InstantSupportDetermined() when the reply is received. | |
| 133 void DetermineIfPageSupportsInstant(); | |
| 134 | |
| 135 // Tells the page about the available autocomplete results. | |
| 136 void SendAutocompleteResults( | |
| 137 const std::vector<InstantAutocompleteResult>& results); | |
| 138 | |
| 139 // Tells the page that the user pressed Up or Down in the omnibox. |count| is | |
| 140 // a repeat count, negative for moving up, positive for moving down. | |
| 141 void UpOrDownKeyPressed(int count); | |
| 142 | |
| 143 // Tells the page that the active tab's search mode has changed. | |
| 144 void SearchModeChanged(const chrome::search::Mode& mode); | |
| 145 | |
| 146 // Tells the page about the current theme background. | |
| 147 void SendThemeBackgroundInfo(const ThemeBackgroundInfo& theme_info); | |
| 148 | |
| 149 // Tells the page about the current theme area height. | |
| 150 void SendThemeAreaHeight(int height); | |
| 151 | |
| 152 // Tells the page whether it is allowed to display Instant results. | |
| 153 void SetDisplayInstantResults(bool display_instant_results); | |
| 154 | |
| 155 // Tells the page whether the browser is capturing user key strokes. | |
| 156 void KeyCaptureChanged(bool is_key_capture_enabled); | |
| 157 | |
| 158 protected: | |
| 159 explicit InstantPage(Delegate* delegate); | |
| 160 | |
| 161 // Sets |contents| as the page to communicate with. |contents| may be NULL, | |
| 162 // which effectively stops all communication. | |
| 163 void SetContents(content::WebContents* contents); | |
| 164 | |
| 165 Delegate* delegate() const { return delegate_; } | |
| 166 | |
| 167 // These functions are called before processing messages received from the | |
| 168 // page. By default, all messages are handled, but any derived classes may | |
| 169 // choose to ingore some or all of the received messages by overriding these | |
| 170 // methods. | |
| 171 virtual bool ShouldProcessRenderViewGone() const; | |
| 172 virtual bool ShouldProcessAboutToNavigateMainFrame() const; | |
| 173 virtual bool ShouldProcessSetSuggestions() const; | |
| 174 virtual bool ShouldProcessShowInstantPreview() const; | |
| 175 virtual bool ShouldProcessStartCapturingKeyStrokes() const; | |
| 176 virtual bool ShouldProcessStopCapturingKeyStrokes() const; | |
| 177 virtual bool ShouldProcessNavigateToURL() const; | |
|
sreeram
2013/01/29 13:35:42
No, there's nothing inherently const about "Should
samarth
2013/01/31 16:24:57
Ok, done.
| |
| 178 | |
| 179 private: | |
| 180 // Overridden from content::WebContentsObserver: | |
| 181 virtual void DidFinishLoad( | |
| 182 int64 frame_id, | |
| 183 const GURL& validated_url, | |
| 184 bool is_main_frame, | |
| 185 content::RenderViewHost* render_view_host) OVERRIDE; | |
| 186 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | |
| 187 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE; | |
| 188 virtual void DidCommitProvisionalLoadForFrame( | |
| 189 int64 frame_id, | |
| 190 bool is_main_frame, | |
| 191 const GURL& url, | |
| 192 content::PageTransition transition_type, | |
| 193 content::RenderViewHost* render_view_host) OVERRIDE; | |
| 194 | |
| 195 void OnSetSuggestions(int page_id, | |
| 196 const std::vector<InstantSuggestion>& suggestions); | |
| 197 void OnInstantSupportDetermined(int page_id, bool supports_instant); | |
| 198 void OnShowInstantPreview(int page_id, | |
| 199 InstantShownReason reason, | |
| 200 int height, | |
| 201 InstantSizeUnits units); | |
| 202 void OnStartCapturingKeyStrokes(int page_id); | |
| 203 void OnStopCapturingKeyStrokes(int page_id); | |
| 204 void OnSearchBoxNavigate(int page_id, const GURL& url, | |
| 205 content::PageTransition transition); | |
| 206 | |
| 207 Delegate* const delegate_; | |
| 208 content::WebContents* contents_; | |
| 209 bool supports_instant_; | |
| 210 | |
| 211 DISALLOW_COPY_AND_ASSIGN(InstantPage); | |
| 212 }; | |
| 213 | |
| 214 #endif // CHROME_BROWSER_INSTANT_INSTANT_PAGE_H_ | |
| OLD | NEW |