blob: 2d47327c99aa23029bc274bb129f6810f037d949 [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"
32
33#if defined(OS_WIN)
34#include "base/win/scoped_handle.h"
35#endif
36
37namespace gfx {
38class Rect;
39}
40
[email protected]686493142011-07-15 21:47:2241class DownloadItem;
[email protected]0dd3a0ab2011-02-18 08:17:4442class LoadNotificationDetails;
[email protected]ddb85052011-05-18 14:40:2743struct RendererPreferences;
[email protected]0dd3a0ab2011-02-18 08:17:4444class RenderViewHost;
45class SessionStorageNamespace;
46class SiteInstance;
47class SkBitmap;
[email protected]0dd3a0ab2011-02-18 08:17:4448class TabContentsDelegate;
49class TabContentsObserver;
[email protected]0dd3a0ab2011-02-18 08:17:4450class TabContentsView;
[email protected]8b0d7542011-05-16 19:36:5851struct ThumbnailScore;
[email protected]ddb85052011-05-18 14:40:2752class URLPattern;
[email protected]0dd3a0ab2011-02-18 08:17:4453struct ViewHostMsg_FrameNavigate_Params;
[email protected]0dd3a0ab2011-02-18 08:17:4454struct WebPreferences;
[email protected]ddb85052011-05-18 14:40:2755class WebUI;
[email protected]0dd3a0ab2011-02-18 08:17:4456
57// Describes what goes in the main content area of a tab. TabContents is
58// the only type of TabContents, and these should be merged together.
59class TabContents : public PageNavigator,
[email protected]0dd3a0ab2011-02-18 08:17:4460 public RenderViewHostDelegate,
61 public RenderViewHostManager::Delegate,
[email protected]6eac57a2011-07-12 21:15:0962 public content::JavaScriptDialogDelegate {
[email protected]0dd3a0ab2011-02-18 08:17:4463 public:
64 // Flags passed to the TabContentsDelegate.NavigationStateChanged to tell it
65 // what has changed. Combine them to update more than one thing.
66 enum InvalidateTypes {
67 INVALIDATE_URL = 1 << 0, // The URL has changed.
68 INVALIDATE_TAB = 1 << 1, // The favicon, app icon, or crashed
69 // state changed.
70 INVALIDATE_LOAD = 1 << 2, // The loading state has changed.
71 INVALIDATE_PAGE_ACTIONS = 1 << 3, // Page action icons have changed.
[email protected]93f230e02011-06-01 14:40:0072 INVALIDATE_TITLE = 1 << 4, // The title changed.
[email protected]0dd3a0ab2011-02-18 08:17:4473 };
74
75 // |base_tab_contents| is used if we want to size the new tab contents view
76 // based on an existing tab contents view. This can be NULL if not needed.
77 //
78 // The session storage namespace parameter allows multiple render views and
79 // tab contentses to share the same session storage (part of the WebStorage
80 // spec) space. This is useful when restoring tabs, but most callers should
81 // pass in NULL which will cause a new SessionStorageNamespace to be created.
[email protected]3d7474ff2011-07-27 17:47:3782 TabContents(content::BrowserContext* browser_context,
[email protected]0dd3a0ab2011-02-18 08:17:4483 SiteInstance* site_instance,
84 int routing_id,
85 const TabContents* base_tab_contents,
86 SessionStorageNamespace* session_storage_namespace);
87 virtual ~TabContents();
88
89 // Intrinsic tab state -------------------------------------------------------
90
91 // Returns the property bag for this tab contents, where callers can add
92 // extra data they may wish to associate with the tab. Returns a pointer
93 // rather than a reference since the PropertyAccessors expect this.
94 const PropertyBag* property_bag() const { return &property_bag_; }
95 PropertyBag* property_bag() { return &property_bag_; }
96
97 TabContentsDelegate* delegate() const { return delegate_; }
[email protected]1de2b8b2011-06-29 19:38:4698 void set_delegate(TabContentsDelegate* delegate);
[email protected]0dd3a0ab2011-02-18 08:17:4499
100 // Gets the controller for this tab contents.
101 NavigationController& controller() { return controller_; }
102 const NavigationController& controller() const { return controller_; }
103
[email protected]3d7474ff2011-07-27 17:47:37104 // Returns the user browser context associated with this TabContents (via the
[email protected]0dd3a0ab2011-02-18 08:17:44105 // NavigationController).
[email protected]3d7474ff2011-07-27 17:47:37106 content::BrowserContext* browser_context() const {
107 return controller_.browser_context();
108 }
109
[email protected]c7dd2f62011-07-18 15:57:59110 // Returns the SavePackage which manages the page saving job. May be NULL.
111 SavePackage* save_package() const { return save_package_.get(); }
112
[email protected]0dd3a0ab2011-02-18 08:17:44113 // Return the currently active RenderProcessHost and RenderViewHost. Each of
114 // these may change over time.
115 RenderProcessHost* GetRenderProcessHost() const;
116 RenderViewHost* render_view_host() const {
117 return render_manager_.current_host();
118 }
119
[email protected]93f230e02011-06-01 14:40:00120 WebUI* committed_web_ui() const {
121 return render_manager_.web_ui();
122 }
123
[email protected]0dd3a0ab2011-02-18 08:17:44124 WebUI* web_ui() const {
125 return render_manager_.web_ui() ? render_manager_.web_ui()
126 : render_manager_.pending_web_ui();
127 }
128
129 // Returns the currently active RenderWidgetHostView. This may change over
130 // time and can be NULL (during setup and teardown).
131 RenderWidgetHostView* GetRenderWidgetHostView() const {
132 return render_manager_.GetRenderWidgetHostView();
133 }
134
135 // The TabContentsView will never change and is guaranteed non-NULL.
136 TabContentsView* view() const {
137 return view_.get();
138 }
139
[email protected]0dd3a0ab2011-02-18 08:17:44140 // Tab navigation state ------------------------------------------------------
141
142 // Returns the current navigation properties, which if a navigation is
143 // pending may be provisional (e.g., the navigation could result in a
144 // download, in which case the URL would revert to what it was previously).
145 virtual const GURL& GetURL() const;
146 virtual const string16& GetTitle() const;
147
148 // The max PageID of any page that this TabContents has loaded. PageIDs
149 // increase with each new page that is loaded by a tab. If this is a
150 // TabContents, then the max PageID is kept separately on each SiteInstance.
151 // Returns -1 if no PageIDs have yet been seen.
152 int32 GetMaxPageID();
153
154 // Updates the max PageID to be at least the given PageID.
155 void UpdateMaxPageID(int32 page_id);
156
157 // Returns the site instance associated with the current page. By default,
158 // there is no site instance. TabContents overrides this to provide proper
159 // access to its site instance.
160 virtual SiteInstance* GetSiteInstance() const;
161
[email protected]77362eb2011-08-01 17:18:38162 // Returns the SiteInstance for the pending navigation, if any. Otherwise
163 // returns the current SiteInstance.
164 SiteInstance* GetPendingSiteInstance() const;
165
[email protected]0dd3a0ab2011-02-18 08:17:44166 // Defines whether this tab's URL should be displayed in the browser's URL
167 // bar. Normally this is true so you can see the URL. This is set to false
168 // for the new tab page and related pages so that the URL bar is empty and
169 // the user is invited to type into it.
170 virtual bool ShouldDisplayURL();
171
[email protected]f5d978c2011-07-21 14:43:51172 // Return whether this tab contents is loading a resource, or whether its
173 // web_ui is.
174 bool IsLoading() const;
[email protected]0dd3a0ab2011-02-18 08:17:44175
176 // Returns whether this tab contents is waiting for a first-response for the
177 // main resource of the page. This controls whether the throbber state is
178 // "waiting" or "loading."
179 bool waiting_for_response() const { return waiting_for_response_; }
180
181 net::LoadState load_state() const { return load_state_; }
182 string16 load_state_host() const { return load_state_host_; }
183 uint64 upload_size() const { return upload_size_; }
184 uint64 upload_position() const { return upload_position_; }
185
186 const std::string& encoding() const { return encoding_; }
187 void set_encoding(const std::string& encoding);
188 void reset_encoding() {
189 encoding_.clear();
190 }
191
[email protected]0dd3a0ab2011-02-18 08:17:44192 bool displayed_insecure_content() const {
193 return displayed_insecure_content_;
194 }
195
196 // Internal state ------------------------------------------------------------
197
198 // This flag indicates whether the tab contents is currently being
199 // screenshotted by the DraggedTabController.
200 bool capturing_contents() const { return capturing_contents_; }
201 void set_capturing_contents(bool cap) { capturing_contents_ = cap; }
202
203 // Indicates whether this tab should be considered crashed. The setter will
204 // also notify the delegate when the flag is changed.
205 bool is_crashed() const {
206 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
207 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
208 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
209 }
210 base::TerminationStatus crashed_status() const { return crashed_status_; }
211 int crashed_error_code() const { return crashed_error_code_; }
212 void SetIsCrashed(base::TerminationStatus status, int error_code);
213
[email protected]0dd3a0ab2011-02-18 08:17:44214 // Whether the tab is in the process of being destroyed.
215 // Added as a tentative work-around for focus related bug #4633. This allows
216 // us not to store focus when a tab is being closed.
217 bool is_being_destroyed() const { return is_being_destroyed_; }
218
219 // Convenience method for notifying the delegate of a navigation state
220 // change. See TabContentsDelegate.
221 void NotifyNavigationStateChanged(unsigned changed_flags);
222
223 // Invoked when the tab contents becomes selected. If you override, be sure
224 // and invoke super's implementation.
225 virtual void DidBecomeSelected();
226 base::TimeTicks last_selected_time() const {
227 return last_selected_time_;
228 }
229
230 // Invoked when the tab contents becomes hidden.
231 // NOTE: If you override this, call the superclass version too!
232 virtual void WasHidden();
233
[email protected]0dd3a0ab2011-02-18 08:17:44234 // TODO(brettw) document these.
235 virtual void ShowContents();
236 virtual void HideContents();
237
238 // Returns true if the before unload and unload listeners need to be
239 // fired. The value of this changes over time. For example, if true and the
240 // before unload listener is executed and allows the user to exit, then this
241 // returns false.
242 bool NeedToFireBeforeUnload();
243
244#ifdef UNIT_TEST
245 // Expose the render manager for testing.
246 RenderViewHostManager* render_manager() { return &render_manager_; }
247#endif
248
249 // In the underlying RenderViewHostManager, swaps in the provided
250 // RenderViewHost to replace the current RenderViewHost. The current RVH
251 // will be shutdown and ultimately deleted.
252 void SwapInRenderViewHost(RenderViewHost* rvh);
253
254 // Commands ------------------------------------------------------------------
255
256 // Implementation of PageNavigator.
[email protected]992e4542011-07-20 23:09:25257 virtual TabContents* OpenURL(const GURL& url,
258 const GURL& referrer,
259 WindowOpenDisposition disposition,
260 PageTransition::Type transition) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44261
262 // Called by the NavigationController to cause the TabContents to navigate to
263 // the current pending entry. The NavigationController should be called back
[email protected]9a7e68c2011-05-26 17:35:50264 // with RendererDidNavigate on success or DiscardPendingEntry on failure.
265 // The callbacks can be inside of this function, or at some future time.
[email protected]0dd3a0ab2011-02-18 08:17:44266 //
267 // The entry has a PageID of -1 if newly created (corresponding to navigation
268 // to a new URL).
269 //
270 // If this method returns false, then the navigation is discarded (equivalent
271 // to calling DiscardPendingEntry on the NavigationController).
272 virtual bool NavigateToPendingEntry(
273 NavigationController::ReloadType reload_type);
274
275 // Stop any pending navigation.
276 virtual void Stop();
277
[email protected]0dd3a0ab2011-02-18 08:17:44278 // Creates a new TabContents with the same state as this one. The returned
279 // heap-allocated pointer is owned by the caller.
280 virtual TabContents* Clone();
281
282 // Shows the page info.
283 void ShowPageInfo(const GURL& url,
284 const NavigationEntry::SSLStatus& ssl,
285 bool show_history);
286
[email protected]0dd3a0ab2011-02-18 08:17:44287 // Window management ---------------------------------------------------------
288
289 // Create a new window constrained to this TabContents' clip and visibility.
290 // The window is initialized by using the supplied delegate to obtain basic
291 // window characteristics, and the supplied view for the content. Note that
292 // the returned ConstrainedWindow might not yet be visible.
293 ConstrainedWindow* CreateConstrainedDialog(
294 ConstrainedWindowDelegate* delegate);
295
[email protected]473174942011-04-19 22:52:35296 // Adds a new tab or window with the given already-created contents.
[email protected]e7cfdbd2011-04-22 14:41:37297 void AddNewContents(TabContents* new_contents,
298 WindowOpenDisposition disposition,
299 const gfx::Rect& initial_pos,
300 bool user_gesture);
[email protected]0dd3a0ab2011-02-18 08:17:44301
302 // Returns the number of constrained windows in this tab. Used by tests.
303 size_t constrained_window_count() { return child_windows_.size(); }
304
305 typedef std::deque<ConstrainedWindow*> ConstrainedWindowList;
306
307 // Return an iterator for the first constrained window in this tab contents.
308 ConstrainedWindowList::iterator constrained_window_begin()
309 { return child_windows_.begin(); }
310
311 // Return an iterator for the last constrained window in this tab contents.
312 ConstrainedWindowList::iterator constrained_window_end()
313 { return child_windows_.end(); }
314
315 // Views and focus -----------------------------------------------------------
316 // TODO(brettw): Most of these should be removed and the caller should call
317 // the view directly.
318
319 // Returns the actual window that is focused when this TabContents is shown.
320 gfx::NativeView GetContentNativeView() const;
321
322 // Returns the NativeView associated with this TabContents. Outside of
323 // automation in the context of the UI, this is required to be implemented.
324 gfx::NativeView GetNativeView() const;
325
326 // Returns the bounds of this TabContents in the screen coordinate system.
327 void GetContainerBounds(gfx::Rect *out) const;
328
329 // Makes the tab the focused window.
330 void Focus();
331
332 // Focuses the first (last if |reverse| is true) element in the page.
333 // Invoked when this tab is getting the focus through tab traversal (|reverse|
334 // is true when using Shift-Tab).
335 void FocusThroughTabTraversal(bool reverse);
336
337 // These next two functions are declared on RenderViewHostManager::Delegate
338 // but also accessed directly by other callers.
339
340 // Returns true if the location bar should be focused by default rather than
341 // the page contents. The view calls this function when the tab is focused
342 // to see what it should do.
343 virtual bool FocusLocationBarByDefault();
344
345 // Focuses the location bar.
346 virtual void SetFocusToLocationBar(bool select_all);
347
348 // Creates a view and sets the size for the specified RVH.
349 virtual void CreateViewAndSetSizeForRVH(RenderViewHost* rvh);
350
[email protected]0dd3a0ab2011-02-18 08:17:44351 // Toolbars and such ---------------------------------------------------------
352
[email protected]686493142011-07-15 21:47:22353 // Notifies the delegate that a download is about to be started.
354 // This notification is fired before a local temporary file has been created.
355 bool CanDownload(int request_id);
356
357 // Notifies the delegate that a download started.
358 void OnStartDownload(DownloadItem* download);
359
[email protected]0dd3a0ab2011-02-18 08:17:44360 // Called when a ConstrainedWindow we own is about to be closed.
361 void WillClose(ConstrainedWindow* window);
362
[email protected]0dd3a0ab2011-02-18 08:17:44363 // Interstitials -------------------------------------------------------------
364
365 // Various other systems need to know about our interstitials.
366 bool showing_interstitial_page() const {
367 return render_manager_.interstitial_page() != NULL;
368 }
369
370 // Sets the passed passed interstitial as the currently showing interstitial.
371 // |interstitial_page| should be non NULL (use the remove_interstitial_page
372 // method to unset the interstitial) and no interstitial page should be set
373 // when there is already a non NULL interstitial page set.
374 void set_interstitial_page(InterstitialPage* interstitial_page) {
375 render_manager_.set_interstitial_page(interstitial_page);
376 }
377
378 // Unsets the currently showing interstitial.
379 void remove_interstitial_page() {
380 render_manager_.remove_interstitial_page();
381 }
382
383 // Returns the currently showing interstitial, NULL if no interstitial is
384 // showing.
385 InterstitialPage* interstitial_page() const {
386 return render_manager_.interstitial_page();
387 }
388
389 // Misc state & callbacks ----------------------------------------------------
390
[email protected]c7dd2f62011-07-18 15:57:59391 // Prepare for saving the current web page to disk.
392 void OnSavePage();
393
394 // Save page with the main HTML file path, the directory for saving resources,
395 // and the save type: HTML only or complete web page. Returns true if the
396 // saving process has been initiated successfully.
397 bool SavePage(const FilePath& main_file, const FilePath& dir_path,
398 SavePackage::SavePackageType save_type);
399
400 // Prepare for saving the URL to disk.
401 // URL may refer to the iframe on the page.
402 void OnSaveURL(const GURL& url);
403
[email protected]0dd3a0ab2011-02-18 08:17:44404 // Returns true if the active NavigationEntry's page_id equals page_id.
405 bool IsActiveEntry(int32 page_id);
406
407 const std::string& contents_mime_type() const {
408 return contents_mime_type_;
409 }
410
411 // Returns true if this TabContents will notify about disconnection.
412 bool notify_disconnection() const { return notify_disconnection_; }
413
414 // Override the encoding and reload the page by sending down
415 // ViewMsg_SetPageEncoding to the renderer. |UpdateEncoding| is kinda
416 // the opposite of this, by which 'browser' is notified of
417 // the encoding of the current tab from 'renderer' (determined by
418 // auto-detect, http header, meta, bom detection, etc).
419 void SetOverrideEncoding(const std::string& encoding);
420
421 // Remove any user-defined override encoding and reload by sending down
422 // ViewMsg_ResetPageEncodingToDefault to the renderer.
423 void ResetOverrideEncoding();
424
[email protected]0dd3a0ab2011-02-18 08:17:44425 RendererPreferences* GetMutableRendererPrefs() {
426 return &renderer_preferences_;
427 }
428
[email protected]1fd1a502011-03-30 16:55:56429 void set_opener_web_ui_type(WebUI::TypeID opener_web_ui_type) {
[email protected]0dd3a0ab2011-02-18 08:17:44430 opener_web_ui_type_ = opener_web_ui_type;
431 }
432
[email protected]0dd3a0ab2011-02-18 08:17:44433 // Set the time when we started to create the new tab page. This time is
434 // from before we created this TabContents.
435 void set_new_tab_start_time(const base::TimeTicks& time) {
436 new_tab_start_time_ = time;
437 }
[email protected]763ec4ca2011-04-29 15:48:12438 base::TimeTicks new_tab_start_time() const { return new_tab_start_time_; }
[email protected]0dd3a0ab2011-02-18 08:17:44439
440 // Notification that tab closing has started. This can be called multiple
441 // times, subsequent calls are ignored.
442 void OnCloseStarted();
443
[email protected]0dd3a0ab2011-02-18 08:17:44444 // Returns true if underlying TabContentsView should accept drag-n-drop.
445 bool ShouldAcceptDragAndDrop() const;
446
447 // A render view-originated drag has ended. Informs the render view host and
448 // tab contents delegate.
449 void SystemDragEnded();
450
451 // Indicates if this tab was explicitly closed by the user (control-w, close
452 // tab menu item...). This is false for actions that indirectly close the tab,
453 // such as closing the window. The setter is maintained by TabStripModel, and
454 // the getter only useful from within TAB_CLOSED notification
455 void set_closed_by_user_gesture(bool value) {
456 closed_by_user_gesture_ = value;
457 }
458 bool closed_by_user_gesture() const { return closed_by_user_gesture_; }
459
[email protected]3ab9cb82011-06-03 18:02:07460 // Overridden from JavaScriptDialogDelegate:
461 virtual void OnDialogClosed(IPC::Message* reply_msg,
462 bool success,
463 const string16& user_input) OVERRIDE;
464 virtual gfx::NativeWindow GetDialogRootWindow() OVERRIDE;
[email protected]a1e97f02011-06-30 14:04:34465 virtual void OnDialogShown() OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44466
[email protected]0dd3a0ab2011-02-18 08:17:44467 // Gets the zoom level for this tab.
468 double GetZoomLevel() const;
469
470 // Gets the zoom percent for this tab.
471 int GetZoomPercent(bool* enable_increment, bool* enable_decrement);
472
[email protected]0dd3a0ab2011-02-18 08:17:44473 // Opens view-source tab for this contents.
474 void ViewSource();
475
[email protected]932b7a12011-03-09 12:50:27476 void ViewFrameSource(const GURL& url,
477 const std::string& content_state);
478
[email protected]0dd3a0ab2011-02-18 08:17:44479 // Gets the minimum/maximum zoom percent.
480 int minimum_zoom_percent() const { return minimum_zoom_percent_; }
481 int maximum_zoom_percent() const { return maximum_zoom_percent_; }
482
483 int content_restrictions() const { return content_restrictions_; }
[email protected]c40d6232011-03-25 00:16:21484 void SetContentRestrictions(int restrictions);
[email protected]0dd3a0ab2011-02-18 08:17:44485
[email protected]1fd1a502011-03-30 16:55:56486 // Query the WebUIFactory for the TypeID for the current URL.
487 WebUI::TypeID GetWebUITypeForCurrentState();
488
[email protected]b375c5d2011-05-03 21:15:04489 // Returns the WebUI for the current state of the tab. This will either be
490 // the pending WebUI, the committed WebUI, or NULL.
491 WebUI* GetWebUIForCurrentState();
492
[email protected]0dd3a0ab2011-02-18 08:17:44493 protected:
[email protected]553602e12011-04-05 17:01:18494 friend class TabContentsObserver;
[email protected]553602e12011-04-05 17:01:18495
496 // Add and remove observers for page navigation notifications. Adding or
497 // removing multiple times has no effect. The order in which notifications
498 // are sent to observers is undefined. Clients must be sure to remove the
499 // observer before they go away.
500 void AddObserver(TabContentsObserver* observer);
501 void RemoveObserver(TabContentsObserver* observer);
502
[email protected]e7cfdbd2011-04-22 14:41:37503 // From RenderViewHostDelegate.
[email protected]0dd3a0ab2011-02-18 08:17:44504 virtual bool OnMessageReceived(const IPC::Message& message);
505
506 private:
507 friend class NavigationController;
508 // Used to access the child_windows_ (ConstrainedWindowList) for testing
509 // automation purposes.
510 friend class TestingAutomationProvider;
511
512 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, NoJSMessageOnInterstitials);
513 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, UpdateTitle);
514 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, CrossSiteCantPreemptAfterUnload);
[email protected]aed59602011-02-28 22:57:33515 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, ConstrainedWindows);
[email protected]0dd3a0ab2011-02-18 08:17:44516 FRIEND_TEST_ALL_PREFIXES(FormStructureBrowserTest, HTMLFiles);
517 FRIEND_TEST_ALL_PREFIXES(NavigationControllerTest, HistoryNavigate);
518 FRIEND_TEST_ALL_PREFIXES(RenderViewHostManagerTest, PageDoesBackAndReload);
519
520 // Temporary until the view/contents separation is complete.
521 friend class TabContentsView;
[email protected]9a56a0d2011-05-13 19:03:31522#if defined(TOOLKIT_VIEWS)
[email protected]7e2cef52011-04-11 21:47:23523 friend class TabContentsViewViews;
[email protected]0dd3a0ab2011-02-18 08:17:44524#elif defined(OS_MACOSX)
525 friend class TabContentsViewMac;
526#elif defined(TOOLKIT_USES_GTK)
527 friend class TabContentsViewGtk;
528#endif
529
530 // So InterstitialPage can access SetIsLoading.
531 friend class InterstitialPage;
532
533 // TODO(brettw) TestTabContents shouldn't exist!
534 friend class TestTabContents;
535
[email protected]0dd3a0ab2011-02-18 08:17:44536 // Message handlers.
537 void OnDidStartProvisionalLoadForFrame(int64 frame_id,
538 bool main_frame,
[email protected]eacb080b2011-05-22 19:40:26539 bool has_opener_set,
[email protected]0dd3a0ab2011-02-18 08:17:44540 const GURL& url);
541 void OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]eacb080b2011-05-22 19:40:26542 bool has_opener_set,
[email protected]0dd3a0ab2011-02-18 08:17:44543 const GURL& source_url,
544 const GURL& target_url);
545 void OnDidFailProvisionalLoadWithError(int64 frame_id,
546 bool main_frame,
547 int error_code,
548 const GURL& url,
549 bool showing_repost_interstitial);
550 void OnDidLoadResourceFromMemoryCache(const GURL& url,
551 const std::string& security_info);
552 void OnDidDisplayInsecureContent();
553 void OnDidRunInsecureContent(const std::string& security_origin,
554 const GURL& target_url);
555 void OnDocumentLoadedInFrame(int64 frame_id);
556 void OnDidFinishLoad(int64 frame_id);
557 void OnUpdateContentRestrictions(int restrictions);
[email protected]0dd3a0ab2011-02-18 08:17:44558 void OnGoToEntryAtOffset(int offset);
[email protected]216813952011-05-19 22:21:26559 void OnUpdateZoomLimits(int minimum_percent,
560 int maximum_percent,
561 bool remember);
562 void OnFocusedNodeChanged(bool is_editable_node);
[email protected]0dd3a0ab2011-02-18 08:17:44563
564 // Changes the IsLoading state and notifies delegate as needed
565 // |details| is used to provide details on the load that just finished
566 // (but can be null if not applicable). Can be overridden.
567 void SetIsLoading(bool is_loading,
568 LoadNotificationDetails* details);
569
[email protected]0dd3a0ab2011-02-18 08:17:44570 // Called by derived classes to indicate that we're no longer waiting for a
571 // response. This won't actually update the throbber, but it will get picked
572 // up at the next animation step if the throbber is going.
573 void SetNotWaitingForResponse() { waiting_for_response_ = false; }
574
575 ConstrainedWindowList child_windows_;
576
[email protected]0dd3a0ab2011-02-18 08:17:44577 // Navigation helpers --------------------------------------------------------
578 //
579 // These functions are helpers for Navigate() and DidNavigate().
580
581 // Handles post-navigation tasks in DidNavigate AFTER the entry has been
582 // committed to the navigation controller. Note that the navigation entry is
583 // not provided since it may be invalid/changed after being committed. The
584 // current navigation entry is in the NavigationController at this point.
585 void DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:13586 const content::LoadCommittedDetails& details,
[email protected]0dd3a0ab2011-02-18 08:17:44587 const ViewHostMsg_FrameNavigate_Params& params);
588 void DidNavigateAnyFramePostCommit(
589 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:13590 const content::LoadCommittedDetails& details,
[email protected]0dd3a0ab2011-02-18 08:17:44591 const ViewHostMsg_FrameNavigate_Params& params);
592
593 // Closes all constrained windows.
594 void CloseConstrainedWindows();
595
[email protected]0dd3a0ab2011-02-18 08:17:44596 // If our controller was restored and the page id is > than the site
597 // instance's page id, the site instances page id is updated as well as the
598 // renderers max page id.
599 void UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
600 RenderViewHost* rvh);
601
[email protected]0dd3a0ab2011-02-18 08:17:44602 // Saves the given title to the navigation entry and does associated work. It
603 // will update history and the view for the new title, and also synthesize
604 // titles for file URLs that have none (so we require that the URL of the
605 // entry already be set).
606 //
607 // This is used as the backend for state updates, which include a new title,
608 // or the dedicated set title message. It returns true if the new title is
609 // different and was therefore updated.
[email protected]acafd272011-07-26 17:35:57610 bool UpdateTitleForEntry(NavigationEntry* entry, const string16& title);
[email protected]0dd3a0ab2011-02-18 08:17:44611
612 // Causes the TabContents to navigate in the right renderer to |entry|, which
613 // must be already part of the entries in the navigation controller.
614 // This does not change the NavigationController state.
615 bool NavigateToEntry(const NavigationEntry& entry,
616 NavigationController::ReloadType reload_type);
617
618 // Misc non-view stuff -------------------------------------------------------
619
620 // Helper functions for sending notifications.
621 void NotifySwapped();
622 void NotifyConnected();
623 void NotifyDisconnected();
624
[email protected]0dd3a0ab2011-02-18 08:17:44625 // RenderViewHostDelegate ----------------------------------------------------
626
627 // RenderViewHostDelegate implementation.
[email protected]544e27f2011-07-25 21:41:54628 virtual RenderViewHostDelegate::View* GetViewDelegate() OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44629 virtual RenderViewHostDelegate::RendererManagement*
[email protected]544e27f2011-07-25 21:41:54630 GetRendererManagementDelegate() OVERRIDE;
631 virtual TabContents* GetAsTabContents() OVERRIDE;
632 virtual ViewType::Type GetRenderViewType() const OVERRIDE;
633 virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE;
634 virtual void RenderViewReady(RenderViewHost* render_view_host) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44635 virtual void RenderViewGone(RenderViewHost* render_view_host,
636 base::TerminationStatus status,
[email protected]544e27f2011-07-25 21:41:54637 int error_code) OVERRIDE;
638 virtual void RenderViewDeleted(RenderViewHost* render_view_host) OVERRIDE;
639 virtual void DidNavigate(
640 RenderViewHost* render_view_host,
641 const ViewHostMsg_FrameNavigate_Params& params) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44642 virtual void UpdateState(RenderViewHost* render_view_host,
643 int32 page_id,
[email protected]544e27f2011-07-25 21:41:54644 const std::string& state) OVERRIDE;
[email protected]6b2f7a82011-04-25 19:30:51645 virtual void UpdateTitle(RenderViewHost* render_view_host,
646 int32 page_id,
[email protected]acafd272011-07-26 17:35:57647 const string16& title) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44648 virtual void UpdateEncoding(RenderViewHost* render_view_host,
[email protected]544e27f2011-07-25 21:41:54649 const std::string& encoding) OVERRIDE;
650 virtual void UpdateTargetURL(int32 page_id, const GURL& url) OVERRIDE;
651 virtual void Close(RenderViewHost* render_view_host) OVERRIDE;
652 virtual void RequestMove(const gfx::Rect& new_bounds) OVERRIDE;
653 virtual void DidStartLoading() OVERRIDE;
654 virtual void DidStopLoading() OVERRIDE;
655 virtual void DidCancelLoading() OVERRIDE;
656 virtual void DidChangeLoadProgress(double progress) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44657 virtual void DocumentOnLoadCompletedInMainFrame(
658 RenderViewHost* render_view_host,
[email protected]544e27f2011-07-25 21:41:54659 int32 page_id) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44660 virtual void RequestOpenURL(const GURL& url, const GURL& referrer,
[email protected]544e27f2011-07-25 21:41:54661 WindowOpenDisposition disposition) OVERRIDE;
[email protected]992db4c2011-05-12 15:37:15662 virtual void RunJavaScriptMessage(const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:41663 const string16& message,
664 const string16& default_prompt,
[email protected]0dd3a0ab2011-02-18 08:17:44665 const GURL& frame_url,
666 const int flags,
667 IPC::Message* reply_msg,
[email protected]3ab9cb82011-06-03 18:02:07668 bool* did_suppress_message) OVERRIDE;
[email protected]992db4c2011-05-12 15:37:15669 virtual void RunBeforeUnloadConfirm(const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:41670 const string16& message,
[email protected]544e27f2011-07-25 21:41:54671 IPC::Message* reply_msg) OVERRIDE;
[email protected]3d7474ff2011-07-27 17:47:37672 virtual RendererPreferences GetRendererPrefs(
673 content::BrowserContext* browser_context) const OVERRIDE;
[email protected]544e27f2011-07-25 21:41:54674 virtual WebPreferences GetWebkitPrefs() OVERRIDE;
675 virtual void OnUserGesture() OVERRIDE;
676 virtual void OnIgnoredUIEvent() OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44677 virtual void RendererUnresponsive(RenderViewHost* render_view_host,
[email protected]544e27f2011-07-25 21:41:54678 bool is_during_unload) OVERRIDE;
679 virtual void RendererResponsive(RenderViewHost* render_view_host) OVERRIDE;
680 virtual void LoadStateChanged(const GURL& url,
681 net::LoadState load_state,
682 uint64 upload_position,
683 uint64 upload_size) OVERRIDE;
684 virtual void WorkerCrashed() OVERRIDE;
685 virtual void Activate() OVERRIDE;
686 virtual void Deactivate() OVERRIDE;
687 virtual void LostCapture() OVERRIDE;
[email protected]63954792011-07-11 04:17:48688 virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
[email protected]544e27f2011-07-25 21:41:54689 bool* is_keyboard_shortcut) OVERRIDE;
690 virtual void HandleKeyboardEvent(
691 const NativeWebKeyboardEvent& event) OVERRIDE;
692 virtual void HandleMouseUp() OVERRIDE;
693 virtual void HandleMouseActivate() OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44694
695 // RenderViewHostManager::Delegate -------------------------------------------
696
697 // Blocks/unblocks interaction with renderer process.
698 void BlockTabContent(bool blocked);
699
700 virtual void BeforeUnloadFiredFromRenderManager(
701 bool proceed,
702 bool* proceed_to_fire_unload);
703 virtual void DidStartLoadingFromRenderManager(
704 RenderViewHost* render_view_host);
705 virtual void RenderViewGoneFromRenderManager(
706 RenderViewHost* render_view_host);
707 virtual void UpdateRenderViewSizeForRenderManager();
708 virtual void NotifySwappedFromRenderManager();
709 virtual NavigationController& GetControllerForRenderManager();
710 virtual WebUI* CreateWebUIForRenderManager(const GURL& url);
711 virtual NavigationEntry* GetLastCommittedNavigationEntryForRenderManager();
712
713 // Initializes the given renderer if necessary and creates the view ID
714 // corresponding to this view host. If this method is not called and the
715 // process is not shared, then the TabContents will act as though the renderer
716 // is not running (i.e., it will render "sad tab"). This method is
717 // automatically called from LoadURL.
718 //
719 // If you are attaching to an already-existing RenderView, you should call
720 // InitWithExistingID.
721 virtual bool CreateRenderViewForRenderManager(
722 RenderViewHost* render_view_host);
723
[email protected]aed59602011-02-28 22:57:33724 // Adds the given window to the list of child windows. The window will notify
725 // via WillClose() when it is being destroyed.
726 void AddConstrainedDialog(ConstrainedWindow* window);
727
[email protected]81898992011-06-14 22:15:00728 // Stores random bits of data for others to associate with this object.
729 // WARNING: this needs to be deleted after NavigationController.
730 PropertyBag property_bag_;
731
[email protected]0dd3a0ab2011-02-18 08:17:44732 // Data for core operation ---------------------------------------------------
733
734 // Delegate for notifying our owner about stuff. Not owned by us.
735 TabContentsDelegate* delegate_;
736
737 // Handles the back/forward list and loading.
738 NavigationController controller_;
739
740 // The corresponding view.
741 scoped_ptr<TabContentsView> view_;
742
743 // Helper classes ------------------------------------------------------------
744
745 // Manages creation and swapping of render views.
746 RenderViewHostManager render_manager_;
747
[email protected]c7dd2f62011-07-18 15:57:59748 // SavePackage, lazily created.
749 scoped_refptr<SavePackage> save_package_;
750
[email protected]0dd3a0ab2011-02-18 08:17:44751 // Data for loading state ----------------------------------------------------
752
753 // Indicates whether we're currently loading a resource.
754 bool is_loading_;
755
756 // Indicates if the tab is considered crashed.
757 base::TerminationStatus crashed_status_;
758 int crashed_error_code_;
759
760 // See waiting_for_response() above.
761 bool waiting_for_response_;
762
763 // Indicates the largest PageID we've seen. This field is ignored if we are
764 // a TabContents, in which case the max page ID is stored separately with
765 // each SiteInstance.
766 // TODO(brettw) this seems like it can be removed according to the comment.
767 int32 max_page_id_;
768
769 // System time at which the current load was started.
770 base::TimeTicks current_load_start_;
771
772 // The current load state and the URL associated with it.
773 net::LoadState load_state_;
774 string16 load_state_host_;
775 // Upload progress, for displaying in the status bar.
776 // Set to zero when there is no significant upload happening.
777 uint64 upload_size_;
778 uint64 upload_position_;
779
780 // Data for current page -----------------------------------------------------
781
[email protected]987fc3a2011-05-26 14:18:09782 // When a title cannot be taken from any entry, this title will be used.
783 string16 page_title_when_no_navigation_entry_;
784
[email protected]0dd3a0ab2011-02-18 08:17:44785 // When a navigation occurs, we record its contents MIME type. It can be
786 // used to check whether we can do something for some special contents.
787 std::string contents_mime_type_;
788
789 // Character encoding.
790 std::string encoding_;
791
[email protected]0dd3a0ab2011-02-18 08:17:44792 // True if this is a secure page which displayed insecure content.
793 bool displayed_insecure_content_;
794
[email protected]0dd3a0ab2011-02-18 08:17:44795 // Data for misc internal state ----------------------------------------------
796
797 // See capturing_contents() above.
798 bool capturing_contents_;
799
800 // See getter above.
801 bool is_being_destroyed_;
802
803 // Indicates whether we should notify about disconnection of this
804 // TabContents. This is used to ensure disconnection notifications only
805 // happen if a connection notification has happened and that they happen only
806 // once.
807 bool notify_disconnection_;
808
[email protected]0dd3a0ab2011-02-18 08:17:44809#if defined(OS_WIN)
810 // Handle to an event that's set when the page is showing a message box (or
811 // equivalent constrained window). Plugin processes check this to know if
812 // they should pump messages then.
813 base::win::ScopedHandle message_box_active_;
814#endif
815
[email protected]0dd3a0ab2011-02-18 08:17:44816 // Set to true when there is an active "before unload" dialog. When true,
817 // we've forced the throbber to start in Navigate, and we need to remember to
818 // turn it off in OnJavaScriptMessageBoxClosed if the navigation is canceled.
819 bool is_showing_before_unload_dialog_;
820
[email protected]0dd3a0ab2011-02-18 08:17:44821 // Settings that get passed to the renderer process.
822 RendererPreferences renderer_preferences_;
823
824 // If this tab was created from a renderer using window.open, this will be
825 // non-NULL and represent the WebUI of the opening renderer.
[email protected]1fd1a502011-03-30 16:55:56826 WebUI::TypeID opener_web_ui_type_;
[email protected]0dd3a0ab2011-02-18 08:17:44827
828 // The time that we started to create the new tab page.
829 base::TimeTicks new_tab_start_time_;
830
831 // The time that we started to close the tab.
832 base::TimeTicks tab_close_start_time_;
833
834 // The time that this tab was last selected.
835 base::TimeTicks last_selected_time_;
836
[email protected]0dd3a0ab2011-02-18 08:17:44837 // See description above setter.
838 bool closed_by_user_gesture_;
839
840 // Minimum/maximum zoom percent.
841 int minimum_zoom_percent_;
842 int maximum_zoom_percent_;
843 // If true, the default zoom limits have been overriden for this tab, in which
844 // case we don't want saved settings to apply to it and we don't want to
845 // remember it.
846 bool temporary_zoom_settings_;
847
848 // A list of observers notified when page state changes. Weak references.
849 ObserverList<TabContentsObserver> observers_;
850
851 // Content restrictions, used to disable print/copy etc based on content's
852 // (full-page plugins for now only) permissions.
853 int content_restrictions_;
854
[email protected]0dd3a0ab2011-02-18 08:17:44855 DISALLOW_COPY_AND_ASSIGN(TabContents);
856};
857
858#endif // CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_H_