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

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"
9 #include "base/callback.h"
12 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
13 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
14 #include "base/string16.h" 12 #include "base/timer.h"
15 #include "chrome/browser/history/history_types.h" 13 #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" 14 #include "content/public/browser/notification_observer.h"
18 #include "content/public/browser/notification_registrar.h" 15 #include "content/public/browser/notification_registrar.h"
16 #include "content/public/browser/web_contents_delegate.h"
19 17
20 struct InstantAutocompleteResult; 18 class GURL;
21 class InstantController; 19 class Profile;
22 struct ThemeBackgroundInfo;
23
24 namespace chrome {
25 namespace search {
26 struct Mode;
27 }
28 }
29 20
30 namespace content { 21 namespace content {
sreeram 2013/02/01 20:36:53 Add a forward declaration for content::OpenURLPara
samarth 2013/02/04 20:43:32 Done.
31 class WebContents; 22 class WebContents;
32 } 23 }
33 24
34 namespace gfx { 25 // InstantLoader is used to create and maintain a WebContents where we can
35 class Rect; 26 // preload a page into. It is used by InstantOverlay and InstantNTP to
36 } 27 // preloading an instant page.
sreeram 2013/02/01 20:36:53 preloading -> preload instant -> Instant
samarth 2013/02/04 20:43:32 Done.
28 class InstantLoader : public content::NotificationObserver,
29 public content::WebContentsDelegate,
30 public CoreTabHelperDelegate {
31 public:
32 // InstantLoader calls these methods on its delegate in response to certain
33 // changes in the underlying contents.
34 class Delegate {
35 public:
36 // Called after someone has swapped in a different WebContents for ours.
37 virtual void OnSwappedContents() = 0;
37 38
38 // InstantLoader is used to communicate with a preview WebContents that it owns 39 // Called when the underlying contents receive focus.
39 // and loads the "Instant URL" into. This preview can appear and disappear at 40 virtual void OnFocus() = 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 41
48 // Doesn't take ownership of |controller|. 42 // Called when the mouse pointer is down.
49 InstantLoader(InstantController* controller, const std::string& instant_url); 43 virtual void OnMouseDown() = 0;
44
45 // Called when the mouse pointer is released (or a drag event ends).
46 virtual void OnMouseUp() = 0;
47
48 // Called to open a URL using the underlying contents (see
49 // WebContentsDelegate::OpenURLFromTab). The Delegate should return the
50 // WebContents the URL is opened in, or NULL if the URL wasn't opened
51 // immediately.
52 virtual content::WebContents* OpenURLFromTab(
53 content::WebContents* source,
54 const content::OpenURLParams& params) = 0;
55
56 protected:
57 ~Delegate();
58 };
59
60 explicit InstantLoader(Delegate* delegate);
50 virtual ~InstantLoader(); 61 virtual ~InstantLoader();
51 62
52 // The preview WebContents. InstantLoader retains ownership. This will be 63 // Loads |instant_url| in a new WebContents in context of |profile|. Uses
53 // non-NULL after InitFromContents(), and until ReleaseContents() is called. 64 // |active_contents|, if non-NULL, to intialize the size of the new contents.
65 // Any existing contents held will be deleted. |on_stale_callback| will be
66 // called after the designated amount of time has elapsed.
sreeram 2013/02/01 20:36:53 The "designated amount of time" is mildly confusin
samarth 2013/02/04 20:43:32 Done. (Left out "without any activity" since that
67 void Load(const GURL& instant_url,
68 Profile* profile,
69 const content::WebContents* active_contents,
70 const base::Closure& on_stale_callback);
71
72 // Returns the contents currently held. May be NULL.
54 content::WebContents* contents() const { return contents_.get(); } 73 content::WebContents* contents() const { return contents_.get(); }
55 74
56 // Creates a new WebContents and loads |instant_url_| into it. |active_tab| is 75 // Replaces the contents held with |contents|. Any existing contents is
57 // the page the preview will be shown on top of and potentially replace. 76 // deleted. The expiration timer is not restarted.
58 void InitContents(const content::WebContents* active_tab); 77 void SetContents(scoped_ptr<content::WebContents> contents);
59 78
60 // Releases the preview WebContents passing ownership to the caller. This 79 // Releases the contents currently held. Must only be called if contents() is
61 // should be called when the preview is committed. 80 // not NULL.
62 content::WebContents* ReleaseContents() WARN_UNUSED_RESULT; 81 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 82
111 private: 83 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: 84 // Overridden from content::NotificationObserver:
129 virtual void Observe(int type, 85 virtual void Observe(int type,
130 const content::NotificationSource& source, 86 const content::NotificationSource& source,
131 const content::NotificationDetails& details) OVERRIDE; 87 const content::NotificationDetails& details) OVERRIDE;
132 88
133 void SetupPreviewContents(); 89 // Overridden from CoreTabHelperDelegate:
134 void CleanupPreviewContents(); 90 virtual void SwapTabContents(content::WebContents* old_contents,
135 void ReplacePreviewContents(content::WebContents* old_contents, 91 content::WebContents* new_contents) OVERRIDE;
136 content::WebContents* new_contents);
137 92
138 InstantClient client_; 93 // Overridden from content::WebContentsDelegate:
139 InstantController* const controller_; 94 virtual bool ShouldSuppressDialogs() OVERRIDE;
95 virtual bool ShouldFocusPageAfterCrash() OVERRIDE;
96 virtual void LostCapture() OVERRIDE;
97 virtual void WebContentsFocused(content::WebContents* contents) OVERRIDE;
98 virtual bool CanDownload(content::RenderViewHost* render_view_host,
99 int request_id,
100 const std::string& request_method) OVERRIDE;
101 virtual void HandleMouseDown() OVERRIDE;
102 virtual void HandleMouseUp() OVERRIDE;
103 virtual void HandlePointerActivate() OVERRIDE;
104 virtual void HandleGestureEnd() OVERRIDE;
105 virtual void DragEnded() OVERRIDE;
106 virtual bool OnGoToEntryOffset(int offset) OVERRIDE;
107 virtual content::WebContents* OpenURLFromTab(
108 content::WebContents* source,
109 const content::OpenURLParams& params) OVERRIDE;
140 110
141 // Delegate of the preview WebContents. Used when the user does some gesture 111 Delegate* const delegate_;
142 // on the preview and it needs to be activated.
143 scoped_ptr<WebContentsDelegateImpl> delegate_;
144 scoped_ptr<content::WebContents> contents_; 112 scoped_ptr<content::WebContents> contents_;
145 113
146 const std::string instant_url_; 114 // Used to mark when the page is stale.
147 bool supports_instant_; 115 base::Timer stale_page_timer_;
148 bool is_pointer_down_from_activate_;
149 history::HistoryAddPageArgs last_navigation_;
150 116
151 // Used to get notifications about renderers coming and going. 117 // Used to get notifications about renderers.
152 content::NotificationRegistrar registrar_; 118 content::NotificationRegistrar registrar_;
153 119
154 DISALLOW_COPY_AND_ASSIGN(InstantLoader); 120 DISALLOW_COPY_AND_ASSIGN(InstantLoader);
155 }; 121 };
156 122
157 #endif // CHROME_BROWSER_INSTANT_INSTANT_LOADER_H_ 123 #endif // CHROME_BROWSER_INSTANT_INSTANT_LOADER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698