| 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 "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" | 11 #include "chrome/browser/ui/search/search_model_observer.h" |
| 12 #include "content/public/browser/web_contents_observer.h" | 12 #include "content/public/browser/web_contents_observer.h" |
| 13 #include "ui/base/page_transition_types.h" | 13 #include "ui/base/page_transition_types.h" |
| 14 | 14 |
| 15 class GURL; | 15 class GURL; |
| 16 | 16 |
| 17 namespace content { | 17 namespace content { |
| 18 class RenderFrameHost; | 18 class RenderFrameHost; |
| 19 class WebContents; | 19 class WebContents; |
| 20 } | 20 } |
| 21 | 21 |
| 22 // InstantPage is used to exchange messages with a page that implements the | 22 // InstantPage is used to exchange messages with a page that implements the |
| 23 // Instant/Embedded Search API (http://dev.chromium.org/embeddedsearch). | 23 // Instant/Embedded Search API (http://dev.chromium.org/embeddedsearch). |
| 24 // InstantPage is not used directly but via its derived class, InstantTab. | |
| 25 class InstantPage : public content::WebContentsObserver, | 24 class InstantPage : public content::WebContentsObserver, |
| 26 public SearchModelObserver { | 25 public SearchModelObserver { |
| 27 public: | 26 public: |
| 28 // InstantPage calls its delegate in response to messages received from the | 27 // InstantPage calls its delegate in response to messages received from the |
| 29 // page. Each method is called with the |contents| corresponding to the page | 28 // page. Each method is called with the |contents| corresponding to the page |
| 30 // we are observing. | 29 // we are observing. |
| 31 class Delegate { | 30 class Delegate { |
| 32 public: | 31 public: |
| 33 // Called upon determination of Instant API support. Either in response to | 32 // Called upon determination of Instant API support. Either in response to |
| 34 // the page loading or because we received some other message. | 33 // the page loading or because we received some other message. |
| 35 virtual void InstantSupportDetermined(const content::WebContents* contents, | 34 virtual void InstantSupportDetermined(const content::WebContents* contents, |
| 36 bool supports_instant) = 0; | 35 bool supports_instant) = 0; |
| 37 | 36 |
| 38 // Called when the page is about to navigate to |url|. | 37 // Called when the page is about to navigate to |url|. |
| 39 virtual void InstantPageAboutToNavigateMainFrame( | 38 virtual void InstantPageAboutToNavigateMainFrame( |
| 40 const content::WebContents* contents, | 39 const content::WebContents* contents, |
| 41 const GURL& url) = 0; | 40 const GURL& url) = 0; |
| 42 | 41 |
| 43 protected: | 42 protected: |
| 44 virtual ~Delegate(); | 43 virtual ~Delegate(); |
| 45 }; | 44 }; |
| 46 | 45 |
| 46 explicit InstantPage(Delegate* delegate); |
| 47 |
| 47 ~InstantPage() override; | 48 ~InstantPage() override; |
| 48 | 49 |
| 50 // Sets |web_contents| as the page to communicate with. |web_contents| may be |
| 51 // NULL, which effectively stops all communication. |
| 52 void Init(content::WebContents* web_contents); |
| 53 |
| 49 // Returns true if the page is known to support the Instant API. This starts | 54 // Returns true if the page is known to support the Instant API. This starts |
| 50 // out false, and is set to true whenever we get any message from the page. | 55 // out false, and is set to true whenever we get any message from the page. |
| 51 // Once true, it never becomes false (the page isn't expected to drop API | 56 // Once true, it never becomes false (the page isn't expected to drop API |
| 52 // support suddenly). | 57 // support suddenly). |
| 53 bool supports_instant() const; | 58 bool supports_instant() const; |
| 54 | 59 |
| 55 // Returns true if the page is the local NTP (i.e. its URL is | 60 // Returns true if the page is the local NTP (i.e. its URL is |
| 56 // chrome::kChromeSearchLocalNTPURL). | 61 // chrome::kChromeSearchLocalNTPURL). |
| 57 bool IsLocal() const; | 62 bool IsLocal() const; |
| 58 | 63 |
| 59 protected: | |
| 60 explicit InstantPage(Delegate* delegate); | |
| 61 | |
| 62 // Sets |web_contents| as the page to communicate with. |web_contents| may be | |
| 63 // NULL, which effectively stops all communication. | |
| 64 void SetContents(content::WebContents* web_contents); | |
| 65 | |
| 66 Delegate* delegate() const { return delegate_; } | |
| 67 | |
| 68 // This method is called before processing messages received from the page. | |
| 69 virtual bool ShouldProcessAboutToNavigateMainFrame(); | |
| 70 | |
| 71 private: | 64 private: |
| 72 FRIEND_TEST_ALL_PREFIXES(InstantPageTest, IsLocal); | 65 FRIEND_TEST_ALL_PREFIXES(InstantPageTest, IsLocal); |
| 73 FRIEND_TEST_ALL_PREFIXES(InstantPageTest, | 66 FRIEND_TEST_ALL_PREFIXES(InstantPageTest, |
| 74 DetermineIfPageSupportsInstant_Local); | 67 DetermineIfPageSupportsInstant_Local); |
| 75 FRIEND_TEST_ALL_PREFIXES(InstantPageTest, | 68 FRIEND_TEST_ALL_PREFIXES(InstantPageTest, |
| 76 DetermineIfPageSupportsInstant_NonLocal); | 69 DetermineIfPageSupportsInstant_NonLocal); |
| 77 FRIEND_TEST_ALL_PREFIXES(InstantPageTest, | 70 FRIEND_TEST_ALL_PREFIXES(InstantPageTest, |
| 78 PageURLDoesntBelongToInstantRenderer); | 71 PageURLDoesntBelongToInstantRenderer); |
| 79 FRIEND_TEST_ALL_PREFIXES(InstantPageTest, PageSupportsInstant); | 72 FRIEND_TEST_ALL_PREFIXES(InstantPageTest, PageSupportsInstant); |
| 80 | 73 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 92 void InstantSupportDetermined(bool supports_instant); | 85 void InstantSupportDetermined(bool supports_instant); |
| 93 | 86 |
| 94 void ClearContents(); | 87 void ClearContents(); |
| 95 | 88 |
| 96 Delegate* const delegate_; | 89 Delegate* const delegate_; |
| 97 | 90 |
| 98 DISALLOW_COPY_AND_ASSIGN(InstantPage); | 91 DISALLOW_COPY_AND_ASSIGN(InstantPage); |
| 99 }; | 92 }; |
| 100 | 93 |
| 101 #endif // CHROME_BROWSER_UI_SEARCH_INSTANT_PAGE_H_ | 94 #endif // CHROME_BROWSER_UI_SEARCH_INSTANT_PAGE_H_ |
| OLD | NEW |