blob: 56539a110ed73562b0847a1d220729fdc6b94619 [file] [log] [blame]
[email protected]91854cd2012-01-10 19:43:571// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]0dd3a0ab2011-02-18 08:17:442// 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
[email protected]01d65172011-12-25 04:39:3013#include "base/compiler_specific.h"
[email protected]0dd3a0ab2011-02-18 08:17:4414#include "base/gtest_prod_util.h"
[email protected]3b63f8f42011-03-28 01:54:1515#include "base/memory/scoped_ptr.h"
[email protected]6eac57a2011-07-12 21:15:0916#include "base/observer_list.h"
[email protected]45644f62011-11-23 00:58:2317#include "base/property_bag.h"
[email protected]3ab9cb82011-06-03 18:02:0718#include "content/browser/javascript_dialogs.h"
[email protected]07161902011-11-11 09:57:4219#include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager.h"
[email protected]5de634712011-03-02 00:20:1920#include "content/browser/renderer_host/render_view_host_delegate.h"
[email protected]d202a7c2012-01-04 07:53:4721#include "content/browser/tab_contents/navigation_controller_impl.h"
[email protected]0dd3a0ab2011-02-18 08:17:4422#include "content/browser/tab_contents/render_view_host_manager.h"
[email protected]8d128d62011-09-13 22:11:5723#include "content/common/content_export.h"
[email protected]58f5d562011-12-20 17:13:0324#include "content/public/browser/web_contents.h"
[email protected]daf82f82011-10-31 22:35:3125#include "content/public/common/renderer_preferences.h"
[email protected]0dd3a0ab2011-02-18 08:17:4426#include "net/base/load_states.h"
[email protected]bcd2815602012-01-14 18:17:2327#include "ui/gfx/size.h"
[email protected]70435962011-08-02 20:13:2828#include "webkit/glue/resource_type.h"
[email protected]0dd3a0ab2011-02-18 08:17:4429
30#if defined(OS_WIN)
31#include "base/win/scoped_handle.h"
32#endif
33
[email protected]0dd3a0ab2011-02-18 08:17:4434class LoadNotificationDetails;
[email protected]0dd3a0ab2011-02-18 08:17:4435class RenderViewHost;
36class SessionStorageNamespace;
37class SiteInstance;
[email protected]0dd3a0ab2011-02-18 08:17:4438class TabContentsView;
[email protected]d7b175e2011-10-11 15:31:5839struct ViewHostMsg_DidFailProvisionalLoadWithError_Params;
[email protected]daf82f82011-10-31 22:35:3140
[email protected]e582fdd2011-12-20 16:48:1741namespace content {
42class DownloadItem;
[email protected]d8c660432011-12-22 20:51:2543class WebContentsObserver;
[email protected]674bc592011-12-20 23:00:4244class WebContentsDelegate;
[email protected]e582fdd2011-12-20 16:48:1745}
46
[email protected]daf82f82011-10-31 22:35:3147namespace webkit_glue {
48struct WebIntentData;
49}
[email protected]0dd3a0ab2011-02-18 08:17:4450
[email protected]01d65172011-12-25 04:39:3051class CONTENT_EXPORT TabContents
52 : public NON_EXPORTED_BASE(content::WebContents),
[email protected]01d65172011-12-25 04:39:3053 public RenderViewHostDelegate,
54 public RenderViewHostManager::Delegate,
55 public content::JavaScriptDialogDelegate {
[email protected]0dd3a0ab2011-02-18 08:17:4456 public:
[email protected]a81343d232011-12-27 07:39:2057 // See WebContents::Create for a description of these parameters.
[email protected]3d7474ff2011-07-27 17:47:3758 TabContents(content::BrowserContext* browser_context,
[email protected]0dd3a0ab2011-02-18 08:17:4459 SiteInstance* site_instance,
60 int routing_id,
61 const TabContents* base_tab_contents,
62 SessionStorageNamespace* session_storage_namespace);
63 virtual ~TabContents();
64
[email protected]c7dd2f62011-07-18 15:57:5965 // Returns the SavePackage which manages the page saving job. May be NULL.
66 SavePackage* save_package() const { return save_package_.get(); }
67
[email protected]74ce1ad2011-12-16 21:51:4668 // Updates the max page ID for the current SiteInstance in this TabContents
69 // to be at least |page_id|.
[email protected]0dd3a0ab2011-02-18 08:17:4470 void UpdateMaxPageID(int32 page_id);
71
[email protected]74ce1ad2011-12-16 21:51:4672 // Updates the max page ID for the given SiteInstance in this TabContents
73 // to be at least |page_id|.
74 void UpdateMaxPageIDForSiteInstance(SiteInstance* site_instance,
75 int32 page_id);
76
[email protected]91854cd2012-01-10 19:43:5777 // Copy the current map of SiteInstance ID to max page ID from another tab.
78 // This is necessary when this tab adopts the NavigationEntries from
79 // |tab_contents|.
80 void CopyMaxPageIDsFrom(TabContents* tab_contents);
81
[email protected]0dd3a0ab2011-02-18 08:17:4482 // Called by the NavigationController to cause the TabContents to navigate to
83 // the current pending entry. The NavigationController should be called back
[email protected]9a7e68c2011-05-26 17:35:5084 // with RendererDidNavigate on success or DiscardPendingEntry on failure.
85 // The callbacks can be inside of this function, or at some future time.
[email protected]0dd3a0ab2011-02-18 08:17:4486 //
87 // The entry has a PageID of -1 if newly created (corresponding to navigation
88 // to a new URL).
89 //
90 // If this method returns false, then the navigation is discarded (equivalent
91 // to calling DiscardPendingEntry on the NavigationController).
[email protected]0bfbf882011-12-22 18:19:2792 bool NavigateToPendingEntry(
[email protected]71fde352011-12-29 03:29:5693 content::NavigationController::ReloadType reload_type);
[email protected]0dd3a0ab2011-02-18 08:17:4494
[email protected]0dd3a0ab2011-02-18 08:17:4495 // Sets the passed passed interstitial as the currently showing interstitial.
96 // |interstitial_page| should be non NULL (use the remove_interstitial_page
97 // method to unset the interstitial) and no interstitial page should be set
98 // when there is already a non NULL interstitial page set.
99 void set_interstitial_page(InterstitialPage* interstitial_page) {
100 render_manager_.set_interstitial_page(interstitial_page);
101 }
102
103 // Unsets the currently showing interstitial.
104 void remove_interstitial_page() {
105 render_manager_.remove_interstitial_page();
106 }
107
[email protected]01ec4ec2012-01-18 04:13:47108 void set_opener_web_ui_type(content::WebUI::TypeID opener_web_ui_type) {
[email protected]0dd3a0ab2011-02-18 08:17:44109 opener_web_ui_type_ = opener_web_ui_type;
110 }
111
[email protected]276b37a22011-11-08 20:45:46112 JavaBridgeDispatcherHostManager* java_bridge_dispatcher_host_manager() const {
113 return java_bridge_dispatcher_host_manager_.get();
114 }
115
[email protected]cdcb1dee2012-01-04 00:46:20116 // Like GetController from WebContents, but returns the concrete object.
[email protected]d202a7c2012-01-04 07:53:47117 NavigationControllerImpl& GetControllerImpl();
[email protected]cdcb1dee2012-01-04 00:46:20118
[email protected]765187182012-01-11 23:59:28119 // Expose the render manager for testing.
120 RenderViewHostManager* GetRenderManagerForTesting();
121
[email protected]58f5d562011-12-20 17:13:03122 // content::WebContents ------------------------------------------------------
[email protected]6934a702011-12-20 00:04:51123 virtual const base::PropertyBag* GetPropertyBag() const OVERRIDE;
124 virtual base::PropertyBag* GetPropertyBag() OVERRIDE;
[email protected]674bc592011-12-20 23:00:42125 virtual content::WebContentsDelegate* GetDelegate() OVERRIDE;
126 virtual void SetDelegate(content::WebContentsDelegate* delegate) OVERRIDE;
[email protected]cdcb1dee2012-01-04 00:46:20127 virtual content::NavigationController& GetController() OVERRIDE;
128 virtual const content::NavigationController& GetController() const OVERRIDE;
[email protected]627e0512011-12-21 22:55:30129 virtual content::BrowserContext* GetBrowserContext() const OVERRIDE;
[email protected]f5fa20e2011-12-21 22:35:56130 virtual void SetViewType(content::ViewType type) OVERRIDE;
[email protected]ea049a02011-12-25 21:37:09131 virtual content::ViewType GetViewType() const OVERRIDE;
[email protected]f5fa20e2011-12-21 22:35:56132 virtual content::RenderProcessHost* GetRenderProcessHost() const OVERRIDE;
[email protected]151a63d2011-12-20 22:32:52133 virtual RenderViewHost* GetRenderViewHost() const OVERRIDE;
[email protected]d487beefe2011-12-21 05:41:21134 virtual RenderWidgetHostView* GetRenderWidgetHostView() const OVERRIDE;
135 virtual TabContentsView* GetView() const OVERRIDE;
[email protected]01ec4ec2012-01-18 04:13:47136 virtual content::WebUI* CreateWebUI(const GURL& url) OVERRIDE;
137 virtual content::WebUI* GetWebUI() const OVERRIDE;
138 virtual content::WebUI* GetCommittedWebUI() const OVERRIDE;
[email protected]be1f56ab2011-12-22 06:55:31139 virtual const string16& GetTitle() const OVERRIDE;
140 virtual int32 GetMaxPageID() OVERRIDE;
141 virtual int32 GetMaxPageIDForSiteInstance(
142 SiteInstance* site_instance) OVERRIDE;
143 virtual SiteInstance* GetSiteInstance() const OVERRIDE;
144 virtual SiteInstance* GetPendingSiteInstance() const OVERRIDE;
145 virtual bool IsLoading() const OVERRIDE;
146 virtual bool IsWaitingForResponse() const OVERRIDE;
147 virtual const net::LoadStateWithParam& GetLoadState() const OVERRIDE;
148 virtual const string16& GetLoadStateHost() const OVERRIDE;
149 virtual uint64 GetUploadSize() const OVERRIDE;
150 virtual uint64 GetUploadPosition() const OVERRIDE;
151 virtual const std::string& GetEncoding() const OVERRIDE;
152 virtual bool DisplayedInsecureContent() const OVERRIDE;
153 virtual void SetCapturingContents(bool cap) OVERRIDE;
154 virtual bool IsCrashed() const OVERRIDE;
155 virtual void SetIsCrashed(base::TerminationStatus status,
156 int error_code) OVERRIDE;
157 virtual base::TerminationStatus GetCrashedStatus() const OVERRIDE;
158 virtual bool IsBeingDestroyed() const OVERRIDE;
159 virtual void NotifyNavigationStateChanged(unsigned changed_flags) OVERRIDE;
160 virtual void DidBecomeSelected() OVERRIDE;
161 virtual base::TimeTicks GetLastSelectedTime() const OVERRIDE;
162 virtual void WasHidden() OVERRIDE;
163 virtual void ShowContents() OVERRIDE;
164 virtual void HideContents() OVERRIDE;
165 virtual bool NeedToFireBeforeUnload() OVERRIDE;
[email protected]0bfbf882011-12-22 18:19:27166 virtual void Stop() OVERRIDE;
[email protected]d9083482012-01-06 00:38:46167 virtual content::WebContents* Clone() OVERRIDE;
[email protected]0bfbf882011-12-22 18:19:27168 virtual void ShowPageInfo(const GURL& url,
[email protected]d583e3f22011-12-27 21:38:17169 const content::SSLStatus& ssl,
[email protected]0bfbf882011-12-22 18:19:27170 bool show_history) OVERRIDE;
[email protected]2a6bc3e2011-12-28 23:51:33171 virtual void AddNewContents(content::WebContents* new_contents,
[email protected]0bfbf882011-12-22 18:19:27172 WindowOpenDisposition disposition,
173 const gfx::Rect& initial_pos,
174 bool user_gesture) OVERRIDE;
175 virtual gfx::NativeView GetContentNativeView() const OVERRIDE;
176 virtual gfx::NativeView GetNativeView() const OVERRIDE;
177 virtual void GetContainerBounds(gfx::Rect* out) const OVERRIDE;
178 virtual void Focus() OVERRIDE;
179 virtual void FocusThroughTabTraversal(bool reverse) OVERRIDE;
180 virtual bool ShowingInterstitialPage() const OVERRIDE;
181 virtual InterstitialPage* GetInterstitialPage() const OVERRIDE;
182 virtual void OnSavePage() OVERRIDE;
183 virtual bool SavePage(const FilePath& main_file,
184 const FilePath& dir_path,
185 SavePackage::SavePackageType save_type) OVERRIDE;
186 virtual bool IsActiveEntry(int32 page_id) OVERRIDE;
187
188 virtual const std::string& GetContentsMimeType() const OVERRIDE;
189 virtual bool WillNotifyDisconnection() const OVERRIDE;
190 virtual void SetOverrideEncoding(const std::string& encoding) OVERRIDE;
191 virtual void ResetOverrideEncoding() OVERRIDE;
192 virtual content::RendererPreferences* GetMutableRendererPrefs() OVERRIDE;
193 virtual void SetNewTabStartTime(const base::TimeTicks& time) OVERRIDE;
194 virtual base::TimeTicks GetNewTabStartTime() const OVERRIDE;
195 virtual void OnCloseStarted() OVERRIDE;
196 virtual bool ShouldAcceptDragAndDrop() const OVERRIDE;
197 virtual void SystemDragEnded() OVERRIDE;
198 virtual void SetClosedByUserGesture(bool value) OVERRIDE;
199 virtual bool GetClosedByUserGesture() const OVERRIDE;
200 virtual double GetZoomLevel() const OVERRIDE;
201 virtual int GetZoomPercent(bool* enable_increment,
202 bool* enable_decrement) OVERRIDE;
203 virtual void ViewSource() OVERRIDE;
204 virtual void ViewFrameSource(const GURL& url,
205 const std::string& content_state) OVERRIDE;
206 virtual int GetMinimumZoomPercent() const OVERRIDE;
207 virtual int GetMaximumZoomPercent() const OVERRIDE;
[email protected]bcd2815602012-01-14 18:17:23208 virtual gfx::Size GetPreferredSize() const OVERRIDE;
[email protected]0bfbf882011-12-22 18:19:27209 virtual int GetContentRestrictions() const OVERRIDE;
[email protected]01ec4ec2012-01-18 04:13:47210 virtual content::WebUI::TypeID GetWebUITypeForCurrentState() OVERRIDE;
211 virtual content::WebUI* GetWebUIForCurrentState() OVERRIDE;
[email protected]0bfbf882011-12-22 18:19:27212 virtual bool GotResponseToLockMouseRequest(bool allowed) OVERRIDE;
213
214 // Implementation of PageNavigator.
[email protected]e5d549d2011-12-28 01:29:20215 virtual content::WebContents* OpenURL(
216 const content::OpenURLParams& params) OVERRIDE;
[email protected]151a63d2011-12-20 22:32:52217
[email protected]952a68e2011-11-17 00:36:10218 // RenderViewHostDelegate ----------------------------------------------------
219
220 virtual RenderViewHostDelegate::View* GetViewDelegate() OVERRIDE;
221 virtual RenderViewHostDelegate::RendererManagement*
222 GetRendererManagementDelegate() OVERRIDE;
[email protected]be1f56ab2011-12-22 06:55:31223 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
224 virtual const GURL& GetURL() const OVERRIDE;
[email protected]952a68e2011-11-17 00:36:10225 virtual TabContents* GetAsTabContents() OVERRIDE;
[email protected]768c5472011-12-26 19:06:17226 virtual WebContents* GetAsWebContents() OVERRIDE;
[email protected]952a68e2011-11-17 00:36:10227 virtual content::ViewType GetRenderViewType() const OVERRIDE;
228 virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE;
229 virtual void RenderViewReady(RenderViewHost* render_view_host) OVERRIDE;
230 virtual void RenderViewGone(RenderViewHost* render_view_host,
231 base::TerminationStatus status,
232 int error_code) OVERRIDE;
233 virtual void RenderViewDeleted(RenderViewHost* render_view_host) OVERRIDE;
234 virtual void DidNavigate(
235 RenderViewHost* render_view_host,
236 const ViewHostMsg_FrameNavigate_Params& params) OVERRIDE;
237 virtual void UpdateState(RenderViewHost* render_view_host,
238 int32 page_id,
239 const std::string& state) OVERRIDE;
240 virtual void UpdateTitle(RenderViewHost* render_view_host,
241 int32 page_id,
242 const string16& title,
243 base::i18n::TextDirection title_direction) OVERRIDE;
244 virtual void UpdateEncoding(RenderViewHost* render_view_host,
245 const std::string& encoding) OVERRIDE;
246 virtual void UpdateTargetURL(int32 page_id, const GURL& url) OVERRIDE;
247 virtual void Close(RenderViewHost* render_view_host) OVERRIDE;
248 virtual void RequestMove(const gfx::Rect& new_bounds) OVERRIDE;
249 virtual void SwappedOut(RenderViewHost* render_view_host) OVERRIDE;
250 virtual void DidStartLoading() OVERRIDE;
251 virtual void DidStopLoading() OVERRIDE;
252 virtual void DidCancelLoading() OVERRIDE;
253 virtual void DidChangeLoadProgress(double progress) OVERRIDE;
254 virtual void DocumentAvailableInMainFrame(
255 RenderViewHost* render_view_host) OVERRIDE;
256 virtual void DocumentOnLoadCompletedInMainFrame(
257 RenderViewHost* render_view_host,
258 int32 page_id) OVERRIDE;
259 virtual void RequestOpenURL(const GURL& url,
[email protected]445e1042011-12-03 21:03:15260 const content::Referrer& referrer,
[email protected]952a68e2011-11-17 00:36:10261 WindowOpenDisposition disposition,
262 int64 source_frame_id) OVERRIDE;
[email protected]4ad5d77d2011-12-03 02:00:48263 virtual void RequestTransferURL(
264 const GURL& url,
[email protected]bce1f1c2011-12-05 15:11:58265 const content::Referrer& referrer,
[email protected]4ad5d77d2011-12-03 02:00:48266 WindowOpenDisposition disposition,
267 int64 source_frame_id,
[email protected]e5d549d2011-12-28 01:29:20268 const content::GlobalRequestID& transferred_global_request_id) OVERRIDE;
[email protected]952a68e2011-11-17 00:36:10269 virtual void RunJavaScriptMessage(const RenderViewHost* rvh,
270 const string16& message,
271 const string16& default_prompt,
272 const GURL& frame_url,
[email protected]269f86d2011-12-07 02:43:47273 ui::JavascriptMessageType type,
[email protected]952a68e2011-11-17 00:36:10274 IPC::Message* reply_msg,
275 bool* did_suppress_message) OVERRIDE;
276 virtual void RunBeforeUnloadConfirm(const RenderViewHost* rvh,
277 const string16& message,
278 IPC::Message* reply_msg) OVERRIDE;
279 virtual content::RendererPreferences GetRendererPrefs(
280 content::BrowserContext* browser_context) const OVERRIDE;
281 virtual WebPreferences GetWebkitPrefs() OVERRIDE;
282 virtual void OnUserGesture() OVERRIDE;
283 virtual void OnIgnoredUIEvent() OVERRIDE;
284 virtual void RendererUnresponsive(RenderViewHost* render_view_host,
285 bool is_during_unload) OVERRIDE;
286 virtual void RendererResponsive(RenderViewHost* render_view_host) OVERRIDE;
287 virtual void LoadStateChanged(const GURL& url,
288 const net::LoadStateWithParam& load_state,
289 uint64 upload_position,
290 uint64 upload_size) OVERRIDE;
291 virtual void WorkerCrashed() OVERRIDE;
292 virtual void Activate() OVERRIDE;
293 virtual void Deactivate() OVERRIDE;
294 virtual void LostCapture() OVERRIDE;
295 virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
296 bool* is_keyboard_shortcut) OVERRIDE;
297 virtual void HandleKeyboardEvent(
298 const NativeWebKeyboardEvent& event) OVERRIDE;
299 virtual void HandleMouseDown() OVERRIDE;
300 virtual void HandleMouseUp() OVERRIDE;
301 virtual void HandleMouseActivate() OVERRIDE;
[email protected]edc64de2011-11-17 20:07:38302 virtual void RunFileChooser(
303 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23304 const content::FileChooserParams& params) OVERRIDE;
[email protected]952a68e2011-11-17 00:36:10305 virtual void ToggleFullscreenMode(bool enter_fullscreen) OVERRIDE;
306 virtual bool IsFullscreenForCurrentTab() const OVERRIDE;
307 virtual void UpdatePreferredSize(const gfx::Size& pref_size) OVERRIDE;
308 virtual void WebUISend(RenderViewHost* render_view_host,
309 const GURL& source_url,
310 const std::string& name,
311 const base::ListValue& args) OVERRIDE;
312 virtual void RequestToLockMouse() OVERRIDE;
313 virtual void LostMouseLock() OVERRIDE;
314
[email protected]0bfbf882011-12-22 18:19:27315 // RenderViewHostManager::Delegate -------------------------------------------
316
317 virtual bool CreateRenderViewForRenderManager(
318 RenderViewHost* render_view_host) OVERRIDE;
319 virtual void BeforeUnloadFiredFromRenderManager(
320 bool proceed,
321 bool* proceed_to_fire_unload) OVERRIDE;
322 virtual void DidStartLoadingFromRenderManager(
323 RenderViewHost* render_view_host) OVERRIDE;
324 virtual void RenderViewGoneFromRenderManager(
325 RenderViewHost* render_view_host) OVERRIDE;
326 virtual void UpdateRenderViewSizeForRenderManager() OVERRIDE;
327 virtual void NotifySwappedFromRenderManager() OVERRIDE;
[email protected]d202a7c2012-01-04 07:53:47328 virtual NavigationControllerImpl& GetControllerForRenderManager() OVERRIDE;
[email protected]0bfbf882011-12-22 18:19:27329 virtual WebUI* CreateWebUIForRenderManager(const GURL& url) OVERRIDE;
[email protected]ad23a092011-12-28 07:02:04330 virtual content::NavigationEntry*
[email protected]0bfbf882011-12-22 18:19:27331 GetLastCommittedNavigationEntryForRenderManager() OVERRIDE;
332 virtual bool FocusLocationBarByDefault() OVERRIDE;
333 virtual void SetFocusToLocationBar(bool select_all) OVERRIDE;
334 virtual void CreateViewAndSetSizeForRVH(RenderViewHost* rvh) OVERRIDE;
335
336 // Overridden from JavaScriptDialogDelegate:
337 virtual void OnDialogClosed(IPC::Message* reply_msg,
338 bool success,
339 const string16& user_input) OVERRIDE;
340 virtual gfx::NativeWindow GetDialogRootWindow() const OVERRIDE;
341 virtual void OnDialogShown() OVERRIDE;
342
[email protected]0dd3a0ab2011-02-18 08:17:44343 protected:
[email protected]d8c660432011-12-22 20:51:25344 friend class content::WebContentsObserver;
[email protected]553602e12011-04-05 17:01:18345
346 // Add and remove observers for page navigation notifications. Adding or
347 // removing multiple times has no effect. The order in which notifications
348 // are sent to observers is undefined. Clients must be sure to remove the
349 // observer before they go away.
[email protected]d8c660432011-12-22 20:51:25350 void AddObserver(content::WebContentsObserver* observer);
351 void RemoveObserver(content::WebContentsObserver* observer);
[email protected]553602e12011-04-05 17:01:18352
[email protected]0dd3a0ab2011-02-18 08:17:44353 private:
[email protected]d202a7c2012-01-04 07:53:47354 friend class NavigationControllerImpl;
[email protected]0dd3a0ab2011-02-18 08:17:44355
356 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, NoJSMessageOnInterstitials);
357 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, UpdateTitle);
358 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, CrossSiteCantPreemptAfterUnload);
359 FRIEND_TEST_ALL_PREFIXES(FormStructureBrowserTest, HTMLFiles);
360 FRIEND_TEST_ALL_PREFIXES(NavigationControllerTest, HistoryNavigate);
361 FRIEND_TEST_ALL_PREFIXES(RenderViewHostManagerTest, PageDoesBackAndReload);
362
363 // Temporary until the view/contents separation is complete.
364 friend class TabContentsView;
[email protected]9a56a0d2011-05-13 19:03:31365#if defined(TOOLKIT_VIEWS)
[email protected]7e2cef52011-04-11 21:47:23366 friend class TabContentsViewViews;
[email protected]0dd3a0ab2011-02-18 08:17:44367#elif defined(OS_MACOSX)
368 friend class TabContentsViewMac;
369#elif defined(TOOLKIT_USES_GTK)
370 friend class TabContentsViewGtk;
371#endif
372
373 // So InterstitialPage can access SetIsLoading.
374 friend class InterstitialPage;
375
376 // TODO(brettw) TestTabContents shouldn't exist!
377 friend class TestTabContents;
378
[email protected]0dd3a0ab2011-02-18 08:17:44379 // Message handlers.
[email protected]8b5af492011-11-28 21:50:58380 void OnRegisterIntentService(const string16& action,
[email protected]63c239322011-10-31 23:56:30381 const string16& type,
382 const string16& href,
383 const string16& title,
384 const string16& disposition);
[email protected]678105012011-12-09 04:01:21385 void OnWebIntentDispatch(const webkit_glue::WebIntentData& intent,
[email protected]63c239322011-10-31 23:56:30386 int intent_id);
[email protected]0dd3a0ab2011-02-18 08:17:44387 void OnDidStartProvisionalLoadForFrame(int64 frame_id,
388 bool main_frame,
[email protected]57b9396c2011-10-07 19:11:59389 const GURL& opener_url,
[email protected]0dd3a0ab2011-02-18 08:17:44390 const GURL& url);
391 void OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]57b9396c2011-10-07 19:11:59392 const GURL& opener_url,
[email protected]0dd3a0ab2011-02-18 08:17:44393 const GURL& source_url,
394 const GURL& target_url);
[email protected]d7b175e2011-10-11 15:31:58395 void OnDidFailProvisionalLoadWithError(
396 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params);
[email protected]0dd3a0ab2011-02-18 08:17:44397 void OnDidLoadResourceFromMemoryCache(const GURL& url,
[email protected]70435962011-08-02 20:13:28398 const std::string& security_info,
399 const std::string& http_request,
400 ResourceType::Type resource_type);
[email protected]0dd3a0ab2011-02-18 08:17:44401 void OnDidDisplayInsecureContent();
402 void OnDidRunInsecureContent(const std::string& security_origin,
403 const GURL& target_url);
404 void OnDocumentLoadedInFrame(int64 frame_id);
[email protected]1a55c5be2011-11-29 11:36:31405 void OnDidFinishLoad(int64 frame_id,
406 const GURL& validated_url,
407 bool is_main_frame);
408 void OnDidFailLoadWithError(int64 frame_id,
409 const GURL& validated_url,
410 bool is_main_frame,
411 int error_code,
412 const string16& error_description);
[email protected]0dd3a0ab2011-02-18 08:17:44413 void OnUpdateContentRestrictions(int restrictions);
[email protected]0dd3a0ab2011-02-18 08:17:44414 void OnGoToEntryAtOffset(int offset);
[email protected]216813952011-05-19 22:21:26415 void OnUpdateZoomLimits(int minimum_percent,
416 int maximum_percent,
417 bool remember);
[email protected]0bfbf882011-12-22 18:19:27418 void OnSaveURL(const GURL& url);
[email protected]3a29a6e2011-08-24 18:26:21419 void OnEnumerateDirectory(int request_id, const FilePath& path);
[email protected]7d189022011-08-25 22:54:20420 void OnJSOutOfMemory();
421 void OnRegisterProtocolHandler(const std::string& protocol,
422 const GURL& url,
423 const string16& title);
[email protected]b888919c2011-09-02 00:32:16424 void OnFindReply(int request_id, int number_of_matches,
425 const gfx::Rect& selection_rect, int active_match_ordinal,
426 bool final_update);
[email protected]d952a052011-09-06 18:42:45427 void OnCrashedPlugin(const FilePath& plugin_path);
[email protected]7fc4bbb2011-09-08 21:23:10428 void OnAppCacheAccessed(const GURL& manifest_url, bool blocked_by_policy);
[email protected]0dd3a0ab2011-02-18 08:17:44429
430 // Changes the IsLoading state and notifies delegate as needed
431 // |details| is used to provide details on the load that just finished
432 // (but can be null if not applicable). Can be overridden.
433 void SetIsLoading(bool is_loading,
434 LoadNotificationDetails* details);
435
[email protected]0dd3a0ab2011-02-18 08:17:44436 // Called by derived classes to indicate that we're no longer waiting for a
437 // response. This won't actually update the throbber, but it will get picked
438 // up at the next animation step if the throbber is going.
439 void SetNotWaitingForResponse() { waiting_for_response_ = false; }
440
[email protected]0dd3a0ab2011-02-18 08:17:44441 // Navigation helpers --------------------------------------------------------
442 //
443 // These functions are helpers for Navigate() and DidNavigate().
444
445 // Handles post-navigation tasks in DidNavigate AFTER the entry has been
446 // committed to the navigation controller. Note that the navigation entry is
447 // not provided since it may be invalid/changed after being committed. The
448 // current navigation entry is in the NavigationController at this point.
449 void DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:13450 const content::LoadCommittedDetails& details,
[email protected]0dd3a0ab2011-02-18 08:17:44451 const ViewHostMsg_FrameNavigate_Params& params);
452 void DidNavigateAnyFramePostCommit(
453 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:13454 const content::LoadCommittedDetails& details,
[email protected]0dd3a0ab2011-02-18 08:17:44455 const ViewHostMsg_FrameNavigate_Params& params);
456
[email protected]74ce1ad2011-12-16 21:51:46457 // If our controller was restored, update the max page ID associated with the
458 // given RenderViewHost to be larger than the number of restored entries.
459 // This is called in CreateRenderView before any navigations in the RenderView
460 // have begun, to prevent any races in updating RenderView::next_page_id.
461 void UpdateMaxPageIDIfNecessary(RenderViewHost* rvh);
[email protected]0dd3a0ab2011-02-18 08:17:44462
[email protected]0dd3a0ab2011-02-18 08:17:44463 // Saves the given title to the navigation entry and does associated work. It
464 // will update history and the view for the new title, and also synthesize
465 // titles for file URLs that have none (so we require that the URL of the
466 // entry already be set).
467 //
468 // This is used as the backend for state updates, which include a new title,
469 // or the dedicated set title message. It returns true if the new title is
470 // different and was therefore updated.
[email protected]10f417c52011-12-28 21:04:23471 bool UpdateTitleForEntry(content::NavigationEntryImpl* entry,
472 const string16& title);
[email protected]0dd3a0ab2011-02-18 08:17:44473
474 // Causes the TabContents to navigate in the right renderer to |entry|, which
475 // must be already part of the entries in the navigation controller.
476 // This does not change the NavigationController state.
[email protected]10f417c52011-12-28 21:04:23477 bool NavigateToEntry(const content::NavigationEntryImpl& entry,
[email protected]71fde352011-12-29 03:29:56478 content::NavigationController::ReloadType reload_type);
[email protected]0dd3a0ab2011-02-18 08:17:44479
[email protected]796931a92011-08-10 01:32:14480 // Sets the history for this tab_contents to |history_length| entries, and
481 // moves the current page_id to the last entry in the list if it's valid.
482 // This is mainly used when a prerendered page is swapped into the current
[email protected]9e1ad4b2011-08-14 16:49:19483 // tab. The method is virtual for testing.
484 virtual void SetHistoryLengthAndPrune(const SiteInstance* site_instance,
485 int merge_history_length,
486 int32 minimum_page_id);
[email protected]796931a92011-08-10 01:32:14487
[email protected]0dd3a0ab2011-02-18 08:17:44488 // Misc non-view stuff -------------------------------------------------------
489
490 // Helper functions for sending notifications.
491 void NotifySwapped();
492 void NotifyConnected();
493 void NotifyDisconnected();
494
[email protected]be1f56ab2011-12-22 06:55:31495 void SetEncoding(const std::string& encoding);
496
[email protected]81898992011-06-14 22:15:00497 // Stores random bits of data for others to associate with this object.
498 // WARNING: this needs to be deleted after NavigationController.
[email protected]45644f62011-11-23 00:58:23499 base::PropertyBag property_bag_;
[email protected]81898992011-06-14 22:15:00500
[email protected]0dd3a0ab2011-02-18 08:17:44501 // Data for core operation ---------------------------------------------------
502
503 // Delegate for notifying our owner about stuff. Not owned by us.
[email protected]674bc592011-12-20 23:00:42504 content::WebContentsDelegate* delegate_;
[email protected]0dd3a0ab2011-02-18 08:17:44505
506 // Handles the back/forward list and loading.
[email protected]d202a7c2012-01-04 07:53:47507 NavigationControllerImpl controller_;
[email protected]0dd3a0ab2011-02-18 08:17:44508
509 // The corresponding view.
510 scoped_ptr<TabContentsView> view_;
511
[email protected]996042972011-11-08 22:43:59512 // A list of observers notified when page state changes. Weak references.
513 // This MUST be listed above render_manager_ since at destruction time the
514 // latter might cause RenderViewHost's destructor to call us and we might use
515 // the observer list then.
[email protected]d8c660432011-12-22 20:51:25516 ObserverList<content::WebContentsObserver> observers_;
[email protected]996042972011-11-08 22:43:59517
[email protected]0dd3a0ab2011-02-18 08:17:44518 // Helper classes ------------------------------------------------------------
519
520 // Manages creation and swapping of render views.
521 RenderViewHostManager render_manager_;
522
[email protected]483623eb2011-10-25 09:30:00523 // Manages injecting Java objects into all RenderViewHosts associated with
524 // this TabContents.
525 scoped_ptr<JavaBridgeDispatcherHostManager>
526 java_bridge_dispatcher_host_manager_;
527
[email protected]c7dd2f62011-07-18 15:57:59528 // SavePackage, lazily created.
529 scoped_refptr<SavePackage> save_package_;
530
[email protected]0dd3a0ab2011-02-18 08:17:44531 // Data for loading state ----------------------------------------------------
532
533 // Indicates whether we're currently loading a resource.
534 bool is_loading_;
535
536 // Indicates if the tab is considered crashed.
537 base::TerminationStatus crashed_status_;
538 int crashed_error_code_;
539
[email protected]be1f56ab2011-12-22 06:55:31540 // Whether this tab contents is waiting for a first-response for the
541 // main resource of the page. This controls whether the throbber state is
542 // "waiting" or "loading."
[email protected]0dd3a0ab2011-02-18 08:17:44543 bool waiting_for_response_;
544
[email protected]74ce1ad2011-12-16 21:51:46545 // Map of SiteInstance ID to max page ID for this tab. A page ID is specific
546 // to a given tab and SiteInstance, and must be valid for the lifetime of the
547 // TabContents.
548 std::map<int32, int32> max_page_ids_;
[email protected]0dd3a0ab2011-02-18 08:17:44549
550 // System time at which the current load was started.
551 base::TimeTicks current_load_start_;
552
553 // The current load state and the URL associated with it.
[email protected]9c235f042011-08-10 22:28:21554 net::LoadStateWithParam load_state_;
[email protected]0dd3a0ab2011-02-18 08:17:44555 string16 load_state_host_;
556 // Upload progress, for displaying in the status bar.
557 // Set to zero when there is no significant upload happening.
558 uint64 upload_size_;
559 uint64 upload_position_;
560
561 // Data for current page -----------------------------------------------------
562
[email protected]987fc3a2011-05-26 14:18:09563 // When a title cannot be taken from any entry, this title will be used.
564 string16 page_title_when_no_navigation_entry_;
565
[email protected]0dd3a0ab2011-02-18 08:17:44566 // When a navigation occurs, we record its contents MIME type. It can be
567 // used to check whether we can do something for some special contents.
568 std::string contents_mime_type_;
569
570 // Character encoding.
571 std::string encoding_;
572
[email protected]0dd3a0ab2011-02-18 08:17:44573 // True if this is a secure page which displayed insecure content.
574 bool displayed_insecure_content_;
575
[email protected]0dd3a0ab2011-02-18 08:17:44576 // Data for misc internal state ----------------------------------------------
577
[email protected]be1f56ab2011-12-22 06:55:31578 // Whether the tab contents is currently being screenshotted by the
579 // DraggedTabController.
[email protected]0dd3a0ab2011-02-18 08:17:44580 bool capturing_contents_;
581
582 // See getter above.
583 bool is_being_destroyed_;
584
585 // Indicates whether we should notify about disconnection of this
586 // TabContents. This is used to ensure disconnection notifications only
587 // happen if a connection notification has happened and that they happen only
588 // once.
589 bool notify_disconnection_;
590
[email protected]2e5b90c2011-08-16 21:11:55591 // Pointer to the JavaScript dialog creator, lazily assigned. Used because the
592 // delegate of this TabContents is nulled before its destructor is called.
593 content::JavaScriptDialogCreator* dialog_creator_;
594
[email protected]0dd3a0ab2011-02-18 08:17:44595#if defined(OS_WIN)
596 // Handle to an event that's set when the page is showing a message box (or
597 // equivalent constrained window). Plugin processes check this to know if
598 // they should pump messages then.
599 base::win::ScopedHandle message_box_active_;
600#endif
601
[email protected]0dd3a0ab2011-02-18 08:17:44602 // Set to true when there is an active "before unload" dialog. When true,
603 // we've forced the throbber to start in Navigate, and we need to remember to
604 // turn it off in OnJavaScriptMessageBoxClosed if the navigation is canceled.
605 bool is_showing_before_unload_dialog_;
606
[email protected]0dd3a0ab2011-02-18 08:17:44607 // Settings that get passed to the renderer process.
[email protected]daf82f82011-10-31 22:35:31608 content::RendererPreferences renderer_preferences_;
[email protected]0dd3a0ab2011-02-18 08:17:44609
610 // If this tab was created from a renderer using window.open, this will be
611 // non-NULL and represent the WebUI of the opening renderer.
[email protected]01ec4ec2012-01-18 04:13:47612 content::WebUI::TypeID opener_web_ui_type_;
[email protected]0dd3a0ab2011-02-18 08:17:44613
614 // The time that we started to create the new tab page.
615 base::TimeTicks new_tab_start_time_;
616
617 // The time that we started to close the tab.
618 base::TimeTicks tab_close_start_time_;
619
620 // The time that this tab was last selected.
621 base::TimeTicks last_selected_time_;
622
[email protected]0dd3a0ab2011-02-18 08:17:44623 // See description above setter.
624 bool closed_by_user_gesture_;
625
626 // Minimum/maximum zoom percent.
627 int minimum_zoom_percent_;
628 int maximum_zoom_percent_;
629 // If true, the default zoom limits have been overriden for this tab, in which
630 // case we don't want saved settings to apply to it and we don't want to
631 // remember it.
632 bool temporary_zoom_settings_;
633
[email protected]bcd2815602012-01-14 18:17:23634 // The intrinsic size of the page.
635 gfx::Size preferred_size_;
636
[email protected]0dd3a0ab2011-02-18 08:17:44637 // Content restrictions, used to disable print/copy etc based on content's
638 // (full-page plugins for now only) permissions.
639 int content_restrictions_;
640
[email protected]32ded2212011-11-10 18:51:43641 // Our view type. Default is VIEW_TYPE_TAB_CONTENTS.
642 content::ViewType view_type_;
643
[email protected]0dd3a0ab2011-02-18 08:17:44644 DISALLOW_COPY_AND_ASSIGN(TabContents);
645};
646
647#endif // CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_H_