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

Side by Side Diff: chrome/browser/tab_contents.h

Issue 5005: Reorganize the declarations to have some grouping and logical ordering in tab... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 2 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/render_view_host_delegate.h ('k') | chrome/browser/tab_contents.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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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_TAB_CONTENTS_H_ 5 #ifndef CHROME_BROWSER_TAB_CONTENTS_H_
6 #define CHROME_BROWSER_TAB_CONTENTS_H_ 6 #define CHROME_BROWSER_TAB_CONTENTS_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "chrome/browser/autocomplete/autocomplete_edit.h" 11 #include "chrome/browser/autocomplete/autocomplete_edit.h"
12 #include "chrome/browser/constrained_window.h" 12 #include "chrome/browser/constrained_window.h"
13 #include "chrome/browser/navigation_controller.h" 13 #include "chrome/browser/navigation_controller.h"
14 #include "chrome/browser/page_navigator.h" 14 #include "chrome/browser/page_navigator.h"
15 #include "chrome/browser/tab_contents_type.h" 15 #include "chrome/browser/tab_contents_type.h"
16 #include "chrome/common/navigation_types.h" 16 #include "chrome/common/navigation_types.h"
17 #include "chrome/common/text_zoom.h" 17 #include "chrome/common/text_zoom.h"
18 18
19 namespace gfx { 19 namespace gfx {
20 class Rect; 20 class Rect;
21 class Size; 21 class Size;
22 } 22 }
23 23
24 class DOMUIHost; 24 class DOMUIHost;
25 class DownloadItem; 25 class DownloadItem;
26 class DownloadShelfView; 26 class DownloadShelfView;
27 class InfoBarView; 27 class InfoBarView;
28 class LoadNotificationDetails; 28 class LoadNotificationDetails;
29 class Profile; 29 class Profile;
30 class TabContentsDelegate; 30 class TabContentsDelegate;
31 class TabContentsFactory; 31 class TabContentsFactory;
(...skipping 11 matching lines...) Expand all
43 // Once they reside within a NavigationController, TabContents objects are 43 // Once they reside within a NavigationController, TabContents objects are
44 // owned by that NavigationController. When the active TabContents within that 44 // owned by that NavigationController. When the active TabContents within that
45 // NavigationController is closed, that TabContents destroys the 45 // NavigationController is closed, that TabContents destroys the
46 // NavigationController, which then destroys all of the TabContentses in it. 46 // NavigationController, which then destroys all of the TabContentses in it.
47 // 47 //
48 // NOTE: When the NavigationController is navigated to an URL corresponding to 48 // NOTE: When the NavigationController is navigated to an URL corresponding to
49 // a different type of TabContents (see the TabContents::TypeForURL method), 49 // a different type of TabContents (see the TabContents::TypeForURL method),
50 // the NavigationController makes the active TabContents inactive, notifies the 50 // the NavigationController makes the active TabContents inactive, notifies the
51 // TabContentsDelegate that the TabContents is being replaced, and then 51 // TabContentsDelegate that the TabContents is being replaced, and then
52 // activates the new TabContents. 52 // activates the new TabContents.
53 //
54 class TabContents : public PageNavigator, 53 class TabContents : public PageNavigator,
55 public ConstrainedTabContentsDelegate, 54 public ConstrainedTabContentsDelegate {
56 public NotificationObserver {
57 // Used to access the child_windows_ (ConstrainedWindowList) for testing
58 // automation purposes.
59 friend class AutomationProvider;
60
61 public: 55 public:
62 // Flags passed to the TabContentsDelegate.NavigationStateChanged to tell it 56 // Flags passed to the TabContentsDelegate.NavigationStateChanged to tell it
63 // what has changed. Combine them to update more than one thing. 57 // what has changed. Combine them to update more than one thing.
64 enum InvalidateTypes { 58 enum InvalidateTypes {
65 INVALIDATE_URL = 1, // The URL has changed. 59 INVALIDATE_URL = 1, // The URL has changed.
66 INVALIDATE_TITLE = 2, // The title has changed. 60 INVALIDATE_TITLE = 2, // The title has changed.
67 INVALIDATE_FAVICON = 4, // The favicon has changed. 61 INVALIDATE_FAVICON = 4, // The favicon has changed.
68 INVALIDATE_LOAD = 8, // The loading state has changed 62 INVALIDATE_LOAD = 8, // The loading state has changed
69 63
70 // Helper for forcing a refresh. 64 // Helper for forcing a refresh.
71 INVALIDATE_EVERYTHING = 0xFFFFFFFF 65 INVALIDATE_EVERYTHING = 0xFFFFFFFF
72 }; 66 };
73 67
68 static void RegisterUserPrefs(PrefService* prefs);
69
70 // Factory -------------------------------------------------------------------
71 // (implemented in tab_contents_factory.cc)
72
74 // Creates a new TabContents of the given type. Will reuse the given 73 // Creates a new TabContents of the given type. Will reuse the given
75 // instance's renderer, if it is not null. 74 // instance's renderer, if it is not null.
76 static TabContents* CreateWithType(TabContentsType type, 75 static TabContents* CreateWithType(TabContentsType type,
77 HWND parent, 76 HWND parent,
78 Profile* profile, 77 Profile* profile,
79 SiteInstance* instance); 78 SiteInstance* instance);
80 79
81 // Returns the type of TabContents needed to handle the URL. |url| may 80 // Returns the type of TabContents needed to handle the URL. |url| may
82 // end up being modified to contain the _real_ url being loaded if the 81 // end up being modified to contain the _real_ url being loaded if the
83 // parameter was an alias (such as about: urls and chrome- urls). 82 // parameter was an alias (such as about: urls and chrome- urls).
84 static TabContentsType TypeForURL(GURL* url); 83 static TabContentsType TypeForURL(GURL* url);
85 84
86 // This method can be used to register a new TabContents type dynamically, 85 // This method can be used to register a new TabContents type dynamically,
87 // which can be very useful for unit testing. If factory is null, then the 86 // which can be very useful for unit testing. If factory is null, then the
88 // tab contents type is unregistered. Returns the previously registered 87 // tab contents type is unregistered. Returns the previously registered
89 // factory for the given type or null if there was none. 88 // factory for the given type or null if there was none.
90 static TabContentsFactory* RegisterFactory(TabContentsType type, 89 static TabContentsFactory* RegisterFactory(TabContentsType type,
91 TabContentsFactory* factory); 90 TabContentsFactory* factory);
92 91
93 // Tell the subclass to set up the view (e.g. create the container HWND if 92 // Creation & destruction ----------------------------------------------------
94 // applicable) and any other create-time setup.
95 virtual void CreateView(HWND parent_hwnd, const gfx::Rect& initial_bounds) {}
96 93
97 // Returns the HWND associated with this TabContents. Outside of automation 94 // Request this tab to shut down. This kills the tab's NavigationController,
98 // in the context of the UI, this is required to be implemented. 95 // which then Destroy()s all tabs it controls.
99 virtual HWND GetContainerHWND() const { return NULL; } 96 void CloseContents();
100 97
101 // Returns the bounds of this TabContents in the screen coordinate system. 98 // Unregister/shut down any pending tasks involving this tab.
102 virtual void GetContainerBounds(gfx::Rect *out) const { 99 // This is called as the tab is shutting down, before the
103 out->SetRect(0, 0, 0, 0); 100 // NavigationController (and consequently profile) are gone.
104 } 101 //
102 // If you override this, be sure to call this implementation at the end
103 // of yours.
104 // See also Close().
105 virtual void Destroy();
105 106
106 // Show, Hide and Size the TabContents. 107 // Intrinsic tab state -------------------------------------------------------
107 // TODO(beng): (Cleanup) Show/Size TabContents should be made to actually
108 // show and size the View. For simplicity sake, for now they're
109 // just empty. This is currently a bit of a mess and is just a
110 // band-aid.
111 virtual void ShowContents() {}
112 virtual void HideContents();
113 virtual void SizeContents(const gfx::Size& size) {}
114 108
109 // Returns the type of tab this is. See also the As* functions following.
115 TabContentsType type() const { return type_; } 110 TabContentsType type() const { return type_; }
116 111
117 // Returns this object as a WebContents if it is one, and NULL otherwise. 112 // Returns this object as a WebContents if it is one, and NULL otherwise.
118 virtual WebContents* AsWebContents() { return NULL; } 113 virtual WebContents* AsWebContents() { return NULL; }
119 114
120 // Const version of above for situations where const TabContents*'s are used. 115 // Const version of above for situations where const TabContents*'s are used.
121 WebContents* AsWebContents() const { 116 WebContents* AsWebContents() const {
122 return const_cast<TabContents*>(this)->AsWebContents(); 117 return const_cast<TabContents*>(this)->AsWebContents();
123 } 118 }
124 119
125 // Returns this object as a DOMUIHost if it is one, and NULL otherwise. 120 // Returns this object as a DOMUIHost if it is one, and NULL otherwise.
126 virtual DOMUIHost* AsDOMUIHost() { return NULL ; } 121 virtual DOMUIHost* AsDOMUIHost() { return NULL; }
127
128 // The max PageID of any page that this TabContents has loaded. PageIDs
129 // increase with each new page that is loaded by a tab. If this is a
130 // WebContents, then the max PageID is kept separately on each SiteInstance.
131 // Returns -1 if no PageIDs have yet been seen.
132 int32 GetMaxPageID();
133
134 // Updates the max PageID to be at least the given PageID.
135 void UpdateMaxPageID(int32 page_id);
136
137 // Returns the site instance associated with the current page. By default,
138 // there is no site instance. WebContents overrides this to provide proper
139 // access to its site instance.
140 virtual SiteInstance* GetSiteInstance() const { return NULL; }
141
142 // Initial title assigned to NavigationEntries from Navigate.
143 virtual const std::wstring GetDefaultTitle() const;
144
145 // Defines whether the url should be displayed within the browser. If false
146 // is returned, the URL field is blank and grabs focus to invite the user
147 // to type a new url
148 virtual bool ShouldDisplayURL() { return true; }
149
150 // Returns the favicon for this tab, or an isNull() bitmap if the tab does not
151 // have a favicon. The default implementation uses the current navigation
152 // entry.
153 virtual SkBitmap GetFavIcon() const;
154
155 // Returns whether the favicon should be displayed. If this returns false, no
156 // space is provided for the favicon, and the favicon is never displayed.
157 virtual bool ShouldDisplayFavIcon() {
158 return true;
159 }
160 122
161 TabContentsDelegate* delegate() const { return delegate_; } 123 TabContentsDelegate* delegate() const { return delegate_; }
162 void set_delegate(TabContentsDelegate* d) { delegate_ = d; } 124 void set_delegate(TabContentsDelegate* d) { delegate_ = d; }
163 125
164 // This can only be null if the TabContents has been created but 126 // This can only be null if the TabContents has been created but
165 // SetupController has not been called. The controller should always outlive 127 // SetupController has not been called. The controller should always outlive
166 // its TabContents. 128 // its TabContents.
167 NavigationController* controller() const { return controller_; } 129 NavigationController* controller() const { return controller_; }
168 void set_controller(NavigationController* c) { controller_ = c; } 130 void set_controller(NavigationController* c) { controller_ = c; }
169 131
170 // Sets up a new NavigationController for this TabContents. 132 // Sets up a new NavigationController for this TabContents.
171 // |profile| is the user profile that should be associated with 133 // |profile| is the user profile that should be associated with
172 // the new controller. 134 // the new controller.
173 // 135 //
174 // TODO(brettw) this seems bogus and I couldn't find any legitimate need for 136 // TODO(brettw) this seems bogus and I couldn't find any legitimate need for
175 // it. I think it should be passed in the constructor. 137 // it. I think it should be passed in the constructor.
176 void SetupController(Profile* profile); 138 void SetupController(Profile* profile);
177 139
178 // Returns the user profile associated with this TabContents (via the 140 // Returns the user profile associated with this TabContents (via the
179 // NavigationController). This will return NULL if there isn't yet a 141 // NavigationController). This will return NULL if there isn't yet a
180 // NavigationController on this TabContents. 142 // NavigationController on this TabContents.
181 // TODO(darin): make it so that controller_ can never be null 143 // TODO(darin): make it so that controller_ can never be null
182 Profile* profile() const { 144 Profile* profile() const {
183 return controller_ ? controller_->profile() : NULL; 145 return controller_ ? controller_->profile() : NULL;
184 } 146 }
185 147
186 // For use when switching tabs, these functions allow the tab contents to 148 // Returns whether this tab contents supports the provided URL. By default,
187 // hold the per-tab state of the location bar. The tab contents takes 149 // this method matches the tab contents type with the result of TypeForURL().
188 // ownership of the pointer. 150 // |url| points to the actual URL that will be used. It can be modified as
189 void set_saved_location_bar_state(const AutocompleteEditState* state) { 151 // needed.
190 saved_location_bar_state_.reset(state); 152 // Override this method if your TabContents subclass supports various URL
191 } 153 // schemes but doesn't want to be the default handler for these schemes.
192 const AutocompleteEditState* saved_location_bar_state() const { 154 // For example, the NewTabUIContents overrides this method to support
193 return saved_location_bar_state_.get(); 155 // javascript: URLs.
194 } 156 virtual bool SupportsURL(GURL* url);
157
158 // Tab navigation state ------------------------------------------------------
195 159
196 // Returns the current navigation properties, which if a navigation is 160 // Returns the current navigation properties, which if a navigation is
197 // pending may be provisional (e.g., the navigation could result in a 161 // pending may be provisional (e.g., the navigation could result in a
198 // download, in which case the URL would revert to what it was previously). 162 // download, in which case the URL would revert to what it was previously).
199 const GURL& GetURL() const; 163 const GURL& GetURL() const;
200 virtual const std::wstring& GetTitle() const; 164 virtual const std::wstring& GetTitle() const;
201 165
166 // The max PageID of any page that this TabContents has loaded. PageIDs
167 // increase with each new page that is loaded by a tab. If this is a
168 // WebContents, then the max PageID is kept separately on each SiteInstance.
169 // Returns -1 if no PageIDs have yet been seen.
170 int32 GetMaxPageID();
171
172 // Updates the max PageID to be at least the given PageID.
173 void UpdateMaxPageID(int32 page_id);
174
175 // Returns the site instance associated with the current page. By default,
176 // there is no site instance. WebContents overrides this to provide proper
177 // access to its site instance.
178 virtual SiteInstance* GetSiteInstance() const { return NULL; }
179
180 // Initial title assigned to NavigationEntries from Navigate.
181 virtual const std::wstring GetDefaultTitle() const;
182
183 // Defines whether this tab's URL should be displayed in the browser's URL
184 // bar. Normally this is true so you can see the URL. This is set to false
185 // for the new tab page and related pages so that the URL bar is empty and
186 // the user is invited to type into it.
187 virtual bool ShouldDisplayURL() { return true; }
188
189 // Returns the favicon for this tab, or an isNull() bitmap if the tab does not
190 // have a favicon. The default implementation uses the current navigation
191 // entry.
192 virtual SkBitmap GetFavIcon() const;
193
194 // Returns whether the favicon should be displayed. If this returns false, no
195 // space is provided for the favicon, and the favicon is never displayed.
196 virtual bool ShouldDisplayFavIcon() { return true; }
197
202 // SSL related states. 198 // SSL related states.
203 SecurityStyle GetSecurityStyle() const; 199 SecurityStyle GetSecurityStyle() const;
204 200
205 // Sets |ev_text| to the text that should be displayed in the EV label of 201 // Sets |ev_text| to the text that should be displayed in the EV label of
206 // the location bar and |ev_tooltip_text| to the tooltip for that label. 202 // the location bar and |ev_tooltip_text| to the tooltip for that label.
207 // Returns false and sets these strings to empty if the current page is either 203 // Returns false and sets these strings to empty if the current page is either
208 // not served over HTTPS or if HTTPS does not use an EV cert. 204 // not served over HTTPS or if HTTPS does not use an EV cert.
209 bool GetSSLEVText(std::wstring* ev_text, std::wstring* ev_tooltip_text) const; 205 bool GetSSLEVText(std::wstring* ev_text, std::wstring* ev_tooltip_text) const;
210 206
211 // Request this tab to shut down. 207 // Returns a human-readable description the tab's loading state.
212 // This kills the tab's NavigationController, which then Destroy()s all 208 virtual std::wstring GetStatusText() const { return std::wstring(); }
213 // tabs it controls.
214 void CloseContents();
215 209
216 // Unregister/shut down any pending tasks involving this tab. 210 const std::wstring& encoding() { return encoding_name_; }
217 // This is called as the tab is shutting down, before the 211 void set_encoding(const std::wstring& encoding_name) {
218 // NavigationController (and consequently profile) are gone. 212 encoding_name_ = encoding_name;
219 // 213 }
220 // If you override this, be sure to call this implementation at the end
221 // of yours.
222 // See also Close().
223 virtual void Destroy();
224
225 // Create a new window constrained to this TabContents' clip and visibility.
226 // The window is initialized by using the supplied delegate to obtain basic
227 // window characteristics, and the supplied view for the content. The window
228 // is sized according to the preferred size of the content_view, and centered
229 // within the contents.
230 ConstrainedWindow* CreateConstrainedDialog(
231 ChromeViews::WindowDelegate* window_delegate,
232 ChromeViews::View* contents_view);
233
234 // Adds a new tab or window with the given already-created contents
235 void AddNewContents(TabContents* new_contents,
236 WindowOpenDisposition disposition,
237 const gfx::Rect& initial_pos,
238 bool user_gesture);
239
240 // Builds a ConstrainedWindow* for the incoming |new_contents| and
241 // adds it to child_windows_.
242 void AddConstrainedPopup(TabContents* new_contents,
243 const gfx::Rect& initial_pos);
244
245 // An asynchronous call to trigger the string search in the page.
246 // It sends an IPC message to the Renderer that handles the string
247 // search, selecting the matches and setting the caret positions.
248 // This function also starts the asynchronous scoping effort.
249 virtual void StartFinding(int request_id,
250 const std::wstring& string,
251 bool forward, bool match_case,
252 bool find_next) { }
253
254 // An asynchronous call to stop the string search in the page. If
255 // |clear_selection| is true, it will also clear the selection on the
256 // focused frame.
257 virtual void StopFinding(bool clear_selection) { }
258
259 // Asynchronous calls to change the text zoom level.
260 virtual void AlterTextSize(text_zoom::TextSize size) { }
261
262 // Asynchronous call to turn on/off encoding auto detector.
263 virtual void SetEncodingAutoDetector(bool encoding_auto_detector) { }
264
265 // Asynchronous call to change page encoding.
266 virtual void SetPageEncoding(const std::wstring& encoding_name) { }
267 214
268 // Return whether this tab contents is loading a resource. 215 // Return whether this tab contents is loading a resource.
269 bool is_loading() const { return is_loading_; } 216 bool is_loading() const { return is_loading_; }
270 217
271 // Returns whether this tab contents is waiting for an first-response from 218 // Returns whether this tab contents is waiting for a first-response for the
272 // and external resource. 219 // main resource of the page. This controls whether the throbber state is
273 bool response_started() const { return response_started_; } 220 // "waiting" or "loading."
221 bool waiting_for_response() const { return waiting_for_response_; }
222
223 // Internal state ------------------------------------------------------------
224
225 // For use when switching tabs, these functions allow the tab contents to
226 // hold the per-tab state of the location bar. The tab contents takes
227 // ownership of the pointer.
228 void set_saved_location_bar_state(const AutocompleteEditState* state) {
229 saved_location_bar_state_.reset(state);
230 }
231 const AutocompleteEditState* saved_location_bar_state() const {
232 return saved_location_bar_state_.get();
233 }
234
235 // This flag indicates whether the tab contents is currently being
236 // screenshotted by the DraggedTabController.
237 bool capturing_contents() const { return capturing_contents_; }
238 void set_capturing_contents(bool cap) { capturing_contents_ = cap; }
239
240 // Indicates whether this tab should be considered crashed. The setter will
241 // also notify the delegate when the flag is changed.
242 bool is_crashed() const { return is_crashed_; }
243 void SetIsCrashed(bool state);
274 244
275 // Set whether this tab contents is active. A tab content is active for a 245 // Set whether this tab contents is active. A tab content is active for a
276 // given tab if it is currently being used to display some contents. Note that 246 // given tab if it is currently being used to display some contents. Note that
277 // this is different from whether a tab is selected. 247 // this is different from whether a tab is selected.
278 virtual void SetActive(bool active) { is_active_ = active; }
279 bool is_active() const { return is_active_; } 248 bool is_active() const { return is_active_; }
249 void set_is_active(bool active) { is_active_ = active; }
250
251 // Convenience method for notifying the delegate of a navigation state
252 // change. See TabContentsDelegate.
253 void NotifyNavigationStateChanged(unsigned changed_flags);
254
255 // Invoked when the tab contents becomes selected. If you override, be sure
256 // and invoke super's implementation.
257 virtual void DidBecomeSelected();
258
259 // Invoked when the tab contents becomes hidden.
260 // NOTE: If you override this, call the superclass version too!
261 virtual void WasHidden();
262
263 // Activates this contents within its containing window, bringing that window
264 // to the foreground if necessary.
265 virtual void Activate();
266
267 // Commands ------------------------------------------------------------------
268
269 // Implementation of PageNavigator.
270 virtual void OpenURL(const GURL& url,
271 WindowOpenDisposition disposition,
272 PageTransition::Type transition);
280 273
281 // Called by the NavigationController to cause the TabContents to navigate to 274 // Called by the NavigationController to cause the TabContents to navigate to
282 // the current pending entry. The NavigationController should be called back 275 // the current pending entry. The NavigationController should be called back
283 // with CommitPendingEntry/RendererDidNavigate on success or 276 // with CommitPendingEntry/RendererDidNavigate on success or
284 // DiscardPendingEntry. The callbacks can be inside of this function, or at 277 // DiscardPendingEntry. The callbacks can be inside of this function, or at
285 // some future time. 278 // some future time.
286 // 279 //
287 // The entry has a PageID of -1 if newly created (corresponding to navigation 280 // The entry has a PageID of -1 if newly created (corresponding to navigation
288 // to a new URL). 281 // to a new URL).
289 // 282 //
290 // If this method returns false, then the navigation is discarded (equivalent 283 // If this method returns false, then the navigation is discarded (equivalent
291 // to calling DiscardPendingEntry on the NavigationController). 284 // to calling DiscardPendingEntry on the NavigationController).
292 virtual bool NavigateToPendingEntry(bool reload); 285 virtual bool NavigateToPendingEntry(bool reload);
293 286
294 // Stop any pending navigation. 287 // Stop any pending navigation.
295 virtual void Stop() {} 288 virtual void Stop() {}
296 289
297 // Convenience method for notifying the delegate of a navigation state 290 // An asynchronous call to trigger the string search in the page.
298 // change. See TabContentsDelegate. 291 // It sends an IPC message to the Renderer that handles the string
299 void NotifyNavigationStateChanged(unsigned changed_flags); 292 // search, selecting the matches and setting the caret positions.
293 // This function also starts the asynchronous scoping effort.
294 virtual void StartFinding(int request_id,
295 const std::wstring& string,
296 bool forward, bool match_case,
297 bool find_next) { }
300 298
301 // Invoked when the tab contents becomes selected. If you override, be sure 299 // An asynchronous call to stop the string search in the page. If
302 // and invoke super's implementation. 300 // |clear_selection| is true, it will also clear the selection on the
303 virtual void DidBecomeSelected(); 301 // focused frame.
302 virtual void StopFinding(bool clear_selection) { }
304 303
305 // Invoked when the tab contents becomes hidden. 304 // TODO(erg): HACK ALERT! This was thrown together for beta and
306 // NOTE: If you override this, call the superclass version too! 305 // needs to be completely removed after we ship it. Right now, the
307 virtual void WasHidden(); 306 // cut/copy/paste menu items are always enabled and will send a
307 // cut/copy/paste command to the currently visible
308 // TabContents. Post-beta, this needs to be replaced with a unified
309 // interface for supporting cut/copy/paste, and managing who has
310 // cut/copy/paste focus. (http://b/1117225)
311 virtual void Cut() { }
312 virtual void Copy() { }
313 virtual void Paste() { }
308 314
309 // Activates this contents within its containing window, bringing that window 315 // Window management ---------------------------------------------------------
310 // to the foreground if necessary. 316
311 virtual void Activate(); 317 // Create a new window constrained to this TabContents' clip and visibility.
318 // The window is initialized by using the supplied delegate to obtain basic
319 // window characteristics, and the supplied view for the content. The window
320 // is sized according to the preferred size of the content_view, and centered
321 // within the contents.
322 ConstrainedWindow* CreateConstrainedDialog(
323 ChromeViews::WindowDelegate* window_delegate,
324 ChromeViews::View* contents_view);
325
326 // Adds a new tab or window with the given already-created contents
327 void AddNewContents(TabContents* new_contents,
328 WindowOpenDisposition disposition,
329 const gfx::Rect& initial_pos,
330 bool user_gesture);
331
332 // Builds a ConstrainedWindow* for the incoming |new_contents| and
333 // adds it to child_windows_.
334 void AddConstrainedPopup(TabContents* new_contents,
335 const gfx::Rect& initial_pos);
336
337 // When a tab is closed, this method is called for all the remaining tabs. If
338 // they all return false or if no tabs are left, the window is closed. The
339 // default is to return true
340 virtual bool ShouldPreventWindowClose() { return true; }
312 341
313 // Closes all constrained windows that represent web popups that have not yet 342 // Closes all constrained windows that represent web popups that have not yet
314 // been activated by the user and are as such auto-positioned in the bottom 343 // been activated by the user and are as such auto-positioned in the bottom
315 // right of the screen. This is a quick way for users to "clean up" a flurry 344 // right of the screen. This is a quick way for users to "clean up" a flurry
316 // of unwanted popups. 345 // of unwanted popups.
317 void CloseAllSuppressedPopups(); 346 void CloseAllSuppressedPopups();
318 347
319 // Displays the download shelf and animation when a download occurs. 348 // Show, Hide and Size the TabContents.
320 void OnStartDownload(DownloadItem* download); 349 // TODO(beng): (Cleanup) Show/Size TabContents should be made to actually
350 // show and size the View. For simplicity sake, for now they're
351 // just empty. This is currently a bit of a mess and is just a
352 // band-aid.
353 virtual void ShowContents() {}
354 virtual void HideContents();
355 virtual void SizeContents(const gfx::Size& size) {}
321 356
322 // ConstrainedTabContentsDelegate methods: 357 // Views and focus -----------------------------------------------------------
323 virtual void AddNewContents(ConstrainedWindow* window,
324 TabContents* contents,
325 WindowOpenDisposition disposition,
326 const gfx::Rect& initial_pos,
327 bool user_gesture);
328 virtual void OpenURL(ConstrainedWindow* window,
329 const GURL& url,
330 WindowOpenDisposition disposition,
331 PageTransition::Type transition);
332 virtual void WillClose(ConstrainedWindow* window);
333 virtual void DetachContents(ConstrainedWindow* window,
334 TabContents* contents,
335 const gfx::Rect& contents_bounds,
336 const gfx::Point& mouse_pt,
337 int frame_component);
338 virtual void DidMoveOrResize(ConstrainedWindow* window);
339 358
340 // Returns the actual window that is focused when this TabContents is shown. 359 // Returns the actual window that is focused when this TabContents is shown.
341 virtual HWND GetContentHWND() { 360 virtual HWND GetContentHWND() {
342 return GetContainerHWND(); 361 return GetContainerHWND();
343 } 362 }
344 363
345 // PageNavigator methods: 364 // Tell the subclass to set up the view (e.g. create the container HWND if
346 virtual void OpenURL(const GURL& url, 365 // applicable) and any other create-time setup.
347 WindowOpenDisposition disposition, 366 virtual void CreateView(HWND parent_hwnd, const gfx::Rect& initial_bounds) {}
348 PageTransition::Type transition);
349 367
350 // NotificationObserver implementation. 368 // Returns the HWND associated with this TabContents. Outside of automation
351 virtual void Observe(NotificationType type, 369 // in the context of the UI, this is required to be implemented.
352 const NotificationSource& source, 370 virtual HWND GetContainerHWND() const { return NULL; }
353 const NotificationDetails& details) { } 371
372 // Returns the bounds of this TabContents in the screen coordinate system.
373 virtual void GetContainerBounds(gfx::Rect *out) const {
374 out->SetRect(0, 0, 0, 0);
375 }
354 376
355 // Make the tab the focused window. 377 // Make the tab the focused window.
356 virtual void Focus(); 378 virtual void Focus();
357 379
358 // Stores the currently focused view. 380 // Stores the currently focused view.
359 virtual void StoreFocus(); 381 virtual void StoreFocus();
360 382
361 // Restores focus to the last focus view. If StoreFocus has not yet been 383 // Restores focus to the last focus view. If StoreFocus has not yet been
362 // invoked, SetInitialFocus is invoked. 384 // invoked, SetInitialFocus is invoked.
363 virtual void RestoreFocus(); 385 virtual void RestoreFocus();
364 386
365 // When a tab is closed, this method is called for all the remaining tabs. If 387 // Invoked the first time this tab is getting the focus through TAB traversal.
366 // they all return false or if no tabs are left, the window is closed. The 388 // By default this does nothing, but is overridden to set the focus for the
367 // default is to return true 389 // first element in the page.
368 virtual bool ShouldPreventWindowClose() { 390 //
369 return true; 391 // |reverse| indicates if the user is going forward or backward, so we know
370 } 392 // whether to set the first or last element focus.
371 393 //
372 // Returns the View to display at the top of the tab. 394 // See also SetInitialFocus(no arg).
373 virtual InfoBarView* GetInfoBarView() { return NULL; } 395 // FIXME(brettw) having two SetInitialFocus that do different things is silly.
374 396 virtual void SetInitialFocus(bool reverse) { }
375 // Returns whether the info bar is visible.
376 // If the visibility dynamically changes, invoke ToolbarSizeChanged
377 // on the delegate. Which forces the frame to layout if size has changed.
378 virtual bool IsInfoBarVisible() { return false; }
379 397
380 // TabContents that contain View hierarchy (such as NativeUIContents) should 398 // TabContents that contain View hierarchy (such as NativeUIContents) should
381 // return their RootView. Other TabContents (such as WebContents) should 399 // return their RootView. Other TabContents (such as WebContents) should
382 // return NULL. 400 // return NULL.
383 // This is used by the focus manager to figure out what to focus when the tab 401 // This is used by the focus manager to figure out what to focus when the tab
384 // is focused (when a tab with no view hierarchy is focused, the 402 // is focused (when a tab with no view hierarchy is focused, the
385 // TabContentsContainerView is focused) and how to process tab events. If 403 // TabContentsContainerView is focused) and how to process tab events. If
386 // this returns NULL, the TabContents is supposed to know how to process TAB 404 // this returns NULL, the TabContents is supposed to know how to process TAB
387 // key events and is just sent the key messages. If this returns a RootView, 405 // key events and is just sent the key messages. If this returns a RootView,
388 // the focus is passed to the RootView. 406 // the focus is passed to the RootView.
389 virtual ChromeViews::RootView* GetContentsRootView() { return NULL; } 407 virtual ChromeViews::RootView* GetContentsRootView() { return NULL; }
390 408
391 // Invoked the first time this tab is getting the focus through TAB traversal. 409 // Toolbars and such ---------------------------------------------------------
392 virtual void SetInitialFocus(bool reverse) { } 410
393
394 // Returns whether the bookmark bar should be visible. 411 // Returns whether the bookmark bar should be visible.
395 virtual bool IsBookmarkBarAlwaysVisible() { return false; } 412 virtual bool IsBookmarkBarAlwaysVisible() { return false; }
396 413
397 // Called before and after capturing an image of this tab contents. The tab 414 // Returns the View to display at the top of the tab.
398 // contents may be temporarily re-parented after WillCaptureContents. 415 virtual InfoBarView* GetInfoBarView() { return NULL; }
399 virtual void WillCaptureContents() {}
400 virtual void DidCaptureContents() {}
401 416
402 // Returns true if the tab is currently loading a resource. 417 // Returns whether the info bar is visible.
403 virtual bool IsLoading() const { return is_loading_; } 418 // If the visibility dynamically changes, invoke ToolbarSizeChanged
404 419 // on the delegate. Which forces the frame to layout if size has changed.
405 // Returns a human-readable description the tab's loading state. 420 virtual bool IsInfoBarVisible() { return false; }
406 virtual std::wstring GetStatusText() const { return std::wstring(); }
407
408 const std::wstring& GetEncoding() { return encoding_name_; }
409 void SetEncoding(const std::wstring& encoding_name) {
410 encoding_name_ = encoding_name;
411 }
412
413 // Changes the IsCrashed state and notifies the delegate as needed.
414 void SetIsCrashed(bool state);
415
416 // Return whether this tab should be considered crashed.
417 bool IsCrashed() const;
418
419 // Returns whether this tab contents supports the provided URL. By default,
420 // this method matches the tab contents type with the result of TypeForURL().
421 // |url| points to the actual URL that will be used. It can be modified as
422 // needed.
423 // Override this method if your TabContents subclass supports various URL
424 // schemes but doesn't want to be the default handler for these schemes.
425 // For example, the NewTabUIContents overrides this method to support
426 // javascript: URLs.
427 virtual bool SupportsURL(GURL* url);
428
429 // TODO(erg): HACK ALERT! This was thrown together for beta and
430 // needs to be completely removed after we ship it. Right now, the
431 // cut/copy/paste menu items are always enabled and will send a
432 // cut/copy/paste command to the currently visible
433 // TabContents. Post-beta, this needs to be replaced with a unified
434 // interface for supporting cut/copy/paste, and managing who has
435 // cut/copy/paste focus. (http://b/1117225)
436 virtual void Cut() { }
437 virtual void Copy() { }
438 virtual void Paste() { }
439 421
440 // Whether or not the shelf view is visible. 422 // Whether or not the shelf view is visible.
441 virtual void SetDownloadShelfVisible(bool visible); 423 virtual void SetDownloadShelfVisible(bool visible);
442 bool IsDownloadShelfVisible() { return shelf_visible_; } 424 bool IsDownloadShelfVisible() { return shelf_visible_; }
443 425
444 // Notify our delegate that some of our content has animated. 426 // Notify our delegate that some of our content has animated.
445 void ToolbarSizeChanged(bool is_animating); 427 void ToolbarSizeChanged(bool is_animating);
446 428
429 // Displays the download shelf and animation when a download occurs.
430 void OnStartDownload(DownloadItem* download);
431
447 // Returns the DownloadShelfView, creating it if necessary. 432 // Returns the DownloadShelfView, creating it if necessary.
448 DownloadShelfView* GetDownloadShelfView(); 433 DownloadShelfView* GetDownloadShelfView();
449 434
450 // Transfer the shelf view from |tab_contents| to the receiving TabContents. 435 // Transfer the shelf view from |tab_contents| to the receiving TabContents.
451 // |tab_contents| no longer owns the shelf after this call. The shelf is owned 436 // |tab_contents| no longer owns the shelf after this call. The shelf is owned
452 // by the receiving TabContents. 437 // by the receiving TabContents.
453 void MigrateShelfViewFrom(TabContents* tab_contents); 438 void MigrateShelfViewFrom(TabContents* tab_contents);
454 439
455 // Migrate the shelf view between 2 TabContents. This helper function is 440 // Migrate the shelf view between 2 TabContents. This helper function is
456 // currently called by NavigationController::DiscardPendingEntry. We may 441 // currently called by NavigationController::DiscardPendingEntry. We may
457 // want to generalize this if we need to migrate some other state. 442 // want to generalize this if we need to migrate some other state.
458 static void MigrateShelfView(TabContents* from, TabContents* to); 443 static void MigrateShelfView(TabContents* from, TabContents* to);
459 444
460 static void RegisterUserPrefs(PrefService* prefs); 445 // ConstrainedTabContentsDelegate --------------------------------------------
446
447 virtual void AddNewContents(ConstrainedWindow* window,
448 TabContents* contents,
449 WindowOpenDisposition disposition,
450 const gfx::Rect& initial_pos,
451 bool user_gesture);
452 virtual void OpenURL(ConstrainedWindow* window,
453 const GURL& url,
454 WindowOpenDisposition disposition,
455 PageTransition::Type transition);
456 virtual void WillClose(ConstrainedWindow* window);
457 virtual void DetachContents(ConstrainedWindow* window,
458 TabContents* contents,
459 const gfx::Rect& contents_bounds,
460 const gfx::Point& mouse_pt,
461 int frame_component);
462 virtual void DidMoveOrResize(ConstrainedWindow* window);
461 463
462 protected: 464 protected:
463 friend class NavigationController; 465 friend class NavigationController;
466 // Used to access the child_windows_ (ConstrainedWindowList) for testing
467 // automation purposes.
468 friend class AutomationProvider;
464 469
465 explicit TabContents(TabContentsType type); 470 explicit TabContents(TabContentsType type);
466 471
472 // Some tab contents types need to override the type.
473 void set_type(TabContentsType type) { type_ = type; }
474
467 // NOTE: the TabContents destructor can run after the NavigationController 475 // NOTE: the TabContents destructor can run after the NavigationController
468 // has gone away, so any complicated unregistering that expects the profile 476 // has gone away, so any complicated unregistering that expects the profile
469 // or other shared objects to still be around does not belong in a 477 // or other shared objects to still be around does not belong in a
470 // destructor. 478 // destructor.
471 // For those purposes, instead see Destroy(). 479 // For those purposes, instead see Destroy().
472 // Protected so that others don't try to delete this directly. 480 // Protected so that others don't try to delete this directly.
473 virtual ~TabContents(); 481 virtual ~TabContents();
474 482
475 // Set focus on the initial component. This is invoked from 483 // Sets focus to the tab contents window, but doesn't actuall set focus to
476 // RestoreFocus if SetLastFocusOwner has not yet been invoked. 484 // a particular element in it (see also SetInitialFocus(bool) which does
485 // that in different circumstances).
486 // FIXME(brettw) having two SetInitialFocus that do different things is silly.
477 virtual void SetInitialFocus(); 487 virtual void SetInitialFocus();
478 488
479 // Changes the IsLoading state and notifies delegate as needed 489 // Changes the IsLoading state and notifies delegate as needed
480 // |details| is used to provide details on the load that just finished 490 // |details| is used to provide details on the load that just finished
481 // (but can be null if not applicable) 491 // (but can be null if not applicable). Can be overridden.
482 void SetIsLoading(bool is_loading, LoadNotificationDetails* details); 492 virtual void SetIsLoading(bool is_loading, LoadNotificationDetails* details);
483 493
484 // Called by a derived class when the TabContents is resized, causing 494 // Called by a derived class when the TabContents is resized, causing
485 // suppressed constrained web popups to be repositioned to the new bounds 495 // suppressed constrained web popups to be repositioned to the new bounds
486 // if necessary. 496 // if necessary.
487 void RepositionSupressedPopupsToFit(const gfx::Size& new_size); 497 void RepositionSupressedPopupsToFit(const gfx::Size& new_size);
488 498
489 // Releases the download shelf. This method is used by MigrateShelfViewFrom. 499 // Releases the download shelf. This method is used by MigrateShelfViewFrom.
490 // Sub-classes should clear any pointer they might keep to the shelf view and 500 // Sub-classes should clear any pointer they might keep to the shelf view and
491 // invoke TabContents::ReleaseDownloadShelfView(). 501 // invoke TabContents::ReleaseDownloadShelfView().
492 virtual void ReleaseDownloadShelfView(); 502 virtual void ReleaseDownloadShelfView();
493 503
494 bool is_loading_; // true if currently loading a resource. 504 // Called by derived classes to indicate that we're no longer waiting for a
495 bool response_started_; // true if waiting for a response. 505 // response. This won't actually update the throbber, but it will get picked
496 bool is_active_; 506 // up at the next animation step if the throbber is going.
497 bool is_crashed_; // true if the tab is considered crashed. 507 void SetNotWaitingForResponse() { waiting_for_response_ = false; }
498 508
499 typedef std::vector<ConstrainedWindow*> ConstrainedWindowList; 509 typedef std::vector<ConstrainedWindow*> ConstrainedWindowList;
500 ConstrainedWindowList child_windows_; 510 ConstrainedWindowList child_windows_;
501 511
512 private:
513 // Data ----------------------------------------------------------------------
514
502 TabContentsType type_; 515 TabContentsType type_;
503 516
504 private:
505 ConstrainedWindowList child_windows() const { return child_windows_; }
506
507 // Clear the last focus view and unregister the notification associated with
508 // it.
509 void ClearLastFocusedView();
510
511 TabContentsDelegate* delegate_; 517 TabContentsDelegate* delegate_;
512 NavigationController* controller_; 518 NavigationController* controller_;
513 519
520 // Indicates whether we're currently loading a resource.
521 bool is_loading_;
522
523 // See is_active() getter above.
524 bool is_active_;
525
526 bool is_crashed_; // true if the tab is considered crashed.
527
528 // See waiting_for_response() above.
529 bool waiting_for_response_;
530
514 scoped_ptr<const AutocompleteEditState> saved_location_bar_state_; 531 scoped_ptr<const AutocompleteEditState> saved_location_bar_state_;
515 532
516 // The download shelf view (view at the bottom of the page). 533 // The download shelf view (view at the bottom of the page).
517 scoped_ptr<DownloadShelfView> download_shelf_view_; 534 scoped_ptr<DownloadShelfView> download_shelf_view_;
518 535
519 // Whether the shelf view is visible. 536 // Whether the shelf view is visible.
520 bool shelf_visible_; 537 bool shelf_visible_;
521 538
522 // Indicates the largest PageID we've seen. This field is ignored if we are 539 // Indicates the largest PageID we've seen. This field is ignored if we are
523 // a WebContents, in which case the max page ID is stored separately with 540 // a WebContents, in which case the max page ID is stored separately with
524 // each SiteInstance. 541 // each SiteInstance.
525 int32 max_page_id_; 542 int32 max_page_id_;
526 543
527 // The id used in the ViewStorage to store the last focused view. 544 // The id used in the ViewStorage to store the last focused view.
528 int last_focused_view_storage_id_; 545 int last_focused_view_storage_id_;
529 546
530 std::wstring encoding_name_; 547 std::wstring encoding_name_;
548
549 // See capturing_contents() above.
550 bool capturing_contents_;
551
552 DISALLOW_COPY_AND_ASSIGN(TabContents);
531 }; 553 };
532 554
533 #endif // CHROME_BROWSER_TAB_CONTENTS_H_ 555 #endif // CHROME_BROWSER_TAB_CONTENTS_H_
534
OLDNEW
« no previous file with comments | « chrome/browser/render_view_host_delegate.h ('k') | chrome/browser/tab_contents.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698