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