blob: be49b117fb844bf9a66571608cede5b7268864a8 [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]483623eb2011-10-25 09:30:0020#include "content/browser/renderer_host/java_bridge_dispatcher_host_manager.h"
[email protected]5de634712011-03-02 00:20:1921#include "content/browser/renderer_host/render_view_host_delegate.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]8d128d62011-09-13 22:11:5728#include "content/common/content_export.h"
[email protected]15a5fa52011-03-10 20:16:0429#include "content/common/property_bag.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.
90 const PropertyBag* property_bag() const { return &property_bag_; }
91 PropertyBag* property_bag() { return &property_bag_; }
92
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]c7dd2f62011-07-18 15:57:59106 // Returns the SavePackage which manages the page saving job. May be NULL.
107 SavePackage* save_package() const { return save_package_.get(); }
108
[email protected]0dd3a0ab2011-02-18 08:17:44109 // Return the currently active RenderProcessHost and RenderViewHost. Each of
110 // these may change over time.
111 RenderProcessHost* GetRenderProcessHost() const;
112 RenderViewHost* render_view_host() const {
113 return render_manager_.current_host();
114 }
115
[email protected]93f230e02011-06-01 14:40:00116 WebUI* committed_web_ui() const {
117 return render_manager_.web_ui();
118 }
119
[email protected]6e5a00a2011-10-13 17:47:16120 // Returns the committed WebUI if one exists, otherwise the pending one.
121 // Callers who want to use the pending WebUI for the pending navigation entry
122 // should use GetWebUIForCurrentState instead.
[email protected]0dd3a0ab2011-02-18 08:17:44123 WebUI* web_ui() const {
124 return render_manager_.web_ui() ? render_manager_.web_ui()
125 : render_manager_.pending_web_ui();
126 }
127
128 // Returns the currently active RenderWidgetHostView. This may change over
129 // time and can be NULL (during setup and teardown).
130 RenderWidgetHostView* GetRenderWidgetHostView() const {
131 return render_manager_.GetRenderWidgetHostView();
132 }
133
134 // The TabContentsView will never change and is guaranteed non-NULL.
135 TabContentsView* view() const {
136 return view_.get();
137 }
138
[email protected]0dd3a0ab2011-02-18 08:17:44139 // Tab navigation state ------------------------------------------------------
140
141 // Returns the current navigation properties, which if a navigation is
142 // pending may be provisional (e.g., the navigation could result in a
143 // download, in which case the URL would revert to what it was previously).
144 virtual const GURL& GetURL() const;
145 virtual const string16& GetTitle() const;
146
147 // The max PageID of any page that this TabContents has loaded. PageIDs
148 // increase with each new page that is loaded by a tab. If this is a
149 // TabContents, then the max PageID is kept separately on each SiteInstance.
150 // Returns -1 if no PageIDs have yet been seen.
151 int32 GetMaxPageID();
152
153 // Updates the max PageID to be at least the given PageID.
154 void UpdateMaxPageID(int32 page_id);
155
156 // Returns the site instance associated with the current page. By default,
157 // there is no site instance. TabContents overrides this to provide proper
158 // access to its site instance.
159 virtual SiteInstance* GetSiteInstance() const;
160
[email protected]77362eb2011-08-01 17:18:38161 // Returns the SiteInstance for the pending navigation, if any. Otherwise
162 // returns the current SiteInstance.
163 SiteInstance* GetPendingSiteInstance() const;
164
[email protected]f5d978c2011-07-21 14:43:51165 // Return whether this tab contents is loading a resource, or whether its
166 // web_ui is.
167 bool IsLoading() const;
[email protected]0dd3a0ab2011-02-18 08:17:44168
169 // Returns whether this tab contents is waiting for a first-response for the
170 // main resource of the page. This controls whether the throbber state is
171 // "waiting" or "loading."
172 bool waiting_for_response() const { return waiting_for_response_; }
173
[email protected]9c235f042011-08-10 22:28:21174 const net::LoadStateWithParam& load_state() const { return load_state_; }
175 const string16& load_state_host() const { return load_state_host_; }
[email protected]0dd3a0ab2011-02-18 08:17:44176 uint64 upload_size() const { return upload_size_; }
177 uint64 upload_position() const { return upload_position_; }
178
179 const std::string& encoding() const { return encoding_; }
180 void set_encoding(const std::string& encoding);
181 void reset_encoding() {
182 encoding_.clear();
183 }
184
[email protected]0dd3a0ab2011-02-18 08:17:44185 bool displayed_insecure_content() const {
186 return displayed_insecure_content_;
187 }
188
189 // Internal state ------------------------------------------------------------
190
191 // This flag indicates whether the tab contents is currently being
192 // screenshotted by the DraggedTabController.
193 bool capturing_contents() const { return capturing_contents_; }
194 void set_capturing_contents(bool cap) { capturing_contents_ = cap; }
195
196 // Indicates whether this tab should be considered crashed. The setter will
197 // also notify the delegate when the flag is changed.
198 bool is_crashed() const {
199 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
200 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
201 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
202 }
203 base::TerminationStatus crashed_status() const { return crashed_status_; }
204 int crashed_error_code() const { return crashed_error_code_; }
205 void SetIsCrashed(base::TerminationStatus status, int error_code);
206
[email protected]0dd3a0ab2011-02-18 08:17:44207 // Whether the tab is in the process of being destroyed.
208 // Added as a tentative work-around for focus related bug #4633. This allows
209 // us not to store focus when a tab is being closed.
210 bool is_being_destroyed() const { return is_being_destroyed_; }
211
212 // Convenience method for notifying the delegate of a navigation state
213 // change. See TabContentsDelegate.
214 void NotifyNavigationStateChanged(unsigned changed_flags);
215
216 // Invoked when the tab contents becomes selected. If you override, be sure
217 // and invoke super's implementation.
218 virtual void DidBecomeSelected();
219 base::TimeTicks last_selected_time() const {
220 return last_selected_time_;
221 }
222
223 // Invoked when the tab contents becomes hidden.
224 // NOTE: If you override this, call the superclass version too!
225 virtual void WasHidden();
226
[email protected]0dd3a0ab2011-02-18 08:17:44227 // TODO(brettw) document these.
228 virtual void ShowContents();
229 virtual void HideContents();
230
231 // Returns true if the before unload and unload listeners need to be
232 // fired. The value of this changes over time. For example, if true and the
233 // before unload listener is executed and allows the user to exit, then this
234 // returns false.
235 bool NeedToFireBeforeUnload();
236
[email protected]0dd3a0ab2011-02-18 08:17:44237 // Expose the render manager for testing.
[email protected]03ff5e52011-09-30 00:28:14238 RenderViewHostManager* render_manager_for_testing() {
239 return &render_manager_;
240 }
[email protected]0dd3a0ab2011-02-18 08:17:44241
[email protected]0dd3a0ab2011-02-18 08:17:44242 // Commands ------------------------------------------------------------------
243
244 // Implementation of PageNavigator.
[email protected]00c37fc2011-08-02 00:22:50245
246 // Deprecated. Please use the one-argument variant instead.
247 // TODO(adriansc): Remove this method once refactoring changed all call sites.
[email protected]992e4542011-07-20 23:09:25248 virtual TabContents* OpenURL(const GURL& url,
249 const GURL& referrer,
250 WindowOpenDisposition disposition,
[email protected]2905f742011-10-13 03:51:58251 content::PageTransition transition) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44252
[email protected]00c37fc2011-08-02 00:22:50253 virtual TabContents* OpenURL(const OpenURLParams& params) OVERRIDE;
254
[email protected]0dd3a0ab2011-02-18 08:17:44255 // Called by the NavigationController to cause the TabContents to navigate to
256 // the current pending entry. The NavigationController should be called back
[email protected]9a7e68c2011-05-26 17:35:50257 // with RendererDidNavigate on success or DiscardPendingEntry on failure.
258 // The callbacks can be inside of this function, or at some future time.
[email protected]0dd3a0ab2011-02-18 08:17:44259 //
260 // The entry has a PageID of -1 if newly created (corresponding to navigation
261 // to a new URL).
262 //
263 // If this method returns false, then the navigation is discarded (equivalent
264 // to calling DiscardPendingEntry on the NavigationController).
265 virtual bool NavigateToPendingEntry(
266 NavigationController::ReloadType reload_type);
267
268 // Stop any pending navigation.
269 virtual void Stop();
270
[email protected]0dd3a0ab2011-02-18 08:17:44271 // Creates a new TabContents with the same state as this one. The returned
272 // heap-allocated pointer is owned by the caller.
273 virtual TabContents* Clone();
274
275 // Shows the page info.
276 void ShowPageInfo(const GURL& url,
277 const NavigationEntry::SSLStatus& ssl,
278 bool show_history);
279
[email protected]0dd3a0ab2011-02-18 08:17:44280 // Window management ---------------------------------------------------------
281
[email protected]473174942011-04-19 22:52:35282 // Adds a new tab or window with the given already-created contents.
[email protected]e7cfdbd2011-04-22 14:41:37283 void AddNewContents(TabContents* new_contents,
284 WindowOpenDisposition disposition,
285 const gfx::Rect& initial_pos,
286 bool user_gesture);
[email protected]0dd3a0ab2011-02-18 08:17:44287
[email protected]0dd3a0ab2011-02-18 08:17:44288 // Views and focus -----------------------------------------------------------
289 // TODO(brettw): Most of these should be removed and the caller should call
290 // the view directly.
291
292 // Returns the actual window that is focused when this TabContents is shown.
293 gfx::NativeView GetContentNativeView() const;
294
295 // Returns the NativeView associated with this TabContents. Outside of
296 // automation in the context of the UI, this is required to be implemented.
297 gfx::NativeView GetNativeView() const;
298
299 // Returns the bounds of this TabContents in the screen coordinate system.
300 void GetContainerBounds(gfx::Rect *out) const;
301
302 // Makes the tab the focused window.
303 void Focus();
304
305 // Focuses the first (last if |reverse| is true) element in the page.
306 // Invoked when this tab is getting the focus through tab traversal (|reverse|
307 // is true when using Shift-Tab).
308 void FocusThroughTabTraversal(bool reverse);
309
310 // These next two functions are declared on RenderViewHostManager::Delegate
311 // but also accessed directly by other callers.
312
313 // Returns true if the location bar should be focused by default rather than
314 // the page contents. The view calls this function when the tab is focused
315 // to see what it should do.
316 virtual bool FocusLocationBarByDefault();
317
318 // Focuses the location bar.
319 virtual void SetFocusToLocationBar(bool select_all);
320
321 // Creates a view and sets the size for the specified RVH.
322 virtual void CreateViewAndSetSizeForRVH(RenderViewHost* rvh);
323
[email protected]0dd3a0ab2011-02-18 08:17:44324 // Toolbars and such ---------------------------------------------------------
325
[email protected]686493142011-07-15 21:47:22326 // Notifies the delegate that a download is about to be started.
327 // This notification is fired before a local temporary file has been created.
328 bool CanDownload(int request_id);
329
330 // Notifies the delegate that a download started.
331 void OnStartDownload(DownloadItem* download);
332
[email protected]0dd3a0ab2011-02-18 08:17:44333 // Interstitials -------------------------------------------------------------
334
335 // Various other systems need to know about our interstitials.
336 bool showing_interstitial_page() const {
337 return render_manager_.interstitial_page() != NULL;
338 }
339
340 // Sets the passed passed interstitial as the currently showing interstitial.
341 // |interstitial_page| should be non NULL (use the remove_interstitial_page
342 // method to unset the interstitial) and no interstitial page should be set
343 // when there is already a non NULL interstitial page set.
344 void set_interstitial_page(InterstitialPage* interstitial_page) {
345 render_manager_.set_interstitial_page(interstitial_page);
346 }
347
348 // Unsets the currently showing interstitial.
349 void remove_interstitial_page() {
350 render_manager_.remove_interstitial_page();
351 }
352
353 // Returns the currently showing interstitial, NULL if no interstitial is
354 // showing.
355 InterstitialPage* interstitial_page() const {
356 return render_manager_.interstitial_page();
357 }
358
359 // Misc state & callbacks ----------------------------------------------------
360
[email protected]c7dd2f62011-07-18 15:57:59361 // Prepare for saving the current web page to disk.
362 void OnSavePage();
363
364 // Save page with the main HTML file path, the directory for saving resources,
365 // and the save type: HTML only or complete web page. Returns true if the
366 // saving process has been initiated successfully.
367 bool SavePage(const FilePath& main_file, const FilePath& dir_path,
368 SavePackage::SavePackageType save_type);
369
370 // Prepare for saving the URL to disk.
371 // URL may refer to the iframe on the page.
372 void OnSaveURL(const GURL& url);
373
[email protected]0dd3a0ab2011-02-18 08:17:44374 // Returns true if the active NavigationEntry's page_id equals page_id.
375 bool IsActiveEntry(int32 page_id);
376
377 const std::string& contents_mime_type() const {
378 return contents_mime_type_;
379 }
380
381 // Returns true if this TabContents will notify about disconnection.
382 bool notify_disconnection() const { return notify_disconnection_; }
383
384 // Override the encoding and reload the page by sending down
385 // ViewMsg_SetPageEncoding to the renderer. |UpdateEncoding| is kinda
386 // the opposite of this, by which 'browser' is notified of
387 // the encoding of the current tab from 'renderer' (determined by
388 // auto-detect, http header, meta, bom detection, etc).
389 void SetOverrideEncoding(const std::string& encoding);
390
391 // Remove any user-defined override encoding and reload by sending down
392 // ViewMsg_ResetPageEncodingToDefault to the renderer.
393 void ResetOverrideEncoding();
394
[email protected]daf82f82011-10-31 22:35:31395 content::RendererPreferences* GetMutableRendererPrefs() {
[email protected]0dd3a0ab2011-02-18 08:17:44396 return &renderer_preferences_;
397 }
398
[email protected]1fd1a502011-03-30 16:55:56399 void set_opener_web_ui_type(WebUI::TypeID opener_web_ui_type) {
[email protected]0dd3a0ab2011-02-18 08:17:44400 opener_web_ui_type_ = opener_web_ui_type;
401 }
402
[email protected]0dd3a0ab2011-02-18 08:17:44403 // Set the time when we started to create the new tab page. This time is
404 // from before we created this TabContents.
405 void set_new_tab_start_time(const base::TimeTicks& time) {
406 new_tab_start_time_ = time;
407 }
[email protected]763ec4ca2011-04-29 15:48:12408 base::TimeTicks new_tab_start_time() const { return new_tab_start_time_; }
[email protected]0dd3a0ab2011-02-18 08:17:44409
410 // Notification that tab closing has started. This can be called multiple
411 // times, subsequent calls are ignored.
412 void OnCloseStarted();
413
[email protected]0dd3a0ab2011-02-18 08:17:44414 // Returns true if underlying TabContentsView should accept drag-n-drop.
415 bool ShouldAcceptDragAndDrop() const;
416
417 // A render view-originated drag has ended. Informs the render view host and
418 // tab contents delegate.
419 void SystemDragEnded();
420
421 // Indicates if this tab was explicitly closed by the user (control-w, close
422 // tab menu item...). This is false for actions that indirectly close the tab,
423 // such as closing the window. The setter is maintained by TabStripModel, and
424 // the getter only useful from within TAB_CLOSED notification
425 void set_closed_by_user_gesture(bool value) {
426 closed_by_user_gesture_ = value;
427 }
428 bool closed_by_user_gesture() const { return closed_by_user_gesture_; }
429
[email protected]3ab9cb82011-06-03 18:02:07430 // Overridden from JavaScriptDialogDelegate:
431 virtual void OnDialogClosed(IPC::Message* reply_msg,
432 bool success,
433 const string16& user_input) OVERRIDE;
434 virtual gfx::NativeWindow GetDialogRootWindow() OVERRIDE;
[email protected]a1e97f02011-06-30 14:04:34435 virtual void OnDialogShown() OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44436
[email protected]0dd3a0ab2011-02-18 08:17:44437 // Gets the zoom level for this tab.
438 double GetZoomLevel() const;
439
440 // Gets the zoom percent for this tab.
441 int GetZoomPercent(bool* enable_increment, bool* enable_decrement);
442
[email protected]0dd3a0ab2011-02-18 08:17:44443 // Opens view-source tab for this contents.
444 void ViewSource();
445
[email protected]932b7a12011-03-09 12:50:27446 void ViewFrameSource(const GURL& url,
447 const std::string& content_state);
448
[email protected]0dd3a0ab2011-02-18 08:17:44449 // Gets the minimum/maximum zoom percent.
450 int minimum_zoom_percent() const { return minimum_zoom_percent_; }
451 int maximum_zoom_percent() const { return maximum_zoom_percent_; }
452
453 int content_restrictions() const { return content_restrictions_; }
[email protected]c40d6232011-03-25 00:16:21454 void SetContentRestrictions(int restrictions);
[email protected]0dd3a0ab2011-02-18 08:17:44455
[email protected]1fd1a502011-03-30 16:55:56456 // Query the WebUIFactory for the TypeID for the current URL.
457 WebUI::TypeID GetWebUITypeForCurrentState();
458
[email protected]b375c5d2011-05-03 21:15:04459 // Returns the WebUI for the current state of the tab. This will either be
460 // the pending WebUI, the committed WebUI, or NULL.
461 WebUI* GetWebUIForCurrentState();
462
[email protected]e9621112011-10-17 05:38:37463 // Called when the reponse to a pending mouse lock request has arrived.
464 // Returns true if |allowed| is true and the mouse has been successfully
465 // locked.
466 bool GotResponseToLockMouseRequest(bool allowed);
467
[email protected]0dd3a0ab2011-02-18 08:17:44468 protected:
[email protected]553602e12011-04-05 17:01:18469 friend class TabContentsObserver;
[email protected]553602e12011-04-05 17:01:18470
471 // Add and remove observers for page navigation notifications. Adding or
472 // removing multiple times has no effect. The order in which notifications
473 // are sent to observers is undefined. Clients must be sure to remove the
474 // observer before they go away.
475 void AddObserver(TabContentsObserver* observer);
476 void RemoveObserver(TabContentsObserver* observer);
477
[email protected]0dd3a0ab2011-02-18 08:17:44478 private:
479 friend class NavigationController;
[email protected]0dd3a0ab2011-02-18 08:17:44480
481 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, NoJSMessageOnInterstitials);
482 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, UpdateTitle);
483 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, CrossSiteCantPreemptAfterUnload);
484 FRIEND_TEST_ALL_PREFIXES(FormStructureBrowserTest, HTMLFiles);
485 FRIEND_TEST_ALL_PREFIXES(NavigationControllerTest, HistoryNavigate);
486 FRIEND_TEST_ALL_PREFIXES(RenderViewHostManagerTest, PageDoesBackAndReload);
487
488 // Temporary until the view/contents separation is complete.
489 friend class TabContentsView;
[email protected]9a56a0d2011-05-13 19:03:31490#if defined(TOOLKIT_VIEWS)
[email protected]7e2cef52011-04-11 21:47:23491 friend class TabContentsViewViews;
[email protected]0dd3a0ab2011-02-18 08:17:44492#elif defined(OS_MACOSX)
493 friend class TabContentsViewMac;
494#elif defined(TOOLKIT_USES_GTK)
495 friend class TabContentsViewGtk;
496#endif
497
498 // So InterstitialPage can access SetIsLoading.
499 friend class InterstitialPage;
500
501 // TODO(brettw) TestTabContents shouldn't exist!
502 friend class TestTabContents;
503
[email protected]0dd3a0ab2011-02-18 08:17:44504 // Message handlers.
505 void OnDidStartProvisionalLoadForFrame(int64 frame_id,
506 bool main_frame,
[email protected]57b9396c2011-10-07 19:11:59507 const GURL& opener_url,
[email protected]0dd3a0ab2011-02-18 08:17:44508 const GURL& url);
509 void OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]57b9396c2011-10-07 19:11:59510 const GURL& opener_url,
[email protected]0dd3a0ab2011-02-18 08:17:44511 const GURL& source_url,
512 const GURL& target_url);
[email protected]d7b175e2011-10-11 15:31:58513 void OnDidFailProvisionalLoadWithError(
514 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params);
[email protected]0dd3a0ab2011-02-18 08:17:44515 void OnDidLoadResourceFromMemoryCache(const GURL& url,
[email protected]70435962011-08-02 20:13:28516 const std::string& security_info,
517 const std::string& http_request,
518 ResourceType::Type resource_type);
[email protected]0dd3a0ab2011-02-18 08:17:44519 void OnDidDisplayInsecureContent();
520 void OnDidRunInsecureContent(const std::string& security_origin,
521 const GURL& target_url);
522 void OnDocumentLoadedInFrame(int64 frame_id);
523 void OnDidFinishLoad(int64 frame_id);
524 void OnUpdateContentRestrictions(int restrictions);
[email protected]0dd3a0ab2011-02-18 08:17:44525 void OnGoToEntryAtOffset(int offset);
[email protected]216813952011-05-19 22:21:26526 void OnUpdateZoomLimits(int minimum_percent,
527 int maximum_percent,
528 bool remember);
529 void OnFocusedNodeChanged(bool is_editable_node);
[email protected]3a29a6e2011-08-24 18:26:21530 void OnEnumerateDirectory(int request_id, const FilePath& path);
[email protected]7d189022011-08-25 22:54:20531 void OnJSOutOfMemory();
532 void OnRegisterProtocolHandler(const std::string& protocol,
533 const GURL& url,
534 const string16& title);
535 void OnRegisterIntentHandler(const string16& action,
536 const string16& type,
537 const string16& href,
538 const string16& title);
539 void OnWebIntentDispatch(const IPC::Message& message,
[email protected]ce9751942011-09-21 01:57:24540 const webkit_glue::WebIntentData& intent,
[email protected]7d189022011-08-25 22:54:20541 int intent_id);
[email protected]b888919c2011-09-02 00:32:16542 void OnFindReply(int request_id, int number_of_matches,
543 const gfx::Rect& selection_rect, int active_match_ordinal,
544 bool final_update);
[email protected]d952a052011-09-06 18:42:45545 void OnCrashedPlugin(const FilePath& plugin_path);
[email protected]7fc4bbb2011-09-08 21:23:10546 void OnAppCacheAccessed(const GURL& manifest_url, bool blocked_by_policy);
[email protected]0dd3a0ab2011-02-18 08:17:44547
548 // Changes the IsLoading state and notifies delegate as needed
549 // |details| is used to provide details on the load that just finished
550 // (but can be null if not applicable). Can be overridden.
551 void SetIsLoading(bool is_loading,
552 LoadNotificationDetails* details);
553
[email protected]0dd3a0ab2011-02-18 08:17:44554 // Called by derived classes to indicate that we're no longer waiting for a
555 // response. This won't actually update the throbber, but it will get picked
556 // up at the next animation step if the throbber is going.
557 void SetNotWaitingForResponse() { waiting_for_response_ = false; }
558
[email protected]0dd3a0ab2011-02-18 08:17:44559 // Navigation helpers --------------------------------------------------------
560 //
561 // These functions are helpers for Navigate() and DidNavigate().
562
563 // Handles post-navigation tasks in DidNavigate AFTER the entry has been
564 // committed to the navigation controller. Note that the navigation entry is
565 // not provided since it may be invalid/changed after being committed. The
566 // current navigation entry is in the NavigationController at this point.
567 void DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:13568 const content::LoadCommittedDetails& details,
[email protected]0dd3a0ab2011-02-18 08:17:44569 const ViewHostMsg_FrameNavigate_Params& params);
570 void DidNavigateAnyFramePostCommit(
571 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:13572 const content::LoadCommittedDetails& details,
[email protected]0dd3a0ab2011-02-18 08:17:44573 const ViewHostMsg_FrameNavigate_Params& params);
574
[email protected]0dd3a0ab2011-02-18 08:17:44575 // If our controller was restored and the page id is > than the site
576 // instance's page id, the site instances page id is updated as well as the
577 // renderers max page id.
578 void UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
579 RenderViewHost* rvh);
580
[email protected]0dd3a0ab2011-02-18 08:17:44581 // Saves the given title to the navigation entry and does associated work. It
582 // will update history and the view for the new title, and also synthesize
583 // titles for file URLs that have none (so we require that the URL of the
584 // entry already be set).
585 //
586 // This is used as the backend for state updates, which include a new title,
587 // or the dedicated set title message. It returns true if the new title is
588 // different and was therefore updated.
[email protected]acafd272011-07-26 17:35:57589 bool UpdateTitleForEntry(NavigationEntry* entry, const string16& title);
[email protected]0dd3a0ab2011-02-18 08:17:44590
591 // Causes the TabContents to navigate in the right renderer to |entry|, which
592 // must be already part of the entries in the navigation controller.
593 // This does not change the NavigationController state.
594 bool NavigateToEntry(const NavigationEntry& entry,
595 NavigationController::ReloadType reload_type);
596
[email protected]796931a92011-08-10 01:32:14597 // Sets the history for this tab_contents to |history_length| entries, and
598 // moves the current page_id to the last entry in the list if it's valid.
599 // This is mainly used when a prerendered page is swapped into the current
[email protected]9e1ad4b2011-08-14 16:49:19600 // tab. The method is virtual for testing.
601 virtual void SetHistoryLengthAndPrune(const SiteInstance* site_instance,
602 int merge_history_length,
603 int32 minimum_page_id);
[email protected]796931a92011-08-10 01:32:14604
[email protected]0dd3a0ab2011-02-18 08:17:44605 // Misc non-view stuff -------------------------------------------------------
606
607 // Helper functions for sending notifications.
608 void NotifySwapped();
609 void NotifyConnected();
610 void NotifyDisconnected();
611
[email protected]0dd3a0ab2011-02-18 08:17:44612 // RenderViewHostDelegate ----------------------------------------------------
613
614 // RenderViewHostDelegate implementation.
[email protected]544e27f2011-07-25 21:41:54615 virtual RenderViewHostDelegate::View* GetViewDelegate() OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44616 virtual RenderViewHostDelegate::RendererManagement*
[email protected]544e27f2011-07-25 21:41:54617 GetRendererManagementDelegate() OVERRIDE;
618 virtual TabContents* GetAsTabContents() OVERRIDE;
[email protected]da4dfc42011-10-12 15:53:56619 virtual content::ViewType GetRenderViewType() const OVERRIDE;
[email protected]544e27f2011-07-25 21:41:54620 virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE;
621 virtual void RenderViewReady(RenderViewHost* render_view_host) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44622 virtual void RenderViewGone(RenderViewHost* render_view_host,
623 base::TerminationStatus status,
[email protected]544e27f2011-07-25 21:41:54624 int error_code) OVERRIDE;
625 virtual void RenderViewDeleted(RenderViewHost* render_view_host) OVERRIDE;
626 virtual void DidNavigate(
627 RenderViewHost* render_view_host,
628 const ViewHostMsg_FrameNavigate_Params& params) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44629 virtual void UpdateState(RenderViewHost* render_view_host,
630 int32 page_id,
[email protected]544e27f2011-07-25 21:41:54631 const std::string& state) OVERRIDE;
[email protected]6b2f7a82011-04-25 19:30:51632 virtual void UpdateTitle(RenderViewHost* render_view_host,
633 int32 page_id,
[email protected]a49e10b2011-08-01 23:57:46634 const string16& title,
635 base::i18n::TextDirection title_direction) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44636 virtual void UpdateEncoding(RenderViewHost* render_view_host,
[email protected]544e27f2011-07-25 21:41:54637 const std::string& encoding) OVERRIDE;
638 virtual void UpdateTargetURL(int32 page_id, const GURL& url) OVERRIDE;
639 virtual void Close(RenderViewHost* render_view_host) OVERRIDE;
640 virtual void RequestMove(const gfx::Rect& new_bounds) OVERRIDE;
641 virtual void DidStartLoading() OVERRIDE;
642 virtual void DidStopLoading() OVERRIDE;
643 virtual void DidCancelLoading() OVERRIDE;
644 virtual void DidChangeLoadProgress(double progress) OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44645 virtual void DocumentOnLoadCompletedInMainFrame(
646 RenderViewHost* render_view_host,
[email protected]544e27f2011-07-25 21:41:54647 int32 page_id) OVERRIDE;
[email protected]ae5184d62011-10-06 19:25:58648 virtual void RequestOpenURL(const GURL& url,
649 const GURL& referrer,
650 WindowOpenDisposition disposition,
651 int64 source_frame_id) OVERRIDE;
[email protected]992db4c2011-05-12 15:37:15652 virtual void RunJavaScriptMessage(const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:41653 const string16& message,
654 const string16& default_prompt,
[email protected]0dd3a0ab2011-02-18 08:17:44655 const GURL& frame_url,
656 const int flags,
657 IPC::Message* reply_msg,
[email protected]3ab9cb82011-06-03 18:02:07658 bool* did_suppress_message) OVERRIDE;
[email protected]992db4c2011-05-12 15:37:15659 virtual void RunBeforeUnloadConfirm(const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:41660 const string16& message,
[email protected]544e27f2011-07-25 21:41:54661 IPC::Message* reply_msg) OVERRIDE;
[email protected]daf82f82011-10-31 22:35:31662 virtual content::RendererPreferences GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:37663 content::BrowserContext* browser_context) const OVERRIDE;
[email protected]544e27f2011-07-25 21:41:54664 virtual WebPreferences GetWebkitPrefs() OVERRIDE;
665 virtual void OnUserGesture() OVERRIDE;
666 virtual void OnIgnoredUIEvent() OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44667 virtual void RendererUnresponsive(RenderViewHost* render_view_host,
[email protected]544e27f2011-07-25 21:41:54668 bool is_during_unload) OVERRIDE;
669 virtual void RendererResponsive(RenderViewHost* render_view_host) OVERRIDE;
670 virtual void LoadStateChanged(const GURL& url,
[email protected]9c235f042011-08-10 22:28:21671 const net::LoadStateWithParam& load_state,
[email protected]544e27f2011-07-25 21:41:54672 uint64 upload_position,
673 uint64 upload_size) OVERRIDE;
674 virtual void WorkerCrashed() OVERRIDE;
675 virtual void Activate() OVERRIDE;
676 virtual void Deactivate() OVERRIDE;
677 virtual void LostCapture() OVERRIDE;
[email protected]63954792011-07-11 04:17:48678 virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
[email protected]544e27f2011-07-25 21:41:54679 bool* is_keyboard_shortcut) OVERRIDE;
680 virtual void HandleKeyboardEvent(
681 const NativeWebKeyboardEvent& event) OVERRIDE;
682 virtual void HandleMouseUp() OVERRIDE;
683 virtual void HandleMouseActivate() OVERRIDE;
[email protected]6c2e472f2011-08-24 23:26:18684 virtual bool OnMessageReceived(const IPC::Message& message);
685 virtual void RunFileChooser(RenderViewHost* render_view_host,
686 const ViewHostMsg_RunFileChooser_Params& params);
[email protected]8a5e0ca2011-08-25 06:30:47687 virtual void ToggleFullscreenMode(bool enter_fullscreen) OVERRIDE;
[email protected]5d5f7af2011-10-01 01:38:12688 virtual bool IsFullscreenForCurrentTab() const OVERRIDE;
[email protected]0548c5352011-09-07 00:33:33689 virtual void UpdatePreferredSize(const gfx::Size& pref_size) OVERRIDE;
[email protected]e9621112011-10-17 05:38:37690 virtual void RequestToLockMouse() OVERRIDE;
691 virtual void LostMouseLock() OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:44692
693 // RenderViewHostManager::Delegate -------------------------------------------
694
[email protected]0dd3a0ab2011-02-18 08:17:44695 virtual void BeforeUnloadFiredFromRenderManager(
696 bool proceed,
697 bool* proceed_to_fire_unload);
698 virtual void DidStartLoadingFromRenderManager(
699 RenderViewHost* render_view_host);
700 virtual void RenderViewGoneFromRenderManager(
701 RenderViewHost* render_view_host);
702 virtual void UpdateRenderViewSizeForRenderManager();
703 virtual void NotifySwappedFromRenderManager();
704 virtual NavigationController& GetControllerForRenderManager();
705 virtual WebUI* CreateWebUIForRenderManager(const GURL& url);
706 virtual NavigationEntry* GetLastCommittedNavigationEntryForRenderManager();
707
708 // Initializes the given renderer if necessary and creates the view ID
709 // corresponding to this view host. If this method is not called and the
710 // process is not shared, then the TabContents will act as though the renderer
711 // is not running (i.e., it will render "sad tab"). This method is
712 // automatically called from LoadURL.
713 //
714 // If you are attaching to an already-existing RenderView, you should call
715 // InitWithExistingID.
716 virtual bool CreateRenderViewForRenderManager(
717 RenderViewHost* render_view_host);
718
[email protected]81898992011-06-14 22:15:00719 // Stores random bits of data for others to associate with this object.
720 // WARNING: this needs to be deleted after NavigationController.
721 PropertyBag property_bag_;
722
[email protected]0dd3a0ab2011-02-18 08:17:44723 // Data for core operation ---------------------------------------------------
724
725 // Delegate for notifying our owner about stuff. Not owned by us.
726 TabContentsDelegate* delegate_;
727
728 // Handles the back/forward list and loading.
729 NavigationController controller_;
730
731 // The corresponding view.
732 scoped_ptr<TabContentsView> view_;
733
734 // Helper classes ------------------------------------------------------------
735
736 // Manages creation and swapping of render views.
737 RenderViewHostManager render_manager_;
738
[email protected]483623eb2011-10-25 09:30:00739 // Manages injecting Java objects into all RenderViewHosts associated with
740 // this TabContents.
741 scoped_ptr<JavaBridgeDispatcherHostManager>
742 java_bridge_dispatcher_host_manager_;
743
[email protected]c7dd2f62011-07-18 15:57:59744 // SavePackage, lazily created.
745 scoped_refptr<SavePackage> save_package_;
746
[email protected]0dd3a0ab2011-02-18 08:17:44747 // Data for loading state ----------------------------------------------------
748
749 // Indicates whether we're currently loading a resource.
750 bool is_loading_;
751
752 // Indicates if the tab is considered crashed.
753 base::TerminationStatus crashed_status_;
754 int crashed_error_code_;
755
756 // See waiting_for_response() above.
757 bool waiting_for_response_;
758
759 // Indicates the largest PageID we've seen. This field is ignored if we are
760 // a TabContents, in which case the max page ID is stored separately with
761 // each SiteInstance.
762 // TODO(brettw) this seems like it can be removed according to the comment.
763 int32 max_page_id_;
764
765 // System time at which the current load was started.
766 base::TimeTicks current_load_start_;
767
768 // The current load state and the URL associated with it.
[email protected]9c235f042011-08-10 22:28:21769 net::LoadStateWithParam load_state_;
[email protected]0dd3a0ab2011-02-18 08:17:44770 string16 load_state_host_;
771 // Upload progress, for displaying in the status bar.
772 // Set to zero when there is no significant upload happening.
773 uint64 upload_size_;
774 uint64 upload_position_;
775
776 // Data for current page -----------------------------------------------------
777
[email protected]987fc3a2011-05-26 14:18:09778 // When a title cannot be taken from any entry, this title will be used.
779 string16 page_title_when_no_navigation_entry_;
780
[email protected]0dd3a0ab2011-02-18 08:17:44781 // When a navigation occurs, we record its contents MIME type. It can be
782 // used to check whether we can do something for some special contents.
783 std::string contents_mime_type_;
784
785 // Character encoding.
786 std::string encoding_;
787
[email protected]0dd3a0ab2011-02-18 08:17:44788 // True if this is a secure page which displayed insecure content.
789 bool displayed_insecure_content_;
790
[email protected]0dd3a0ab2011-02-18 08:17:44791 // Data for misc internal state ----------------------------------------------
792
793 // See capturing_contents() above.
794 bool capturing_contents_;
795
796 // See getter above.
797 bool is_being_destroyed_;
798
799 // Indicates whether we should notify about disconnection of this
800 // TabContents. This is used to ensure disconnection notifications only
801 // happen if a connection notification has happened and that they happen only
802 // once.
803 bool notify_disconnection_;
804
[email protected]2e5b90c2011-08-16 21:11:55805 // Pointer to the JavaScript dialog creator, lazily assigned. Used because the
806 // delegate of this TabContents is nulled before its destructor is called.
807 content::JavaScriptDialogCreator* dialog_creator_;
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.
[email protected]daf82f82011-10-31 22:35:31822 content::RendererPreferences renderer_preferences_;
[email protected]0dd3a0ab2011-02-18 08:17:44823
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_