blob: 8b8e4edffbbb567834368ab80cfd26165f753774 [file] [log] [blame]
[email protected]0dd3a0ab2011-02-18 08:17:441// Copyright (c) 2011 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_H_
6#define CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_H_
7#pragma once
8
9#include <deque>
10#include <map>
11#include <string>
[email protected]0dd3a0ab2011-02-18 08:17:4412
13#include "base/basictypes.h"
14#include "base/gtest_prod_util.h"
[email protected]3b63f8f42011-03-28 01:54:1515#include "base/memory/scoped_ptr.h"
[email protected]6eac57a2011-07-12 21:15:0916#include "base/observer_list.h"
[email protected]0dd3a0ab2011-02-18 08:17:4417#include "base/string16.h"
[email protected]c7dd2f62011-07-18 15:57:5918#include "content/browser/download/save_package.h"
[email protected]3ab9cb82011-06-03 18:02:0719#include "content/browser/javascript_dialogs.h"
[email protected]5de634712011-03-02 00:20:1920#include "content/browser/renderer_host/render_view_host_delegate.h"
[email protected]0dd3a0ab2011-02-18 08:17:4421#include "content/browser/tab_contents/constrained_window.h"
[email protected]0dd3a0ab2011-02-18 08:17:4422#include "content/browser/tab_contents/navigation_controller.h"
23#include "content/browser/tab_contents/navigation_entry.h"
24#include "content/browser/tab_contents/page_navigator.h"
25#include "content/browser/tab_contents/render_view_host_manager.h"
[email protected]553602e12011-04-05 17:01:1826#include "content/browser/tab_contents/tab_contents_observer.h"
[email protected]1fd1a502011-03-30 16:55:5627#include "content/browser/webui/web_ui.h"
[email protected]15a5fa52011-03-10 20:16:0428#include "content/common/property_bag.h"
[email protected]60916042011-03-19 00:43:3629#include "content/common/renderer_preferences.h"
[email protected]0dd3a0ab2011-02-18 08:17:4430#include "net/base/load_states.h"
31#include "ui/gfx/native_widget_types.h"
[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}
41
[email protected]686493142011-07-15 21:47:2242class DownloadItem;
[email protected]0dd3a0ab2011-02-18 08:17:4443class LoadNotificationDetails;
[email protected]ddb85052011-05-18 14:40:2744struct RendererPreferences;
[email protected]0dd3a0ab2011-02-18 08:17:4445class RenderViewHost;
46class SessionStorageNamespace;
47class SiteInstance;
48class SkBitmap;
[email protected]0dd3a0ab2011-02-18 08:17:4449class TabContentsDelegate;
50class TabContentsObserver;
[email protected]0dd3a0ab2011-02-18 08:17:4451class TabContentsView;
[email protected]8b0d7542011-05-16 19:36:5852struct ThumbnailScore;
[email protected]ddb85052011-05-18 14:40:2753class URLPattern;
[email protected]0dd3a0ab2011-02-18 08:17:4454struct ViewHostMsg_FrameNavigate_Params;
[email protected]0dd3a0ab2011-02-18 08:17:4455struct WebPreferences;
[email protected]ddb85052011-05-18 14:40:2756class WebUI;
[email protected]3a29a6e2011-08-24 18:26:2157struct ViewHostMsg_RunFileChooser_Params;
[email protected]0dd3a0ab2011-02-18 08:17:4458
59// Describes what goes in the main content area of a tab. TabContents is
60// the only type of TabContents, and these should be merged together.
61class TabContents : public PageNavigator,
[email protected]0dd3a0ab2011-02-18 08:17:4462 public RenderViewHostDelegate,
63 public RenderViewHostManager::Delegate,
[email protected]6eac57a2011-07-12 21:15:0964 public content::JavaScriptDialogDelegate {
[email protected]0dd3a0ab2011-02-18 08:17:4465 public:
66 // Flags passed to the TabContentsDelegate.NavigationStateChanged to tell it
67 // what has changed. Combine them to update more than one thing.
68 enum InvalidateTypes {
69 INVALIDATE_URL = 1 << 0, // The URL has changed.
70 INVALIDATE_TAB = 1 << 1, // The favicon, app icon, or crashed
71 // state changed.
72 INVALIDATE_LOAD = 1 << 2, // The loading state has changed.
73 INVALIDATE_PAGE_ACTIONS = 1 << 3, // Page action icons have changed.
[email protected]93f230e02011-06-01 14:40:0074 INVALIDATE_TITLE = 1 << 4, // The title changed.
[email protected]0dd3a0ab2011-02-18 08:17:4475 };
76
77 // |base_tab_contents| is used if we want to size the new tab contents view
78 // based on an existing tab contents view. This can be NULL if not needed.
79 //
80 // The session storage namespace parameter allows multiple render views and
81 // tab contentses to share the same session storage (part of the WebStorage
82 // spec) space. This is useful when restoring tabs, but most callers should
83 // pass in NULL which will cause a new SessionStorageNamespace to be created.
[email protected]3d7474ff2011-07-27 17:47:3784 TabContents(content::BrowserContext* browser_context,
[email protected]0dd3a0ab2011-02-18 08:17:4485 SiteInstance* site_instance,
86 int routing_id,
87 const TabContents* base_tab_contents,
88 SessionStorageNamespace* session_storage_namespace);
89 virtual ~TabContents();
90
91 // Intrinsic tab state -------------------------------------------------------
92
93 // Returns the property bag for this tab contents, where callers can add
94 // extra data they may wish to associate with the tab. Returns a pointer
95 // rather than a reference since the PropertyAccessors expect this.
96 const PropertyBag* property_bag() const { return &property_bag_; }
97 PropertyBag* property_bag() { return &property_bag_; }
98
99 TabContentsDelegate* delegate() const { return delegate_; }
[email protected]1de2b8b2011-06-29 19:38:46100 void set_delegate(TabContentsDelegate* delegate);
[email protected]0dd3a0ab2011-02-18 08:17:44101
102 // Gets the controller for this tab contents.
103 NavigationController& controller() { return controller_; }
104 const NavigationController& controller() const { return controller_; }
105
[email protected]3d7474ff2011-07-27 17:47:37106 // Returns the user browser context associated with this TabContents (via the
[email protected]0dd3a0ab2011-02-18 08:17:44107 // NavigationController).
[email protected]3d7474ff2011-07-27 17:47:37108 content::BrowserContext* browser_context() const {
109 return controller_.browser_context();
110 }
111
[email protected]c7dd2f62011-07-18 15:57:59112 // Returns the SavePackage which manages the page saving job. May be NULL.
113 SavePackage* save_package() const { return save_package_.get(); }
114
[email protected]0dd3a0ab2011-02-18 08:17:44115 // Return the currently active RenderProcessHost and RenderViewHost. Each of
116 // these may change over time.
117 RenderProcessHost* GetRenderProcessHost() const;
118 RenderViewHost* render_view_host() const {
119 return render_manager_.current_host();
120 }
121
[email protected]93f230e02011-06-01 14:40:00122 WebUI* committed_web_ui() const {
123 return render_manager_.web_ui();
124 }
125
[email protected]0dd3a0ab2011-02-18 08:17:44126 WebUI* web_ui() const {
127 return render_manager_.web_ui() ? render_manager_.web_ui()
128 : render_manager_.pending_web_ui();
129 }
130
131 // Returns the currently active RenderWidgetHostView. This may change over
132 // time and can be NULL (during setup and teardown).
133 RenderWidgetHostView* GetRenderWidgetHostView() const {
134 return render_manager_.GetRenderWidgetHostView();
135 }
136
137 // The TabContentsView will never change and is guaranteed non-NULL.
138 TabContentsView* view() const {
139 return view_.get();
140 }
141
[email protected]0dd3a0ab2011-02-18 08:17:44142 // Tab navigation state ------------------------------------------------------
143
144 // Returns the current navigation properties, which if a navigation is
145 // pending may be provisional (e.g., the navigation could result in a
146 // download, in which case the URL would revert to what it was previously).
147 virtual const GURL& GetURL() const;
148 virtual const string16& GetTitle() const;
149
150 // The max PageID of any page that this TabContents has loaded. PageIDs
151 // increase with each new page that is loaded by a tab. If this is a
152 // TabContents, then the max PageID is kept separately on each SiteInstance.
153 // Returns -1 if no PageIDs have yet been seen.
154 int32 GetMaxPageID();
155
156 // Updates the max PageID to be at least the given PageID.
157 void UpdateMaxPageID(int32 page_id);
158
159 // Returns the site instance associated with the current page. By default,
160 // there is no site instance. TabContents overrides this to provide proper
161 // access to its site instance.
162 virtual SiteInstance* GetSiteInstance() const;
163
[email protected]77362eb2011-08-01 17:18:38164 // Returns the SiteInstance for the pending navigation, if any. Otherwise
165 // returns the current SiteInstance.
166 SiteInstance* GetPendingSiteInstance() const;
167
[email protected]0dd3a0ab2011-02-18 08:17:44168 // Defines whether this tab's URL should be displayed in the browser's URL
169 // bar. Normally this is true so you can see the URL. This is set to false
170 // for the new tab page and related pages so that the URL bar is empty and
171 // the user is invited to type into it.
172 virtual bool ShouldDisplayURL();
173
[email protected]f5d978c2011-07-21 14:43:51174 // Return whether this tab contents is loading a resource, or whether its
175 // web_ui is.
176 bool IsLoading() const;
[email protected]0dd3a0ab2011-02-18 08:17:44177
178 // Returns whether this tab contents is waiting for a first-response for the
179 // main resource of the page. This controls whether the throbber state is
180 // "waiting" or "loading."
181 bool waiting_for_response() const { return waiting_for_response_; }
182
[email protected]9c235f042011-08-10 22:28:21183 const net::LoadStateWithParam& load_state() const { return load_state_; }
184 const string16& load_state_host() const { return load_state_host_; }
[email protected]0dd3a0ab2011-02-18 08:17:44185 uint64 upload_size() const { return upload_size_; }
186 uint64 upload_position() const { return upload_position_; }
187
188 const std::string& encoding() const { return encoding_; }
189 void set_encoding(const std::string& encoding);
190 void reset_encoding() {
191 encoding_.clear();
192 }
193
[email protected]0dd3a0ab2011-02-18 08:17:44194 bool displayed_insecure_content() const {
195 return displayed_insecure_content_;
196 }
197
198 // Internal state ------------------------------------------------------------
199
200 // This flag indicates whether the tab contents is currently being
201 // screenshotted by the DraggedTabController.
202 bool capturing_contents() const { return capturing_contents_; }
203 void set_capturing_contents(bool cap) { capturing_contents_ = cap; }
204
205 // Indicates whether this tab should be considered crashed. The setter will
206 // also notify the delegate when the flag is changed.
207 bool is_crashed() const {
208 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
209 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
210 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
211 }
212 base::TerminationStatus crashed_status() const { return crashed_status_; }
213 int crashed_error_code() const { return crashed_error_code_; }
214 void SetIsCrashed(base::TerminationStatus status, int error_code);
215
[email protected]0dd3a0ab2011-02-18 08:17:44216 // Whether the tab is in the process of being destroyed.
217 // Added as a tentative work-around for focus related bug #4633. This allows
218 // us not to store focus when a tab is being closed.
219 bool is_being_destroyed() const { return is_being_destroyed_; }
220
221 // Convenience method for notifying the delegate of a navigation state
222 // change. See TabContentsDelegate.
223 void NotifyNavigationStateChanged(unsigned changed_flags);
224
225 // Invoked when the tab contents becomes selected. If you override, be sure
226 // and invoke super's implementation.
227 virtual void DidBecomeSelected();
228 base::TimeTicks last_selected_time() const {
229 return last_selected_time_;
230 }
231
232 // Invoked when the tab contents becomes hidden.
233 // NOTE: If you override this, call the superclass version too!
234 virtual void WasHidden();
235
[email protected]0dd3a0ab2011-02-18 08:17:44236 // TODO(brettw) document these.
237 virtual void ShowContents();
238 virtual void HideContents();
239
240 // Returns true if the before unload and unload listeners need to be
241 // fired. The value of this changes over time. For example, if true and the
242 // before unload listener is executed and allows the user to exit, then this
243 // returns false.
244 bool NeedToFireBeforeUnload();
245
246#ifdef UNIT_TEST
247 // Expose the render manager for testing.
248 RenderViewHostManager* render_manager() { return &render_manager_; }
249#endif
250
251 // In the underlying RenderViewHostManager, swaps in the provided
252 // RenderViewHost to replace the current RenderViewHost. The current RVH
253 // will be shutdown and ultimately deleted.
254 void SwapInRenderViewHost(RenderViewHost* rvh);
255
256 // Commands ------------------------------------------------------------------
257
258 // Implementation of PageNavigator.
[email protected]00c37fc2011-08-02 00:22:50259
260 // Deprecated. Please use the one-argument variant instead.
261 // TODO(adriansc): Remove this method once refactoring changed all call sites.
[email protected]992e4542011-07-20 23:09:25262 virtual TabContents* OpenURL(const GURL& url,
263 const GURL& referrer,
264 WindowOpenDisposition disposition,
265 PageTransition::Type transition) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44266
[email protected]00c37fc2011-08-02 00:22:50267 virtual TabContents* OpenURL(const OpenURLParams& params) OVERRIDE;
268
[email protected]0dd3a0ab2011-02-18 08:17:44269 // Called by the NavigationController to cause the TabContents to navigate to
270 // the current pending entry. The NavigationController should be called back
[email protected]9a7e68c2011-05-26 17:35:50271 // with RendererDidNavigate on success or DiscardPendingEntry on failure.
272 // The callbacks can be inside of this function, or at some future time.
[email protected]0dd3a0ab2011-02-18 08:17:44273 //
274 // The entry has a PageID of -1 if newly created (corresponding to navigation
275 // to a new URL).
276 //
277 // If this method returns false, then the navigation is discarded (equivalent
278 // to calling DiscardPendingEntry on the NavigationController).
279 virtual bool NavigateToPendingEntry(
280 NavigationController::ReloadType reload_type);
281
282 // Stop any pending navigation.
283 virtual void Stop();
284
[email protected]0dd3a0ab2011-02-18 08:17:44285 // Creates a new TabContents with the same state as this one. The returned
286 // heap-allocated pointer is owned by the caller.
287 virtual TabContents* Clone();
288
289 // Shows the page info.
290 void ShowPageInfo(const GURL& url,
291 const NavigationEntry::SSLStatus& ssl,
292 bool show_history);
293
[email protected]0dd3a0ab2011-02-18 08:17:44294 // Window management ---------------------------------------------------------
295
[email protected]9d4984e2011-08-24 19:16:02296 // Adds the given window to the list of child windows. The window will notify
297 // via WillClose() when it is being destroyed.
298 void AddConstrainedDialog(ConstrainedWindow* window);
[email protected]0dd3a0ab2011-02-18 08:17:44299
[email protected]473174942011-04-19 22:52:35300 // Adds a new tab or window with the given already-created contents.
[email protected]e7cfdbd2011-04-22 14:41:37301 void AddNewContents(TabContents* new_contents,
302 WindowOpenDisposition disposition,
303 const gfx::Rect& initial_pos,
304 bool user_gesture);
[email protected]0dd3a0ab2011-02-18 08:17:44305
306 // Returns the number of constrained windows in this tab. Used by tests.
307 size_t constrained_window_count() { return child_windows_.size(); }
308
309 typedef std::deque<ConstrainedWindow*> ConstrainedWindowList;
310
311 // Return an iterator for the first constrained window in this tab contents.
312 ConstrainedWindowList::iterator constrained_window_begin()
313 { return child_windows_.begin(); }
314
315 // Return an iterator for the last constrained window in this tab contents.
316 ConstrainedWindowList::iterator constrained_window_end()
317 { return child_windows_.end(); }
318
319 // Views and focus -----------------------------------------------------------
320 // TODO(brettw): Most of these should be removed and the caller should call
321 // the view directly.
322
323 // Returns the actual window that is focused when this TabContents is shown.
324 gfx::NativeView GetContentNativeView() const;
325
326 // Returns the NativeView associated with this TabContents. Outside of
327 // automation in the context of the UI, this is required to be implemented.
328 gfx::NativeView GetNativeView() const;
329
330 // Returns the bounds of this TabContents in the screen coordinate system.
331 void GetContainerBounds(gfx::Rect *out) const;
332
333 // Makes the tab the focused window.
334 void Focus();
335
336 // Focuses the first (last if |reverse| is true) element in the page.
337 // Invoked when this tab is getting the focus through tab traversal (|reverse|
338 // is true when using Shift-Tab).
339 void FocusThroughTabTraversal(bool reverse);
340
341 // These next two functions are declared on RenderViewHostManager::Delegate
342 // but also accessed directly by other callers.
343
344 // Returns true if the location bar should be focused by default rather than
345 // the page contents. The view calls this function when the tab is focused
346 // to see what it should do.
347 virtual bool FocusLocationBarByDefault();
348
349 // Focuses the location bar.
350 virtual void SetFocusToLocationBar(bool select_all);
351
352 // Creates a view and sets the size for the specified RVH.
353 virtual void CreateViewAndSetSizeForRVH(RenderViewHost* rvh);
354
[email protected]0dd3a0ab2011-02-18 08:17:44355 // Toolbars and such ---------------------------------------------------------
356
[email protected]686493142011-07-15 21:47:22357 // Notifies the delegate that a download is about to be started.
358 // This notification is fired before a local temporary file has been created.
359 bool CanDownload(int request_id);
360
361 // Notifies the delegate that a download started.
362 void OnStartDownload(DownloadItem* download);
363
[email protected]0dd3a0ab2011-02-18 08:17:44364 // Called when a ConstrainedWindow we own is about to be closed.
365 void WillClose(ConstrainedWindow* window);
366
[email protected]0dd3a0ab2011-02-18 08:17:44367 // Interstitials -------------------------------------------------------------
368
369 // Various other systems need to know about our interstitials.
370 bool showing_interstitial_page() const {
371 return render_manager_.interstitial_page() != NULL;
372 }
373
374 // Sets the passed passed interstitial as the currently showing interstitial.
375 // |interstitial_page| should be non NULL (use the remove_interstitial_page
376 // method to unset the interstitial) and no interstitial page should be set
377 // when there is already a non NULL interstitial page set.
378 void set_interstitial_page(InterstitialPage* interstitial_page) {
379 render_manager_.set_interstitial_page(interstitial_page);
380 }
381
382 // Unsets the currently showing interstitial.
383 void remove_interstitial_page() {
384 render_manager_.remove_interstitial_page();
385 }
386
387 // Returns the currently showing interstitial, NULL if no interstitial is
388 // showing.
389 InterstitialPage* interstitial_page() const {
390 return render_manager_.interstitial_page();
391 }
392
393 // Misc state & callbacks ----------------------------------------------------
394
[email protected]c7dd2f62011-07-18 15:57:59395 // Prepare for saving the current web page to disk.
396 void OnSavePage();
397
398 // Save page with the main HTML file path, the directory for saving resources,
399 // and the save type: HTML only or complete web page. Returns true if the
400 // saving process has been initiated successfully.
401 bool SavePage(const FilePath& main_file, const FilePath& dir_path,
402 SavePackage::SavePackageType save_type);
403
404 // Prepare for saving the URL to disk.
405 // URL may refer to the iframe on the page.
406 void OnSaveURL(const GURL& url);
407
[email protected]0dd3a0ab2011-02-18 08:17:44408 // Returns true if the active NavigationEntry's page_id equals page_id.
409 bool IsActiveEntry(int32 page_id);
410
411 const std::string& contents_mime_type() const {
412 return contents_mime_type_;
413 }
414
415 // Returns true if this TabContents will notify about disconnection.
416 bool notify_disconnection() const { return notify_disconnection_; }
417
418 // Override the encoding and reload the page by sending down
419 // ViewMsg_SetPageEncoding to the renderer. |UpdateEncoding| is kinda
420 // the opposite of this, by which 'browser' is notified of
421 // the encoding of the current tab from 'renderer' (determined by
422 // auto-detect, http header, meta, bom detection, etc).
423 void SetOverrideEncoding(const std::string& encoding);
424
425 // Remove any user-defined override encoding and reload by sending down
426 // ViewMsg_ResetPageEncodingToDefault to the renderer.
427 void ResetOverrideEncoding();
428
[email protected]0dd3a0ab2011-02-18 08:17:44429 RendererPreferences* GetMutableRendererPrefs() {
430 return &renderer_preferences_;
431 }
432
[email protected]1fd1a502011-03-30 16:55:56433 void set_opener_web_ui_type(WebUI::TypeID opener_web_ui_type) {
[email protected]0dd3a0ab2011-02-18 08:17:44434 opener_web_ui_type_ = opener_web_ui_type;
435 }
436
[email protected]0dd3a0ab2011-02-18 08:17:44437 // Set the time when we started to create the new tab page. This time is
438 // from before we created this TabContents.
439 void set_new_tab_start_time(const base::TimeTicks& time) {
440 new_tab_start_time_ = time;
441 }
[email protected]763ec4ca2011-04-29 15:48:12442 base::TimeTicks new_tab_start_time() const { return new_tab_start_time_; }
[email protected]0dd3a0ab2011-02-18 08:17:44443
444 // Notification that tab closing has started. This can be called multiple
445 // times, subsequent calls are ignored.
446 void OnCloseStarted();
447
[email protected]0dd3a0ab2011-02-18 08:17:44448 // Returns true if underlying TabContentsView should accept drag-n-drop.
449 bool ShouldAcceptDragAndDrop() const;
450
451 // A render view-originated drag has ended. Informs the render view host and
452 // tab contents delegate.
453 void SystemDragEnded();
454
455 // Indicates if this tab was explicitly closed by the user (control-w, close
456 // tab menu item...). This is false for actions that indirectly close the tab,
457 // such as closing the window. The setter is maintained by TabStripModel, and
458 // the getter only useful from within TAB_CLOSED notification
459 void set_closed_by_user_gesture(bool value) {
460 closed_by_user_gesture_ = value;
461 }
462 bool closed_by_user_gesture() const { return closed_by_user_gesture_; }
463
[email protected]3ab9cb82011-06-03 18:02:07464 // Overridden from JavaScriptDialogDelegate:
465 virtual void OnDialogClosed(IPC::Message* reply_msg,
466 bool success,
467 const string16& user_input) OVERRIDE;
468 virtual gfx::NativeWindow GetDialogRootWindow() OVERRIDE;
[email protected]a1e97f02011-06-30 14:04:34469 virtual void OnDialogShown() OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44470
[email protected]0dd3a0ab2011-02-18 08:17:44471 // Gets the zoom level for this tab.
472 double GetZoomLevel() const;
473
474 // Gets the zoom percent for this tab.
475 int GetZoomPercent(bool* enable_increment, bool* enable_decrement);
476
[email protected]0dd3a0ab2011-02-18 08:17:44477 // Opens view-source tab for this contents.
478 void ViewSource();
479
[email protected]932b7a12011-03-09 12:50:27480 void ViewFrameSource(const GURL& url,
481 const std::string& content_state);
482
[email protected]0dd3a0ab2011-02-18 08:17:44483 // Gets the minimum/maximum zoom percent.
484 int minimum_zoom_percent() const { return minimum_zoom_percent_; }
485 int maximum_zoom_percent() const { return maximum_zoom_percent_; }
486
487 int content_restrictions() const { return content_restrictions_; }
[email protected]c40d6232011-03-25 00:16:21488 void SetContentRestrictions(int restrictions);
[email protected]0dd3a0ab2011-02-18 08:17:44489
[email protected]1fd1a502011-03-30 16:55:56490 // Query the WebUIFactory for the TypeID for the current URL.
491 WebUI::TypeID GetWebUITypeForCurrentState();
492
[email protected]b375c5d2011-05-03 21:15:04493 // Returns the WebUI for the current state of the tab. This will either be
494 // the pending WebUI, the committed WebUI, or NULL.
495 WebUI* GetWebUIForCurrentState();
496
[email protected]0dd3a0ab2011-02-18 08:17:44497 protected:
[email protected]553602e12011-04-05 17:01:18498 friend class TabContentsObserver;
[email protected]553602e12011-04-05 17:01:18499
500 // Add and remove observers for page navigation notifications. Adding or
501 // removing multiple times has no effect. The order in which notifications
502 // are sent to observers is undefined. Clients must be sure to remove the
503 // observer before they go away.
504 void AddObserver(TabContentsObserver* observer);
505 void RemoveObserver(TabContentsObserver* observer);
506
[email protected]0dd3a0ab2011-02-18 08:17:44507 private:
508 friend class NavigationController;
509 // Used to access the child_windows_ (ConstrainedWindowList) for testing
510 // automation purposes.
511 friend class TestingAutomationProvider;
512
513 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, NoJSMessageOnInterstitials);
514 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, UpdateTitle);
515 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, CrossSiteCantPreemptAfterUnload);
[email protected]aed59602011-02-28 22:57:33516 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, ConstrainedWindows);
[email protected]0dd3a0ab2011-02-18 08:17:44517 FRIEND_TEST_ALL_PREFIXES(FormStructureBrowserTest, HTMLFiles);
518 FRIEND_TEST_ALL_PREFIXES(NavigationControllerTest, HistoryNavigate);
519 FRIEND_TEST_ALL_PREFIXES(RenderViewHostManagerTest, PageDoesBackAndReload);
520
521 // Temporary until the view/contents separation is complete.
522 friend class TabContentsView;
[email protected]9a56a0d2011-05-13 19:03:31523#if defined(TOOLKIT_VIEWS)
[email protected]7e2cef52011-04-11 21:47:23524 friend class TabContentsViewViews;
[email protected]0dd3a0ab2011-02-18 08:17:44525#elif defined(OS_MACOSX)
526 friend class TabContentsViewMac;
527#elif defined(TOOLKIT_USES_GTK)
528 friend class TabContentsViewGtk;
529#endif
530
531 // So InterstitialPage can access SetIsLoading.
532 friend class InterstitialPage;
533
534 // TODO(brettw) TestTabContents shouldn't exist!
535 friend class TestTabContents;
536
[email protected]0dd3a0ab2011-02-18 08:17:44537 // Message handlers.
538 void OnDidStartProvisionalLoadForFrame(int64 frame_id,
539 bool main_frame,
[email protected]eacb080b2011-05-22 19:40:26540 bool has_opener_set,
[email protected]0dd3a0ab2011-02-18 08:17:44541 const GURL& url);
542 void OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]eacb080b2011-05-22 19:40:26543 bool has_opener_set,
[email protected]0dd3a0ab2011-02-18 08:17:44544 const GURL& source_url,
545 const GURL& target_url);
546 void OnDidFailProvisionalLoadWithError(int64 frame_id,
547 bool main_frame,
548 int error_code,
549 const GURL& url,
550 bool showing_repost_interstitial);
551 void OnDidLoadResourceFromMemoryCache(const GURL& url,
[email protected]70435962011-08-02 20:13:28552 const std::string& security_info,
553 const std::string& http_request,
554 ResourceType::Type resource_type);
[email protected]0dd3a0ab2011-02-18 08:17:44555 void OnDidDisplayInsecureContent();
556 void OnDidRunInsecureContent(const std::string& security_origin,
557 const GURL& target_url);
558 void OnDocumentLoadedInFrame(int64 frame_id);
559 void OnDidFinishLoad(int64 frame_id);
560 void OnUpdateContentRestrictions(int restrictions);
[email protected]0dd3a0ab2011-02-18 08:17:44561 void OnGoToEntryAtOffset(int offset);
[email protected]216813952011-05-19 22:21:26562 void OnUpdateZoomLimits(int minimum_percent,
563 int maximum_percent,
564 bool remember);
565 void OnFocusedNodeChanged(bool is_editable_node);
[email protected]3a29a6e2011-08-24 18:26:21566 void OnEnumerateDirectory(int request_id, const FilePath& path);
[email protected]7d189022011-08-25 22:54:20567 void OnJSOutOfMemory();
568 void OnRegisterProtocolHandler(const std::string& protocol,
569 const GURL& url,
570 const string16& title);
571 void OnRegisterIntentHandler(const string16& action,
572 const string16& type,
573 const string16& href,
574 const string16& title);
575 void OnWebIntentDispatch(const IPC::Message& message,
576 const string16& action,
577 const string16& type,
578 const string16& data,
579 int intent_id);
[email protected]b888919c2011-09-02 00:32:16580 void OnFindReply(int request_id, int number_of_matches,
581 const gfx::Rect& selection_rect, int active_match_ordinal,
582 bool final_update);
[email protected]d952a052011-09-06 18:42:45583 void OnCrashedPlugin(const FilePath& plugin_path);
[email protected]7fc4bbb2011-09-08 21:23:10584 void OnAppCacheAccessed(const GURL& manifest_url, bool blocked_by_policy);
[email protected]0dd3a0ab2011-02-18 08:17:44585
586 // Changes the IsLoading state and notifies delegate as needed
587 // |details| is used to provide details on the load that just finished
588 // (but can be null if not applicable). Can be overridden.
589 void SetIsLoading(bool is_loading,
590 LoadNotificationDetails* details);
591
[email protected]0dd3a0ab2011-02-18 08:17:44592 // Called by derived classes to indicate that we're no longer waiting for a
593 // response. This won't actually update the throbber, but it will get picked
594 // up at the next animation step if the throbber is going.
595 void SetNotWaitingForResponse() { waiting_for_response_ = false; }
596
597 ConstrainedWindowList child_windows_;
598
[email protected]0dd3a0ab2011-02-18 08:17:44599 // Navigation helpers --------------------------------------------------------
600 //
601 // These functions are helpers for Navigate() and DidNavigate().
602
603 // Handles post-navigation tasks in DidNavigate AFTER the entry has been
604 // committed to the navigation controller. Note that the navigation entry is
605 // not provided since it may be invalid/changed after being committed. The
606 // current navigation entry is in the NavigationController at this point.
607 void DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:13608 const content::LoadCommittedDetails& details,
[email protected]0dd3a0ab2011-02-18 08:17:44609 const ViewHostMsg_FrameNavigate_Params& params);
610 void DidNavigateAnyFramePostCommit(
611 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:13612 const content::LoadCommittedDetails& details,
[email protected]0dd3a0ab2011-02-18 08:17:44613 const ViewHostMsg_FrameNavigate_Params& params);
614
615 // Closes all constrained windows.
616 void CloseConstrainedWindows();
617
[email protected]0dd3a0ab2011-02-18 08:17:44618 // If our controller was restored and the page id is > than the site
619 // instance's page id, the site instances page id is updated as well as the
620 // renderers max page id.
621 void UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
622 RenderViewHost* rvh);
623
[email protected]0dd3a0ab2011-02-18 08:17:44624 // Saves the given title to the navigation entry and does associated work. It
625 // will update history and the view for the new title, and also synthesize
626 // titles for file URLs that have none (so we require that the URL of the
627 // entry already be set).
628 //
629 // This is used as the backend for state updates, which include a new title,
630 // or the dedicated set title message. It returns true if the new title is
631 // different and was therefore updated.
[email protected]acafd272011-07-26 17:35:57632 bool UpdateTitleForEntry(NavigationEntry* entry, const string16& title);
[email protected]0dd3a0ab2011-02-18 08:17:44633
634 // Causes the TabContents to navigate in the right renderer to |entry|, which
635 // must be already part of the entries in the navigation controller.
636 // This does not change the NavigationController state.
637 bool NavigateToEntry(const NavigationEntry& entry,
638 NavigationController::ReloadType reload_type);
639
[email protected]796931a92011-08-10 01:32:14640 // Sets the history for this tab_contents to |history_length| entries, and
641 // moves the current page_id to the last entry in the list if it's valid.
642 // This is mainly used when a prerendered page is swapped into the current
[email protected]9e1ad4b2011-08-14 16:49:19643 // tab. The method is virtual for testing.
644 virtual void SetHistoryLengthAndPrune(const SiteInstance* site_instance,
645 int merge_history_length,
646 int32 minimum_page_id);
[email protected]796931a92011-08-10 01:32:14647
[email protected]0dd3a0ab2011-02-18 08:17:44648 // Misc non-view stuff -------------------------------------------------------
649
650 // Helper functions for sending notifications.
651 void NotifySwapped();
652 void NotifyConnected();
653 void NotifyDisconnected();
654
[email protected]0dd3a0ab2011-02-18 08:17:44655 // RenderViewHostDelegate ----------------------------------------------------
656
657 // RenderViewHostDelegate implementation.
[email protected]544e27f2011-07-25 21:41:54658 virtual RenderViewHostDelegate::View* GetViewDelegate() OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44659 virtual RenderViewHostDelegate::RendererManagement*
[email protected]544e27f2011-07-25 21:41:54660 GetRendererManagementDelegate() OVERRIDE;
661 virtual TabContents* GetAsTabContents() OVERRIDE;
662 virtual ViewType::Type GetRenderViewType() const OVERRIDE;
663 virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE;
664 virtual void RenderViewReady(RenderViewHost* render_view_host) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44665 virtual void RenderViewGone(RenderViewHost* render_view_host,
666 base::TerminationStatus status,
[email protected]544e27f2011-07-25 21:41:54667 int error_code) OVERRIDE;
668 virtual void RenderViewDeleted(RenderViewHost* render_view_host) OVERRIDE;
669 virtual void DidNavigate(
670 RenderViewHost* render_view_host,
671 const ViewHostMsg_FrameNavigate_Params& params) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44672 virtual void UpdateState(RenderViewHost* render_view_host,
673 int32 page_id,
[email protected]544e27f2011-07-25 21:41:54674 const std::string& state) OVERRIDE;
[email protected]6b2f7a82011-04-25 19:30:51675 virtual void UpdateTitle(RenderViewHost* render_view_host,
676 int32 page_id,
[email protected]a49e10b2011-08-01 23:57:46677 const string16& title,
678 base::i18n::TextDirection title_direction) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44679 virtual void UpdateEncoding(RenderViewHost* render_view_host,
[email protected]544e27f2011-07-25 21:41:54680 const std::string& encoding) OVERRIDE;
681 virtual void UpdateTargetURL(int32 page_id, const GURL& url) OVERRIDE;
682 virtual void Close(RenderViewHost* render_view_host) OVERRIDE;
683 virtual void RequestMove(const gfx::Rect& new_bounds) OVERRIDE;
684 virtual void DidStartLoading() OVERRIDE;
685 virtual void DidStopLoading() OVERRIDE;
686 virtual void DidCancelLoading() OVERRIDE;
687 virtual void DidChangeLoadProgress(double progress) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44688 virtual void DocumentOnLoadCompletedInMainFrame(
689 RenderViewHost* render_view_host,
[email protected]544e27f2011-07-25 21:41:54690 int32 page_id) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44691 virtual void RequestOpenURL(const GURL& url, const GURL& referrer,
[email protected]544e27f2011-07-25 21:41:54692 WindowOpenDisposition disposition) OVERRIDE;
[email protected]992db4c2011-05-12 15:37:15693 virtual void RunJavaScriptMessage(const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:41694 const string16& message,
695 const string16& default_prompt,
[email protected]0dd3a0ab2011-02-18 08:17:44696 const GURL& frame_url,
697 const int flags,
698 IPC::Message* reply_msg,
[email protected]3ab9cb82011-06-03 18:02:07699 bool* did_suppress_message) OVERRIDE;
[email protected]992db4c2011-05-12 15:37:15700 virtual void RunBeforeUnloadConfirm(const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:41701 const string16& message,
[email protected]544e27f2011-07-25 21:41:54702 IPC::Message* reply_msg) OVERRIDE;
[email protected]3d7474ff2011-07-27 17:47:37703 virtual RendererPreferences GetRendererPrefs(
704 content::BrowserContext* browser_context) const OVERRIDE;
[email protected]544e27f2011-07-25 21:41:54705 virtual WebPreferences GetWebkitPrefs() OVERRIDE;
706 virtual void OnUserGesture() OVERRIDE;
707 virtual void OnIgnoredUIEvent() OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44708 virtual void RendererUnresponsive(RenderViewHost* render_view_host,
[email protected]544e27f2011-07-25 21:41:54709 bool is_during_unload) OVERRIDE;
710 virtual void RendererResponsive(RenderViewHost* render_view_host) OVERRIDE;
711 virtual void LoadStateChanged(const GURL& url,
[email protected]9c235f042011-08-10 22:28:21712 const net::LoadStateWithParam& load_state,
[email protected]544e27f2011-07-25 21:41:54713 uint64 upload_position,
714 uint64 upload_size) OVERRIDE;
715 virtual void WorkerCrashed() OVERRIDE;
716 virtual void Activate() OVERRIDE;
717 virtual void Deactivate() OVERRIDE;
718 virtual void LostCapture() OVERRIDE;
[email protected]63954792011-07-11 04:17:48719 virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
[email protected]544e27f2011-07-25 21:41:54720 bool* is_keyboard_shortcut) OVERRIDE;
721 virtual void HandleKeyboardEvent(
722 const NativeWebKeyboardEvent& event) OVERRIDE;
723 virtual void HandleMouseUp() OVERRIDE;
724 virtual void HandleMouseActivate() OVERRIDE;
[email protected]6c2e472f2011-08-24 23:26:18725 virtual bool OnMessageReceived(const IPC::Message& message);
726 virtual void RunFileChooser(RenderViewHost* render_view_host,
727 const ViewHostMsg_RunFileChooser_Params& params);
[email protected]8a5e0ca2011-08-25 06:30:47728 virtual void ToggleFullscreenMode(bool enter_fullscreen) OVERRIDE;
[email protected]0548c5352011-09-07 00:33:33729 virtual void UpdatePreferredSize(const gfx::Size& pref_size) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44730
731 // RenderViewHostManager::Delegate -------------------------------------------
732
733 // Blocks/unblocks interaction with renderer process.
734 void BlockTabContent(bool blocked);
735
736 virtual void BeforeUnloadFiredFromRenderManager(
737 bool proceed,
738 bool* proceed_to_fire_unload);
739 virtual void DidStartLoadingFromRenderManager(
740 RenderViewHost* render_view_host);
741 virtual void RenderViewGoneFromRenderManager(
742 RenderViewHost* render_view_host);
743 virtual void UpdateRenderViewSizeForRenderManager();
744 virtual void NotifySwappedFromRenderManager();
745 virtual NavigationController& GetControllerForRenderManager();
746 virtual WebUI* CreateWebUIForRenderManager(const GURL& url);
747 virtual NavigationEntry* GetLastCommittedNavigationEntryForRenderManager();
748
749 // Initializes the given renderer if necessary and creates the view ID
750 // corresponding to this view host. If this method is not called and the
751 // process is not shared, then the TabContents will act as though the renderer
752 // is not running (i.e., it will render "sad tab"). This method is
753 // automatically called from LoadURL.
754 //
755 // If you are attaching to an already-existing RenderView, you should call
756 // InitWithExistingID.
757 virtual bool CreateRenderViewForRenderManager(
758 RenderViewHost* render_view_host);
759
[email protected]81898992011-06-14 22:15:00760 // Stores random bits of data for others to associate with this object.
761 // WARNING: this needs to be deleted after NavigationController.
762 PropertyBag property_bag_;
763
[email protected]0dd3a0ab2011-02-18 08:17:44764 // Data for core operation ---------------------------------------------------
765
766 // Delegate for notifying our owner about stuff. Not owned by us.
767 TabContentsDelegate* delegate_;
768
769 // Handles the back/forward list and loading.
770 NavigationController controller_;
771
772 // The corresponding view.
773 scoped_ptr<TabContentsView> view_;
774
775 // Helper classes ------------------------------------------------------------
776
777 // Manages creation and swapping of render views.
778 RenderViewHostManager render_manager_;
779
[email protected]c7dd2f62011-07-18 15:57:59780 // SavePackage, lazily created.
781 scoped_refptr<SavePackage> save_package_;
782
[email protected]0dd3a0ab2011-02-18 08:17:44783 // Data for loading state ----------------------------------------------------
784
785 // Indicates whether we're currently loading a resource.
786 bool is_loading_;
787
788 // Indicates if the tab is considered crashed.
789 base::TerminationStatus crashed_status_;
790 int crashed_error_code_;
791
792 // See waiting_for_response() above.
793 bool waiting_for_response_;
794
795 // Indicates the largest PageID we've seen. This field is ignored if we are
796 // a TabContents, in which case the max page ID is stored separately with
797 // each SiteInstance.
798 // TODO(brettw) this seems like it can be removed according to the comment.
799 int32 max_page_id_;
800
801 // System time at which the current load was started.
802 base::TimeTicks current_load_start_;
803
804 // The current load state and the URL associated with it.
[email protected]9c235f042011-08-10 22:28:21805 net::LoadStateWithParam load_state_;
[email protected]0dd3a0ab2011-02-18 08:17:44806 string16 load_state_host_;
807 // Upload progress, for displaying in the status bar.
808 // Set to zero when there is no significant upload happening.
809 uint64 upload_size_;
810 uint64 upload_position_;
811
812 // Data for current page -----------------------------------------------------
813
[email protected]987fc3a2011-05-26 14:18:09814 // When a title cannot be taken from any entry, this title will be used.
815 string16 page_title_when_no_navigation_entry_;
816
[email protected]0dd3a0ab2011-02-18 08:17:44817 // When a navigation occurs, we record its contents MIME type. It can be
818 // used to check whether we can do something for some special contents.
819 std::string contents_mime_type_;
820
821 // Character encoding.
822 std::string encoding_;
823
[email protected]0dd3a0ab2011-02-18 08:17:44824 // True if this is a secure page which displayed insecure content.
825 bool displayed_insecure_content_;
826
[email protected]0dd3a0ab2011-02-18 08:17:44827 // Data for misc internal state ----------------------------------------------
828
829 // See capturing_contents() above.
830 bool capturing_contents_;
831
832 // See getter above.
833 bool is_being_destroyed_;
834
835 // Indicates whether we should notify about disconnection of this
836 // TabContents. This is used to ensure disconnection notifications only
837 // happen if a connection notification has happened and that they happen only
838 // once.
839 bool notify_disconnection_;
840
[email protected]2e5b90c2011-08-16 21:11:55841 // Pointer to the JavaScript dialog creator, lazily assigned. Used because the
842 // delegate of this TabContents is nulled before its destructor is called.
843 content::JavaScriptDialogCreator* dialog_creator_;
844
[email protected]0dd3a0ab2011-02-18 08:17:44845#if defined(OS_WIN)
846 // Handle to an event that's set when the page is showing a message box (or
847 // equivalent constrained window). Plugin processes check this to know if
848 // they should pump messages then.
849 base::win::ScopedHandle message_box_active_;
850#endif
851
[email protected]0dd3a0ab2011-02-18 08:17:44852 // Set to true when there is an active "before unload" dialog. When true,
853 // we've forced the throbber to start in Navigate, and we need to remember to
854 // turn it off in OnJavaScriptMessageBoxClosed if the navigation is canceled.
855 bool is_showing_before_unload_dialog_;
856
[email protected]0dd3a0ab2011-02-18 08:17:44857 // Settings that get passed to the renderer process.
858 RendererPreferences renderer_preferences_;
859
860 // If this tab was created from a renderer using window.open, this will be
861 // non-NULL and represent the WebUI of the opening renderer.
[email protected]1fd1a502011-03-30 16:55:56862 WebUI::TypeID opener_web_ui_type_;
[email protected]0dd3a0ab2011-02-18 08:17:44863
864 // The time that we started to create the new tab page.
865 base::TimeTicks new_tab_start_time_;
866
867 // The time that we started to close the tab.
868 base::TimeTicks tab_close_start_time_;
869
870 // The time that this tab was last selected.
871 base::TimeTicks last_selected_time_;
872
[email protected]0dd3a0ab2011-02-18 08:17:44873 // See description above setter.
874 bool closed_by_user_gesture_;
875
876 // Minimum/maximum zoom percent.
877 int minimum_zoom_percent_;
878 int maximum_zoom_percent_;
879 // If true, the default zoom limits have been overriden for this tab, in which
880 // case we don't want saved settings to apply to it and we don't want to
881 // remember it.
882 bool temporary_zoom_settings_;
883
884 // A list of observers notified when page state changes. Weak references.
885 ObserverList<TabContentsObserver> observers_;
886
887 // Content restrictions, used to disable print/copy etc based on content's
888 // (full-page plugins for now only) permissions.
889 int content_restrictions_;
890
[email protected]0dd3a0ab2011-02-18 08:17:44891 DISALLOW_COPY_AND_ASSIGN(TabContents);
892};
893
894#endif // CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_H_