OLD | NEW |
(Empty) | |
| 1 // Copyright 2012 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 #include <vector> |
| 10 |
| 11 #include "base/basictypes.h" |
| 12 #include "base/compiler_specific.h" |
| 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/string16.h" |
| 15 #include "chrome/browser/history/history_types.h" |
| 16 #include "chrome/browser/instant/instant_loader.h" |
| 17 #include "chrome/browser/instant/instant_page.h" |
| 18 |
| 19 struct InstantAutocompleteResult; |
| 20 class InstantController; |
| 21 class Profile; |
| 22 struct ThemeBackgroundInfo; |
| 23 |
| 24 namespace chrome { |
| 25 namespace search { |
| 26 struct Mode; |
| 27 } |
| 28 } |
| 29 |
| 30 namespace content { |
| 31 class WebContents; |
| 32 } |
| 33 |
| 34 // InstantOverlay is used to communicate with a preview WebContents that it owns |
| 35 // and loads the "Instant URL" into. This preview can appear and disappear at |
| 36 // will as the user types in the omnibox (compare: InstantTab, which talks to a |
| 37 // committed tab on the tab strip). |
| 38 class InstantOverlay : public InstantPage, |
| 39 public InstantLoader::Delegate { |
| 40 public: |
| 41 // Returns the InstantOverlay for |contents| if it's used for Instant. |
| 42 static InstantOverlay* FromWebContents(const content::WebContents* contents); |
| 43 |
| 44 // Doesn't take ownership of |controller|. |
| 45 InstantOverlay(InstantController* controller, const std::string& instant_url); |
| 46 virtual ~InstantOverlay(); |
| 47 |
| 48 // Creates a new WebContents and loads |instant_url_| into it. Uses |
| 49 // |active_tab|, if non-NULL, to initialize the size of the WebContents. |
| 50 void InitContents(Profile* profile, |
| 51 const content::WebContents* active_tab); |
| 52 |
| 53 // Overriden from InstantPage. |
| 54 virtual content::WebContents* contents() const OVERRIDE { |
| 55 return loader_->contents(); |
| 56 } |
| 57 |
| 58 // Releases the overlay WebContents passing ownership to the caller. This |
| 59 // should be called when the overlay is committed. |
| 60 content::WebContents* ReleaseContents() WARN_UNUSED_RESULT; |
| 61 |
| 62 // Returns the URL that we're loading. |
| 63 const std::string& instant_url() const { return instant_url_; } |
| 64 |
| 65 // Returns whether the underlying contents is stale (i.e. was loaded too long |
| 66 // ago). |
| 67 bool is_stale() const { return is_stale_; } |
| 68 |
| 69 // Returns true if the mouse or a touch pointer is down due to activating the |
| 70 // preview contents. |
| 71 bool is_pointer_down_from_activate() const { |
| 72 return is_pointer_down_from_activate_; |
| 73 } |
| 74 |
| 75 // Returns info about the last navigation by the Instant page. If the page |
| 76 // hasn't navigated since the last Update(), the URL is empty. |
| 77 const history::HistoryAddPageArgs& last_navigation() const { |
| 78 return last_navigation_; |
| 79 } |
| 80 |
| 81 // Called by the history tab helper with information that it would have added |
| 82 // to the history service had this WebContents not been used for Instant. |
| 83 void DidNavigate(const history::HistoryAddPageArgs& add_page_args); |
| 84 |
| 85 // Returns true if the overlay is using |
| 86 // InstantController::kLocalOmniboxPopupURL as the |instant_url_|. |
| 87 bool IsUsingLocalPreview() const; |
| 88 |
| 89 private: |
| 90 // Overriden from InstantLoader::Delegate. |
| 91 virtual content::WebContents* ReplaceAndReleaseContents( |
| 92 content::WebContents* new_contents) OVERRIDE; |
| 93 virtual void OnFocus() OVERRIDE; |
| 94 virtual bool OnOpenURL() OVERRIDE; |
| 95 virtual void SetPointerDown() OVERRIDE; |
| 96 virtual void MaybeCommitFromPointerRelease() OVERRIDE; |
| 97 virtual void OnStalePage() OVERRIDE; |
| 98 |
| 99 // Overridden from InstantAPIWrapper::Controller. |
| 100 virtual void OnUpdate() OVERRIDE; |
| 101 virtual bool OnRenderViewGone() const OVERRIDE; |
| 102 virtual bool OnAboutToNavigateMainFrame() const OVERRIDE; |
| 103 virtual bool OnSetSuggestions() const OVERRIDE; |
| 104 virtual bool OnShowInstantPreview() const OVERRIDE; |
| 105 virtual bool OnStartCapturingKeyStrokes() const OVERRIDE; |
| 106 virtual bool OnStopCapturingKeyStrokes() const OVERRIDE; |
| 107 virtual bool OnNavigateToURL() const OVERRIDE; |
| 108 |
| 109 scoped_ptr<InstantLoader> loader_; |
| 110 const std::string instant_url_; |
| 111 bool is_stale_; |
| 112 bool is_pointer_down_from_activate_; |
| 113 history::HistoryAddPageArgs last_navigation_; |
| 114 |
| 115 DISALLOW_COPY_AND_ASSIGN(InstantOverlay); |
| 116 }; |
| 117 |
| 118 #endif // CHROME_BROWSER_INSTANT_INSTANT_OVERLAY_H_ |
OLD | NEW |