blob: 8262c9540f76c2ecf43cbb646d765b06a8bfd39d [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
[email protected]0dd3a0ab2011-02-18 08:17:44254 // Commands ------------------------------------------------------------------
255
256 // Implementation of PageNavigator.
[email protected]00c37fc2011-08-02 00:22:50257
258 // Deprecated. Please use the one-argument variant instead.
259 // TODO(adriansc): Remove this method once refactoring changed all call sites.
[email protected]992e4542011-07-20 23:09:25260 virtual TabContents* OpenURL(const GURL& url,
261 const GURL& referrer,
262 WindowOpenDisposition disposition,
263 PageTransition::Type transition) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44264
[email protected]00c37fc2011-08-02 00:22:50265 virtual TabContents* OpenURL(const OpenURLParams& params) OVERRIDE;
266
[email protected]0dd3a0ab2011-02-18 08:17:44267 // Called by the NavigationController to cause the TabContents to navigate to
268 // the current pending entry. The NavigationController should be called back
[email protected]9a7e68c2011-05-26 17:35:50269 // with RendererDidNavigate on success or DiscardPendingEntry on failure.
270 // The callbacks can be inside of this function, or at some future time.
[email protected]0dd3a0ab2011-02-18 08:17:44271 //
272 // The entry has a PageID of -1 if newly created (corresponding to navigation
273 // to a new URL).
274 //
275 // If this method returns false, then the navigation is discarded (equivalent
276 // to calling DiscardPendingEntry on the NavigationController).
277 virtual bool NavigateToPendingEntry(
278 NavigationController::ReloadType reload_type);
279
280 // Stop any pending navigation.
281 virtual void Stop();
282
[email protected]0dd3a0ab2011-02-18 08:17:44283 // Creates a new TabContents with the same state as this one. The returned
284 // heap-allocated pointer is owned by the caller.
285 virtual TabContents* Clone();
286
287 // Shows the page info.
288 void ShowPageInfo(const GURL& url,
289 const NavigationEntry::SSLStatus& ssl,
290 bool show_history);
291
[email protected]0dd3a0ab2011-02-18 08:17:44292 // Window management ---------------------------------------------------------
293
[email protected]473174942011-04-19 22:52:35294 // Adds a new tab or window with the given already-created contents.
[email protected]e7cfdbd2011-04-22 14:41:37295 void AddNewContents(TabContents* new_contents,
296 WindowOpenDisposition disposition,
297 const gfx::Rect& initial_pos,
298 bool user_gesture);
[email protected]0dd3a0ab2011-02-18 08:17:44299
[email protected]0dd3a0ab2011-02-18 08:17:44300 // Views and focus -----------------------------------------------------------
301 // TODO(brettw): Most of these should be removed and the caller should call
302 // the view directly.
303
304 // Returns the actual window that is focused when this TabContents is shown.
305 gfx::NativeView GetContentNativeView() const;
306
307 // Returns the NativeView associated with this TabContents. Outside of
308 // automation in the context of the UI, this is required to be implemented.
309 gfx::NativeView GetNativeView() const;
310
311 // Returns the bounds of this TabContents in the screen coordinate system.
312 void GetContainerBounds(gfx::Rect *out) const;
313
314 // Makes the tab the focused window.
315 void Focus();
316
317 // Focuses the first (last if |reverse| is true) element in the page.
318 // Invoked when this tab is getting the focus through tab traversal (|reverse|
319 // is true when using Shift-Tab).
320 void FocusThroughTabTraversal(bool reverse);
321
322 // These next two functions are declared on RenderViewHostManager::Delegate
323 // but also accessed directly by other callers.
324
325 // Returns true if the location bar should be focused by default rather than
326 // the page contents. The view calls this function when the tab is focused
327 // to see what it should do.
328 virtual bool FocusLocationBarByDefault();
329
330 // Focuses the location bar.
331 virtual void SetFocusToLocationBar(bool select_all);
332
333 // Creates a view and sets the size for the specified RVH.
334 virtual void CreateViewAndSetSizeForRVH(RenderViewHost* rvh);
335
[email protected]0dd3a0ab2011-02-18 08:17:44336 // Toolbars and such ---------------------------------------------------------
337
[email protected]686493142011-07-15 21:47:22338 // Notifies the delegate that a download is about to be started.
339 // This notification is fired before a local temporary file has been created.
340 bool CanDownload(int request_id);
341
342 // Notifies the delegate that a download started.
343 void OnStartDownload(DownloadItem* download);
344
[email protected]0dd3a0ab2011-02-18 08:17:44345 // Interstitials -------------------------------------------------------------
346
347 // Various other systems need to know about our interstitials.
348 bool showing_interstitial_page() const {
349 return render_manager_.interstitial_page() != NULL;
350 }
351
352 // Sets the passed passed interstitial as the currently showing interstitial.
353 // |interstitial_page| should be non NULL (use the remove_interstitial_page
354 // method to unset the interstitial) and no interstitial page should be set
355 // when there is already a non NULL interstitial page set.
356 void set_interstitial_page(InterstitialPage* interstitial_page) {
357 render_manager_.set_interstitial_page(interstitial_page);
358 }
359
360 // Unsets the currently showing interstitial.
361 void remove_interstitial_page() {
362 render_manager_.remove_interstitial_page();
363 }
364
365 // Returns the currently showing interstitial, NULL if no interstitial is
366 // showing.
367 InterstitialPage* interstitial_page() const {
368 return render_manager_.interstitial_page();
369 }
370
371 // Misc state & callbacks ----------------------------------------------------
372
[email protected]c7dd2f62011-07-18 15:57:59373 // Prepare for saving the current web page to disk.
374 void OnSavePage();
375
376 // Save page with the main HTML file path, the directory for saving resources,
377 // and the save type: HTML only or complete web page. Returns true if the
378 // saving process has been initiated successfully.
379 bool SavePage(const FilePath& main_file, const FilePath& dir_path,
380 SavePackage::SavePackageType save_type);
381
382 // Prepare for saving the URL to disk.
383 // URL may refer to the iframe on the page.
384 void OnSaveURL(const GURL& url);
385
[email protected]0dd3a0ab2011-02-18 08:17:44386 // Returns true if the active NavigationEntry's page_id equals page_id.
387 bool IsActiveEntry(int32 page_id);
388
389 const std::string& contents_mime_type() const {
390 return contents_mime_type_;
391 }
392
393 // Returns true if this TabContents will notify about disconnection.
394 bool notify_disconnection() const { return notify_disconnection_; }
395
396 // Override the encoding and reload the page by sending down
397 // ViewMsg_SetPageEncoding to the renderer. |UpdateEncoding| is kinda
398 // the opposite of this, by which 'browser' is notified of
399 // the encoding of the current tab from 'renderer' (determined by
400 // auto-detect, http header, meta, bom detection, etc).
401 void SetOverrideEncoding(const std::string& encoding);
402
403 // Remove any user-defined override encoding and reload by sending down
404 // ViewMsg_ResetPageEncodingToDefault to the renderer.
405 void ResetOverrideEncoding();
406
[email protected]0dd3a0ab2011-02-18 08:17:44407 RendererPreferences* GetMutableRendererPrefs() {
408 return &renderer_preferences_;
409 }
410
[email protected]1fd1a502011-03-30 16:55:56411 void set_opener_web_ui_type(WebUI::TypeID opener_web_ui_type) {
[email protected]0dd3a0ab2011-02-18 08:17:44412 opener_web_ui_type_ = opener_web_ui_type;
413 }
414
[email protected]0dd3a0ab2011-02-18 08:17:44415 // Set the time when we started to create the new tab page. This time is
416 // from before we created this TabContents.
417 void set_new_tab_start_time(const base::TimeTicks& time) {
418 new_tab_start_time_ = time;
419 }
[email protected]763ec4ca2011-04-29 15:48:12420 base::TimeTicks new_tab_start_time() const { return new_tab_start_time_; }
[email protected]0dd3a0ab2011-02-18 08:17:44421
422 // Notification that tab closing has started. This can be called multiple
423 // times, subsequent calls are ignored.
424 void OnCloseStarted();
425
[email protected]0dd3a0ab2011-02-18 08:17:44426 // Returns true if underlying TabContentsView should accept drag-n-drop.
427 bool ShouldAcceptDragAndDrop() const;
428
429 // A render view-originated drag has ended. Informs the render view host and
430 // tab contents delegate.
431 void SystemDragEnded();
432
433 // Indicates if this tab was explicitly closed by the user (control-w, close
434 // tab menu item...). This is false for actions that indirectly close the tab,
435 // such as closing the window. The setter is maintained by TabStripModel, and
436 // the getter only useful from within TAB_CLOSED notification
437 void set_closed_by_user_gesture(bool value) {
438 closed_by_user_gesture_ = value;
439 }
440 bool closed_by_user_gesture() const { return closed_by_user_gesture_; }
441
[email protected]3ab9cb82011-06-03 18:02:07442 // Overridden from JavaScriptDialogDelegate:
443 virtual void OnDialogClosed(IPC::Message* reply_msg,
444 bool success,
445 const string16& user_input) OVERRIDE;
446 virtual gfx::NativeWindow GetDialogRootWindow() OVERRIDE;
[email protected]a1e97f02011-06-30 14:04:34447 virtual void OnDialogShown() OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44448
[email protected]0dd3a0ab2011-02-18 08:17:44449 // Gets the zoom level for this tab.
450 double GetZoomLevel() const;
451
452 // Gets the zoom percent for this tab.
453 int GetZoomPercent(bool* enable_increment, bool* enable_decrement);
454
[email protected]0dd3a0ab2011-02-18 08:17:44455 // Opens view-source tab for this contents.
456 void ViewSource();
457
[email protected]932b7a12011-03-09 12:50:27458 void ViewFrameSource(const GURL& url,
459 const std::string& content_state);
460
[email protected]0dd3a0ab2011-02-18 08:17:44461 // Gets the minimum/maximum zoom percent.
462 int minimum_zoom_percent() const { return minimum_zoom_percent_; }
463 int maximum_zoom_percent() const { return maximum_zoom_percent_; }
464
465 int content_restrictions() const { return content_restrictions_; }
[email protected]c40d6232011-03-25 00:16:21466 void SetContentRestrictions(int restrictions);
[email protected]0dd3a0ab2011-02-18 08:17:44467
[email protected]1fd1a502011-03-30 16:55:56468 // Query the WebUIFactory for the TypeID for the current URL.
469 WebUI::TypeID GetWebUITypeForCurrentState();
470
[email protected]b375c5d2011-05-03 21:15:04471 // Returns the WebUI for the current state of the tab. This will either be
472 // the pending WebUI, the committed WebUI, or NULL.
473 WebUI* GetWebUIForCurrentState();
474
[email protected]0dd3a0ab2011-02-18 08:17:44475 protected:
[email protected]553602e12011-04-05 17:01:18476 friend class TabContentsObserver;
[email protected]553602e12011-04-05 17:01:18477
478 // Add and remove observers for page navigation notifications. Adding or
479 // removing multiple times has no effect. The order in which notifications
480 // are sent to observers is undefined. Clients must be sure to remove the
481 // observer before they go away.
482 void AddObserver(TabContentsObserver* observer);
483 void RemoveObserver(TabContentsObserver* observer);
484
[email protected]0dd3a0ab2011-02-18 08:17:44485 private:
486 friend class NavigationController;
[email protected]0dd3a0ab2011-02-18 08:17:44487
488 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, NoJSMessageOnInterstitials);
489 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, UpdateTitle);
490 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, CrossSiteCantPreemptAfterUnload);
[email protected]0dd3a0ab2011-02-18 08:17:44491 FRIEND_TEST_ALL_PREFIXES(FormStructureBrowserTest, HTMLFiles);
492 FRIEND_TEST_ALL_PREFIXES(NavigationControllerTest, HistoryNavigate);
493 FRIEND_TEST_ALL_PREFIXES(RenderViewHostManagerTest, PageDoesBackAndReload);
494
495 // Temporary until the view/contents separation is complete.
496 friend class TabContentsView;
[email protected]9a56a0d2011-05-13 19:03:31497#if defined(TOOLKIT_VIEWS)
[email protected]7e2cef52011-04-11 21:47:23498 friend class TabContentsViewViews;
[email protected]0dd3a0ab2011-02-18 08:17:44499#elif defined(OS_MACOSX)
500 friend class TabContentsViewMac;
501#elif defined(TOOLKIT_USES_GTK)
502 friend class TabContentsViewGtk;
503#endif
504
505 // So InterstitialPage can access SetIsLoading.
506 friend class InterstitialPage;
507
508 // TODO(brettw) TestTabContents shouldn't exist!
509 friend class TestTabContents;
510
[email protected]0dd3a0ab2011-02-18 08:17:44511 // Message handlers.
512 void OnDidStartProvisionalLoadForFrame(int64 frame_id,
513 bool main_frame,
[email protected]eacb080b2011-05-22 19:40:26514 bool has_opener_set,
[email protected]0dd3a0ab2011-02-18 08:17:44515 const GURL& url);
516 void OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]eacb080b2011-05-22 19:40:26517 bool has_opener_set,
[email protected]0dd3a0ab2011-02-18 08:17:44518 const GURL& source_url,
519 const GURL& target_url);
520 void OnDidFailProvisionalLoadWithError(int64 frame_id,
521 bool main_frame,
522 int error_code,
523 const GURL& url,
524 bool showing_repost_interstitial);
525 void OnDidLoadResourceFromMemoryCache(const GURL& url,
[email protected]70435962011-08-02 20:13:28526 const std::string& security_info,
527 const std::string& http_request,
528 ResourceType::Type resource_type);
[email protected]0dd3a0ab2011-02-18 08:17:44529 void OnDidDisplayInsecureContent();
530 void OnDidRunInsecureContent(const std::string& security_origin,
531 const GURL& target_url);
532 void OnDocumentLoadedInFrame(int64 frame_id);
533 void OnDidFinishLoad(int64 frame_id);
534 void OnUpdateContentRestrictions(int restrictions);
[email protected]0dd3a0ab2011-02-18 08:17:44535 void OnGoToEntryAtOffset(int offset);
[email protected]216813952011-05-19 22:21:26536 void OnUpdateZoomLimits(int minimum_percent,
537 int maximum_percent,
538 bool remember);
539 void OnFocusedNodeChanged(bool is_editable_node);
[email protected]3a29a6e2011-08-24 18:26:21540 void OnEnumerateDirectory(int request_id, const FilePath& path);
[email protected]7d189022011-08-25 22:54:20541 void OnJSOutOfMemory();
542 void OnRegisterProtocolHandler(const std::string& protocol,
543 const GURL& url,
544 const string16& title);
545 void OnRegisterIntentHandler(const string16& action,
546 const string16& type,
547 const string16& href,
548 const string16& title);
549 void OnWebIntentDispatch(const IPC::Message& message,
[email protected]ce9751942011-09-21 01:57:24550 const webkit_glue::WebIntentData& intent,
[email protected]7d189022011-08-25 22:54:20551 int intent_id);
[email protected]b888919c2011-09-02 00:32:16552 void OnFindReply(int request_id, int number_of_matches,
553 const gfx::Rect& selection_rect, int active_match_ordinal,
554 bool final_update);
[email protected]d952a052011-09-06 18:42:45555 void OnCrashedPlugin(const FilePath& plugin_path);
[email protected]7fc4bbb2011-09-08 21:23:10556 void OnAppCacheAccessed(const GURL& manifest_url, bool blocked_by_policy);
[email protected]0dd3a0ab2011-02-18 08:17:44557
558 // Changes the IsLoading state and notifies delegate as needed
559 // |details| is used to provide details on the load that just finished
560 // (but can be null if not applicable). Can be overridden.
561 void SetIsLoading(bool is_loading,
562 LoadNotificationDetails* details);
563
[email protected]0dd3a0ab2011-02-18 08:17:44564 // Called by derived classes to indicate that we're no longer waiting for a
565 // response. This won't actually update the throbber, but it will get picked
566 // up at the next animation step if the throbber is going.
567 void SetNotWaitingForResponse() { waiting_for_response_ = false; }
568
[email protected]0dd3a0ab2011-02-18 08:17:44569 // Navigation helpers --------------------------------------------------------
570 //
571 // These functions are helpers for Navigate() and DidNavigate().
572
573 // Handles post-navigation tasks in DidNavigate AFTER the entry has been
574 // committed to the navigation controller. Note that the navigation entry is
575 // not provided since it may be invalid/changed after being committed. The
576 // current navigation entry is in the NavigationController at this point.
577 void DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:13578 const content::LoadCommittedDetails& details,
[email protected]0dd3a0ab2011-02-18 08:17:44579 const ViewHostMsg_FrameNavigate_Params& params);
580 void DidNavigateAnyFramePostCommit(
581 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:13582 const content::LoadCommittedDetails& details,
[email protected]0dd3a0ab2011-02-18 08:17:44583 const ViewHostMsg_FrameNavigate_Params& params);
584
[email protected]0dd3a0ab2011-02-18 08:17:44585 // If our controller was restored and the page id is > than the site
586 // instance's page id, the site instances page id is updated as well as the
587 // renderers max page id.
588 void UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
589 RenderViewHost* rvh);
590
[email protected]0dd3a0ab2011-02-18 08:17:44591 // Saves the given title to the navigation entry and does associated work. It
592 // will update history and the view for the new title, and also synthesize
593 // titles for file URLs that have none (so we require that the URL of the
594 // entry already be set).
595 //
596 // This is used as the backend for state updates, which include a new title,
597 // or the dedicated set title message. It returns true if the new title is
598 // different and was therefore updated.
[email protected]acafd272011-07-26 17:35:57599 bool UpdateTitleForEntry(NavigationEntry* entry, const string16& title);
[email protected]0dd3a0ab2011-02-18 08:17:44600
601 // Causes the TabContents to navigate in the right renderer to |entry|, which
602 // must be already part of the entries in the navigation controller.
603 // This does not change the NavigationController state.
604 bool NavigateToEntry(const NavigationEntry& entry,
605 NavigationController::ReloadType reload_type);
606
[email protected]796931a92011-08-10 01:32:14607 // Sets the history for this tab_contents to |history_length| entries, and
608 // moves the current page_id to the last entry in the list if it's valid.
609 // This is mainly used when a prerendered page is swapped into the current
[email protected]9e1ad4b2011-08-14 16:49:19610 // tab. The method is virtual for testing.
611 virtual void SetHistoryLengthAndPrune(const SiteInstance* site_instance,
612 int merge_history_length,
613 int32 minimum_page_id);
[email protected]796931a92011-08-10 01:32:14614
[email protected]0dd3a0ab2011-02-18 08:17:44615 // Misc non-view stuff -------------------------------------------------------
616
617 // Helper functions for sending notifications.
618 void NotifySwapped();
619 void NotifyConnected();
620 void NotifyDisconnected();
621
[email protected]0dd3a0ab2011-02-18 08:17:44622 // RenderViewHostDelegate ----------------------------------------------------
623
624 // RenderViewHostDelegate implementation.
[email protected]544e27f2011-07-25 21:41:54625 virtual RenderViewHostDelegate::View* GetViewDelegate() OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44626 virtual RenderViewHostDelegate::RendererManagement*
[email protected]544e27f2011-07-25 21:41:54627 GetRendererManagementDelegate() OVERRIDE;
628 virtual TabContents* GetAsTabContents() OVERRIDE;
[email protected]ee162d82011-10-06 06:35:37629 virtual content::ViewType::Type GetRenderViewType() const OVERRIDE;
[email protected]544e27f2011-07-25 21:41:54630 virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE;
631 virtual void RenderViewReady(RenderViewHost* render_view_host) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44632 virtual void RenderViewGone(RenderViewHost* render_view_host,
633 base::TerminationStatus status,
[email protected]544e27f2011-07-25 21:41:54634 int error_code) OVERRIDE;
635 virtual void RenderViewDeleted(RenderViewHost* render_view_host) OVERRIDE;
636 virtual void DidNavigate(
637 RenderViewHost* render_view_host,
638 const ViewHostMsg_FrameNavigate_Params& params) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44639 virtual void UpdateState(RenderViewHost* render_view_host,
640 int32 page_id,
[email protected]544e27f2011-07-25 21:41:54641 const std::string& state) OVERRIDE;
[email protected]6b2f7a82011-04-25 19:30:51642 virtual void UpdateTitle(RenderViewHost* render_view_host,
643 int32 page_id,
[email protected]a49e10b2011-08-01 23:57:46644 const string16& title,
645 base::i18n::TextDirection title_direction) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44646 virtual void UpdateEncoding(RenderViewHost* render_view_host,
[email protected]544e27f2011-07-25 21:41:54647 const std::string& encoding) OVERRIDE;
648 virtual void UpdateTargetURL(int32 page_id, const GURL& url) OVERRIDE;
649 virtual void Close(RenderViewHost* render_view_host) OVERRIDE;
650 virtual void RequestMove(const gfx::Rect& new_bounds) OVERRIDE;
651 virtual void DidStartLoading() OVERRIDE;
652 virtual void DidStopLoading() OVERRIDE;
653 virtual void DidCancelLoading() OVERRIDE;
654 virtual void DidChangeLoadProgress(double progress) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44655 virtual void DocumentOnLoadCompletedInMainFrame(
656 RenderViewHost* render_view_host,
[email protected]544e27f2011-07-25 21:41:54657 int32 page_id) OVERRIDE;
[email protected]ae5184d62011-10-06 19:25:58658 virtual void RequestOpenURL(const GURL& url,
659 const GURL& referrer,
660 WindowOpenDisposition disposition,
661 int64 source_frame_id) OVERRIDE;
[email protected]992db4c2011-05-12 15:37:15662 virtual void RunJavaScriptMessage(const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:41663 const string16& message,
664 const string16& default_prompt,
[email protected]0dd3a0ab2011-02-18 08:17:44665 const GURL& frame_url,
666 const int flags,
667 IPC::Message* reply_msg,
[email protected]3ab9cb82011-06-03 18:02:07668 bool* did_suppress_message) OVERRIDE;
[email protected]992db4c2011-05-12 15:37:15669 virtual void RunBeforeUnloadConfirm(const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:41670 const string16& message,
[email protected]544e27f2011-07-25 21:41:54671 IPC::Message* reply_msg) OVERRIDE;
[email protected]3d7474ff2011-07-27 17:47:37672 virtual RendererPreferences GetRendererPrefs(
673 content::BrowserContext* browser_context) const OVERRIDE;
[email protected]544e27f2011-07-25 21:41:54674 virtual WebPreferences GetWebkitPrefs() OVERRIDE;
675 virtual void OnUserGesture() OVERRIDE;
676 virtual void OnIgnoredUIEvent() OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44677 virtual void RendererUnresponsive(RenderViewHost* render_view_host,
[email protected]544e27f2011-07-25 21:41:54678 bool is_during_unload) OVERRIDE;
679 virtual void RendererResponsive(RenderViewHost* render_view_host) OVERRIDE;
680 virtual void LoadStateChanged(const GURL& url,
[email protected]9c235f042011-08-10 22:28:21681 const net::LoadStateWithParam& load_state,
[email protected]544e27f2011-07-25 21:41:54682 uint64 upload_position,
683 uint64 upload_size) OVERRIDE;
684 virtual void WorkerCrashed() OVERRIDE;
685 virtual void Activate() OVERRIDE;
686 virtual void Deactivate() OVERRIDE;
687 virtual void LostCapture() OVERRIDE;
[email protected]63954792011-07-11 04:17:48688 virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
[email protected]544e27f2011-07-25 21:41:54689 bool* is_keyboard_shortcut) OVERRIDE;
690 virtual void HandleKeyboardEvent(
691 const NativeWebKeyboardEvent& event) OVERRIDE;
692 virtual void HandleMouseUp() OVERRIDE;
693 virtual void HandleMouseActivate() OVERRIDE;
[email protected]6c2e472f2011-08-24 23:26:18694 virtual bool OnMessageReceived(const IPC::Message& message);
695 virtual void RunFileChooser(RenderViewHost* render_view_host,
696 const ViewHostMsg_RunFileChooser_Params& params);
[email protected]8a5e0ca2011-08-25 06:30:47697 virtual void ToggleFullscreenMode(bool enter_fullscreen) OVERRIDE;
[email protected]5d5f7af2011-10-01 01:38:12698 virtual bool IsFullscreenForCurrentTab() const OVERRIDE;
[email protected]0548c5352011-09-07 00:33:33699 virtual void UpdatePreferredSize(const gfx::Size& pref_size) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44700
701 // RenderViewHostManager::Delegate -------------------------------------------
702
[email protected]0dd3a0ab2011-02-18 08:17:44703 virtual void BeforeUnloadFiredFromRenderManager(
704 bool proceed,
705 bool* proceed_to_fire_unload);
706 virtual void DidStartLoadingFromRenderManager(
707 RenderViewHost* render_view_host);
708 virtual void RenderViewGoneFromRenderManager(
709 RenderViewHost* render_view_host);
710 virtual void UpdateRenderViewSizeForRenderManager();
711 virtual void NotifySwappedFromRenderManager();
712 virtual NavigationController& GetControllerForRenderManager();
713 virtual WebUI* CreateWebUIForRenderManager(const GURL& url);
714 virtual NavigationEntry* GetLastCommittedNavigationEntryForRenderManager();
715
716 // Initializes the given renderer if necessary and creates the view ID
717 // corresponding to this view host. If this method is not called and the
718 // process is not shared, then the TabContents will act as though the renderer
719 // is not running (i.e., it will render "sad tab"). This method is
720 // automatically called from LoadURL.
721 //
722 // If you are attaching to an already-existing RenderView, you should call
723 // InitWithExistingID.
724 virtual bool CreateRenderViewForRenderManager(
725 RenderViewHost* render_view_host);
726
[email protected]81898992011-06-14 22:15:00727 // Stores random bits of data for others to associate with this object.
728 // WARNING: this needs to be deleted after NavigationController.
729 PropertyBag property_bag_;
730
[email protected]0dd3a0ab2011-02-18 08:17:44731 // Data for core operation ---------------------------------------------------
732
733 // Delegate for notifying our owner about stuff. Not owned by us.
734 TabContentsDelegate* delegate_;
735
736 // Handles the back/forward list and loading.
737 NavigationController controller_;
738
739 // The corresponding view.
740 scoped_ptr<TabContentsView> view_;
741
742 // Helper classes ------------------------------------------------------------
743
744 // Manages creation and swapping of render views.
745 RenderViewHostManager render_manager_;
746
[email protected]c7dd2f62011-07-18 15:57:59747 // SavePackage, lazily created.
748 scoped_refptr<SavePackage> save_package_;
749
[email protected]0dd3a0ab2011-02-18 08:17:44750 // Data for loading state ----------------------------------------------------
751
752 // Indicates whether we're currently loading a resource.
753 bool is_loading_;
754
755 // Indicates if the tab is considered crashed.
756 base::TerminationStatus crashed_status_;
757 int crashed_error_code_;
758
759 // See waiting_for_response() above.
760 bool waiting_for_response_;
761
762 // Indicates the largest PageID we've seen. This field is ignored if we are
763 // a TabContents, in which case the max page ID is stored separately with
764 // each SiteInstance.
765 // TODO(brettw) this seems like it can be removed according to the comment.
766 int32 max_page_id_;
767
768 // System time at which the current load was started.
769 base::TimeTicks current_load_start_;
770
771 // The current load state and the URL associated with it.
[email protected]9c235f042011-08-10 22:28:21772 net::LoadStateWithParam load_state_;
[email protected]0dd3a0ab2011-02-18 08:17:44773 string16 load_state_host_;
774 // Upload progress, for displaying in the status bar.
775 // Set to zero when there is no significant upload happening.
776 uint64 upload_size_;
777 uint64 upload_position_;
778
779 // Data for current page -----------------------------------------------------
780
[email protected]987fc3a2011-05-26 14:18:09781 // When a title cannot be taken from any entry, this title will be used.
782 string16 page_title_when_no_navigation_entry_;
783
[email protected]0dd3a0ab2011-02-18 08:17:44784 // When a navigation occurs, we record its contents MIME type. It can be
785 // used to check whether we can do something for some special contents.
786 std::string contents_mime_type_;
787
788 // Character encoding.
789 std::string encoding_;
790
[email protected]0dd3a0ab2011-02-18 08:17:44791 // True if this is a secure page which displayed insecure content.
792 bool displayed_insecure_content_;
793
[email protected]0dd3a0ab2011-02-18 08:17:44794 // Data for misc internal state ----------------------------------------------
795
796 // See capturing_contents() above.
797 bool capturing_contents_;
798
799 // See getter above.
800 bool is_being_destroyed_;
801
802 // Indicates whether we should notify about disconnection of this
803 // TabContents. This is used to ensure disconnection notifications only
804 // happen if a connection notification has happened and that they happen only
805 // once.
806 bool notify_disconnection_;
807
[email protected]2e5b90c2011-08-16 21:11:55808 // Pointer to the JavaScript dialog creator, lazily assigned. Used because the
809 // delegate of this TabContents is nulled before its destructor is called.
810 content::JavaScriptDialogCreator* dialog_creator_;
811
[email protected]0dd3a0ab2011-02-18 08:17:44812#if defined(OS_WIN)
813 // Handle to an event that's set when the page is showing a message box (or
814 // equivalent constrained window). Plugin processes check this to know if
815 // they should pump messages then.
816 base::win::ScopedHandle message_box_active_;
817#endif
818
[email protected]0dd3a0ab2011-02-18 08:17:44819 // Set to true when there is an active "before unload" dialog. When true,
820 // we've forced the throbber to start in Navigate, and we need to remember to
821 // turn it off in OnJavaScriptMessageBoxClosed if the navigation is canceled.
822 bool is_showing_before_unload_dialog_;
823
[email protected]0dd3a0ab2011-02-18 08:17:44824 // Settings that get passed to the renderer process.
825 RendererPreferences renderer_preferences_;
826
827 // If this tab was created from a renderer using window.open, this will be
828 // non-NULL and represent the WebUI of the opening renderer.
[email protected]1fd1a502011-03-30 16:55:56829 WebUI::TypeID opener_web_ui_type_;
[email protected]0dd3a0ab2011-02-18 08:17:44830
831 // The time that we started to create the new tab page.
832 base::TimeTicks new_tab_start_time_;
833
834 // The time that we started to close the tab.
835 base::TimeTicks tab_close_start_time_;
836
837 // The time that this tab was last selected.
838 base::TimeTicks last_selected_time_;
839
[email protected]0dd3a0ab2011-02-18 08:17:44840 // See description above setter.
841 bool closed_by_user_gesture_;
842
843 // Minimum/maximum zoom percent.
844 int minimum_zoom_percent_;
845 int maximum_zoom_percent_;
846 // If true, the default zoom limits have been overriden for this tab, in which
847 // case we don't want saved settings to apply to it and we don't want to
848 // remember it.
849 bool temporary_zoom_settings_;
850
851 // A list of observers notified when page state changes. Weak references.
852 ObserverList<TabContentsObserver> observers_;
853
854 // Content restrictions, used to disable print/copy etc based on content's
855 // (full-page plugins for now only) permissions.
856 int content_restrictions_;
857
[email protected]0dd3a0ab2011-02-18 08:17:44858 DISALLOW_COPY_AND_ASSIGN(TabContents);
859};
860
861#endif // CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_H_