blob: 3f416e4ac8723dc76ba93ced2dff7ce573a3ee84 [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]0dd3a0ab2011-02-18 08:17:4457
58// Describes what goes in the main content area of a tab. TabContents is
59// the only type of TabContents, and these should be merged together.
60class TabContents : public PageNavigator,
[email protected]0dd3a0ab2011-02-18 08:17:4461 public RenderViewHostDelegate,
62 public RenderViewHostManager::Delegate,
[email protected]6eac57a2011-07-12 21:15:0963 public content::JavaScriptDialogDelegate {
[email protected]0dd3a0ab2011-02-18 08:17:4464 public:
65 // Flags passed to the TabContentsDelegate.NavigationStateChanged to tell it
66 // what has changed. Combine them to update more than one thing.
67 enum InvalidateTypes {
68 INVALIDATE_URL = 1 << 0, // The URL has changed.
69 INVALIDATE_TAB = 1 << 1, // The favicon, app icon, or crashed
70 // state changed.
71 INVALIDATE_LOAD = 1 << 2, // The loading state has changed.
72 INVALIDATE_PAGE_ACTIONS = 1 << 3, // Page action icons have changed.
[email protected]93f230e02011-06-01 14:40:0073 INVALIDATE_TITLE = 1 << 4, // The title changed.
[email protected]0dd3a0ab2011-02-18 08:17:4474 };
75
76 // |base_tab_contents| is used if we want to size the new tab contents view
77 // based on an existing tab contents view. This can be NULL if not needed.
78 //
79 // The session storage namespace parameter allows multiple render views and
80 // tab contentses to share the same session storage (part of the WebStorage
81 // spec) space. This is useful when restoring tabs, but most callers should
82 // pass in NULL which will cause a new SessionStorageNamespace to be created.
[email protected]3d7474ff2011-07-27 17:47:3783 TabContents(content::BrowserContext* browser_context,
[email protected]0dd3a0ab2011-02-18 08:17:4484 SiteInstance* site_instance,
85 int routing_id,
86 const TabContents* base_tab_contents,
87 SessionStorageNamespace* session_storage_namespace);
88 virtual ~TabContents();
89
90 // Intrinsic tab state -------------------------------------------------------
91
92 // Returns the property bag for this tab contents, where callers can add
93 // extra data they may wish to associate with the tab. Returns a pointer
94 // rather than a reference since the PropertyAccessors expect this.
95 const PropertyBag* property_bag() const { return &property_bag_; }
96 PropertyBag* property_bag() { return &property_bag_; }
97
98 TabContentsDelegate* delegate() const { return delegate_; }
[email protected]1de2b8b2011-06-29 19:38:4699 void set_delegate(TabContentsDelegate* delegate);
[email protected]0dd3a0ab2011-02-18 08:17:44100
101 // Gets the controller for this tab contents.
102 NavigationController& controller() { return controller_; }
103 const NavigationController& controller() const { return controller_; }
104
[email protected]3d7474ff2011-07-27 17:47:37105 // Returns the user browser context associated with this TabContents (via the
[email protected]0dd3a0ab2011-02-18 08:17:44106 // NavigationController).
[email protected]3d7474ff2011-07-27 17:47:37107 content::BrowserContext* browser_context() const {
108 return controller_.browser_context();
109 }
110
[email protected]c7dd2f62011-07-18 15:57:59111 // Returns the SavePackage which manages the page saving job. May be NULL.
112 SavePackage* save_package() const { return save_package_.get(); }
113
[email protected]0dd3a0ab2011-02-18 08:17:44114 // Return the currently active RenderProcessHost and RenderViewHost. Each of
115 // these may change over time.
116 RenderProcessHost* GetRenderProcessHost() const;
117 RenderViewHost* render_view_host() const {
118 return render_manager_.current_host();
119 }
120
[email protected]93f230e02011-06-01 14:40:00121 WebUI* committed_web_ui() const {
122 return render_manager_.web_ui();
123 }
124
[email protected]0dd3a0ab2011-02-18 08:17:44125 WebUI* web_ui() const {
126 return render_manager_.web_ui() ? render_manager_.web_ui()
127 : render_manager_.pending_web_ui();
128 }
129
130 // Returns the currently active RenderWidgetHostView. This may change over
131 // time and can be NULL (during setup and teardown).
132 RenderWidgetHostView* GetRenderWidgetHostView() const {
133 return render_manager_.GetRenderWidgetHostView();
134 }
135
136 // The TabContentsView will never change and is guaranteed non-NULL.
137 TabContentsView* view() const {
138 return view_.get();
139 }
140
[email protected]0dd3a0ab2011-02-18 08:17:44141 // Tab navigation state ------------------------------------------------------
142
143 // Returns the current navigation properties, which if a navigation is
144 // pending may be provisional (e.g., the navigation could result in a
145 // download, in which case the URL would revert to what it was previously).
146 virtual const GURL& GetURL() const;
147 virtual const string16& GetTitle() const;
148
149 // The max PageID of any page that this TabContents has loaded. PageIDs
150 // increase with each new page that is loaded by a tab. If this is a
151 // TabContents, then the max PageID is kept separately on each SiteInstance.
152 // Returns -1 if no PageIDs have yet been seen.
153 int32 GetMaxPageID();
154
155 // Updates the max PageID to be at least the given PageID.
156 void UpdateMaxPageID(int32 page_id);
157
158 // Returns the site instance associated with the current page. By default,
159 // there is no site instance. TabContents overrides this to provide proper
160 // access to its site instance.
161 virtual SiteInstance* GetSiteInstance() const;
162
[email protected]77362eb2011-08-01 17:18:38163 // Returns the SiteInstance for the pending navigation, if any. Otherwise
164 // returns the current SiteInstance.
165 SiteInstance* GetPendingSiteInstance() const;
166
[email protected]0dd3a0ab2011-02-18 08:17:44167 // Defines whether this tab's URL should be displayed in the browser's URL
168 // bar. Normally this is true so you can see the URL. This is set to false
169 // for the new tab page and related pages so that the URL bar is empty and
170 // the user is invited to type into it.
171 virtual bool ShouldDisplayURL();
172
[email protected]f5d978c2011-07-21 14:43:51173 // Return whether this tab contents is loading a resource, or whether its
174 // web_ui is.
175 bool IsLoading() const;
[email protected]0dd3a0ab2011-02-18 08:17:44176
177 // Returns whether this tab contents is waiting for a first-response for the
178 // main resource of the page. This controls whether the throbber state is
179 // "waiting" or "loading."
180 bool waiting_for_response() const { return waiting_for_response_; }
181
[email protected]9c235f042011-08-10 22:28:21182 const net::LoadStateWithParam& load_state() const { return load_state_; }
183 const string16& load_state_host() const { return load_state_host_; }
[email protected]0dd3a0ab2011-02-18 08:17:44184 uint64 upload_size() const { return upload_size_; }
185 uint64 upload_position() const { return upload_position_; }
186
187 const std::string& encoding() const { return encoding_; }
188 void set_encoding(const std::string& encoding);
189 void reset_encoding() {
190 encoding_.clear();
191 }
192
[email protected]0dd3a0ab2011-02-18 08:17:44193 bool displayed_insecure_content() const {
194 return displayed_insecure_content_;
195 }
196
197 // Internal state ------------------------------------------------------------
198
199 // This flag indicates whether the tab contents is currently being
200 // screenshotted by the DraggedTabController.
201 bool capturing_contents() const { return capturing_contents_; }
202 void set_capturing_contents(bool cap) { capturing_contents_ = cap; }
203
204 // Indicates whether this tab should be considered crashed. The setter will
205 // also notify the delegate when the flag is changed.
206 bool is_crashed() const {
207 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
208 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
209 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
210 }
211 base::TerminationStatus crashed_status() const { return crashed_status_; }
212 int crashed_error_code() const { return crashed_error_code_; }
213 void SetIsCrashed(base::TerminationStatus status, int error_code);
214
[email protected]0dd3a0ab2011-02-18 08:17:44215 // Whether the tab is in the process of being destroyed.
216 // Added as a tentative work-around for focus related bug #4633. This allows
217 // us not to store focus when a tab is being closed.
218 bool is_being_destroyed() const { return is_being_destroyed_; }
219
220 // Convenience method for notifying the delegate of a navigation state
221 // change. See TabContentsDelegate.
222 void NotifyNavigationStateChanged(unsigned changed_flags);
223
224 // Invoked when the tab contents becomes selected. If you override, be sure
225 // and invoke super's implementation.
226 virtual void DidBecomeSelected();
227 base::TimeTicks last_selected_time() const {
228 return last_selected_time_;
229 }
230
231 // Invoked when the tab contents becomes hidden.
232 // NOTE: If you override this, call the superclass version too!
233 virtual void WasHidden();
234
[email protected]0dd3a0ab2011-02-18 08:17:44235 // TODO(brettw) document these.
236 virtual void ShowContents();
237 virtual void HideContents();
238
239 // Returns true if the before unload and unload listeners need to be
240 // fired. The value of this changes over time. For example, if true and the
241 // before unload listener is executed and allows the user to exit, then this
242 // returns false.
243 bool NeedToFireBeforeUnload();
244
245#ifdef UNIT_TEST
246 // Expose the render manager for testing.
247 RenderViewHostManager* render_manager() { return &render_manager_; }
248#endif
249
250 // In the underlying RenderViewHostManager, swaps in the provided
251 // RenderViewHost to replace the current RenderViewHost. The current RVH
252 // will be shutdown and ultimately deleted.
253 void SwapInRenderViewHost(RenderViewHost* rvh);
254
255 // Commands ------------------------------------------------------------------
256
257 // Implementation of PageNavigator.
[email protected]00c37fc2011-08-02 00:22:50258
259 // Deprecated. Please use the one-argument variant instead.
260 // TODO(adriansc): Remove this method once refactoring changed all call sites.
[email protected]992e4542011-07-20 23:09:25261 virtual TabContents* OpenURL(const GURL& url,
262 const GURL& referrer,
263 WindowOpenDisposition disposition,
264 PageTransition::Type transition) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44265
[email protected]00c37fc2011-08-02 00:22:50266 virtual TabContents* OpenURL(const OpenURLParams& params) OVERRIDE;
267
[email protected]0dd3a0ab2011-02-18 08:17:44268 // Called by the NavigationController to cause the TabContents to navigate to
269 // the current pending entry. The NavigationController should be called back
[email protected]9a7e68c2011-05-26 17:35:50270 // with RendererDidNavigate on success or DiscardPendingEntry on failure.
271 // The callbacks can be inside of this function, or at some future time.
[email protected]0dd3a0ab2011-02-18 08:17:44272 //
273 // The entry has a PageID of -1 if newly created (corresponding to navigation
274 // to a new URL).
275 //
276 // If this method returns false, then the navigation is discarded (equivalent
277 // to calling DiscardPendingEntry on the NavigationController).
278 virtual bool NavigateToPendingEntry(
279 NavigationController::ReloadType reload_type);
280
281 // Stop any pending navigation.
282 virtual void Stop();
283
[email protected]0dd3a0ab2011-02-18 08:17:44284 // Creates a new TabContents with the same state as this one. The returned
285 // heap-allocated pointer is owned by the caller.
286 virtual TabContents* Clone();
287
288 // Shows the page info.
289 void ShowPageInfo(const GURL& url,
290 const NavigationEntry::SSLStatus& ssl,
291 bool show_history);
292
[email protected]0dd3a0ab2011-02-18 08:17:44293 // Window management ---------------------------------------------------------
294
295 // Create a new window constrained to this TabContents' clip and visibility.
296 // The window is initialized by using the supplied delegate to obtain basic
297 // window characteristics, and the supplied view for the content. Note that
298 // the returned ConstrainedWindow might not yet be visible.
299 ConstrainedWindow* CreateConstrainedDialog(
300 ConstrainedWindowDelegate* delegate);
301
[email protected]473174942011-04-19 22:52:35302 // Adds a new tab or window with the given already-created contents.
[email protected]e7cfdbd2011-04-22 14:41:37303 void AddNewContents(TabContents* new_contents,
304 WindowOpenDisposition disposition,
305 const gfx::Rect& initial_pos,
306 bool user_gesture);
[email protected]0dd3a0ab2011-02-18 08:17:44307
308 // Returns the number of constrained windows in this tab. Used by tests.
309 size_t constrained_window_count() { return child_windows_.size(); }
310
311 typedef std::deque<ConstrainedWindow*> ConstrainedWindowList;
312
313 // Return an iterator for the first constrained window in this tab contents.
314 ConstrainedWindowList::iterator constrained_window_begin()
315 { return child_windows_.begin(); }
316
317 // Return an iterator for the last constrained window in this tab contents.
318 ConstrainedWindowList::iterator constrained_window_end()
319 { return child_windows_.end(); }
320
321 // Views and focus -----------------------------------------------------------
322 // TODO(brettw): Most of these should be removed and the caller should call
323 // the view directly.
324
325 // Returns the actual window that is focused when this TabContents is shown.
326 gfx::NativeView GetContentNativeView() const;
327
328 // Returns the NativeView associated with this TabContents. Outside of
329 // automation in the context of the UI, this is required to be implemented.
330 gfx::NativeView GetNativeView() const;
331
332 // Returns the bounds of this TabContents in the screen coordinate system.
333 void GetContainerBounds(gfx::Rect *out) const;
334
335 // Makes the tab the focused window.
336 void Focus();
337
338 // Focuses the first (last if |reverse| is true) element in the page.
339 // Invoked when this tab is getting the focus through tab traversal (|reverse|
340 // is true when using Shift-Tab).
341 void FocusThroughTabTraversal(bool reverse);
342
343 // These next two functions are declared on RenderViewHostManager::Delegate
344 // but also accessed directly by other callers.
345
346 // Returns true if the location bar should be focused by default rather than
347 // the page contents. The view calls this function when the tab is focused
348 // to see what it should do.
349 virtual bool FocusLocationBarByDefault();
350
351 // Focuses the location bar.
352 virtual void SetFocusToLocationBar(bool select_all);
353
354 // Creates a view and sets the size for the specified RVH.
355 virtual void CreateViewAndSetSizeForRVH(RenderViewHost* rvh);
356
[email protected]0dd3a0ab2011-02-18 08:17:44357 // Toolbars and such ---------------------------------------------------------
358
[email protected]686493142011-07-15 21:47:22359 // Notifies the delegate that a download is about to be started.
360 // This notification is fired before a local temporary file has been created.
361 bool CanDownload(int request_id);
362
363 // Notifies the delegate that a download started.
364 void OnStartDownload(DownloadItem* download);
365
[email protected]0dd3a0ab2011-02-18 08:17:44366 // Called when a ConstrainedWindow we own is about to be closed.
367 void WillClose(ConstrainedWindow* window);
368
[email protected]0dd3a0ab2011-02-18 08:17:44369 // Interstitials -------------------------------------------------------------
370
371 // Various other systems need to know about our interstitials.
372 bool showing_interstitial_page() const {
373 return render_manager_.interstitial_page() != NULL;
374 }
375
376 // Sets the passed passed interstitial as the currently showing interstitial.
377 // |interstitial_page| should be non NULL (use the remove_interstitial_page
378 // method to unset the interstitial) and no interstitial page should be set
379 // when there is already a non NULL interstitial page set.
380 void set_interstitial_page(InterstitialPage* interstitial_page) {
381 render_manager_.set_interstitial_page(interstitial_page);
382 }
383
384 // Unsets the currently showing interstitial.
385 void remove_interstitial_page() {
386 render_manager_.remove_interstitial_page();
387 }
388
389 // Returns the currently showing interstitial, NULL if no interstitial is
390 // showing.
391 InterstitialPage* interstitial_page() const {
392 return render_manager_.interstitial_page();
393 }
394
395 // Misc state & callbacks ----------------------------------------------------
396
[email protected]c7dd2f62011-07-18 15:57:59397 // Prepare for saving the current web page to disk.
398 void OnSavePage();
399
400 // Save page with the main HTML file path, the directory for saving resources,
401 // and the save type: HTML only or complete web page. Returns true if the
402 // saving process has been initiated successfully.
403 bool SavePage(const FilePath& main_file, const FilePath& dir_path,
404 SavePackage::SavePackageType save_type);
405
406 // Prepare for saving the URL to disk.
407 // URL may refer to the iframe on the page.
408 void OnSaveURL(const GURL& url);
409
[email protected]0dd3a0ab2011-02-18 08:17:44410 // Returns true if the active NavigationEntry's page_id equals page_id.
411 bool IsActiveEntry(int32 page_id);
412
413 const std::string& contents_mime_type() const {
414 return contents_mime_type_;
415 }
416
417 // Returns true if this TabContents will notify about disconnection.
418 bool notify_disconnection() const { return notify_disconnection_; }
419
420 // Override the encoding and reload the page by sending down
421 // ViewMsg_SetPageEncoding to the renderer. |UpdateEncoding| is kinda
422 // the opposite of this, by which 'browser' is notified of
423 // the encoding of the current tab from 'renderer' (determined by
424 // auto-detect, http header, meta, bom detection, etc).
425 void SetOverrideEncoding(const std::string& encoding);
426
427 // Remove any user-defined override encoding and reload by sending down
428 // ViewMsg_ResetPageEncodingToDefault to the renderer.
429 void ResetOverrideEncoding();
430
[email protected]0dd3a0ab2011-02-18 08:17:44431 RendererPreferences* GetMutableRendererPrefs() {
432 return &renderer_preferences_;
433 }
434
[email protected]1fd1a502011-03-30 16:55:56435 void set_opener_web_ui_type(WebUI::TypeID opener_web_ui_type) {
[email protected]0dd3a0ab2011-02-18 08:17:44436 opener_web_ui_type_ = opener_web_ui_type;
437 }
438
[email protected]0dd3a0ab2011-02-18 08:17:44439 // Set the time when we started to create the new tab page. This time is
440 // from before we created this TabContents.
441 void set_new_tab_start_time(const base::TimeTicks& time) {
442 new_tab_start_time_ = time;
443 }
[email protected]763ec4ca2011-04-29 15:48:12444 base::TimeTicks new_tab_start_time() const { return new_tab_start_time_; }
[email protected]0dd3a0ab2011-02-18 08:17:44445
446 // Notification that tab closing has started. This can be called multiple
447 // times, subsequent calls are ignored.
448 void OnCloseStarted();
449
[email protected]0dd3a0ab2011-02-18 08:17:44450 // Returns true if underlying TabContentsView should accept drag-n-drop.
451 bool ShouldAcceptDragAndDrop() const;
452
453 // A render view-originated drag has ended. Informs the render view host and
454 // tab contents delegate.
455 void SystemDragEnded();
456
457 // Indicates if this tab was explicitly closed by the user (control-w, close
458 // tab menu item...). This is false for actions that indirectly close the tab,
459 // such as closing the window. The setter is maintained by TabStripModel, and
460 // the getter only useful from within TAB_CLOSED notification
461 void set_closed_by_user_gesture(bool value) {
462 closed_by_user_gesture_ = value;
463 }
464 bool closed_by_user_gesture() const { return closed_by_user_gesture_; }
465
[email protected]3ab9cb82011-06-03 18:02:07466 // Overridden from JavaScriptDialogDelegate:
467 virtual void OnDialogClosed(IPC::Message* reply_msg,
468 bool success,
469 const string16& user_input) OVERRIDE;
470 virtual gfx::NativeWindow GetDialogRootWindow() OVERRIDE;
[email protected]a1e97f02011-06-30 14:04:34471 virtual void OnDialogShown() OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44472
[email protected]0dd3a0ab2011-02-18 08:17:44473 // Gets the zoom level for this tab.
474 double GetZoomLevel() const;
475
476 // Gets the zoom percent for this tab.
477 int GetZoomPercent(bool* enable_increment, bool* enable_decrement);
478
[email protected]0dd3a0ab2011-02-18 08:17:44479 // Opens view-source tab for this contents.
480 void ViewSource();
481
[email protected]932b7a12011-03-09 12:50:27482 void ViewFrameSource(const GURL& url,
483 const std::string& content_state);
484
[email protected]0dd3a0ab2011-02-18 08:17:44485 // Gets the minimum/maximum zoom percent.
486 int minimum_zoom_percent() const { return minimum_zoom_percent_; }
487 int maximum_zoom_percent() const { return maximum_zoom_percent_; }
488
489 int content_restrictions() const { return content_restrictions_; }
[email protected]c40d6232011-03-25 00:16:21490 void SetContentRestrictions(int restrictions);
[email protected]0dd3a0ab2011-02-18 08:17:44491
[email protected]1fd1a502011-03-30 16:55:56492 // Query the WebUIFactory for the TypeID for the current URL.
493 WebUI::TypeID GetWebUITypeForCurrentState();
494
[email protected]b375c5d2011-05-03 21:15:04495 // Returns the WebUI for the current state of the tab. This will either be
496 // the pending WebUI, the committed WebUI, or NULL.
497 WebUI* GetWebUIForCurrentState();
498
[email protected]0dd3a0ab2011-02-18 08:17:44499 protected:
[email protected]553602e12011-04-05 17:01:18500 friend class TabContentsObserver;
[email protected]553602e12011-04-05 17:01:18501
502 // Add and remove observers for page navigation notifications. Adding or
503 // removing multiple times has no effect. The order in which notifications
504 // are sent to observers is undefined. Clients must be sure to remove the
505 // observer before they go away.
506 void AddObserver(TabContentsObserver* observer);
507 void RemoveObserver(TabContentsObserver* observer);
508
[email protected]e7cfdbd2011-04-22 14:41:37509 // From RenderViewHostDelegate.
[email protected]0dd3a0ab2011-02-18 08:17:44510 virtual bool OnMessageReceived(const IPC::Message& message);
511
512 private:
513 friend class NavigationController;
514 // Used to access the child_windows_ (ConstrainedWindowList) for testing
515 // automation purposes.
516 friend class TestingAutomationProvider;
517
518 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, NoJSMessageOnInterstitials);
519 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, UpdateTitle);
520 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, CrossSiteCantPreemptAfterUnload);
[email protected]aed59602011-02-28 22:57:33521 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, ConstrainedWindows);
[email protected]0dd3a0ab2011-02-18 08:17:44522 FRIEND_TEST_ALL_PREFIXES(FormStructureBrowserTest, HTMLFiles);
523 FRIEND_TEST_ALL_PREFIXES(NavigationControllerTest, HistoryNavigate);
524 FRIEND_TEST_ALL_PREFIXES(RenderViewHostManagerTest, PageDoesBackAndReload);
525
526 // Temporary until the view/contents separation is complete.
527 friend class TabContentsView;
[email protected]9a56a0d2011-05-13 19:03:31528#if defined(TOOLKIT_VIEWS)
[email protected]7e2cef52011-04-11 21:47:23529 friend class TabContentsViewViews;
[email protected]0dd3a0ab2011-02-18 08:17:44530#elif defined(OS_MACOSX)
531 friend class TabContentsViewMac;
532#elif defined(TOOLKIT_USES_GTK)
533 friend class TabContentsViewGtk;
534#endif
535
536 // So InterstitialPage can access SetIsLoading.
537 friend class InterstitialPage;
538
539 // TODO(brettw) TestTabContents shouldn't exist!
540 friend class TestTabContents;
541
[email protected]0dd3a0ab2011-02-18 08:17:44542 // Message handlers.
543 void OnDidStartProvisionalLoadForFrame(int64 frame_id,
544 bool main_frame,
[email protected]eacb080b2011-05-22 19:40:26545 bool has_opener_set,
[email protected]0dd3a0ab2011-02-18 08:17:44546 const GURL& url);
547 void OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]eacb080b2011-05-22 19:40:26548 bool has_opener_set,
[email protected]0dd3a0ab2011-02-18 08:17:44549 const GURL& source_url,
550 const GURL& target_url);
551 void OnDidFailProvisionalLoadWithError(int64 frame_id,
552 bool main_frame,
553 int error_code,
554 const GURL& url,
555 bool showing_repost_interstitial);
556 void OnDidLoadResourceFromMemoryCache(const GURL& url,
[email protected]70435962011-08-02 20:13:28557 const std::string& security_info,
558 const std::string& http_request,
559 ResourceType::Type resource_type);
[email protected]0dd3a0ab2011-02-18 08:17:44560 void OnDidDisplayInsecureContent();
561 void OnDidRunInsecureContent(const std::string& security_origin,
562 const GURL& target_url);
563 void OnDocumentLoadedInFrame(int64 frame_id);
564 void OnDidFinishLoad(int64 frame_id);
565 void OnUpdateContentRestrictions(int restrictions);
[email protected]0dd3a0ab2011-02-18 08:17:44566 void OnGoToEntryAtOffset(int offset);
[email protected]216813952011-05-19 22:21:26567 void OnUpdateZoomLimits(int minimum_percent,
568 int maximum_percent,
569 bool remember);
570 void OnFocusedNodeChanged(bool is_editable_node);
[email protected]0dd3a0ab2011-02-18 08:17:44571
572 // Changes the IsLoading state and notifies delegate as needed
573 // |details| is used to provide details on the load that just finished
574 // (but can be null if not applicable). Can be overridden.
575 void SetIsLoading(bool is_loading,
576 LoadNotificationDetails* details);
577
[email protected]0dd3a0ab2011-02-18 08:17:44578 // Called by derived classes to indicate that we're no longer waiting for a
579 // response. This won't actually update the throbber, but it will get picked
580 // up at the next animation step if the throbber is going.
581 void SetNotWaitingForResponse() { waiting_for_response_ = false; }
582
583 ConstrainedWindowList child_windows_;
584
[email protected]0dd3a0ab2011-02-18 08:17:44585 // Navigation helpers --------------------------------------------------------
586 //
587 // These functions are helpers for Navigate() and DidNavigate().
588
589 // Handles post-navigation tasks in DidNavigate AFTER the entry has been
590 // committed to the navigation controller. Note that the navigation entry is
591 // not provided since it may be invalid/changed after being committed. The
592 // current navigation entry is in the NavigationController at this point.
593 void DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:13594 const content::LoadCommittedDetails& details,
[email protected]0dd3a0ab2011-02-18 08:17:44595 const ViewHostMsg_FrameNavigate_Params& params);
596 void DidNavigateAnyFramePostCommit(
597 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:13598 const content::LoadCommittedDetails& details,
[email protected]0dd3a0ab2011-02-18 08:17:44599 const ViewHostMsg_FrameNavigate_Params& params);
600
601 // Closes all constrained windows.
602 void CloseConstrainedWindows();
603
[email protected]0dd3a0ab2011-02-18 08:17:44604 // If our controller was restored and the page id is > than the site
605 // instance's page id, the site instances page id is updated as well as the
606 // renderers max page id.
607 void UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
608 RenderViewHost* rvh);
609
[email protected]0dd3a0ab2011-02-18 08:17:44610 // Saves the given title to the navigation entry and does associated work. It
611 // will update history and the view for the new title, and also synthesize
612 // titles for file URLs that have none (so we require that the URL of the
613 // entry already be set).
614 //
615 // This is used as the backend for state updates, which include a new title,
616 // or the dedicated set title message. It returns true if the new title is
617 // different and was therefore updated.
[email protected]acafd272011-07-26 17:35:57618 bool UpdateTitleForEntry(NavigationEntry* entry, const string16& title);
[email protected]0dd3a0ab2011-02-18 08:17:44619
620 // Causes the TabContents to navigate in the right renderer to |entry|, which
621 // must be already part of the entries in the navigation controller.
622 // This does not change the NavigationController state.
623 bool NavigateToEntry(const NavigationEntry& entry,
624 NavigationController::ReloadType reload_type);
625
[email protected]796931a92011-08-10 01:32:14626 // Sets the history for this tab_contents to |history_length| entries, and
627 // moves the current page_id to the last entry in the list if it's valid.
628 // This is mainly used when a prerendered page is swapped into the current
[email protected]9e1ad4b2011-08-14 16:49:19629 // tab. The method is virtual for testing.
630 virtual void SetHistoryLengthAndPrune(const SiteInstance* site_instance,
631 int merge_history_length,
632 int32 minimum_page_id);
[email protected]796931a92011-08-10 01:32:14633
[email protected]0dd3a0ab2011-02-18 08:17:44634 // Misc non-view stuff -------------------------------------------------------
635
636 // Helper functions for sending notifications.
637 void NotifySwapped();
638 void NotifyConnected();
639 void NotifyDisconnected();
640
[email protected]0dd3a0ab2011-02-18 08:17:44641 // RenderViewHostDelegate ----------------------------------------------------
642
643 // RenderViewHostDelegate implementation.
[email protected]544e27f2011-07-25 21:41:54644 virtual RenderViewHostDelegate::View* GetViewDelegate() OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44645 virtual RenderViewHostDelegate::RendererManagement*
[email protected]544e27f2011-07-25 21:41:54646 GetRendererManagementDelegate() OVERRIDE;
647 virtual TabContents* GetAsTabContents() OVERRIDE;
648 virtual ViewType::Type GetRenderViewType() const OVERRIDE;
649 virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE;
650 virtual void RenderViewReady(RenderViewHost* render_view_host) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44651 virtual void RenderViewGone(RenderViewHost* render_view_host,
652 base::TerminationStatus status,
[email protected]544e27f2011-07-25 21:41:54653 int error_code) OVERRIDE;
654 virtual void RenderViewDeleted(RenderViewHost* render_view_host) OVERRIDE;
655 virtual void DidNavigate(
656 RenderViewHost* render_view_host,
657 const ViewHostMsg_FrameNavigate_Params& params) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44658 virtual void UpdateState(RenderViewHost* render_view_host,
659 int32 page_id,
[email protected]544e27f2011-07-25 21:41:54660 const std::string& state) OVERRIDE;
[email protected]6b2f7a82011-04-25 19:30:51661 virtual void UpdateTitle(RenderViewHost* render_view_host,
662 int32 page_id,
[email protected]a49e10b2011-08-01 23:57:46663 const string16& title,
664 base::i18n::TextDirection title_direction) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44665 virtual void UpdateEncoding(RenderViewHost* render_view_host,
[email protected]544e27f2011-07-25 21:41:54666 const std::string& encoding) OVERRIDE;
667 virtual void UpdateTargetURL(int32 page_id, const GURL& url) OVERRIDE;
668 virtual void Close(RenderViewHost* render_view_host) OVERRIDE;
669 virtual void RequestMove(const gfx::Rect& new_bounds) OVERRIDE;
670 virtual void DidStartLoading() OVERRIDE;
671 virtual void DidStopLoading() OVERRIDE;
672 virtual void DidCancelLoading() OVERRIDE;
673 virtual void DidChangeLoadProgress(double progress) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44674 virtual void DocumentOnLoadCompletedInMainFrame(
675 RenderViewHost* render_view_host,
[email protected]544e27f2011-07-25 21:41:54676 int32 page_id) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44677 virtual void RequestOpenURL(const GURL& url, const GURL& referrer,
[email protected]544e27f2011-07-25 21:41:54678 WindowOpenDisposition disposition) OVERRIDE;
[email protected]992db4c2011-05-12 15:37:15679 virtual void RunJavaScriptMessage(const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:41680 const string16& message,
681 const string16& default_prompt,
[email protected]0dd3a0ab2011-02-18 08:17:44682 const GURL& frame_url,
683 const int flags,
684 IPC::Message* reply_msg,
[email protected]3ab9cb82011-06-03 18:02:07685 bool* did_suppress_message) OVERRIDE;
[email protected]992db4c2011-05-12 15:37:15686 virtual void RunBeforeUnloadConfirm(const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:41687 const string16& message,
[email protected]544e27f2011-07-25 21:41:54688 IPC::Message* reply_msg) OVERRIDE;
[email protected]3d7474ff2011-07-27 17:47:37689 virtual RendererPreferences GetRendererPrefs(
690 content::BrowserContext* browser_context) const OVERRIDE;
[email protected]544e27f2011-07-25 21:41:54691 virtual WebPreferences GetWebkitPrefs() OVERRIDE;
692 virtual void OnUserGesture() OVERRIDE;
693 virtual void OnIgnoredUIEvent() OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44694 virtual void RendererUnresponsive(RenderViewHost* render_view_host,
[email protected]544e27f2011-07-25 21:41:54695 bool is_during_unload) OVERRIDE;
696 virtual void RendererResponsive(RenderViewHost* render_view_host) OVERRIDE;
697 virtual void LoadStateChanged(const GURL& url,
[email protected]9c235f042011-08-10 22:28:21698 const net::LoadStateWithParam& load_state,
[email protected]544e27f2011-07-25 21:41:54699 uint64 upload_position,
700 uint64 upload_size) OVERRIDE;
701 virtual void WorkerCrashed() OVERRIDE;
702 virtual void Activate() OVERRIDE;
703 virtual void Deactivate() OVERRIDE;
704 virtual void LostCapture() OVERRIDE;
[email protected]63954792011-07-11 04:17:48705 virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
[email protected]544e27f2011-07-25 21:41:54706 bool* is_keyboard_shortcut) OVERRIDE;
707 virtual void HandleKeyboardEvent(
708 const NativeWebKeyboardEvent& event) OVERRIDE;
709 virtual void HandleMouseUp() OVERRIDE;
710 virtual void HandleMouseActivate() OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44711
712 // RenderViewHostManager::Delegate -------------------------------------------
713
714 // Blocks/unblocks interaction with renderer process.
715 void BlockTabContent(bool blocked);
716
717 virtual void BeforeUnloadFiredFromRenderManager(
718 bool proceed,
719 bool* proceed_to_fire_unload);
720 virtual void DidStartLoadingFromRenderManager(
721 RenderViewHost* render_view_host);
722 virtual void RenderViewGoneFromRenderManager(
723 RenderViewHost* render_view_host);
724 virtual void UpdateRenderViewSizeForRenderManager();
725 virtual void NotifySwappedFromRenderManager();
726 virtual NavigationController& GetControllerForRenderManager();
727 virtual WebUI* CreateWebUIForRenderManager(const GURL& url);
728 virtual NavigationEntry* GetLastCommittedNavigationEntryForRenderManager();
729
730 // Initializes the given renderer if necessary and creates the view ID
731 // corresponding to this view host. If this method is not called and the
732 // process is not shared, then the TabContents will act as though the renderer
733 // is not running (i.e., it will render "sad tab"). This method is
734 // automatically called from LoadURL.
735 //
736 // If you are attaching to an already-existing RenderView, you should call
737 // InitWithExistingID.
738 virtual bool CreateRenderViewForRenderManager(
739 RenderViewHost* render_view_host);
740
[email protected]aed59602011-02-28 22:57:33741 // Adds the given window to the list of child windows. The window will notify
742 // via WillClose() when it is being destroyed.
743 void AddConstrainedDialog(ConstrainedWindow* window);
744
[email protected]81898992011-06-14 22:15:00745 // Stores random bits of data for others to associate with this object.
746 // WARNING: this needs to be deleted after NavigationController.
747 PropertyBag property_bag_;
748
[email protected]0dd3a0ab2011-02-18 08:17:44749 // Data for core operation ---------------------------------------------------
750
751 // Delegate for notifying our owner about stuff. Not owned by us.
752 TabContentsDelegate* delegate_;
753
754 // Handles the back/forward list and loading.
755 NavigationController controller_;
756
757 // The corresponding view.
758 scoped_ptr<TabContentsView> view_;
759
760 // Helper classes ------------------------------------------------------------
761
762 // Manages creation and swapping of render views.
763 RenderViewHostManager render_manager_;
764
[email protected]c7dd2f62011-07-18 15:57:59765 // SavePackage, lazily created.
766 scoped_refptr<SavePackage> save_package_;
767
[email protected]0dd3a0ab2011-02-18 08:17:44768 // Data for loading state ----------------------------------------------------
769
770 // Indicates whether we're currently loading a resource.
771 bool is_loading_;
772
773 // Indicates if the tab is considered crashed.
774 base::TerminationStatus crashed_status_;
775 int crashed_error_code_;
776
777 // See waiting_for_response() above.
778 bool waiting_for_response_;
779
780 // Indicates the largest PageID we've seen. This field is ignored if we are
781 // a TabContents, in which case the max page ID is stored separately with
782 // each SiteInstance.
783 // TODO(brettw) this seems like it can be removed according to the comment.
784 int32 max_page_id_;
785
786 // System time at which the current load was started.
787 base::TimeTicks current_load_start_;
788
789 // The current load state and the URL associated with it.
[email protected]9c235f042011-08-10 22:28:21790 net::LoadStateWithParam load_state_;
[email protected]0dd3a0ab2011-02-18 08:17:44791 string16 load_state_host_;
792 // Upload progress, for displaying in the status bar.
793 // Set to zero when there is no significant upload happening.
794 uint64 upload_size_;
795 uint64 upload_position_;
796
797 // Data for current page -----------------------------------------------------
798
[email protected]987fc3a2011-05-26 14:18:09799 // When a title cannot be taken from any entry, this title will be used.
800 string16 page_title_when_no_navigation_entry_;
801
[email protected]0dd3a0ab2011-02-18 08:17:44802 // When a navigation occurs, we record its contents MIME type. It can be
803 // used to check whether we can do something for some special contents.
804 std::string contents_mime_type_;
805
806 // Character encoding.
807 std::string encoding_;
808
[email protected]0dd3a0ab2011-02-18 08:17:44809 // True if this is a secure page which displayed insecure content.
810 bool displayed_insecure_content_;
811
[email protected]0dd3a0ab2011-02-18 08:17:44812 // Data for misc internal state ----------------------------------------------
813
814 // See capturing_contents() above.
815 bool capturing_contents_;
816
817 // See getter above.
818 bool is_being_destroyed_;
819
820 // Indicates whether we should notify about disconnection of this
821 // TabContents. This is used to ensure disconnection notifications only
822 // happen if a connection notification has happened and that they happen only
823 // once.
824 bool notify_disconnection_;
825
[email protected]0dd3a0ab2011-02-18 08:17:44826#if defined(OS_WIN)
827 // Handle to an event that's set when the page is showing a message box (or
828 // equivalent constrained window). Plugin processes check this to know if
829 // they should pump messages then.
830 base::win::ScopedHandle message_box_active_;
831#endif
832
[email protected]0dd3a0ab2011-02-18 08:17:44833 // Set to true when there is an active "before unload" dialog. When true,
834 // we've forced the throbber to start in Navigate, and we need to remember to
835 // turn it off in OnJavaScriptMessageBoxClosed if the navigation is canceled.
836 bool is_showing_before_unload_dialog_;
837
[email protected]0dd3a0ab2011-02-18 08:17:44838 // Settings that get passed to the renderer process.
839 RendererPreferences renderer_preferences_;
840
841 // If this tab was created from a renderer using window.open, this will be
842 // non-NULL and represent the WebUI of the opening renderer.
[email protected]1fd1a502011-03-30 16:55:56843 WebUI::TypeID opener_web_ui_type_;
[email protected]0dd3a0ab2011-02-18 08:17:44844
845 // The time that we started to create the new tab page.
846 base::TimeTicks new_tab_start_time_;
847
848 // The time that we started to close the tab.
849 base::TimeTicks tab_close_start_time_;
850
851 // The time that this tab was last selected.
852 base::TimeTicks last_selected_time_;
853
[email protected]0dd3a0ab2011-02-18 08:17:44854 // See description above setter.
855 bool closed_by_user_gesture_;
856
857 // Minimum/maximum zoom percent.
858 int minimum_zoom_percent_;
859 int maximum_zoom_percent_;
860 // If true, the default zoom limits have been overriden for this tab, in which
861 // case we don't want saved settings to apply to it and we don't want to
862 // remember it.
863 bool temporary_zoom_settings_;
864
865 // A list of observers notified when page state changes. Weak references.
866 ObserverList<TabContentsObserver> observers_;
867
868 // Content restrictions, used to disable print/copy etc based on content's
869 // (full-page plugins for now only) permissions.
870 int content_restrictions_;
871
[email protected]0dd3a0ab2011-02-18 08:17:44872 DISALLOW_COPY_AND_ASSIGN(TabContents);
873};
874
875#endif // CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_H_