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

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, 11 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"
16 #include "chrome/browser/instant/instant_client.h"
17 #include "content/public/browser/notification_observer.h" 12 #include "content/public/browser/notification_observer.h"
18 #include "content/public/browser/notification_registrar.h" 13 #include "content/public/browser/notification_registrar.h"
19 14
20 struct InstantAutocompleteResult; 15 class GURL;
21 class InstantController; 16 class Profile;
22 struct ThemeBackgroundInfo;
23
24 namespace chrome {
25 namespace search {
26 struct Mode;
27 }
28 }
29 17
30 namespace content { 18 namespace content {
31 class WebContents; 19 class WebContents;
32 } 20 }
33 21
34 namespace gfx { 22 // InstantLoader is used to create and maintain a WebContents where we can
35 class Rect; 23 // preload a page into. It is used by InstantOverlay and InstantNTP to
36 } 24 // preloading an instant page.
25 class InstantLoader : public content::NotificationObserver {
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.
33 virtual content::WebContents* ReplaceAndReleaseContents(
dhollowa 2013/01/22 22:34:58 Return type should be scoped_ptr<content::WebConte
samarth 2013/01/25 21:08:40 Done.
34 content::WebContents* new_contents) = 0;
37 35
38 // InstantLoader is used to communicate with a preview WebContents that it owns 36 // Called when the underlying contents receive focus.
39 // and loads the "Instant URL" into. This preview can appear and disappear at 37 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 38
48 // Doesn't take ownership of |controller|. 39 // Called when a URL is about to be opened using the underlying contents
49 InstantLoader(InstantController* controller, const std::string& instant_url); 40 // (see WebContentsDelegate::OpenURLFromTab). If true is returned, we try to
41 // open the URL using whatever delegate is attached to the contents;
42 // otherwise, the URL is not opened.
43 virtual bool OnOpenURL() = 0;
44
45 // Called when the mouse pointer is down.
46 virtual void OnPointerDown() = 0;
dhollowa 2013/01/22 22:34:58 How about the terms "mouse down" / "mouse up"? Or
samarth 2013/01/25 21:08:40 Done.
47
48 // Called when the mouse pointer is released (or a drag event ends).
49 virtual void OnPointerRelease() = 0;
50
51 // Called when the specified amount of time has passed since the page was
52 // loaded.
53 virtual void OnStalePage() = 0;
54
55 protected:
56 ~Delegate();
57 };
58
59 // Does not take ownership of |delegate|.
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 // OnStalePage() will be called on the delegate after |expirationDurationMS|.
66 // Any existing contents held will be deleted.
67 void Load(const GURL& instant_url,
68 Profile* profile,
69 const content::WebContents* active_contents,
70 int expirationDurationMS);
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(content::WebContents* contents);
dhollowa 2013/01/22 22:34:58 arg: scoped_ptr<WebContents> contents
samarth 2013/01/25 21:08:40 Done.
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 content::WebContents* ReleaseContents() WARN_UNUSED_RESULT;
63 82
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
111 private: 83 private:
112 class WebContentsDelegateImpl; 84 class WebContentsDelegateImpl;
113 85
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: 86 // Overridden from content::NotificationObserver:
129 virtual void Observe(int type, 87 virtual void Observe(int type,
130 const content::NotificationSource& source, 88 const content::NotificationSource& source,
131 const content::NotificationDetails& details) OVERRIDE; 89 const content::NotificationDetails& details) OVERRIDE;
132 90
133 void SetupPreviewContents(); 91 Delegate* const delegate_;
134 void CleanupPreviewContents(); 92 scoped_ptr<content::WebContents> contents_;
135 void ReplacePreviewContents(content::WebContents* old_contents, 93 scoped_ptr<WebContentsDelegateImpl> contents_delegate_;
dhollowa 2013/01/22 22:34:58 Can this be a direct data member instead of a scop
samarth 2013/01/25 21:08:40 Got rid of this entirely and just folded it into I
136 content::WebContents* new_contents);
137 94
138 InstantClient client_; 95 // Used to mark when the page is stale.
139 InstantController* const controller_; 96 base::OneShotTimer<InstantLoader::Delegate> stale_page_timer_;
140 97
141 // Delegate of the preview WebContents. Used when the user does some gesture 98 // Used to get notifications about renderers.
142 // on the preview and it needs to be activated.
143 scoped_ptr<WebContentsDelegateImpl> delegate_;
144 scoped_ptr<content::WebContents> contents_;
145
146 const std::string instant_url_;
147 bool supports_instant_;
148 bool is_pointer_down_from_activate_;
149 history::HistoryAddPageArgs last_navigation_;
150
151 // Used to get notifications about renderers coming and going.
152 content::NotificationRegistrar registrar_; 99 content::NotificationRegistrar registrar_;
153 100
154 DISALLOW_COPY_AND_ASSIGN(InstantLoader); 101 DISALLOW_COPY_AND_ASSIGN(InstantLoader);
155 }; 102 };
156 103
157 #endif // CHROME_BROWSER_INSTANT_INSTANT_LOADER_H_ 104 #endif // CHROME_BROWSER_INSTANT_INSTANT_LOADER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698