blob: bfba7742f086dcc2f4f7bca6b97896a9857f608e [file] [log] [blame]
[email protected]0dd3a0ab2011-02-18 08:17:441// Copyright (c) 2011 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_H_
6#define CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_H_
7#pragma once
8
9#include <deque>
10#include <map>
11#include <string>
12#include <vector>
13
14#include "base/basictypes.h"
15#include "base/gtest_prod_util.h"
[email protected]3b63f8f42011-03-28 01:54:1516#include "base/memory/scoped_ptr.h"
[email protected]0dd3a0ab2011-02-18 08:17:4417#include "base/string16.h"
[email protected]0dd3a0ab2011-02-18 08:17:4418#include "chrome/browser/prefs/pref_change_registrar.h"
[email protected]0dd3a0ab2011-02-18 08:17:4419#include "chrome/browser/tab_contents/tab_specific_content_settings.h"
20#include "chrome/browser/ui/app_modal_dialogs/js_modal_dialog.h"
[email protected]5de634712011-03-02 00:20:1921#include "content/browser/renderer_host/render_view_host_delegate.h"
[email protected]0dd3a0ab2011-02-18 08:17:4422#include "content/browser/tab_contents/constrained_window.h"
[email protected]0dd3a0ab2011-02-18 08:17:4423#include "content/browser/tab_contents/navigation_controller.h"
24#include "content/browser/tab_contents/navigation_entry.h"
25#include "content/browser/tab_contents/page_navigator.h"
26#include "content/browser/tab_contents/render_view_host_manager.h"
[email protected]553602e12011-04-05 17:01:1827#include "content/browser/tab_contents/tab_contents_observer.h"
[email protected]1fd1a502011-03-30 16:55:5628#include "content/browser/webui/web_ui.h"
[email protected]7f070d42011-03-09 20:25:3229#include "content/common/notification_registrar.h"
[email protected]15a5fa52011-03-10 20:16:0430#include "content/common/property_bag.h"
[email protected]60916042011-03-19 00:43:3631#include "content/common/renderer_preferences.h"
[email protected]0dd3a0ab2011-02-18 08:17:4432#include "net/base/load_states.h"
[email protected]232a5812011-03-04 22:42:0833#include "net/base/network_change_notifier.h"
[email protected]0dd3a0ab2011-02-18 08:17:4434#include "ui/gfx/native_widget_types.h"
35
36#if defined(OS_WIN)
37#include "base/win/scoped_handle.h"
38#endif
39
40namespace gfx {
41class Rect;
42}
43
44namespace history {
45class HistoryAddPageArgs;
46}
47
[email protected]0dd3a0ab2011-02-18 08:17:4448class WebUI;
[email protected]0dd3a0ab2011-02-18 08:17:4449class DownloadItem;
50class Extension;
[email protected]0dd3a0ab2011-02-18 08:17:4451class InfoBarDelegate;
52class LoadNotificationDetails;
[email protected]0dd3a0ab2011-02-18 08:17:4453class PluginObserver;
54class Profile;
55class RenderViewHost;
56class SessionStorageNamespace;
57class SiteInstance;
58class SkBitmap;
59class TabContents;
60class TabContentsDelegate;
61class TabContentsObserver;
62class TabContentsSSLHelper;
63class TabContentsView;
64class URLPattern;
65struct RendererPreferences;
66struct ThumbnailScore;
[email protected]0dd3a0ab2011-02-18 08:17:4467struct ViewHostMsg_FrameNavigate_Params;
[email protected]0dd3a0ab2011-02-18 08:17:4468struct WebPreferences;
69
70// Describes what goes in the main content area of a tab. TabContents is
71// the only type of TabContents, and these should be merged together.
72class TabContents : public PageNavigator,
73 public NotificationObserver,
74 public RenderViewHostDelegate,
75 public RenderViewHostManager::Delegate,
76 public JavaScriptAppModalDialogDelegate,
[email protected]232a5812011-03-04 22:42:0877 public net::NetworkChangeNotifier::OnlineStateObserver {
[email protected]0dd3a0ab2011-02-18 08:17:4478 public:
79 // Flags passed to the TabContentsDelegate.NavigationStateChanged to tell it
80 // what has changed. Combine them to update more than one thing.
81 enum InvalidateTypes {
82 INVALIDATE_URL = 1 << 0, // The URL has changed.
83 INVALIDATE_TAB = 1 << 1, // The favicon, app icon, or crashed
84 // state changed.
85 INVALIDATE_LOAD = 1 << 2, // The loading state has changed.
86 INVALIDATE_PAGE_ACTIONS = 1 << 3, // Page action icons have changed.
87 INVALIDATE_BOOKMARK_BAR = 1 << 4, // State of ShouldShowBookmarkBar
88 // changed.
89 INVALIDATE_TITLE = 1 << 5, // The title changed.
90 };
91
92 // |base_tab_contents| is used if we want to size the new tab contents view
93 // based on an existing tab contents view. This can be NULL if not needed.
94 //
95 // The session storage namespace parameter allows multiple render views and
96 // tab contentses to share the same session storage (part of the WebStorage
97 // spec) space. This is useful when restoring tabs, but most callers should
98 // pass in NULL which will cause a new SessionStorageNamespace to be created.
99 TabContents(Profile* profile,
100 SiteInstance* site_instance,
101 int routing_id,
102 const TabContents* base_tab_contents,
103 SessionStorageNamespace* session_storage_namespace);
104 virtual ~TabContents();
105
106 // Intrinsic tab state -------------------------------------------------------
107
108 // Returns the property bag for this tab contents, where callers can add
109 // extra data they may wish to associate with the tab. Returns a pointer
110 // rather than a reference since the PropertyAccessors expect this.
111 const PropertyBag* property_bag() const { return &property_bag_; }
112 PropertyBag* property_bag() { return &property_bag_; }
113
114 TabContentsDelegate* delegate() const { return delegate_; }
115 void set_delegate(TabContentsDelegate* d) { delegate_ = d; }
116
117 // Gets the controller for this tab contents.
118 NavigationController& controller() { return controller_; }
119 const NavigationController& controller() const { return controller_; }
120
121 // Returns the user profile associated with this TabContents (via the
122 // NavigationController).
123 Profile* profile() const { return controller_.profile(); }
124
125 // Returns true if contains content rendered by an extension.
126 bool HostsExtension() const;
127
128 // Returns the TabContentsSSLHelper, creating it if necessary.
129 TabContentsSSLHelper* GetSSLHelper();
130
[email protected]0dd3a0ab2011-02-18 08:17:44131 // Return the currently active RenderProcessHost and RenderViewHost. Each of
132 // these may change over time.
133 RenderProcessHost* GetRenderProcessHost() const;
134 RenderViewHost* render_view_host() const {
135 return render_manager_.current_host();
136 }
137
138 WebUI* web_ui() const {
139 return render_manager_.web_ui() ? render_manager_.web_ui()
140 : render_manager_.pending_web_ui();
141 }
142
143 // Returns the currently active RenderWidgetHostView. This may change over
144 // time and can be NULL (during setup and teardown).
145 RenderWidgetHostView* GetRenderWidgetHostView() const {
146 return render_manager_.GetRenderWidgetHostView();
147 }
148
149 // The TabContentsView will never change and is guaranteed non-NULL.
150 TabContentsView* view() const {
151 return view_.get();
152 }
153
[email protected]0dd3a0ab2011-02-18 08:17:44154 // Tab navigation state ------------------------------------------------------
155
156 // Returns the current navigation properties, which if a navigation is
157 // pending may be provisional (e.g., the navigation could result in a
158 // download, in which case the URL would revert to what it was previously).
159 virtual const GURL& GetURL() const;
160 virtual const string16& GetTitle() const;
161
162 // The max PageID of any page that this TabContents has loaded. PageIDs
163 // increase with each new page that is loaded by a tab. If this is a
164 // TabContents, then the max PageID is kept separately on each SiteInstance.
165 // Returns -1 if no PageIDs have yet been seen.
166 int32 GetMaxPageID();
167
168 // Updates the max PageID to be at least the given PageID.
169 void UpdateMaxPageID(int32 page_id);
170
171 // Returns the site instance associated with the current page. By default,
172 // there is no site instance. TabContents overrides this to provide proper
173 // access to its site instance.
174 virtual SiteInstance* GetSiteInstance() const;
175
176 // Defines whether this tab's URL should be displayed in the browser's URL
177 // bar. Normally this is true so you can see the URL. This is set to false
178 // for the new tab page and related pages so that the URL bar is empty and
179 // the user is invited to type into it.
180 virtual bool ShouldDisplayURL();
181
[email protected]0dd3a0ab2011-02-18 08:17:44182 // Return whether this tab contents is loading a resource.
183 bool is_loading() const { return is_loading_; }
184
185 // Returns whether this tab contents is waiting for a first-response for the
186 // main resource of the page. This controls whether the throbber state is
187 // "waiting" or "loading."
188 bool waiting_for_response() const { return waiting_for_response_; }
189
190 net::LoadState load_state() const { return load_state_; }
191 string16 load_state_host() const { return load_state_host_; }
192 uint64 upload_size() const { return upload_size_; }
193 uint64 upload_position() const { return upload_position_; }
194
195 const std::string& encoding() const { return encoding_; }
196 void set_encoding(const std::string& encoding);
197 void reset_encoding() {
198 encoding_.clear();
199 }
200
[email protected]0dd3a0ab2011-02-18 08:17:44201 bool displayed_insecure_content() const {
202 return displayed_insecure_content_;
203 }
204
205 // Internal state ------------------------------------------------------------
206
207 // This flag indicates whether the tab contents is currently being
208 // screenshotted by the DraggedTabController.
209 bool capturing_contents() const { return capturing_contents_; }
210 void set_capturing_contents(bool cap) { capturing_contents_ = cap; }
211
212 // Indicates whether this tab should be considered crashed. The setter will
213 // also notify the delegate when the flag is changed.
214 bool is_crashed() const {
215 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
216 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
217 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
218 }
219 base::TerminationStatus crashed_status() const { return crashed_status_; }
220 int crashed_error_code() const { return crashed_error_code_; }
221 void SetIsCrashed(base::TerminationStatus status, int error_code);
222
[email protected]0dd3a0ab2011-02-18 08:17:44223 // Whether the tab is in the process of being destroyed.
224 // Added as a tentative work-around for focus related bug #4633. This allows
225 // us not to store focus when a tab is being closed.
226 bool is_being_destroyed() const { return is_being_destroyed_; }
227
228 // Convenience method for notifying the delegate of a navigation state
229 // change. See TabContentsDelegate.
230 void NotifyNavigationStateChanged(unsigned changed_flags);
231
232 // Invoked when the tab contents becomes selected. If you override, be sure
233 // and invoke super's implementation.
234 virtual void DidBecomeSelected();
235 base::TimeTicks last_selected_time() const {
236 return last_selected_time_;
237 }
238
239 // Invoked when the tab contents becomes hidden.
240 // NOTE: If you override this, call the superclass version too!
241 virtual void WasHidden();
242
243 // Activates this contents within its containing window, bringing that window
244 // to the foreground if necessary.
245 void Activate();
246
247 // Deactivates this contents by deactivating its containing window.
248 void Deactivate();
249
250 // TODO(brettw) document these.
251 virtual void ShowContents();
252 virtual void HideContents();
253
254 // Returns true if the before unload and unload listeners need to be
255 // fired. The value of this changes over time. For example, if true and the
256 // before unload listener is executed and allows the user to exit, then this
257 // returns false.
258 bool NeedToFireBeforeUnload();
259
260#ifdef UNIT_TEST
261 // Expose the render manager for testing.
262 RenderViewHostManager* render_manager() { return &render_manager_; }
263#endif
264
265 // In the underlying RenderViewHostManager, swaps in the provided
266 // RenderViewHost to replace the current RenderViewHost. The current RVH
267 // will be shutdown and ultimately deleted.
268 void SwapInRenderViewHost(RenderViewHost* rvh);
269
270 // Commands ------------------------------------------------------------------
271
272 // Implementation of PageNavigator.
273 virtual void OpenURL(const GURL& url, const GURL& referrer,
274 WindowOpenDisposition disposition,
275 PageTransition::Type transition);
276
277 // Called by the NavigationController to cause the TabContents to navigate to
278 // the current pending entry. The NavigationController should be called back
279 // with CommitPendingEntry/RendererDidNavigate on success or
280 // DiscardPendingEntry. The callbacks can be inside of this function, or at
281 // some future time.
282 //
283 // The entry has a PageID of -1 if newly created (corresponding to navigation
284 // to a new URL).
285 //
286 // If this method returns false, then the navigation is discarded (equivalent
287 // to calling DiscardPendingEntry on the NavigationController).
288 virtual bool NavigateToPendingEntry(
289 NavigationController::ReloadType reload_type);
290
291 // Stop any pending navigation.
292 virtual void Stop();
293
294 // Called on a TabContents when it isn't a popup, but a new window.
295 virtual void DisassociateFromPopupCount();
296
297 // Creates a new TabContents with the same state as this one. The returned
298 // heap-allocated pointer is owned by the caller.
299 virtual TabContents* Clone();
300
301 // Shows the page info.
302 void ShowPageInfo(const GURL& url,
303 const NavigationEntry::SSLStatus& ssl,
304 bool show_history);
305
[email protected]0dd3a0ab2011-02-18 08:17:44306 // Window management ---------------------------------------------------------
307
308 // Create a new window constrained to this TabContents' clip and visibility.
309 // The window is initialized by using the supplied delegate to obtain basic
310 // window characteristics, and the supplied view for the content. Note that
311 // the returned ConstrainedWindow might not yet be visible.
312 ConstrainedWindow* CreateConstrainedDialog(
313 ConstrainedWindowDelegate* delegate);
314
[email protected]473174942011-04-19 22:52:35315 // Adds a new tab or window with the given already-created contents.
[email protected]e7cfdbd2011-04-22 14:41:37316 void AddNewContents(TabContents* new_contents,
317 WindowOpenDisposition disposition,
318 const gfx::Rect& initial_pos,
319 bool user_gesture);
[email protected]0dd3a0ab2011-02-18 08:17:44320
321 // Returns the number of constrained windows in this tab. Used by tests.
322 size_t constrained_window_count() { return child_windows_.size(); }
323
324 typedef std::deque<ConstrainedWindow*> ConstrainedWindowList;
325
326 // Return an iterator for the first constrained window in this tab contents.
327 ConstrainedWindowList::iterator constrained_window_begin()
328 { return child_windows_.begin(); }
329
330 // Return an iterator for the last constrained window in this tab contents.
331 ConstrainedWindowList::iterator constrained_window_end()
332 { return child_windows_.end(); }
333
334 // Views and focus -----------------------------------------------------------
335 // TODO(brettw): Most of these should be removed and the caller should call
336 // the view directly.
337
338 // Returns the actual window that is focused when this TabContents is shown.
339 gfx::NativeView GetContentNativeView() const;
340
341 // Returns the NativeView associated with this TabContents. Outside of
342 // automation in the context of the UI, this is required to be implemented.
343 gfx::NativeView GetNativeView() const;
344
345 // Returns the bounds of this TabContents in the screen coordinate system.
346 void GetContainerBounds(gfx::Rect *out) const;
347
348 // Makes the tab the focused window.
349 void Focus();
350
351 // Focuses the first (last if |reverse| is true) element in the page.
352 // Invoked when this tab is getting the focus through tab traversal (|reverse|
353 // is true when using Shift-Tab).
354 void FocusThroughTabTraversal(bool reverse);
355
356 // These next two functions are declared on RenderViewHostManager::Delegate
357 // but also accessed directly by other callers.
358
359 // Returns true if the location bar should be focused by default rather than
360 // the page contents. The view calls this function when the tab is focused
361 // to see what it should do.
362 virtual bool FocusLocationBarByDefault();
363
364 // Focuses the location bar.
365 virtual void SetFocusToLocationBar(bool select_all);
366
367 // Creates a view and sets the size for the specified RVH.
368 virtual void CreateViewAndSetSizeForRVH(RenderViewHost* rvh);
369
370 // Infobars ------------------------------------------------------------------
371
372 // Adds an InfoBar for the specified |delegate|.
[email protected]dc83fcbd2011-02-23 23:26:52373 void AddInfoBar(InfoBarDelegate* delegate);
[email protected]0dd3a0ab2011-02-18 08:17:44374
375 // Removes the InfoBar for the specified |delegate|.
376 void RemoveInfoBar(InfoBarDelegate* delegate);
377
378 // Replaces one infobar with another, without any animation in between.
379 void ReplaceInfoBar(InfoBarDelegate* old_delegate,
380 InfoBarDelegate* new_delegate);
381
382 // Enumeration and access functions.
383 size_t infobar_count() const { return infobar_delegates_.size(); }
384 // WARNING: This does not sanity-check |index|!
385 InfoBarDelegate* GetInfoBarDelegateAt(size_t index) {
386 return infobar_delegates_[index];
387 }
388
389 // Toolbars and such ---------------------------------------------------------
390
391 // Returns true if a Bookmark Bar should be shown for this tab.
392 virtual bool ShouldShowBookmarkBar();
393
394 // Notifies the delegate that a download is about to be started.
395 // This notification is fired before a local temporary file has been created.
396 bool CanDownload(int request_id);
397
398 // Notifies the delegate that a download started.
399 void OnStartDownload(DownloadItem* download);
400
[email protected]0dd3a0ab2011-02-18 08:17:44401 // Called when a ConstrainedWindow we own is about to be closed.
402 void WillClose(ConstrainedWindow* window);
403
[email protected]0dd3a0ab2011-02-18 08:17:44404 // Interstitials -------------------------------------------------------------
405
406 // Various other systems need to know about our interstitials.
407 bool showing_interstitial_page() const {
408 return render_manager_.interstitial_page() != NULL;
409 }
410
411 // Sets the passed passed interstitial as the currently showing interstitial.
412 // |interstitial_page| should be non NULL (use the remove_interstitial_page
413 // method to unset the interstitial) and no interstitial page should be set
414 // when there is already a non NULL interstitial page set.
415 void set_interstitial_page(InterstitialPage* interstitial_page) {
416 render_manager_.set_interstitial_page(interstitial_page);
417 }
418
419 // Unsets the currently showing interstitial.
420 void remove_interstitial_page() {
421 render_manager_.remove_interstitial_page();
422 }
423
424 // Returns the currently showing interstitial, NULL if no interstitial is
425 // showing.
426 InterstitialPage* interstitial_page() const {
427 return render_manager_.interstitial_page();
428 }
429
430 // Misc state & callbacks ----------------------------------------------------
431
432 // Set whether the contents should block javascript message boxes or not.
433 // Default is not to block any message boxes.
434 void set_suppress_javascript_messages(bool suppress_javascript_messages) {
435 suppress_javascript_messages_ = suppress_javascript_messages;
436 }
437
[email protected]0dd3a0ab2011-02-18 08:17:44438 // Tells the user's email client to open a compose window containing the
439 // current page's URL.
440 void EmailPageLocation();
441
[email protected]0dd3a0ab2011-02-18 08:17:44442 // Returns true if the active NavigationEntry's page_id equals page_id.
443 bool IsActiveEntry(int32 page_id);
444
445 const std::string& contents_mime_type() const {
446 return contents_mime_type_;
447 }
448
449 // Returns true if this TabContents will notify about disconnection.
450 bool notify_disconnection() const { return notify_disconnection_; }
451
452 // Override the encoding and reload the page by sending down
453 // ViewMsg_SetPageEncoding to the renderer. |UpdateEncoding| is kinda
454 // the opposite of this, by which 'browser' is notified of
455 // the encoding of the current tab from 'renderer' (determined by
456 // auto-detect, http header, meta, bom detection, etc).
457 void SetOverrideEncoding(const std::string& encoding);
458
459 // Remove any user-defined override encoding and reload by sending down
460 // ViewMsg_ResetPageEncodingToDefault to the renderer.
461 void ResetOverrideEncoding();
462
463 void WindowMoveOrResizeStarted();
464
[email protected]0dd3a0ab2011-02-18 08:17:44465 RendererPreferences* GetMutableRendererPrefs() {
466 return &renderer_preferences_;
467 }
468
[email protected]1fd1a502011-03-30 16:55:56469 void set_opener_web_ui_type(WebUI::TypeID opener_web_ui_type) {
[email protected]0dd3a0ab2011-02-18 08:17:44470 opener_web_ui_type_ = opener_web_ui_type;
471 }
472
[email protected]0dd3a0ab2011-02-18 08:17:44473 // Set the time when we started to create the new tab page. This time is
474 // from before we created this TabContents.
475 void set_new_tab_start_time(const base::TimeTicks& time) {
476 new_tab_start_time_ = time;
477 }
[email protected]763ec4ca2011-04-29 15:48:12478 base::TimeTicks new_tab_start_time() const { return new_tab_start_time_; }
[email protected]0dd3a0ab2011-02-18 08:17:44479
480 // Notification that tab closing has started. This can be called multiple
481 // times, subsequent calls are ignored.
482 void OnCloseStarted();
483
[email protected]0dd3a0ab2011-02-18 08:17:44484 // Returns true if underlying TabContentsView should accept drag-n-drop.
485 bool ShouldAcceptDragAndDrop() const;
486
487 // A render view-originated drag has ended. Informs the render view host and
488 // tab contents delegate.
489 void SystemDragEnded();
490
491 // Indicates if this tab was explicitly closed by the user (control-w, close
492 // tab menu item...). This is false for actions that indirectly close the tab,
493 // such as closing the window. The setter is maintained by TabStripModel, and
494 // the getter only useful from within TAB_CLOSED notification
495 void set_closed_by_user_gesture(bool value) {
496 closed_by_user_gesture_ = value;
497 }
498 bool closed_by_user_gesture() const { return closed_by_user_gesture_; }
499
500 // Overridden from JavaScriptAppModalDialogDelegate:
501 virtual void OnMessageBoxClosed(IPC::Message* reply_msg,
502 bool success,
503 const std::wstring& prompt);
504 virtual void SetSuppressMessageBoxes(bool suppress_message_boxes);
505 virtual gfx::NativeWindow GetMessageBoxRootWindow();
506 virtual TabContents* AsTabContents();
507 virtual ExtensionHost* AsExtensionHost();
508
509 // The BookmarkDragDelegate is used to forward bookmark drag and drop events
510 // to extensions.
511 virtual RenderViewHostDelegate::BookmarkDrag* GetBookmarkDragDelegate();
512
513 // It is up to callers to call SetBookmarkDragDelegate(NULL) when
514 // |bookmark_drag| is deleted since this class does not take ownership of
515 // |bookmark_drag|.
516 virtual void SetBookmarkDragDelegate(
517 RenderViewHostDelegate::BookmarkDrag* bookmark_drag);
518
519 // The TabSpecificContentSettings object is used to query the blocked content
520 // state by various UI elements.
521 TabSpecificContentSettings* GetTabSpecificContentSettings() const;
522
523 // Updates history with the specified navigation. This is called by
524 // OnMsgNavigate to update history state.
525 void UpdateHistoryForNavigation(
526 scoped_refptr<history::HistoryAddPageArgs> add_page_args);
527
528 // Sends the page title to the history service. This is called when we receive
529 // the page title and we know we want to update history.
530 void UpdateHistoryPageTitle(const NavigationEntry& entry);
531
532 // Gets the zoom level for this tab.
533 double GetZoomLevel() const;
534
535 // Gets the zoom percent for this tab.
536 int GetZoomPercent(bool* enable_increment, bool* enable_decrement);
537
[email protected]0dd3a0ab2011-02-18 08:17:44538 // Opens view-source tab for this contents.
539 void ViewSource();
540
[email protected]932b7a12011-03-09 12:50:27541 void ViewFrameSource(const GURL& url,
542 const std::string& content_state);
543
[email protected]0dd3a0ab2011-02-18 08:17:44544 // Gets the minimum/maximum zoom percent.
545 int minimum_zoom_percent() const { return minimum_zoom_percent_; }
546 int maximum_zoom_percent() const { return maximum_zoom_percent_; }
547
548 int content_restrictions() const { return content_restrictions_; }
[email protected]c40d6232011-03-25 00:16:21549 void SetContentRestrictions(int restrictions);
[email protected]0dd3a0ab2011-02-18 08:17:44550
[email protected]1fd1a502011-03-30 16:55:56551 // Query the WebUIFactory for the TypeID for the current URL.
552 WebUI::TypeID GetWebUITypeForCurrentState();
553
[email protected]b375c5d2011-05-03 21:15:04554 // Returns the WebUI for the current state of the tab. This will either be
555 // the pending WebUI, the committed WebUI, or NULL.
556 WebUI* GetWebUIForCurrentState();
557
[email protected]e7cfdbd2011-04-22 14:41:37558 // From RenderViewHostDelegate.
559 virtual RenderViewHostDelegate::ContentSettings* GetContentSettingsDelegate();
560
[email protected]0dd3a0ab2011-02-18 08:17:44561 protected:
[email protected]553602e12011-04-05 17:01:18562 friend class TabContentsObserver;
563 friend class TabContentsObserver::Registrar;
564
565 // Add and remove observers for page navigation notifications. Adding or
566 // removing multiple times has no effect. The order in which notifications
567 // are sent to observers is undefined. Clients must be sure to remove the
568 // observer before they go away.
569 void AddObserver(TabContentsObserver* observer);
570 void RemoveObserver(TabContentsObserver* observer);
571
[email protected]e7cfdbd2011-04-22 14:41:37572 // From RenderViewHostDelegate.
[email protected]0dd3a0ab2011-02-18 08:17:44573 virtual bool OnMessageReceived(const IPC::Message& message);
574
575 private:
576 friend class NavigationController;
577 // Used to access the child_windows_ (ConstrainedWindowList) for testing
578 // automation purposes.
579 friend class TestingAutomationProvider;
580
581 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, NoJSMessageOnInterstitials);
582 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, UpdateTitle);
583 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, CrossSiteCantPreemptAfterUnload);
[email protected]aed59602011-02-28 22:57:33584 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, ConstrainedWindows);
[email protected]0dd3a0ab2011-02-18 08:17:44585 FRIEND_TEST_ALL_PREFIXES(FormStructureBrowserTest, HTMLFiles);
586 FRIEND_TEST_ALL_PREFIXES(NavigationControllerTest, HistoryNavigate);
587 FRIEND_TEST_ALL_PREFIXES(RenderViewHostManagerTest, PageDoesBackAndReload);
588
589 // Temporary until the view/contents separation is complete.
590 friend class TabContentsView;
591#if defined(OS_WIN)
[email protected]7e2cef52011-04-11 21:47:23592 friend class TabContentsViewViews;
[email protected]0dd3a0ab2011-02-18 08:17:44593#elif defined(OS_MACOSX)
594 friend class TabContentsViewMac;
595#elif defined(TOOLKIT_USES_GTK)
596 friend class TabContentsViewGtk;
597#endif
598
599 // So InterstitialPage can access SetIsLoading.
600 friend class InterstitialPage;
601
602 // TODO(brettw) TestTabContents shouldn't exist!
603 friend class TestTabContents;
604
605 // Used to access the CreateHistoryAddPageArgs member function.
606 friend class ExternalTabContainer;
607
[email protected]0dd3a0ab2011-02-18 08:17:44608 // Add all the TabContentObservers.
609 void AddObservers();
610
611 // Message handlers.
612 void OnDidStartProvisionalLoadForFrame(int64 frame_id,
613 bool main_frame,
614 const GURL& url);
615 void OnDidRedirectProvisionalLoad(int32 page_id,
616 const GURL& source_url,
617 const GURL& target_url);
618 void OnDidFailProvisionalLoadWithError(int64 frame_id,
619 bool main_frame,
620 int error_code,
621 const GURL& url,
622 bool showing_repost_interstitial);
623 void OnDidLoadResourceFromMemoryCache(const GURL& url,
624 const std::string& security_info);
625 void OnDidDisplayInsecureContent();
626 void OnDidRunInsecureContent(const std::string& security_origin,
627 const GURL& target_url);
628 void OnDocumentLoadedInFrame(int64 frame_id);
629 void OnDidFinishLoad(int64 frame_id);
630 void OnUpdateContentRestrictions(int restrictions);
[email protected]0dd3a0ab2011-02-18 08:17:44631
632 void OnGoToEntryAtOffset(int offset);
[email protected]0dd3a0ab2011-02-18 08:17:44633
634 // Changes the IsLoading state and notifies delegate as needed
635 // |details| is used to provide details on the load that just finished
636 // (but can be null if not applicable). Can be overridden.
637 void SetIsLoading(bool is_loading,
638 LoadNotificationDetails* details);
639
[email protected]0dd3a0ab2011-02-18 08:17:44640 // Called by derived classes to indicate that we're no longer waiting for a
641 // response. This won't actually update the throbber, but it will get picked
642 // up at the next animation step if the throbber is going.
643 void SetNotWaitingForResponse() { waiting_for_response_ = false; }
644
645 ConstrainedWindowList child_windows_;
646
647 // Expires InfoBars that need to be expired, according to the state carried
648 // in |details|, in response to a new NavigationEntry being committed (the
649 // user navigated to another page).
650 void ExpireInfoBars(
651 const NavigationController::LoadCommittedDetails& details);
652
[email protected]0dd3a0ab2011-02-18 08:17:44653 // Navigation helpers --------------------------------------------------------
654 //
655 // These functions are helpers for Navigate() and DidNavigate().
656
657 // Handles post-navigation tasks in DidNavigate AFTER the entry has been
658 // committed to the navigation controller. Note that the navigation entry is
659 // not provided since it may be invalid/changed after being committed. The
660 // current navigation entry is in the NavigationController at this point.
661 void DidNavigateMainFramePostCommit(
662 const NavigationController::LoadCommittedDetails& details,
663 const ViewHostMsg_FrameNavigate_Params& params);
664 void DidNavigateAnyFramePostCommit(
665 RenderViewHost* render_view_host,
666 const NavigationController::LoadCommittedDetails& details,
667 const ViewHostMsg_FrameNavigate_Params& params);
668
669 // Closes all constrained windows.
670 void CloseConstrainedWindows();
671
672 // Send the alternate error page URL to the renderer. This method is virtual
673 // so special html pages can override this (e.g., the new tab page).
674 virtual void UpdateAlternateErrorPageURL();
675
676 // Send webkit specific settings to the renderer.
677 void UpdateWebPreferences();
678
679 // Instruct the renderer to update the zoom level.
680 void UpdateZoomLevel();
681
682 // If our controller was restored and the page id is > than the site
683 // instance's page id, the site instances page id is updated as well as the
684 // renderers max page id.
685 void UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
686 RenderViewHost* rvh);
687
688 // Returns the history::HistoryAddPageArgs to use for adding a page to
689 // history.
690 scoped_refptr<history::HistoryAddPageArgs> CreateHistoryAddPageArgs(
691 const GURL& virtual_url,
692 const NavigationController::LoadCommittedDetails& details,
693 const ViewHostMsg_FrameNavigate_Params& params);
694
695 // Saves the given title to the navigation entry and does associated work. It
696 // will update history and the view for the new title, and also synthesize
697 // titles for file URLs that have none (so we require that the URL of the
698 // entry already be set).
699 //
700 // This is used as the backend for state updates, which include a new title,
701 // or the dedicated set title message. It returns true if the new title is
702 // different and was therefore updated.
[email protected]6b2f7a82011-04-25 19:30:51703 bool UpdateTitleForEntry(NavigationEntry* entry, const std::wstring& title);
[email protected]0dd3a0ab2011-02-18 08:17:44704
705 // Causes the TabContents to navigate in the right renderer to |entry|, which
706 // must be already part of the entries in the navigation controller.
707 // This does not change the NavigationController state.
708 bool NavigateToEntry(const NavigationEntry& entry,
709 NavigationController::ReloadType reload_type);
710
711 // Misc non-view stuff -------------------------------------------------------
712
713 // Helper functions for sending notifications.
714 void NotifySwapped();
715 void NotifyConnected();
716 void NotifyDisconnected();
717
[email protected]0dd3a0ab2011-02-18 08:17:44718 // RenderViewHostDelegate ----------------------------------------------------
719
720 // RenderViewHostDelegate implementation.
721 virtual RenderViewHostDelegate::View* GetViewDelegate();
722 virtual RenderViewHostDelegate::RendererManagement*
723 GetRendererManagementDelegate();
[email protected]0dd3a0ab2011-02-18 08:17:44724 virtual RenderViewHostDelegate::SSL* GetSSLDelegate();
[email protected]0dd3a0ab2011-02-18 08:17:44725 virtual TabContents* GetAsTabContents();
726 virtual ViewType::Type GetRenderViewType() const;
727 virtual int GetBrowserWindowID() const;
728 virtual void RenderViewCreated(RenderViewHost* render_view_host);
729 virtual void RenderViewReady(RenderViewHost* render_view_host);
730 virtual void RenderViewGone(RenderViewHost* render_view_host,
731 base::TerminationStatus status,
732 int error_code);
733 virtual void RenderViewDeleted(RenderViewHost* render_view_host);
734 virtual void DidNavigate(RenderViewHost* render_view_host,
735 const ViewHostMsg_FrameNavigate_Params& params);
736 virtual void UpdateState(RenderViewHost* render_view_host,
737 int32 page_id,
738 const std::string& state);
[email protected]6b2f7a82011-04-25 19:30:51739 virtual void UpdateTitle(RenderViewHost* render_view_host,
740 int32 page_id,
741 const std::wstring& title);
[email protected]0dd3a0ab2011-02-18 08:17:44742 virtual void UpdateEncoding(RenderViewHost* render_view_host,
743 const std::string& encoding);
744 virtual void UpdateTargetURL(int32 page_id, const GURL& url);
[email protected]0dd3a0ab2011-02-18 08:17:44745 virtual void UpdateInspectorSetting(const std::string& key,
746 const std::string& value);
747 virtual void ClearInspectorSettings();
748 virtual void Close(RenderViewHost* render_view_host);
749 virtual void RequestMove(const gfx::Rect& new_bounds);
750 virtual void DidStartLoading();
751 virtual void DidStopLoading();
[email protected]c95fa8b2011-04-28 20:26:16752 virtual void DidCancelLoading();
[email protected]0dd3a0ab2011-02-18 08:17:44753 virtual void DidChangeLoadProgress(double progress);
754 virtual void DocumentOnLoadCompletedInMainFrame(
755 RenderViewHost* render_view_host,
756 int32 page_id);
757 virtual void RequestOpenURL(const GURL& url, const GURL& referrer,
758 WindowOpenDisposition disposition);
[email protected]0dd3a0ab2011-02-18 08:17:44759 virtual void ProcessExternalHostMessage(const std::string& message,
760 const std::string& origin,
761 const std::string& target);
762 virtual void RunJavaScriptMessage(const std::wstring& message,
763 const std::wstring& default_prompt,
764 const GURL& frame_url,
765 const int flags,
766 IPC::Message* reply_msg,
767 bool* did_suppress_message);
768 virtual void RunBeforeUnloadConfirm(const std::wstring& message,
769 IPC::Message* reply_msg);
[email protected]0dd3a0ab2011-02-18 08:17:44770 virtual GURL GetAlternateErrorPageURL() const;
771 virtual RendererPreferences GetRendererPrefs(Profile* profile) const;
772 virtual WebPreferences GetWebkitPrefs();
773 virtual void OnUserGesture();
774 virtual void OnIgnoredUIEvent();
775 virtual void OnCrossSiteResponse(int new_render_process_host_id,
776 int new_request_id);
777 virtual void RendererUnresponsive(RenderViewHost* render_view_host,
778 bool is_during_unload);
779 virtual void RendererResponsive(RenderViewHost* render_view_host);
780 virtual void LoadStateChanged(const GURL& url, net::LoadState load_state,
781 uint64 upload_position, uint64 upload_size);
782 virtual bool IsExternalTabContainer() const;
783 virtual void DidInsertCSS();
784 virtual void FocusedNodeChanged(bool is_editable_node);
785 virtual void UpdateZoomLimits(int minimum_percent,
786 int maximum_percent,
787 bool remember);
788 virtual void WorkerCrashed();
[email protected]f364d1392011-04-08 21:03:10789 virtual void RequestDesktopNotificationPermission(const GURL& source_origin,
790 int callback_context);
[email protected]0dd3a0ab2011-02-18 08:17:44791
792 // RenderViewHostManager::Delegate -------------------------------------------
793
794 // Blocks/unblocks interaction with renderer process.
795 void BlockTabContent(bool blocked);
796
797 virtual void BeforeUnloadFiredFromRenderManager(
798 bool proceed,
799 bool* proceed_to_fire_unload);
800 virtual void DidStartLoadingFromRenderManager(
801 RenderViewHost* render_view_host);
802 virtual void RenderViewGoneFromRenderManager(
803 RenderViewHost* render_view_host);
804 virtual void UpdateRenderViewSizeForRenderManager();
805 virtual void NotifySwappedFromRenderManager();
806 virtual NavigationController& GetControllerForRenderManager();
807 virtual WebUI* CreateWebUIForRenderManager(const GURL& url);
808 virtual NavigationEntry* GetLastCommittedNavigationEntryForRenderManager();
809
810 // Initializes the given renderer if necessary and creates the view ID
811 // corresponding to this view host. If this method is not called and the
812 // process is not shared, then the TabContents will act as though the renderer
813 // is not running (i.e., it will render "sad tab"). This method is
814 // automatically called from LoadURL.
815 //
816 // If you are attaching to an already-existing RenderView, you should call
817 // InitWithExistingID.
818 virtual bool CreateRenderViewForRenderManager(
819 RenderViewHost* render_view_host);
820
821 // NotificationObserver ------------------------------------------------------
822
823 virtual void Observe(NotificationType type,
824 const NotificationSource& source,
825 const NotificationDetails& details);
826
[email protected]232a5812011-03-04 22:42:08827 // NetworkChangeNotifier::OnlineStateObserver:
828 virtual void OnOnlineStateChanged(bool online);
829
[email protected]aed59602011-02-28 22:57:33830 // Adds the given window to the list of child windows. The window will notify
831 // via WillClose() when it is being destroyed.
832 void AddConstrainedDialog(ConstrainedWindow* window);
833
[email protected]0dd3a0ab2011-02-18 08:17:44834 // Data for core operation ---------------------------------------------------
835
836 // Delegate for notifying our owner about stuff. Not owned by us.
837 TabContentsDelegate* delegate_;
838
839 // Handles the back/forward list and loading.
840 NavigationController controller_;
841
842 // The corresponding view.
843 scoped_ptr<TabContentsView> view_;
844
845 // Helper classes ------------------------------------------------------------
846
847 // Manages creation and swapping of render views.
848 RenderViewHostManager render_manager_;
849
850 // Stores random bits of data for others to associate with this object.
851 PropertyBag property_bag_;
852
853 // Registers and unregisters us for notifications.
854 NotificationRegistrar registrar_;
855
856 // Registers and unregisters for pref notifications.
857 PrefChangeRegistrar pref_change_registrar_;
858
[email protected]0dd3a0ab2011-02-18 08:17:44859 // Handles plugin messages.
860 scoped_ptr<PluginObserver> plugin_observer_;
861
[email protected]0dd3a0ab2011-02-18 08:17:44862 // TabContentsSSLHelper, lazily created.
863 scoped_ptr<TabContentsSSLHelper> ssl_helper_;
864
[email protected]0dd3a0ab2011-02-18 08:17:44865 // Handles drag and drop event forwarding to extensions.
866 BookmarkDrag* bookmark_drag_;
867
[email protected]0dd3a0ab2011-02-18 08:17:44868 // RenderViewHost::ContentSettingsDelegate.
869 scoped_ptr<TabSpecificContentSettings> content_settings_delegate_;
870
[email protected]0dd3a0ab2011-02-18 08:17:44871 // Data for loading state ----------------------------------------------------
872
873 // Indicates whether we're currently loading a resource.
874 bool is_loading_;
875
876 // Indicates if the tab is considered crashed.
877 base::TerminationStatus crashed_status_;
878 int crashed_error_code_;
879
880 // See waiting_for_response() above.
881 bool waiting_for_response_;
882
883 // Indicates the largest PageID we've seen. This field is ignored if we are
884 // a TabContents, in which case the max page ID is stored separately with
885 // each SiteInstance.
886 // TODO(brettw) this seems like it can be removed according to the comment.
887 int32 max_page_id_;
888
889 // System time at which the current load was started.
890 base::TimeTicks current_load_start_;
891
892 // The current load state and the URL associated with it.
893 net::LoadState load_state_;
894 string16 load_state_host_;
895 // Upload progress, for displaying in the status bar.
896 // Set to zero when there is no significant upload happening.
897 uint64 upload_size_;
898 uint64 upload_position_;
899
900 // Data for current page -----------------------------------------------------
901
902 // Whether we have a (non-empty) title for the current page.
903 // Used to prevent subsequent title updates from affecting history. This
904 // prevents some weirdness because some AJAXy apps use titles for status
905 // messages.
906 bool received_page_title_;
907
908 // When a navigation occurs, we record its contents MIME type. It can be
909 // used to check whether we can do something for some special contents.
910 std::string contents_mime_type_;
911
912 // Character encoding.
913 std::string encoding_;
914
[email protected]0dd3a0ab2011-02-18 08:17:44915 // True if this is a secure page which displayed insecure content.
916 bool displayed_insecure_content_;
917
918 // Data for shelves and stuff ------------------------------------------------
919
920 // Delegates for InfoBars associated with this TabContents.
921 std::vector<InfoBarDelegate*> infobar_delegates_;
922
[email protected]0dd3a0ab2011-02-18 08:17:44923 // Data for misc internal state ----------------------------------------------
924
925 // See capturing_contents() above.
926 bool capturing_contents_;
927
928 // See getter above.
929 bool is_being_destroyed_;
930
931 // Indicates whether we should notify about disconnection of this
932 // TabContents. This is used to ensure disconnection notifications only
933 // happen if a connection notification has happened and that they happen only
934 // once.
935 bool notify_disconnection_;
936
[email protected]0dd3a0ab2011-02-18 08:17:44937#if defined(OS_WIN)
938 // Handle to an event that's set when the page is showing a message box (or
939 // equivalent constrained window). Plugin processes check this to know if
940 // they should pump messages then.
941 base::win::ScopedHandle message_box_active_;
942#endif
943
944 // The time that the last javascript message was dismissed.
945 base::TimeTicks last_javascript_message_dismissal_;
946
947 // True if the user has decided to block future javascript messages. This is
948 // reset on navigations to false on navigations.
949 bool suppress_javascript_messages_;
950
951 // Set to true when there is an active "before unload" dialog. When true,
952 // we've forced the throbber to start in Navigate, and we need to remember to
953 // turn it off in OnJavaScriptMessageBoxClosed if the navigation is canceled.
954 bool is_showing_before_unload_dialog_;
955
[email protected]0dd3a0ab2011-02-18 08:17:44956 // Settings that get passed to the renderer process.
957 RendererPreferences renderer_preferences_;
958
959 // If this tab was created from a renderer using window.open, this will be
960 // non-NULL and represent the WebUI of the opening renderer.
[email protected]1fd1a502011-03-30 16:55:56961 WebUI::TypeID opener_web_ui_type_;
[email protected]0dd3a0ab2011-02-18 08:17:44962
963 // The time that we started to create the new tab page.
964 base::TimeTicks new_tab_start_time_;
965
966 // The time that we started to close the tab.
967 base::TimeTicks tab_close_start_time_;
968
969 // The time that this tab was last selected.
970 base::TimeTicks last_selected_time_;
971
[email protected]0dd3a0ab2011-02-18 08:17:44972 // See description above setter.
973 bool closed_by_user_gesture_;
974
975 // Minimum/maximum zoom percent.
976 int minimum_zoom_percent_;
977 int maximum_zoom_percent_;
978 // If true, the default zoom limits have been overriden for this tab, in which
979 // case we don't want saved settings to apply to it and we don't want to
980 // remember it.
981 bool temporary_zoom_settings_;
982
983 // A list of observers notified when page state changes. Weak references.
984 ObserverList<TabContentsObserver> observers_;
985
986 // Content restrictions, used to disable print/copy etc based on content's
987 // (full-page plugins for now only) permissions.
988 int content_restrictions_;
989
[email protected]0dd3a0ab2011-02-18 08:17:44990 DISALLOW_COPY_AND_ASSIGN(TabContents);
991};
992
993#endif // CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_H_