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

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

Issue 10539064: TabContentsWrapper -> TabContents, part 18. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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
« no previous file with comments | « chrome/browser/instant/instant_delegate.h ('k') | chrome/browser/instant/instant_loader.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/string16.h" 14 #include "base/string16.h"
15 #include "base/timer.h" 15 #include "base/timer.h"
16 #include "chrome/browser/instant/instant_commit_type.h" 16 #include "chrome/browser/instant/instant_commit_type.h"
17 #include "chrome/browser/search_engines/template_url_id.h" 17 #include "chrome/browser/search_engines/template_url_id.h"
18 #include "chrome/common/instant_types.h" 18 #include "chrome/common/instant_types.h"
19 #include "content/public/browser/notification_observer.h" 19 #include "content/public/browser/notification_observer.h"
20 #include "content/public/browser/notification_registrar.h" 20 #include "content/public/browser/notification_registrar.h"
21 #include "content/public/common/page_transition_types.h" 21 #include "content/public/common/page_transition_types.h"
22 #include "googleurl/src/gurl.h" 22 #include "googleurl/src/gurl.h"
23 #include "ui/gfx/rect.h" 23 #include "ui/gfx/rect.h"
24 24
25 class InstantLoaderDelegate; 25 class InstantLoaderDelegate;
26 class InstantLoaderManagerTest; 26 class InstantLoaderManagerTest;
27 class TabContents; 27 class TabContents;
28 typedef TabContents TabContentsWrapper;
29 class TemplateURL; 28 class TemplateURL;
30 29
31 namespace content { 30 namespace content {
32 class SessionStorageNamespace; 31 class SessionStorageNamespace;
33 } 32 }
34 33
35 // InstantLoader does the loading of a particular URL for InstantController. 34 // InstantLoader does the loading of a particular URL for InstantController.
36 // InstantLoader notifies its delegate, which is typically InstantController, of 35 // InstantLoader notifies its delegate, which is typically InstantController, of
37 // all interesting events. 36 // all interesting events.
38 // 37 //
39 // InstantLoader is created with a TemplateURLID. If non-zero InstantLoader 38 // InstantLoader is created with a TemplateURLID. If non-zero InstantLoader
40 // first determines if the site actually supports instant. If it doesn't, the 39 // first determines if the site actually supports instant. If it doesn't, the
41 // delegate is notified by way of |InstantLoaderDoesntSupportInstant|. 40 // delegate is notified by way of |InstantLoaderDoesntSupportInstant|.
42 // 41 //
43 // If the TemplateURLID supplied to the constructor is zero, then the url is 42 // If the TemplateURLID supplied to the constructor is zero, then the url is
44 // loaded as is. 43 // loaded as is.
45 class InstantLoader : public content::NotificationObserver { 44 class InstantLoader : public content::NotificationObserver {
46 public: 45 public:
47 // Header and value set on loads that originate from instant. 46 // Header and value set on loads that originate from instant.
48 static const char* const kInstantHeader; 47 static const char* const kInstantHeader;
49 static const char* const kInstantHeaderValue; 48 static const char* const kInstantHeaderValue;
50 49
51 // |group| is an identifier suffixed to histograms to distinguish field trial 50 // |group| is an identifier suffixed to histograms to distinguish field trial
52 // statistics from regular operation; can be a blank string. 51 // statistics from regular operation; can be a blank string.
53 InstantLoader(InstantLoaderDelegate* delegate, 52 InstantLoader(InstantLoaderDelegate* delegate,
54 TemplateURLID id, 53 TemplateURLID id,
55 const std::string& group); 54 const std::string& group);
56 virtual ~InstantLoader(); 55 virtual ~InstantLoader();
57 56
58 // Invoked to load a URL. |tab_contents| is the TabContentsWrapper the preview 57 // Invoked to load a URL. |tab_contents| is the TabContents the preview
59 // is going to be shown on top of and potentially replace. Returns true if the 58 // is going to be shown on top of and potentially replace. Returns true if the
60 // arguments differ from the last call to |Update|. 59 // arguments differ from the last call to |Update|.
61 bool Update(TabContentsWrapper* tab_contents, 60 bool Update(TabContents* tab_contents,
62 const TemplateURL* template_url, 61 const TemplateURL* template_url,
63 const GURL& url, 62 const GURL& url,
64 content::PageTransition transition_type, 63 content::PageTransition transition_type,
65 const string16& user_text, 64 const string16& user_text,
66 bool verbatim, 65 bool verbatim,
67 string16* suggested_text); 66 string16* suggested_text);
68 67
69 // Sets the bounds of the omnibox (in screen coordinates). The bounds are 68 // Sets the bounds of the omnibox (in screen coordinates). The bounds are
70 // remembered until the preview is committed or destroyed. This is only used 69 // remembered until the preview is committed or destroyed. This is only used
71 // when showing results for a search provider that supports instant. 70 // when showing results for a search provider that supports instant.
72 void SetOmniboxBounds(const gfx::Rect& bounds); 71 void SetOmniboxBounds(const gfx::Rect& bounds);
73 72
74 // Returns true if the mouse is down as the result of activating the preview 73 // Returns true if the mouse is down as the result of activating the preview
75 // content. 74 // content.
76 bool IsMouseDownFromActivate(); 75 bool IsMouseDownFromActivate();
77 76
78 // Releases the preview TabContentsWrapper passing ownership to the caller. 77 // Releases the preview TabContents passing ownership to the caller.
79 // This is intended to be called when the preview TabContentsWrapper is 78 // This is intended to be called when the preview TabContents is
80 // committed. This does not notify the delegate. |tab_contents| is the 79 // committed. This does not notify the delegate. |tab_contents| is the
81 // underlying tab onto which the preview will be committed. It can be NULL 80 // underlying tab onto which the preview will be committed. It can be NULL
82 // when the underlying tab is irrelevant, for example when |type| is 81 // when the underlying tab is irrelevant, for example when |type| is
83 // INSTANT_COMMIT_DESTROY. 82 // INSTANT_COMMIT_DESTROY.
84 TabContentsWrapper* ReleasePreviewContents(InstantCommitType type, 83 TabContents* ReleasePreviewContents(InstantCommitType type,
85 TabContentsWrapper* tab_contents); 84 TabContents* tab_contents);
86 85
87 // Calls through to method of same name on delegate. 86 // Calls through to method of same name on delegate.
88 bool ShouldCommitInstantOnMouseUp(); 87 bool ShouldCommitInstantOnMouseUp();
89 void CommitInstantLoader(); 88 void CommitInstantLoader();
90 89
91 // Preload |template_url|'s instant URL, if the loader doesn't already have 90 // Preload |template_url|'s instant URL, if the loader doesn't already have
92 // a |preview_contents()| for it. 91 // a |preview_contents()| for it.
93 void MaybeLoadInstantURL(TabContentsWrapper* tab_contents, 92 void MaybeLoadInstantURL(TabContents* tab_contents,
94 const TemplateURL* template_url); 93 const TemplateURL* template_url);
95 94
96 // Returns true if the preview NavigationController's WebContents has a 95 // Returns true if the preview NavigationController's WebContents has a
97 // pending NavigationEntry. 96 // pending NavigationEntry.
98 bool IsNavigationPending() const; 97 bool IsNavigationPending() const;
99 98
100 // content::NotificationObserver: 99 // content::NotificationObserver:
101 virtual void Observe(int type, 100 virtual void Observe(int type,
102 const content::NotificationSource& source, 101 const content::NotificationSource& source,
103 const content::NotificationDetails& details) OVERRIDE; 102 const content::NotificationDetails& details) OVERRIDE;
104 103
105 // The preview TabContentsWrapper; may be null. 104 // The preview TabContents; may be null.
106 TabContentsWrapper* preview_contents() const { 105 TabContents* preview_contents() const {
107 return preview_contents_.get(); 106 return preview_contents_.get();
108 } 107 }
109 108
110 // Returns true if the preview TabContentsWrapper is ready to be shown. A 109 // Returns true if the preview TabContents is ready to be shown. A
111 // non-instant loader is ready once the renderer paints, otherwise it isn't 110 // non-instant loader is ready once the renderer paints, otherwise it isn't
112 // ready until we get a response back from the page. 111 // ready until we get a response back from the page.
113 bool ready() const { return ready_; } 112 bool ready() const { return ready_; }
114 113
115 // Returns true if the current load returned a 200. 114 // Returns true if the current load returned a 200.
116 bool http_status_ok() const { return http_status_ok_; } 115 bool http_status_ok() const { return http_status_ok_; }
117 116
118 // Returns true if the url needs to be reloaded. This is set to true for 117 // Returns true if the url needs to be reloaded. This is set to true for
119 // downloads. 118 // downloads.
120 bool needs_reload() const { return needs_reload_; } 119 bool needs_reload() const { return needs_reload_; }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 void PageDoesntSupportInstant(bool needs_reload); 173 void PageDoesntSupportInstant(bool needs_reload);
175 174
176 // Invokes |SetBoundsToPage(false)|. This is called from the timer. 175 // Invokes |SetBoundsToPage(false)|. This is called from the timer.
177 void ProcessBoundsChange(); 176 void ProcessBoundsChange();
178 177
179 // Notifes the page of the omnibox bounds. If |force_if_loading| is true the 178 // Notifes the page of the omnibox bounds. If |force_if_loading| is true the
180 // bounds are sent down even if we're waiting on the load, otherwise if we're 179 // bounds are sent down even if we're waiting on the load, otherwise if we're
181 // waiting on the load and |force_if_loading| is false this does nothing. 180 // waiting on the load and |force_if_loading| is false this does nothing.
182 void SendBoundsToPage(bool force_if_loading); 181 void SendBoundsToPage(bool force_if_loading);
183 182
184 // Called when the TabContentsDelegate wants to swap a new TabContentsWrapper 183 // Called when the TabContentsDelegate wants to swap a new TabContents
185 // into our |preview_contents_|. 184 // into our |preview_contents_|.
186 void ReplacePreviewContents(TabContentsWrapper* old_tc, 185 void ReplacePreviewContents(TabContents* old_tc,
187 TabContentsWrapper* new_tc); 186 TabContents* new_tc);
188 187
189 // Called to set up the |preview_contents_| based on |tab_contents| when it is 188 // Called to set up the |preview_contents_| based on |tab_contents| when it is
190 // created or replaced. 189 // created or replaced.
191 void SetupPreviewContents(TabContentsWrapper* tab_contents); 190 void SetupPreviewContents(TabContents* tab_contents);
192 191
193 // Creates and sets the preview TabContentsWrapper. 192 // Creates and sets the preview TabContents.
194 void CreatePreviewContents(TabContentsWrapper* tab_contents); 193 void CreatePreviewContents(TabContents* tab_contents);
195 194
196 // Creates and loads the |template_url|'s instant URL. 195 // Creates and loads the |template_url|'s instant URL.
197 void LoadInstantURL(const TemplateURL* template_url, 196 void LoadInstantURL(const TemplateURL* template_url,
198 content::PageTransition transition_type, 197 content::PageTransition transition_type,
199 const string16& user_text, 198 const string16& user_text,
200 bool verbatim); 199 bool verbatim);
201 200
202 InstantLoaderDelegate* delegate_; 201 InstantLoaderDelegate* delegate_;
203 202
204 // If we're showing instant results this is the ID of the TemplateURL driving 203 // If we're showing instant results this is the ID of the TemplateURL driving
205 // the results. A value of 0 means there is no TemplateURL. 204 // the results. A value of 0 means there is no TemplateURL.
206 const TemplateURLID template_url_id_; 205 const TemplateURLID template_url_id_;
207 206
208 // The url we're displaying. 207 // The url we're displaying.
209 GURL url_; 208 GURL url_;
210 209
211 // Delegate of the preview WebContents. Used to detect when the user does some 210 // Delegate of the preview WebContents. Used to detect when the user does some
212 // gesture on the WebContents and the preview needs to be activated. 211 // gesture on the WebContents and the preview needs to be activated.
213 scoped_ptr<TabContentsDelegateImpl> preview_tab_contents_delegate_; 212 scoped_ptr<TabContentsDelegateImpl> preview_tab_contents_delegate_;
214 213
215 // The preview TabContentsWrapper; may be null. 214 // The preview TabContents; may be null.
216 scoped_ptr<TabContentsWrapper> preview_contents_; 215 scoped_ptr<TabContents> preview_contents_;
217 216
218 // Is the preview_contents ready to be shown? 217 // Is the preview_contents ready to be shown?
219 bool ready_; 218 bool ready_;
220 219
221 // Was the last status code a 200? 220 // Was the last status code a 200?
222 bool http_status_ok_; 221 bool http_status_ok_;
223 222
224 // The text the user typed in the omnibox, stripped of the leading ?, if any. 223 // The text the user typed in the omnibox, stripped of the leading ?, if any.
225 string16 user_text_; 224 string16 user_text_;
226 225
(...skipping 30 matching lines...) Expand all
257 std::string group_; 256 std::string group_;
258 257
259 // The session storage namespace identifier of the original tab contents that 258 // The session storage namespace identifier of the original tab contents that
260 // the preview_contents_ was based upon. 259 // the preview_contents_ was based upon.
261 scoped_refptr<content::SessionStorageNamespace> session_storage_namespace_; 260 scoped_refptr<content::SessionStorageNamespace> session_storage_namespace_;
262 261
263 DISALLOW_COPY_AND_ASSIGN(InstantLoader); 262 DISALLOW_COPY_AND_ASSIGN(InstantLoader);
264 }; 263 };
265 264
266 #endif // CHROME_BROWSER_INSTANT_INSTANT_LOADER_H_ 265 #endif // CHROME_BROWSER_INSTANT_INSTANT_LOADER_H_
OLDNEW
« no previous file with comments | « chrome/browser/instant/instant_delegate.h ('k') | chrome/browser/instant/instant_loader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698