| 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/string16.h" | 13 #include "base/string16.h" |
| 14 #include "chrome/browser/ui/search/search_model_observer.h" | |
| 15 #include "chrome/common/instant_types.h" | 14 #include "chrome/common/instant_types.h" |
| 16 #include "chrome/common/omnibox_focus_state.h" | 15 #include "chrome/common/omnibox_focus_state.h" |
| 17 #include "content/public/browser/web_contents_observer.h" | 16 #include "content/public/browser/web_contents_observer.h" |
| 18 #include "content/public/common/page_transition_types.h" | 17 #include "content/public/common/page_transition_types.h" |
| 19 | 18 |
| 20 class GURL; | 19 class GURL; |
| 21 | 20 |
| 22 namespace content { | 21 namespace content { |
| 23 struct FrameNavigateParams; | 22 struct FrameNavigateParams; |
| 24 struct LoadCommittedDetails; | 23 struct LoadCommittedDetails; |
| 25 class WebContents; | 24 class WebContents; |
| 26 } | 25 } |
| 27 | 26 |
| 28 namespace gfx { | 27 namespace gfx { |
| 29 class Rect; | 28 class Rect; |
| 30 } | 29 } |
| 31 | 30 |
| 32 // InstantPage is used to exchange messages with a page that implements the | 31 // InstantPage is used to exchange messages with a page that implements the |
| 33 // Instant/Embedded Search API (http://dev.chromium.org/embeddedsearch). | 32 // Instant/Embedded Search API (http://dev.chromium.org/embeddedsearch). |
| 34 // InstantPage is not used directly but via one of its derived classes: | 33 // InstantPage is not used directly but via one of its derived classes: |
| 35 // InstantOverlay, InstantNTP and InstantTab. | 34 // InstantOverlay, InstantNTP and InstantTab. |
| 36 class InstantPage : public content::WebContentsObserver, | 35 class InstantPage : public content::WebContentsObserver { |
| 37 public SearchModelObserver { | |
| 38 public: | 36 public: |
| 39 // InstantPage calls its delegate in response to messages received from the | 37 // InstantPage calls its delegate in response to messages received from the |
| 40 // page. Each method is called with the |contents| corresponding to the page | 38 // page. Each method is called with the |contents| corresponding to the page |
| 41 // we are observing. | 39 // we are observing. |
| 42 class Delegate { | 40 class Delegate { |
| 43 public: | 41 public: |
| 44 // Called when a RenderView is created, so that state can be initialized. | 42 // Called when a RenderView is created, so that state can be initialized. |
| 45 virtual void InstantPageRenderViewCreated( | 43 virtual void InstantPageRenderViewCreated( |
| 46 const content::WebContents* contents) = 0; | 44 const content::WebContents* contents) = 0; |
| 47 | 45 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 // Returns the Instant URL that was loaded for this page. Returns the empty | 112 // Returns the Instant URL that was loaded for this page. Returns the empty |
| 115 // string if no URL was explicitly loaded as is the case for InstantTab. | 113 // string if no URL was explicitly loaded as is the case for InstantTab. |
| 116 const std::string& instant_url() const { return instant_url_; } | 114 const std::string& instant_url() const { return instant_url_; } |
| 117 | 115 |
| 118 // Returns true if the page is known to support the Instant API. This starts | 116 // Returns true if the page is known to support the Instant API. This starts |
| 119 // out false, and is set to true whenever we get any message from the page. | 117 // out false, and is set to true whenever we get any message from the page. |
| 120 // Once true, it never becomes false (the page isn't expected to drop API | 118 // Once true, it never becomes false (the page isn't expected to drop API |
| 121 // support suddenly). | 119 // support suddenly). |
| 122 virtual bool supports_instant() const; | 120 virtual bool supports_instant() const; |
| 123 | 121 |
| 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 |
| 124 // Returns true if the page is the local NTP (i.e. its URL is | 128 // Returns true if the page is the local NTP (i.e. its URL is |
| 125 // chrome::kChromeSearchLocalNTPURL). | 129 // chrome::kChromeSearchLocalNTPURL). |
| 126 virtual bool IsLocal() const; | 130 virtual bool IsLocal() const; |
| 127 | 131 |
| 128 // Tells the page that the user typed |text| into the omnibox. If |verbatim| | 132 // Tells the page that the user typed |text| into the omnibox. If |verbatim| |
| 129 // is false, the page predicts the query the user means to type and fetches | 133 // is false, the page predicts the query the user means to type and fetches |
| 130 // results for the prediction. If |verbatim| is true, |text| is taken as the | 134 // results for the prediction. If |verbatim| is true, |text| is taken as the |
| 131 // exact query (no prediction is made). |selection_start| and |selection_end| | 135 // exact query (no prediction is made). |selection_start| and |selection_end| |
| 132 // mark the inline autocompleted portion (i.e., blue highlighted text). The | 136 // mark the inline autocompleted portion (i.e., blue highlighted text). The |
| 133 // omnibox caret (cursor) is at |selection_end|. | 137 // omnibox caret (cursor) is at |selection_end|. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 148 // by the omnibox dropdown. | 152 // by the omnibox dropdown. |
| 149 void SetPopupBounds(const gfx::Rect& bounds); | 153 void SetPopupBounds(const gfx::Rect& bounds); |
| 150 | 154 |
| 151 // Tells the page the bounds of the omnibox (in screen coordinates). This is | 155 // Tells the page the bounds of the omnibox (in screen coordinates). This is |
| 152 // used by the page to align text or assets properly with the omnibox. | 156 // used by the page to align text or assets properly with the omnibox. |
| 153 void SetOmniboxBounds(const gfx::Rect& bounds); | 157 void SetOmniboxBounds(const gfx::Rect& bounds); |
| 154 | 158 |
| 155 // Tells the page about the font information. | 159 // Tells the page about the font information. |
| 156 void InitializeFonts(); | 160 void InitializeFonts(); |
| 157 | 161 |
| 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 |
| 158 // Tells the page about the available autocomplete results. | 166 // Tells the page about the available autocomplete results. |
| 159 void SendAutocompleteResults( | 167 void SendAutocompleteResults( |
| 160 const std::vector<InstantAutocompleteResult>& results); | 168 const std::vector<InstantAutocompleteResult>& results); |
| 161 | 169 |
| 162 // Tells the page that the user pressed Up or Down in the omnibox. |count| is | 170 // Tells the page that the user pressed Up or Down in the omnibox. |count| is |
| 163 // a repeat count, negative for moving up, positive for moving down. | 171 // a repeat count, negative for moving up, positive for moving down. |
| 164 void UpOrDownKeyPressed(int count); | 172 void UpOrDownKeyPressed(int count); |
| 165 | 173 |
| 166 // Tells the page that the user pressed Esc key in the omnibox. | 174 // Tells the page that the user pressed Esc key in the omnibox. |
| 167 void EscKeyPressed(); | 175 void EscKeyPressed(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 FRIEND_TEST_ALL_PREFIXES(InstantPageTest, | 223 FRIEND_TEST_ALL_PREFIXES(InstantPageTest, |
| 216 DispatchRequestToDeleteMostVisitedItem); | 224 DispatchRequestToDeleteMostVisitedItem); |
| 217 FRIEND_TEST_ALL_PREFIXES(InstantPageTest, | 225 FRIEND_TEST_ALL_PREFIXES(InstantPageTest, |
| 218 DispatchRequestToUndoMostVisitedDeletion); | 226 DispatchRequestToUndoMostVisitedDeletion); |
| 219 FRIEND_TEST_ALL_PREFIXES(InstantPageTest, | 227 FRIEND_TEST_ALL_PREFIXES(InstantPageTest, |
| 220 DispatchRequestToUndoAllMostVisitedDeletions); | 228 DispatchRequestToUndoAllMostVisitedDeletions); |
| 221 | 229 |
| 222 // Overridden from content::WebContentsObserver: | 230 // Overridden from content::WebContentsObserver: |
| 223 virtual void RenderViewCreated( | 231 virtual void RenderViewCreated( |
| 224 content::RenderViewHost* render_view_host) OVERRIDE; | 232 content::RenderViewHost* render_view_host) OVERRIDE; |
| 233 virtual void DidFinishLoad( |
| 234 int64 frame_id, |
| 235 const GURL& validated_url, |
| 236 bool is_main_frame, |
| 237 content::RenderViewHost* render_view_host) OVERRIDE; |
| 225 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 238 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 226 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE; | 239 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE; |
| 227 virtual void DidCommitProvisionalLoadForFrame( | 240 virtual void DidCommitProvisionalLoadForFrame( |
| 228 int64 frame_id, | 241 int64 frame_id, |
| 229 bool is_main_frame, | 242 bool is_main_frame, |
| 230 const GURL& url, | 243 const GURL& url, |
| 231 content::PageTransition transition_type, | 244 content::PageTransition transition_type, |
| 232 content::RenderViewHost* render_view_host) OVERRIDE; | 245 content::RenderViewHost* render_view_host) OVERRIDE; |
| 233 virtual void DidNavigateMainFrame( | 246 virtual void DidNavigateMainFrame( |
| 234 const content::LoadCommittedDetails& details, | 247 const content::LoadCommittedDetails& details, |
| 235 const content::FrameNavigateParams& params) OVERRIDE; | 248 const content::FrameNavigateParams& params) OVERRIDE; |
| 236 virtual void DidFailProvisionalLoad( | 249 virtual void DidFailProvisionalLoad( |
| 237 int64 frame_id, | 250 int64 frame_id, |
| 238 bool is_main_frame, | 251 bool is_main_frame, |
| 239 const GURL& validated_url, | 252 const GURL& validated_url, |
| 240 int error_code, | 253 int error_code, |
| 241 const string16& error_description, | 254 const string16& error_description, |
| 242 content::RenderViewHost* render_view_host) OVERRIDE; | 255 content::RenderViewHost* render_view_host) OVERRIDE; |
| 243 | 256 |
| 244 // Overridden from SearchModelObserver: | |
| 245 virtual void ModelChanged(const SearchModel::State& old_state, | |
| 246 const SearchModel::State& new_state) OVERRIDE; | |
| 247 | |
| 248 // Helper to look up the SearchModel for this page. | |
| 249 SearchModel* GetSearchModel(); | |
| 250 | |
| 251 // Update the status of Instant support. | |
| 252 void SetSupportsInstant(bool supports_instant); | |
| 253 | |
| 254 void OnSetSuggestions(int page_id, | 257 void OnSetSuggestions(int page_id, |
| 255 const std::vector<InstantSuggestion>& suggestions); | 258 const std::vector<InstantSuggestion>& suggestions); |
| 259 void OnInstantSupportDetermined(int page_id, bool supports_instant); |
| 256 void OnShowInstantOverlay(int page_id, | 260 void OnShowInstantOverlay(int page_id, |
| 257 int height, | 261 int height, |
| 258 InstantSizeUnits units); | 262 InstantSizeUnits units); |
| 259 void OnFocusOmnibox(int page_id, OmniboxFocusState state); | 263 void OnFocusOmnibox(int page_id, OmniboxFocusState state); |
| 260 void OnSearchBoxNavigate(int page_id, | 264 void OnSearchBoxNavigate(int page_id, |
| 261 const GURL& url, | 265 const GURL& url, |
| 262 content::PageTransition transition, | 266 content::PageTransition transition, |
| 263 WindowOpenDisposition disposition, | 267 WindowOpenDisposition disposition, |
| 264 bool is_search_type); | 268 bool is_search_type); |
| 265 void OnDeleteMostVisitedItem(const GURL& url); | 269 void OnDeleteMostVisitedItem(const GURL& url); |
| 266 void OnUndoMostVisitedDeletion(const GURL& url); | 270 void OnUndoMostVisitedDeletion(const GURL& url); |
| 267 void OnUndoAllMostVisitedDeletions(); | 271 void OnUndoAllMostVisitedDeletions(); |
| 268 | 272 |
| 269 Delegate* const delegate_; | 273 Delegate* const delegate_; |
| 270 const std::string instant_url_; | 274 const std::string instant_url_; |
| 271 | |
| 272 // TODO(kmadhusu): Remove |supports_instant_| from here and get the details | |
| 273 // from SearchModel. Refer to crbug.com/246323 for more details. | |
| 274 bool supports_instant_; | 275 bool supports_instant_; |
| 276 bool instant_support_determined_; |
| 275 | 277 |
| 276 DISALLOW_COPY_AND_ASSIGN(InstantPage); | 278 DISALLOW_COPY_AND_ASSIGN(InstantPage); |
| 277 }; | 279 }; |
| 278 | 280 |
| 279 #endif // CHROME_BROWSER_UI_SEARCH_INSTANT_PAGE_H_ | 281 #endif // CHROME_BROWSER_UI_SEARCH_INSTANT_PAGE_H_ |
| OLD | NEW |