blob: 4e045528135d09e9058c8df58f6c46b127fa32cb [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]6eac57a2011-07-12 21:15:0916#include "base/observer_list.h"
[email protected]0dd3a0ab2011-02-18 08:17:4417#include "base/string16.h"
[email protected]c7dd2f62011-07-18 15:57:5918#include "content/browser/download/save_package.h"
[email protected]3ab9cb82011-06-03 18:02:0719#include "content/browser/javascript_dialogs.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]15a5fa52011-03-10 20:16:0428#include "content/common/property_bag.h"
[email protected]60916042011-03-19 00:43:3629#include "content/common/renderer_preferences.h"
[email protected]0dd3a0ab2011-02-18 08:17:4430#include "net/base/load_states.h"
31#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]686493142011-07-15 21:47:2241class DownloadItem;
[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,
[email protected]0dd3a0ab2011-02-18 08:17:4461 public RenderViewHostDelegate,
62 public RenderViewHostManager::Delegate,
[email protected]6eac57a2011-07-12 21:15:0963 public content::JavaScriptDialogDelegate {
[email protected]0dd3a0ab2011-02-18 08:17:4464 public:
65 // Flags passed to the TabContentsDelegate.NavigationStateChanged to tell it
66 // what has changed. Combine them to update more than one thing.
67 enum InvalidateTypes {
68 INVALIDATE_URL = 1 << 0, // The URL has changed.
69 INVALIDATE_TAB = 1 << 1, // The favicon, app icon, or crashed
70 // state changed.
71 INVALIDATE_LOAD = 1 << 2, // The loading state has changed.
72 INVALIDATE_PAGE_ACTIONS = 1 << 3, // Page action icons have changed.
[email protected]93f230e02011-06-01 14:40:0073 INVALIDATE_TITLE = 1 << 4, // The title changed.
[email protected]0dd3a0ab2011-02-18 08:17:4474 };
75
76 // |base_tab_contents| is used if we want to size the new tab contents view
77 // based on an existing tab contents view. This can be NULL if not needed.
78 //
79 // The session storage namespace parameter allows multiple render views and
80 // tab contentses to share the same session storage (part of the WebStorage
81 // spec) space. This is useful when restoring tabs, but most callers should
82 // pass in NULL which will cause a new SessionStorageNamespace to be created.
83 TabContents(Profile* profile,
84 SiteInstance* site_instance,
85 int routing_id,
86 const TabContents* base_tab_contents,
87 SessionStorageNamespace* session_storage_namespace);
88 virtual ~TabContents();
89
90 // Intrinsic tab state -------------------------------------------------------
91
92 // Returns the property bag for this tab contents, where callers can add
93 // extra data they may wish to associate with the tab. Returns a pointer
94 // rather than a reference since the PropertyAccessors expect this.
95 const PropertyBag* property_bag() const { return &property_bag_; }
96 PropertyBag* property_bag() { return &property_bag_; }
97
98 TabContentsDelegate* delegate() const { return delegate_; }
[email protected]1de2b8b2011-06-29 19:38:4699 void set_delegate(TabContentsDelegate* delegate);
[email protected]0dd3a0ab2011-02-18 08:17:44100
101 // Gets the controller for this tab contents.
102 NavigationController& controller() { return controller_; }
103 const NavigationController& controller() const { return controller_; }
104
105 // Returns the user profile associated with this TabContents (via the
106 // NavigationController).
107 Profile* profile() const { return controller_.profile(); }
108
[email protected]c7dd2f62011-07-18 15:57:59109 // Returns the SavePackage which manages the page saving job. May be NULL.
110 SavePackage* save_package() const { return save_package_.get(); }
111
[email protected]0dd3a0ab2011-02-18 08:17:44112 // Return the currently active RenderProcessHost and RenderViewHost. Each of
113 // these may change over time.
114 RenderProcessHost* GetRenderProcessHost() const;
115 RenderViewHost* render_view_host() const {
116 return render_manager_.current_host();
117 }
118
[email protected]93f230e02011-06-01 14:40:00119 WebUI* committed_web_ui() const {
120 return render_manager_.web_ui();
121 }
122
[email protected]0dd3a0ab2011-02-18 08:17:44123 WebUI* web_ui() const {
124 return render_manager_.web_ui() ? render_manager_.web_ui()
125 : render_manager_.pending_web_ui();
126 }
127
128 // Returns the currently active RenderWidgetHostView. This may change over
129 // time and can be NULL (during setup and teardown).
130 RenderWidgetHostView* GetRenderWidgetHostView() const {
131 return render_manager_.GetRenderWidgetHostView();
132 }
133
134 // The TabContentsView will never change and is guaranteed non-NULL.
135 TabContentsView* view() const {
136 return view_.get();
137 }
138
[email protected]0dd3a0ab2011-02-18 08:17:44139 // Tab navigation state ------------------------------------------------------
140
141 // Returns the current navigation properties, which if a navigation is
142 // pending may be provisional (e.g., the navigation could result in a
143 // download, in which case the URL would revert to what it was previously).
144 virtual const GURL& GetURL() const;
145 virtual const string16& GetTitle() const;
146
147 // The max PageID of any page that this TabContents has loaded. PageIDs
148 // increase with each new page that is loaded by a tab. If this is a
149 // TabContents, then the max PageID is kept separately on each SiteInstance.
150 // Returns -1 if no PageIDs have yet been seen.
151 int32 GetMaxPageID();
152
153 // Updates the max PageID to be at least the given PageID.
154 void UpdateMaxPageID(int32 page_id);
155
156 // Returns the site instance associated with the current page. By default,
157 // there is no site instance. TabContents overrides this to provide proper
158 // access to its site instance.
159 virtual SiteInstance* GetSiteInstance() const;
160
161 // Defines whether this tab's URL should be displayed in the browser's URL
162 // bar. Normally this is true so you can see the URL. This is set to false
163 // for the new tab page and related pages so that the URL bar is empty and
164 // the user is invited to type into it.
165 virtual bool ShouldDisplayURL();
166
[email protected]f5d978c2011-07-21 14:43:51167 // Return whether this tab contents is loading a resource, or whether its
168 // web_ui is.
169 bool IsLoading() const;
[email protected]0dd3a0ab2011-02-18 08:17:44170
171 // Returns whether this tab contents is waiting for a first-response for the
172 // main resource of the page. This controls whether the throbber state is
173 // "waiting" or "loading."
174 bool waiting_for_response() const { return waiting_for_response_; }
175
176 net::LoadState load_state() const { return load_state_; }
177 string16 load_state_host() const { return load_state_host_; }
178 uint64 upload_size() const { return upload_size_; }
179 uint64 upload_position() const { return upload_position_; }
180
181 const std::string& encoding() const { return encoding_; }
182 void set_encoding(const std::string& encoding);
183 void reset_encoding() {
184 encoding_.clear();
185 }
186
[email protected]0dd3a0ab2011-02-18 08:17:44187 bool displayed_insecure_content() const {
188 return displayed_insecure_content_;
189 }
190
191 // Internal state ------------------------------------------------------------
192
193 // This flag indicates whether the tab contents is currently being
194 // screenshotted by the DraggedTabController.
195 bool capturing_contents() const { return capturing_contents_; }
196 void set_capturing_contents(bool cap) { capturing_contents_ = cap; }
197
198 // Indicates whether this tab should be considered crashed. The setter will
199 // also notify the delegate when the flag is changed.
200 bool is_crashed() const {
201 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
202 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
203 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
204 }
205 base::TerminationStatus crashed_status() const { return crashed_status_; }
206 int crashed_error_code() const { return crashed_error_code_; }
207 void SetIsCrashed(base::TerminationStatus status, int error_code);
208
[email protected]0dd3a0ab2011-02-18 08:17:44209 // Whether the tab is in the process of being destroyed.
210 // Added as a tentative work-around for focus related bug #4633. This allows
211 // us not to store focus when a tab is being closed.
212 bool is_being_destroyed() const { return is_being_destroyed_; }
213
214 // Convenience method for notifying the delegate of a navigation state
215 // change. See TabContentsDelegate.
216 void NotifyNavigationStateChanged(unsigned changed_flags);
217
218 // Invoked when the tab contents becomes selected. If you override, be sure
219 // and invoke super's implementation.
220 virtual void DidBecomeSelected();
221 base::TimeTicks last_selected_time() const {
222 return last_selected_time_;
223 }
224
225 // Invoked when the tab contents becomes hidden.
226 // NOTE: If you override this, call the superclass version too!
227 virtual void WasHidden();
228
[email protected]0dd3a0ab2011-02-18 08:17:44229 // TODO(brettw) document these.
230 virtual void ShowContents();
231 virtual void HideContents();
232
233 // Returns true if the before unload and unload listeners need to be
234 // fired. The value of this changes over time. For example, if true and the
235 // before unload listener is executed and allows the user to exit, then this
236 // returns false.
237 bool NeedToFireBeforeUnload();
238
239#ifdef UNIT_TEST
240 // Expose the render manager for testing.
241 RenderViewHostManager* render_manager() { return &render_manager_; }
242#endif
243
244 // In the underlying RenderViewHostManager, swaps in the provided
245 // RenderViewHost to replace the current RenderViewHost. The current RVH
246 // will be shutdown and ultimately deleted.
247 void SwapInRenderViewHost(RenderViewHost* rvh);
248
249 // Commands ------------------------------------------------------------------
250
251 // Implementation of PageNavigator.
[email protected]992e4542011-07-20 23:09:25252 virtual TabContents* OpenURL(const GURL& url,
253 const GURL& referrer,
254 WindowOpenDisposition disposition,
255 PageTransition::Type transition) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44256
257 // Called by the NavigationController to cause the TabContents to navigate to
258 // the current pending entry. The NavigationController should be called back
[email protected]9a7e68c2011-05-26 17:35:50259 // with RendererDidNavigate on success or DiscardPendingEntry on failure.
260 // The callbacks can be inside of this function, or at some future time.
[email protected]0dd3a0ab2011-02-18 08:17:44261 //
262 // The entry has a PageID of -1 if newly created (corresponding to navigation
263 // to a new URL).
264 //
265 // If this method returns false, then the navigation is discarded (equivalent
266 // to calling DiscardPendingEntry on the NavigationController).
267 virtual bool NavigateToPendingEntry(
268 NavigationController::ReloadType reload_type);
269
270 // Stop any pending navigation.
271 virtual void Stop();
272
[email protected]0dd3a0ab2011-02-18 08:17:44273 // Creates a new TabContents with the same state as this one. The returned
274 // heap-allocated pointer is owned by the caller.
275 virtual TabContents* Clone();
276
277 // Shows the page info.
278 void ShowPageInfo(const GURL& url,
279 const NavigationEntry::SSLStatus& ssl,
280 bool show_history);
281
[email protected]0dd3a0ab2011-02-18 08:17:44282 // Window management ---------------------------------------------------------
283
284 // Create a new window constrained to this TabContents' clip and visibility.
285 // The window is initialized by using the supplied delegate to obtain basic
286 // window characteristics, and the supplied view for the content. Note that
287 // the returned ConstrainedWindow might not yet be visible.
288 ConstrainedWindow* CreateConstrainedDialog(
289 ConstrainedWindowDelegate* delegate);
290
[email protected]473174942011-04-19 22:52:35291 // Adds a new tab or window with the given already-created contents.
[email protected]e7cfdbd2011-04-22 14:41:37292 void AddNewContents(TabContents* new_contents,
293 WindowOpenDisposition disposition,
294 const gfx::Rect& initial_pos,
295 bool user_gesture);
[email protected]0dd3a0ab2011-02-18 08:17:44296
297 // Returns the number of constrained windows in this tab. Used by tests.
298 size_t constrained_window_count() { return child_windows_.size(); }
299
300 typedef std::deque<ConstrainedWindow*> ConstrainedWindowList;
301
302 // Return an iterator for the first constrained window in this tab contents.
303 ConstrainedWindowList::iterator constrained_window_begin()
304 { return child_windows_.begin(); }
305
306 // Return an iterator for the last constrained window in this tab contents.
307 ConstrainedWindowList::iterator constrained_window_end()
308 { return child_windows_.end(); }
309
310 // Views and focus -----------------------------------------------------------
311 // TODO(brettw): Most of these should be removed and the caller should call
312 // the view directly.
313
314 // Returns the actual window that is focused when this TabContents is shown.
315 gfx::NativeView GetContentNativeView() const;
316
317 // Returns the NativeView associated with this TabContents. Outside of
318 // automation in the context of the UI, this is required to be implemented.
319 gfx::NativeView GetNativeView() const;
320
321 // Returns the bounds of this TabContents in the screen coordinate system.
322 void GetContainerBounds(gfx::Rect *out) const;
323
324 // Makes the tab the focused window.
325 void Focus();
326
327 // Focuses the first (last if |reverse| is true) element in the page.
328 // Invoked when this tab is getting the focus through tab traversal (|reverse|
329 // is true when using Shift-Tab).
330 void FocusThroughTabTraversal(bool reverse);
331
332 // These next two functions are declared on RenderViewHostManager::Delegate
333 // but also accessed directly by other callers.
334
335 // Returns true if the location bar should be focused by default rather than
336 // the page contents. The view calls this function when the tab is focused
337 // to see what it should do.
338 virtual bool FocusLocationBarByDefault();
339
340 // Focuses the location bar.
341 virtual void SetFocusToLocationBar(bool select_all);
342
343 // Creates a view and sets the size for the specified RVH.
344 virtual void CreateViewAndSetSizeForRVH(RenderViewHost* rvh);
345
[email protected]0dd3a0ab2011-02-18 08:17:44346 // Toolbars and such ---------------------------------------------------------
347
[email protected]686493142011-07-15 21:47:22348 // Notifies the delegate that a download is about to be started.
349 // This notification is fired before a local temporary file has been created.
350 bool CanDownload(int request_id);
351
352 // Notifies the delegate that a download started.
353 void OnStartDownload(DownloadItem* download);
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]c7dd2f62011-07-18 15:57:59386 // Prepare for saving the current web page to disk.
387 void OnSavePage();
388
389 // Save page with the main HTML file path, the directory for saving resources,
390 // and the save type: HTML only or complete web page. Returns true if the
391 // saving process has been initiated successfully.
392 bool SavePage(const FilePath& main_file, const FilePath& dir_path,
393 SavePackage::SavePackageType save_type);
394
395 // Prepare for saving the URL to disk.
396 // URL may refer to the iframe on the page.
397 void OnSaveURL(const GURL& url);
398
[email protected]0dd3a0ab2011-02-18 08:17:44399 // Returns true if the active NavigationEntry's page_id equals page_id.
400 bool IsActiveEntry(int32 page_id);
401
402 const std::string& contents_mime_type() const {
403 return contents_mime_type_;
404 }
405
406 // Returns true if this TabContents will notify about disconnection.
407 bool notify_disconnection() const { return notify_disconnection_; }
408
409 // Override the encoding and reload the page by sending down
410 // ViewMsg_SetPageEncoding to the renderer. |UpdateEncoding| is kinda
411 // the opposite of this, by which 'browser' is notified of
412 // the encoding of the current tab from 'renderer' (determined by
413 // auto-detect, http header, meta, bom detection, etc).
414 void SetOverrideEncoding(const std::string& encoding);
415
416 // Remove any user-defined override encoding and reload by sending down
417 // ViewMsg_ResetPageEncodingToDefault to the renderer.
418 void ResetOverrideEncoding();
419
[email protected]0dd3a0ab2011-02-18 08:17:44420 RendererPreferences* GetMutableRendererPrefs() {
421 return &renderer_preferences_;
422 }
423
[email protected]1fd1a502011-03-30 16:55:56424 void set_opener_web_ui_type(WebUI::TypeID opener_web_ui_type) {
[email protected]0dd3a0ab2011-02-18 08:17:44425 opener_web_ui_type_ = opener_web_ui_type;
426 }
427
[email protected]0dd3a0ab2011-02-18 08:17:44428 // Set the time when we started to create the new tab page. This time is
429 // from before we created this TabContents.
430 void set_new_tab_start_time(const base::TimeTicks& time) {
431 new_tab_start_time_ = time;
432 }
[email protected]763ec4ca2011-04-29 15:48:12433 base::TimeTicks new_tab_start_time() const { return new_tab_start_time_; }
[email protected]0dd3a0ab2011-02-18 08:17:44434
435 // Notification that tab closing has started. This can be called multiple
436 // times, subsequent calls are ignored.
437 void OnCloseStarted();
438
[email protected]0dd3a0ab2011-02-18 08:17:44439 // Returns true if underlying TabContentsView should accept drag-n-drop.
440 bool ShouldAcceptDragAndDrop() const;
441
442 // A render view-originated drag has ended. Informs the render view host and
443 // tab contents delegate.
444 void SystemDragEnded();
445
446 // Indicates if this tab was explicitly closed by the user (control-w, close
447 // tab menu item...). This is false for actions that indirectly close the tab,
448 // such as closing the window. The setter is maintained by TabStripModel, and
449 // the getter only useful from within TAB_CLOSED notification
450 void set_closed_by_user_gesture(bool value) {
451 closed_by_user_gesture_ = value;
452 }
453 bool closed_by_user_gesture() const { return closed_by_user_gesture_; }
454
[email protected]3ab9cb82011-06-03 18:02:07455 // Overridden from JavaScriptDialogDelegate:
456 virtual void OnDialogClosed(IPC::Message* reply_msg,
457 bool success,
458 const string16& user_input) OVERRIDE;
459 virtual gfx::NativeWindow GetDialogRootWindow() OVERRIDE;
[email protected]a1e97f02011-06-30 14:04:34460 virtual void OnDialogShown() OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44461
[email protected]0dd3a0ab2011-02-18 08:17:44462 // Gets the zoom level for this tab.
463 double GetZoomLevel() const;
464
465 // Gets the zoom percent for this tab.
466 int GetZoomPercent(bool* enable_increment, bool* enable_decrement);
467
[email protected]0dd3a0ab2011-02-18 08:17:44468 // Opens view-source tab for this contents.
469 void ViewSource();
470
[email protected]932b7a12011-03-09 12:50:27471 void ViewFrameSource(const GURL& url,
472 const std::string& content_state);
473
[email protected]0dd3a0ab2011-02-18 08:17:44474 // Gets the minimum/maximum zoom percent.
475 int minimum_zoom_percent() const { return minimum_zoom_percent_; }
476 int maximum_zoom_percent() const { return maximum_zoom_percent_; }
477
478 int content_restrictions() const { return content_restrictions_; }
[email protected]c40d6232011-03-25 00:16:21479 void SetContentRestrictions(int restrictions);
[email protected]0dd3a0ab2011-02-18 08:17:44480
[email protected]1fd1a502011-03-30 16:55:56481 // Query the WebUIFactory for the TypeID for the current URL.
482 WebUI::TypeID GetWebUITypeForCurrentState();
483
[email protected]b375c5d2011-05-03 21:15:04484 // Returns the WebUI for the current state of the tab. This will either be
485 // the pending WebUI, the committed WebUI, or NULL.
486 WebUI* GetWebUIForCurrentState();
487
[email protected]0dd3a0ab2011-02-18 08:17:44488 protected:
[email protected]553602e12011-04-05 17:01:18489 friend class TabContentsObserver;
[email protected]553602e12011-04-05 17:01:18490
491 // Add and remove observers for page navigation notifications. Adding or
492 // removing multiple times has no effect. The order in which notifications
493 // are sent to observers is undefined. Clients must be sure to remove the
494 // observer before they go away.
495 void AddObserver(TabContentsObserver* observer);
496 void RemoveObserver(TabContentsObserver* observer);
497
[email protected]e7cfdbd2011-04-22 14:41:37498 // From RenderViewHostDelegate.
[email protected]0dd3a0ab2011-02-18 08:17:44499 virtual bool OnMessageReceived(const IPC::Message& message);
500
501 private:
502 friend class NavigationController;
503 // Used to access the child_windows_ (ConstrainedWindowList) for testing
504 // automation purposes.
505 friend class TestingAutomationProvider;
506
507 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, NoJSMessageOnInterstitials);
508 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, UpdateTitle);
509 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, CrossSiteCantPreemptAfterUnload);
[email protected]aed59602011-02-28 22:57:33510 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, ConstrainedWindows);
[email protected]0dd3a0ab2011-02-18 08:17:44511 FRIEND_TEST_ALL_PREFIXES(FormStructureBrowserTest, HTMLFiles);
512 FRIEND_TEST_ALL_PREFIXES(NavigationControllerTest, HistoryNavigate);
513 FRIEND_TEST_ALL_PREFIXES(RenderViewHostManagerTest, PageDoesBackAndReload);
514
515 // Temporary until the view/contents separation is complete.
516 friend class TabContentsView;
[email protected]9a56a0d2011-05-13 19:03:31517#if defined(TOOLKIT_VIEWS)
[email protected]7e2cef52011-04-11 21:47:23518 friend class TabContentsViewViews;
[email protected]0dd3a0ab2011-02-18 08:17:44519#elif defined(OS_MACOSX)
520 friend class TabContentsViewMac;
521#elif defined(TOOLKIT_USES_GTK)
522 friend class TabContentsViewGtk;
523#endif
524
525 // So InterstitialPage can access SetIsLoading.
526 friend class InterstitialPage;
527
528 // TODO(brettw) TestTabContents shouldn't exist!
529 friend class TestTabContents;
530
[email protected]0dd3a0ab2011-02-18 08:17:44531 // 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]acafd272011-07-26 17:35:57605 bool UpdateTitleForEntry(NavigationEntry* entry, const string16& 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.
[email protected]544e27f2011-07-25 21:41:54623 virtual RenderViewHostDelegate::View* GetViewDelegate() OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44624 virtual RenderViewHostDelegate::RendererManagement*
[email protected]544e27f2011-07-25 21:41:54625 GetRendererManagementDelegate() OVERRIDE;
626 virtual TabContents* GetAsTabContents() OVERRIDE;
627 virtual ViewType::Type GetRenderViewType() const OVERRIDE;
628 virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE;
629 virtual void RenderViewReady(RenderViewHost* render_view_host) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44630 virtual void RenderViewGone(RenderViewHost* render_view_host,
631 base::TerminationStatus status,
[email protected]544e27f2011-07-25 21:41:54632 int error_code) OVERRIDE;
633 virtual void RenderViewDeleted(RenderViewHost* render_view_host) OVERRIDE;
634 virtual void DidNavigate(
635 RenderViewHost* render_view_host,
636 const ViewHostMsg_FrameNavigate_Params& params) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44637 virtual void UpdateState(RenderViewHost* render_view_host,
638 int32 page_id,
[email protected]544e27f2011-07-25 21:41:54639 const std::string& state) OVERRIDE;
[email protected]6b2f7a82011-04-25 19:30:51640 virtual void UpdateTitle(RenderViewHost* render_view_host,
641 int32 page_id,
[email protected]acafd272011-07-26 17:35:57642 const string16& title) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44643 virtual void UpdateEncoding(RenderViewHost* render_view_host,
[email protected]544e27f2011-07-25 21:41:54644 const std::string& encoding) OVERRIDE;
645 virtual void UpdateTargetURL(int32 page_id, const GURL& url) OVERRIDE;
646 virtual void Close(RenderViewHost* render_view_host) OVERRIDE;
647 virtual void RequestMove(const gfx::Rect& new_bounds) OVERRIDE;
648 virtual void DidStartLoading() OVERRIDE;
649 virtual void DidStopLoading() OVERRIDE;
650 virtual void DidCancelLoading() OVERRIDE;
651 virtual void DidChangeLoadProgress(double progress) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44652 virtual void DocumentOnLoadCompletedInMainFrame(
653 RenderViewHost* render_view_host,
[email protected]544e27f2011-07-25 21:41:54654 int32 page_id) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44655 virtual void RequestOpenURL(const GURL& url, const GURL& referrer,
[email protected]544e27f2011-07-25 21:41:54656 WindowOpenDisposition disposition) OVERRIDE;
[email protected]992db4c2011-05-12 15:37:15657 virtual void RunJavaScriptMessage(const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:41658 const string16& message,
659 const string16& default_prompt,
[email protected]0dd3a0ab2011-02-18 08:17:44660 const GURL& frame_url,
661 const int flags,
662 IPC::Message* reply_msg,
[email protected]3ab9cb82011-06-03 18:02:07663 bool* did_suppress_message) OVERRIDE;
[email protected]992db4c2011-05-12 15:37:15664 virtual void RunBeforeUnloadConfirm(const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:41665 const string16& message,
[email protected]544e27f2011-07-25 21:41:54666 IPC::Message* reply_msg) OVERRIDE;
667 virtual RendererPreferences GetRendererPrefs(Profile* profile) const OVERRIDE;
668 virtual WebPreferences GetWebkitPrefs() OVERRIDE;
669 virtual void OnUserGesture() OVERRIDE;
670 virtual void OnIgnoredUIEvent() OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44671 virtual void RendererUnresponsive(RenderViewHost* render_view_host,
[email protected]544e27f2011-07-25 21:41:54672 bool is_during_unload) OVERRIDE;
673 virtual void RendererResponsive(RenderViewHost* render_view_host) OVERRIDE;
674 virtual void LoadStateChanged(const GURL& url,
675 net::LoadState load_state,
676 uint64 upload_position,
677 uint64 upload_size) OVERRIDE;
678 virtual void WorkerCrashed() OVERRIDE;
679 virtual void Activate() OVERRIDE;
680 virtual void Deactivate() OVERRIDE;
681 virtual void LostCapture() OVERRIDE;
[email protected]63954792011-07-11 04:17:48682 virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
[email protected]544e27f2011-07-25 21:41:54683 bool* is_keyboard_shortcut) OVERRIDE;
684 virtual void HandleKeyboardEvent(
685 const NativeWebKeyboardEvent& event) OVERRIDE;
686 virtual void HandleMouseUp() OVERRIDE;
687 virtual void HandleMouseActivate() OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44688
689 // RenderViewHostManager::Delegate -------------------------------------------
690
691 // Blocks/unblocks interaction with renderer process.
692 void BlockTabContent(bool blocked);
693
694 virtual void BeforeUnloadFiredFromRenderManager(
695 bool proceed,
696 bool* proceed_to_fire_unload);
697 virtual void DidStartLoadingFromRenderManager(
698 RenderViewHost* render_view_host);
699 virtual void RenderViewGoneFromRenderManager(
700 RenderViewHost* render_view_host);
701 virtual void UpdateRenderViewSizeForRenderManager();
702 virtual void NotifySwappedFromRenderManager();
703 virtual NavigationController& GetControllerForRenderManager();
704 virtual WebUI* CreateWebUIForRenderManager(const GURL& url);
705 virtual NavigationEntry* GetLastCommittedNavigationEntryForRenderManager();
706
707 // Initializes the given renderer if necessary and creates the view ID
708 // corresponding to this view host. If this method is not called and the
709 // process is not shared, then the TabContents will act as though the renderer
710 // is not running (i.e., it will render "sad tab"). This method is
711 // automatically called from LoadURL.
712 //
713 // If you are attaching to an already-existing RenderView, you should call
714 // InitWithExistingID.
715 virtual bool CreateRenderViewForRenderManager(
716 RenderViewHost* render_view_host);
717
[email protected]aed59602011-02-28 22:57:33718 // Adds the given window to the list of child windows. The window will notify
719 // via WillClose() when it is being destroyed.
720 void AddConstrainedDialog(ConstrainedWindow* window);
721
[email protected]81898992011-06-14 22:15:00722 // Stores random bits of data for others to associate with this object.
723 // WARNING: this needs to be deleted after NavigationController.
724 PropertyBag property_bag_;
725
[email protected]0dd3a0ab2011-02-18 08:17:44726 // Data for core operation ---------------------------------------------------
727
728 // Delegate for notifying our owner about stuff. Not owned by us.
729 TabContentsDelegate* delegate_;
730
731 // Handles the back/forward list and loading.
732 NavigationController controller_;
733
734 // The corresponding view.
735 scoped_ptr<TabContentsView> view_;
736
737 // Helper classes ------------------------------------------------------------
738
739 // Manages creation and swapping of render views.
740 RenderViewHostManager render_manager_;
741
[email protected]c7dd2f62011-07-18 15:57:59742 // SavePackage, lazily created.
743 scoped_refptr<SavePackage> save_package_;
744
[email protected]0dd3a0ab2011-02-18 08:17:44745 // Data for loading state ----------------------------------------------------
746
747 // Indicates whether we're currently loading a resource.
748 bool is_loading_;
749
750 // Indicates if the tab is considered crashed.
751 base::TerminationStatus crashed_status_;
752 int crashed_error_code_;
753
754 // See waiting_for_response() above.
755 bool waiting_for_response_;
756
757 // Indicates the largest PageID we've seen. This field is ignored if we are
758 // a TabContents, in which case the max page ID is stored separately with
759 // each SiteInstance.
760 // TODO(brettw) this seems like it can be removed according to the comment.
761 int32 max_page_id_;
762
763 // System time at which the current load was started.
764 base::TimeTicks current_load_start_;
765
766 // The current load state and the URL associated with it.
767 net::LoadState load_state_;
768 string16 load_state_host_;
769 // Upload progress, for displaying in the status bar.
770 // Set to zero when there is no significant upload happening.
771 uint64 upload_size_;
772 uint64 upload_position_;
773
774 // Data for current page -----------------------------------------------------
775
[email protected]987fc3a2011-05-26 14:18:09776 // When a title cannot be taken from any entry, this title will be used.
777 string16 page_title_when_no_navigation_entry_;
778
[email protected]0dd3a0ab2011-02-18 08:17:44779 // When a navigation occurs, we record its contents MIME type. It can be
780 // used to check whether we can do something for some special contents.
781 std::string contents_mime_type_;
782
783 // Character encoding.
784 std::string encoding_;
785
[email protected]0dd3a0ab2011-02-18 08:17:44786 // True if this is a secure page which displayed insecure content.
787 bool displayed_insecure_content_;
788
[email protected]0dd3a0ab2011-02-18 08:17:44789 // Data for misc internal state ----------------------------------------------
790
791 // See capturing_contents() above.
792 bool capturing_contents_;
793
794 // See getter above.
795 bool is_being_destroyed_;
796
797 // Indicates whether we should notify about disconnection of this
798 // TabContents. This is used to ensure disconnection notifications only
799 // happen if a connection notification has happened and that they happen only
800 // once.
801 bool notify_disconnection_;
802
[email protected]0dd3a0ab2011-02-18 08:17:44803#if defined(OS_WIN)
804 // Handle to an event that's set when the page is showing a message box (or
805 // equivalent constrained window). Plugin processes check this to know if
806 // they should pump messages then.
807 base::win::ScopedHandle message_box_active_;
808#endif
809
[email protected]0dd3a0ab2011-02-18 08:17:44810 // Set to true when there is an active "before unload" dialog. When true,
811 // we've forced the throbber to start in Navigate, and we need to remember to
812 // turn it off in OnJavaScriptMessageBoxClosed if the navigation is canceled.
813 bool is_showing_before_unload_dialog_;
814
[email protected]0dd3a0ab2011-02-18 08:17:44815 // Settings that get passed to the renderer process.
816 RendererPreferences renderer_preferences_;
817
818 // If this tab was created from a renderer using window.open, this will be
819 // non-NULL and represent the WebUI of the opening renderer.
[email protected]1fd1a502011-03-30 16:55:56820 WebUI::TypeID opener_web_ui_type_;
[email protected]0dd3a0ab2011-02-18 08:17:44821
822 // The time that we started to create the new tab page.
823 base::TimeTicks new_tab_start_time_;
824
825 // The time that we started to close the tab.
826 base::TimeTicks tab_close_start_time_;
827
828 // The time that this tab was last selected.
829 base::TimeTicks last_selected_time_;
830
[email protected]0dd3a0ab2011-02-18 08:17:44831 // See description above setter.
832 bool closed_by_user_gesture_;
833
834 // Minimum/maximum zoom percent.
835 int minimum_zoom_percent_;
836 int maximum_zoom_percent_;
837 // If true, the default zoom limits have been overriden for this tab, in which
838 // case we don't want saved settings to apply to it and we don't want to
839 // remember it.
840 bool temporary_zoom_settings_;
841
842 // A list of observers notified when page state changes. Weak references.
843 ObserverList<TabContentsObserver> observers_;
844
845 // Content restrictions, used to disable print/copy etc based on content's
846 // (full-page plugins for now only) permissions.
847 int content_restrictions_;
848
[email protected]0dd3a0ab2011-02-18 08:17:44849 DISALLOW_COPY_AND_ASSIGN(TabContents);
850};
851
852#endif // CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_H_