| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_UI_SEARCH_INSTANT_PAGE_H_ | 5 #ifndef CHROME_BROWSER_UI_SEARCH_INSTANT_PAGE_H_ |
| 6 #define CHROME_BROWSER_UI_SEARCH_INSTANT_PAGE_H_ | 6 #define CHROME_BROWSER_UI_SEARCH_INSTANT_PAGE_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
| 13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 14 #include "chrome/browser/ui/search/search_model_observer.h" |
| 14 #include "chrome/common/instant_types.h" | 15 #include "chrome/common/instant_types.h" |
| 15 #include "chrome/common/omnibox_focus_state.h" | 16 #include "chrome/common/omnibox_focus_state.h" |
| 16 #include "content/public/browser/web_contents_observer.h" | 17 #include "content/public/browser/web_contents_observer.h" |
| 17 #include "content/public/common/page_transition_types.h" | 18 #include "content/public/common/page_transition_types.h" |
| 18 | 19 |
| 19 class GURL; | 20 class GURL; |
| 20 | 21 |
| 21 namespace content { | 22 namespace content { |
| 22 struct FrameNavigateParams; | 23 struct FrameNavigateParams; |
| 23 struct LoadCommittedDetails; | 24 struct LoadCommittedDetails; |
| 24 class WebContents; | 25 class WebContents; |
| 25 } | 26 } |
| 26 | 27 |
| 27 namespace gfx { | 28 namespace gfx { |
| 28 class Rect; | 29 class Rect; |
| 29 } | 30 } |
| 30 | 31 |
| 31 // InstantPage is used to exchange messages with a page that implements the | 32 // InstantPage is used to exchange messages with a page that implements the |
| 32 // Instant/Embedded Search API (http://dev.chromium.org/embeddedsearch). | 33 // Instant/Embedded Search API (http://dev.chromium.org/embeddedsearch). |
| 33 // InstantPage is not used directly but via one of its derived classes: | 34 // InstantPage is not used directly but via one of its derived classes: |
| 34 // InstantOverlay, InstantNTP and InstantTab. | 35 // InstantOverlay, InstantNTP and InstantTab. |
| 35 class InstantPage : public content::WebContentsObserver { | 36 class InstantPage : public content::WebContentsObserver, |
| 37 public SearchModelObserver { |
| 36 public: | 38 public: |
| 37 // InstantPage calls its delegate in response to messages received from the | 39 // InstantPage calls its delegate in response to messages received from the |
| 38 // page. Each method is called with the |contents| corresponding to the page | 40 // page. Each method is called with the |contents| corresponding to the page |
| 39 // we are observing. | 41 // we are observing. |
| 40 class Delegate { | 42 class Delegate { |
| 41 public: | 43 public: |
| 42 // Called when a RenderView is created, so that state can be initialized. | 44 // Called when a RenderView is created, so that state can be initialized. |
| 43 virtual void InstantPageRenderViewCreated( | 45 virtual void InstantPageRenderViewCreated( |
| 44 const content::WebContents* contents) = 0; | 46 const content::WebContents* contents) = 0; |
| 45 | 47 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 // Returns the Instant URL that was loaded for this page. Returns the empty | 114 // Returns the Instant URL that was loaded for this page. Returns the empty |
| 113 // string if no URL was explicitly loaded as is the case for InstantTab. | 115 // string if no URL was explicitly loaded as is the case for InstantTab. |
| 114 const std::string& instant_url() const { return instant_url_; } | 116 const std::string& instant_url() const { return instant_url_; } |
| 115 | 117 |
| 116 // Returns true if the page is known to support the Instant API. This starts | 118 // Returns true if the page is known to support the Instant API. This starts |
| 117 // out false, and is set to true whenever we get any message from the page. | 119 // out false, and is set to true whenever we get any message from the page. |
| 118 // Once true, it never becomes false (the page isn't expected to drop API | 120 // Once true, it never becomes false (the page isn't expected to drop API |
| 119 // support suddenly). | 121 // support suddenly). |
| 120 virtual bool supports_instant() const; | 122 virtual bool supports_instant() const; |
| 121 | 123 |
| 122 // True if Instant support has been tested and determined for this page at | |
| 123 // least once. Note that Instant support may change in the future. | |
| 124 bool instant_support_determined() const { | |
| 125 return instant_support_determined_; | |
| 126 } | |
| 127 | |
| 128 // Returns true if the page is the local NTP (i.e. its URL is | 124 // Returns true if the page is the local NTP (i.e. its URL is |
| 129 // chrome::kChromeSearchLocalNTPURL). | 125 // chrome::kChromeSearchLocalNTPURL). |
| 130 virtual bool IsLocal() const; | 126 virtual bool IsLocal() const; |
| 131 | 127 |
| 132 // Tells the page that the user typed |text| into the omnibox. If |verbatim| | 128 // Tells the page that the user typed |text| into the omnibox. If |verbatim| |
| 133 // is false, the page predicts the query the user means to type and fetches | 129 // is false, the page predicts the query the user means to type and fetches |
| 134 // results for the prediction. If |verbatim| is true, |text| is taken as the | 130 // results for the prediction. If |verbatim| is true, |text| is taken as the |
| 135 // exact query (no prediction is made). |selection_start| and |selection_end| | 131 // exact query (no prediction is made). |selection_start| and |selection_end| |
| 136 // mark the inline autocompleted portion (i.e., blue highlighted text). The | 132 // mark the inline autocompleted portion (i.e., blue highlighted text). The |
| 137 // omnibox caret (cursor) is at |selection_end|. | 133 // omnibox caret (cursor) is at |selection_end|. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 152 // by the omnibox dropdown. | 148 // by the omnibox dropdown. |
| 153 void SetPopupBounds(const gfx::Rect& bounds); | 149 void SetPopupBounds(const gfx::Rect& bounds); |
| 154 | 150 |
| 155 // Tells the page the bounds of the omnibox (in screen coordinates). This is | 151 // Tells the page the bounds of the omnibox (in screen coordinates). This is |
| 156 // used by the page to align text or assets properly with the omnibox. | 152 // used by the page to align text or assets properly with the omnibox. |
| 157 void SetOmniboxBounds(const gfx::Rect& bounds); | 153 void SetOmniboxBounds(const gfx::Rect& bounds); |
| 158 | 154 |
| 159 // Tells the page about the font information. | 155 // Tells the page about the font information. |
| 160 void InitializeFonts(); | 156 void InitializeFonts(); |
| 161 | 157 |
| 162 // Tells the renderer to determine if the page supports the Instant API, which | |
| 163 // results in a call to InstantSupportDetermined() when the reply is received. | |
| 164 void DetermineIfPageSupportsInstant(); | |
| 165 | |
| 166 // Tells the page about the available autocomplete results. | 158 // Tells the page about the available autocomplete results. |
| 167 void SendAutocompleteResults( | 159 void SendAutocompleteResults( |
| 168 const std::vector<InstantAutocompleteResult>& results); | 160 const std::vector<InstantAutocompleteResult>& results); |
| 169 | 161 |
| 170 // Tells the page that the user pressed Up or Down in the omnibox. |count| is | 162 // Tells the page that the user pressed Up or Down in the omnibox. |count| is |
| 171 // a repeat count, negative for moving up, positive for moving down. | 163 // a repeat count, negative for moving up, positive for moving down. |
| 172 void UpOrDownKeyPressed(int count); | 164 void UpOrDownKeyPressed(int count); |
| 173 | 165 |
| 174 // Tells the page that the user pressed Esc key in the omnibox. | 166 // Tells the page that the user pressed Esc key in the omnibox. |
| 175 void EscKeyPressed(); | 167 void EscKeyPressed(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 194 // Tells the page about new Most Visited data. | 186 // Tells the page about new Most Visited data. |
| 195 void SendMostVisitedItems( | 187 void SendMostVisitedItems( |
| 196 const std::vector<InstantMostVisitedItem>& items); | 188 const std::vector<InstantMostVisitedItem>& items); |
| 197 | 189 |
| 198 // Tells the page to toggle voice search. | 190 // Tells the page to toggle voice search. |
| 199 void ToggleVoiceSearch(); | 191 void ToggleVoiceSearch(); |
| 200 | 192 |
| 201 protected: | 193 protected: |
| 202 InstantPage(Delegate* delegate, const std::string& instant_url); | 194 InstantPage(Delegate* delegate, const std::string& instant_url); |
| 203 | 195 |
| 204 // Sets |contents| as the page to communicate with. |contents| may be NULL, | 196 // Sets |web_contents| as the page to communicate with. |web_contents| may be |
| 205 // which effectively stops all communication. | 197 // NULL, which effectively stops all communication. |
| 206 void SetContents(content::WebContents* contents); | 198 void SetContents(content::WebContents* web_contents); |
| 207 | 199 |
| 208 Delegate* delegate() const { return delegate_; } | 200 Delegate* delegate() const { return delegate_; } |
| 209 | 201 |
| 210 // These functions are called before processing messages received from the | 202 // These functions are called before processing messages received from the |
| 211 // page. By default, all messages are handled, but any derived classes may | 203 // page. By default, all messages are handled, but any derived classes may |
| 212 // choose to ignore some or all of the received messages by overriding these | 204 // choose to ignore some or all of the received messages by overriding these |
| 213 // methods. | 205 // methods. |
| 214 virtual bool ShouldProcessRenderViewCreated(); | 206 virtual bool ShouldProcessRenderViewCreated(); |
| 215 virtual bool ShouldProcessRenderViewGone(); | 207 virtual bool ShouldProcessRenderViewGone(); |
| 216 virtual bool ShouldProcessAboutToNavigateMainFrame(); | 208 virtual bool ShouldProcessAboutToNavigateMainFrame(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 230 FRIEND_TEST_ALL_PREFIXES(InstantPageTest, | 222 FRIEND_TEST_ALL_PREFIXES(InstantPageTest, |
| 231 DispatchRequestToUndoAllMostVisitedDeletions); | 223 DispatchRequestToUndoAllMostVisitedDeletions); |
| 232 FRIEND_TEST_ALL_PREFIXES(InstantPageTest, | 224 FRIEND_TEST_ALL_PREFIXES(InstantPageTest, |
| 233 IgnoreMessageIfThePageIsNotActive); | 225 IgnoreMessageIfThePageIsNotActive); |
| 234 FRIEND_TEST_ALL_PREFIXES(InstantPageTest, | 226 FRIEND_TEST_ALL_PREFIXES(InstantPageTest, |
| 235 IgnoreMessageReceivedFromThePage); | 227 IgnoreMessageReceivedFromThePage); |
| 236 | 228 |
| 237 // Overridden from content::WebContentsObserver: | 229 // Overridden from content::WebContentsObserver: |
| 238 virtual void RenderViewCreated( | 230 virtual void RenderViewCreated( |
| 239 content::RenderViewHost* render_view_host) OVERRIDE; | 231 content::RenderViewHost* render_view_host) OVERRIDE; |
| 240 virtual void DidFinishLoad( | |
| 241 int64 frame_id, | |
| 242 const GURL& validated_url, | |
| 243 bool is_main_frame, | |
| 244 content::RenderViewHost* render_view_host) OVERRIDE; | |
| 245 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 232 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 246 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE; | 233 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE; |
| 247 virtual void DidCommitProvisionalLoadForFrame( | 234 virtual void DidCommitProvisionalLoadForFrame( |
| 248 int64 frame_id, | 235 int64 frame_id, |
| 249 bool is_main_frame, | 236 bool is_main_frame, |
| 250 const GURL& url, | 237 const GURL& url, |
| 251 content::PageTransition transition_type, | 238 content::PageTransition transition_type, |
| 252 content::RenderViewHost* render_view_host) OVERRIDE; | 239 content::RenderViewHost* render_view_host) OVERRIDE; |
| 253 virtual void DidNavigateMainFrame( | 240 virtual void DidNavigateMainFrame( |
| 254 const content::LoadCommittedDetails& details, | 241 const content::LoadCommittedDetails& details, |
| 255 const content::FrameNavigateParams& params) OVERRIDE; | 242 const content::FrameNavigateParams& params) OVERRIDE; |
| 256 virtual void DidFailProvisionalLoad( | 243 virtual void DidFailProvisionalLoad( |
| 257 int64 frame_id, | 244 int64 frame_id, |
| 258 bool is_main_frame, | 245 bool is_main_frame, |
| 259 const GURL& validated_url, | 246 const GURL& validated_url, |
| 260 int error_code, | 247 int error_code, |
| 261 const string16& error_description, | 248 const string16& error_description, |
| 262 content::RenderViewHost* render_view_host) OVERRIDE; | 249 content::RenderViewHost* render_view_host) OVERRIDE; |
| 263 | 250 |
| 251 // Overridden from SearchModelObserver: |
| 252 virtual void ModelChanged(const SearchModel::State& old_state, |
| 253 const SearchModel::State& new_state) OVERRIDE; |
| 254 |
| 255 // Helper to look up the SearchModel for this page. |
| 256 SearchModel* GetSearchModel(); |
| 257 |
| 258 // Update the status of Instant support. |
| 259 void SetSupportsInstant(bool supports_instant); |
| 260 |
| 264 void OnSetSuggestions(int page_id, | 261 void OnSetSuggestions(int page_id, |
| 265 const std::vector<InstantSuggestion>& suggestions); | 262 const std::vector<InstantSuggestion>& suggestions); |
| 266 void OnInstantSupportDetermined(int page_id, bool supports_instant); | |
| 267 void OnShowInstantOverlay(int page_id, | 263 void OnShowInstantOverlay(int page_id, |
| 268 int height, | 264 int height, |
| 269 InstantSizeUnits units); | 265 InstantSizeUnits units); |
| 270 void OnFocusOmnibox(int page_id, OmniboxFocusState state); | 266 void OnFocusOmnibox(int page_id, OmniboxFocusState state); |
| 271 void OnSearchBoxNavigate(int page_id, | 267 void OnSearchBoxNavigate(int page_id, |
| 272 const GURL& url, | 268 const GURL& url, |
| 273 content::PageTransition transition, | 269 content::PageTransition transition, |
| 274 WindowOpenDisposition disposition, | 270 WindowOpenDisposition disposition, |
| 275 bool is_search_type); | 271 bool is_search_type); |
| 276 void OnDeleteMostVisitedItem(int page_id, const GURL& url); | 272 void OnDeleteMostVisitedItem(int page_id, const GURL& url); |
| 277 void OnUndoMostVisitedDeletion(int page_id, const GURL& url); | 273 void OnUndoMostVisitedDeletion(int page_id, const GURL& url); |
| 278 void OnUndoAllMostVisitedDeletions(int page_id); | 274 void OnUndoAllMostVisitedDeletions(int page_id); |
| 279 | 275 |
| 280 Delegate* const delegate_; | 276 Delegate* const delegate_; |
| 281 const std::string instant_url_; | 277 const std::string instant_url_; |
| 282 bool supports_instant_; | |
| 283 bool instant_support_determined_; | |
| 284 | 278 |
| 285 DISALLOW_COPY_AND_ASSIGN(InstantPage); | 279 DISALLOW_COPY_AND_ASSIGN(InstantPage); |
| 286 }; | 280 }; |
| 287 | 281 |
| 288 #endif // CHROME_BROWSER_UI_SEARCH_INSTANT_PAGE_H_ | 282 #endif // CHROME_BROWSER_UI_SEARCH_INSTANT_PAGE_H_ |
| OLD | NEW |