blob: b34985395896542ed53691a7000b1e9e28b7820c [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/navigation_controller.h"
22#include "content/browser/tab_contents/navigation_entry.h"
23#include "content/browser/tab_contents/page_navigator.h"
24#include "content/browser/tab_contents/render_view_host_manager.h"
[email protected]553602e12011-04-05 17:01:1825#include "content/browser/tab_contents/tab_contents_observer.h"
[email protected]1fd1a502011-03-30 16:55:5626#include "content/browser/webui/web_ui.h"
[email protected]8d128d62011-09-13 22:11:5727#include "content/common/content_export.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"
[email protected]70435962011-08-02 20:13:2832#include "webkit/glue/resource_type.h"
[email protected]0dd3a0ab2011-02-18 08:17:4433
34#if defined(OS_WIN)
35#include "base/win/scoped_handle.h"
36#endif
37
38namespace gfx {
39class Rect;
40}
[email protected]ce9751942011-09-21 01:57:2441namespace webkit_glue {
42struct WebIntentData;
43}
[email protected]0dd3a0ab2011-02-18 08:17:4444
[email protected]686493142011-07-15 21:47:2245class DownloadItem;
[email protected]0dd3a0ab2011-02-18 08:17:4446class LoadNotificationDetails;
[email protected]ddb85052011-05-18 14:40:2747struct RendererPreferences;
[email protected]0dd3a0ab2011-02-18 08:17:4448class RenderViewHost;
49class SessionStorageNamespace;
50class SiteInstance;
51class SkBitmap;
[email protected]0dd3a0ab2011-02-18 08:17:4452class TabContentsDelegate;
53class TabContentsObserver;
[email protected]0dd3a0ab2011-02-18 08:17:4454class TabContentsView;
[email protected]8b0d7542011-05-16 19:36:5855struct ThumbnailScore;
[email protected]ddb85052011-05-18 14:40:2756class URLPattern;
[email protected]d7b175e2011-10-11 15:31:5857struct ViewHostMsg_DidFailProvisionalLoadWithError_Params;
[email protected]0dd3a0ab2011-02-18 08:17:4458struct ViewHostMsg_FrameNavigate_Params;
[email protected]d7b175e2011-10-11 15:31:5859struct ViewHostMsg_RunFileChooser_Params;
[email protected]0dd3a0ab2011-02-18 08:17:4460struct WebPreferences;
[email protected]ddb85052011-05-18 14:40:2761class WebUI;
[email protected]0dd3a0ab2011-02-18 08:17:4462
63// Describes what goes in the main content area of a tab. TabContents is
64// the only type of TabContents, and these should be merged together.
[email protected]8d128d62011-09-13 22:11:5765class CONTENT_EXPORT TabContents : public PageNavigator,
66 public RenderViewHostDelegate,
67 public RenderViewHostManager::Delegate,
68 public content::JavaScriptDialogDelegate {
[email protected]0dd3a0ab2011-02-18 08:17:4469 public:
70 // Flags passed to the TabContentsDelegate.NavigationStateChanged to tell it
71 // what has changed. Combine them to update more than one thing.
72 enum InvalidateTypes {
73 INVALIDATE_URL = 1 << 0, // The URL has changed.
74 INVALIDATE_TAB = 1 << 1, // The favicon, app icon, or crashed
75 // state changed.
76 INVALIDATE_LOAD = 1 << 2, // The loading state has changed.
77 INVALIDATE_PAGE_ACTIONS = 1 << 3, // Page action icons have changed.
[email protected]93f230e02011-06-01 14:40:0078 INVALIDATE_TITLE = 1 << 4, // The title changed.
[email protected]0dd3a0ab2011-02-18 08:17:4479 };
80
81 // |base_tab_contents| is used if we want to size the new tab contents view
82 // based on an existing tab contents view. This can be NULL if not needed.
83 //
84 // The session storage namespace parameter allows multiple render views and
85 // tab contentses to share the same session storage (part of the WebStorage
86 // spec) space. This is useful when restoring tabs, but most callers should
87 // pass in NULL which will cause a new SessionStorageNamespace to be created.
[email protected]3d7474ff2011-07-27 17:47:3788 TabContents(content::BrowserContext* browser_context,
[email protected]0dd3a0ab2011-02-18 08:17:4489 SiteInstance* site_instance,
90 int routing_id,
91 const TabContents* base_tab_contents,
92 SessionStorageNamespace* session_storage_namespace);
93 virtual ~TabContents();
94
95 // Intrinsic tab state -------------------------------------------------------
96
97 // Returns the property bag for this tab contents, where callers can add
98 // extra data they may wish to associate with the tab. Returns a pointer
99 // rather than a reference since the PropertyAccessors expect this.
100 const PropertyBag* property_bag() const { return &property_bag_; }
101 PropertyBag* property_bag() { return &property_bag_; }
102
103 TabContentsDelegate* delegate() const { return delegate_; }
[email protected]1de2b8b2011-06-29 19:38:46104 void set_delegate(TabContentsDelegate* delegate);
[email protected]0dd3a0ab2011-02-18 08:17:44105
106 // Gets the controller for this tab contents.
107 NavigationController& controller() { return controller_; }
108 const NavigationController& controller() const { return controller_; }
109
[email protected]3d7474ff2011-07-27 17:47:37110 // Returns the user browser context associated with this TabContents (via the
[email protected]0dd3a0ab2011-02-18 08:17:44111 // NavigationController).
[email protected]3d7474ff2011-07-27 17:47:37112 content::BrowserContext* browser_context() const {
113 return controller_.browser_context();
114 }
115
[email protected]c7dd2f62011-07-18 15:57:59116 // Returns the SavePackage which manages the page saving job. May be NULL.
117 SavePackage* save_package() const { return save_package_.get(); }
118
[email protected]0dd3a0ab2011-02-18 08:17:44119 // Return the currently active RenderProcessHost and RenderViewHost. Each of
120 // these may change over time.
121 RenderProcessHost* GetRenderProcessHost() const;
122 RenderViewHost* render_view_host() const {
123 return render_manager_.current_host();
124 }
125
[email protected]93f230e02011-06-01 14:40:00126 WebUI* committed_web_ui() const {
127 return render_manager_.web_ui();
128 }
129
[email protected]0dd3a0ab2011-02-18 08:17:44130 WebUI* web_ui() const {
131 return render_manager_.web_ui() ? render_manager_.web_ui()
132 : render_manager_.pending_web_ui();
133 }
134
135 // Returns the currently active RenderWidgetHostView. This may change over
136 // time and can be NULL (during setup and teardown).
137 RenderWidgetHostView* GetRenderWidgetHostView() const {
138 return render_manager_.GetRenderWidgetHostView();
139 }
140
141 // The TabContentsView will never change and is guaranteed non-NULL.
142 TabContentsView* view() const {
143 return view_.get();
144 }
145
[email protected]0dd3a0ab2011-02-18 08:17:44146 // Tab navigation state ------------------------------------------------------
147
148 // Returns the current navigation properties, which if a navigation is
149 // pending may be provisional (e.g., the navigation could result in a
150 // download, in which case the URL would revert to what it was previously).
151 virtual const GURL& GetURL() const;
152 virtual const string16& GetTitle() const;
153
154 // The max PageID of any page that this TabContents has loaded. PageIDs
155 // increase with each new page that is loaded by a tab. If this is a
156 // TabContents, then the max PageID is kept separately on each SiteInstance.
157 // Returns -1 if no PageIDs have yet been seen.
158 int32 GetMaxPageID();
159
160 // Updates the max PageID to be at least the given PageID.
161 void UpdateMaxPageID(int32 page_id);
162
163 // Returns the site instance associated with the current page. By default,
164 // there is no site instance. TabContents overrides this to provide proper
165 // access to its site instance.
166 virtual SiteInstance* GetSiteInstance() const;
167
[email protected]77362eb2011-08-01 17:18:38168 // Returns the SiteInstance for the pending navigation, if any. Otherwise
169 // returns the current SiteInstance.
170 SiteInstance* GetPendingSiteInstance() const;
171
[email protected]f5d978c2011-07-21 14:43:51172 // Return whether this tab contents is loading a resource, or whether its
173 // web_ui is.
174 bool IsLoading() const;
[email protected]0dd3a0ab2011-02-18 08:17:44175
176 // Returns whether this tab contents is waiting for a first-response for the
177 // main resource of the page. This controls whether the throbber state is
178 // "waiting" or "loading."
179 bool waiting_for_response() const { return waiting_for_response_; }
180
[email protected]9c235f042011-08-10 22:28:21181 const net::LoadStateWithParam& load_state() const { return load_state_; }
182 const string16& load_state_host() const { return load_state_host_; }
[email protected]0dd3a0ab2011-02-18 08:17:44183 uint64 upload_size() const { return upload_size_; }
184 uint64 upload_position() const { return upload_position_; }
185
186 const std::string& encoding() const { return encoding_; }
187 void set_encoding(const std::string& encoding);
188 void reset_encoding() {
189 encoding_.clear();
190 }
191
[email protected]0dd3a0ab2011-02-18 08:17:44192 bool displayed_insecure_content() const {
193 return displayed_insecure_content_;
194 }
195
196 // Internal state ------------------------------------------------------------
197
198 // This flag indicates whether the tab contents is currently being
199 // screenshotted by the DraggedTabController.
200 bool capturing_contents() const { return capturing_contents_; }
201 void set_capturing_contents(bool cap) { capturing_contents_ = cap; }
202
203 // Indicates whether this tab should be considered crashed. The setter will
204 // also notify the delegate when the flag is changed.
205 bool is_crashed() const {
206 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
207 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
208 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
209 }
210 base::TerminationStatus crashed_status() const { return crashed_status_; }
211 int crashed_error_code() const { return crashed_error_code_; }
212 void SetIsCrashed(base::TerminationStatus status, int error_code);
213
[email protected]0dd3a0ab2011-02-18 08:17:44214 // Whether the tab is in the process of being destroyed.
215 // Added as a tentative work-around for focus related bug #4633. This allows
216 // us not to store focus when a tab is being closed.
217 bool is_being_destroyed() const { return is_being_destroyed_; }
218
219 // Convenience method for notifying the delegate of a navigation state
220 // change. See TabContentsDelegate.
221 void NotifyNavigationStateChanged(unsigned changed_flags);
222
223 // Invoked when the tab contents becomes selected. If you override, be sure
224 // and invoke super's implementation.
225 virtual void DidBecomeSelected();
226 base::TimeTicks last_selected_time() const {
227 return last_selected_time_;
228 }
229
230 // Invoked when the tab contents becomes hidden.
231 // NOTE: If you override this, call the superclass version too!
232 virtual void WasHidden();
233
[email protected]0dd3a0ab2011-02-18 08:17:44234 // TODO(brettw) document these.
235 virtual void ShowContents();
236 virtual void HideContents();
237
238 // Returns true if the before unload and unload listeners need to be
239 // fired. The value of this changes over time. For example, if true and the
240 // before unload listener is executed and allows the user to exit, then this
241 // returns false.
242 bool NeedToFireBeforeUnload();
243
[email protected]0dd3a0ab2011-02-18 08:17:44244 // Expose the render manager for testing.
[email protected]03ff5e52011-09-30 00:28:14245 RenderViewHostManager* render_manager_for_testing() {
246 return &render_manager_;
247 }
[email protected]0dd3a0ab2011-02-18 08:17:44248
[email protected]0dd3a0ab2011-02-18 08:17:44249 // Commands ------------------------------------------------------------------
250
251 // Implementation of PageNavigator.
[email protected]00c37fc2011-08-02 00:22:50252
253 // Deprecated. Please use the one-argument variant instead.
254 // TODO(adriansc): Remove this method once refactoring changed all call sites.
[email protected]992e4542011-07-20 23:09:25255 virtual TabContents* OpenURL(const GURL& url,
256 const GURL& referrer,
257 WindowOpenDisposition disposition,
[email protected]2905f742011-10-13 03:51:58258 content::PageTransition transition) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44259
[email protected]00c37fc2011-08-02 00:22:50260 virtual TabContents* OpenURL(const OpenURLParams& params) OVERRIDE;
261
[email protected]0dd3a0ab2011-02-18 08:17:44262 // Called by the NavigationController to cause the TabContents to navigate to
263 // the current pending entry. The NavigationController should be called back
[email protected]9a7e68c2011-05-26 17:35:50264 // with RendererDidNavigate on success or DiscardPendingEntry on failure.
265 // The callbacks can be inside of this function, or at some future time.
[email protected]0dd3a0ab2011-02-18 08:17:44266 //
267 // The entry has a PageID of -1 if newly created (corresponding to navigation
268 // to a new URL).
269 //
270 // If this method returns false, then the navigation is discarded (equivalent
271 // to calling DiscardPendingEntry on the NavigationController).
272 virtual bool NavigateToPendingEntry(
273 NavigationController::ReloadType reload_type);
274
275 // Stop any pending navigation.
276 virtual void Stop();
277
[email protected]0dd3a0ab2011-02-18 08:17:44278 // Creates a new TabContents with the same state as this one. The returned
279 // heap-allocated pointer is owned by the caller.
280 virtual TabContents* Clone();
281
282 // Shows the page info.
283 void ShowPageInfo(const GURL& url,
284 const NavigationEntry::SSLStatus& ssl,
285 bool show_history);
286
[email protected]0dd3a0ab2011-02-18 08:17:44287 // Window management ---------------------------------------------------------
288
[email protected]473174942011-04-19 22:52:35289 // Adds a new tab or window with the given already-created contents.
[email protected]e7cfdbd2011-04-22 14:41:37290 void AddNewContents(TabContents* new_contents,
291 WindowOpenDisposition disposition,
292 const gfx::Rect& initial_pos,
293 bool user_gesture);
[email protected]0dd3a0ab2011-02-18 08:17:44294
[email protected]0dd3a0ab2011-02-18 08:17:44295 // Views and focus -----------------------------------------------------------
296 // TODO(brettw): Most of these should be removed and the caller should call
297 // the view directly.
298
299 // Returns the actual window that is focused when this TabContents is shown.
300 gfx::NativeView GetContentNativeView() const;
301
302 // Returns the NativeView associated with this TabContents. Outside of
303 // automation in the context of the UI, this is required to be implemented.
304 gfx::NativeView GetNativeView() const;
305
306 // Returns the bounds of this TabContents in the screen coordinate system.
307 void GetContainerBounds(gfx::Rect *out) const;
308
309 // Makes the tab the focused window.
310 void Focus();
311
312 // Focuses the first (last if |reverse| is true) element in the page.
313 // Invoked when this tab is getting the focus through tab traversal (|reverse|
314 // is true when using Shift-Tab).
315 void FocusThroughTabTraversal(bool reverse);
316
317 // These next two functions are declared on RenderViewHostManager::Delegate
318 // but also accessed directly by other callers.
319
320 // Returns true if the location bar should be focused by default rather than
321 // the page contents. The view calls this function when the tab is focused
322 // to see what it should do.
323 virtual bool FocusLocationBarByDefault();
324
325 // Focuses the location bar.
326 virtual void SetFocusToLocationBar(bool select_all);
327
328 // Creates a view and sets the size for the specified RVH.
329 virtual void CreateViewAndSetSizeForRVH(RenderViewHost* rvh);
330
[email protected]0dd3a0ab2011-02-18 08:17:44331 // Toolbars and such ---------------------------------------------------------
332
[email protected]686493142011-07-15 21:47:22333 // Notifies the delegate that a download is about to be started.
334 // This notification is fired before a local temporary file has been created.
335 bool CanDownload(int request_id);
336
337 // Notifies the delegate that a download started.
338 void OnStartDownload(DownloadItem* download);
339
[email protected]0dd3a0ab2011-02-18 08:17:44340 // Interstitials -------------------------------------------------------------
341
342 // Various other systems need to know about our interstitials.
343 bool showing_interstitial_page() const {
344 return render_manager_.interstitial_page() != NULL;
345 }
346
347 // Sets the passed passed interstitial as the currently showing interstitial.
348 // |interstitial_page| should be non NULL (use the remove_interstitial_page
349 // method to unset the interstitial) and no interstitial page should be set
350 // when there is already a non NULL interstitial page set.
351 void set_interstitial_page(InterstitialPage* interstitial_page) {
352 render_manager_.set_interstitial_page(interstitial_page);
353 }
354
355 // Unsets the currently showing interstitial.
356 void remove_interstitial_page() {
357 render_manager_.remove_interstitial_page();
358 }
359
360 // Returns the currently showing interstitial, NULL if no interstitial is
361 // showing.
362 InterstitialPage* interstitial_page() const {
363 return render_manager_.interstitial_page();
364 }
365
366 // Misc state & callbacks ----------------------------------------------------
367
[email protected]c7dd2f62011-07-18 15:57:59368 // Prepare for saving the current web page to disk.
369 void OnSavePage();
370
371 // Save page with the main HTML file path, the directory for saving resources,
372 // and the save type: HTML only or complete web page. Returns true if the
373 // saving process has been initiated successfully.
374 bool SavePage(const FilePath& main_file, const FilePath& dir_path,
375 SavePackage::SavePackageType save_type);
376
377 // Prepare for saving the URL to disk.
378 // URL may refer to the iframe on the page.
379 void OnSaveURL(const GURL& url);
380
[email protected]0dd3a0ab2011-02-18 08:17:44381 // Returns true if the active NavigationEntry's page_id equals page_id.
382 bool IsActiveEntry(int32 page_id);
383
384 const std::string& contents_mime_type() const {
385 return contents_mime_type_;
386 }
387
388 // Returns true if this TabContents will notify about disconnection.
389 bool notify_disconnection() const { return notify_disconnection_; }
390
391 // Override the encoding and reload the page by sending down
392 // ViewMsg_SetPageEncoding to the renderer. |UpdateEncoding| is kinda
393 // the opposite of this, by which 'browser' is notified of
394 // the encoding of the current tab from 'renderer' (determined by
395 // auto-detect, http header, meta, bom detection, etc).
396 void SetOverrideEncoding(const std::string& encoding);
397
398 // Remove any user-defined override encoding and reload by sending down
399 // ViewMsg_ResetPageEncodingToDefault to the renderer.
400 void ResetOverrideEncoding();
401
[email protected]0dd3a0ab2011-02-18 08:17:44402 RendererPreferences* GetMutableRendererPrefs() {
403 return &renderer_preferences_;
404 }
405
[email protected]1fd1a502011-03-30 16:55:56406 void set_opener_web_ui_type(WebUI::TypeID opener_web_ui_type) {
[email protected]0dd3a0ab2011-02-18 08:17:44407 opener_web_ui_type_ = opener_web_ui_type;
408 }
409
[email protected]0dd3a0ab2011-02-18 08:17:44410 // Set the time when we started to create the new tab page. This time is
411 // from before we created this TabContents.
412 void set_new_tab_start_time(const base::TimeTicks& time) {
413 new_tab_start_time_ = time;
414 }
[email protected]763ec4ca2011-04-29 15:48:12415 base::TimeTicks new_tab_start_time() const { return new_tab_start_time_; }
[email protected]0dd3a0ab2011-02-18 08:17:44416
417 // Notification that tab closing has started. This can be called multiple
418 // times, subsequent calls are ignored.
419 void OnCloseStarted();
420
[email protected]0dd3a0ab2011-02-18 08:17:44421 // Returns true if underlying TabContentsView should accept drag-n-drop.
422 bool ShouldAcceptDragAndDrop() const;
423
424 // A render view-originated drag has ended. Informs the render view host and
425 // tab contents delegate.
426 void SystemDragEnded();
427
428 // Indicates if this tab was explicitly closed by the user (control-w, close
429 // tab menu item...). This is false for actions that indirectly close the tab,
430 // such as closing the window. The setter is maintained by TabStripModel, and
431 // the getter only useful from within TAB_CLOSED notification
432 void set_closed_by_user_gesture(bool value) {
433 closed_by_user_gesture_ = value;
434 }
435 bool closed_by_user_gesture() const { return closed_by_user_gesture_; }
436
[email protected]3ab9cb82011-06-03 18:02:07437 // Overridden from JavaScriptDialogDelegate:
438 virtual void OnDialogClosed(IPC::Message* reply_msg,
439 bool success,
440 const string16& user_input) OVERRIDE;
441 virtual gfx::NativeWindow GetDialogRootWindow() OVERRIDE;
[email protected]a1e97f02011-06-30 14:04:34442 virtual void OnDialogShown() OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44443
[email protected]0dd3a0ab2011-02-18 08:17:44444 // Gets the zoom level for this tab.
445 double GetZoomLevel() const;
446
447 // Gets the zoom percent for this tab.
448 int GetZoomPercent(bool* enable_increment, bool* enable_decrement);
449
[email protected]0dd3a0ab2011-02-18 08:17:44450 // Opens view-source tab for this contents.
451 void ViewSource();
452
[email protected]932b7a12011-03-09 12:50:27453 void ViewFrameSource(const GURL& url,
454 const std::string& content_state);
455
[email protected]0dd3a0ab2011-02-18 08:17:44456 // Gets the minimum/maximum zoom percent.
457 int minimum_zoom_percent() const { return minimum_zoom_percent_; }
458 int maximum_zoom_percent() const { return maximum_zoom_percent_; }
459
460 int content_restrictions() const { return content_restrictions_; }
[email protected]c40d6232011-03-25 00:16:21461 void SetContentRestrictions(int restrictions);
[email protected]0dd3a0ab2011-02-18 08:17:44462
[email protected]1fd1a502011-03-30 16:55:56463 // Query the WebUIFactory for the TypeID for the current URL.
464 WebUI::TypeID GetWebUITypeForCurrentState();
465
[email protected]b375c5d2011-05-03 21:15:04466 // Returns the WebUI for the current state of the tab. This will either be
467 // the pending WebUI, the committed WebUI, or NULL.
468 WebUI* GetWebUIForCurrentState();
469
[email protected]0dd3a0ab2011-02-18 08:17:44470 protected:
[email protected]553602e12011-04-05 17:01:18471 friend class TabContentsObserver;
[email protected]553602e12011-04-05 17:01:18472
473 // Add and remove observers for page navigation notifications. Adding or
474 // removing multiple times has no effect. The order in which notifications
475 // are sent to observers is undefined. Clients must be sure to remove the
476 // observer before they go away.
477 void AddObserver(TabContentsObserver* observer);
478 void RemoveObserver(TabContentsObserver* observer);
479
[email protected]0dd3a0ab2011-02-18 08:17:44480 private:
481 friend class NavigationController;
[email protected]0dd3a0ab2011-02-18 08:17:44482
483 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, NoJSMessageOnInterstitials);
484 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, UpdateTitle);
485 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, CrossSiteCantPreemptAfterUnload);
486 FRIEND_TEST_ALL_PREFIXES(FormStructureBrowserTest, HTMLFiles);
487 FRIEND_TEST_ALL_PREFIXES(NavigationControllerTest, HistoryNavigate);
488 FRIEND_TEST_ALL_PREFIXES(RenderViewHostManagerTest, PageDoesBackAndReload);
489
490 // Temporary until the view/contents separation is complete.
491 friend class TabContentsView;
[email protected]9a56a0d2011-05-13 19:03:31492#if defined(TOOLKIT_VIEWS)
[email protected]7e2cef52011-04-11 21:47:23493 friend class TabContentsViewViews;
[email protected]0dd3a0ab2011-02-18 08:17:44494#elif defined(OS_MACOSX)
495 friend class TabContentsViewMac;
496#elif defined(TOOLKIT_USES_GTK)
497 friend class TabContentsViewGtk;
498#endif
499
500 // So InterstitialPage can access SetIsLoading.
501 friend class InterstitialPage;
502
503 // TODO(brettw) TestTabContents shouldn't exist!
504 friend class TestTabContents;
505
[email protected]0dd3a0ab2011-02-18 08:17:44506 // Message handlers.
507 void OnDidStartProvisionalLoadForFrame(int64 frame_id,
508 bool main_frame,
[email protected]57b9396c2011-10-07 19:11:59509 const GURL& opener_url,
[email protected]0dd3a0ab2011-02-18 08:17:44510 const GURL& url);
511 void OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]57b9396c2011-10-07 19:11:59512 const GURL& opener_url,
[email protected]0dd3a0ab2011-02-18 08:17:44513 const GURL& source_url,
514 const GURL& target_url);
[email protected]d7b175e2011-10-11 15:31:58515 void OnDidFailProvisionalLoadWithError(
516 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params);
[email protected]0dd3a0ab2011-02-18 08:17:44517 void OnDidLoadResourceFromMemoryCache(const GURL& url,
[email protected]70435962011-08-02 20:13:28518 const std::string& security_info,
519 const std::string& http_request,
520 ResourceType::Type resource_type);
[email protected]0dd3a0ab2011-02-18 08:17:44521 void OnDidDisplayInsecureContent();
522 void OnDidRunInsecureContent(const std::string& security_origin,
523 const GURL& target_url);
524 void OnDocumentLoadedInFrame(int64 frame_id);
525 void OnDidFinishLoad(int64 frame_id);
526 void OnUpdateContentRestrictions(int restrictions);
[email protected]0dd3a0ab2011-02-18 08:17:44527 void OnGoToEntryAtOffset(int offset);
[email protected]216813952011-05-19 22:21:26528 void OnUpdateZoomLimits(int minimum_percent,
529 int maximum_percent,
530 bool remember);
531 void OnFocusedNodeChanged(bool is_editable_node);
[email protected]3a29a6e2011-08-24 18:26:21532 void OnEnumerateDirectory(int request_id, const FilePath& path);
[email protected]7d189022011-08-25 22:54:20533 void OnJSOutOfMemory();
534 void OnRegisterProtocolHandler(const std::string& protocol,
535 const GURL& url,
536 const string16& title);
537 void OnRegisterIntentHandler(const string16& action,
538 const string16& type,
539 const string16& href,
540 const string16& title);
541 void OnWebIntentDispatch(const IPC::Message& message,
[email protected]ce9751942011-09-21 01:57:24542 const webkit_glue::WebIntentData& intent,
[email protected]7d189022011-08-25 22:54:20543 int intent_id);
[email protected]b888919c2011-09-02 00:32:16544 void OnFindReply(int request_id, int number_of_matches,
545 const gfx::Rect& selection_rect, int active_match_ordinal,
546 bool final_update);
[email protected]d952a052011-09-06 18:42:45547 void OnCrashedPlugin(const FilePath& plugin_path);
[email protected]7fc4bbb2011-09-08 21:23:10548 void OnAppCacheAccessed(const GURL& manifest_url, bool blocked_by_policy);
[email protected]0dd3a0ab2011-02-18 08:17:44549
550 // Changes the IsLoading state and notifies delegate as needed
551 // |details| is used to provide details on the load that just finished
552 // (but can be null if not applicable). Can be overridden.
553 void SetIsLoading(bool is_loading,
554 LoadNotificationDetails* details);
555
[email protected]0dd3a0ab2011-02-18 08:17:44556 // Called by derived classes to indicate that we're no longer waiting for a
557 // response. This won't actually update the throbber, but it will get picked
558 // up at the next animation step if the throbber is going.
559 void SetNotWaitingForResponse() { waiting_for_response_ = false; }
560
[email protected]0dd3a0ab2011-02-18 08:17:44561 // Navigation helpers --------------------------------------------------------
562 //
563 // These functions are helpers for Navigate() and DidNavigate().
564
565 // Handles post-navigation tasks in DidNavigate AFTER the entry has been
566 // committed to the navigation controller. Note that the navigation entry is
567 // not provided since it may be invalid/changed after being committed. The
568 // current navigation entry is in the NavigationController at this point.
569 void DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:13570 const content::LoadCommittedDetails& details,
[email protected]0dd3a0ab2011-02-18 08:17:44571 const ViewHostMsg_FrameNavigate_Params& params);
572 void DidNavigateAnyFramePostCommit(
573 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:13574 const content::LoadCommittedDetails& details,
[email protected]0dd3a0ab2011-02-18 08:17:44575 const ViewHostMsg_FrameNavigate_Params& params);
576
[email protected]0dd3a0ab2011-02-18 08:17:44577 // If our controller was restored and the page id is > than the site
578 // instance's page id, the site instances page id is updated as well as the
579 // renderers max page id.
580 void UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
581 RenderViewHost* rvh);
582
[email protected]0dd3a0ab2011-02-18 08:17:44583 // Saves the given title to the navigation entry and does associated work. It
584 // will update history and the view for the new title, and also synthesize
585 // titles for file URLs that have none (so we require that the URL of the
586 // entry already be set).
587 //
588 // This is used as the backend for state updates, which include a new title,
589 // or the dedicated set title message. It returns true if the new title is
590 // different and was therefore updated.
[email protected]acafd272011-07-26 17:35:57591 bool UpdateTitleForEntry(NavigationEntry* entry, const string16& title);
[email protected]0dd3a0ab2011-02-18 08:17:44592
593 // Causes the TabContents to navigate in the right renderer to |entry|, which
594 // must be already part of the entries in the navigation controller.
595 // This does not change the NavigationController state.
596 bool NavigateToEntry(const NavigationEntry& entry,
597 NavigationController::ReloadType reload_type);
598
[email protected]796931a92011-08-10 01:32:14599 // Sets the history for this tab_contents to |history_length| entries, and
600 // moves the current page_id to the last entry in the list if it's valid.
601 // This is mainly used when a prerendered page is swapped into the current
[email protected]9e1ad4b2011-08-14 16:49:19602 // tab. The method is virtual for testing.
603 virtual void SetHistoryLengthAndPrune(const SiteInstance* site_instance,
604 int merge_history_length,
605 int32 minimum_page_id);
[email protected]796931a92011-08-10 01:32:14606
[email protected]0dd3a0ab2011-02-18 08:17:44607 // Misc non-view stuff -------------------------------------------------------
608
609 // Helper functions for sending notifications.
610 void NotifySwapped();
611 void NotifyConnected();
612 void NotifyDisconnected();
613
[email protected]0dd3a0ab2011-02-18 08:17:44614 // RenderViewHostDelegate ----------------------------------------------------
615
616 // RenderViewHostDelegate implementation.
[email protected]544e27f2011-07-25 21:41:54617 virtual RenderViewHostDelegate::View* GetViewDelegate() OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44618 virtual RenderViewHostDelegate::RendererManagement*
[email protected]544e27f2011-07-25 21:41:54619 GetRendererManagementDelegate() OVERRIDE;
620 virtual TabContents* GetAsTabContents() OVERRIDE;
[email protected]da4dfc42011-10-12 15:53:56621 virtual content::ViewType GetRenderViewType() const OVERRIDE;
[email protected]544e27f2011-07-25 21:41:54622 virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE;
623 virtual void RenderViewReady(RenderViewHost* render_view_host) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44624 virtual void RenderViewGone(RenderViewHost* render_view_host,
625 base::TerminationStatus status,
[email protected]544e27f2011-07-25 21:41:54626 int error_code) OVERRIDE;
627 virtual void RenderViewDeleted(RenderViewHost* render_view_host) OVERRIDE;
628 virtual void DidNavigate(
629 RenderViewHost* render_view_host,
630 const ViewHostMsg_FrameNavigate_Params& params) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44631 virtual void UpdateState(RenderViewHost* render_view_host,
632 int32 page_id,
[email protected]544e27f2011-07-25 21:41:54633 const std::string& state) OVERRIDE;
[email protected]6b2f7a82011-04-25 19:30:51634 virtual void UpdateTitle(RenderViewHost* render_view_host,
635 int32 page_id,
[email protected]a49e10b2011-08-01 23:57:46636 const string16& title,
637 base::i18n::TextDirection title_direction) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44638 virtual void UpdateEncoding(RenderViewHost* render_view_host,
[email protected]544e27f2011-07-25 21:41:54639 const std::string& encoding) OVERRIDE;
640 virtual void UpdateTargetURL(int32 page_id, const GURL& url) OVERRIDE;
641 virtual void Close(RenderViewHost* render_view_host) OVERRIDE;
642 virtual void RequestMove(const gfx::Rect& new_bounds) OVERRIDE;
643 virtual void DidStartLoading() OVERRIDE;
644 virtual void DidStopLoading() OVERRIDE;
645 virtual void DidCancelLoading() OVERRIDE;
646 virtual void DidChangeLoadProgress(double progress) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44647 virtual void DocumentOnLoadCompletedInMainFrame(
648 RenderViewHost* render_view_host,
[email protected]544e27f2011-07-25 21:41:54649 int32 page_id) OVERRIDE;
[email protected]ae5184d62011-10-06 19:25:58650 virtual void RequestOpenURL(const GURL& url,
651 const GURL& referrer,
652 WindowOpenDisposition disposition,
653 int64 source_frame_id) OVERRIDE;
[email protected]992db4c2011-05-12 15:37:15654 virtual void RunJavaScriptMessage(const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:41655 const string16& message,
656 const string16& default_prompt,
[email protected]0dd3a0ab2011-02-18 08:17:44657 const GURL& frame_url,
658 const int flags,
659 IPC::Message* reply_msg,
[email protected]3ab9cb82011-06-03 18:02:07660 bool* did_suppress_message) OVERRIDE;
[email protected]992db4c2011-05-12 15:37:15661 virtual void RunBeforeUnloadConfirm(const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:41662 const string16& message,
[email protected]544e27f2011-07-25 21:41:54663 IPC::Message* reply_msg) OVERRIDE;
[email protected]3d7474ff2011-07-27 17:47:37664 virtual RendererPreferences GetRendererPrefs(
665 content::BrowserContext* browser_context) const OVERRIDE;
[email protected]544e27f2011-07-25 21:41:54666 virtual WebPreferences GetWebkitPrefs() OVERRIDE;
667 virtual void OnUserGesture() OVERRIDE;
668 virtual void OnIgnoredUIEvent() OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44669 virtual void RendererUnresponsive(RenderViewHost* render_view_host,
[email protected]544e27f2011-07-25 21:41:54670 bool is_during_unload) OVERRIDE;
671 virtual void RendererResponsive(RenderViewHost* render_view_host) OVERRIDE;
672 virtual void LoadStateChanged(const GURL& url,
[email protected]9c235f042011-08-10 22:28:21673 const net::LoadStateWithParam& load_state,
[email protected]544e27f2011-07-25 21:41:54674 uint64 upload_position,
675 uint64 upload_size) OVERRIDE;
676 virtual void WorkerCrashed() OVERRIDE;
677 virtual void Activate() OVERRIDE;
678 virtual void Deactivate() OVERRIDE;
679 virtual void LostCapture() OVERRIDE;
[email protected]63954792011-07-11 04:17:48680 virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
[email protected]544e27f2011-07-25 21:41:54681 bool* is_keyboard_shortcut) OVERRIDE;
682 virtual void HandleKeyboardEvent(
683 const NativeWebKeyboardEvent& event) OVERRIDE;
684 virtual void HandleMouseUp() OVERRIDE;
685 virtual void HandleMouseActivate() OVERRIDE;
[email protected]6c2e472f2011-08-24 23:26:18686 virtual bool OnMessageReceived(const IPC::Message& message);
687 virtual void RunFileChooser(RenderViewHost* render_view_host,
688 const ViewHostMsg_RunFileChooser_Params& params);
[email protected]8a5e0ca2011-08-25 06:30:47689 virtual void ToggleFullscreenMode(bool enter_fullscreen) OVERRIDE;
[email protected]5d5f7af2011-10-01 01:38:12690 virtual bool IsFullscreenForCurrentTab() const OVERRIDE;
[email protected]0548c5352011-09-07 00:33:33691 virtual void UpdatePreferredSize(const gfx::Size& pref_size) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44692
693 // RenderViewHostManager::Delegate -------------------------------------------
694
[email protected]0dd3a0ab2011-02-18 08:17:44695 virtual void BeforeUnloadFiredFromRenderManager(
696 bool proceed,
697 bool* proceed_to_fire_unload);
698 virtual void DidStartLoadingFromRenderManager(
699 RenderViewHost* render_view_host);
700 virtual void RenderViewGoneFromRenderManager(
701 RenderViewHost* render_view_host);
702 virtual void UpdateRenderViewSizeForRenderManager();
703 virtual void NotifySwappedFromRenderManager();
704 virtual NavigationController& GetControllerForRenderManager();
705 virtual WebUI* CreateWebUIForRenderManager(const GURL& url);
706 virtual NavigationEntry* GetLastCommittedNavigationEntryForRenderManager();
707
708 // Initializes the given renderer if necessary and creates the view ID
709 // corresponding to this view host. If this method is not called and the
710 // process is not shared, then the TabContents will act as though the renderer
711 // is not running (i.e., it will render "sad tab"). This method is
712 // automatically called from LoadURL.
713 //
714 // If you are attaching to an already-existing RenderView, you should call
715 // InitWithExistingID.
716 virtual bool CreateRenderViewForRenderManager(
717 RenderViewHost* render_view_host);
718
[email protected]81898992011-06-14 22:15:00719 // Stores random bits of data for others to associate with this object.
720 // WARNING: this needs to be deleted after NavigationController.
721 PropertyBag property_bag_;
722
[email protected]0dd3a0ab2011-02-18 08:17:44723 // Data for core operation ---------------------------------------------------
724
725 // Delegate for notifying our owner about stuff. Not owned by us.
726 TabContentsDelegate* delegate_;
727
728 // Handles the back/forward list and loading.
729 NavigationController controller_;
730
731 // The corresponding view.
732 scoped_ptr<TabContentsView> view_;
733
734 // Helper classes ------------------------------------------------------------
735
736 // Manages creation and swapping of render views.
737 RenderViewHostManager render_manager_;
738
[email protected]c7dd2f62011-07-18 15:57:59739 // SavePackage, lazily created.
740 scoped_refptr<SavePackage> save_package_;
741
[email protected]0dd3a0ab2011-02-18 08:17:44742 // Data for loading state ----------------------------------------------------
743
744 // Indicates whether we're currently loading a resource.
745 bool is_loading_;
746
747 // Indicates if the tab is considered crashed.
748 base::TerminationStatus crashed_status_;
749 int crashed_error_code_;
750
751 // See waiting_for_response() above.
752 bool waiting_for_response_;
753
754 // Indicates the largest PageID we've seen. This field is ignored if we are
755 // a TabContents, in which case the max page ID is stored separately with
756 // each SiteInstance.
757 // TODO(brettw) this seems like it can be removed according to the comment.
758 int32 max_page_id_;
759
760 // System time at which the current load was started.
761 base::TimeTicks current_load_start_;
762
763 // The current load state and the URL associated with it.
[email protected]9c235f042011-08-10 22:28:21764 net::LoadStateWithParam load_state_;
[email protected]0dd3a0ab2011-02-18 08:17:44765 string16 load_state_host_;
766 // Upload progress, for displaying in the status bar.
767 // Set to zero when there is no significant upload happening.
768 uint64 upload_size_;
769 uint64 upload_position_;
770
771 // Data for current page -----------------------------------------------------
772
[email protected]987fc3a2011-05-26 14:18:09773 // When a title cannot be taken from any entry, this title will be used.
774 string16 page_title_when_no_navigation_entry_;
775
[email protected]0dd3a0ab2011-02-18 08:17:44776 // When a navigation occurs, we record its contents MIME type. It can be
777 // used to check whether we can do something for some special contents.
778 std::string contents_mime_type_;
779
780 // Character encoding.
781 std::string encoding_;
782
[email protected]0dd3a0ab2011-02-18 08:17:44783 // True if this is a secure page which displayed insecure content.
784 bool displayed_insecure_content_;
785
[email protected]0dd3a0ab2011-02-18 08:17:44786 // Data for misc internal state ----------------------------------------------
787
788 // See capturing_contents() above.
789 bool capturing_contents_;
790
791 // See getter above.
792 bool is_being_destroyed_;
793
794 // Indicates whether we should notify about disconnection of this
795 // TabContents. This is used to ensure disconnection notifications only
796 // happen if a connection notification has happened and that they happen only
797 // once.
798 bool notify_disconnection_;
799
[email protected]2e5b90c2011-08-16 21:11:55800 // Pointer to the JavaScript dialog creator, lazily assigned. Used because the
801 // delegate of this TabContents is nulled before its destructor is called.
802 content::JavaScriptDialogCreator* dialog_creator_;
803
[email protected]0dd3a0ab2011-02-18 08:17:44804#if defined(OS_WIN)
805 // Handle to an event that's set when the page is showing a message box (or
806 // equivalent constrained window). Plugin processes check this to know if
807 // they should pump messages then.
808 base::win::ScopedHandle message_box_active_;
809#endif
810
[email protected]0dd3a0ab2011-02-18 08:17:44811 // Set to true when there is an active "before unload" dialog. When true,
812 // we've forced the throbber to start in Navigate, and we need to remember to
813 // turn it off in OnJavaScriptMessageBoxClosed if the navigation is canceled.
814 bool is_showing_before_unload_dialog_;
815
[email protected]0dd3a0ab2011-02-18 08:17:44816 // Settings that get passed to the renderer process.
817 RendererPreferences renderer_preferences_;
818
819 // If this tab was created from a renderer using window.open, this will be
820 // non-NULL and represent the WebUI of the opening renderer.
[email protected]1fd1a502011-03-30 16:55:56821 WebUI::TypeID opener_web_ui_type_;
[email protected]0dd3a0ab2011-02-18 08:17:44822
823 // The time that we started to create the new tab page.
824 base::TimeTicks new_tab_start_time_;
825
826 // The time that we started to close the tab.
827 base::TimeTicks tab_close_start_time_;
828
829 // The time that this tab was last selected.
830 base::TimeTicks last_selected_time_;
831
[email protected]0dd3a0ab2011-02-18 08:17:44832 // See description above setter.
833 bool closed_by_user_gesture_;
834
835 // Minimum/maximum zoom percent.
836 int minimum_zoom_percent_;
837 int maximum_zoom_percent_;
838 // If true, the default zoom limits have been overriden for this tab, in which
839 // case we don't want saved settings to apply to it and we don't want to
840 // remember it.
841 bool temporary_zoom_settings_;
842
843 // A list of observers notified when page state changes. Weak references.
844 ObserverList<TabContentsObserver> observers_;
845
846 // Content restrictions, used to disable print/copy etc based on content's
847 // (full-page plugins for now only) permissions.
848 int content_restrictions_;
849
[email protected]0dd3a0ab2011-02-18 08:17:44850 DISALLOW_COPY_AND_ASSIGN(TabContents);
851};
852
853#endif // CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_H_