blob: 78a69528ad57ee66630e67f22270c666f83c1e1a [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]45644f62011-11-23 00:58:2317#include "base/property_bag.h"
[email protected]0dd3a0ab2011-02-18 08:17:4418#include "base/string16.h"
[email protected]c7dd2f62011-07-18 15:57:5919#include "content/browser/download/save_package.h"
[email protected]3ab9cb82011-06-03 18:02:0720#include "content/browser/javascript_dialogs.h"
[email protected]07161902011-11-11 09:57:4221#include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager.h"
[email protected]5de634712011-03-02 00:20:1922#include "content/browser/renderer_host/render_view_host_delegate.h"
[email protected]0dd3a0ab2011-02-18 08:17:4423#include "content/browser/tab_contents/navigation_controller.h"
24#include "content/browser/tab_contents/navigation_entry.h"
25#include "content/browser/tab_contents/page_navigator.h"
26#include "content/browser/tab_contents/render_view_host_manager.h"
[email protected]553602e12011-04-05 17:01:1827#include "content/browser/tab_contents/tab_contents_observer.h"
[email protected]1fd1a502011-03-30 16:55:5628#include "content/browser/webui/web_ui.h"
[email protected]8d128d62011-09-13 22:11:5729#include "content/common/content_export.h"
[email protected]daf82f82011-10-31 22:35:3130#include "content/public/common/renderer_preferences.h"
[email protected]0dd3a0ab2011-02-18 08:17:4431#include "net/base/load_states.h"
32#include "ui/gfx/native_widget_types.h"
[email protected]70435962011-08-02 20:13:2833#include "webkit/glue/resource_type.h"
[email protected]0dd3a0ab2011-02-18 08:17:4434
35#if defined(OS_WIN)
36#include "base/win/scoped_handle.h"
37#endif
38
[email protected]686493142011-07-15 21:47:2239class DownloadItem;
[email protected]0dd3a0ab2011-02-18 08:17:4440class LoadNotificationDetails;
[email protected]0dd3a0ab2011-02-18 08:17:4441class RenderViewHost;
42class SessionStorageNamespace;
43class SiteInstance;
[email protected]0dd3a0ab2011-02-18 08:17:4444class TabContentsDelegate;
45class TabContentsObserver;
[email protected]0dd3a0ab2011-02-18 08:17:4446class TabContentsView;
[email protected]d7b175e2011-10-11 15:31:5847struct ViewHostMsg_DidFailProvisionalLoadWithError_Params;
[email protected]daf82f82011-10-31 22:35:3148
49namespace webkit_glue {
50struct WebIntentData;
51}
[email protected]0dd3a0ab2011-02-18 08:17:4452
53// Describes what goes in the main content area of a tab. TabContents is
54// the only type of TabContents, and these should be merged together.
[email protected]8d128d62011-09-13 22:11:5755class CONTENT_EXPORT TabContents : public PageNavigator,
56 public RenderViewHostDelegate,
57 public RenderViewHostManager::Delegate,
58 public content::JavaScriptDialogDelegate {
[email protected]0dd3a0ab2011-02-18 08:17:4459 public:
60 // Flags passed to the TabContentsDelegate.NavigationStateChanged to tell it
61 // what has changed. Combine them to update more than one thing.
62 enum InvalidateTypes {
63 INVALIDATE_URL = 1 << 0, // The URL has changed.
64 INVALIDATE_TAB = 1 << 1, // The favicon, app icon, or crashed
65 // state changed.
66 INVALIDATE_LOAD = 1 << 2, // The loading state has changed.
67 INVALIDATE_PAGE_ACTIONS = 1 << 3, // Page action icons have changed.
[email protected]93f230e02011-06-01 14:40:0068 INVALIDATE_TITLE = 1 << 4, // The title changed.
[email protected]0dd3a0ab2011-02-18 08:17:4469 };
70
71 // |base_tab_contents| is used if we want to size the new tab contents view
72 // based on an existing tab contents view. This can be NULL if not needed.
73 //
74 // The session storage namespace parameter allows multiple render views and
75 // tab contentses to share the same session storage (part of the WebStorage
76 // spec) space. This is useful when restoring tabs, but most callers should
77 // pass in NULL which will cause a new SessionStorageNamespace to be created.
[email protected]3d7474ff2011-07-27 17:47:3778 TabContents(content::BrowserContext* browser_context,
[email protected]0dd3a0ab2011-02-18 08:17:4479 SiteInstance* site_instance,
80 int routing_id,
81 const TabContents* base_tab_contents,
82 SessionStorageNamespace* session_storage_namespace);
83 virtual ~TabContents();
84
85 // Intrinsic tab state -------------------------------------------------------
86
87 // Returns the property bag for this tab contents, where callers can add
88 // extra data they may wish to associate with the tab. Returns a pointer
89 // rather than a reference since the PropertyAccessors expect this.
[email protected]45644f62011-11-23 00:58:2390 const base::PropertyBag* property_bag() const { return &property_bag_; }
91 base::PropertyBag* property_bag() { return &property_bag_; }
[email protected]0dd3a0ab2011-02-18 08:17:4492
93 TabContentsDelegate* delegate() const { return delegate_; }
[email protected]1de2b8b2011-06-29 19:38:4694 void set_delegate(TabContentsDelegate* delegate);
[email protected]0dd3a0ab2011-02-18 08:17:4495
96 // Gets the controller for this tab contents.
97 NavigationController& controller() { return controller_; }
98 const NavigationController& controller() const { return controller_; }
99
[email protected]3d7474ff2011-07-27 17:47:37100 // Returns the user browser context associated with this TabContents (via the
[email protected]0dd3a0ab2011-02-18 08:17:44101 // NavigationController).
[email protected]3d7474ff2011-07-27 17:47:37102 content::BrowserContext* browser_context() const {
103 return controller_.browser_context();
104 }
105
[email protected]32ded2212011-11-10 18:51:43106 // Allows overriding the type of this tab.
107 void set_view_type(content::ViewType type) { view_type_ = type; }
108
[email protected]c7dd2f62011-07-18 15:57:59109 // Returns the SavePackage which manages the page saving job. May be NULL.
110 SavePackage* save_package() const { return save_package_.get(); }
111
[email protected]0dd3a0ab2011-02-18 08:17:44112 // Return the currently active RenderProcessHost and RenderViewHost. Each of
113 // these may change over time.
[email protected]f3b1a082011-11-18 00:34:30114 content::RenderProcessHost* GetRenderProcessHost() const;
[email protected]0dd3a0ab2011-02-18 08:17:44115 RenderViewHost* render_view_host() const {
116 return render_manager_.current_host();
117 }
118
[email protected]93f230e02011-06-01 14:40:00119 WebUI* committed_web_ui() const {
120 return render_manager_.web_ui();
121 }
122
[email protected]6e5a00a2011-10-13 17:47:16123 // Returns the committed WebUI if one exists, otherwise the pending one.
124 // Callers who want to use the pending WebUI for the pending navigation entry
125 // should use GetWebUIForCurrentState instead.
[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).
[email protected]edc64de2011-11-17 20:07:38147 virtual const GURL& GetURL() const OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44148 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]755d174b2011-11-07 23:33:30168 // Return whether this tab contents is loading a resource.
169 bool IsLoading() const { return is_loading_; }
[email protected]0dd3a0ab2011-02-18 08:17:44170
171 // Returns whether this tab contents is waiting for a first-response for the
172 // main resource of the page. This controls whether the throbber state is
173 // "waiting" or "loading."
174 bool waiting_for_response() const { return waiting_for_response_; }
175
[email protected]9c235f042011-08-10 22:28:21176 const net::LoadStateWithParam& load_state() const { return load_state_; }
177 const string16& load_state_host() const { return load_state_host_; }
[email protected]0dd3a0ab2011-02-18 08:17:44178 uint64 upload_size() const { return upload_size_; }
179 uint64 upload_position() const { return upload_position_; }
180
181 const std::string& encoding() const { return encoding_; }
182 void set_encoding(const std::string& encoding);
183 void reset_encoding() {
184 encoding_.clear();
185 }
186
[email protected]0dd3a0ab2011-02-18 08:17:44187 bool displayed_insecure_content() const {
188 return displayed_insecure_content_;
189 }
190
191 // Internal state ------------------------------------------------------------
192
193 // This flag indicates whether the tab contents is currently being
194 // screenshotted by the DraggedTabController.
195 bool capturing_contents() const { return capturing_contents_; }
196 void set_capturing_contents(bool cap) { capturing_contents_ = cap; }
197
198 // Indicates whether this tab should be considered crashed. The setter will
199 // also notify the delegate when the flag is changed.
200 bool is_crashed() const {
201 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
202 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
203 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
204 }
205 base::TerminationStatus crashed_status() const { return crashed_status_; }
206 int crashed_error_code() const { return crashed_error_code_; }
207 void SetIsCrashed(base::TerminationStatus status, int error_code);
208
[email protected]0dd3a0ab2011-02-18 08:17:44209 // Whether the tab is in the process of being destroyed.
210 // Added as a tentative work-around for focus related bug #4633. This allows
211 // us not to store focus when a tab is being closed.
212 bool is_being_destroyed() const { return is_being_destroyed_; }
213
214 // Convenience method for notifying the delegate of a navigation state
215 // change. See TabContentsDelegate.
216 void NotifyNavigationStateChanged(unsigned changed_flags);
217
218 // Invoked when the tab contents becomes selected. If you override, be sure
219 // and invoke super's implementation.
220 virtual void DidBecomeSelected();
221 base::TimeTicks last_selected_time() const {
222 return last_selected_time_;
223 }
224
225 // Invoked when the tab contents becomes hidden.
226 // NOTE: If you override this, call the superclass version too!
227 virtual void WasHidden();
228
[email protected]0dd3a0ab2011-02-18 08:17:44229 // TODO(brettw) document these.
230 virtual void ShowContents();
231 virtual void HideContents();
232
233 // Returns true if the before unload and unload listeners need to be
234 // fired. The value of this changes over time. For example, if true and the
235 // before unload listener is executed and allows the user to exit, then this
236 // returns false.
237 bool NeedToFireBeforeUnload();
238
[email protected]0dd3a0ab2011-02-18 08:17:44239 // Expose the render manager for testing.
[email protected]03ff5e52011-09-30 00:28:14240 RenderViewHostManager* render_manager_for_testing() {
241 return &render_manager_;
242 }
[email protected]0dd3a0ab2011-02-18 08:17:44243
[email protected]0dd3a0ab2011-02-18 08:17:44244 // Commands ------------------------------------------------------------------
245
246 // Implementation of PageNavigator.
[email protected]00c37fc2011-08-02 00:22:50247
248 // Deprecated. Please use the one-argument variant instead.
249 // TODO(adriansc): Remove this method once refactoring changed all call sites.
[email protected]992e4542011-07-20 23:09:25250 virtual TabContents* OpenURL(const GURL& url,
251 const GURL& referrer,
252 WindowOpenDisposition disposition,
[email protected]2905f742011-10-13 03:51:58253 content::PageTransition transition) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44254
[email protected]00c37fc2011-08-02 00:22:50255 virtual TabContents* OpenURL(const OpenURLParams& params) OVERRIDE;
256
[email protected]0dd3a0ab2011-02-18 08:17:44257 // Called by the NavigationController to cause the TabContents to navigate to
258 // the current pending entry. The NavigationController should be called back
[email protected]9a7e68c2011-05-26 17:35:50259 // with RendererDidNavigate on success or DiscardPendingEntry on failure.
260 // The callbacks can be inside of this function, or at some future time.
[email protected]0dd3a0ab2011-02-18 08:17:44261 //
262 // The entry has a PageID of -1 if newly created (corresponding to navigation
263 // to a new URL).
264 //
265 // If this method returns false, then the navigation is discarded (equivalent
266 // to calling DiscardPendingEntry on the NavigationController).
267 virtual bool NavigateToPendingEntry(
268 NavigationController::ReloadType reload_type);
269
270 // Stop any pending navigation.
271 virtual void Stop();
272
[email protected]0dd3a0ab2011-02-18 08:17:44273 // Creates a new TabContents with the same state as this one. The returned
274 // heap-allocated pointer is owned by the caller.
275 virtual TabContents* Clone();
276
277 // Shows the page info.
278 void ShowPageInfo(const GURL& url,
279 const NavigationEntry::SSLStatus& ssl,
280 bool show_history);
281
[email protected]0dd3a0ab2011-02-18 08:17:44282 // Window management ---------------------------------------------------------
283
[email protected]473174942011-04-19 22:52:35284 // Adds a new tab or window with the given already-created contents.
[email protected]e7cfdbd2011-04-22 14:41:37285 void AddNewContents(TabContents* new_contents,
286 WindowOpenDisposition disposition,
287 const gfx::Rect& initial_pos,
288 bool user_gesture);
[email protected]0dd3a0ab2011-02-18 08:17:44289
[email protected]0dd3a0ab2011-02-18 08:17:44290 // Views and focus -----------------------------------------------------------
291 // TODO(brettw): Most of these should be removed and the caller should call
292 // the view directly.
293
294 // Returns the actual window that is focused when this TabContents is shown.
295 gfx::NativeView GetContentNativeView() const;
296
297 // Returns the NativeView associated with this TabContents. Outside of
298 // automation in the context of the UI, this is required to be implemented.
299 gfx::NativeView GetNativeView() const;
300
301 // Returns the bounds of this TabContents in the screen coordinate system.
302 void GetContainerBounds(gfx::Rect *out) const;
303
304 // Makes the tab the focused window.
305 void Focus();
306
307 // Focuses the first (last if |reverse| is true) element in the page.
308 // Invoked when this tab is getting the focus through tab traversal (|reverse|
309 // is true when using Shift-Tab).
310 void FocusThroughTabTraversal(bool reverse);
311
312 // These next two functions are declared on RenderViewHostManager::Delegate
313 // but also accessed directly by other callers.
314
315 // Returns true if the location bar should be focused by default rather than
316 // the page contents. The view calls this function when the tab is focused
317 // to see what it should do.
[email protected]edc64de2011-11-17 20:07:38318 virtual bool FocusLocationBarByDefault() OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44319
320 // Focuses the location bar.
[email protected]edc64de2011-11-17 20:07:38321 virtual void SetFocusToLocationBar(bool select_all) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44322
323 // Creates a view and sets the size for the specified RVH.
[email protected]edc64de2011-11-17 20:07:38324 virtual void CreateViewAndSetSizeForRVH(RenderViewHost* rvh) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44325
[email protected]0dd3a0ab2011-02-18 08:17:44326 // Toolbars and such ---------------------------------------------------------
327
[email protected]686493142011-07-15 21:47:22328 // Notifies the delegate that a download is about to be started.
329 // This notification is fired before a local temporary file has been created.
330 bool CanDownload(int request_id);
331
332 // Notifies the delegate that a download started.
333 void OnStartDownload(DownloadItem* download);
334
[email protected]0dd3a0ab2011-02-18 08:17:44335 // Interstitials -------------------------------------------------------------
336
337 // Various other systems need to know about our interstitials.
338 bool showing_interstitial_page() const {
339 return render_manager_.interstitial_page() != NULL;
340 }
341
342 // Sets the passed passed interstitial as the currently showing interstitial.
343 // |interstitial_page| should be non NULL (use the remove_interstitial_page
344 // method to unset the interstitial) and no interstitial page should be set
345 // when there is already a non NULL interstitial page set.
346 void set_interstitial_page(InterstitialPage* interstitial_page) {
347 render_manager_.set_interstitial_page(interstitial_page);
348 }
349
350 // Unsets the currently showing interstitial.
351 void remove_interstitial_page() {
352 render_manager_.remove_interstitial_page();
353 }
354
355 // Returns the currently showing interstitial, NULL if no interstitial is
356 // showing.
357 InterstitialPage* interstitial_page() const {
358 return render_manager_.interstitial_page();
359 }
360
361 // Misc state & callbacks ----------------------------------------------------
362
[email protected]c7dd2f62011-07-18 15:57:59363 // Prepare for saving the current web page to disk.
364 void OnSavePage();
365
366 // Save page with the main HTML file path, the directory for saving resources,
367 // and the save type: HTML only or complete web page. Returns true if the
368 // saving process has been initiated successfully.
369 bool SavePage(const FilePath& main_file, const FilePath& dir_path,
370 SavePackage::SavePackageType save_type);
371
372 // Prepare for saving the URL to disk.
373 // URL may refer to the iframe on the page.
374 void OnSaveURL(const GURL& url);
375
[email protected]0dd3a0ab2011-02-18 08:17:44376 // Returns true if the active NavigationEntry's page_id equals page_id.
377 bool IsActiveEntry(int32 page_id);
378
379 const std::string& contents_mime_type() const {
380 return contents_mime_type_;
381 }
382
383 // Returns true if this TabContents will notify about disconnection.
384 bool notify_disconnection() const { return notify_disconnection_; }
385
386 // Override the encoding and reload the page by sending down
387 // ViewMsg_SetPageEncoding to the renderer. |UpdateEncoding| is kinda
388 // the opposite of this, by which 'browser' is notified of
389 // the encoding of the current tab from 'renderer' (determined by
390 // auto-detect, http header, meta, bom detection, etc).
391 void SetOverrideEncoding(const std::string& encoding);
392
393 // Remove any user-defined override encoding and reload by sending down
394 // ViewMsg_ResetPageEncodingToDefault to the renderer.
395 void ResetOverrideEncoding();
396
[email protected]daf82f82011-10-31 22:35:31397 content::RendererPreferences* GetMutableRendererPrefs() {
[email protected]0dd3a0ab2011-02-18 08:17:44398 return &renderer_preferences_;
399 }
400
[email protected]1fd1a502011-03-30 16:55:56401 void set_opener_web_ui_type(WebUI::TypeID opener_web_ui_type) {
[email protected]0dd3a0ab2011-02-18 08:17:44402 opener_web_ui_type_ = opener_web_ui_type;
403 }
404
[email protected]0dd3a0ab2011-02-18 08:17:44405 // Set the time when we started to create the new tab page. This time is
406 // from before we created this TabContents.
407 void set_new_tab_start_time(const base::TimeTicks& time) {
408 new_tab_start_time_ = time;
409 }
[email protected]763ec4ca2011-04-29 15:48:12410 base::TimeTicks new_tab_start_time() const { return new_tab_start_time_; }
[email protected]0dd3a0ab2011-02-18 08:17:44411
412 // Notification that tab closing has started. This can be called multiple
413 // times, subsequent calls are ignored.
414 void OnCloseStarted();
415
[email protected]0dd3a0ab2011-02-18 08:17:44416 // Returns true if underlying TabContentsView should accept drag-n-drop.
417 bool ShouldAcceptDragAndDrop() const;
418
419 // A render view-originated drag has ended. Informs the render view host and
420 // tab contents delegate.
421 void SystemDragEnded();
422
423 // Indicates if this tab was explicitly closed by the user (control-w, close
424 // tab menu item...). This is false for actions that indirectly close the tab,
425 // such as closing the window. The setter is maintained by TabStripModel, and
426 // the getter only useful from within TAB_CLOSED notification
427 void set_closed_by_user_gesture(bool value) {
428 closed_by_user_gesture_ = value;
429 }
430 bool closed_by_user_gesture() const { return closed_by_user_gesture_; }
431
[email protected]3ab9cb82011-06-03 18:02:07432 // Overridden from JavaScriptDialogDelegate:
433 virtual void OnDialogClosed(IPC::Message* reply_msg,
434 bool success,
435 const string16& user_input) OVERRIDE;
[email protected]0b08add2011-11-29 03:27:06436 virtual gfx::NativeWindow GetDialogRootWindow() const OVERRIDE;
[email protected]a1e97f02011-06-30 14:04:34437 virtual void OnDialogShown() OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44438
[email protected]0dd3a0ab2011-02-18 08:17:44439 // Gets the zoom level for this tab.
440 double GetZoomLevel() const;
441
442 // Gets the zoom percent for this tab.
443 int GetZoomPercent(bool* enable_increment, bool* enable_decrement);
444
[email protected]0dd3a0ab2011-02-18 08:17:44445 // Opens view-source tab for this contents.
446 void ViewSource();
447
[email protected]932b7a12011-03-09 12:50:27448 void ViewFrameSource(const GURL& url,
449 const std::string& content_state);
450
[email protected]0dd3a0ab2011-02-18 08:17:44451 // Gets the minimum/maximum zoom percent.
452 int minimum_zoom_percent() const { return minimum_zoom_percent_; }
453 int maximum_zoom_percent() const { return maximum_zoom_percent_; }
454
455 int content_restrictions() const { return content_restrictions_; }
[email protected]c40d6232011-03-25 00:16:21456 void SetContentRestrictions(int restrictions);
[email protected]0dd3a0ab2011-02-18 08:17:44457
[email protected]1fd1a502011-03-30 16:55:56458 // Query the WebUIFactory for the TypeID for the current URL.
459 WebUI::TypeID GetWebUITypeForCurrentState();
460
[email protected]b375c5d2011-05-03 21:15:04461 // Returns the WebUI for the current state of the tab. This will either be
462 // the pending WebUI, the committed WebUI, or NULL.
463 WebUI* GetWebUIForCurrentState();
464
[email protected]e9621112011-10-17 05:38:37465 // Called when the reponse to a pending mouse lock request has arrived.
466 // Returns true if |allowed| is true and the mouse has been successfully
467 // locked.
468 bool GotResponseToLockMouseRequest(bool allowed);
469
[email protected]276b37a22011-11-08 20:45:46470 JavaBridgeDispatcherHostManager* java_bridge_dispatcher_host_manager() const {
471 return java_bridge_dispatcher_host_manager_.get();
472 }
473
[email protected]952a68e2011-11-17 00:36:10474 // RenderViewHostDelegate ----------------------------------------------------
475
476 virtual RenderViewHostDelegate::View* GetViewDelegate() OVERRIDE;
477 virtual RenderViewHostDelegate::RendererManagement*
478 GetRendererManagementDelegate() OVERRIDE;
479 virtual TabContents* GetAsTabContents() OVERRIDE;
480 virtual content::ViewType GetRenderViewType() const OVERRIDE;
481 virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE;
482 virtual void RenderViewReady(RenderViewHost* render_view_host) OVERRIDE;
483 virtual void RenderViewGone(RenderViewHost* render_view_host,
484 base::TerminationStatus status,
485 int error_code) OVERRIDE;
486 virtual void RenderViewDeleted(RenderViewHost* render_view_host) OVERRIDE;
487 virtual void DidNavigate(
488 RenderViewHost* render_view_host,
489 const ViewHostMsg_FrameNavigate_Params& params) OVERRIDE;
490 virtual void UpdateState(RenderViewHost* render_view_host,
491 int32 page_id,
492 const std::string& state) OVERRIDE;
493 virtual void UpdateTitle(RenderViewHost* render_view_host,
494 int32 page_id,
495 const string16& title,
496 base::i18n::TextDirection title_direction) OVERRIDE;
497 virtual void UpdateEncoding(RenderViewHost* render_view_host,
498 const std::string& encoding) OVERRIDE;
499 virtual void UpdateTargetURL(int32 page_id, const GURL& url) OVERRIDE;
500 virtual void Close(RenderViewHost* render_view_host) OVERRIDE;
501 virtual void RequestMove(const gfx::Rect& new_bounds) OVERRIDE;
502 virtual void SwappedOut(RenderViewHost* render_view_host) OVERRIDE;
503 virtual void DidStartLoading() OVERRIDE;
504 virtual void DidStopLoading() OVERRIDE;
505 virtual void DidCancelLoading() OVERRIDE;
506 virtual void DidChangeLoadProgress(double progress) OVERRIDE;
507 virtual void DocumentAvailableInMainFrame(
508 RenderViewHost* render_view_host) OVERRIDE;
509 virtual void DocumentOnLoadCompletedInMainFrame(
510 RenderViewHost* render_view_host,
511 int32 page_id) OVERRIDE;
512 virtual void RequestOpenURL(const GURL& url,
[email protected]445e1042011-12-03 21:03:15513 const content::Referrer& referrer,
[email protected]952a68e2011-11-17 00:36:10514 WindowOpenDisposition disposition,
515 int64 source_frame_id) OVERRIDE;
[email protected]4ad5d77d2011-12-03 02:00:48516 virtual void RequestTransferURL(
517 const GURL& url,
[email protected]bce1f1c2011-12-05 15:11:58518 const content::Referrer& referrer,
[email protected]4ad5d77d2011-12-03 02:00:48519 WindowOpenDisposition disposition,
520 int64 source_frame_id,
521 const GlobalRequestID& transferred_global_request_id) OVERRIDE;
[email protected]952a68e2011-11-17 00:36:10522 virtual void RunJavaScriptMessage(const RenderViewHost* rvh,
523 const string16& message,
524 const string16& default_prompt,
525 const GURL& frame_url,
526 const int flags,
527 IPC::Message* reply_msg,
528 bool* did_suppress_message) OVERRIDE;
529 virtual void RunBeforeUnloadConfirm(const RenderViewHost* rvh,
530 const string16& message,
531 IPC::Message* reply_msg) OVERRIDE;
532 virtual content::RendererPreferences GetRendererPrefs(
533 content::BrowserContext* browser_context) const OVERRIDE;
534 virtual WebPreferences GetWebkitPrefs() OVERRIDE;
535 virtual void OnUserGesture() OVERRIDE;
536 virtual void OnIgnoredUIEvent() OVERRIDE;
537 virtual void RendererUnresponsive(RenderViewHost* render_view_host,
538 bool is_during_unload) OVERRIDE;
539 virtual void RendererResponsive(RenderViewHost* render_view_host) OVERRIDE;
540 virtual void LoadStateChanged(const GURL& url,
541 const net::LoadStateWithParam& load_state,
542 uint64 upload_position,
543 uint64 upload_size) OVERRIDE;
544 virtual void WorkerCrashed() OVERRIDE;
545 virtual void Activate() OVERRIDE;
546 virtual void Deactivate() OVERRIDE;
547 virtual void LostCapture() OVERRIDE;
548 virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
549 bool* is_keyboard_shortcut) OVERRIDE;
550 virtual void HandleKeyboardEvent(
551 const NativeWebKeyboardEvent& event) OVERRIDE;
552 virtual void HandleMouseDown() OVERRIDE;
553 virtual void HandleMouseUp() OVERRIDE;
554 virtual void HandleMouseActivate() OVERRIDE;
[email protected]edc64de2011-11-17 20:07:38555 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
556 virtual void RunFileChooser(
557 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23558 const content::FileChooserParams& params) OVERRIDE;
[email protected]952a68e2011-11-17 00:36:10559 virtual void ToggleFullscreenMode(bool enter_fullscreen) OVERRIDE;
560 virtual bool IsFullscreenForCurrentTab() const OVERRIDE;
561 virtual void UpdatePreferredSize(const gfx::Size& pref_size) OVERRIDE;
562 virtual void WebUISend(RenderViewHost* render_view_host,
563 const GURL& source_url,
564 const std::string& name,
565 const base::ListValue& args) OVERRIDE;
566 virtual void RequestToLockMouse() OVERRIDE;
567 virtual void LostMouseLock() OVERRIDE;
568
[email protected]0dd3a0ab2011-02-18 08:17:44569 protected:
[email protected]553602e12011-04-05 17:01:18570 friend class TabContentsObserver;
[email protected]553602e12011-04-05 17:01:18571
572 // Add and remove observers for page navigation notifications. Adding or
573 // removing multiple times has no effect. The order in which notifications
574 // are sent to observers is undefined. Clients must be sure to remove the
575 // observer before they go away.
576 void AddObserver(TabContentsObserver* observer);
577 void RemoveObserver(TabContentsObserver* observer);
578
[email protected]0dd3a0ab2011-02-18 08:17:44579 private:
580 friend class NavigationController;
[email protected]0dd3a0ab2011-02-18 08:17:44581
582 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, NoJSMessageOnInterstitials);
583 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, UpdateTitle);
584 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, CrossSiteCantPreemptAfterUnload);
585 FRIEND_TEST_ALL_PREFIXES(FormStructureBrowserTest, HTMLFiles);
586 FRIEND_TEST_ALL_PREFIXES(NavigationControllerTest, HistoryNavigate);
587 FRIEND_TEST_ALL_PREFIXES(RenderViewHostManagerTest, PageDoesBackAndReload);
588
589 // Temporary until the view/contents separation is complete.
590 friend class TabContentsView;
[email protected]9a56a0d2011-05-13 19:03:31591#if defined(TOOLKIT_VIEWS)
[email protected]7e2cef52011-04-11 21:47:23592 friend class TabContentsViewViews;
[email protected]0dd3a0ab2011-02-18 08:17:44593#elif defined(OS_MACOSX)
594 friend class TabContentsViewMac;
595#elif defined(TOOLKIT_USES_GTK)
596 friend class TabContentsViewGtk;
597#endif
598
599 // So InterstitialPage can access SetIsLoading.
600 friend class InterstitialPage;
601
602 // TODO(brettw) TestTabContents shouldn't exist!
603 friend class TestTabContents;
604
[email protected]0dd3a0ab2011-02-18 08:17:44605 // Message handlers.
[email protected]8b5af492011-11-28 21:50:58606 void OnRegisterIntentService(const string16& action,
[email protected]63c239322011-10-31 23:56:30607 const string16& type,
608 const string16& href,
609 const string16& title,
610 const string16& disposition);
611 void OnWebIntentDispatch(const IPC::Message& message,
612 const webkit_glue::WebIntentData& intent,
613 int intent_id);
[email protected]0dd3a0ab2011-02-18 08:17:44614 void OnDidStartProvisionalLoadForFrame(int64 frame_id,
615 bool main_frame,
[email protected]57b9396c2011-10-07 19:11:59616 const GURL& opener_url,
[email protected]0dd3a0ab2011-02-18 08:17:44617 const GURL& url);
618 void OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]57b9396c2011-10-07 19:11:59619 const GURL& opener_url,
[email protected]0dd3a0ab2011-02-18 08:17:44620 const GURL& source_url,
621 const GURL& target_url);
[email protected]d7b175e2011-10-11 15:31:58622 void OnDidFailProvisionalLoadWithError(
623 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params);
[email protected]0dd3a0ab2011-02-18 08:17:44624 void OnDidLoadResourceFromMemoryCache(const GURL& url,
[email protected]70435962011-08-02 20:13:28625 const std::string& security_info,
626 const std::string& http_request,
627 ResourceType::Type resource_type);
[email protected]0dd3a0ab2011-02-18 08:17:44628 void OnDidDisplayInsecureContent();
629 void OnDidRunInsecureContent(const std::string& security_origin,
630 const GURL& target_url);
631 void OnDocumentLoadedInFrame(int64 frame_id);
[email protected]1a55c5be2011-11-29 11:36:31632 void OnDidFinishLoad(int64 frame_id,
633 const GURL& validated_url,
634 bool is_main_frame);
635 void OnDidFailLoadWithError(int64 frame_id,
636 const GURL& validated_url,
637 bool is_main_frame,
638 int error_code,
639 const string16& error_description);
[email protected]0dd3a0ab2011-02-18 08:17:44640 void OnUpdateContentRestrictions(int restrictions);
[email protected]0dd3a0ab2011-02-18 08:17:44641 void OnGoToEntryAtOffset(int offset);
[email protected]216813952011-05-19 22:21:26642 void OnUpdateZoomLimits(int minimum_percent,
643 int maximum_percent,
644 bool remember);
645 void OnFocusedNodeChanged(bool is_editable_node);
[email protected]3a29a6e2011-08-24 18:26:21646 void OnEnumerateDirectory(int request_id, const FilePath& path);
[email protected]7d189022011-08-25 22:54:20647 void OnJSOutOfMemory();
648 void OnRegisterProtocolHandler(const std::string& protocol,
649 const GURL& url,
650 const string16& title);
[email protected]b888919c2011-09-02 00:32:16651 void OnFindReply(int request_id, int number_of_matches,
652 const gfx::Rect& selection_rect, int active_match_ordinal,
653 bool final_update);
[email protected]d952a052011-09-06 18:42:45654 void OnCrashedPlugin(const FilePath& plugin_path);
[email protected]7fc4bbb2011-09-08 21:23:10655 void OnAppCacheAccessed(const GURL& manifest_url, bool blocked_by_policy);
[email protected]0dd3a0ab2011-02-18 08:17:44656
657 // Changes the IsLoading state and notifies delegate as needed
658 // |details| is used to provide details on the load that just finished
659 // (but can be null if not applicable). Can be overridden.
660 void SetIsLoading(bool is_loading,
661 LoadNotificationDetails* details);
662
[email protected]0dd3a0ab2011-02-18 08:17:44663 // Called by derived classes to indicate that we're no longer waiting for a
664 // response. This won't actually update the throbber, but it will get picked
665 // up at the next animation step if the throbber is going.
666 void SetNotWaitingForResponse() { waiting_for_response_ = false; }
667
[email protected]0dd3a0ab2011-02-18 08:17:44668 // Navigation helpers --------------------------------------------------------
669 //
670 // These functions are helpers for Navigate() and DidNavigate().
671
672 // Handles post-navigation tasks in DidNavigate AFTER the entry has been
673 // committed to the navigation controller. Note that the navigation entry is
674 // not provided since it may be invalid/changed after being committed. The
675 // current navigation entry is in the NavigationController at this point.
676 void DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:13677 const content::LoadCommittedDetails& details,
[email protected]0dd3a0ab2011-02-18 08:17:44678 const ViewHostMsg_FrameNavigate_Params& params);
679 void DidNavigateAnyFramePostCommit(
680 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:13681 const content::LoadCommittedDetails& details,
[email protected]0dd3a0ab2011-02-18 08:17:44682 const ViewHostMsg_FrameNavigate_Params& params);
683
[email protected]0dd3a0ab2011-02-18 08:17:44684 // If our controller was restored and the page id is > than the site
685 // instance's page id, the site instances page id is updated as well as the
686 // renderers max page id.
687 void UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
688 RenderViewHost* rvh);
689
[email protected]0dd3a0ab2011-02-18 08:17:44690 // Saves the given title to the navigation entry and does associated work. It
691 // will update history and the view for the new title, and also synthesize
692 // titles for file URLs that have none (so we require that the URL of the
693 // entry already be set).
694 //
695 // This is used as the backend for state updates, which include a new title,
696 // or the dedicated set title message. It returns true if the new title is
697 // different and was therefore updated.
[email protected]acafd272011-07-26 17:35:57698 bool UpdateTitleForEntry(NavigationEntry* entry, const string16& title);
[email protected]0dd3a0ab2011-02-18 08:17:44699
700 // Causes the TabContents to navigate in the right renderer to |entry|, which
701 // must be already part of the entries in the navigation controller.
702 // This does not change the NavigationController state.
[email protected]dd11de52011-11-03 22:54:27703 bool NavigateToEntry(const NavigationEntry& entry,
[email protected]0dd3a0ab2011-02-18 08:17:44704 NavigationController::ReloadType reload_type);
705
[email protected]796931a92011-08-10 01:32:14706 // Sets the history for this tab_contents to |history_length| entries, and
707 // moves the current page_id to the last entry in the list if it's valid.
708 // This is mainly used when a prerendered page is swapped into the current
[email protected]9e1ad4b2011-08-14 16:49:19709 // tab. The method is virtual for testing.
710 virtual void SetHistoryLengthAndPrune(const SiteInstance* site_instance,
711 int merge_history_length,
712 int32 minimum_page_id);
[email protected]796931a92011-08-10 01:32:14713
[email protected]0dd3a0ab2011-02-18 08:17:44714 // Misc non-view stuff -------------------------------------------------------
715
716 // Helper functions for sending notifications.
717 void NotifySwapped();
718 void NotifyConnected();
719 void NotifyDisconnected();
720
[email protected]0dd3a0ab2011-02-18 08:17:44721 // RenderViewHostManager::Delegate -------------------------------------------
722
[email protected]0dd3a0ab2011-02-18 08:17:44723 virtual void BeforeUnloadFiredFromRenderManager(
724 bool proceed,
[email protected]edc64de2011-11-17 20:07:38725 bool* proceed_to_fire_unload) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44726 virtual void DidStartLoadingFromRenderManager(
[email protected]edc64de2011-11-17 20:07:38727 RenderViewHost* render_view_host) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44728 virtual void RenderViewGoneFromRenderManager(
[email protected]edc64de2011-11-17 20:07:38729 RenderViewHost* render_view_host) OVERRIDE;
730 virtual void UpdateRenderViewSizeForRenderManager() OVERRIDE;
731 virtual void NotifySwappedFromRenderManager() OVERRIDE;
732 virtual NavigationController& GetControllerForRenderManager() OVERRIDE;
733 virtual WebUI* CreateWebUIForRenderManager(const GURL& url) OVERRIDE;
734 virtual NavigationEntry*
735 GetLastCommittedNavigationEntryForRenderManager() OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44736
737 // Initializes the given renderer if necessary and creates the view ID
738 // corresponding to this view host. If this method is not called and the
739 // process is not shared, then the TabContents will act as though the renderer
740 // is not running (i.e., it will render "sad tab"). This method is
741 // automatically called from LoadURL.
742 //
743 // If you are attaching to an already-existing RenderView, you should call
744 // InitWithExistingID.
745 virtual bool CreateRenderViewForRenderManager(
[email protected]edc64de2011-11-17 20:07:38746 RenderViewHost* render_view_host) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44747
[email protected]81898992011-06-14 22:15:00748 // Stores random bits of data for others to associate with this object.
749 // WARNING: this needs to be deleted after NavigationController.
[email protected]45644f62011-11-23 00:58:23750 base::PropertyBag property_bag_;
[email protected]81898992011-06-14 22:15:00751
[email protected]0dd3a0ab2011-02-18 08:17:44752 // Data for core operation ---------------------------------------------------
753
754 // Delegate for notifying our owner about stuff. Not owned by us.
755 TabContentsDelegate* delegate_;
756
757 // Handles the back/forward list and loading.
758 NavigationController controller_;
759
760 // The corresponding view.
761 scoped_ptr<TabContentsView> view_;
762
[email protected]996042972011-11-08 22:43:59763 // A list of observers notified when page state changes. Weak references.
764 // This MUST be listed above render_manager_ since at destruction time the
765 // latter might cause RenderViewHost's destructor to call us and we might use
766 // the observer list then.
767 ObserverList<TabContentsObserver> observers_;
768
[email protected]0dd3a0ab2011-02-18 08:17:44769 // Helper classes ------------------------------------------------------------
770
771 // Manages creation and swapping of render views.
772 RenderViewHostManager render_manager_;
773
[email protected]483623eb2011-10-25 09:30:00774 // Manages injecting Java objects into all RenderViewHosts associated with
775 // this TabContents.
776 scoped_ptr<JavaBridgeDispatcherHostManager>
777 java_bridge_dispatcher_host_manager_;
778
[email protected]c7dd2f62011-07-18 15:57:59779 // SavePackage, lazily created.
780 scoped_refptr<SavePackage> save_package_;
781
[email protected]0dd3a0ab2011-02-18 08:17:44782 // Data for loading state ----------------------------------------------------
783
784 // Indicates whether we're currently loading a resource.
785 bool is_loading_;
786
787 // Indicates if the tab is considered crashed.
788 base::TerminationStatus crashed_status_;
789 int crashed_error_code_;
790
791 // See waiting_for_response() above.
792 bool waiting_for_response_;
793
794 // Indicates the largest PageID we've seen. This field is ignored if we are
795 // a TabContents, in which case the max page ID is stored separately with
796 // each SiteInstance.
797 // TODO(brettw) this seems like it can be removed according to the comment.
798 int32 max_page_id_;
799
800 // System time at which the current load was started.
801 base::TimeTicks current_load_start_;
802
803 // The current load state and the URL associated with it.
[email protected]9c235f042011-08-10 22:28:21804 net::LoadStateWithParam load_state_;
[email protected]0dd3a0ab2011-02-18 08:17:44805 string16 load_state_host_;
806 // Upload progress, for displaying in the status bar.
807 // Set to zero when there is no significant upload happening.
808 uint64 upload_size_;
809 uint64 upload_position_;
810
811 // Data for current page -----------------------------------------------------
812
[email protected]987fc3a2011-05-26 14:18:09813 // When a title cannot be taken from any entry, this title will be used.
814 string16 page_title_when_no_navigation_entry_;
815
[email protected]0dd3a0ab2011-02-18 08:17:44816 // When a navigation occurs, we record its contents MIME type. It can be
817 // used to check whether we can do something for some special contents.
818 std::string contents_mime_type_;
819
820 // Character encoding.
821 std::string encoding_;
822
[email protected]0dd3a0ab2011-02-18 08:17:44823 // True if this is a secure page which displayed insecure content.
824 bool displayed_insecure_content_;
825
[email protected]0dd3a0ab2011-02-18 08:17:44826 // Data for misc internal state ----------------------------------------------
827
828 // See capturing_contents() above.
829 bool capturing_contents_;
830
831 // See getter above.
832 bool is_being_destroyed_;
833
834 // Indicates whether we should notify about disconnection of this
835 // TabContents. This is used to ensure disconnection notifications only
836 // happen if a connection notification has happened and that they happen only
837 // once.
838 bool notify_disconnection_;
839
[email protected]2e5b90c2011-08-16 21:11:55840 // Pointer to the JavaScript dialog creator, lazily assigned. Used because the
841 // delegate of this TabContents is nulled before its destructor is called.
842 content::JavaScriptDialogCreator* dialog_creator_;
843
[email protected]0dd3a0ab2011-02-18 08:17:44844#if defined(OS_WIN)
845 // Handle to an event that's set when the page is showing a message box (or
846 // equivalent constrained window). Plugin processes check this to know if
847 // they should pump messages then.
848 base::win::ScopedHandle message_box_active_;
849#endif
850
[email protected]0dd3a0ab2011-02-18 08:17:44851 // Set to true when there is an active "before unload" dialog. When true,
852 // we've forced the throbber to start in Navigate, and we need to remember to
853 // turn it off in OnJavaScriptMessageBoxClosed if the navigation is canceled.
854 bool is_showing_before_unload_dialog_;
855
[email protected]0dd3a0ab2011-02-18 08:17:44856 // Settings that get passed to the renderer process.
[email protected]daf82f82011-10-31 22:35:31857 content::RendererPreferences renderer_preferences_;
[email protected]0dd3a0ab2011-02-18 08:17:44858
859 // If this tab was created from a renderer using window.open, this will be
860 // non-NULL and represent the WebUI of the opening renderer.
[email protected]1fd1a502011-03-30 16:55:56861 WebUI::TypeID opener_web_ui_type_;
[email protected]0dd3a0ab2011-02-18 08:17:44862
863 // The time that we started to create the new tab page.
864 base::TimeTicks new_tab_start_time_;
865
866 // The time that we started to close the tab.
867 base::TimeTicks tab_close_start_time_;
868
869 // The time that this tab was last selected.
870 base::TimeTicks last_selected_time_;
871
[email protected]0dd3a0ab2011-02-18 08:17:44872 // See description above setter.
873 bool closed_by_user_gesture_;
874
875 // Minimum/maximum zoom percent.
876 int minimum_zoom_percent_;
877 int maximum_zoom_percent_;
878 // If true, the default zoom limits have been overriden for this tab, in which
879 // case we don't want saved settings to apply to it and we don't want to
880 // remember it.
881 bool temporary_zoom_settings_;
882
[email protected]0dd3a0ab2011-02-18 08:17:44883 // Content restrictions, used to disable print/copy etc based on content's
884 // (full-page plugins for now only) permissions.
885 int content_restrictions_;
886
[email protected]32ded2212011-11-10 18:51:43887 // Our view type. Default is VIEW_TYPE_TAB_CONTENTS.
888 content::ViewType view_type_;
889
[email protected]0dd3a0ab2011-02-18 08:17:44890 DISALLOW_COPY_AND_ASSIGN(TabContents);
891};
892
893#endif // CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_H_