| 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_TAB_H_ | 5 #ifndef CHROME_BROWSER_UI_SEARCH_INSTANT_TAB_H_ |
| 6 #define CHROME_BROWSER_UI_SEARCH_INSTANT_TAB_H_ | 6 #define CHROME_BROWSER_UI_SEARCH_INSTANT_TAB_H_ |
| 7 | 7 |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/gtest_prod_util.h" | 9 #include "base/gtest_prod_util.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "chrome/browser/ui/search/search_model_observer.h" | |
| 12 #include "content/public/browser/web_contents_observer.h" | 11 #include "content/public/browser/web_contents_observer.h" |
| 13 #include "ui/base/page_transition_types.h" | |
| 14 | 12 |
| 15 class GURL; | 13 class GURL; |
| 16 | 14 |
| 17 namespace content { | 15 namespace content { |
| 18 class WebContents; | 16 class WebContents; |
| 19 } | 17 } |
| 20 | 18 |
| 21 // InstantTab is used to exchange messages with a page that implements the | 19 // InstantTab is used to exchange messages with a page that implements the |
| 22 // Instant/Embedded Search API (http://dev.chromium.org/embeddedsearch). | 20 // Instant/Embedded Search API (http://dev.chromium.org/embeddedsearch). |
| 23 class InstantTab : public content::WebContentsObserver, | 21 class InstantTab : public content::WebContentsObserver { |
| 24 public SearchModelObserver { | |
| 25 public: | 22 public: |
| 26 // InstantTab calls its delegate in response to messages received from the | 23 // InstantTab calls its delegate in response to messages received from the |
| 27 // page. Each method is called with the |contents| corresponding to the page | 24 // page. Each method is called with the |contents| corresponding to the page |
| 28 // we are observing. | 25 // we are observing. |
| 29 class Delegate { | 26 class Delegate { |
| 30 public: | 27 public: |
| 31 // Called upon determination of Instant API support. Either in response to | |
| 32 // the page loading or because we received some other message. | |
| 33 virtual void InstantSupportDetermined(const content::WebContents* contents, | |
| 34 bool supports_instant) = 0; | |
| 35 | |
| 36 // Called when the page is about to navigate to |url|. | 28 // Called when the page is about to navigate to |url|. |
| 37 virtual void InstantTabAboutToNavigateMainFrame( | 29 virtual void InstantTabAboutToNavigateMainFrame( |
| 38 const content::WebContents* contents, | 30 const content::WebContents* contents, |
| 39 const GURL& url) = 0; | 31 const GURL& url) = 0; |
| 40 | 32 |
| 41 protected: | 33 protected: |
| 42 virtual ~Delegate(); | 34 virtual ~Delegate(); |
| 43 }; | 35 }; |
| 44 | 36 |
| 45 explicit InstantTab(Delegate* delegate, content::WebContents* web_contents); | 37 InstantTab(Delegate* delegate, content::WebContents* web_contents); |
| 46 | |
| 47 ~InstantTab() override; | 38 ~InstantTab() override; |
| 48 | 39 |
| 49 // Sets up communication with the WebContents passed to the constructor. Does | 40 // Sets up communication with the WebContents passed to the constructor. Does |
| 50 // nothing if that WebContents was null. Should not be called more than once. | 41 // nothing if that WebContents was null. Should not be called more than once. |
| 51 void Init(); | 42 void Init(); |
| 52 | 43 |
| 53 private: | 44 private: |
| 54 // Overridden from content::WebContentsObserver: | 45 // Overridden from content::WebContentsObserver: |
| 55 void DidFinishNavigation( | 46 void DidFinishNavigation( |
| 56 content::NavigationHandle* navigation_handle) override; | 47 content::NavigationHandle* navigation_handle) override; |
| 57 | 48 |
| 58 // Overridden from SearchModelObserver: | |
| 59 void ModelChanged(const SearchModel::State& old_state, | |
| 60 const SearchModel::State& new_state) override; | |
| 61 | |
| 62 void InstantSupportDetermined(bool supports_instant); | |
| 63 | |
| 64 Delegate* const delegate_; | 49 Delegate* const delegate_; |
| 65 | 50 |
| 66 content::WebContents* pending_web_contents_; | 51 content::WebContents* pending_web_contents_; |
| 67 | 52 |
| 68 DISALLOW_COPY_AND_ASSIGN(InstantTab); | 53 DISALLOW_COPY_AND_ASSIGN(InstantTab); |
| 69 }; | 54 }; |
| 70 | 55 |
| 71 #endif // CHROME_BROWSER_UI_SEARCH_INSTANT_TAB_H_ | 56 #endif // CHROME_BROWSER_UI_SEARCH_INSTANT_TAB_H_ |
| OLD | NEW |