blob: baeb7819919a1a8c20cd8dccd1de872967069586 [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]07161902011-11-11 09:57:4218#include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager.h"
[email protected]d202a7c2012-01-04 07:53:4719#include "content/browser/tab_contents/navigation_controller_impl.h"
[email protected]0dd3a0ab2011-02-18 08:17:4420#include "content/browser/tab_contents/render_view_host_manager.h"
[email protected]8d128d62011-09-13 22:11:5721#include "content/common/content_export.h"
[email protected]b0b67cf2012-01-18 21:59:5722#include "content/public/browser/render_view_host_delegate.h"
[email protected]58f5d562011-12-20 17:13:0323#include "content/public/browser/web_contents.h"
[email protected]daf82f82011-10-31 22:35:3124#include "content/public/common/renderer_preferences.h"
[email protected]0dd3a0ab2011-02-18 08:17:4425#include "net/base/load_states.h"
[email protected]bcd2815602012-01-14 18:17:2326#include "ui/gfx/size.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]cadaec52012-02-08 21:53:1333class InterstitialPageImpl;
[email protected]0dd3a0ab2011-02-18 08:17:4434class LoadNotificationDetails;
[email protected]0dd3a0ab2011-02-18 08:17:4435class RenderViewHost;
[email protected]a53209b2012-01-20 16:48:1636class SavePackage;
[email protected]0dd3a0ab2011-02-18 08:17:4437class SessionStorageNamespace;
[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]b6583592012-01-25 19:52:3342class SiteInstance;
[email protected]51da7e32012-01-30 19:24:5243class JavaScriptDialogCreator;
[email protected]674bc592011-12-20 23:00:4244class WebContentsDelegate;
[email protected]51da7e32012-01-30 19:24:5245class WebContentsObserver;
[email protected]8643e6d2012-01-18 20:26:1046class WebContentsView;
[email protected]e582fdd2011-12-20 16:48:1747}
48
[email protected]daf82f82011-10-31 22:35:3149namespace webkit_glue {
50struct WebIntentData;
51}
[email protected]0dd3a0ab2011-02-18 08:17:4452
[email protected]01d65172011-12-25 04:39:3053class CONTENT_EXPORT TabContents
54 : public NON_EXPORTED_BASE(content::WebContents),
[email protected]b0b67cf2012-01-18 21:59:5755 public content::RenderViewHostDelegate,
[email protected]51da7e32012-01-30 19:24:5256 public RenderViewHostManager::Delegate {
[email protected]0dd3a0ab2011-02-18 08:17:4457 public:
[email protected]a81343d232011-12-27 07:39:2058 // See WebContents::Create for a description of these parameters.
[email protected]3d7474ff2011-07-27 17:47:3759 TabContents(content::BrowserContext* browser_context,
[email protected]b6583592012-01-25 19:52:3360 content::SiteInstance* site_instance,
[email protected]0dd3a0ab2011-02-18 08:17:4461 int routing_id,
62 const TabContents* base_tab_contents,
63 SessionStorageNamespace* session_storage_namespace);
64 virtual ~TabContents();
65
[email protected]64d69de42012-02-06 00:19:5466 // Returns the content specific prefs for the given RVH.
67 static WebPreferences GetWebkitPrefs(RenderViewHost* rvh, const GURL& url);
68
[email protected]c7dd2f62011-07-18 15:57:5969 // Returns the SavePackage which manages the page saving job. May be NULL.
70 SavePackage* save_package() const { return save_package_.get(); }
71
[email protected]74ce1ad2011-12-16 21:51:4672 // Updates the max page ID for the current SiteInstance in this TabContents
73 // to be at least |page_id|.
[email protected]0dd3a0ab2011-02-18 08:17:4474 void UpdateMaxPageID(int32 page_id);
75
[email protected]74ce1ad2011-12-16 21:51:4676 // Updates the max page ID for the given SiteInstance in this TabContents
77 // to be at least |page_id|.
[email protected]b6583592012-01-25 19:52:3378 void UpdateMaxPageIDForSiteInstance(content::SiteInstance* site_instance,
[email protected]74ce1ad2011-12-16 21:51:4679 int32 page_id);
80
[email protected]91854cd2012-01-10 19:43:5781 // Copy the current map of SiteInstance ID to max page ID from another tab.
82 // This is necessary when this tab adopts the NavigationEntries from
83 // |tab_contents|.
84 void CopyMaxPageIDsFrom(TabContents* tab_contents);
85
[email protected]0dd3a0ab2011-02-18 08:17:4486 // Called by the NavigationController to cause the TabContents to navigate to
87 // the current pending entry. The NavigationController should be called back
[email protected]9a7e68c2011-05-26 17:35:5088 // with RendererDidNavigate on success or DiscardPendingEntry on failure.
89 // The callbacks can be inside of this function, or at some future time.
[email protected]0dd3a0ab2011-02-18 08:17:4490 //
91 // The entry has a PageID of -1 if newly created (corresponding to navigation
92 // to a new URL).
93 //
94 // If this method returns false, then the navigation is discarded (equivalent
95 // to calling DiscardPendingEntry on the NavigationController).
[email protected]0bfbf882011-12-22 18:19:2796 bool NavigateToPendingEntry(
[email protected]71fde352011-12-29 03:29:5697 content::NavigationController::ReloadType reload_type);
[email protected]0dd3a0ab2011-02-18 08:17:4498
[email protected]0dd3a0ab2011-02-18 08:17:4499 // Sets the passed passed interstitial as the currently showing interstitial.
100 // |interstitial_page| should be non NULL (use the remove_interstitial_page
101 // method to unset the interstitial) and no interstitial page should be set
102 // when there is already a non NULL interstitial page set.
[email protected]cadaec52012-02-08 21:53:13103 void set_interstitial_page(InterstitialPageImpl* interstitial_page) {
[email protected]0dd3a0ab2011-02-18 08:17:44104 render_manager_.set_interstitial_page(interstitial_page);
105 }
106
107 // Unsets the currently showing interstitial.
108 void remove_interstitial_page() {
109 render_manager_.remove_interstitial_page();
110 }
111
[email protected]01ec4ec2012-01-18 04:13:47112 void set_opener_web_ui_type(content::WebUI::TypeID opener_web_ui_type) {
[email protected]0dd3a0ab2011-02-18 08:17:44113 opener_web_ui_type_ = opener_web_ui_type;
114 }
115
[email protected]276b37a22011-11-08 20:45:46116 JavaBridgeDispatcherHostManager* java_bridge_dispatcher_host_manager() const {
117 return java_bridge_dispatcher_host_manager_.get();
118 }
119
[email protected]cdcb1dee2012-01-04 00:46:20120 // Like GetController from WebContents, but returns the concrete object.
[email protected]d202a7c2012-01-04 07:53:47121 NavigationControllerImpl& GetControllerImpl();
[email protected]cdcb1dee2012-01-04 00:46:20122
[email protected]765187182012-01-11 23:59:28123 // Expose the render manager for testing.
124 RenderViewHostManager* GetRenderManagerForTesting();
125
[email protected]58f5d562011-12-20 17:13:03126 // content::WebContents ------------------------------------------------------
[email protected]6934a702011-12-20 00:04:51127 virtual const base::PropertyBag* GetPropertyBag() const OVERRIDE;
128 virtual base::PropertyBag* GetPropertyBag() OVERRIDE;
[email protected]674bc592011-12-20 23:00:42129 virtual content::WebContentsDelegate* GetDelegate() OVERRIDE;
130 virtual void SetDelegate(content::WebContentsDelegate* delegate) OVERRIDE;
[email protected]cdcb1dee2012-01-04 00:46:20131 virtual content::NavigationController& GetController() OVERRIDE;
132 virtual const content::NavigationController& GetController() const OVERRIDE;
[email protected]627e0512011-12-21 22:55:30133 virtual content::BrowserContext* GetBrowserContext() const OVERRIDE;
[email protected]f5fa20e2011-12-21 22:35:56134 virtual void SetViewType(content::ViewType type) OVERRIDE;
[email protected]ea049a02011-12-25 21:37:09135 virtual content::ViewType GetViewType() const OVERRIDE;
[email protected]f5fa20e2011-12-21 22:35:56136 virtual content::RenderProcessHost* GetRenderProcessHost() const OVERRIDE;
[email protected]151a63d2011-12-20 22:32:52137 virtual RenderViewHost* GetRenderViewHost() const OVERRIDE;
[email protected]d487beefe2011-12-21 05:41:21138 virtual RenderWidgetHostView* GetRenderWidgetHostView() const OVERRIDE;
[email protected]8643e6d2012-01-18 20:26:10139 virtual content::WebContentsView* GetView() const OVERRIDE;
[email protected]01ec4ec2012-01-18 04:13:47140 virtual content::WebUI* CreateWebUI(const GURL& url) OVERRIDE;
141 virtual content::WebUI* GetWebUI() const OVERRIDE;
142 virtual content::WebUI* GetCommittedWebUI() const OVERRIDE;
[email protected]be1f56ab2011-12-22 06:55:31143 virtual const string16& GetTitle() const OVERRIDE;
144 virtual int32 GetMaxPageID() OVERRIDE;
145 virtual int32 GetMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33146 content::SiteInstance* site_instance) OVERRIDE;
147 virtual content::SiteInstance* GetSiteInstance() const OVERRIDE;
148 virtual content::SiteInstance* GetPendingSiteInstance() const OVERRIDE;
[email protected]be1f56ab2011-12-22 06:55:31149 virtual bool IsLoading() const OVERRIDE;
150 virtual bool IsWaitingForResponse() const OVERRIDE;
151 virtual const net::LoadStateWithParam& GetLoadState() const OVERRIDE;
152 virtual const string16& GetLoadStateHost() const OVERRIDE;
153 virtual uint64 GetUploadSize() const OVERRIDE;
154 virtual uint64 GetUploadPosition() const OVERRIDE;
155 virtual const std::string& GetEncoding() const OVERRIDE;
156 virtual bool DisplayedInsecureContent() const OVERRIDE;
157 virtual void SetCapturingContents(bool cap) OVERRIDE;
158 virtual bool IsCrashed() const OVERRIDE;
159 virtual void SetIsCrashed(base::TerminationStatus status,
160 int error_code) OVERRIDE;
161 virtual base::TerminationStatus GetCrashedStatus() const OVERRIDE;
162 virtual bool IsBeingDestroyed() const OVERRIDE;
163 virtual void NotifyNavigationStateChanged(unsigned changed_flags) OVERRIDE;
164 virtual void DidBecomeSelected() OVERRIDE;
165 virtual base::TimeTicks GetLastSelectedTime() const OVERRIDE;
166 virtual void WasHidden() OVERRIDE;
167 virtual void ShowContents() OVERRIDE;
168 virtual void HideContents() OVERRIDE;
169 virtual bool NeedToFireBeforeUnload() OVERRIDE;
[email protected]0bfbf882011-12-22 18:19:27170 virtual void Stop() OVERRIDE;
[email protected]d9083482012-01-06 00:38:46171 virtual content::WebContents* Clone() OVERRIDE;
[email protected]0bfbf882011-12-22 18:19:27172 virtual void ShowPageInfo(const GURL& url,
[email protected]d583e3f22011-12-27 21:38:17173 const content::SSLStatus& ssl,
[email protected]0bfbf882011-12-22 18:19:27174 bool show_history) OVERRIDE;
[email protected]2a6bc3e2011-12-28 23:51:33175 virtual void AddNewContents(content::WebContents* new_contents,
[email protected]0bfbf882011-12-22 18:19:27176 WindowOpenDisposition disposition,
177 const gfx::Rect& initial_pos,
178 bool user_gesture) OVERRIDE;
179 virtual gfx::NativeView GetContentNativeView() const OVERRIDE;
180 virtual gfx::NativeView GetNativeView() const OVERRIDE;
181 virtual void GetContainerBounds(gfx::Rect* out) const OVERRIDE;
182 virtual void Focus() OVERRIDE;
183 virtual void FocusThroughTabTraversal(bool reverse) OVERRIDE;
184 virtual bool ShowingInterstitialPage() const OVERRIDE;
[email protected]cadaec52012-02-08 21:53:13185 virtual content::InterstitialPage* GetInterstitialPage() const OVERRIDE;
[email protected]a53209b2012-01-20 16:48:16186 virtual bool IsSavable() OVERRIDE;
[email protected]0bfbf882011-12-22 18:19:27187 virtual void OnSavePage() OVERRIDE;
188 virtual bool SavePage(const FilePath& main_file,
189 const FilePath& dir_path,
[email protected]a53209b2012-01-20 16:48:16190 content::SavePageType save_type) OVERRIDE;
[email protected]0bfbf882011-12-22 18:19:27191 virtual bool IsActiveEntry(int32 page_id) OVERRIDE;
192
193 virtual const std::string& GetContentsMimeType() const OVERRIDE;
194 virtual bool WillNotifyDisconnection() const OVERRIDE;
195 virtual void SetOverrideEncoding(const std::string& encoding) OVERRIDE;
196 virtual void ResetOverrideEncoding() OVERRIDE;
197 virtual content::RendererPreferences* GetMutableRendererPrefs() OVERRIDE;
198 virtual void SetNewTabStartTime(const base::TimeTicks& time) OVERRIDE;
199 virtual base::TimeTicks GetNewTabStartTime() const OVERRIDE;
200 virtual void OnCloseStarted() OVERRIDE;
201 virtual bool ShouldAcceptDragAndDrop() const OVERRIDE;
202 virtual void SystemDragEnded() OVERRIDE;
203 virtual void SetClosedByUserGesture(bool value) OVERRIDE;
204 virtual bool GetClosedByUserGesture() const OVERRIDE;
205 virtual double GetZoomLevel() const OVERRIDE;
206 virtual int GetZoomPercent(bool* enable_increment,
207 bool* enable_decrement) OVERRIDE;
208 virtual void ViewSource() OVERRIDE;
209 virtual void ViewFrameSource(const GURL& url,
210 const std::string& content_state) OVERRIDE;
211 virtual int GetMinimumZoomPercent() const OVERRIDE;
212 virtual int GetMaximumZoomPercent() const OVERRIDE;
[email protected]bcd2815602012-01-14 18:17:23213 virtual gfx::Size GetPreferredSize() const OVERRIDE;
[email protected]0bfbf882011-12-22 18:19:27214 virtual int GetContentRestrictions() const OVERRIDE;
[email protected]01ec4ec2012-01-18 04:13:47215 virtual content::WebUI::TypeID GetWebUITypeForCurrentState() OVERRIDE;
216 virtual content::WebUI* GetWebUIForCurrentState() OVERRIDE;
[email protected]0bfbf882011-12-22 18:19:27217 virtual bool GotResponseToLockMouseRequest(bool allowed) OVERRIDE;
218
219 // Implementation of PageNavigator.
[email protected]e5d549d2011-12-28 01:29:20220 virtual content::WebContents* OpenURL(
221 const content::OpenURLParams& params) OVERRIDE;
[email protected]151a63d2011-12-20 22:32:52222
[email protected]952a68e2011-11-17 00:36:10223 // RenderViewHostDelegate ----------------------------------------------------
224
[email protected]b0b67cf2012-01-18 21:59:57225 virtual content::RenderViewHostDelegate::View* GetViewDelegate() OVERRIDE;
226 virtual content::RenderViewHostDelegate::RendererManagement*
[email protected]952a68e2011-11-17 00:36:10227 GetRendererManagementDelegate() OVERRIDE;
[email protected]be1f56ab2011-12-22 06:55:31228 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
229 virtual const GURL& GetURL() const OVERRIDE;
[email protected]768c5472011-12-26 19:06:17230 virtual WebContents* GetAsWebContents() OVERRIDE;
[email protected]952a68e2011-11-17 00:36:10231 virtual content::ViewType GetRenderViewType() const OVERRIDE;
[email protected]b7a756d42012-01-23 18:08:17232 virtual gfx::Rect GetRootWindowResizerRect() const OVERRIDE;
[email protected]952a68e2011-11-17 00:36:10233 virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE;
234 virtual void RenderViewReady(RenderViewHost* render_view_host) OVERRIDE;
235 virtual void RenderViewGone(RenderViewHost* render_view_host,
236 base::TerminationStatus status,
237 int error_code) OVERRIDE;
238 virtual void RenderViewDeleted(RenderViewHost* render_view_host) OVERRIDE;
239 virtual void DidNavigate(
240 RenderViewHost* render_view_host,
241 const ViewHostMsg_FrameNavigate_Params& params) OVERRIDE;
242 virtual void UpdateState(RenderViewHost* render_view_host,
243 int32 page_id,
244 const std::string& state) OVERRIDE;
245 virtual void UpdateTitle(RenderViewHost* render_view_host,
246 int32 page_id,
247 const string16& title,
248 base::i18n::TextDirection title_direction) OVERRIDE;
249 virtual void UpdateEncoding(RenderViewHost* render_view_host,
250 const std::string& encoding) OVERRIDE;
251 virtual void UpdateTargetURL(int32 page_id, const GURL& url) OVERRIDE;
252 virtual void Close(RenderViewHost* render_view_host) OVERRIDE;
253 virtual void RequestMove(const gfx::Rect& new_bounds) OVERRIDE;
254 virtual void SwappedOut(RenderViewHost* render_view_host) OVERRIDE;
255 virtual void DidStartLoading() OVERRIDE;
256 virtual void DidStopLoading() OVERRIDE;
257 virtual void DidCancelLoading() OVERRIDE;
258 virtual void DidChangeLoadProgress(double progress) OVERRIDE;
259 virtual void DocumentAvailableInMainFrame(
260 RenderViewHost* render_view_host) OVERRIDE;
261 virtual void DocumentOnLoadCompletedInMainFrame(
262 RenderViewHost* render_view_host,
263 int32 page_id) OVERRIDE;
264 virtual void RequestOpenURL(const GURL& url,
[email protected]445e1042011-12-03 21:03:15265 const content::Referrer& referrer,
[email protected]952a68e2011-11-17 00:36:10266 WindowOpenDisposition disposition,
267 int64 source_frame_id) OVERRIDE;
[email protected]4ad5d77d2011-12-03 02:00:48268 virtual void RequestTransferURL(
269 const GURL& url,
[email protected]bce1f1c2011-12-05 15:11:58270 const content::Referrer& referrer,
[email protected]4ad5d77d2011-12-03 02:00:48271 WindowOpenDisposition disposition,
272 int64 source_frame_id,
[email protected]e5d549d2011-12-28 01:29:20273 const content::GlobalRequestID& transferred_global_request_id) OVERRIDE;
[email protected]fedec012012-01-28 03:09:34274 virtual void RunJavaScriptMessage(RenderViewHost* rvh,
[email protected]952a68e2011-11-17 00:36:10275 const string16& message,
276 const string16& default_prompt,
277 const GURL& frame_url,
[email protected]269f86d2011-12-07 02:43:47278 ui::JavascriptMessageType type,
[email protected]952a68e2011-11-17 00:36:10279 IPC::Message* reply_msg,
280 bool* did_suppress_message) OVERRIDE;
[email protected]fedec012012-01-28 03:09:34281 virtual void RunBeforeUnloadConfirm(RenderViewHost* rvh,
[email protected]952a68e2011-11-17 00:36:10282 const string16& message,
283 IPC::Message* reply_msg) OVERRIDE;
284 virtual content::RendererPreferences GetRendererPrefs(
285 content::BrowserContext* browser_context) const OVERRIDE;
286 virtual WebPreferences GetWebkitPrefs() OVERRIDE;
287 virtual void OnUserGesture() OVERRIDE;
288 virtual void OnIgnoredUIEvent() OVERRIDE;
289 virtual void RendererUnresponsive(RenderViewHost* render_view_host,
290 bool is_during_unload) OVERRIDE;
291 virtual void RendererResponsive(RenderViewHost* render_view_host) OVERRIDE;
292 virtual void LoadStateChanged(const GURL& url,
293 const net::LoadStateWithParam& load_state,
294 uint64 upload_position,
295 uint64 upload_size) OVERRIDE;
296 virtual void WorkerCrashed() OVERRIDE;
297 virtual void Activate() OVERRIDE;
298 virtual void Deactivate() OVERRIDE;
299 virtual void LostCapture() OVERRIDE;
300 virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
301 bool* is_keyboard_shortcut) OVERRIDE;
302 virtual void HandleKeyboardEvent(
303 const NativeWebKeyboardEvent& event) OVERRIDE;
304 virtual void HandleMouseDown() OVERRIDE;
305 virtual void HandleMouseUp() OVERRIDE;
306 virtual void HandleMouseActivate() OVERRIDE;
[email protected]edc64de2011-11-17 20:07:38307 virtual void RunFileChooser(
308 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23309 const content::FileChooserParams& params) OVERRIDE;
[email protected]952a68e2011-11-17 00:36:10310 virtual void ToggleFullscreenMode(bool enter_fullscreen) OVERRIDE;
311 virtual bool IsFullscreenForCurrentTab() const OVERRIDE;
312 virtual void UpdatePreferredSize(const gfx::Size& pref_size) OVERRIDE;
313 virtual void WebUISend(RenderViewHost* render_view_host,
314 const GURL& source_url,
315 const std::string& name,
316 const base::ListValue& args) OVERRIDE;
317 virtual void RequestToLockMouse() OVERRIDE;
318 virtual void LostMouseLock() OVERRIDE;
319
[email protected]0bfbf882011-12-22 18:19:27320 // RenderViewHostManager::Delegate -------------------------------------------
321
322 virtual bool CreateRenderViewForRenderManager(
323 RenderViewHost* render_view_host) OVERRIDE;
324 virtual void BeforeUnloadFiredFromRenderManager(
325 bool proceed,
326 bool* proceed_to_fire_unload) OVERRIDE;
327 virtual void DidStartLoadingFromRenderManager(
328 RenderViewHost* render_view_host) OVERRIDE;
329 virtual void RenderViewGoneFromRenderManager(
330 RenderViewHost* render_view_host) OVERRIDE;
331 virtual void UpdateRenderViewSizeForRenderManager() OVERRIDE;
332 virtual void NotifySwappedFromRenderManager() OVERRIDE;
[email protected]d202a7c2012-01-04 07:53:47333 virtual NavigationControllerImpl& GetControllerForRenderManager() OVERRIDE;
[email protected]d2353452012-01-19 19:53:56334 virtual WebUIImpl* CreateWebUIForRenderManager(const GURL& url) OVERRIDE;
[email protected]ad23a092011-12-28 07:02:04335 virtual content::NavigationEntry*
[email protected]0bfbf882011-12-22 18:19:27336 GetLastCommittedNavigationEntryForRenderManager() OVERRIDE;
337 virtual bool FocusLocationBarByDefault() OVERRIDE;
338 virtual void SetFocusToLocationBar(bool select_all) OVERRIDE;
339 virtual void CreateViewAndSetSizeForRVH(RenderViewHost* rvh) OVERRIDE;
340
[email protected]0dd3a0ab2011-02-18 08:17:44341 protected:
[email protected]d8c660432011-12-22 20:51:25342 friend class content::WebContentsObserver;
[email protected]553602e12011-04-05 17:01:18343
344 // Add and remove observers for page navigation notifications. Adding or
345 // removing multiple times has no effect. The order in which notifications
346 // are sent to observers is undefined. Clients must be sure to remove the
347 // observer before they go away.
[email protected]d8c660432011-12-22 20:51:25348 void AddObserver(content::WebContentsObserver* observer);
349 void RemoveObserver(content::WebContentsObserver* observer);
[email protected]553602e12011-04-05 17:01:18350
[email protected]0dd3a0ab2011-02-18 08:17:44351 private:
[email protected]d202a7c2012-01-04 07:53:47352 friend class NavigationControllerImpl;
[email protected]0dd3a0ab2011-02-18 08:17:44353
354 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, NoJSMessageOnInterstitials);
355 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, UpdateTitle);
356 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, CrossSiteCantPreemptAfterUnload);
357 FRIEND_TEST_ALL_PREFIXES(FormStructureBrowserTest, HTMLFiles);
358 FRIEND_TEST_ALL_PREFIXES(NavigationControllerTest, HistoryNavigate);
359 FRIEND_TEST_ALL_PREFIXES(RenderViewHostManagerTest, PageDoesBackAndReload);
360
361 // Temporary until the view/contents separation is complete.
[email protected]8643e6d2012-01-18 20:26:10362 friend class content::WebContentsView;
[email protected]9a56a0d2011-05-13 19:03:31363#if defined(TOOLKIT_VIEWS)
[email protected]7e2cef52011-04-11 21:47:23364 friend class TabContentsViewViews;
[email protected]0dd3a0ab2011-02-18 08:17:44365#elif defined(OS_MACOSX)
[email protected]eb668c92012-02-06 15:35:29366 friend class WebContentsViewMac;
[email protected]0dd3a0ab2011-02-18 08:17:44367#elif defined(TOOLKIT_USES_GTK)
368 friend class TabContentsViewGtk;
369#endif
370
[email protected]cadaec52012-02-08 21:53:13371 // So InterstitialPageImpl can access SetIsLoading.
372 friend class InterstitialPageImpl;
[email protected]0dd3a0ab2011-02-18 08:17:44373
374 // TODO(brettw) TestTabContents shouldn't exist!
375 friend class TestTabContents;
376
[email protected]51da7e32012-01-30 19:24:52377 // Callback function when showing JS dialogs.
378 void OnDialogClosed(RenderViewHost* rvh,
379 IPC::Message* reply_msg,
380 bool success,
381 const string16& user_input);
382
[email protected]0dd3a0ab2011-02-18 08:17:44383 // Message handlers.
[email protected]8b5af492011-11-28 21:50:58384 void OnRegisterIntentService(const string16& action,
[email protected]63c239322011-10-31 23:56:30385 const string16& type,
386 const string16& href,
387 const string16& title,
388 const string16& disposition);
[email protected]678105012011-12-09 04:01:21389 void OnWebIntentDispatch(const webkit_glue::WebIntentData& intent,
[email protected]63c239322011-10-31 23:56:30390 int intent_id);
[email protected]0dd3a0ab2011-02-18 08:17:44391 void OnDidStartProvisionalLoadForFrame(int64 frame_id,
392 bool main_frame,
[email protected]57b9396c2011-10-07 19:11:59393 const GURL& opener_url,
[email protected]0dd3a0ab2011-02-18 08:17:44394 const GURL& url);
395 void OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]57b9396c2011-10-07 19:11:59396 const GURL& opener_url,
[email protected]0dd3a0ab2011-02-18 08:17:44397 const GURL& source_url,
398 const GURL& target_url);
[email protected]d7b175e2011-10-11 15:31:58399 void OnDidFailProvisionalLoadWithError(
400 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params);
[email protected]0dd3a0ab2011-02-18 08:17:44401 void OnDidLoadResourceFromMemoryCache(const GURL& url,
[email protected]70435962011-08-02 20:13:28402 const std::string& security_info,
403 const std::string& http_request,
404 ResourceType::Type resource_type);
[email protected]0dd3a0ab2011-02-18 08:17:44405 void OnDidDisplayInsecureContent();
406 void OnDidRunInsecureContent(const std::string& security_origin,
407 const GURL& target_url);
408 void OnDocumentLoadedInFrame(int64 frame_id);
[email protected]1a55c5be2011-11-29 11:36:31409 void OnDidFinishLoad(int64 frame_id,
410 const GURL& validated_url,
411 bool is_main_frame);
412 void OnDidFailLoadWithError(int64 frame_id,
413 const GURL& validated_url,
414 bool is_main_frame,
415 int error_code,
416 const string16& error_description);
[email protected]0dd3a0ab2011-02-18 08:17:44417 void OnUpdateContentRestrictions(int restrictions);
[email protected]0dd3a0ab2011-02-18 08:17:44418 void OnGoToEntryAtOffset(int offset);
[email protected]216813952011-05-19 22:21:26419 void OnUpdateZoomLimits(int minimum_percent,
420 int maximum_percent,
421 bool remember);
[email protected]0bfbf882011-12-22 18:19:27422 void OnSaveURL(const GURL& url);
[email protected]3a29a6e2011-08-24 18:26:21423 void OnEnumerateDirectory(int request_id, const FilePath& path);
[email protected]7d189022011-08-25 22:54:20424 void OnJSOutOfMemory();
[email protected]b7a756d42012-01-23 18:08:17425
[email protected]7d189022011-08-25 22:54:20426 void OnRegisterProtocolHandler(const std::string& protocol,
427 const GURL& url,
428 const string16& title);
[email protected]b888919c2011-09-02 00:32:16429 void OnFindReply(int request_id, int number_of_matches,
430 const gfx::Rect& selection_rect, int active_match_ordinal,
431 bool final_update);
[email protected]d952a052011-09-06 18:42:45432 void OnCrashedPlugin(const FilePath& plugin_path);
[email protected]7fc4bbb2011-09-08 21:23:10433 void OnAppCacheAccessed(const GURL& manifest_url, bool blocked_by_policy);
[email protected]0dd3a0ab2011-02-18 08:17:44434
435 // Changes the IsLoading state and notifies delegate as needed
436 // |details| is used to provide details on the load that just finished
437 // (but can be null if not applicable). Can be overridden.
438 void SetIsLoading(bool is_loading,
439 LoadNotificationDetails* details);
440
[email protected]0dd3a0ab2011-02-18 08:17:44441 // Called by derived classes to indicate that we're no longer waiting for a
442 // response. This won't actually update the throbber, but it will get picked
443 // up at the next animation step if the throbber is going.
444 void SetNotWaitingForResponse() { waiting_for_response_ = false; }
445
[email protected]0dd3a0ab2011-02-18 08:17:44446 // Navigation helpers --------------------------------------------------------
447 //
448 // These functions are helpers for Navigate() and DidNavigate().
449
450 // Handles post-navigation tasks in DidNavigate AFTER the entry has been
451 // committed to the navigation controller. Note that the navigation entry is
452 // not provided since it may be invalid/changed after being committed. The
453 // current navigation entry is in the NavigationController at this point.
454 void DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:13455 const content::LoadCommittedDetails& details,
[email protected]0dd3a0ab2011-02-18 08:17:44456 const ViewHostMsg_FrameNavigate_Params& params);
457 void DidNavigateAnyFramePostCommit(
458 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:13459 const content::LoadCommittedDetails& details,
[email protected]0dd3a0ab2011-02-18 08:17:44460 const ViewHostMsg_FrameNavigate_Params& params);
461
[email protected]74ce1ad2011-12-16 21:51:46462 // If our controller was restored, update the max page ID associated with the
463 // given RenderViewHost to be larger than the number of restored entries.
464 // This is called in CreateRenderView before any navigations in the RenderView
465 // have begun, to prevent any races in updating RenderView::next_page_id.
466 void UpdateMaxPageIDIfNecessary(RenderViewHost* rvh);
[email protected]0dd3a0ab2011-02-18 08:17:44467
[email protected]0dd3a0ab2011-02-18 08:17:44468 // Saves the given title to the navigation entry and does associated work. It
469 // will update history and the view for the new title, and also synthesize
470 // titles for file URLs that have none (so we require that the URL of the
471 // entry already be set).
472 //
473 // This is used as the backend for state updates, which include a new title,
474 // or the dedicated set title message. It returns true if the new title is
475 // different and was therefore updated.
[email protected]10f417c52011-12-28 21:04:23476 bool UpdateTitleForEntry(content::NavigationEntryImpl* entry,
477 const string16& title);
[email protected]0dd3a0ab2011-02-18 08:17:44478
479 // Causes the TabContents to navigate in the right renderer to |entry|, which
480 // must be already part of the entries in the navigation controller.
481 // This does not change the NavigationController state.
[email protected]10f417c52011-12-28 21:04:23482 bool NavigateToEntry(const content::NavigationEntryImpl& entry,
[email protected]71fde352011-12-29 03:29:56483 content::NavigationController::ReloadType reload_type);
[email protected]0dd3a0ab2011-02-18 08:17:44484
[email protected]796931a92011-08-10 01:32:14485 // Sets the history for this tab_contents to |history_length| entries, and
486 // moves the current page_id to the last entry in the list if it's valid.
487 // This is mainly used when a prerendered page is swapped into the current
[email protected]9e1ad4b2011-08-14 16:49:19488 // tab. The method is virtual for testing.
[email protected]b6583592012-01-25 19:52:33489 virtual void SetHistoryLengthAndPrune(
490 const content::SiteInstance* site_instance,
491 int merge_history_length,
492 int32 minimum_page_id);
[email protected]796931a92011-08-10 01:32:14493
[email protected]0dd3a0ab2011-02-18 08:17:44494 // Misc non-view stuff -------------------------------------------------------
495
496 // Helper functions for sending notifications.
497 void NotifySwapped();
498 void NotifyConnected();
499 void NotifyDisconnected();
500
[email protected]be1f56ab2011-12-22 06:55:31501 void SetEncoding(const std::string& encoding);
502
[email protected]27678b2a2012-02-04 22:09:14503 // Save a URL to the local filesystem.
504 void SaveURL(const GURL& url, const GURL& referrer);
505
[email protected]81898992011-06-14 22:15:00506 // Stores random bits of data for others to associate with this object.
507 // WARNING: this needs to be deleted after NavigationController.
[email protected]45644f62011-11-23 00:58:23508 base::PropertyBag property_bag_;
[email protected]81898992011-06-14 22:15:00509
[email protected]0dd3a0ab2011-02-18 08:17:44510 // Data for core operation ---------------------------------------------------
511
512 // Delegate for notifying our owner about stuff. Not owned by us.
[email protected]674bc592011-12-20 23:00:42513 content::WebContentsDelegate* delegate_;
[email protected]0dd3a0ab2011-02-18 08:17:44514
515 // Handles the back/forward list and loading.
[email protected]d202a7c2012-01-04 07:53:47516 NavigationControllerImpl controller_;
[email protected]0dd3a0ab2011-02-18 08:17:44517
518 // The corresponding view.
[email protected]8643e6d2012-01-18 20:26:10519 scoped_ptr<content::WebContentsView> view_;
[email protected]0dd3a0ab2011-02-18 08:17:44520
[email protected]996042972011-11-08 22:43:59521 // A list of observers notified when page state changes. Weak references.
522 // This MUST be listed above render_manager_ since at destruction time the
523 // latter might cause RenderViewHost's destructor to call us and we might use
524 // the observer list then.
[email protected]d8c660432011-12-22 20:51:25525 ObserverList<content::WebContentsObserver> observers_;
[email protected]996042972011-11-08 22:43:59526
[email protected]0dd3a0ab2011-02-18 08:17:44527 // Helper classes ------------------------------------------------------------
528
529 // Manages creation and swapping of render views.
530 RenderViewHostManager render_manager_;
531
[email protected]483623eb2011-10-25 09:30:00532 // Manages injecting Java objects into all RenderViewHosts associated with
533 // this TabContents.
534 scoped_ptr<JavaBridgeDispatcherHostManager>
535 java_bridge_dispatcher_host_manager_;
536
[email protected]c7dd2f62011-07-18 15:57:59537 // SavePackage, lazily created.
538 scoped_refptr<SavePackage> save_package_;
539
[email protected]0dd3a0ab2011-02-18 08:17:44540 // Data for loading state ----------------------------------------------------
541
542 // Indicates whether we're currently loading a resource.
543 bool is_loading_;
544
545 // Indicates if the tab is considered crashed.
546 base::TerminationStatus crashed_status_;
547 int crashed_error_code_;
548
[email protected]be1f56ab2011-12-22 06:55:31549 // Whether this tab contents is waiting for a first-response for the
550 // main resource of the page. This controls whether the throbber state is
551 // "waiting" or "loading."
[email protected]0dd3a0ab2011-02-18 08:17:44552 bool waiting_for_response_;
553
[email protected]74ce1ad2011-12-16 21:51:46554 // Map of SiteInstance ID to max page ID for this tab. A page ID is specific
555 // to a given tab and SiteInstance, and must be valid for the lifetime of the
556 // TabContents.
557 std::map<int32, int32> max_page_ids_;
[email protected]0dd3a0ab2011-02-18 08:17:44558
559 // System time at which the current load was started.
560 base::TimeTicks current_load_start_;
561
562 // The current load state and the URL associated with it.
[email protected]9c235f042011-08-10 22:28:21563 net::LoadStateWithParam load_state_;
[email protected]0dd3a0ab2011-02-18 08:17:44564 string16 load_state_host_;
565 // Upload progress, for displaying in the status bar.
566 // Set to zero when there is no significant upload happening.
567 uint64 upload_size_;
568 uint64 upload_position_;
569
570 // Data for current page -----------------------------------------------------
571
[email protected]987fc3a2011-05-26 14:18:09572 // When a title cannot be taken from any entry, this title will be used.
573 string16 page_title_when_no_navigation_entry_;
574
[email protected]0dd3a0ab2011-02-18 08:17:44575 // When a navigation occurs, we record its contents MIME type. It can be
576 // used to check whether we can do something for some special contents.
577 std::string contents_mime_type_;
578
579 // Character encoding.
580 std::string encoding_;
581
[email protected]0dd3a0ab2011-02-18 08:17:44582 // True if this is a secure page which displayed insecure content.
583 bool displayed_insecure_content_;
584
[email protected]0dd3a0ab2011-02-18 08:17:44585 // Data for misc internal state ----------------------------------------------
586
[email protected]be1f56ab2011-12-22 06:55:31587 // Whether the tab contents is currently being screenshotted by the
588 // DraggedTabController.
[email protected]0dd3a0ab2011-02-18 08:17:44589 bool capturing_contents_;
590
591 // See getter above.
592 bool is_being_destroyed_;
593
594 // Indicates whether we should notify about disconnection of this
595 // TabContents. This is used to ensure disconnection notifications only
596 // happen if a connection notification has happened and that they happen only
597 // once.
598 bool notify_disconnection_;
599
[email protected]2e5b90c2011-08-16 21:11:55600 // Pointer to the JavaScript dialog creator, lazily assigned. Used because the
601 // delegate of this TabContents is nulled before its destructor is called.
602 content::JavaScriptDialogCreator* dialog_creator_;
603
[email protected]0dd3a0ab2011-02-18 08:17:44604#if defined(OS_WIN)
605 // Handle to an event that's set when the page is showing a message box (or
606 // equivalent constrained window). Plugin processes check this to know if
607 // they should pump messages then.
608 base::win::ScopedHandle message_box_active_;
609#endif
610
[email protected]0dd3a0ab2011-02-18 08:17:44611 // Set to true when there is an active "before unload" dialog. When true,
612 // we've forced the throbber to start in Navigate, and we need to remember to
613 // turn it off in OnJavaScriptMessageBoxClosed if the navigation is canceled.
614 bool is_showing_before_unload_dialog_;
615
[email protected]0dd3a0ab2011-02-18 08:17:44616 // Settings that get passed to the renderer process.
[email protected]daf82f82011-10-31 22:35:31617 content::RendererPreferences renderer_preferences_;
[email protected]0dd3a0ab2011-02-18 08:17:44618
619 // If this tab was created from a renderer using window.open, this will be
620 // non-NULL and represent the WebUI of the opening renderer.
[email protected]01ec4ec2012-01-18 04:13:47621 content::WebUI::TypeID opener_web_ui_type_;
[email protected]0dd3a0ab2011-02-18 08:17:44622
623 // The time that we started to create the new tab page.
624 base::TimeTicks new_tab_start_time_;
625
626 // The time that we started to close the tab.
627 base::TimeTicks tab_close_start_time_;
628
629 // The time that this tab was last selected.
630 base::TimeTicks last_selected_time_;
631
[email protected]0dd3a0ab2011-02-18 08:17:44632 // See description above setter.
633 bool closed_by_user_gesture_;
634
635 // Minimum/maximum zoom percent.
636 int minimum_zoom_percent_;
637 int maximum_zoom_percent_;
638 // If true, the default zoom limits have been overriden for this tab, in which
639 // case we don't want saved settings to apply to it and we don't want to
640 // remember it.
641 bool temporary_zoom_settings_;
642
[email protected]bcd2815602012-01-14 18:17:23643 // The intrinsic size of the page.
644 gfx::Size preferred_size_;
645
[email protected]0dd3a0ab2011-02-18 08:17:44646 // Content restrictions, used to disable print/copy etc based on content's
647 // (full-page plugins for now only) permissions.
648 int content_restrictions_;
649
[email protected]32ded2212011-11-10 18:51:43650 // Our view type. Default is VIEW_TYPE_TAB_CONTENTS.
651 content::ViewType view_type_;
652
[email protected]0dd3a0ab2011-02-18 08:17:44653 DISALLOW_COPY_AND_ASSIGN(TabContents);
654};
655
656#endif // CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_H_