OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_INSTANT_INSTANT_OVERLAY_H_ |
| 6 #define CHROME_BROWSER_INSTANT_INSTANT_OVERLAY_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/basictypes.h" |
| 11 #include "base/compiler_specific.h" |
| 12 #include "base/gtest_prod_util.h" |
| 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "chrome/browser/history/history_types.h" |
| 15 #include "chrome/browser/instant/instant_controller.h" |
| 16 #include "chrome/browser/instant/instant_loader.h" |
| 17 #include "chrome/browser/instant/instant_page.h" |
| 18 |
| 19 class Profile; |
| 20 |
| 21 namespace content { |
| 22 class WebContents; |
| 23 } |
| 24 |
| 25 // InstantOverlay is used to communicate with a preview WebContents that it owns |
| 26 // and loads the "Instant URL" into. This preview can appear and disappear at |
| 27 // will as the user types in the omnibox. |
| 28 class InstantOverlay : public InstantPage, |
| 29 public InstantLoader::Delegate { |
| 30 public: |
| 31 // Returns the InstantOverlay for |contents| if it's used for Instant. |
| 32 static InstantOverlay* FromWebContents(const content::WebContents* contents); |
| 33 |
| 34 InstantOverlay(InstantController* controller, |
| 35 const std::string& instant_url); |
| 36 virtual ~InstantOverlay(); |
| 37 |
| 38 // Creates a new WebContents and loads |instant_url_| into it. Uses |
| 39 // |active_tab|, if non-NULL, to initialize the size of the WebContents. |
| 40 void InitContents(Profile* profile, |
| 41 const content::WebContents* active_tab); |
| 42 |
| 43 // Releases the overlay WebContents. This should be called when the overlay |
| 44 // is committed. |
| 45 scoped_ptr<content::WebContents> ReleaseContents() WARN_UNUSED_RESULT; |
| 46 |
| 47 // Returns the URL that we're loading. |
| 48 const std::string& instant_url() const { return instant_url_; } |
| 49 |
| 50 // Returns whether the underlying contents is stale (i.e. was loaded too long |
| 51 // ago). |
| 52 bool is_stale() const { return is_stale_; } |
| 53 |
| 54 // Returns true if the mouse or a touch pointer is down due to activating the |
| 55 // preview contents. |
| 56 bool is_pointer_down_from_activate() const { |
| 57 return is_pointer_down_from_activate_; |
| 58 } |
| 59 |
| 60 // Returns info about the last navigation by the Instant page. If the page |
| 61 // hasn't navigated since the last Update(), the URL is empty. |
| 62 const history::HistoryAddPageArgs& last_navigation() const { |
| 63 return last_navigation_; |
| 64 } |
| 65 |
| 66 // Called by the history tab helper with information that it would have added |
| 67 // to the history service had this WebContents not been used for Instant. |
| 68 void DidNavigate(const history::HistoryAddPageArgs& add_page_args); |
| 69 |
| 70 // Returns true if the overlay is using |
| 71 // InstantController::kLocalOmniboxPopupURL as the |instant_url_|. |
| 72 bool IsUsingLocalPreview() const; |
| 73 |
| 74 // Overridden from InstantPage: |
| 75 virtual void Update(const string16& text, |
| 76 size_t selection_start, |
| 77 size_t selection_end, |
| 78 bool verbatim) OVERRIDE; |
| 79 |
| 80 private: |
| 81 FRIEND_TEST_ALL_PREFIXES(InstantTest, InstantOverlayRefresh); |
| 82 |
| 83 // Helper to access delegate() as an InstantController object. |
| 84 InstantController* instant_controller() const { |
| 85 return static_cast<InstantController*>(delegate()); |
| 86 } |
| 87 |
| 88 // Overriden from InstantLoader::Delegate: |
| 89 virtual void OnSwappedContents() OVERRIDE; |
| 90 virtual void OnFocus() OVERRIDE; |
| 91 virtual void OnMouseDown() OVERRIDE; |
| 92 virtual void OnMouseUp() OVERRIDE; |
| 93 virtual content::WebContents* OpenURLFromTab( |
| 94 content::WebContents* source, |
| 95 const content::OpenURLParams& params) OVERRIDE; |
| 96 |
| 97 // Called when the underlying page becomes stale. |
| 98 void HandleStalePage(); |
| 99 |
| 100 InstantLoader loader_; |
| 101 const std::string instant_url_; |
| 102 bool is_stale_; |
| 103 bool is_pointer_down_from_activate_; |
| 104 history::HistoryAddPageArgs last_navigation_; |
| 105 |
| 106 DISALLOW_COPY_AND_ASSIGN(InstantOverlay); |
| 107 }; |
| 108 |
| 109 #endif // CHROME_BROWSER_INSTANT_INSTANT_OVERLAY_H_ |
OLD | NEW |