blob: 7ecd21cfe35ee55349ac33761b5b15d3c29177c6 [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]0dd3a0ab2011-02-18 08:17:4457struct ViewHostMsg_FrameNavigate_Params;
[email protected]0dd3a0ab2011-02-18 08:17:4458struct WebPreferences;
[email protected]ddb85052011-05-18 14:40:2759class WebUI;
[email protected]3a29a6e2011-08-24 18:26:2160struct ViewHostMsg_RunFileChooser_Params;
[email protected]0dd3a0ab2011-02-18 08:17:4461
62// Describes what goes in the main content area of a tab. TabContents is
63// the only type of TabContents, and these should be merged together.
[email protected]8d128d62011-09-13 22:11:5764class CONTENT_EXPORT TabContents : public PageNavigator,
65 public RenderViewHostDelegate,
66 public RenderViewHostManager::Delegate,
67 public content::JavaScriptDialogDelegate {
[email protected]0dd3a0ab2011-02-18 08:17:4468 public:
69 // Flags passed to the TabContentsDelegate.NavigationStateChanged to tell it
70 // what has changed. Combine them to update more than one thing.
71 enum InvalidateTypes {
72 INVALIDATE_URL = 1 << 0, // The URL has changed.
73 INVALIDATE_TAB = 1 << 1, // The favicon, app icon, or crashed
74 // state changed.
75 INVALIDATE_LOAD = 1 << 2, // The loading state has changed.
76 INVALIDATE_PAGE_ACTIONS = 1 << 3, // Page action icons have changed.
[email protected]93f230e02011-06-01 14:40:0077 INVALIDATE_TITLE = 1 << 4, // The title changed.
[email protected]0dd3a0ab2011-02-18 08:17:4478 };
79
80 // |base_tab_contents| is used if we want to size the new tab contents view
81 // based on an existing tab contents view. This can be NULL if not needed.
82 //
83 // The session storage namespace parameter allows multiple render views and
84 // tab contentses to share the same session storage (part of the WebStorage
85 // spec) space. This is useful when restoring tabs, but most callers should
86 // pass in NULL which will cause a new SessionStorageNamespace to be created.
[email protected]3d7474ff2011-07-27 17:47:3787 TabContents(content::BrowserContext* browser_context,
[email protected]0dd3a0ab2011-02-18 08:17:4488 SiteInstance* site_instance,
89 int routing_id,
90 const TabContents* base_tab_contents,
91 SessionStorageNamespace* session_storage_namespace);
92 virtual ~TabContents();
93
94 // Intrinsic tab state -------------------------------------------------------
95
96 // Returns the property bag for this tab contents, where callers can add
97 // extra data they may wish to associate with the tab. Returns a pointer
98 // rather than a reference since the PropertyAccessors expect this.
99 const PropertyBag* property_bag() const { return &property_bag_; }
100 PropertyBag* property_bag() { return &property_bag_; }
101
102 TabContentsDelegate* delegate() const { return delegate_; }
[email protected]1de2b8b2011-06-29 19:38:46103 void set_delegate(TabContentsDelegate* delegate);
[email protected]0dd3a0ab2011-02-18 08:17:44104
105 // Gets the controller for this tab contents.
106 NavigationController& controller() { return controller_; }
107 const NavigationController& controller() const { return controller_; }
108
[email protected]3d7474ff2011-07-27 17:47:37109 // Returns the user browser context associated with this TabContents (via the
[email protected]0dd3a0ab2011-02-18 08:17:44110 // NavigationController).
[email protected]3d7474ff2011-07-27 17:47:37111 content::BrowserContext* browser_context() const {
112 return controller_.browser_context();
113 }
114
[email protected]c7dd2f62011-07-18 15:57:59115 // Returns the SavePackage which manages the page saving job. May be NULL.
116 SavePackage* save_package() const { return save_package_.get(); }
117
[email protected]0dd3a0ab2011-02-18 08:17:44118 // Return the currently active RenderProcessHost and RenderViewHost. Each of
119 // these may change over time.
120 RenderProcessHost* GetRenderProcessHost() const;
121 RenderViewHost* render_view_host() const {
122 return render_manager_.current_host();
123 }
124
[email protected]93f230e02011-06-01 14:40:00125 WebUI* committed_web_ui() const {
126 return render_manager_.web_ui();
127 }
128
[email protected]0dd3a0ab2011-02-18 08:17:44129 WebUI* web_ui() const {
130 return render_manager_.web_ui() ? render_manager_.web_ui()
131 : render_manager_.pending_web_ui();
132 }
133
134 // Returns the currently active RenderWidgetHostView. This may change over
135 // time and can be NULL (during setup and teardown).
136 RenderWidgetHostView* GetRenderWidgetHostView() const {
137 return render_manager_.GetRenderWidgetHostView();
138 }
139
140 // The TabContentsView will never change and is guaranteed non-NULL.
141 TabContentsView* view() const {
142 return view_.get();
143 }
144
[email protected]0dd3a0ab2011-02-18 08:17:44145 // Tab navigation state ------------------------------------------------------
146
147 // Returns the current navigation properties, which if a navigation is
148 // pending may be provisional (e.g., the navigation could result in a
149 // download, in which case the URL would revert to what it was previously).
150 virtual const GURL& GetURL() const;
151 virtual const string16& GetTitle() const;
152
153 // The max PageID of any page that this TabContents has loaded. PageIDs
154 // increase with each new page that is loaded by a tab. If this is a
155 // TabContents, then the max PageID is kept separately on each SiteInstance.
156 // Returns -1 if no PageIDs have yet been seen.
157 int32 GetMaxPageID();
158
159 // Updates the max PageID to be at least the given PageID.
160 void UpdateMaxPageID(int32 page_id);
161
162 // Returns the site instance associated with the current page. By default,
163 // there is no site instance. TabContents overrides this to provide proper
164 // access to its site instance.
165 virtual SiteInstance* GetSiteInstance() const;
166
[email protected]77362eb2011-08-01 17:18:38167 // Returns the SiteInstance for the pending navigation, if any. Otherwise
168 // returns the current SiteInstance.
169 SiteInstance* GetPendingSiteInstance() const;
170
[email protected]0dd3a0ab2011-02-18 08:17:44171 // Defines whether this tab's URL should be displayed in the browser's URL
172 // bar. Normally this is true so you can see the URL. This is set to false
173 // for the new tab page and related pages so that the URL bar is empty and
174 // the user is invited to type into it.
175 virtual bool ShouldDisplayURL();
176
[email protected]f5d978c2011-07-21 14:43:51177 // Return whether this tab contents is loading a resource, or whether its
178 // web_ui is.
179 bool IsLoading() const;
[email protected]0dd3a0ab2011-02-18 08:17:44180
181 // Returns whether this tab contents is waiting for a first-response for the
182 // main resource of the page. This controls whether the throbber state is
183 // "waiting" or "loading."
184 bool waiting_for_response() const { return waiting_for_response_; }
185
[email protected]9c235f042011-08-10 22:28:21186 const net::LoadStateWithParam& load_state() const { return load_state_; }
187 const string16& load_state_host() const { return load_state_host_; }
[email protected]0dd3a0ab2011-02-18 08:17:44188 uint64 upload_size() const { return upload_size_; }
189 uint64 upload_position() const { return upload_position_; }
190
191 const std::string& encoding() const { return encoding_; }
192 void set_encoding(const std::string& encoding);
193 void reset_encoding() {
194 encoding_.clear();
195 }
196
[email protected]0dd3a0ab2011-02-18 08:17:44197 bool displayed_insecure_content() const {
198 return displayed_insecure_content_;
199 }
200
201 // Internal state ------------------------------------------------------------
202
203 // This flag indicates whether the tab contents is currently being
204 // screenshotted by the DraggedTabController.
205 bool capturing_contents() const { return capturing_contents_; }
206 void set_capturing_contents(bool cap) { capturing_contents_ = cap; }
207
208 // Indicates whether this tab should be considered crashed. The setter will
209 // also notify the delegate when the flag is changed.
210 bool is_crashed() const {
211 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
212 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
213 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
214 }
215 base::TerminationStatus crashed_status() const { return crashed_status_; }
216 int crashed_error_code() const { return crashed_error_code_; }
217 void SetIsCrashed(base::TerminationStatus status, int error_code);
218
[email protected]0dd3a0ab2011-02-18 08:17:44219 // Whether the tab is in the process of being destroyed.
220 // Added as a tentative work-around for focus related bug #4633. This allows
221 // us not to store focus when a tab is being closed.
222 bool is_being_destroyed() const { return is_being_destroyed_; }
223
224 // Convenience method for notifying the delegate of a navigation state
225 // change. See TabContentsDelegate.
226 void NotifyNavigationStateChanged(unsigned changed_flags);
227
228 // Invoked when the tab contents becomes selected. If you override, be sure
229 // and invoke super's implementation.
230 virtual void DidBecomeSelected();
231 base::TimeTicks last_selected_time() const {
232 return last_selected_time_;
233 }
234
235 // Invoked when the tab contents becomes hidden.
236 // NOTE: If you override this, call the superclass version too!
237 virtual void WasHidden();
238
[email protected]0dd3a0ab2011-02-18 08:17:44239 // TODO(brettw) document these.
240 virtual void ShowContents();
241 virtual void HideContents();
242
243 // Returns true if the before unload and unload listeners need to be
244 // fired. The value of this changes over time. For example, if true and the
245 // before unload listener is executed and allows the user to exit, then this
246 // returns false.
247 bool NeedToFireBeforeUnload();
248
[email protected]0dd3a0ab2011-02-18 08:17:44249 // Expose the render manager for testing.
[email protected]03ff5e52011-09-30 00:28:14250 RenderViewHostManager* render_manager_for_testing() {
251 return &render_manager_;
252 }
[email protected]0dd3a0ab2011-02-18 08:17:44253
254 // In the underlying RenderViewHostManager, swaps in the provided
255 // RenderViewHost to replace the current RenderViewHost. The current RVH
256 // will be shutdown and ultimately deleted.
257 void SwapInRenderViewHost(RenderViewHost* rvh);
258
259 // Commands ------------------------------------------------------------------
260
261 // Implementation of PageNavigator.
[email protected]00c37fc2011-08-02 00:22:50262
263 // Deprecated. Please use the one-argument variant instead.
264 // TODO(adriansc): Remove this method once refactoring changed all call sites.
[email protected]992e4542011-07-20 23:09:25265 virtual TabContents* OpenURL(const GURL& url,
266 const GURL& referrer,
267 WindowOpenDisposition disposition,
268 PageTransition::Type transition) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44269
[email protected]00c37fc2011-08-02 00:22:50270 virtual TabContents* OpenURL(const OpenURLParams& params) OVERRIDE;
271
[email protected]0dd3a0ab2011-02-18 08:17:44272 // Called by the NavigationController to cause the TabContents to navigate to
273 // the current pending entry. The NavigationController should be called back
[email protected]9a7e68c2011-05-26 17:35:50274 // with RendererDidNavigate on success or DiscardPendingEntry on failure.
275 // The callbacks can be inside of this function, or at some future time.
[email protected]0dd3a0ab2011-02-18 08:17:44276 //
277 // The entry has a PageID of -1 if newly created (corresponding to navigation
278 // to a new URL).
279 //
280 // If this method returns false, then the navigation is discarded (equivalent
281 // to calling DiscardPendingEntry on the NavigationController).
282 virtual bool NavigateToPendingEntry(
283 NavigationController::ReloadType reload_type);
284
285 // Stop any pending navigation.
286 virtual void Stop();
287
[email protected]0dd3a0ab2011-02-18 08:17:44288 // Creates a new TabContents with the same state as this one. The returned
289 // heap-allocated pointer is owned by the caller.
290 virtual TabContents* Clone();
291
292 // Shows the page info.
293 void ShowPageInfo(const GURL& url,
294 const NavigationEntry::SSLStatus& ssl,
295 bool show_history);
296
[email protected]0dd3a0ab2011-02-18 08:17:44297 // Window management ---------------------------------------------------------
298
[email protected]473174942011-04-19 22:52:35299 // Adds a new tab or window with the given already-created contents.
[email protected]e7cfdbd2011-04-22 14:41:37300 void AddNewContents(TabContents* new_contents,
301 WindowOpenDisposition disposition,
302 const gfx::Rect& initial_pos,
303 bool user_gesture);
[email protected]0dd3a0ab2011-02-18 08:17:44304
[email protected]0dd3a0ab2011-02-18 08:17:44305 // Views and focus -----------------------------------------------------------
306 // TODO(brettw): Most of these should be removed and the caller should call
307 // the view directly.
308
309 // Returns the actual window that is focused when this TabContents is shown.
310 gfx::NativeView GetContentNativeView() const;
311
312 // Returns the NativeView associated with this TabContents. Outside of
313 // automation in the context of the UI, this is required to be implemented.
314 gfx::NativeView GetNativeView() const;
315
316 // Returns the bounds of this TabContents in the screen coordinate system.
317 void GetContainerBounds(gfx::Rect *out) const;
318
319 // Makes the tab the focused window.
320 void Focus();
321
322 // Focuses the first (last if |reverse| is true) element in the page.
323 // Invoked when this tab is getting the focus through tab traversal (|reverse|
324 // is true when using Shift-Tab).
325 void FocusThroughTabTraversal(bool reverse);
326
327 // These next two functions are declared on RenderViewHostManager::Delegate
328 // but also accessed directly by other callers.
329
330 // Returns true if the location bar should be focused by default rather than
331 // the page contents. The view calls this function when the tab is focused
332 // to see what it should do.
333 virtual bool FocusLocationBarByDefault();
334
335 // Focuses the location bar.
336 virtual void SetFocusToLocationBar(bool select_all);
337
338 // Creates a view and sets the size for the specified RVH.
339 virtual void CreateViewAndSetSizeForRVH(RenderViewHost* rvh);
340
[email protected]0dd3a0ab2011-02-18 08:17:44341 // Toolbars and such ---------------------------------------------------------
342
[email protected]686493142011-07-15 21:47:22343 // Notifies the delegate that a download is about to be started.
344 // This notification is fired before a local temporary file has been created.
345 bool CanDownload(int request_id);
346
347 // Notifies the delegate that a download started.
348 void OnStartDownload(DownloadItem* download);
349
[email protected]0dd3a0ab2011-02-18 08:17:44350 // Interstitials -------------------------------------------------------------
351
352 // Various other systems need to know about our interstitials.
353 bool showing_interstitial_page() const {
354 return render_manager_.interstitial_page() != NULL;
355 }
356
357 // Sets the passed passed interstitial as the currently showing interstitial.
358 // |interstitial_page| should be non NULL (use the remove_interstitial_page
359 // method to unset the interstitial) and no interstitial page should be set
360 // when there is already a non NULL interstitial page set.
361 void set_interstitial_page(InterstitialPage* interstitial_page) {
362 render_manager_.set_interstitial_page(interstitial_page);
363 }
364
365 // Unsets the currently showing interstitial.
366 void remove_interstitial_page() {
367 render_manager_.remove_interstitial_page();
368 }
369
370 // Returns the currently showing interstitial, NULL if no interstitial is
371 // showing.
372 InterstitialPage* interstitial_page() const {
373 return render_manager_.interstitial_page();
374 }
375
376 // Misc state & callbacks ----------------------------------------------------
377
[email protected]c7dd2f62011-07-18 15:57:59378 // Prepare for saving the current web page to disk.
379 void OnSavePage();
380
381 // Save page with the main HTML file path, the directory for saving resources,
382 // and the save type: HTML only or complete web page. Returns true if the
383 // saving process has been initiated successfully.
384 bool SavePage(const FilePath& main_file, const FilePath& dir_path,
385 SavePackage::SavePackageType save_type);
386
387 // Prepare for saving the URL to disk.
388 // URL may refer to the iframe on the page.
389 void OnSaveURL(const GURL& url);
390
[email protected]0dd3a0ab2011-02-18 08:17:44391 // Returns true if the active NavigationEntry's page_id equals page_id.
392 bool IsActiveEntry(int32 page_id);
393
394 const std::string& contents_mime_type() const {
395 return contents_mime_type_;
396 }
397
398 // Returns true if this TabContents will notify about disconnection.
399 bool notify_disconnection() const { return notify_disconnection_; }
400
401 // Override the encoding and reload the page by sending down
402 // ViewMsg_SetPageEncoding to the renderer. |UpdateEncoding| is kinda
403 // the opposite of this, by which 'browser' is notified of
404 // the encoding of the current tab from 'renderer' (determined by
405 // auto-detect, http header, meta, bom detection, etc).
406 void SetOverrideEncoding(const std::string& encoding);
407
408 // Remove any user-defined override encoding and reload by sending down
409 // ViewMsg_ResetPageEncodingToDefault to the renderer.
410 void ResetOverrideEncoding();
411
[email protected]0dd3a0ab2011-02-18 08:17:44412 RendererPreferences* GetMutableRendererPrefs() {
413 return &renderer_preferences_;
414 }
415
[email protected]1fd1a502011-03-30 16:55:56416 void set_opener_web_ui_type(WebUI::TypeID opener_web_ui_type) {
[email protected]0dd3a0ab2011-02-18 08:17:44417 opener_web_ui_type_ = opener_web_ui_type;
418 }
419
[email protected]0dd3a0ab2011-02-18 08:17:44420 // Set the time when we started to create the new tab page. This time is
421 // from before we created this TabContents.
422 void set_new_tab_start_time(const base::TimeTicks& time) {
423 new_tab_start_time_ = time;
424 }
[email protected]763ec4ca2011-04-29 15:48:12425 base::TimeTicks new_tab_start_time() const { return new_tab_start_time_; }
[email protected]0dd3a0ab2011-02-18 08:17:44426
427 // Notification that tab closing has started. This can be called multiple
428 // times, subsequent calls are ignored.
429 void OnCloseStarted();
430
[email protected]0dd3a0ab2011-02-18 08:17:44431 // Returns true if underlying TabContentsView should accept drag-n-drop.
432 bool ShouldAcceptDragAndDrop() const;
433
434 // A render view-originated drag has ended. Informs the render view host and
435 // tab contents delegate.
436 void SystemDragEnded();
437
438 // Indicates if this tab was explicitly closed by the user (control-w, close
439 // tab menu item...). This is false for actions that indirectly close the tab,
440 // such as closing the window. The setter is maintained by TabStripModel, and
441 // the getter only useful from within TAB_CLOSED notification
442 void set_closed_by_user_gesture(bool value) {
443 closed_by_user_gesture_ = value;
444 }
445 bool closed_by_user_gesture() const { return closed_by_user_gesture_; }
446
[email protected]3ab9cb82011-06-03 18:02:07447 // Overridden from JavaScriptDialogDelegate:
448 virtual void OnDialogClosed(IPC::Message* reply_msg,
449 bool success,
450 const string16& user_input) OVERRIDE;
451 virtual gfx::NativeWindow GetDialogRootWindow() OVERRIDE;
[email protected]a1e97f02011-06-30 14:04:34452 virtual void OnDialogShown() OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44453
[email protected]0dd3a0ab2011-02-18 08:17:44454 // Gets the zoom level for this tab.
455 double GetZoomLevel() const;
456
457 // Gets the zoom percent for this tab.
458 int GetZoomPercent(bool* enable_increment, bool* enable_decrement);
459
[email protected]0dd3a0ab2011-02-18 08:17:44460 // Opens view-source tab for this contents.
461 void ViewSource();
462
[email protected]932b7a12011-03-09 12:50:27463 void ViewFrameSource(const GURL& url,
464 const std::string& content_state);
465
[email protected]0dd3a0ab2011-02-18 08:17:44466 // Gets the minimum/maximum zoom percent.
467 int minimum_zoom_percent() const { return minimum_zoom_percent_; }
468 int maximum_zoom_percent() const { return maximum_zoom_percent_; }
469
470 int content_restrictions() const { return content_restrictions_; }
[email protected]c40d6232011-03-25 00:16:21471 void SetContentRestrictions(int restrictions);
[email protected]0dd3a0ab2011-02-18 08:17:44472
[email protected]1fd1a502011-03-30 16:55:56473 // Query the WebUIFactory for the TypeID for the current URL.
474 WebUI::TypeID GetWebUITypeForCurrentState();
475
[email protected]b375c5d2011-05-03 21:15:04476 // Returns the WebUI for the current state of the tab. This will either be
477 // the pending WebUI, the committed WebUI, or NULL.
478 WebUI* GetWebUIForCurrentState();
479
[email protected]0dd3a0ab2011-02-18 08:17:44480 protected:
[email protected]553602e12011-04-05 17:01:18481 friend class TabContentsObserver;
[email protected]553602e12011-04-05 17:01:18482
483 // Add and remove observers for page navigation notifications. Adding or
484 // removing multiple times has no effect. The order in which notifications
485 // are sent to observers is undefined. Clients must be sure to remove the
486 // observer before they go away.
487 void AddObserver(TabContentsObserver* observer);
488 void RemoveObserver(TabContentsObserver* observer);
489
[email protected]0dd3a0ab2011-02-18 08:17:44490 private:
491 friend class NavigationController;
[email protected]0dd3a0ab2011-02-18 08:17:44492
493 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, NoJSMessageOnInterstitials);
494 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, UpdateTitle);
495 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, CrossSiteCantPreemptAfterUnload);
[email protected]0dd3a0ab2011-02-18 08:17:44496 FRIEND_TEST_ALL_PREFIXES(FormStructureBrowserTest, HTMLFiles);
497 FRIEND_TEST_ALL_PREFIXES(NavigationControllerTest, HistoryNavigate);
498 FRIEND_TEST_ALL_PREFIXES(RenderViewHostManagerTest, PageDoesBackAndReload);
499
500 // Temporary until the view/contents separation is complete.
501 friend class TabContentsView;
[email protected]9a56a0d2011-05-13 19:03:31502#if defined(TOOLKIT_VIEWS)
[email protected]7e2cef52011-04-11 21:47:23503 friend class TabContentsViewViews;
[email protected]0dd3a0ab2011-02-18 08:17:44504#elif defined(OS_MACOSX)
505 friend class TabContentsViewMac;
506#elif defined(TOOLKIT_USES_GTK)
507 friend class TabContentsViewGtk;
508#endif
509
510 // So InterstitialPage can access SetIsLoading.
511 friend class InterstitialPage;
512
513 // TODO(brettw) TestTabContents shouldn't exist!
514 friend class TestTabContents;
515
[email protected]0dd3a0ab2011-02-18 08:17:44516 // Message handlers.
517 void OnDidStartProvisionalLoadForFrame(int64 frame_id,
518 bool main_frame,
[email protected]eacb080b2011-05-22 19:40:26519 bool has_opener_set,
[email protected]0dd3a0ab2011-02-18 08:17:44520 const GURL& url);
521 void OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]eacb080b2011-05-22 19:40:26522 bool has_opener_set,
[email protected]0dd3a0ab2011-02-18 08:17:44523 const GURL& source_url,
524 const GURL& target_url);
525 void OnDidFailProvisionalLoadWithError(int64 frame_id,
526 bool main_frame,
527 int error_code,
528 const GURL& url,
529 bool showing_repost_interstitial);
530 void OnDidLoadResourceFromMemoryCache(const GURL& url,
[email protected]70435962011-08-02 20:13:28531 const std::string& security_info,
532 const std::string& http_request,
533 ResourceType::Type resource_type);
[email protected]0dd3a0ab2011-02-18 08:17:44534 void OnDidDisplayInsecureContent();
535 void OnDidRunInsecureContent(const std::string& security_origin,
536 const GURL& target_url);
537 void OnDocumentLoadedInFrame(int64 frame_id);
538 void OnDidFinishLoad(int64 frame_id);
539 void OnUpdateContentRestrictions(int restrictions);
[email protected]0dd3a0ab2011-02-18 08:17:44540 void OnGoToEntryAtOffset(int offset);
[email protected]216813952011-05-19 22:21:26541 void OnUpdateZoomLimits(int minimum_percent,
542 int maximum_percent,
543 bool remember);
544 void OnFocusedNodeChanged(bool is_editable_node);
[email protected]3a29a6e2011-08-24 18:26:21545 void OnEnumerateDirectory(int request_id, const FilePath& path);
[email protected]7d189022011-08-25 22:54:20546 void OnJSOutOfMemory();
547 void OnRegisterProtocolHandler(const std::string& protocol,
548 const GURL& url,
549 const string16& title);
550 void OnRegisterIntentHandler(const string16& action,
551 const string16& type,
552 const string16& href,
553 const string16& title);
554 void OnWebIntentDispatch(const IPC::Message& message,
[email protected]ce9751942011-09-21 01:57:24555 const webkit_glue::WebIntentData& intent,
[email protected]7d189022011-08-25 22:54:20556 int intent_id);
[email protected]b888919c2011-09-02 00:32:16557 void OnFindReply(int request_id, int number_of_matches,
558 const gfx::Rect& selection_rect, int active_match_ordinal,
559 bool final_update);
[email protected]d952a052011-09-06 18:42:45560 void OnCrashedPlugin(const FilePath& plugin_path);
[email protected]7fc4bbb2011-09-08 21:23:10561 void OnAppCacheAccessed(const GURL& manifest_url, bool blocked_by_policy);
[email protected]0dd3a0ab2011-02-18 08:17:44562
563 // Changes the IsLoading state and notifies delegate as needed
564 // |details| is used to provide details on the load that just finished
565 // (but can be null if not applicable). Can be overridden.
566 void SetIsLoading(bool is_loading,
567 LoadNotificationDetails* details);
568
[email protected]0dd3a0ab2011-02-18 08:17:44569 // Called by derived classes to indicate that we're no longer waiting for a
570 // response. This won't actually update the throbber, but it will get picked
571 // up at the next animation step if the throbber is going.
572 void SetNotWaitingForResponse() { waiting_for_response_ = false; }
573
[email protected]0dd3a0ab2011-02-18 08:17:44574 // Navigation helpers --------------------------------------------------------
575 //
576 // These functions are helpers for Navigate() and DidNavigate().
577
578 // Handles post-navigation tasks in DidNavigate AFTER the entry has been
579 // committed to the navigation controller. Note that the navigation entry is
580 // not provided since it may be invalid/changed after being committed. The
581 // current navigation entry is in the NavigationController at this point.
582 void DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:13583 const content::LoadCommittedDetails& details,
[email protected]0dd3a0ab2011-02-18 08:17:44584 const ViewHostMsg_FrameNavigate_Params& params);
585 void DidNavigateAnyFramePostCommit(
586 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:13587 const content::LoadCommittedDetails& details,
[email protected]0dd3a0ab2011-02-18 08:17:44588 const ViewHostMsg_FrameNavigate_Params& params);
589
[email protected]0dd3a0ab2011-02-18 08:17:44590 // If our controller was restored and the page id is > than the site
591 // instance's page id, the site instances page id is updated as well as the
592 // renderers max page id.
593 void UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
594 RenderViewHost* rvh);
595
[email protected]0dd3a0ab2011-02-18 08:17:44596 // Saves the given title to the navigation entry and does associated work. It
597 // will update history and the view for the new title, and also synthesize
598 // titles for file URLs that have none (so we require that the URL of the
599 // entry already be set).
600 //
601 // This is used as the backend for state updates, which include a new title,
602 // or the dedicated set title message. It returns true if the new title is
603 // different and was therefore updated.
[email protected]acafd272011-07-26 17:35:57604 bool UpdateTitleForEntry(NavigationEntry* entry, const string16& title);
[email protected]0dd3a0ab2011-02-18 08:17:44605
606 // Causes the TabContents to navigate in the right renderer to |entry|, which
607 // must be already part of the entries in the navigation controller.
608 // This does not change the NavigationController state.
609 bool NavigateToEntry(const NavigationEntry& entry,
610 NavigationController::ReloadType reload_type);
611
[email protected]796931a92011-08-10 01:32:14612 // Sets the history for this tab_contents to |history_length| entries, and
613 // moves the current page_id to the last entry in the list if it's valid.
614 // This is mainly used when a prerendered page is swapped into the current
[email protected]9e1ad4b2011-08-14 16:49:19615 // tab. The method is virtual for testing.
616 virtual void SetHistoryLengthAndPrune(const SiteInstance* site_instance,
617 int merge_history_length,
618 int32 minimum_page_id);
[email protected]796931a92011-08-10 01:32:14619
[email protected]0dd3a0ab2011-02-18 08:17:44620 // Misc non-view stuff -------------------------------------------------------
621
622 // Helper functions for sending notifications.
623 void NotifySwapped();
624 void NotifyConnected();
625 void NotifyDisconnected();
626
[email protected]0dd3a0ab2011-02-18 08:17:44627 // RenderViewHostDelegate ----------------------------------------------------
628
629 // RenderViewHostDelegate implementation.
[email protected]544e27f2011-07-25 21:41:54630 virtual RenderViewHostDelegate::View* GetViewDelegate() OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44631 virtual RenderViewHostDelegate::RendererManagement*
[email protected]544e27f2011-07-25 21:41:54632 GetRendererManagementDelegate() OVERRIDE;
633 virtual TabContents* GetAsTabContents() OVERRIDE;
634 virtual ViewType::Type GetRenderViewType() const OVERRIDE;
635 virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE;
636 virtual void RenderViewReady(RenderViewHost* render_view_host) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44637 virtual void RenderViewGone(RenderViewHost* render_view_host,
638 base::TerminationStatus status,
[email protected]544e27f2011-07-25 21:41:54639 int error_code) OVERRIDE;
640 virtual void RenderViewDeleted(RenderViewHost* render_view_host) OVERRIDE;
641 virtual void DidNavigate(
642 RenderViewHost* render_view_host,
643 const ViewHostMsg_FrameNavigate_Params& params) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44644 virtual void UpdateState(RenderViewHost* render_view_host,
645 int32 page_id,
[email protected]544e27f2011-07-25 21:41:54646 const std::string& state) OVERRIDE;
[email protected]6b2f7a82011-04-25 19:30:51647 virtual void UpdateTitle(RenderViewHost* render_view_host,
648 int32 page_id,
[email protected]a49e10b2011-08-01 23:57:46649 const string16& title,
650 base::i18n::TextDirection title_direction) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44651 virtual void UpdateEncoding(RenderViewHost* render_view_host,
[email protected]544e27f2011-07-25 21:41:54652 const std::string& encoding) OVERRIDE;
653 virtual void UpdateTargetURL(int32 page_id, const GURL& url) OVERRIDE;
654 virtual void Close(RenderViewHost* render_view_host) OVERRIDE;
655 virtual void RequestMove(const gfx::Rect& new_bounds) OVERRIDE;
656 virtual void DidStartLoading() OVERRIDE;
657 virtual void DidStopLoading() OVERRIDE;
658 virtual void DidCancelLoading() OVERRIDE;
659 virtual void DidChangeLoadProgress(double progress) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44660 virtual void DocumentOnLoadCompletedInMainFrame(
661 RenderViewHost* render_view_host,
[email protected]544e27f2011-07-25 21:41:54662 int32 page_id) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44663 virtual void RequestOpenURL(const GURL& url, const GURL& referrer,
[email protected]544e27f2011-07-25 21:41:54664 WindowOpenDisposition disposition) OVERRIDE;
[email protected]992db4c2011-05-12 15:37:15665 virtual void RunJavaScriptMessage(const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:41666 const string16& message,
667 const string16& default_prompt,
[email protected]0dd3a0ab2011-02-18 08:17:44668 const GURL& frame_url,
669 const int flags,
670 IPC::Message* reply_msg,
[email protected]3ab9cb82011-06-03 18:02:07671 bool* did_suppress_message) OVERRIDE;
[email protected]992db4c2011-05-12 15:37:15672 virtual void RunBeforeUnloadConfirm(const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:41673 const string16& message,
[email protected]544e27f2011-07-25 21:41:54674 IPC::Message* reply_msg) OVERRIDE;
[email protected]3d7474ff2011-07-27 17:47:37675 virtual RendererPreferences GetRendererPrefs(
676 content::BrowserContext* browser_context) const OVERRIDE;
[email protected]544e27f2011-07-25 21:41:54677 virtual WebPreferences GetWebkitPrefs() OVERRIDE;
678 virtual void OnUserGesture() OVERRIDE;
679 virtual void OnIgnoredUIEvent() OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44680 virtual void RendererUnresponsive(RenderViewHost* render_view_host,
[email protected]544e27f2011-07-25 21:41:54681 bool is_during_unload) OVERRIDE;
682 virtual void RendererResponsive(RenderViewHost* render_view_host) OVERRIDE;
683 virtual void LoadStateChanged(const GURL& url,
[email protected]9c235f042011-08-10 22:28:21684 const net::LoadStateWithParam& load_state,
[email protected]544e27f2011-07-25 21:41:54685 uint64 upload_position,
686 uint64 upload_size) OVERRIDE;
687 virtual void WorkerCrashed() OVERRIDE;
688 virtual void Activate() OVERRIDE;
689 virtual void Deactivate() OVERRIDE;
690 virtual void LostCapture() OVERRIDE;
[email protected]63954792011-07-11 04:17:48691 virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
[email protected]544e27f2011-07-25 21:41:54692 bool* is_keyboard_shortcut) OVERRIDE;
693 virtual void HandleKeyboardEvent(
694 const NativeWebKeyboardEvent& event) OVERRIDE;
695 virtual void HandleMouseUp() OVERRIDE;
696 virtual void HandleMouseActivate() OVERRIDE;
[email protected]6c2e472f2011-08-24 23:26:18697 virtual bool OnMessageReceived(const IPC::Message& message);
698 virtual void RunFileChooser(RenderViewHost* render_view_host,
699 const ViewHostMsg_RunFileChooser_Params& params);
[email protected]8a5e0ca2011-08-25 06:30:47700 virtual void ToggleFullscreenMode(bool enter_fullscreen) OVERRIDE;
[email protected]5d5f7af2011-10-01 01:38:12701 virtual bool IsFullscreenForCurrentTab() const OVERRIDE;
[email protected]0548c5352011-09-07 00:33:33702 virtual void UpdatePreferredSize(const gfx::Size& pref_size) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44703
704 // RenderViewHostManager::Delegate -------------------------------------------
705
[email protected]0dd3a0ab2011-02-18 08:17:44706 virtual void BeforeUnloadFiredFromRenderManager(
707 bool proceed,
708 bool* proceed_to_fire_unload);
709 virtual void DidStartLoadingFromRenderManager(
710 RenderViewHost* render_view_host);
711 virtual void RenderViewGoneFromRenderManager(
712 RenderViewHost* render_view_host);
713 virtual void UpdateRenderViewSizeForRenderManager();
714 virtual void NotifySwappedFromRenderManager();
715 virtual NavigationController& GetControllerForRenderManager();
716 virtual WebUI* CreateWebUIForRenderManager(const GURL& url);
717 virtual NavigationEntry* GetLastCommittedNavigationEntryForRenderManager();
718
719 // Initializes the given renderer if necessary and creates the view ID
720 // corresponding to this view host. If this method is not called and the
721 // process is not shared, then the TabContents will act as though the renderer
722 // is not running (i.e., it will render "sad tab"). This method is
723 // automatically called from LoadURL.
724 //
725 // If you are attaching to an already-existing RenderView, you should call
726 // InitWithExistingID.
727 virtual bool CreateRenderViewForRenderManager(
728 RenderViewHost* render_view_host);
729
[email protected]81898992011-06-14 22:15:00730 // Stores random bits of data for others to associate with this object.
731 // WARNING: this needs to be deleted after NavigationController.
732 PropertyBag property_bag_;
733
[email protected]0dd3a0ab2011-02-18 08:17:44734 // Data for core operation ---------------------------------------------------
735
736 // Delegate for notifying our owner about stuff. Not owned by us.
737 TabContentsDelegate* delegate_;
738
739 // Handles the back/forward list and loading.
740 NavigationController controller_;
741
742 // The corresponding view.
743 scoped_ptr<TabContentsView> view_;
744
745 // Helper classes ------------------------------------------------------------
746
747 // Manages creation and swapping of render views.
748 RenderViewHostManager render_manager_;
749
[email protected]c7dd2f62011-07-18 15:57:59750 // SavePackage, lazily created.
751 scoped_refptr<SavePackage> save_package_;
752
[email protected]0dd3a0ab2011-02-18 08:17:44753 // Data for loading state ----------------------------------------------------
754
755 // Indicates whether we're currently loading a resource.
756 bool is_loading_;
757
758 // Indicates if the tab is considered crashed.
759 base::TerminationStatus crashed_status_;
760 int crashed_error_code_;
761
762 // See waiting_for_response() above.
763 bool waiting_for_response_;
764
765 // Indicates the largest PageID we've seen. This field is ignored if we are
766 // a TabContents, in which case the max page ID is stored separately with
767 // each SiteInstance.
768 // TODO(brettw) this seems like it can be removed according to the comment.
769 int32 max_page_id_;
770
771 // System time at which the current load was started.
772 base::TimeTicks current_load_start_;
773
774 // The current load state and the URL associated with it.
[email protected]9c235f042011-08-10 22:28:21775 net::LoadStateWithParam load_state_;
[email protected]0dd3a0ab2011-02-18 08:17:44776 string16 load_state_host_;
777 // Upload progress, for displaying in the status bar.
778 // Set to zero when there is no significant upload happening.
779 uint64 upload_size_;
780 uint64 upload_position_;
781
782 // Data for current page -----------------------------------------------------
783
[email protected]987fc3a2011-05-26 14:18:09784 // When a title cannot be taken from any entry, this title will be used.
785 string16 page_title_when_no_navigation_entry_;
786
[email protected]0dd3a0ab2011-02-18 08:17:44787 // When a navigation occurs, we record its contents MIME type. It can be
788 // used to check whether we can do something for some special contents.
789 std::string contents_mime_type_;
790
791 // Character encoding.
792 std::string encoding_;
793
[email protected]0dd3a0ab2011-02-18 08:17:44794 // True if this is a secure page which displayed insecure content.
795 bool displayed_insecure_content_;
796
[email protected]0dd3a0ab2011-02-18 08:17:44797 // Data for misc internal state ----------------------------------------------
798
799 // See capturing_contents() above.
800 bool capturing_contents_;
801
802 // See getter above.
803 bool is_being_destroyed_;
804
805 // Indicates whether we should notify about disconnection of this
806 // TabContents. This is used to ensure disconnection notifications only
807 // happen if a connection notification has happened and that they happen only
808 // once.
809 bool notify_disconnection_;
810
[email protected]2e5b90c2011-08-16 21:11:55811 // Pointer to the JavaScript dialog creator, lazily assigned. Used because the
812 // delegate of this TabContents is nulled before its destructor is called.
813 content::JavaScriptDialogCreator* dialog_creator_;
814
[email protected]0dd3a0ab2011-02-18 08:17:44815#if defined(OS_WIN)
816 // Handle to an event that's set when the page is showing a message box (or
817 // equivalent constrained window). Plugin processes check this to know if
818 // they should pump messages then.
819 base::win::ScopedHandle message_box_active_;
820#endif
821
[email protected]0dd3a0ab2011-02-18 08:17:44822 // Set to true when there is an active "before unload" dialog. When true,
823 // we've forced the throbber to start in Navigate, and we need to remember to
824 // turn it off in OnJavaScriptMessageBoxClosed if the navigation is canceled.
825 bool is_showing_before_unload_dialog_;
826
[email protected]0dd3a0ab2011-02-18 08:17:44827 // Settings that get passed to the renderer process.
828 RendererPreferences renderer_preferences_;
829
830 // If this tab was created from a renderer using window.open, this will be
831 // non-NULL and represent the WebUI of the opening renderer.
[email protected]1fd1a502011-03-30 16:55:56832 WebUI::TypeID opener_web_ui_type_;
[email protected]0dd3a0ab2011-02-18 08:17:44833
834 // The time that we started to create the new tab page.
835 base::TimeTicks new_tab_start_time_;
836
837 // The time that we started to close the tab.
838 base::TimeTicks tab_close_start_time_;
839
840 // The time that this tab was last selected.
841 base::TimeTicks last_selected_time_;
842
[email protected]0dd3a0ab2011-02-18 08:17:44843 // See description above setter.
844 bool closed_by_user_gesture_;
845
846 // Minimum/maximum zoom percent.
847 int minimum_zoom_percent_;
848 int maximum_zoom_percent_;
849 // If true, the default zoom limits have been overriden for this tab, in which
850 // case we don't want saved settings to apply to it and we don't want to
851 // remember it.
852 bool temporary_zoom_settings_;
853
854 // A list of observers notified when page state changes. Weak references.
855 ObserverList<TabContentsObserver> observers_;
856
857 // Content restrictions, used to disable print/copy etc based on content's
858 // (full-page plugins for now only) permissions.
859 int content_restrictions_;
860
[email protected]0dd3a0ab2011-02-18 08:17:44861 DISALLOW_COPY_AND_ASSIGN(TabContents);
862};
863
864#endif // CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_H_