Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | |
|
dhollowa
2013/01/22 22:34:58
nit: 2013
samarth
2013/01/25 21:08:40
Done.
| |
| 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_loader.h" | |
| 16 #include "chrome/browser/instant/instant_page.h" | |
| 17 | |
| 18 class Profile; | |
| 19 | |
| 20 // InstantOverlay is used to communicate with a preview WebContents that it owns | |
| 21 // and loads the "Instant URL" into. This preview can appear and disappear at | |
| 22 // will as the user types in the omnibox. | |
| 23 class InstantOverlay : public InstantPage, | |
| 24 public InstantLoader::Delegate { | |
| 25 public: | |
| 26 // Returns the InstantOverlay for |contents| if it's used for Instant. | |
| 27 static InstantOverlay* FromWebContents(const content::WebContents* contents); | |
| 28 | |
| 29 // Doesn't take ownership of |delegate|. | |
| 30 InstantOverlay(InstantPage::Delegate* delegate, | |
| 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 passing ownership to the caller. This | |
| 40 // should be called when the overlay is committed. | |
| 41 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 // Overriden from InstantLoader::Delegate. | |
| 78 virtual content::WebContents* ReplaceAndReleaseContents( | |
| 79 content::WebContents* new_contents) OVERRIDE; | |
| 80 virtual void OnFocus() OVERRIDE; | |
| 81 virtual bool OnOpenURL() OVERRIDE; | |
| 82 virtual void OnPointerDown() OVERRIDE; | |
| 83 virtual void OnPointerRelease() OVERRIDE; | |
| 84 virtual void OnStalePage() OVERRIDE; | |
| 85 | |
| 86 scoped_ptr<InstantLoader> loader_; | |
|
dhollowa
2013/01/22 22:34:58
Can this be a direct data member?
samarth
2013/01/25 21:08:40
It couldn't before because of the forward-declared
| |
| 87 const std::string instant_url_; | |
| 88 bool is_stale_; | |
| 89 bool is_pointer_down_from_activate_; | |
| 90 history::HistoryAddPageArgs last_navigation_; | |
| 91 | |
| 92 DISALLOW_COPY_AND_ASSIGN(InstantOverlay); | |
| 93 }; | |
| 94 | |
| 95 #endif // CHROME_BROWSER_INSTANT_INSTANT_OVERLAY_H_ | |
| OLD | NEW |