blob: 6585c7a80af720e51a7c89ad1560ed2aaa52e4c1 [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]70435962011-08-02 20:13:2827#include "webkit/glue/resource_type.h"
[email protected]0dd3a0ab2011-02-18 08:17:4428
29#if defined(OS_WIN)
30#include "base/win/scoped_handle.h"
31#endif
32
[email protected]0dd3a0ab2011-02-18 08:17:4433class LoadNotificationDetails;
[email protected]0dd3a0ab2011-02-18 08:17:4434class RenderViewHost;
35class SessionStorageNamespace;
36class SiteInstance;
[email protected]0dd3a0ab2011-02-18 08:17:4437class TabContentsView;
[email protected]d7b175e2011-10-11 15:31:5838struct ViewHostMsg_DidFailProvisionalLoadWithError_Params;
[email protected]daf82f82011-10-31 22:35:3139
[email protected]e582fdd2011-12-20 16:48:1740namespace content {
41class DownloadItem;
[email protected]d8c660432011-12-22 20:51:2542class WebContentsObserver;
[email protected]674bc592011-12-20 23:00:4243class WebContentsDelegate;
[email protected]e582fdd2011-12-20 16:48:1744}
45
[email protected]daf82f82011-10-31 22:35:3146namespace webkit_glue {
47struct WebIntentData;
48}
[email protected]0dd3a0ab2011-02-18 08:17:4449
[email protected]01d65172011-12-25 04:39:3050class CONTENT_EXPORT TabContents
51 : public NON_EXPORTED_BASE(content::WebContents),
[email protected]01d65172011-12-25 04:39:3052 public RenderViewHostDelegate,
53 public RenderViewHostManager::Delegate,
54 public content::JavaScriptDialogDelegate {
[email protected]0dd3a0ab2011-02-18 08:17:4455 public:
[email protected]a81343d232011-12-27 07:39:2056 // See WebContents::Create for a description of these parameters.
[email protected]3d7474ff2011-07-27 17:47:3757 TabContents(content::BrowserContext* browser_context,
[email protected]0dd3a0ab2011-02-18 08:17:4458 SiteInstance* site_instance,
59 int routing_id,
60 const TabContents* base_tab_contents,
61 SessionStorageNamespace* session_storage_namespace);
62 virtual ~TabContents();
63
[email protected]c7dd2f62011-07-18 15:57:5964 // Returns the SavePackage which manages the page saving job. May be NULL.
65 SavePackage* save_package() const { return save_package_.get(); }
66
[email protected]74ce1ad2011-12-16 21:51:4667 // Updates the max page ID for the current SiteInstance in this TabContents
68 // to be at least |page_id|.
[email protected]0dd3a0ab2011-02-18 08:17:4469 void UpdateMaxPageID(int32 page_id);
70
[email protected]74ce1ad2011-12-16 21:51:4671 // Updates the max page ID for the given SiteInstance in this TabContents
72 // to be at least |page_id|.
73 void UpdateMaxPageIDForSiteInstance(SiteInstance* site_instance,
74 int32 page_id);
75
[email protected]91854cd2012-01-10 19:43:5776 // Copy the current map of SiteInstance ID to max page ID from another tab.
77 // This is necessary when this tab adopts the NavigationEntries from
78 // |tab_contents|.
79 void CopyMaxPageIDsFrom(TabContents* tab_contents);
80
[email protected]0dd3a0ab2011-02-18 08:17:4481 // Called by the NavigationController to cause the TabContents to navigate to
82 // the current pending entry. The NavigationController should be called back
[email protected]9a7e68c2011-05-26 17:35:5083 // with RendererDidNavigate on success or DiscardPendingEntry on failure.
84 // The callbacks can be inside of this function, or at some future time.
[email protected]0dd3a0ab2011-02-18 08:17:4485 //
86 // The entry has a PageID of -1 if newly created (corresponding to navigation
87 // to a new URL).
88 //
89 // If this method returns false, then the navigation is discarded (equivalent
90 // to calling DiscardPendingEntry on the NavigationController).
[email protected]0bfbf882011-12-22 18:19:2791 bool NavigateToPendingEntry(
[email protected]71fde352011-12-29 03:29:5692 content::NavigationController::ReloadType reload_type);
[email protected]0dd3a0ab2011-02-18 08:17:4493
[email protected]0dd3a0ab2011-02-18 08:17:4494 // Sets the passed passed interstitial as the currently showing interstitial.
95 // |interstitial_page| should be non NULL (use the remove_interstitial_page
96 // method to unset the interstitial) and no interstitial page should be set
97 // when there is already a non NULL interstitial page set.
98 void set_interstitial_page(InterstitialPage* interstitial_page) {
99 render_manager_.set_interstitial_page(interstitial_page);
100 }
101
102 // Unsets the currently showing interstitial.
103 void remove_interstitial_page() {
104 render_manager_.remove_interstitial_page();
105 }
106
[email protected]1fd1a502011-03-30 16:55:56107 void set_opener_web_ui_type(WebUI::TypeID opener_web_ui_type) {
[email protected]0dd3a0ab2011-02-18 08:17:44108 opener_web_ui_type_ = opener_web_ui_type;
109 }
110
[email protected]276b37a22011-11-08 20:45:46111 JavaBridgeDispatcherHostManager* java_bridge_dispatcher_host_manager() const {
112 return java_bridge_dispatcher_host_manager_.get();
113 }
114
[email protected]cdcb1dee2012-01-04 00:46:20115 // Like GetController from WebContents, but returns the concrete object.
[email protected]d202a7c2012-01-04 07:53:47116 NavigationControllerImpl& GetControllerImpl();
[email protected]cdcb1dee2012-01-04 00:46:20117
[email protected]765187182012-01-11 23:59:28118 // Expose the render manager for testing.
119 RenderViewHostManager* GetRenderManagerForTesting();
120
[email protected]58f5d562011-12-20 17:13:03121 // content::WebContents ------------------------------------------------------
[email protected]6934a702011-12-20 00:04:51122 virtual const base::PropertyBag* GetPropertyBag() const OVERRIDE;
123 virtual base::PropertyBag* GetPropertyBag() OVERRIDE;
[email protected]674bc592011-12-20 23:00:42124 virtual content::WebContentsDelegate* GetDelegate() OVERRIDE;
125 virtual void SetDelegate(content::WebContentsDelegate* delegate) OVERRIDE;
[email protected]cdcb1dee2012-01-04 00:46:20126 virtual content::NavigationController& GetController() OVERRIDE;
127 virtual const content::NavigationController& GetController() const OVERRIDE;
[email protected]627e0512011-12-21 22:55:30128 virtual content::BrowserContext* GetBrowserContext() const OVERRIDE;
[email protected]f5fa20e2011-12-21 22:35:56129 virtual void SetViewType(content::ViewType type) OVERRIDE;
[email protected]ea049a02011-12-25 21:37:09130 virtual content::ViewType GetViewType() const OVERRIDE;
[email protected]f5fa20e2011-12-21 22:35:56131 virtual content::RenderProcessHost* GetRenderProcessHost() const OVERRIDE;
[email protected]151a63d2011-12-20 22:32:52132 virtual RenderViewHost* GetRenderViewHost() const OVERRIDE;
[email protected]d487beefe2011-12-21 05:41:21133 virtual RenderWidgetHostView* GetRenderWidgetHostView() const OVERRIDE;
134 virtual TabContentsView* GetView() const OVERRIDE;
[email protected]be1f56ab2011-12-22 06:55:31135 virtual WebUI* GetWebUI() const OVERRIDE;
136 virtual WebUI* GetCommittedWebUI() const OVERRIDE;
137 virtual const string16& GetTitle() const OVERRIDE;
138 virtual int32 GetMaxPageID() OVERRIDE;
139 virtual int32 GetMaxPageIDForSiteInstance(
140 SiteInstance* site_instance) OVERRIDE;
141 virtual SiteInstance* GetSiteInstance() const OVERRIDE;
142 virtual SiteInstance* GetPendingSiteInstance() const OVERRIDE;
143 virtual bool IsLoading() const OVERRIDE;
144 virtual bool IsWaitingForResponse() const OVERRIDE;
145 virtual const net::LoadStateWithParam& GetLoadState() const OVERRIDE;
146 virtual const string16& GetLoadStateHost() const OVERRIDE;
147 virtual uint64 GetUploadSize() const OVERRIDE;
148 virtual uint64 GetUploadPosition() const OVERRIDE;
149 virtual const std::string& GetEncoding() const OVERRIDE;
150 virtual bool DisplayedInsecureContent() const OVERRIDE;
151 virtual void SetCapturingContents(bool cap) OVERRIDE;
152 virtual bool IsCrashed() const OVERRIDE;
153 virtual void SetIsCrashed(base::TerminationStatus status,
154 int error_code) OVERRIDE;
155 virtual base::TerminationStatus GetCrashedStatus() const OVERRIDE;
156 virtual bool IsBeingDestroyed() const OVERRIDE;
157 virtual void NotifyNavigationStateChanged(unsigned changed_flags) OVERRIDE;
158 virtual void DidBecomeSelected() OVERRIDE;
159 virtual base::TimeTicks GetLastSelectedTime() const OVERRIDE;
160 virtual void WasHidden() OVERRIDE;
161 virtual void ShowContents() OVERRIDE;
162 virtual void HideContents() OVERRIDE;
163 virtual bool NeedToFireBeforeUnload() OVERRIDE;
[email protected]0bfbf882011-12-22 18:19:27164 virtual void Stop() OVERRIDE;
[email protected]d9083482012-01-06 00:38:46165 virtual content::WebContents* Clone() OVERRIDE;
[email protected]0bfbf882011-12-22 18:19:27166 virtual void ShowPageInfo(const GURL& url,
[email protected]d583e3f22011-12-27 21:38:17167 const content::SSLStatus& ssl,
[email protected]0bfbf882011-12-22 18:19:27168 bool show_history) OVERRIDE;
[email protected]2a6bc3e2011-12-28 23:51:33169 virtual void AddNewContents(content::WebContents* new_contents,
[email protected]0bfbf882011-12-22 18:19:27170 WindowOpenDisposition disposition,
171 const gfx::Rect& initial_pos,
172 bool user_gesture) OVERRIDE;
173 virtual gfx::NativeView GetContentNativeView() const OVERRIDE;
174 virtual gfx::NativeView GetNativeView() const OVERRIDE;
175 virtual void GetContainerBounds(gfx::Rect* out) const OVERRIDE;
176 virtual void Focus() OVERRIDE;
177 virtual void FocusThroughTabTraversal(bool reverse) OVERRIDE;
178 virtual bool ShowingInterstitialPage() const OVERRIDE;
179 virtual InterstitialPage* GetInterstitialPage() const OVERRIDE;
180 virtual void OnSavePage() OVERRIDE;
181 virtual bool SavePage(const FilePath& main_file,
182 const FilePath& dir_path,
183 SavePackage::SavePackageType save_type) OVERRIDE;
184 virtual bool IsActiveEntry(int32 page_id) OVERRIDE;
185
186 virtual const std::string& GetContentsMimeType() const OVERRIDE;
187 virtual bool WillNotifyDisconnection() const OVERRIDE;
188 virtual void SetOverrideEncoding(const std::string& encoding) OVERRIDE;
189 virtual void ResetOverrideEncoding() OVERRIDE;
190 virtual content::RendererPreferences* GetMutableRendererPrefs() OVERRIDE;
191 virtual void SetNewTabStartTime(const base::TimeTicks& time) OVERRIDE;
192 virtual base::TimeTicks GetNewTabStartTime() const OVERRIDE;
193 virtual void OnCloseStarted() OVERRIDE;
194 virtual bool ShouldAcceptDragAndDrop() const OVERRIDE;
195 virtual void SystemDragEnded() OVERRIDE;
196 virtual void SetClosedByUserGesture(bool value) OVERRIDE;
197 virtual bool GetClosedByUserGesture() const OVERRIDE;
198 virtual double GetZoomLevel() const OVERRIDE;
199 virtual int GetZoomPercent(bool* enable_increment,
200 bool* enable_decrement) OVERRIDE;
201 virtual void ViewSource() OVERRIDE;
202 virtual void ViewFrameSource(const GURL& url,
203 const std::string& content_state) OVERRIDE;
204 virtual int GetMinimumZoomPercent() const OVERRIDE;
205 virtual int GetMaximumZoomPercent() const OVERRIDE;
206 virtual int GetContentRestrictions() const OVERRIDE;
207 virtual WebUI::TypeID GetWebUITypeForCurrentState() OVERRIDE;
208 virtual WebUI* GetWebUIForCurrentState() OVERRIDE;
209 virtual bool GotResponseToLockMouseRequest(bool allowed) OVERRIDE;
210
211 // Implementation of PageNavigator.
[email protected]e5d549d2011-12-28 01:29:20212 virtual content::WebContents* OpenURL(
213 const content::OpenURLParams& params) OVERRIDE;
[email protected]151a63d2011-12-20 22:32:52214
[email protected]952a68e2011-11-17 00:36:10215 // RenderViewHostDelegate ----------------------------------------------------
216
217 virtual RenderViewHostDelegate::View* GetViewDelegate() OVERRIDE;
218 virtual RenderViewHostDelegate::RendererManagement*
219 GetRendererManagementDelegate() OVERRIDE;
[email protected]be1f56ab2011-12-22 06:55:31220 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
221 virtual const GURL& GetURL() const OVERRIDE;
[email protected]952a68e2011-11-17 00:36:10222 virtual TabContents* GetAsTabContents() OVERRIDE;
[email protected]768c5472011-12-26 19:06:17223 virtual WebContents* GetAsWebContents() OVERRIDE;
[email protected]952a68e2011-11-17 00:36:10224 virtual content::ViewType GetRenderViewType() const OVERRIDE;
225 virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE;
226 virtual void RenderViewReady(RenderViewHost* render_view_host) OVERRIDE;
227 virtual void RenderViewGone(RenderViewHost* render_view_host,
228 base::TerminationStatus status,
229 int error_code) OVERRIDE;
230 virtual void RenderViewDeleted(RenderViewHost* render_view_host) OVERRIDE;
231 virtual void DidNavigate(
232 RenderViewHost* render_view_host,
233 const ViewHostMsg_FrameNavigate_Params& params) OVERRIDE;
234 virtual void UpdateState(RenderViewHost* render_view_host,
235 int32 page_id,
236 const std::string& state) OVERRIDE;
237 virtual void UpdateTitle(RenderViewHost* render_view_host,
238 int32 page_id,
239 const string16& title,
240 base::i18n::TextDirection title_direction) OVERRIDE;
241 virtual void UpdateEncoding(RenderViewHost* render_view_host,
242 const std::string& encoding) OVERRIDE;
243 virtual void UpdateTargetURL(int32 page_id, const GURL& url) OVERRIDE;
244 virtual void Close(RenderViewHost* render_view_host) OVERRIDE;
245 virtual void RequestMove(const gfx::Rect& new_bounds) OVERRIDE;
246 virtual void SwappedOut(RenderViewHost* render_view_host) OVERRIDE;
247 virtual void DidStartLoading() OVERRIDE;
248 virtual void DidStopLoading() OVERRIDE;
249 virtual void DidCancelLoading() OVERRIDE;
250 virtual void DidChangeLoadProgress(double progress) OVERRIDE;
251 virtual void DocumentAvailableInMainFrame(
252 RenderViewHost* render_view_host) OVERRIDE;
253 virtual void DocumentOnLoadCompletedInMainFrame(
254 RenderViewHost* render_view_host,
255 int32 page_id) OVERRIDE;
256 virtual void RequestOpenURL(const GURL& url,
[email protected]445e1042011-12-03 21:03:15257 const content::Referrer& referrer,
[email protected]952a68e2011-11-17 00:36:10258 WindowOpenDisposition disposition,
259 int64 source_frame_id) OVERRIDE;
[email protected]4ad5d77d2011-12-03 02:00:48260 virtual void RequestTransferURL(
261 const GURL& url,
[email protected]bce1f1c2011-12-05 15:11:58262 const content::Referrer& referrer,
[email protected]4ad5d77d2011-12-03 02:00:48263 WindowOpenDisposition disposition,
264 int64 source_frame_id,
[email protected]e5d549d2011-12-28 01:29:20265 const content::GlobalRequestID& transferred_global_request_id) OVERRIDE;
[email protected]952a68e2011-11-17 00:36:10266 virtual void RunJavaScriptMessage(const RenderViewHost* rvh,
267 const string16& message,
268 const string16& default_prompt,
269 const GURL& frame_url,
[email protected]269f86d2011-12-07 02:43:47270 ui::JavascriptMessageType type,
[email protected]952a68e2011-11-17 00:36:10271 IPC::Message* reply_msg,
272 bool* did_suppress_message) OVERRIDE;
273 virtual void RunBeforeUnloadConfirm(const RenderViewHost* rvh,
274 const string16& message,
275 IPC::Message* reply_msg) OVERRIDE;
276 virtual content::RendererPreferences GetRendererPrefs(
277 content::BrowserContext* browser_context) const OVERRIDE;
278 virtual WebPreferences GetWebkitPrefs() OVERRIDE;
279 virtual void OnUserGesture() OVERRIDE;
280 virtual void OnIgnoredUIEvent() OVERRIDE;
281 virtual void RendererUnresponsive(RenderViewHost* render_view_host,
282 bool is_during_unload) OVERRIDE;
283 virtual void RendererResponsive(RenderViewHost* render_view_host) OVERRIDE;
284 virtual void LoadStateChanged(const GURL& url,
285 const net::LoadStateWithParam& load_state,
286 uint64 upload_position,
287 uint64 upload_size) OVERRIDE;
288 virtual void WorkerCrashed() OVERRIDE;
289 virtual void Activate() OVERRIDE;
290 virtual void Deactivate() OVERRIDE;
291 virtual void LostCapture() OVERRIDE;
292 virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
293 bool* is_keyboard_shortcut) OVERRIDE;
294 virtual void HandleKeyboardEvent(
295 const NativeWebKeyboardEvent& event) OVERRIDE;
296 virtual void HandleMouseDown() OVERRIDE;
297 virtual void HandleMouseUp() OVERRIDE;
298 virtual void HandleMouseActivate() OVERRIDE;
[email protected]edc64de2011-11-17 20:07:38299 virtual void RunFileChooser(
300 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23301 const content::FileChooserParams& params) OVERRIDE;
[email protected]952a68e2011-11-17 00:36:10302 virtual void ToggleFullscreenMode(bool enter_fullscreen) OVERRIDE;
303 virtual bool IsFullscreenForCurrentTab() const OVERRIDE;
304 virtual void UpdatePreferredSize(const gfx::Size& pref_size) OVERRIDE;
305 virtual void WebUISend(RenderViewHost* render_view_host,
306 const GURL& source_url,
307 const std::string& name,
308 const base::ListValue& args) OVERRIDE;
309 virtual void RequestToLockMouse() OVERRIDE;
310 virtual void LostMouseLock() OVERRIDE;
311
[email protected]0bfbf882011-12-22 18:19:27312 // RenderViewHostManager::Delegate -------------------------------------------
313
314 virtual bool CreateRenderViewForRenderManager(
315 RenderViewHost* render_view_host) OVERRIDE;
316 virtual void BeforeUnloadFiredFromRenderManager(
317 bool proceed,
318 bool* proceed_to_fire_unload) OVERRIDE;
319 virtual void DidStartLoadingFromRenderManager(
320 RenderViewHost* render_view_host) OVERRIDE;
321 virtual void RenderViewGoneFromRenderManager(
322 RenderViewHost* render_view_host) OVERRIDE;
323 virtual void UpdateRenderViewSizeForRenderManager() OVERRIDE;
324 virtual void NotifySwappedFromRenderManager() OVERRIDE;
[email protected]d202a7c2012-01-04 07:53:47325 virtual NavigationControllerImpl& GetControllerForRenderManager() OVERRIDE;
[email protected]0bfbf882011-12-22 18:19:27326 virtual WebUI* CreateWebUIForRenderManager(const GURL& url) OVERRIDE;
[email protected]ad23a092011-12-28 07:02:04327 virtual content::NavigationEntry*
[email protected]0bfbf882011-12-22 18:19:27328 GetLastCommittedNavigationEntryForRenderManager() OVERRIDE;
329 virtual bool FocusLocationBarByDefault() OVERRIDE;
330 virtual void SetFocusToLocationBar(bool select_all) OVERRIDE;
331 virtual void CreateViewAndSetSizeForRVH(RenderViewHost* rvh) OVERRIDE;
332
333 // Overridden from JavaScriptDialogDelegate:
334 virtual void OnDialogClosed(IPC::Message* reply_msg,
335 bool success,
336 const string16& user_input) OVERRIDE;
337 virtual gfx::NativeWindow GetDialogRootWindow() const OVERRIDE;
338 virtual void OnDialogShown() OVERRIDE;
339
[email protected]0dd3a0ab2011-02-18 08:17:44340 protected:
[email protected]d8c660432011-12-22 20:51:25341 friend class content::WebContentsObserver;
[email protected]553602e12011-04-05 17:01:18342
343 // Add and remove observers for page navigation notifications. Adding or
344 // removing multiple times has no effect. The order in which notifications
345 // are sent to observers is undefined. Clients must be sure to remove the
346 // observer before they go away.
[email protected]d8c660432011-12-22 20:51:25347 void AddObserver(content::WebContentsObserver* observer);
348 void RemoveObserver(content::WebContentsObserver* observer);
[email protected]553602e12011-04-05 17:01:18349
[email protected]0dd3a0ab2011-02-18 08:17:44350 private:
[email protected]d202a7c2012-01-04 07:53:47351 friend class NavigationControllerImpl;
[email protected]0dd3a0ab2011-02-18 08:17:44352
353 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, NoJSMessageOnInterstitials);
354 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, UpdateTitle);
355 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, CrossSiteCantPreemptAfterUnload);
356 FRIEND_TEST_ALL_PREFIXES(FormStructureBrowserTest, HTMLFiles);
357 FRIEND_TEST_ALL_PREFIXES(NavigationControllerTest, HistoryNavigate);
358 FRIEND_TEST_ALL_PREFIXES(RenderViewHostManagerTest, PageDoesBackAndReload);
359
360 // Temporary until the view/contents separation is complete.
361 friend class TabContentsView;
[email protected]9a56a0d2011-05-13 19:03:31362#if defined(TOOLKIT_VIEWS)
[email protected]7e2cef52011-04-11 21:47:23363 friend class TabContentsViewViews;
[email protected]0dd3a0ab2011-02-18 08:17:44364#elif defined(OS_MACOSX)
365 friend class TabContentsViewMac;
366#elif defined(TOOLKIT_USES_GTK)
367 friend class TabContentsViewGtk;
368#endif
369
370 // So InterstitialPage can access SetIsLoading.
371 friend class InterstitialPage;
372
373 // TODO(brettw) TestTabContents shouldn't exist!
374 friend class TestTabContents;
375
[email protected]0dd3a0ab2011-02-18 08:17:44376 // Message handlers.
[email protected]8b5af492011-11-28 21:50:58377 void OnRegisterIntentService(const string16& action,
[email protected]63c239322011-10-31 23:56:30378 const string16& type,
379 const string16& href,
380 const string16& title,
381 const string16& disposition);
[email protected]678105012011-12-09 04:01:21382 void OnWebIntentDispatch(const webkit_glue::WebIntentData& intent,
[email protected]63c239322011-10-31 23:56:30383 int intent_id);
[email protected]0dd3a0ab2011-02-18 08:17:44384 void OnDidStartProvisionalLoadForFrame(int64 frame_id,
385 bool main_frame,
[email protected]57b9396c2011-10-07 19:11:59386 const GURL& opener_url,
[email protected]0dd3a0ab2011-02-18 08:17:44387 const GURL& url);
388 void OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]57b9396c2011-10-07 19:11:59389 const GURL& opener_url,
[email protected]0dd3a0ab2011-02-18 08:17:44390 const GURL& source_url,
391 const GURL& target_url);
[email protected]d7b175e2011-10-11 15:31:58392 void OnDidFailProvisionalLoadWithError(
393 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params);
[email protected]0dd3a0ab2011-02-18 08:17:44394 void OnDidLoadResourceFromMemoryCache(const GURL& url,
[email protected]70435962011-08-02 20:13:28395 const std::string& security_info,
396 const std::string& http_request,
397 ResourceType::Type resource_type);
[email protected]0dd3a0ab2011-02-18 08:17:44398 void OnDidDisplayInsecureContent();
399 void OnDidRunInsecureContent(const std::string& security_origin,
400 const GURL& target_url);
401 void OnDocumentLoadedInFrame(int64 frame_id);
[email protected]1a55c5be2011-11-29 11:36:31402 void OnDidFinishLoad(int64 frame_id,
403 const GURL& validated_url,
404 bool is_main_frame);
405 void OnDidFailLoadWithError(int64 frame_id,
406 const GURL& validated_url,
407 bool is_main_frame,
408 int error_code,
409 const string16& error_description);
[email protected]0dd3a0ab2011-02-18 08:17:44410 void OnUpdateContentRestrictions(int restrictions);
[email protected]0dd3a0ab2011-02-18 08:17:44411 void OnGoToEntryAtOffset(int offset);
[email protected]216813952011-05-19 22:21:26412 void OnUpdateZoomLimits(int minimum_percent,
413 int maximum_percent,
414 bool remember);
[email protected]0bfbf882011-12-22 18:19:27415 void OnSaveURL(const GURL& url);
[email protected]3a29a6e2011-08-24 18:26:21416 void OnEnumerateDirectory(int request_id, const FilePath& path);
[email protected]7d189022011-08-25 22:54:20417 void OnJSOutOfMemory();
418 void OnRegisterProtocolHandler(const std::string& protocol,
419 const GURL& url,
420 const string16& title);
[email protected]b888919c2011-09-02 00:32:16421 void OnFindReply(int request_id, int number_of_matches,
422 const gfx::Rect& selection_rect, int active_match_ordinal,
423 bool final_update);
[email protected]d952a052011-09-06 18:42:45424 void OnCrashedPlugin(const FilePath& plugin_path);
[email protected]7fc4bbb2011-09-08 21:23:10425 void OnAppCacheAccessed(const GURL& manifest_url, bool blocked_by_policy);
[email protected]0dd3a0ab2011-02-18 08:17:44426
427 // Changes the IsLoading state and notifies delegate as needed
428 // |details| is used to provide details on the load that just finished
429 // (but can be null if not applicable). Can be overridden.
430 void SetIsLoading(bool is_loading,
431 LoadNotificationDetails* details);
432
[email protected]0dd3a0ab2011-02-18 08:17:44433 // Called by derived classes to indicate that we're no longer waiting for a
434 // response. This won't actually update the throbber, but it will get picked
435 // up at the next animation step if the throbber is going.
436 void SetNotWaitingForResponse() { waiting_for_response_ = false; }
437
[email protected]0dd3a0ab2011-02-18 08:17:44438 // Navigation helpers --------------------------------------------------------
439 //
440 // These functions are helpers for Navigate() and DidNavigate().
441
442 // Handles post-navigation tasks in DidNavigate AFTER the entry has been
443 // committed to the navigation controller. Note that the navigation entry is
444 // not provided since it may be invalid/changed after being committed. The
445 // current navigation entry is in the NavigationController at this point.
446 void DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:13447 const content::LoadCommittedDetails& details,
[email protected]0dd3a0ab2011-02-18 08:17:44448 const ViewHostMsg_FrameNavigate_Params& params);
449 void DidNavigateAnyFramePostCommit(
450 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:13451 const content::LoadCommittedDetails& details,
[email protected]0dd3a0ab2011-02-18 08:17:44452 const ViewHostMsg_FrameNavigate_Params& params);
453
[email protected]74ce1ad2011-12-16 21:51:46454 // If our controller was restored, update the max page ID associated with the
455 // given RenderViewHost to be larger than the number of restored entries.
456 // This is called in CreateRenderView before any navigations in the RenderView
457 // have begun, to prevent any races in updating RenderView::next_page_id.
458 void UpdateMaxPageIDIfNecessary(RenderViewHost* rvh);
[email protected]0dd3a0ab2011-02-18 08:17:44459
[email protected]0dd3a0ab2011-02-18 08:17:44460 // Saves the given title to the navigation entry and does associated work. It
461 // will update history and the view for the new title, and also synthesize
462 // titles for file URLs that have none (so we require that the URL of the
463 // entry already be set).
464 //
465 // This is used as the backend for state updates, which include a new title,
466 // or the dedicated set title message. It returns true if the new title is
467 // different and was therefore updated.
[email protected]10f417c52011-12-28 21:04:23468 bool UpdateTitleForEntry(content::NavigationEntryImpl* entry,
469 const string16& title);
[email protected]0dd3a0ab2011-02-18 08:17:44470
471 // Causes the TabContents to navigate in the right renderer to |entry|, which
472 // must be already part of the entries in the navigation controller.
473 // This does not change the NavigationController state.
[email protected]10f417c52011-12-28 21:04:23474 bool NavigateToEntry(const content::NavigationEntryImpl& entry,
[email protected]71fde352011-12-29 03:29:56475 content::NavigationController::ReloadType reload_type);
[email protected]0dd3a0ab2011-02-18 08:17:44476
[email protected]796931a92011-08-10 01:32:14477 // Sets the history for this tab_contents to |history_length| entries, and
478 // moves the current page_id to the last entry in the list if it's valid.
479 // This is mainly used when a prerendered page is swapped into the current
[email protected]9e1ad4b2011-08-14 16:49:19480 // tab. The method is virtual for testing.
481 virtual void SetHistoryLengthAndPrune(const SiteInstance* site_instance,
482 int merge_history_length,
483 int32 minimum_page_id);
[email protected]796931a92011-08-10 01:32:14484
[email protected]0dd3a0ab2011-02-18 08:17:44485 // Misc non-view stuff -------------------------------------------------------
486
487 // Helper functions for sending notifications.
488 void NotifySwapped();
489 void NotifyConnected();
490 void NotifyDisconnected();
491
[email protected]be1f56ab2011-12-22 06:55:31492 void SetEncoding(const std::string& encoding);
493
[email protected]81898992011-06-14 22:15:00494 // Stores random bits of data for others to associate with this object.
495 // WARNING: this needs to be deleted after NavigationController.
[email protected]45644f62011-11-23 00:58:23496 base::PropertyBag property_bag_;
[email protected]81898992011-06-14 22:15:00497
[email protected]0dd3a0ab2011-02-18 08:17:44498 // Data for core operation ---------------------------------------------------
499
500 // Delegate for notifying our owner about stuff. Not owned by us.
[email protected]674bc592011-12-20 23:00:42501 content::WebContentsDelegate* delegate_;
[email protected]0dd3a0ab2011-02-18 08:17:44502
503 // Handles the back/forward list and loading.
[email protected]d202a7c2012-01-04 07:53:47504 NavigationControllerImpl controller_;
[email protected]0dd3a0ab2011-02-18 08:17:44505
506 // The corresponding view.
507 scoped_ptr<TabContentsView> view_;
508
[email protected]996042972011-11-08 22:43:59509 // A list of observers notified when page state changes. Weak references.
510 // This MUST be listed above render_manager_ since at destruction time the
511 // latter might cause RenderViewHost's destructor to call us and we might use
512 // the observer list then.
[email protected]d8c660432011-12-22 20:51:25513 ObserverList<content::WebContentsObserver> observers_;
[email protected]996042972011-11-08 22:43:59514
[email protected]0dd3a0ab2011-02-18 08:17:44515 // Helper classes ------------------------------------------------------------
516
517 // Manages creation and swapping of render views.
518 RenderViewHostManager render_manager_;
519
[email protected]483623eb2011-10-25 09:30:00520 // Manages injecting Java objects into all RenderViewHosts associated with
521 // this TabContents.
522 scoped_ptr<JavaBridgeDispatcherHostManager>
523 java_bridge_dispatcher_host_manager_;
524
[email protected]c7dd2f62011-07-18 15:57:59525 // SavePackage, lazily created.
526 scoped_refptr<SavePackage> save_package_;
527
[email protected]0dd3a0ab2011-02-18 08:17:44528 // Data for loading state ----------------------------------------------------
529
530 // Indicates whether we're currently loading a resource.
531 bool is_loading_;
532
533 // Indicates if the tab is considered crashed.
534 base::TerminationStatus crashed_status_;
535 int crashed_error_code_;
536
[email protected]be1f56ab2011-12-22 06:55:31537 // Whether this tab contents is waiting for a first-response for the
538 // main resource of the page. This controls whether the throbber state is
539 // "waiting" or "loading."
[email protected]0dd3a0ab2011-02-18 08:17:44540 bool waiting_for_response_;
541
[email protected]74ce1ad2011-12-16 21:51:46542 // Map of SiteInstance ID to max page ID for this tab. A page ID is specific
543 // to a given tab and SiteInstance, and must be valid for the lifetime of the
544 // TabContents.
545 std::map<int32, int32> max_page_ids_;
[email protected]0dd3a0ab2011-02-18 08:17:44546
547 // System time at which the current load was started.
548 base::TimeTicks current_load_start_;
549
550 // The current load state and the URL associated with it.
[email protected]9c235f042011-08-10 22:28:21551 net::LoadStateWithParam load_state_;
[email protected]0dd3a0ab2011-02-18 08:17:44552 string16 load_state_host_;
553 // Upload progress, for displaying in the status bar.
554 // Set to zero when there is no significant upload happening.
555 uint64 upload_size_;
556 uint64 upload_position_;
557
558 // Data for current page -----------------------------------------------------
559
[email protected]987fc3a2011-05-26 14:18:09560 // When a title cannot be taken from any entry, this title will be used.
561 string16 page_title_when_no_navigation_entry_;
562
[email protected]0dd3a0ab2011-02-18 08:17:44563 // When a navigation occurs, we record its contents MIME type. It can be
564 // used to check whether we can do something for some special contents.
565 std::string contents_mime_type_;
566
567 // Character encoding.
568 std::string encoding_;
569
[email protected]0dd3a0ab2011-02-18 08:17:44570 // True if this is a secure page which displayed insecure content.
571 bool displayed_insecure_content_;
572
[email protected]0dd3a0ab2011-02-18 08:17:44573 // Data for misc internal state ----------------------------------------------
574
[email protected]be1f56ab2011-12-22 06:55:31575 // Whether the tab contents is currently being screenshotted by the
576 // DraggedTabController.
[email protected]0dd3a0ab2011-02-18 08:17:44577 bool capturing_contents_;
578
579 // See getter above.
580 bool is_being_destroyed_;
581
582 // Indicates whether we should notify about disconnection of this
583 // TabContents. This is used to ensure disconnection notifications only
584 // happen if a connection notification has happened and that they happen only
585 // once.
586 bool notify_disconnection_;
587
[email protected]2e5b90c2011-08-16 21:11:55588 // Pointer to the JavaScript dialog creator, lazily assigned. Used because the
589 // delegate of this TabContents is nulled before its destructor is called.
590 content::JavaScriptDialogCreator* dialog_creator_;
591
[email protected]0dd3a0ab2011-02-18 08:17:44592#if defined(OS_WIN)
593 // Handle to an event that's set when the page is showing a message box (or
594 // equivalent constrained window). Plugin processes check this to know if
595 // they should pump messages then.
596 base::win::ScopedHandle message_box_active_;
597#endif
598
[email protected]0dd3a0ab2011-02-18 08:17:44599 // Set to true when there is an active "before unload" dialog. When true,
600 // we've forced the throbber to start in Navigate, and we need to remember to
601 // turn it off in OnJavaScriptMessageBoxClosed if the navigation is canceled.
602 bool is_showing_before_unload_dialog_;
603
[email protected]0dd3a0ab2011-02-18 08:17:44604 // Settings that get passed to the renderer process.
[email protected]daf82f82011-10-31 22:35:31605 content::RendererPreferences renderer_preferences_;
[email protected]0dd3a0ab2011-02-18 08:17:44606
607 // If this tab was created from a renderer using window.open, this will be
608 // non-NULL and represent the WebUI of the opening renderer.
[email protected]1fd1a502011-03-30 16:55:56609 WebUI::TypeID opener_web_ui_type_;
[email protected]0dd3a0ab2011-02-18 08:17:44610
611 // The time that we started to create the new tab page.
612 base::TimeTicks new_tab_start_time_;
613
614 // The time that we started to close the tab.
615 base::TimeTicks tab_close_start_time_;
616
617 // The time that this tab was last selected.
618 base::TimeTicks last_selected_time_;
619
[email protected]0dd3a0ab2011-02-18 08:17:44620 // See description above setter.
621 bool closed_by_user_gesture_;
622
623 // Minimum/maximum zoom percent.
624 int minimum_zoom_percent_;
625 int maximum_zoom_percent_;
626 // If true, the default zoom limits have been overriden for this tab, in which
627 // case we don't want saved settings to apply to it and we don't want to
628 // remember it.
629 bool temporary_zoom_settings_;
630
[email protected]0dd3a0ab2011-02-18 08:17:44631 // Content restrictions, used to disable print/copy etc based on content's
632 // (full-page plugins for now only) permissions.
633 int content_restrictions_;
634
[email protected]32ded2212011-11-10 18:51:43635 // Our view type. Default is VIEW_TYPE_TAB_CONTENTS.
636 content::ViewType view_type_;
637
[email protected]0dd3a0ab2011-02-18 08:17:44638 DISALLOW_COPY_AND_ASSIGN(TabContents);
639};
640
641#endif // CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_H_