| 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" |
| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 FRIEND_TEST_ALL_PREFIXES(InstantPageTest, | 212 FRIEND_TEST_ALL_PREFIXES(InstantPageTest, |
| 221 DispatchRequestToDeleteMostVisitedItem); | 213 DispatchRequestToDeleteMostVisitedItem); |
| 222 FRIEND_TEST_ALL_PREFIXES(InstantPageTest, | 214 FRIEND_TEST_ALL_PREFIXES(InstantPageTest, |
| 223 DispatchRequestToUndoMostVisitedDeletion); | 215 DispatchRequestToUndoMostVisitedDeletion); |
| 224 FRIEND_TEST_ALL_PREFIXES(InstantPageTest, | 216 FRIEND_TEST_ALL_PREFIXES(InstantPageTest, |
| 225 DispatchRequestToUndoAllMostVisitedDeletions); | 217 DispatchRequestToUndoAllMostVisitedDeletions); |
| 226 | 218 |
| 227 // Overridden from content::WebContentsObserver: | 219 // Overridden from content::WebContentsObserver: |
| 228 virtual void RenderViewCreated( | 220 virtual void RenderViewCreated( |
| 229 content::RenderViewHost* render_view_host) OVERRIDE; | 221 content::RenderViewHost* render_view_host) OVERRIDE; |
| 230 virtual void DidFinishLoad( | |
| 231 int64 frame_id, | |
| 232 const GURL& validated_url, | |
| 233 bool is_main_frame, | |
| 234 content::RenderViewHost* render_view_host) OVERRIDE; | |
| 235 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 222 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 236 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE; | 223 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE; |
| 237 virtual void DidCommitProvisionalLoadForFrame( | 224 virtual void DidCommitProvisionalLoadForFrame( |
| 238 int64 frame_id, | 225 int64 frame_id, |
| 239 bool is_main_frame, | 226 bool is_main_frame, |
| 240 const GURL& url, | 227 const GURL& url, |
| 241 content::PageTransition transition_type, | 228 content::PageTransition transition_type, |
| 242 content::RenderViewHost* render_view_host) OVERRIDE; | 229 content::RenderViewHost* render_view_host) OVERRIDE; |
| 243 virtual void DidNavigateMainFrame( | 230 virtual void DidNavigateMainFrame( |
| 244 const content::LoadCommittedDetails& details, | 231 const content::LoadCommittedDetails& details, |
| 245 const content::FrameNavigateParams& params) OVERRIDE; | 232 const content::FrameNavigateParams& params) OVERRIDE; |
| 246 virtual void DidFailProvisionalLoad( | 233 virtual void DidFailProvisionalLoad( |
| 247 int64 frame_id, | 234 int64 frame_id, |
| 248 bool is_main_frame, | 235 bool is_main_frame, |
| 249 const GURL& validated_url, | 236 const GURL& validated_url, |
| 250 int error_code, | 237 int error_code, |
| 251 const string16& error_description, | 238 const string16& error_description, |
| 252 content::RenderViewHost* render_view_host) OVERRIDE; | 239 content::RenderViewHost* render_view_host) OVERRIDE; |
| 253 | 240 |
| 241 // Overridden from SearchModelObserver: |
| 242 virtual void ModelChanged(const SearchModel::State& old_state, |
| 243 const SearchModel::State& new_state) OVERRIDE; |
| 244 |
| 245 // Helper to look up the SearchModel for this page. |
| 246 SearchModel* GetSearchModel(); |
| 247 |
| 248 // Update the status of Instant support. |
| 249 void SetSupportsInstant(bool supports_instant); |
| 250 |
| 254 void OnSetSuggestions(int page_id, | 251 void OnSetSuggestions(int page_id, |
| 255 const std::vector<InstantSuggestion>& suggestions); | 252 const std::vector<InstantSuggestion>& suggestions); |
| 256 void OnInstantSupportDetermined(int page_id, bool supports_instant); | |
| 257 void OnShowInstantOverlay(int page_id, | 253 void OnShowInstantOverlay(int page_id, |
| 258 int height, | 254 int height, |
| 259 InstantSizeUnits units); | 255 InstantSizeUnits units); |
| 260 void OnFocusOmnibox(int page_id, OmniboxFocusState state); | 256 void OnFocusOmnibox(int page_id, OmniboxFocusState state); |
| 261 void OnSearchBoxNavigate(int page_id, | 257 void OnSearchBoxNavigate(int page_id, |
| 262 const GURL& url, | 258 const GURL& url, |
| 263 content::PageTransition transition, | 259 content::PageTransition transition, |
| 264 WindowOpenDisposition disposition, | 260 WindowOpenDisposition disposition, |
| 265 bool is_search_type); | 261 bool is_search_type); |
| 266 void OnDeleteMostVisitedItem(const GURL& url); | 262 void OnDeleteMostVisitedItem(const GURL& url); |
| 267 void OnUndoMostVisitedDeletion(const GURL& url); | 263 void OnUndoMostVisitedDeletion(const GURL& url); |
| 268 void OnUndoAllMostVisitedDeletions(); | 264 void OnUndoAllMostVisitedDeletions(); |
| 269 | 265 |
| 270 Delegate* const delegate_; | 266 Delegate* const delegate_; |
| 271 const std::string instant_url_; | 267 const std::string instant_url_; |
| 268 |
| 269 // TODO(kmadhusu): Remove |supports_instant_| from here and get the details |
| 270 // from SearchModel. Refer to crbug.com/246323 for more details. |
| 272 bool supports_instant_; | 271 bool supports_instant_; |
| 273 bool instant_support_determined_; | |
| 274 | 272 |
| 275 DISALLOW_COPY_AND_ASSIGN(InstantPage); | 273 DISALLOW_COPY_AND_ASSIGN(InstantPage); |
| 276 }; | 274 }; |
| 277 | 275 |
| 278 #endif // CHROME_BROWSER_UI_SEARCH_INSTANT_PAGE_H_ | 276 #endif // CHROME_BROWSER_UI_SEARCH_INSTANT_PAGE_H_ |
| OLD | NEW |