Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(258)

Side by Side Diff: chrome/browser/instant/instant_overlay.h

Issue 12386019: Instant: Use only one hidden WebContents per profile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_INSTANT_INSTANT_OVERLAY_H_ 5 #ifndef CHROME_BROWSER_INSTANT_INSTANT_OVERLAY_H_
6 #define CHROME_BROWSER_INSTANT_INSTANT_OVERLAY_H_ 6 #define CHROME_BROWSER_INSTANT_INSTANT_OVERLAY_H_
7 7
8 #include <string>
9
10 #include "base/basictypes.h" 8 #include "base/basictypes.h"
11 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
12 #include "base/gtest_prod_util.h"
13 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
14 #include "chrome/browser/history/history_types.h" 11 #include "chrome/browser/instant/instant_web_contents_container.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 12
19 class Profile; 13 class InstantController;
14 class InstantPage;
15 class InstantService;
20 16
21 namespace content { 17 namespace content {
22 class WebContents; 18 class WebContents;
23 } 19 }
24 20
25 // InstantOverlay is used to communicate with an overlay WebContents that it 21 // InstantOverlay represents an overlay WebContents that shows a preview of
26 // owns and loads the "Instant URL" into. This overlay can appear and disappear 22 // search results. This overlay can appear and disappear at will as the user
27 // at will as the user types in the omnibox. 23 // types into the omnibox. It may be "committed" (merged into a tab).
28 class InstantOverlay : public InstantPage, 24 class InstantOverlay : public InstantWebContentsContainer {
29 public InstantLoader::Delegate {
30 public: 25 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, 26 InstantOverlay(InstantController* controller,
35 const std::string& instant_url); 27 InstantService* service,
28 scoped_ptr<content::WebContents> contents);
36 virtual ~InstantOverlay(); 29 virtual ~InstantOverlay();
37 30
38 // Creates a new WebContents and loads |instant_url_| into it. Uses 31 InstantPage* page() { return &page_; }
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 32
43 // Releases the overlay WebContents. This should be called when the overlay 33 // Releases the overlay WebContents. This should be called when the overlay
44 // is committed. 34 // is committed.
45 scoped_ptr<content::WebContents> ReleaseContents() WARN_UNUSED_RESULT; 35 scoped_ptr<content::WebContents> ReleaseContents();
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 36
54 // Returns true if the mouse or a touch pointer is down due to activating the 37 // Returns true if the mouse or a touch pointer is down due to activating the
55 // overlay contents. 38 // overlay contents.
56 bool is_pointer_down_from_activate() const { 39 bool is_pointer_down_from_activate() const {
57 return is_pointer_down_from_activate_; 40 return is_pointer_down_from_activate_;
58 } 41 }
59 42
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 IsUsingLocalOverlay() 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: 43 private:
81 FRIEND_TEST_ALL_PREFIXES(InstantTest, InstantOverlayRefresh); 44 // Overridden from InstantWebContentsContainer:
82 45 virtual void SwapTabContents(content::WebContents* old_contents,
83 // Helper to access delegate() as an InstantController object. 46 content::WebContents* new_contents) OVERRIDE;
84 InstantController* instant_controller() const {
85 return static_cast<InstantController*>(delegate());
86 }
87
88 // Overridden from InstantPage:
89 virtual bool ShouldProcessRenderViewCreated() OVERRIDE;
90 virtual bool ShouldProcessRenderViewGone() OVERRIDE;
91 virtual bool ShouldProcessAboutToNavigateMainFrame() OVERRIDE;
92 virtual bool ShouldProcessSetSuggestions() OVERRIDE;
93 virtual bool ShouldProcessShowInstantOverlay() OVERRIDE;
94 virtual bool ShouldProcessNavigateToURL() OVERRIDE;
95
96 // Overriden from InstantLoader::Delegate:
97 virtual void OnSwappedContents() OVERRIDE;
98 virtual void OnFocus() OVERRIDE;
99 virtual void OnMouseDown() OVERRIDE;
100 virtual void OnMouseUp() OVERRIDE;
101 virtual content::WebContents* OpenURLFromTab( 47 virtual content::WebContents* OpenURLFromTab(
102 content::WebContents* source, 48 content::WebContents* source,
103 const content::OpenURLParams& params) OVERRIDE; 49 const content::OpenURLParams& params) OVERRIDE;
50 virtual void CloseContents(content::WebContents* source) OVERRIDE;
51 virtual void LostCapture() OVERRIDE;
52 virtual void WebContentsFocused(content::WebContents* contents) OVERRIDE;
53 virtual void HandleMouseDown() OVERRIDE;
54 virtual void HandleMouseUp() OVERRIDE;
55 virtual void HandlePointerActivate() OVERRIDE;
56 virtual void HandleGestureEnd() OVERRIDE;
57 virtual void DragEnded() OVERRIDE;
104 58
105 // Called when the underlying page becomes stale. 59 InstantController* const controller_;
106 void HandleStalePage();
107
108 InstantLoader loader_;
109 const std::string instant_url_;
110 bool is_stale_;
111 bool is_pointer_down_from_activate_; 60 bool is_pointer_down_from_activate_;
112 history::HistoryAddPageArgs last_navigation_;
113 61
114 DISALLOW_COPY_AND_ASSIGN(InstantOverlay); 62 DISALLOW_COPY_AND_ASSIGN(InstantOverlay);
115 }; 63 };
116 64
117 #endif // CHROME_BROWSER_INSTANT_INSTANT_OVERLAY_H_ 65 #endif // CHROME_BROWSER_INSTANT_INSTANT_OVERLAY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698