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

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

Issue 11824050: InstantExtended: Committed NTP (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 7 years, 10 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
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 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 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_LOADER_H_ 5 #ifndef CHROME_BROWSER_INSTANT_INSTANT_LOADER_H_
6 #define CHROME_BROWSER_INSTANT_INSTANT_LOADER_H_ 6 #define CHROME_BROWSER_INSTANT_INSTANT_LOADER_H_
7 7
8 #include <string>
9 #include <vector>
10
11 #include "base/basictypes.h" 8 #include "base/basictypes.h"
12 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
13 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
14 #include "base/string16.h" 11 #include "base/timer.h"
15 #include "chrome/browser/history/history_types.h" 12 #include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h"
16 #include "chrome/browser/instant/instant_client.h"
17 #include "content/public/browser/notification_observer.h" 13 #include "content/public/browser/notification_observer.h"
18 #include "content/public/browser/notification_registrar.h" 14 #include "content/public/browser/notification_registrar.h"
15 #include "content/public/browser/web_contents_delegate.h"
19 16
20 struct InstantAutocompleteResult; 17 class GURL;
21 class InstantController; 18 class Profile;
22 struct ThemeBackgroundInfo;
23 19
24 namespace chrome { 20 // InstantLoader is used to create and maintain a WebContents where we can
25 namespace search { 21 // preload a page into. It is used by InstantOverlay and InstantNTP to
26 struct Mode; 22 // preloading an instant page.
27 } 23 class InstantLoader : public content::NotificationObserver,
28 } 24 public content::WebContentsDelegate,
25 public CoreTabHelperDelegate {
26 public:
27 // InstantLoader calls these methods on its delegate in response to certain
28 // changes in the underlying contents.
29 class Delegate {
30 public:
31 // Called when someone else tries to swap a different contents for ours. The
32 // contents currently held is released and returned.
dhollowa 2013/01/29 02:37:53 The phrase "...is released and returned." is a bit
samarth 2013/01/29 05:42:01 Done.
33 virtual scoped_ptr<content::WebContents> ReplaceAndReleaseContents(
34 scoped_ptr<content::WebContents> new_contents) = 0;
29 35
30 namespace content { 36 // Called when the underlying contents receive focus.
31 class WebContents; 37 virtual void OnFocus() = 0;
32 }
33 38
34 namespace gfx { 39 // Called when a URL is about to be opened using the underlying contents
35 class Rect; 40 // (see WebContentsDelegate::OpenURLFromTab). If true is returned, we try to
36 } 41 // open the URL using whatever delegate is attached to the contents;
42 // otherwise, the URL is not opened.
43 virtual bool OnOpenURL() = 0;
37 44
38 // InstantLoader is used to communicate with a preview WebContents that it owns 45 // Called when the mouse pointer is down.
39 // and loads the "Instant URL" into. This preview can appear and disappear at 46 virtual void OnMouseDown() = 0;
40 // will as the user types in the omnibox (compare: InstantTab, which talks to a
41 // committed tab on the tab strip).
42 class InstantLoader : public InstantClient::Delegate,
43 public content::NotificationObserver {
44 public:
45 // Returns the Instant loader for |contents| if it's used for Instant.
46 static InstantLoader* FromWebContents(const content::WebContents* contents);
47 47
48 // Doesn't take ownership of |controller|. 48 // Called when the mouse pointer is released (or a drag event ends).
49 InstantLoader(InstantController* controller, const std::string& instant_url); 49 virtual void OnMouseUp() = 0;
50
51 protected:
52 ~Delegate();
53 };
54
55 // Does not take ownership of |delegate|.
dhollowa 2013/01/29 02:37:53 It is rare for a class to own its delegate. So th
samarth 2013/01/29 05:42:01 Oh yeah, meant to remove all of these after switch
56 explicit InstantLoader(Delegate* delegate);
50 virtual ~InstantLoader(); 57 virtual ~InstantLoader();
51 58
52 // The preview WebContents. InstantLoader retains ownership. This will be 59 // Loads |instant_url| in a new WebContents in context of |profile|. Uses
53 // non-NULL after InitFromContents(), and until ReleaseContents() is called. 60 // |active_contents|, if non-NULL, to intialize the size of the new contents.
61 // Any existing contents held will be deleted. |on_stale_callback| will be
62 // called after the designated amount of time has elapsed.
63 void Load(const GURL& instant_url,
64 Profile* profile,
65 const content::WebContents* active_contents,
66 const base::Closure& on_stale_callback);
67
68 // Returns the contents currently held. May be NULL.
54 content::WebContents* contents() const { return contents_.get(); } 69 content::WebContents* contents() const { return contents_.get(); }
55 70
56 // Creates a new WebContents and loads |instant_url_| into it. |active_tab| is 71 // Replaces the contents held with |contents|. Any existing contents is
57 // the page the preview will be shown on top of and potentially replace. 72 // deleted. The expiration timer is not restarted.
58 void InitContents(const content::WebContents* active_tab); 73 void SetContents(scoped_ptr<content::WebContents> contents);
59 74
60 // Releases the preview WebContents passing ownership to the caller. This 75 // Releases the contents currently held. Must only be called if contents() is
61 // should be called when the preview is committed. 76 // not NULL.
62 content::WebContents* ReleaseContents() WARN_UNUSED_RESULT; 77 scoped_ptr<content::WebContents> ReleaseContents() WARN_UNUSED_RESULT;
63
64 // Returns the URL that we're loading.
65 const std::string& instant_url() const { return instant_url_; }
66
67 // Returns true if the preview is known to support the Instant API. This
68 // starts out false, and becomes true whenever we get any message from the
69 // page. Once true, it never becomes false (the page isn't expected to drop
70 // Instant API support suddenly).
71 bool supports_instant() const { return supports_instant_; }
72
73 // Returns true if the mouse or a touch pointer is down due to activating the
74 // preview contents.
75 bool is_pointer_down_from_activate() const {
76 return is_pointer_down_from_activate_;
77 }
78
79 // Returns info about the last navigation by the Instant page. If the page
80 // hasn't navigated since the last Update(), the URL is empty.
81 const history::HistoryAddPageArgs& last_navigation() const {
82 return last_navigation_;
83 }
84
85 // Called by the history tab helper with information that it would have added
86 // to the history service had this WebContents not been used for Instant.
87 void DidNavigate(const history::HistoryAddPageArgs& add_page_args);
88
89 // Returns true if the loader is using
90 // InstantController::kLocalOmniboxPopupURL as the |instant_url_|.
91 bool IsUsingLocalPreview() const;
92
93 // Calls through to methods of the same name on InstantClient.
94 void Update(const string16& text,
95 size_t selection_start,
96 size_t selection_end,
97 bool verbatim);
98 void Submit(const string16& text);
99 void Cancel(const string16& text);
100 void SetPopupBounds(const gfx::Rect& bounds);
101 void SetMarginSize(int start, int end);
102 void SendAutocompleteResults(
103 const std::vector<InstantAutocompleteResult>& results);
104 void UpOrDownKeyPressed(int count);
105 void SearchModeChanged(const chrome::search::Mode& mode);
106 void SendThemeBackgroundInfo(const ThemeBackgroundInfo& theme_info);
107 void SendThemeAreaHeight(int height);
108 void SetDisplayInstantResults(bool display_instant_results);
109 void KeyCaptureChanged(bool is_key_capture_enabled);
110 78
111 private: 79 private:
112 class WebContentsDelegateImpl;
113
114 // Overridden from InstantClient::Delegate:
115 virtual void SetSuggestions(
116 const std::vector<InstantSuggestion>& suggestions) OVERRIDE;
117 virtual void InstantSupportDetermined(bool supports_instant) OVERRIDE;
118 virtual void ShowInstantPreview(InstantShownReason reason,
119 int height,
120 InstantSizeUnits units) OVERRIDE;
121 virtual void StartCapturingKeyStrokes() OVERRIDE;
122 virtual void StopCapturingKeyStrokes() OVERRIDE;
123 virtual void RenderViewGone() OVERRIDE;
124 virtual void AboutToNavigateMainFrame(const GURL& url) OVERRIDE;
125 virtual void NavigateToURL(const GURL& url,
126 content::PageTransition transition) OVERRIDE;
127
128 // Overridden from content::NotificationObserver: 80 // Overridden from content::NotificationObserver:
129 virtual void Observe(int type, 81 virtual void Observe(int type,
130 const content::NotificationSource& source, 82 const content::NotificationSource& source,
131 const content::NotificationDetails& details) OVERRIDE; 83 const content::NotificationDetails& details) OVERRIDE;
132 84
133 void SetupPreviewContents(); 85 // Overridden from CoreTabHelperDelegate:
134 void CleanupPreviewContents(); 86 virtual void SwapTabContents(content::WebContents* old_contents,
135 void ReplacePreviewContents(content::WebContents* old_contents, 87 content::WebContents* new_contents) OVERRIDE;
136 content::WebContents* new_contents);
137 88
138 InstantClient client_; 89 // Overridden from content::WebContentsDelegate:
139 InstantController* const controller_; 90 virtual bool ShouldSuppressDialogs() OVERRIDE;
91 virtual bool ShouldFocusPageAfterCrash() OVERRIDE;
92 virtual void LostCapture() OVERRIDE;
93 virtual void WebContentsFocused(content::WebContents* contents) OVERRIDE;
94 virtual bool CanDownload(content::RenderViewHost* render_view_host,
95 int request_id,
96 const std::string& request_method) OVERRIDE;
97 virtual void HandleMouseDown() OVERRIDE;
98 virtual void HandleMouseUp() OVERRIDE;
99 virtual void HandlePointerActivate() OVERRIDE;
100 virtual void HandleGestureEnd() OVERRIDE;
101 virtual void DragEnded() OVERRIDE;
102 virtual bool OnGoToEntryOffset(int offset) OVERRIDE;
103 virtual content::WebContents* OpenURLFromTab(
104 content::WebContents* source,
105 const content::OpenURLParams& params) OVERRIDE;
140 106
141 // Delegate of the preview WebContents. Used when the user does some gesture 107 Delegate* const delegate_;
142 // on the preview and it needs to be activated.
143 scoped_ptr<WebContentsDelegateImpl> delegate_;
144 scoped_ptr<content::WebContents> contents_; 108 scoped_ptr<content::WebContents> contents_;
145 109
146 const std::string instant_url_; 110 // Used to mark when the page is stale.
147 bool supports_instant_; 111 base::Timer stale_page_timer_;
148 bool is_pointer_down_from_activate_;
149 history::HistoryAddPageArgs last_navigation_;
150 112
151 // Used to get notifications about renderers coming and going. 113 // Used to get notifications about renderers.
152 content::NotificationRegistrar registrar_; 114 content::NotificationRegistrar registrar_;
153 115
154 DISALLOW_COPY_AND_ASSIGN(InstantLoader); 116 DISALLOW_COPY_AND_ASSIGN(InstantLoader);
155 }; 117 };
156 118
157 #endif // CHROME_BROWSER_INSTANT_INSTANT_LOADER_H_ 119 #endif // CHROME_BROWSER_INSTANT_INSTANT_LOADER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698