blob: 4220e203fcddeb6d6740c36f2861c672a6255cc9 [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]0dd3a0ab2011-02-18 08:17:4417#include "chrome/browser/ui/app_modal_dialogs/js_modal_dialog.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,
64 public JavaScriptAppModalDialogDelegate,
[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_; }
101 void set_delegate(TabContentsDelegate* d) { delegate_ = d; }
102
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
386 // Set whether the contents should block javascript message boxes or not.
387 // Default is not to block any message boxes.
388 void set_suppress_javascript_messages(bool suppress_javascript_messages) {
389 suppress_javascript_messages_ = suppress_javascript_messages;
390 }
391
[email protected]0dd3a0ab2011-02-18 08:17:44392 // Returns true if the active NavigationEntry's page_id equals page_id.
393 bool IsActiveEntry(int32 page_id);
394
395 const std::string& contents_mime_type() const {
396 return contents_mime_type_;
397 }
398
399 // Returns true if this TabContents will notify about disconnection.
400 bool notify_disconnection() const { return notify_disconnection_; }
401
402 // Override the encoding and reload the page by sending down
403 // ViewMsg_SetPageEncoding to the renderer. |UpdateEncoding| is kinda
404 // the opposite of this, by which 'browser' is notified of
405 // the encoding of the current tab from 'renderer' (determined by
406 // auto-detect, http header, meta, bom detection, etc).
407 void SetOverrideEncoding(const std::string& encoding);
408
409 // Remove any user-defined override encoding and reload by sending down
410 // ViewMsg_ResetPageEncodingToDefault to the renderer.
411 void ResetOverrideEncoding();
412
[email protected]0dd3a0ab2011-02-18 08:17:44413 RendererPreferences* GetMutableRendererPrefs() {
414 return &renderer_preferences_;
415 }
416
[email protected]1fd1a502011-03-30 16:55:56417 void set_opener_web_ui_type(WebUI::TypeID opener_web_ui_type) {
[email protected]0dd3a0ab2011-02-18 08:17:44418 opener_web_ui_type_ = opener_web_ui_type;
419 }
420
[email protected]0dd3a0ab2011-02-18 08:17:44421 // Set the time when we started to create the new tab page. This time is
422 // from before we created this TabContents.
423 void set_new_tab_start_time(const base::TimeTicks& time) {
424 new_tab_start_time_ = time;
425 }
[email protected]763ec4ca2011-04-29 15:48:12426 base::TimeTicks new_tab_start_time() const { return new_tab_start_time_; }
[email protected]0dd3a0ab2011-02-18 08:17:44427
428 // Notification that tab closing has started. This can be called multiple
429 // times, subsequent calls are ignored.
430 void OnCloseStarted();
431
[email protected]0dd3a0ab2011-02-18 08:17:44432 // Returns true if underlying TabContentsView should accept drag-n-drop.
433 bool ShouldAcceptDragAndDrop() const;
434
435 // A render view-originated drag has ended. Informs the render view host and
436 // tab contents delegate.
437 void SystemDragEnded();
438
439 // Indicates if this tab was explicitly closed by the user (control-w, close
440 // tab menu item...). This is false for actions that indirectly close the tab,
441 // such as closing the window. The setter is maintained by TabStripModel, and
442 // the getter only useful from within TAB_CLOSED notification
443 void set_closed_by_user_gesture(bool value) {
444 closed_by_user_gesture_ = value;
445 }
446 bool closed_by_user_gesture() const { return closed_by_user_gesture_; }
447
448 // Overridden from JavaScriptAppModalDialogDelegate:
449 virtual void OnMessageBoxClosed(IPC::Message* reply_msg,
450 bool success,
[email protected]4f5ce842011-05-27 19:34:41451 const std::wstring& user_input);
[email protected]0dd3a0ab2011-02-18 08:17:44452 virtual void SetSuppressMessageBoxes(bool suppress_message_boxes);
453 virtual gfx::NativeWindow GetMessageBoxRootWindow();
454 virtual TabContents* AsTabContents();
455 virtual ExtensionHost* AsExtensionHost();
456
457 // The BookmarkDragDelegate is used to forward bookmark drag and drop events
458 // to extensions.
459 virtual RenderViewHostDelegate::BookmarkDrag* GetBookmarkDragDelegate();
460
461 // It is up to callers to call SetBookmarkDragDelegate(NULL) when
462 // |bookmark_drag| is deleted since this class does not take ownership of
463 // |bookmark_drag|.
464 virtual void SetBookmarkDragDelegate(
465 RenderViewHostDelegate::BookmarkDrag* bookmark_drag);
466
[email protected]0dd3a0ab2011-02-18 08:17:44467 // Gets the zoom level for this tab.
468 double GetZoomLevel() const;
469
470 // Gets the zoom percent for this tab.
471 int GetZoomPercent(bool* enable_increment, bool* enable_decrement);
472
[email protected]0dd3a0ab2011-02-18 08:17:44473 // Opens view-source tab for this contents.
474 void ViewSource();
475
[email protected]932b7a12011-03-09 12:50:27476 void ViewFrameSource(const GURL& url,
477 const std::string& content_state);
478
[email protected]0dd3a0ab2011-02-18 08:17:44479 // Gets the minimum/maximum zoom percent.
480 int minimum_zoom_percent() const { return minimum_zoom_percent_; }
481 int maximum_zoom_percent() const { return maximum_zoom_percent_; }
482
483 int content_restrictions() const { return content_restrictions_; }
[email protected]c40d6232011-03-25 00:16:21484 void SetContentRestrictions(int restrictions);
[email protected]0dd3a0ab2011-02-18 08:17:44485
[email protected]1fd1a502011-03-30 16:55:56486 // Query the WebUIFactory for the TypeID for the current URL.
487 WebUI::TypeID GetWebUITypeForCurrentState();
488
[email protected]b375c5d2011-05-03 21:15:04489 // Returns the WebUI for the current state of the tab. This will either be
490 // the pending WebUI, the committed WebUI, or NULL.
491 WebUI* GetWebUIForCurrentState();
492
[email protected]0dd3a0ab2011-02-18 08:17:44493 protected:
[email protected]553602e12011-04-05 17:01:18494 friend class TabContentsObserver;
495 friend class TabContentsObserver::Registrar;
496
497 // Add and remove observers for page navigation notifications. Adding or
498 // removing multiple times has no effect. The order in which notifications
499 // are sent to observers is undefined. Clients must be sure to remove the
500 // observer before they go away.
501 void AddObserver(TabContentsObserver* observer);
502 void RemoveObserver(TabContentsObserver* observer);
503
[email protected]e7cfdbd2011-04-22 14:41:37504 // From RenderViewHostDelegate.
[email protected]0dd3a0ab2011-02-18 08:17:44505 virtual bool OnMessageReceived(const IPC::Message& message);
506
507 private:
508 friend class NavigationController;
509 // Used to access the child_windows_ (ConstrainedWindowList) for testing
510 // automation purposes.
511 friend class TestingAutomationProvider;
512
513 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, NoJSMessageOnInterstitials);
514 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, UpdateTitle);
515 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, CrossSiteCantPreemptAfterUnload);
[email protected]aed59602011-02-28 22:57:33516 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, ConstrainedWindows);
[email protected]0dd3a0ab2011-02-18 08:17:44517 FRIEND_TEST_ALL_PREFIXES(FormStructureBrowserTest, HTMLFiles);
518 FRIEND_TEST_ALL_PREFIXES(NavigationControllerTest, HistoryNavigate);
519 FRIEND_TEST_ALL_PREFIXES(RenderViewHostManagerTest, PageDoesBackAndReload);
520
521 // Temporary until the view/contents separation is complete.
522 friend class TabContentsView;
[email protected]9a56a0d2011-05-13 19:03:31523#if defined(TOOLKIT_VIEWS)
[email protected]7e2cef52011-04-11 21:47:23524 friend class TabContentsViewViews;
[email protected]0dd3a0ab2011-02-18 08:17:44525#elif defined(OS_MACOSX)
526 friend class TabContentsViewMac;
527#elif defined(TOOLKIT_USES_GTK)
528 friend class TabContentsViewGtk;
529#endif
530
531 // So InterstitialPage can access SetIsLoading.
532 friend class InterstitialPage;
533
534 // TODO(brettw) TestTabContents shouldn't exist!
535 friend class TestTabContents;
536
[email protected]0dd3a0ab2011-02-18 08:17:44537 // Add all the TabContentObservers.
538 void AddObservers();
539
540 // Message handlers.
541 void OnDidStartProvisionalLoadForFrame(int64 frame_id,
542 bool main_frame,
[email protected]eacb080b2011-05-22 19:40:26543 bool has_opener_set,
[email protected]0dd3a0ab2011-02-18 08:17:44544 const GURL& url);
545 void OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]eacb080b2011-05-22 19:40:26546 bool has_opener_set,
[email protected]0dd3a0ab2011-02-18 08:17:44547 const GURL& source_url,
548 const GURL& target_url);
549 void OnDidFailProvisionalLoadWithError(int64 frame_id,
550 bool main_frame,
551 int error_code,
552 const GURL& url,
553 bool showing_repost_interstitial);
554 void OnDidLoadResourceFromMemoryCache(const GURL& url,
555 const std::string& security_info);
556 void OnDidDisplayInsecureContent();
557 void OnDidRunInsecureContent(const std::string& security_origin,
558 const GURL& target_url);
559 void OnDocumentLoadedInFrame(int64 frame_id);
560 void OnDidFinishLoad(int64 frame_id);
561 void OnUpdateContentRestrictions(int restrictions);
[email protected]0dd3a0ab2011-02-18 08:17:44562 void OnGoToEntryAtOffset(int offset);
[email protected]216813952011-05-19 22:21:26563 void OnUpdateZoomLimits(int minimum_percent,
564 int maximum_percent,
565 bool remember);
566 void OnFocusedNodeChanged(bool is_editable_node);
[email protected]0dd3a0ab2011-02-18 08:17:44567
568 // Changes the IsLoading state and notifies delegate as needed
569 // |details| is used to provide details on the load that just finished
570 // (but can be null if not applicable). Can be overridden.
571 void SetIsLoading(bool is_loading,
572 LoadNotificationDetails* details);
573
[email protected]0dd3a0ab2011-02-18 08:17:44574 // Called by derived classes to indicate that we're no longer waiting for a
575 // response. This won't actually update the throbber, but it will get picked
576 // up at the next animation step if the throbber is going.
577 void SetNotWaitingForResponse() { waiting_for_response_ = false; }
578
579 ConstrainedWindowList child_windows_;
580
[email protected]0dd3a0ab2011-02-18 08:17:44581 // Navigation helpers --------------------------------------------------------
582 //
583 // These functions are helpers for Navigate() and DidNavigate().
584
585 // Handles post-navigation tasks in DidNavigate AFTER the entry has been
586 // committed to the navigation controller. Note that the navigation entry is
587 // not provided since it may be invalid/changed after being committed. The
588 // current navigation entry is in the NavigationController at this point.
589 void DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:13590 const content::LoadCommittedDetails& details,
[email protected]0dd3a0ab2011-02-18 08:17:44591 const ViewHostMsg_FrameNavigate_Params& params);
592 void DidNavigateAnyFramePostCommit(
593 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:13594 const content::LoadCommittedDetails& details,
[email protected]0dd3a0ab2011-02-18 08:17:44595 const ViewHostMsg_FrameNavigate_Params& params);
596
597 // Closes all constrained windows.
598 void CloseConstrainedWindows();
599
[email protected]0dd3a0ab2011-02-18 08:17:44600 // If our controller was restored and the page id is > than the site
601 // instance's page id, the site instances page id is updated as well as the
602 // renderers max page id.
603 void UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
604 RenderViewHost* rvh);
605
[email protected]0dd3a0ab2011-02-18 08:17:44606 // Saves the given title to the navigation entry and does associated work. It
607 // will update history and the view for the new title, and also synthesize
608 // titles for file URLs that have none (so we require that the URL of the
609 // entry already be set).
610 //
611 // This is used as the backend for state updates, which include a new title,
612 // or the dedicated set title message. It returns true if the new title is
613 // different and was therefore updated.
[email protected]6b2f7a82011-04-25 19:30:51614 bool UpdateTitleForEntry(NavigationEntry* entry, const std::wstring& title);
[email protected]0dd3a0ab2011-02-18 08:17:44615
616 // Causes the TabContents to navigate in the right renderer to |entry|, which
617 // must be already part of the entries in the navigation controller.
618 // This does not change the NavigationController state.
619 bool NavigateToEntry(const NavigationEntry& entry,
620 NavigationController::ReloadType reload_type);
621
622 // Misc non-view stuff -------------------------------------------------------
623
624 // Helper functions for sending notifications.
625 void NotifySwapped();
626 void NotifyConnected();
627 void NotifyDisconnected();
628
[email protected]0dd3a0ab2011-02-18 08:17:44629 // RenderViewHostDelegate ----------------------------------------------------
630
631 // RenderViewHostDelegate implementation.
632 virtual RenderViewHostDelegate::View* GetViewDelegate();
633 virtual RenderViewHostDelegate::RendererManagement*
634 GetRendererManagementDelegate();
[email protected]0dd3a0ab2011-02-18 08:17:44635 virtual TabContents* GetAsTabContents();
636 virtual ViewType::Type GetRenderViewType() const;
637 virtual int GetBrowserWindowID() const;
638 virtual void RenderViewCreated(RenderViewHost* render_view_host);
639 virtual void RenderViewReady(RenderViewHost* render_view_host);
640 virtual void RenderViewGone(RenderViewHost* render_view_host,
641 base::TerminationStatus status,
642 int error_code);
643 virtual void RenderViewDeleted(RenderViewHost* render_view_host);
644 virtual void DidNavigate(RenderViewHost* render_view_host,
645 const ViewHostMsg_FrameNavigate_Params& params);
646 virtual void UpdateState(RenderViewHost* render_view_host,
647 int32 page_id,
648 const std::string& state);
[email protected]6b2f7a82011-04-25 19:30:51649 virtual void UpdateTitle(RenderViewHost* render_view_host,
650 int32 page_id,
651 const std::wstring& title);
[email protected]0dd3a0ab2011-02-18 08:17:44652 virtual void UpdateEncoding(RenderViewHost* render_view_host,
653 const std::string& encoding);
654 virtual void UpdateTargetURL(int32 page_id, const GURL& url);
[email protected]0dd3a0ab2011-02-18 08:17:44655 virtual void UpdateInspectorSetting(const std::string& key,
656 const std::string& value);
657 virtual void ClearInspectorSettings();
658 virtual void Close(RenderViewHost* render_view_host);
659 virtual void RequestMove(const gfx::Rect& new_bounds);
660 virtual void DidStartLoading();
661 virtual void DidStopLoading();
[email protected]c95fa8b2011-04-28 20:26:16662 virtual void DidCancelLoading();
[email protected]0dd3a0ab2011-02-18 08:17:44663 virtual void DidChangeLoadProgress(double progress);
664 virtual void DocumentOnLoadCompletedInMainFrame(
665 RenderViewHost* render_view_host,
666 int32 page_id);
667 virtual void RequestOpenURL(const GURL& url, const GURL& referrer,
668 WindowOpenDisposition disposition);
[email protected]992db4c2011-05-12 15:37:15669 virtual void RunJavaScriptMessage(const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:41670 const string16& message,
671 const string16& default_prompt,
[email protected]0dd3a0ab2011-02-18 08:17:44672 const GURL& frame_url,
673 const int flags,
674 IPC::Message* reply_msg,
675 bool* did_suppress_message);
[email protected]992db4c2011-05-12 15:37:15676 virtual void RunBeforeUnloadConfirm(const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:41677 const string16& message,
[email protected]0dd3a0ab2011-02-18 08:17:44678 IPC::Message* reply_msg);
[email protected]0dd3a0ab2011-02-18 08:17:44679 virtual RendererPreferences GetRendererPrefs(Profile* profile) const;
680 virtual WebPreferences GetWebkitPrefs();
681 virtual void OnUserGesture();
682 virtual void OnIgnoredUIEvent();
683 virtual void OnCrossSiteResponse(int new_render_process_host_id,
684 int new_request_id);
685 virtual void RendererUnresponsive(RenderViewHost* render_view_host,
686 bool is_during_unload);
687 virtual void RendererResponsive(RenderViewHost* render_view_host);
688 virtual void LoadStateChanged(const GURL& url, net::LoadState load_state,
689 uint64 upload_position, uint64 upload_size);
690 virtual bool IsExternalTabContainer() const;
[email protected]0dd3a0ab2011-02-18 08:17:44691 virtual void WorkerCrashed();
[email protected]f364d1392011-04-08 21:03:10692 virtual void RequestDesktopNotificationPermission(const GURL& source_origin,
693 int callback_context);
[email protected]0dd3a0ab2011-02-18 08:17:44694
695 // RenderViewHostManager::Delegate -------------------------------------------
696
697 // Blocks/unblocks interaction with renderer process.
698 void BlockTabContent(bool blocked);
699
700 virtual void BeforeUnloadFiredFromRenderManager(
701 bool proceed,
702 bool* proceed_to_fire_unload);
703 virtual void DidStartLoadingFromRenderManager(
704 RenderViewHost* render_view_host);
705 virtual void RenderViewGoneFromRenderManager(
706 RenderViewHost* render_view_host);
707 virtual void UpdateRenderViewSizeForRenderManager();
708 virtual void NotifySwappedFromRenderManager();
709 virtual NavigationController& GetControllerForRenderManager();
710 virtual WebUI* CreateWebUIForRenderManager(const GURL& url);
711 virtual NavigationEntry* GetLastCommittedNavigationEntryForRenderManager();
712
713 // Initializes the given renderer if necessary and creates the view ID
714 // corresponding to this view host. If this method is not called and the
715 // process is not shared, then the TabContents will act as though the renderer
716 // is not running (i.e., it will render "sad tab"). This method is
717 // automatically called from LoadURL.
718 //
719 // If you are attaching to an already-existing RenderView, you should call
720 // InitWithExistingID.
721 virtual bool CreateRenderViewForRenderManager(
722 RenderViewHost* render_view_host);
723
724 // NotificationObserver ------------------------------------------------------
725
726 virtual void Observe(NotificationType type,
727 const NotificationSource& source,
728 const NotificationDetails& details);
729
[email protected]232a5812011-03-04 22:42:08730 // NetworkChangeNotifier::OnlineStateObserver:
731 virtual void OnOnlineStateChanged(bool online);
732
[email protected]aed59602011-02-28 22:57:33733 // Adds the given window to the list of child windows. The window will notify
734 // via WillClose() when it is being destroyed.
735 void AddConstrainedDialog(ConstrainedWindow* window);
736
[email protected]0dd3a0ab2011-02-18 08:17:44737 // Data for core operation ---------------------------------------------------
738
739 // Delegate for notifying our owner about stuff. Not owned by us.
740 TabContentsDelegate* delegate_;
741
742 // Handles the back/forward list and loading.
743 NavigationController controller_;
744
745 // The corresponding view.
746 scoped_ptr<TabContentsView> view_;
747
748 // Helper classes ------------------------------------------------------------
749
750 // Manages creation and swapping of render views.
751 RenderViewHostManager render_manager_;
752
753 // Stores random bits of data for others to associate with this object.
754 PropertyBag property_bag_;
755
756 // Registers and unregisters us for notifications.
757 NotificationRegistrar registrar_;
758
[email protected]0dd3a0ab2011-02-18 08:17:44759 // Handles drag and drop event forwarding to extensions.
760 BookmarkDrag* bookmark_drag_;
761
[email protected]0dd3a0ab2011-02-18 08:17:44762 // Data for loading state ----------------------------------------------------
763
764 // Indicates whether we're currently loading a resource.
765 bool is_loading_;
766
767 // Indicates if the tab is considered crashed.
768 base::TerminationStatus crashed_status_;
769 int crashed_error_code_;
770
771 // See waiting_for_response() above.
772 bool waiting_for_response_;
773
774 // Indicates the largest PageID we've seen. This field is ignored if we are
775 // a TabContents, in which case the max page ID is stored separately with
776 // each SiteInstance.
777 // TODO(brettw) this seems like it can be removed according to the comment.
778 int32 max_page_id_;
779
780 // System time at which the current load was started.
781 base::TimeTicks current_load_start_;
782
783 // The current load state and the URL associated with it.
784 net::LoadState load_state_;
785 string16 load_state_host_;
786 // Upload progress, for displaying in the status bar.
787 // Set to zero when there is no significant upload happening.
788 uint64 upload_size_;
789 uint64 upload_position_;
790
791 // Data for current page -----------------------------------------------------
792
[email protected]987fc3a2011-05-26 14:18:09793 // When a title cannot be taken from any entry, this title will be used.
794 string16 page_title_when_no_navigation_entry_;
795
[email protected]0dd3a0ab2011-02-18 08:17:44796 // When a navigation occurs, we record its contents MIME type. It can be
797 // used to check whether we can do something for some special contents.
798 std::string contents_mime_type_;
799
800 // Character encoding.
801 std::string encoding_;
802
[email protected]0dd3a0ab2011-02-18 08:17:44803 // True if this is a secure page which displayed insecure content.
804 bool displayed_insecure_content_;
805
[email protected]0dd3a0ab2011-02-18 08:17:44806 // Data for misc internal state ----------------------------------------------
807
808 // See capturing_contents() above.
809 bool capturing_contents_;
810
811 // See getter above.
812 bool is_being_destroyed_;
813
814 // Indicates whether we should notify about disconnection of this
815 // TabContents. This is used to ensure disconnection notifications only
816 // happen if a connection notification has happened and that they happen only
817 // once.
818 bool notify_disconnection_;
819
[email protected]0dd3a0ab2011-02-18 08:17:44820#if defined(OS_WIN)
821 // Handle to an event that's set when the page is showing a message box (or
822 // equivalent constrained window). Plugin processes check this to know if
823 // they should pump messages then.
824 base::win::ScopedHandle message_box_active_;
825#endif
826
827 // The time that the last javascript message was dismissed.
828 base::TimeTicks last_javascript_message_dismissal_;
829
830 // True if the user has decided to block future javascript messages. This is
831 // reset on navigations to false on navigations.
832 bool suppress_javascript_messages_;
833
834 // Set to true when there is an active "before unload" dialog. When true,
835 // we've forced the throbber to start in Navigate, and we need to remember to
836 // turn it off in OnJavaScriptMessageBoxClosed if the navigation is canceled.
837 bool is_showing_before_unload_dialog_;
838
[email protected]0dd3a0ab2011-02-18 08:17:44839 // Settings that get passed to the renderer process.
840 RendererPreferences renderer_preferences_;
841
842 // If this tab was created from a renderer using window.open, this will be
843 // non-NULL and represent the WebUI of the opening renderer.
[email protected]1fd1a502011-03-30 16:55:56844 WebUI::TypeID opener_web_ui_type_;
[email protected]0dd3a0ab2011-02-18 08:17:44845
846 // The time that we started to create the new tab page.
847 base::TimeTicks new_tab_start_time_;
848
849 // The time that we started to close the tab.
850 base::TimeTicks tab_close_start_time_;
851
852 // The time that this tab was last selected.
853 base::TimeTicks last_selected_time_;
854
[email protected]0dd3a0ab2011-02-18 08:17:44855 // See description above setter.
856 bool closed_by_user_gesture_;
857
858 // Minimum/maximum zoom percent.
859 int minimum_zoom_percent_;
860 int maximum_zoom_percent_;
861 // If true, the default zoom limits have been overriden for this tab, in which
862 // case we don't want saved settings to apply to it and we don't want to
863 // remember it.
864 bool temporary_zoom_settings_;
865
866 // A list of observers notified when page state changes. Weak references.
867 ObserverList<TabContentsObserver> observers_;
868
869 // Content restrictions, used to disable print/copy etc based on content's
870 // (full-page plugins for now only) permissions.
871 int content_restrictions_;
872
[email protected]0dd3a0ab2011-02-18 08:17:44873 DISALLOW_COPY_AND_ASSIGN(TabContents);
874};
875
876#endif // CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_H_