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