blob: bc2bdd36c5b85c5e83f93b23332e5236bb4b1ed8 [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>
[email protected]0dd3a0ab2011-02-18 08:17:4412
13#include "base/basictypes.h"
14#include "base/gtest_prod_util.h"
[email protected]3b63f8f42011-03-28 01:54:1515#include "base/memory/scoped_ptr.h"
[email protected]0dd3a0ab2011-02-18 08:17:4416#include "base/string16.h"
[email protected]3ab9cb82011-06-03 18:02:0717#include "content/browser/javascript_dialogs.h"
[email protected]5de634712011-03-02 00:20:1918#include "content/browser/renderer_host/render_view_host_delegate.h"
[email protected]0dd3a0ab2011-02-18 08:17:4419#include "content/browser/tab_contents/constrained_window.h"
[email protected]0dd3a0ab2011-02-18 08:17:4420#include "content/browser/tab_contents/navigation_controller.h"
21#include "content/browser/tab_contents/navigation_entry.h"
22#include "content/browser/tab_contents/page_navigator.h"
23#include "content/browser/tab_contents/render_view_host_manager.h"
[email protected]553602e12011-04-05 17:01:1824#include "content/browser/tab_contents/tab_contents_observer.h"
[email protected]1fd1a502011-03-30 16:55:5625#include "content/browser/webui/web_ui.h"
[email protected]7f070d42011-03-09 20:25:3226#include "content/common/notification_registrar.h"
[email protected]15a5fa52011-03-10 20:16:0427#include "content/common/property_bag.h"
[email protected]60916042011-03-19 00:43:3628#include "content/common/renderer_preferences.h"
[email protected]0dd3a0ab2011-02-18 08:17:4429#include "net/base/load_states.h"
[email protected]232a5812011-03-04 22:42:0830#include "net/base/network_change_notifier.h"
[email protected]0dd3a0ab2011-02-18 08:17:4431#include "ui/gfx/native_widget_types.h"
32
33#if defined(OS_WIN)
34#include "base/win/scoped_handle.h"
35#endif
36
37namespace gfx {
38class Rect;
39}
40
[email protected]0dd3a0ab2011-02-18 08:17:4441class Extension;
[email protected]0dd3a0ab2011-02-18 08:17:4442class LoadNotificationDetails;
[email protected]0dd3a0ab2011-02-18 08:17:4443class Profile;
[email protected]ddb85052011-05-18 14:40:2744struct RendererPreferences;
[email protected]0dd3a0ab2011-02-18 08:17:4445class RenderViewHost;
46class SessionStorageNamespace;
47class SiteInstance;
48class SkBitmap;
[email protected]0dd3a0ab2011-02-18 08:17:4449class TabContentsDelegate;
50class TabContentsObserver;
[email protected]0dd3a0ab2011-02-18 08:17:4451class TabContentsView;
[email protected]8b0d7542011-05-16 19:36:5852struct ThumbnailScore;
[email protected]ddb85052011-05-18 14:40:2753class URLPattern;
[email protected]0dd3a0ab2011-02-18 08:17:4454struct ViewHostMsg_FrameNavigate_Params;
[email protected]0dd3a0ab2011-02-18 08:17:4455struct WebPreferences;
[email protected]ddb85052011-05-18 14:40:2756class WebUI;
[email protected]0dd3a0ab2011-02-18 08:17:4457
58// Describes what goes in the main content area of a tab. TabContents is
59// the only type of TabContents, and these should be merged together.
60class TabContents : public PageNavigator,
61 public NotificationObserver,
62 public RenderViewHostDelegate,
63 public RenderViewHostManager::Delegate,
[email protected]3ab9cb82011-06-03 18:02:0764 public content::JavaScriptDialogDelegate,
[email protected]232a5812011-03-04 22:42:0865 public net::NetworkChangeNotifier::OnlineStateObserver {
[email protected]0dd3a0ab2011-02-18 08:17:4466 public:
67 // Flags passed to the TabContentsDelegate.NavigationStateChanged to tell it
68 // what has changed. Combine them to update more than one thing.
69 enum InvalidateTypes {
70 INVALIDATE_URL = 1 << 0, // The URL has changed.
71 INVALIDATE_TAB = 1 << 1, // The favicon, app icon, or crashed
72 // state changed.
73 INVALIDATE_LOAD = 1 << 2, // The loading state has changed.
74 INVALIDATE_PAGE_ACTIONS = 1 << 3, // Page action icons have changed.
[email protected]93f230e02011-06-01 14:40:0075 INVALIDATE_TITLE = 1 << 4, // The title changed.
[email protected]0dd3a0ab2011-02-18 08:17:4476 };
77
78 // |base_tab_contents| is used if we want to size the new tab contents view
79 // based on an existing tab contents view. This can be NULL if not needed.
80 //
81 // The session storage namespace parameter allows multiple render views and
82 // tab contentses to share the same session storage (part of the WebStorage
83 // spec) space. This is useful when restoring tabs, but most callers should
84 // pass in NULL which will cause a new SessionStorageNamespace to be created.
85 TabContents(Profile* profile,
86 SiteInstance* site_instance,
87 int routing_id,
88 const TabContents* base_tab_contents,
89 SessionStorageNamespace* session_storage_namespace);
90 virtual ~TabContents();
91
92 // Intrinsic tab state -------------------------------------------------------
93
94 // Returns the property bag for this tab contents, where callers can add
95 // extra data they may wish to associate with the tab. Returns a pointer
96 // rather than a reference since the PropertyAccessors expect this.
97 const PropertyBag* property_bag() const { return &property_bag_; }
98 PropertyBag* property_bag() { return &property_bag_; }
99
100 TabContentsDelegate* delegate() const { return delegate_; }
[email protected]1de2b8b2011-06-29 19:38:46101 void set_delegate(TabContentsDelegate* delegate);
[email protected]0dd3a0ab2011-02-18 08:17:44102
103 // Gets the controller for this tab contents.
104 NavigationController& controller() { return controller_; }
105 const NavigationController& controller() const { return controller_; }
106
107 // Returns the user profile associated with this TabContents (via the
108 // NavigationController).
109 Profile* profile() const { return controller_.profile(); }
110
111 // Returns true if contains content rendered by an extension.
112 bool HostsExtension() const;
113
[email protected]0dd3a0ab2011-02-18 08:17:44114 // Return the currently active RenderProcessHost and RenderViewHost. Each of
115 // these may change over time.
116 RenderProcessHost* GetRenderProcessHost() const;
117 RenderViewHost* render_view_host() const {
118 return render_manager_.current_host();
119 }
120
[email protected]93f230e02011-06-01 14:40:00121 WebUI* committed_web_ui() const {
122 return render_manager_.web_ui();
123 }
124
[email protected]0dd3a0ab2011-02-18 08:17:44125 WebUI* web_ui() const {
126 return render_manager_.web_ui() ? render_manager_.web_ui()
127 : render_manager_.pending_web_ui();
128 }
129
130 // Returns the currently active RenderWidgetHostView. This may change over
131 // time and can be NULL (during setup and teardown).
132 RenderWidgetHostView* GetRenderWidgetHostView() const {
133 return render_manager_.GetRenderWidgetHostView();
134 }
135
136 // The TabContentsView will never change and is guaranteed non-NULL.
137 TabContentsView* view() const {
138 return view_.get();
139 }
140
[email protected]0dd3a0ab2011-02-18 08:17:44141 // Tab navigation state ------------------------------------------------------
142
143 // Returns the current navigation properties, which if a navigation is
144 // pending may be provisional (e.g., the navigation could result in a
145 // download, in which case the URL would revert to what it was previously).
146 virtual const GURL& GetURL() const;
147 virtual const string16& GetTitle() const;
148
149 // The max PageID of any page that this TabContents has loaded. PageIDs
150 // increase with each new page that is loaded by a tab. If this is a
151 // TabContents, then the max PageID is kept separately on each SiteInstance.
152 // Returns -1 if no PageIDs have yet been seen.
153 int32 GetMaxPageID();
154
155 // Updates the max PageID to be at least the given PageID.
156 void UpdateMaxPageID(int32 page_id);
157
158 // Returns the site instance associated with the current page. By default,
159 // there is no site instance. TabContents overrides this to provide proper
160 // access to its site instance.
161 virtual SiteInstance* GetSiteInstance() const;
162
163 // Defines whether this tab's URL should be displayed in the browser's URL
164 // bar. Normally this is true so you can see the URL. This is set to false
165 // for the new tab page and related pages so that the URL bar is empty and
166 // the user is invited to type into it.
167 virtual bool ShouldDisplayURL();
168
[email protected]0dd3a0ab2011-02-18 08:17:44169 // Return whether this tab contents is loading a resource.
170 bool is_loading() const { return is_loading_; }
171
172 // Returns whether this tab contents is waiting for a first-response for the
173 // main resource of the page. This controls whether the throbber state is
174 // "waiting" or "loading."
175 bool waiting_for_response() const { return waiting_for_response_; }
176
177 net::LoadState load_state() const { return load_state_; }
178 string16 load_state_host() const { return load_state_host_; }
179 uint64 upload_size() const { return upload_size_; }
180 uint64 upload_position() const { return upload_position_; }
181
182 const std::string& encoding() const { return encoding_; }
183 void set_encoding(const std::string& encoding);
184 void reset_encoding() {
185 encoding_.clear();
186 }
187
[email protected]0dd3a0ab2011-02-18 08:17:44188 bool displayed_insecure_content() const {
189 return displayed_insecure_content_;
190 }
191
192 // Internal state ------------------------------------------------------------
193
194 // This flag indicates whether the tab contents is currently being
195 // screenshotted by the DraggedTabController.
196 bool capturing_contents() const { return capturing_contents_; }
197 void set_capturing_contents(bool cap) { capturing_contents_ = cap; }
198
199 // Indicates whether this tab should be considered crashed. The setter will
200 // also notify the delegate when the flag is changed.
201 bool is_crashed() const {
202 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
203 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
204 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
205 }
206 base::TerminationStatus crashed_status() const { return crashed_status_; }
207 int crashed_error_code() const { return crashed_error_code_; }
208 void SetIsCrashed(base::TerminationStatus status, int error_code);
209
[email protected]0dd3a0ab2011-02-18 08:17:44210 // Whether the tab is in the process of being destroyed.
211 // Added as a tentative work-around for focus related bug #4633. This allows
212 // us not to store focus when a tab is being closed.
213 bool is_being_destroyed() const { return is_being_destroyed_; }
214
215 // Convenience method for notifying the delegate of a navigation state
216 // change. See TabContentsDelegate.
217 void NotifyNavigationStateChanged(unsigned changed_flags);
218
219 // Invoked when the tab contents becomes selected. If you override, be sure
220 // and invoke super's implementation.
221 virtual void DidBecomeSelected();
222 base::TimeTicks last_selected_time() const {
223 return last_selected_time_;
224 }
225
226 // Invoked when the tab contents becomes hidden.
227 // NOTE: If you override this, call the superclass version too!
228 virtual void WasHidden();
229
230 // Activates this contents within its containing window, bringing that window
231 // to the foreground if necessary.
232 void Activate();
233
234 // Deactivates this contents by deactivating its containing window.
235 void Deactivate();
236
237 // TODO(brettw) document these.
238 virtual void ShowContents();
239 virtual void HideContents();
240
241 // Returns true if the before unload and unload listeners need to be
242 // fired. The value of this changes over time. For example, if true and the
243 // before unload listener is executed and allows the user to exit, then this
244 // returns false.
245 bool NeedToFireBeforeUnload();
246
247#ifdef UNIT_TEST
248 // Expose the render manager for testing.
249 RenderViewHostManager* render_manager() { return &render_manager_; }
250#endif
251
252 // In the underlying RenderViewHostManager, swaps in the provided
253 // RenderViewHost to replace the current RenderViewHost. The current RVH
254 // will be shutdown and ultimately deleted.
255 void SwapInRenderViewHost(RenderViewHost* rvh);
256
257 // Commands ------------------------------------------------------------------
258
259 // Implementation of PageNavigator.
260 virtual void OpenURL(const GURL& url, const GURL& referrer,
261 WindowOpenDisposition disposition,
262 PageTransition::Type transition);
263
264 // Called by the NavigationController to cause the TabContents to navigate to
265 // the current pending entry. The NavigationController should be called back
[email protected]9a7e68c2011-05-26 17:35:50266 // with RendererDidNavigate on success or DiscardPendingEntry on failure.
267 // The callbacks can be inside of this function, or at some future time.
[email protected]0dd3a0ab2011-02-18 08:17:44268 //
269 // The entry has a PageID of -1 if newly created (corresponding to navigation
270 // to a new URL).
271 //
272 // If this method returns false, then the navigation is discarded (equivalent
273 // to calling DiscardPendingEntry on the NavigationController).
274 virtual bool NavigateToPendingEntry(
275 NavigationController::ReloadType reload_type);
276
277 // Stop any pending navigation.
278 virtual void Stop();
279
[email protected]0dd3a0ab2011-02-18 08:17:44280 // Creates a new TabContents with the same state as this one. The returned
281 // heap-allocated pointer is owned by the caller.
282 virtual TabContents* Clone();
283
284 // Shows the page info.
285 void ShowPageInfo(const GURL& url,
286 const NavigationEntry::SSLStatus& ssl,
287 bool show_history);
288
[email protected]0dd3a0ab2011-02-18 08:17:44289 // Window management ---------------------------------------------------------
290
291 // Create a new window constrained to this TabContents' clip and visibility.
292 // The window is initialized by using the supplied delegate to obtain basic
293 // window characteristics, and the supplied view for the content. Note that
294 // the returned ConstrainedWindow might not yet be visible.
295 ConstrainedWindow* CreateConstrainedDialog(
296 ConstrainedWindowDelegate* delegate);
297
[email protected]473174942011-04-19 22:52:35298 // Adds a new tab or window with the given already-created contents.
[email protected]e7cfdbd2011-04-22 14:41:37299 void AddNewContents(TabContents* new_contents,
300 WindowOpenDisposition disposition,
301 const gfx::Rect& initial_pos,
302 bool user_gesture);
[email protected]0dd3a0ab2011-02-18 08:17:44303
304 // Returns the number of constrained windows in this tab. Used by tests.
305 size_t constrained_window_count() { return child_windows_.size(); }
306
307 typedef std::deque<ConstrainedWindow*> ConstrainedWindowList;
308
309 // Return an iterator for the first constrained window in this tab contents.
310 ConstrainedWindowList::iterator constrained_window_begin()
311 { return child_windows_.begin(); }
312
313 // Return an iterator for the last constrained window in this tab contents.
314 ConstrainedWindowList::iterator constrained_window_end()
315 { return child_windows_.end(); }
316
317 // Views and focus -----------------------------------------------------------
318 // TODO(brettw): Most of these should be removed and the caller should call
319 // the view directly.
320
321 // Returns the actual window that is focused when this TabContents is shown.
322 gfx::NativeView GetContentNativeView() const;
323
324 // Returns the NativeView associated with this TabContents. Outside of
325 // automation in the context of the UI, this is required to be implemented.
326 gfx::NativeView GetNativeView() const;
327
328 // Returns the bounds of this TabContents in the screen coordinate system.
329 void GetContainerBounds(gfx::Rect *out) const;
330
331 // Makes the tab the focused window.
332 void Focus();
333
334 // Focuses the first (last if |reverse| is true) element in the page.
335 // Invoked when this tab is getting the focus through tab traversal (|reverse|
336 // is true when using Shift-Tab).
337 void FocusThroughTabTraversal(bool reverse);
338
339 // These next two functions are declared on RenderViewHostManager::Delegate
340 // but also accessed directly by other callers.
341
342 // Returns true if the location bar should be focused by default rather than
343 // the page contents. The view calls this function when the tab is focused
344 // to see what it should do.
345 virtual bool FocusLocationBarByDefault();
346
347 // Focuses the location bar.
348 virtual void SetFocusToLocationBar(bool select_all);
349
350 // Creates a view and sets the size for the specified RVH.
351 virtual void CreateViewAndSetSizeForRVH(RenderViewHost* rvh);
352
[email protected]0dd3a0ab2011-02-18 08:17:44353 // Toolbars and such ---------------------------------------------------------
354
[email protected]0dd3a0ab2011-02-18 08:17:44355 // Called when a ConstrainedWindow we own is about to be closed.
356 void WillClose(ConstrainedWindow* window);
357
[email protected]0dd3a0ab2011-02-18 08:17:44358 // Interstitials -------------------------------------------------------------
359
360 // Various other systems need to know about our interstitials.
361 bool showing_interstitial_page() const {
362 return render_manager_.interstitial_page() != NULL;
363 }
364
365 // Sets the passed passed interstitial as the currently showing interstitial.
366 // |interstitial_page| should be non NULL (use the remove_interstitial_page
367 // method to unset the interstitial) and no interstitial page should be set
368 // when there is already a non NULL interstitial page set.
369 void set_interstitial_page(InterstitialPage* interstitial_page) {
370 render_manager_.set_interstitial_page(interstitial_page);
371 }
372
373 // Unsets the currently showing interstitial.
374 void remove_interstitial_page() {
375 render_manager_.remove_interstitial_page();
376 }
377
378 // Returns the currently showing interstitial, NULL if no interstitial is
379 // showing.
380 InterstitialPage* interstitial_page() const {
381 return render_manager_.interstitial_page();
382 }
383
384 // Misc state & callbacks ----------------------------------------------------
385
[email protected]0dd3a0ab2011-02-18 08:17:44386 // Returns true if the active NavigationEntry's page_id equals page_id.
387 bool IsActiveEntry(int32 page_id);
388
389 const std::string& contents_mime_type() const {
390 return contents_mime_type_;
391 }
392
393 // Returns true if this TabContents will notify about disconnection.
394 bool notify_disconnection() const { return notify_disconnection_; }
395
396 // Override the encoding and reload the page by sending down
397 // ViewMsg_SetPageEncoding to the renderer. |UpdateEncoding| is kinda
398 // the opposite of this, by which 'browser' is notified of
399 // the encoding of the current tab from 'renderer' (determined by
400 // auto-detect, http header, meta, bom detection, etc).
401 void SetOverrideEncoding(const std::string& encoding);
402
403 // Remove any user-defined override encoding and reload by sending down
404 // ViewMsg_ResetPageEncodingToDefault to the renderer.
405 void ResetOverrideEncoding();
406
[email protected]0dd3a0ab2011-02-18 08:17:44407 RendererPreferences* GetMutableRendererPrefs() {
408 return &renderer_preferences_;
409 }
410
[email protected]1fd1a502011-03-30 16:55:56411 void set_opener_web_ui_type(WebUI::TypeID opener_web_ui_type) {
[email protected]0dd3a0ab2011-02-18 08:17:44412 opener_web_ui_type_ = opener_web_ui_type;
413 }
414
[email protected]0dd3a0ab2011-02-18 08:17:44415 // Set the time when we started to create the new tab page. This time is
416 // from before we created this TabContents.
417 void set_new_tab_start_time(const base::TimeTicks& time) {
418 new_tab_start_time_ = time;
419 }
[email protected]763ec4ca2011-04-29 15:48:12420 base::TimeTicks new_tab_start_time() const { return new_tab_start_time_; }
[email protected]0dd3a0ab2011-02-18 08:17:44421
422 // Notification that tab closing has started. This can be called multiple
423 // times, subsequent calls are ignored.
424 void OnCloseStarted();
425
[email protected]0dd3a0ab2011-02-18 08:17:44426 // Returns true if underlying TabContentsView should accept drag-n-drop.
427 bool ShouldAcceptDragAndDrop() const;
428
429 // A render view-originated drag has ended. Informs the render view host and
430 // tab contents delegate.
431 void SystemDragEnded();
432
433 // Indicates if this tab was explicitly closed by the user (control-w, close
434 // tab menu item...). This is false for actions that indirectly close the tab,
435 // such as closing the window. The setter is maintained by TabStripModel, and
436 // the getter only useful from within TAB_CLOSED notification
437 void set_closed_by_user_gesture(bool value) {
438 closed_by_user_gesture_ = value;
439 }
440 bool closed_by_user_gesture() const { return closed_by_user_gesture_; }
441
[email protected]3ab9cb82011-06-03 18:02:07442 // Overridden from JavaScriptDialogDelegate:
443 virtual void OnDialogClosed(IPC::Message* reply_msg,
444 bool success,
445 const string16& user_input) OVERRIDE;
446 virtual gfx::NativeWindow GetDialogRootWindow() OVERRIDE;
[email protected]a1e97f02011-06-30 14:04:34447 virtual void OnDialogShown() OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44448
449 // The BookmarkDragDelegate is used to forward bookmark drag and drop events
450 // to extensions.
451 virtual RenderViewHostDelegate::BookmarkDrag* GetBookmarkDragDelegate();
452
453 // It is up to callers to call SetBookmarkDragDelegate(NULL) when
454 // |bookmark_drag| is deleted since this class does not take ownership of
455 // |bookmark_drag|.
456 virtual void SetBookmarkDragDelegate(
457 RenderViewHostDelegate::BookmarkDrag* bookmark_drag);
458
[email protected]0dd3a0ab2011-02-18 08:17:44459 // Gets the zoom level for this tab.
460 double GetZoomLevel() const;
461
462 // Gets the zoom percent for this tab.
463 int GetZoomPercent(bool* enable_increment, bool* enable_decrement);
464
[email protected]0dd3a0ab2011-02-18 08:17:44465 // Opens view-source tab for this contents.
466 void ViewSource();
467
[email protected]932b7a12011-03-09 12:50:27468 void ViewFrameSource(const GURL& url,
469 const std::string& content_state);
470
[email protected]0dd3a0ab2011-02-18 08:17:44471 // Gets the minimum/maximum zoom percent.
472 int minimum_zoom_percent() const { return minimum_zoom_percent_; }
473 int maximum_zoom_percent() const { return maximum_zoom_percent_; }
474
475 int content_restrictions() const { return content_restrictions_; }
[email protected]c40d6232011-03-25 00:16:21476 void SetContentRestrictions(int restrictions);
[email protected]0dd3a0ab2011-02-18 08:17:44477
[email protected]1fd1a502011-03-30 16:55:56478 // Query the WebUIFactory for the TypeID for the current URL.
479 WebUI::TypeID GetWebUITypeForCurrentState();
480
[email protected]b375c5d2011-05-03 21:15:04481 // Returns the WebUI for the current state of the tab. This will either be
482 // the pending WebUI, the committed WebUI, or NULL.
483 WebUI* GetWebUIForCurrentState();
484
[email protected]0dd3a0ab2011-02-18 08:17:44485 protected:
[email protected]553602e12011-04-05 17:01:18486 friend class TabContentsObserver;
[email protected]553602e12011-04-05 17:01:18487
488 // Add and remove observers for page navigation notifications. Adding or
489 // removing multiple times has no effect. The order in which notifications
490 // are sent to observers is undefined. Clients must be sure to remove the
491 // observer before they go away.
492 void AddObserver(TabContentsObserver* observer);
493 void RemoveObserver(TabContentsObserver* observer);
494
[email protected]e7cfdbd2011-04-22 14:41:37495 // From RenderViewHostDelegate.
[email protected]0dd3a0ab2011-02-18 08:17:44496 virtual bool OnMessageReceived(const IPC::Message& message);
497
498 private:
499 friend class NavigationController;
500 // Used to access the child_windows_ (ConstrainedWindowList) for testing
501 // automation purposes.
502 friend class TestingAutomationProvider;
503
504 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, NoJSMessageOnInterstitials);
505 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, UpdateTitle);
506 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, CrossSiteCantPreemptAfterUnload);
[email protected]aed59602011-02-28 22:57:33507 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, ConstrainedWindows);
[email protected]0dd3a0ab2011-02-18 08:17:44508 FRIEND_TEST_ALL_PREFIXES(FormStructureBrowserTest, HTMLFiles);
509 FRIEND_TEST_ALL_PREFIXES(NavigationControllerTest, HistoryNavigate);
510 FRIEND_TEST_ALL_PREFIXES(RenderViewHostManagerTest, PageDoesBackAndReload);
511
512 // Temporary until the view/contents separation is complete.
513 friend class TabContentsView;
[email protected]9a56a0d2011-05-13 19:03:31514#if defined(TOOLKIT_VIEWS)
[email protected]7e2cef52011-04-11 21:47:23515 friend class TabContentsViewViews;
[email protected]0dd3a0ab2011-02-18 08:17:44516#elif defined(OS_MACOSX)
517 friend class TabContentsViewMac;
518#elif defined(TOOLKIT_USES_GTK)
519 friend class TabContentsViewGtk;
520#endif
521
522 // So InterstitialPage can access SetIsLoading.
523 friend class InterstitialPage;
524
525 // TODO(brettw) TestTabContents shouldn't exist!
526 friend class TestTabContents;
527
[email protected]0dd3a0ab2011-02-18 08:17:44528 // Add all the TabContentObservers.
529 void AddObservers();
530
531 // Message handlers.
532 void OnDidStartProvisionalLoadForFrame(int64 frame_id,
533 bool main_frame,
[email protected]eacb080b2011-05-22 19:40:26534 bool has_opener_set,
[email protected]0dd3a0ab2011-02-18 08:17:44535 const GURL& url);
536 void OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]eacb080b2011-05-22 19:40:26537 bool has_opener_set,
[email protected]0dd3a0ab2011-02-18 08:17:44538 const GURL& source_url,
539 const GURL& target_url);
540 void OnDidFailProvisionalLoadWithError(int64 frame_id,
541 bool main_frame,
542 int error_code,
543 const GURL& url,
544 bool showing_repost_interstitial);
545 void OnDidLoadResourceFromMemoryCache(const GURL& url,
546 const std::string& security_info);
547 void OnDidDisplayInsecureContent();
548 void OnDidRunInsecureContent(const std::string& security_origin,
549 const GURL& target_url);
550 void OnDocumentLoadedInFrame(int64 frame_id);
551 void OnDidFinishLoad(int64 frame_id);
552 void OnUpdateContentRestrictions(int restrictions);
[email protected]0dd3a0ab2011-02-18 08:17:44553 void OnGoToEntryAtOffset(int offset);
[email protected]216813952011-05-19 22:21:26554 void OnUpdateZoomLimits(int minimum_percent,
555 int maximum_percent,
556 bool remember);
557 void OnFocusedNodeChanged(bool is_editable_node);
[email protected]0dd3a0ab2011-02-18 08:17:44558
559 // Changes the IsLoading state and notifies delegate as needed
560 // |details| is used to provide details on the load that just finished
561 // (but can be null if not applicable). Can be overridden.
562 void SetIsLoading(bool is_loading,
563 LoadNotificationDetails* details);
564
[email protected]0dd3a0ab2011-02-18 08:17:44565 // Called by derived classes to indicate that we're no longer waiting for a
566 // response. This won't actually update the throbber, but it will get picked
567 // up at the next animation step if the throbber is going.
568 void SetNotWaitingForResponse() { waiting_for_response_ = false; }
569
570 ConstrainedWindowList child_windows_;
571
[email protected]0dd3a0ab2011-02-18 08:17:44572 // Navigation helpers --------------------------------------------------------
573 //
574 // These functions are helpers for Navigate() and DidNavigate().
575
576 // Handles post-navigation tasks in DidNavigate AFTER the entry has been
577 // committed to the navigation controller. Note that the navigation entry is
578 // not provided since it may be invalid/changed after being committed. The
579 // current navigation entry is in the NavigationController at this point.
580 void DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:13581 const content::LoadCommittedDetails& details,
[email protected]0dd3a0ab2011-02-18 08:17:44582 const ViewHostMsg_FrameNavigate_Params& params);
583 void DidNavigateAnyFramePostCommit(
584 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:13585 const content::LoadCommittedDetails& details,
[email protected]0dd3a0ab2011-02-18 08:17:44586 const ViewHostMsg_FrameNavigate_Params& params);
587
588 // Closes all constrained windows.
589 void CloseConstrainedWindows();
590
[email protected]0dd3a0ab2011-02-18 08:17:44591 // If our controller was restored and the page id is > than the site
592 // instance's page id, the site instances page id is updated as well as the
593 // renderers max page id.
594 void UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
595 RenderViewHost* rvh);
596
[email protected]0dd3a0ab2011-02-18 08:17:44597 // Saves the given title to the navigation entry and does associated work. It
598 // will update history and the view for the new title, and also synthesize
599 // titles for file URLs that have none (so we require that the URL of the
600 // entry already be set).
601 //
602 // This is used as the backend for state updates, which include a new title,
603 // or the dedicated set title message. It returns true if the new title is
604 // different and was therefore updated.
[email protected]6b2f7a82011-04-25 19:30:51605 bool UpdateTitleForEntry(NavigationEntry* entry, const std::wstring& title);
[email protected]0dd3a0ab2011-02-18 08:17:44606
607 // Causes the TabContents to navigate in the right renderer to |entry|, which
608 // must be already part of the entries in the navigation controller.
609 // This does not change the NavigationController state.
610 bool NavigateToEntry(const NavigationEntry& entry,
611 NavigationController::ReloadType reload_type);
612
613 // Misc non-view stuff -------------------------------------------------------
614
615 // Helper functions for sending notifications.
616 void NotifySwapped();
617 void NotifyConnected();
618 void NotifyDisconnected();
619
[email protected]0dd3a0ab2011-02-18 08:17:44620 // RenderViewHostDelegate ----------------------------------------------------
621
622 // RenderViewHostDelegate implementation.
623 virtual RenderViewHostDelegate::View* GetViewDelegate();
624 virtual RenderViewHostDelegate::RendererManagement*
625 GetRendererManagementDelegate();
[email protected]0dd3a0ab2011-02-18 08:17:44626 virtual TabContents* GetAsTabContents();
627 virtual ViewType::Type GetRenderViewType() const;
[email protected]0dd3a0ab2011-02-18 08:17:44628 virtual void RenderViewCreated(RenderViewHost* render_view_host);
629 virtual void RenderViewReady(RenderViewHost* render_view_host);
630 virtual void RenderViewGone(RenderViewHost* render_view_host,
631 base::TerminationStatus status,
632 int error_code);
633 virtual void RenderViewDeleted(RenderViewHost* render_view_host);
634 virtual void DidNavigate(RenderViewHost* render_view_host,
635 const ViewHostMsg_FrameNavigate_Params& params);
636 virtual void UpdateState(RenderViewHost* render_view_host,
637 int32 page_id,
638 const std::string& state);
[email protected]6b2f7a82011-04-25 19:30:51639 virtual void UpdateTitle(RenderViewHost* render_view_host,
640 int32 page_id,
641 const std::wstring& title);
[email protected]0dd3a0ab2011-02-18 08:17:44642 virtual void UpdateEncoding(RenderViewHost* render_view_host,
643 const std::string& encoding);
644 virtual void UpdateTargetURL(int32 page_id, const GURL& url);
[email protected]0dd3a0ab2011-02-18 08:17:44645 virtual void UpdateInspectorSetting(const std::string& key,
646 const std::string& value);
647 virtual void ClearInspectorSettings();
648 virtual void Close(RenderViewHost* render_view_host);
649 virtual void RequestMove(const gfx::Rect& new_bounds);
650 virtual void DidStartLoading();
651 virtual void DidStopLoading();
[email protected]c95fa8b2011-04-28 20:26:16652 virtual void DidCancelLoading();
[email protected]0dd3a0ab2011-02-18 08:17:44653 virtual void DidChangeLoadProgress(double progress);
654 virtual void DocumentOnLoadCompletedInMainFrame(
655 RenderViewHost* render_view_host,
656 int32 page_id);
657 virtual void RequestOpenURL(const GURL& url, const GURL& referrer,
658 WindowOpenDisposition disposition);
[email protected]992db4c2011-05-12 15:37:15659 virtual void RunJavaScriptMessage(const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:41660 const string16& message,
661 const string16& default_prompt,
[email protected]0dd3a0ab2011-02-18 08:17:44662 const GURL& frame_url,
663 const int flags,
664 IPC::Message* reply_msg,
[email protected]3ab9cb82011-06-03 18:02:07665 bool* did_suppress_message) OVERRIDE;
[email protected]992db4c2011-05-12 15:37:15666 virtual void RunBeforeUnloadConfirm(const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:41667 const string16& message,
[email protected]0dd3a0ab2011-02-18 08:17:44668 IPC::Message* reply_msg);
[email protected]0dd3a0ab2011-02-18 08:17:44669 virtual RendererPreferences GetRendererPrefs(Profile* profile) const;
670 virtual WebPreferences GetWebkitPrefs();
671 virtual void OnUserGesture();
672 virtual void OnIgnoredUIEvent();
673 virtual void OnCrossSiteResponse(int new_render_process_host_id,
674 int new_request_id);
675 virtual void RendererUnresponsive(RenderViewHost* render_view_host,
676 bool is_during_unload);
677 virtual void RendererResponsive(RenderViewHost* render_view_host);
678 virtual void LoadStateChanged(const GURL& url, net::LoadState load_state,
679 uint64 upload_position, uint64 upload_size);
[email protected]0dd3a0ab2011-02-18 08:17:44680 virtual void WorkerCrashed();
681
682 // RenderViewHostManager::Delegate -------------------------------------------
683
684 // Blocks/unblocks interaction with renderer process.
685 void BlockTabContent(bool blocked);
686
687 virtual void BeforeUnloadFiredFromRenderManager(
688 bool proceed,
689 bool* proceed_to_fire_unload);
690 virtual void DidStartLoadingFromRenderManager(
691 RenderViewHost* render_view_host);
692 virtual void RenderViewGoneFromRenderManager(
693 RenderViewHost* render_view_host);
694 virtual void UpdateRenderViewSizeForRenderManager();
695 virtual void NotifySwappedFromRenderManager();
696 virtual NavigationController& GetControllerForRenderManager();
697 virtual WebUI* CreateWebUIForRenderManager(const GURL& url);
698 virtual NavigationEntry* GetLastCommittedNavigationEntryForRenderManager();
699
700 // Initializes the given renderer if necessary and creates the view ID
701 // corresponding to this view host. If this method is not called and the
702 // process is not shared, then the TabContents will act as though the renderer
703 // is not running (i.e., it will render "sad tab"). This method is
704 // automatically called from LoadURL.
705 //
706 // If you are attaching to an already-existing RenderView, you should call
707 // InitWithExistingID.
708 virtual bool CreateRenderViewForRenderManager(
709 RenderViewHost* render_view_host);
710
711 // NotificationObserver ------------------------------------------------------
712
713 virtual void Observe(NotificationType type,
714 const NotificationSource& source,
715 const NotificationDetails& details);
716
[email protected]232a5812011-03-04 22:42:08717 // NetworkChangeNotifier::OnlineStateObserver:
718 virtual void OnOnlineStateChanged(bool online);
719
[email protected]aed59602011-02-28 22:57:33720 // Adds the given window to the list of child windows. The window will notify
721 // via WillClose() when it is being destroyed.
722 void AddConstrainedDialog(ConstrainedWindow* window);
723
[email protected]81898992011-06-14 22:15:00724 // Stores random bits of data for others to associate with this object.
725 // WARNING: this needs to be deleted after NavigationController.
726 PropertyBag property_bag_;
727
[email protected]0dd3a0ab2011-02-18 08:17:44728 // Data for core operation ---------------------------------------------------
729
730 // Delegate for notifying our owner about stuff. Not owned by us.
731 TabContentsDelegate* delegate_;
732
733 // Handles the back/forward list and loading.
734 NavigationController controller_;
735
736 // The corresponding view.
737 scoped_ptr<TabContentsView> view_;
738
739 // Helper classes ------------------------------------------------------------
740
741 // Manages creation and swapping of render views.
742 RenderViewHostManager render_manager_;
743
[email protected]0dd3a0ab2011-02-18 08:17:44744 // Registers and unregisters us for notifications.
745 NotificationRegistrar registrar_;
746
[email protected]0dd3a0ab2011-02-18 08:17:44747 // Handles drag and drop event forwarding to extensions.
748 BookmarkDrag* bookmark_drag_;
749
[email protected]0dd3a0ab2011-02-18 08:17:44750 // Data for loading state ----------------------------------------------------
751
752 // Indicates whether we're currently loading a resource.
753 bool is_loading_;
754
755 // Indicates if the tab is considered crashed.
756 base::TerminationStatus crashed_status_;
757 int crashed_error_code_;
758
759 // See waiting_for_response() above.
760 bool waiting_for_response_;
761
762 // Indicates the largest PageID we've seen. This field is ignored if we are
763 // a TabContents, in which case the max page ID is stored separately with
764 // each SiteInstance.
765 // TODO(brettw) this seems like it can be removed according to the comment.
766 int32 max_page_id_;
767
768 // System time at which the current load was started.
769 base::TimeTicks current_load_start_;
770
771 // The current load state and the URL associated with it.
772 net::LoadState load_state_;
773 string16 load_state_host_;
774 // Upload progress, for displaying in the status bar.
775 // Set to zero when there is no significant upload happening.
776 uint64 upload_size_;
777 uint64 upload_position_;
778
779 // Data for current page -----------------------------------------------------
780
[email protected]987fc3a2011-05-26 14:18:09781 // When a title cannot be taken from any entry, this title will be used.
782 string16 page_title_when_no_navigation_entry_;
783
[email protected]0dd3a0ab2011-02-18 08:17:44784 // When a navigation occurs, we record its contents MIME type. It can be
785 // used to check whether we can do something for some special contents.
786 std::string contents_mime_type_;
787
788 // Character encoding.
789 std::string encoding_;
790
[email protected]0dd3a0ab2011-02-18 08:17:44791 // True if this is a secure page which displayed insecure content.
792 bool displayed_insecure_content_;
793
[email protected]0dd3a0ab2011-02-18 08:17:44794 // Data for misc internal state ----------------------------------------------
795
796 // See capturing_contents() above.
797 bool capturing_contents_;
798
799 // See getter above.
800 bool is_being_destroyed_;
801
802 // Indicates whether we should notify about disconnection of this
803 // TabContents. This is used to ensure disconnection notifications only
804 // happen if a connection notification has happened and that they happen only
805 // once.
806 bool notify_disconnection_;
807
[email protected]0dd3a0ab2011-02-18 08:17:44808#if defined(OS_WIN)
809 // Handle to an event that's set when the page is showing a message box (or
810 // equivalent constrained window). Plugin processes check this to know if
811 // they should pump messages then.
812 base::win::ScopedHandle message_box_active_;
813#endif
814
[email protected]0dd3a0ab2011-02-18 08:17:44815 // Set to true when there is an active "before unload" dialog. When true,
816 // we've forced the throbber to start in Navigate, and we need to remember to
817 // turn it off in OnJavaScriptMessageBoxClosed if the navigation is canceled.
818 bool is_showing_before_unload_dialog_;
819
[email protected]0dd3a0ab2011-02-18 08:17:44820 // Settings that get passed to the renderer process.
821 RendererPreferences renderer_preferences_;
822
823 // If this tab was created from a renderer using window.open, this will be
824 // non-NULL and represent the WebUI of the opening renderer.
[email protected]1fd1a502011-03-30 16:55:56825 WebUI::TypeID opener_web_ui_type_;
[email protected]0dd3a0ab2011-02-18 08:17:44826
827 // The time that we started to create the new tab page.
828 base::TimeTicks new_tab_start_time_;
829
830 // The time that we started to close the tab.
831 base::TimeTicks tab_close_start_time_;
832
833 // The time that this tab was last selected.
834 base::TimeTicks last_selected_time_;
835
[email protected]0dd3a0ab2011-02-18 08:17:44836 // See description above setter.
837 bool closed_by_user_gesture_;
838
839 // Minimum/maximum zoom percent.
840 int minimum_zoom_percent_;
841 int maximum_zoom_percent_;
842 // If true, the default zoom limits have been overriden for this tab, in which
843 // case we don't want saved settings to apply to it and we don't want to
844 // remember it.
845 bool temporary_zoom_settings_;
846
847 // A list of observers notified when page state changes. Weak references.
848 ObserverList<TabContentsObserver> observers_;
849
850 // Content restrictions, used to disable print/copy etc based on content's
851 // (full-page plugins for now only) permissions.
852 int content_restrictions_;
853
[email protected]0dd3a0ab2011-02-18 08:17:44854 DISALLOW_COPY_AND_ASSIGN(TabContents);
855};
856
857#endif // CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_H_