blob: 5dda23e323bd806975e4d91c205abc9649b3a1df [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]d202a7c2012-01-04 07:53:4720#include "content/browser/tab_contents/navigation_controller_impl.h"
[email protected]0dd3a0ab2011-02-18 08:17:4421#include "content/browser/tab_contents/render_view_host_manager.h"
[email protected]8d128d62011-09-13 22:11:5722#include "content/common/content_export.h"
[email protected]b0b67cf2012-01-18 21:59:5723#include "content/public/browser/render_view_host_delegate.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;
[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]d8c660432011-12-22 20:51:2543class WebContentsObserver;
[email protected]674bc592011-12-20 23:00:4244class WebContentsDelegate;
[email protected]8643e6d2012-01-18 20:26:1045class WebContentsView;
[email protected]e582fdd2011-12-20 16:48:1746}
47
[email protected]daf82f82011-10-31 22:35:3148namespace webkit_glue {
49struct WebIntentData;
50}
[email protected]0dd3a0ab2011-02-18 08:17:4451
[email protected]01d65172011-12-25 04:39:3052class CONTENT_EXPORT TabContents
53 : public NON_EXPORTED_BASE(content::WebContents),
[email protected]b0b67cf2012-01-18 21:59:5754 public content::RenderViewHostDelegate,
[email protected]01d65172011-12-25 04:39:3055 public RenderViewHostManager::Delegate,
56 public content::JavaScriptDialogDelegate {
[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]c7dd2f62011-07-18 15:57:5966 // Returns the SavePackage which manages the page saving job. May be NULL.
67 SavePackage* save_package() const { return save_package_.get(); }
68
[email protected]74ce1ad2011-12-16 21:51:4669 // Updates the max page ID for the current SiteInstance in this TabContents
70 // to be at least |page_id|.
[email protected]0dd3a0ab2011-02-18 08:17:4471 void UpdateMaxPageID(int32 page_id);
72
[email protected]74ce1ad2011-12-16 21:51:4673 // Updates the max page ID for the given SiteInstance in this TabContents
74 // to be at least |page_id|.
[email protected]b6583592012-01-25 19:52:3375 void UpdateMaxPageIDForSiteInstance(content::SiteInstance* site_instance,
[email protected]74ce1ad2011-12-16 21:51:4676 int32 page_id);
77
[email protected]91854cd2012-01-10 19:43:5778 // Copy the current map of SiteInstance ID to max page ID from another tab.
79 // This is necessary when this tab adopts the NavigationEntries from
80 // |tab_contents|.
81 void CopyMaxPageIDsFrom(TabContents* tab_contents);
82
[email protected]0dd3a0ab2011-02-18 08:17:4483 // Called by the NavigationController to cause the TabContents to navigate to
84 // the current pending entry. The NavigationController should be called back
[email protected]9a7e68c2011-05-26 17:35:5085 // with RendererDidNavigate on success or DiscardPendingEntry on failure.
86 // The callbacks can be inside of this function, or at some future time.
[email protected]0dd3a0ab2011-02-18 08:17:4487 //
88 // The entry has a PageID of -1 if newly created (corresponding to navigation
89 // to a new URL).
90 //
91 // If this method returns false, then the navigation is discarded (equivalent
92 // to calling DiscardPendingEntry on the NavigationController).
[email protected]0bfbf882011-12-22 18:19:2793 bool NavigateToPendingEntry(
[email protected]71fde352011-12-29 03:29:5694 content::NavigationController::ReloadType reload_type);
[email protected]0dd3a0ab2011-02-18 08:17:4495
[email protected]0dd3a0ab2011-02-18 08:17:4496 // Sets the passed passed interstitial as the currently showing interstitial.
97 // |interstitial_page| should be non NULL (use the remove_interstitial_page
98 // method to unset the interstitial) and no interstitial page should be set
99 // when there is already a non NULL interstitial page set.
100 void set_interstitial_page(InterstitialPage* interstitial_page) {
101 render_manager_.set_interstitial_page(interstitial_page);
102 }
103
104 // Unsets the currently showing interstitial.
105 void remove_interstitial_page() {
106 render_manager_.remove_interstitial_page();
107 }
108
[email protected]01ec4ec2012-01-18 04:13:47109 void set_opener_web_ui_type(content::WebUI::TypeID opener_web_ui_type) {
[email protected]0dd3a0ab2011-02-18 08:17:44110 opener_web_ui_type_ = opener_web_ui_type;
111 }
112
[email protected]276b37a22011-11-08 20:45:46113 JavaBridgeDispatcherHostManager* java_bridge_dispatcher_host_manager() const {
114 return java_bridge_dispatcher_host_manager_.get();
115 }
116
[email protected]cdcb1dee2012-01-04 00:46:20117 // Like GetController from WebContents, but returns the concrete object.
[email protected]d202a7c2012-01-04 07:53:47118 NavigationControllerImpl& GetControllerImpl();
[email protected]cdcb1dee2012-01-04 00:46:20119
[email protected]765187182012-01-11 23:59:28120 // Expose the render manager for testing.
121 RenderViewHostManager* GetRenderManagerForTesting();
122
[email protected]58f5d562011-12-20 17:13:03123 // content::WebContents ------------------------------------------------------
[email protected]6934a702011-12-20 00:04:51124 virtual const base::PropertyBag* GetPropertyBag() const OVERRIDE;
125 virtual base::PropertyBag* GetPropertyBag() OVERRIDE;
[email protected]674bc592011-12-20 23:00:42126 virtual content::WebContentsDelegate* GetDelegate() OVERRIDE;
127 virtual void SetDelegate(content::WebContentsDelegate* delegate) OVERRIDE;
[email protected]cdcb1dee2012-01-04 00:46:20128 virtual content::NavigationController& GetController() OVERRIDE;
129 virtual const content::NavigationController& GetController() const OVERRIDE;
[email protected]627e0512011-12-21 22:55:30130 virtual content::BrowserContext* GetBrowserContext() const OVERRIDE;
[email protected]f5fa20e2011-12-21 22:35:56131 virtual void SetViewType(content::ViewType type) OVERRIDE;
[email protected]ea049a02011-12-25 21:37:09132 virtual content::ViewType GetViewType() const OVERRIDE;
[email protected]f5fa20e2011-12-21 22:35:56133 virtual content::RenderProcessHost* GetRenderProcessHost() const OVERRIDE;
[email protected]151a63d2011-12-20 22:32:52134 virtual RenderViewHost* GetRenderViewHost() const OVERRIDE;
[email protected]d487beefe2011-12-21 05:41:21135 virtual RenderWidgetHostView* GetRenderWidgetHostView() const OVERRIDE;
[email protected]8643e6d2012-01-18 20:26:10136 virtual content::WebContentsView* GetView() const OVERRIDE;
[email protected]01ec4ec2012-01-18 04:13:47137 virtual content::WebUI* CreateWebUI(const GURL& url) OVERRIDE;
138 virtual content::WebUI* GetWebUI() const OVERRIDE;
139 virtual content::WebUI* GetCommittedWebUI() const OVERRIDE;
[email protected]be1f56ab2011-12-22 06:55:31140 virtual const string16& GetTitle() const OVERRIDE;
141 virtual int32 GetMaxPageID() OVERRIDE;
142 virtual int32 GetMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33143 content::SiteInstance* site_instance) OVERRIDE;
144 virtual content::SiteInstance* GetSiteInstance() const OVERRIDE;
145 virtual content::SiteInstance* GetPendingSiteInstance() const OVERRIDE;
[email protected]be1f56ab2011-12-22 06:55:31146 virtual bool IsLoading() const OVERRIDE;
147 virtual bool IsWaitingForResponse() const OVERRIDE;
148 virtual const net::LoadStateWithParam& GetLoadState() const OVERRIDE;
149 virtual const string16& GetLoadStateHost() const OVERRIDE;
150 virtual uint64 GetUploadSize() const OVERRIDE;
151 virtual uint64 GetUploadPosition() const OVERRIDE;
152 virtual const std::string& GetEncoding() const OVERRIDE;
153 virtual bool DisplayedInsecureContent() const OVERRIDE;
154 virtual void SetCapturingContents(bool cap) OVERRIDE;
155 virtual bool IsCrashed() const OVERRIDE;
156 virtual void SetIsCrashed(base::TerminationStatus status,
157 int error_code) OVERRIDE;
158 virtual base::TerminationStatus GetCrashedStatus() const OVERRIDE;
159 virtual bool IsBeingDestroyed() const OVERRIDE;
160 virtual void NotifyNavigationStateChanged(unsigned changed_flags) OVERRIDE;
161 virtual void DidBecomeSelected() OVERRIDE;
162 virtual base::TimeTicks GetLastSelectedTime() const OVERRIDE;
163 virtual void WasHidden() OVERRIDE;
164 virtual void ShowContents() OVERRIDE;
165 virtual void HideContents() OVERRIDE;
166 virtual bool NeedToFireBeforeUnload() OVERRIDE;
[email protected]0bfbf882011-12-22 18:19:27167 virtual void Stop() OVERRIDE;
[email protected]d9083482012-01-06 00:38:46168 virtual content::WebContents* Clone() OVERRIDE;
[email protected]0bfbf882011-12-22 18:19:27169 virtual void ShowPageInfo(const GURL& url,
[email protected]d583e3f22011-12-27 21:38:17170 const content::SSLStatus& ssl,
[email protected]0bfbf882011-12-22 18:19:27171 bool show_history) OVERRIDE;
[email protected]2a6bc3e2011-12-28 23:51:33172 virtual void AddNewContents(content::WebContents* new_contents,
[email protected]0bfbf882011-12-22 18:19:27173 WindowOpenDisposition disposition,
174 const gfx::Rect& initial_pos,
175 bool user_gesture) OVERRIDE;
176 virtual gfx::NativeView GetContentNativeView() const OVERRIDE;
177 virtual gfx::NativeView GetNativeView() const OVERRIDE;
178 virtual void GetContainerBounds(gfx::Rect* out) const OVERRIDE;
179 virtual void Focus() OVERRIDE;
180 virtual void FocusThroughTabTraversal(bool reverse) OVERRIDE;
181 virtual bool ShowingInterstitialPage() const OVERRIDE;
182 virtual InterstitialPage* GetInterstitialPage() const OVERRIDE;
[email protected]a53209b2012-01-20 16:48:16183 virtual bool IsSavable() OVERRIDE;
[email protected]0bfbf882011-12-22 18:19:27184 virtual void OnSavePage() OVERRIDE;
185 virtual bool SavePage(const FilePath& main_file,
186 const FilePath& dir_path,
[email protected]a53209b2012-01-20 16:48:16187 content::SavePageType save_type) OVERRIDE;
[email protected]0bfbf882011-12-22 18:19:27188 virtual bool IsActiveEntry(int32 page_id) OVERRIDE;
189
190 virtual const std::string& GetContentsMimeType() const OVERRIDE;
191 virtual bool WillNotifyDisconnection() const OVERRIDE;
192 virtual void SetOverrideEncoding(const std::string& encoding) OVERRIDE;
193 virtual void ResetOverrideEncoding() OVERRIDE;
194 virtual content::RendererPreferences* GetMutableRendererPrefs() OVERRIDE;
195 virtual void SetNewTabStartTime(const base::TimeTicks& time) OVERRIDE;
196 virtual base::TimeTicks GetNewTabStartTime() const OVERRIDE;
197 virtual void OnCloseStarted() OVERRIDE;
198 virtual bool ShouldAcceptDragAndDrop() const OVERRIDE;
199 virtual void SystemDragEnded() OVERRIDE;
200 virtual void SetClosedByUserGesture(bool value) OVERRIDE;
201 virtual bool GetClosedByUserGesture() const OVERRIDE;
202 virtual double GetZoomLevel() const OVERRIDE;
203 virtual int GetZoomPercent(bool* enable_increment,
204 bool* enable_decrement) OVERRIDE;
205 virtual void ViewSource() OVERRIDE;
206 virtual void ViewFrameSource(const GURL& url,
207 const std::string& content_state) OVERRIDE;
208 virtual int GetMinimumZoomPercent() const OVERRIDE;
209 virtual int GetMaximumZoomPercent() const OVERRIDE;
[email protected]bcd2815602012-01-14 18:17:23210 virtual gfx::Size GetPreferredSize() const OVERRIDE;
[email protected]0bfbf882011-12-22 18:19:27211 virtual int GetContentRestrictions() const OVERRIDE;
[email protected]01ec4ec2012-01-18 04:13:47212 virtual content::WebUI::TypeID GetWebUITypeForCurrentState() OVERRIDE;
213 virtual content::WebUI* GetWebUIForCurrentState() OVERRIDE;
[email protected]0bfbf882011-12-22 18:19:27214 virtual bool GotResponseToLockMouseRequest(bool allowed) OVERRIDE;
215
216 // Implementation of PageNavigator.
[email protected]e5d549d2011-12-28 01:29:20217 virtual content::WebContents* OpenURL(
218 const content::OpenURLParams& params) OVERRIDE;
[email protected]151a63d2011-12-20 22:32:52219
[email protected]952a68e2011-11-17 00:36:10220 // RenderViewHostDelegate ----------------------------------------------------
221
[email protected]b0b67cf2012-01-18 21:59:57222 virtual content::RenderViewHostDelegate::View* GetViewDelegate() OVERRIDE;
223 virtual content::RenderViewHostDelegate::RendererManagement*
[email protected]952a68e2011-11-17 00:36:10224 GetRendererManagementDelegate() OVERRIDE;
[email protected]be1f56ab2011-12-22 06:55:31225 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
226 virtual const GURL& GetURL() const OVERRIDE;
[email protected]768c5472011-12-26 19:06:17227 virtual WebContents* GetAsWebContents() OVERRIDE;
[email protected]952a68e2011-11-17 00:36:10228 virtual content::ViewType GetRenderViewType() const OVERRIDE;
[email protected]b7a756d42012-01-23 18:08:17229 virtual gfx::Rect GetRootWindowResizerRect() const OVERRIDE;
[email protected]952a68e2011-11-17 00:36:10230 virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE;
231 virtual void RenderViewReady(RenderViewHost* render_view_host) OVERRIDE;
232 virtual void RenderViewGone(RenderViewHost* render_view_host,
233 base::TerminationStatus status,
234 int error_code) OVERRIDE;
235 virtual void RenderViewDeleted(RenderViewHost* render_view_host) OVERRIDE;
236 virtual void DidNavigate(
237 RenderViewHost* render_view_host,
238 const ViewHostMsg_FrameNavigate_Params& params) OVERRIDE;
239 virtual void UpdateState(RenderViewHost* render_view_host,
240 int32 page_id,
241 const std::string& state) OVERRIDE;
242 virtual void UpdateTitle(RenderViewHost* render_view_host,
243 int32 page_id,
244 const string16& title,
245 base::i18n::TextDirection title_direction) OVERRIDE;
246 virtual void UpdateEncoding(RenderViewHost* render_view_host,
247 const std::string& encoding) OVERRIDE;
248 virtual void UpdateTargetURL(int32 page_id, const GURL& url) OVERRIDE;
249 virtual void Close(RenderViewHost* render_view_host) OVERRIDE;
250 virtual void RequestMove(const gfx::Rect& new_bounds) OVERRIDE;
251 virtual void SwappedOut(RenderViewHost* render_view_host) OVERRIDE;
252 virtual void DidStartLoading() OVERRIDE;
253 virtual void DidStopLoading() OVERRIDE;
254 virtual void DidCancelLoading() OVERRIDE;
255 virtual void DidChangeLoadProgress(double progress) OVERRIDE;
256 virtual void DocumentAvailableInMainFrame(
257 RenderViewHost* render_view_host) OVERRIDE;
258 virtual void DocumentOnLoadCompletedInMainFrame(
259 RenderViewHost* render_view_host,
260 int32 page_id) OVERRIDE;
261 virtual void RequestOpenURL(const GURL& url,
[email protected]445e1042011-12-03 21:03:15262 const content::Referrer& referrer,
[email protected]952a68e2011-11-17 00:36:10263 WindowOpenDisposition disposition,
264 int64 source_frame_id) OVERRIDE;
[email protected]4ad5d77d2011-12-03 02:00:48265 virtual void RequestTransferURL(
266 const GURL& url,
[email protected]bce1f1c2011-12-05 15:11:58267 const content::Referrer& referrer,
[email protected]4ad5d77d2011-12-03 02:00:48268 WindowOpenDisposition disposition,
269 int64 source_frame_id,
[email protected]e5d549d2011-12-28 01:29:20270 const content::GlobalRequestID& transferred_global_request_id) OVERRIDE;
[email protected]952a68e2011-11-17 00:36:10271 virtual void RunJavaScriptMessage(const RenderViewHost* rvh,
272 const string16& message,
273 const string16& default_prompt,
274 const GURL& frame_url,
[email protected]269f86d2011-12-07 02:43:47275 ui::JavascriptMessageType type,
[email protected]952a68e2011-11-17 00:36:10276 IPC::Message* reply_msg,
277 bool* did_suppress_message) OVERRIDE;
278 virtual void RunBeforeUnloadConfirm(const RenderViewHost* rvh,
279 const string16& message,
280 IPC::Message* reply_msg) OVERRIDE;
281 virtual content::RendererPreferences GetRendererPrefs(
282 content::BrowserContext* browser_context) const OVERRIDE;
283 virtual WebPreferences GetWebkitPrefs() OVERRIDE;
284 virtual void OnUserGesture() OVERRIDE;
285 virtual void OnIgnoredUIEvent() OVERRIDE;
286 virtual void RendererUnresponsive(RenderViewHost* render_view_host,
287 bool is_during_unload) OVERRIDE;
288 virtual void RendererResponsive(RenderViewHost* render_view_host) OVERRIDE;
289 virtual void LoadStateChanged(const GURL& url,
290 const net::LoadStateWithParam& load_state,
291 uint64 upload_position,
292 uint64 upload_size) OVERRIDE;
293 virtual void WorkerCrashed() OVERRIDE;
294 virtual void Activate() OVERRIDE;
295 virtual void Deactivate() OVERRIDE;
296 virtual void LostCapture() OVERRIDE;
297 virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
298 bool* is_keyboard_shortcut) OVERRIDE;
299 virtual void HandleKeyboardEvent(
300 const NativeWebKeyboardEvent& event) OVERRIDE;
301 virtual void HandleMouseDown() OVERRIDE;
302 virtual void HandleMouseUp() OVERRIDE;
303 virtual void HandleMouseActivate() OVERRIDE;
[email protected]edc64de2011-11-17 20:07:38304 virtual void RunFileChooser(
305 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23306 const content::FileChooserParams& params) OVERRIDE;
[email protected]952a68e2011-11-17 00:36:10307 virtual void ToggleFullscreenMode(bool enter_fullscreen) OVERRIDE;
308 virtual bool IsFullscreenForCurrentTab() const OVERRIDE;
309 virtual void UpdatePreferredSize(const gfx::Size& pref_size) OVERRIDE;
310 virtual void WebUISend(RenderViewHost* render_view_host,
311 const GURL& source_url,
312 const std::string& name,
313 const base::ListValue& args) OVERRIDE;
314 virtual void RequestToLockMouse() OVERRIDE;
315 virtual void LostMouseLock() OVERRIDE;
316
[email protected]0bfbf882011-12-22 18:19:27317 // RenderViewHostManager::Delegate -------------------------------------------
318
319 virtual bool CreateRenderViewForRenderManager(
320 RenderViewHost* render_view_host) OVERRIDE;
321 virtual void BeforeUnloadFiredFromRenderManager(
322 bool proceed,
323 bool* proceed_to_fire_unload) OVERRIDE;
324 virtual void DidStartLoadingFromRenderManager(
325 RenderViewHost* render_view_host) OVERRIDE;
326 virtual void RenderViewGoneFromRenderManager(
327 RenderViewHost* render_view_host) OVERRIDE;
328 virtual void UpdateRenderViewSizeForRenderManager() OVERRIDE;
329 virtual void NotifySwappedFromRenderManager() OVERRIDE;
[email protected]d202a7c2012-01-04 07:53:47330 virtual NavigationControllerImpl& GetControllerForRenderManager() OVERRIDE;
[email protected]d2353452012-01-19 19:53:56331 virtual WebUIImpl* CreateWebUIForRenderManager(const GURL& url) OVERRIDE;
[email protected]ad23a092011-12-28 07:02:04332 virtual content::NavigationEntry*
[email protected]0bfbf882011-12-22 18:19:27333 GetLastCommittedNavigationEntryForRenderManager() OVERRIDE;
334 virtual bool FocusLocationBarByDefault() OVERRIDE;
335 virtual void SetFocusToLocationBar(bool select_all) OVERRIDE;
336 virtual void CreateViewAndSetSizeForRVH(RenderViewHost* rvh) OVERRIDE;
337
338 // Overridden from JavaScriptDialogDelegate:
339 virtual void OnDialogClosed(IPC::Message* reply_msg,
340 bool success,
341 const string16& user_input) OVERRIDE;
342 virtual gfx::NativeWindow GetDialogRootWindow() const OVERRIDE;
343 virtual void OnDialogShown() OVERRIDE;
344
[email protected]0dd3a0ab2011-02-18 08:17:44345 protected:
[email protected]d8c660432011-12-22 20:51:25346 friend class content::WebContentsObserver;
[email protected]553602e12011-04-05 17:01:18347
348 // Add and remove observers for page navigation notifications. Adding or
349 // removing multiple times has no effect. The order in which notifications
350 // are sent to observers is undefined. Clients must be sure to remove the
351 // observer before they go away.
[email protected]d8c660432011-12-22 20:51:25352 void AddObserver(content::WebContentsObserver* observer);
353 void RemoveObserver(content::WebContentsObserver* observer);
[email protected]553602e12011-04-05 17:01:18354
[email protected]0dd3a0ab2011-02-18 08:17:44355 private:
[email protected]d202a7c2012-01-04 07:53:47356 friend class NavigationControllerImpl;
[email protected]0dd3a0ab2011-02-18 08:17:44357
358 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, NoJSMessageOnInterstitials);
359 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, UpdateTitle);
360 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, CrossSiteCantPreemptAfterUnload);
361 FRIEND_TEST_ALL_PREFIXES(FormStructureBrowserTest, HTMLFiles);
362 FRIEND_TEST_ALL_PREFIXES(NavigationControllerTest, HistoryNavigate);
363 FRIEND_TEST_ALL_PREFIXES(RenderViewHostManagerTest, PageDoesBackAndReload);
364
365 // Temporary until the view/contents separation is complete.
[email protected]8643e6d2012-01-18 20:26:10366 friend class content::WebContentsView;
[email protected]9a56a0d2011-05-13 19:03:31367#if defined(TOOLKIT_VIEWS)
[email protected]7e2cef52011-04-11 21:47:23368 friend class TabContentsViewViews;
[email protected]0dd3a0ab2011-02-18 08:17:44369#elif defined(OS_MACOSX)
370 friend class TabContentsViewMac;
371#elif defined(TOOLKIT_USES_GTK)
372 friend class TabContentsViewGtk;
373#endif
374
375 // So InterstitialPage can access SetIsLoading.
376 friend class InterstitialPage;
377
378 // TODO(brettw) TestTabContents shouldn't exist!
379 friend class TestTabContents;
380
[email protected]0dd3a0ab2011-02-18 08:17:44381 // Message handlers.
[email protected]8b5af492011-11-28 21:50:58382 void OnRegisterIntentService(const string16& action,
[email protected]63c239322011-10-31 23:56:30383 const string16& type,
384 const string16& href,
385 const string16& title,
386 const string16& disposition);
[email protected]678105012011-12-09 04:01:21387 void OnWebIntentDispatch(const webkit_glue::WebIntentData& intent,
[email protected]63c239322011-10-31 23:56:30388 int intent_id);
[email protected]0dd3a0ab2011-02-18 08:17:44389 void OnDidStartProvisionalLoadForFrame(int64 frame_id,
390 bool main_frame,
[email protected]57b9396c2011-10-07 19:11:59391 const GURL& opener_url,
[email protected]0dd3a0ab2011-02-18 08:17:44392 const GURL& url);
393 void OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]57b9396c2011-10-07 19:11:59394 const GURL& opener_url,
[email protected]0dd3a0ab2011-02-18 08:17:44395 const GURL& source_url,
396 const GURL& target_url);
[email protected]d7b175e2011-10-11 15:31:58397 void OnDidFailProvisionalLoadWithError(
398 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params);
[email protected]0dd3a0ab2011-02-18 08:17:44399 void OnDidLoadResourceFromMemoryCache(const GURL& url,
[email protected]70435962011-08-02 20:13:28400 const std::string& security_info,
401 const std::string& http_request,
402 ResourceType::Type resource_type);
[email protected]0dd3a0ab2011-02-18 08:17:44403 void OnDidDisplayInsecureContent();
404 void OnDidRunInsecureContent(const std::string& security_origin,
405 const GURL& target_url);
406 void OnDocumentLoadedInFrame(int64 frame_id);
[email protected]1a55c5be2011-11-29 11:36:31407 void OnDidFinishLoad(int64 frame_id,
408 const GURL& validated_url,
409 bool is_main_frame);
410 void OnDidFailLoadWithError(int64 frame_id,
411 const GURL& validated_url,
412 bool is_main_frame,
413 int error_code,
414 const string16& error_description);
[email protected]0dd3a0ab2011-02-18 08:17:44415 void OnUpdateContentRestrictions(int restrictions);
[email protected]0dd3a0ab2011-02-18 08:17:44416 void OnGoToEntryAtOffset(int offset);
[email protected]216813952011-05-19 22:21:26417 void OnUpdateZoomLimits(int minimum_percent,
418 int maximum_percent,
419 bool remember);
[email protected]0bfbf882011-12-22 18:19:27420 void OnSaveURL(const GURL& url);
[email protected]3a29a6e2011-08-24 18:26:21421 void OnEnumerateDirectory(int request_id, const FilePath& path);
[email protected]7d189022011-08-25 22:54:20422 void OnJSOutOfMemory();
[email protected]b7a756d42012-01-23 18:08:17423
[email protected]7d189022011-08-25 22:54:20424 void OnRegisterProtocolHandler(const std::string& protocol,
425 const GURL& url,
426 const string16& title);
[email protected]b888919c2011-09-02 00:32:16427 void OnFindReply(int request_id, int number_of_matches,
428 const gfx::Rect& selection_rect, int active_match_ordinal,
429 bool final_update);
[email protected]d952a052011-09-06 18:42:45430 void OnCrashedPlugin(const FilePath& plugin_path);
[email protected]7fc4bbb2011-09-08 21:23:10431 void OnAppCacheAccessed(const GURL& manifest_url, bool blocked_by_policy);
[email protected]0dd3a0ab2011-02-18 08:17:44432
433 // Changes the IsLoading state and notifies delegate as needed
434 // |details| is used to provide details on the load that just finished
435 // (but can be null if not applicable). Can be overridden.
436 void SetIsLoading(bool is_loading,
437 LoadNotificationDetails* details);
438
[email protected]0dd3a0ab2011-02-18 08:17:44439 // Called by derived classes to indicate that we're no longer waiting for a
440 // response. This won't actually update the throbber, but it will get picked
441 // up at the next animation step if the throbber is going.
442 void SetNotWaitingForResponse() { waiting_for_response_ = false; }
443
[email protected]0dd3a0ab2011-02-18 08:17:44444 // Navigation helpers --------------------------------------------------------
445 //
446 // These functions are helpers for Navigate() and DidNavigate().
447
448 // Handles post-navigation tasks in DidNavigate AFTER the entry has been
449 // committed to the navigation controller. Note that the navigation entry is
450 // not provided since it may be invalid/changed after being committed. The
451 // current navigation entry is in the NavigationController at this point.
452 void DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:13453 const content::LoadCommittedDetails& details,
[email protected]0dd3a0ab2011-02-18 08:17:44454 const ViewHostMsg_FrameNavigate_Params& params);
455 void DidNavigateAnyFramePostCommit(
456 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:13457 const content::LoadCommittedDetails& details,
[email protected]0dd3a0ab2011-02-18 08:17:44458 const ViewHostMsg_FrameNavigate_Params& params);
459
[email protected]74ce1ad2011-12-16 21:51:46460 // If our controller was restored, update the max page ID associated with the
461 // given RenderViewHost to be larger than the number of restored entries.
462 // This is called in CreateRenderView before any navigations in the RenderView
463 // have begun, to prevent any races in updating RenderView::next_page_id.
464 void UpdateMaxPageIDIfNecessary(RenderViewHost* rvh);
[email protected]0dd3a0ab2011-02-18 08:17:44465
[email protected]0dd3a0ab2011-02-18 08:17:44466 // Saves the given title to the navigation entry and does associated work. It
467 // will update history and the view for the new title, and also synthesize
468 // titles for file URLs that have none (so we require that the URL of the
469 // entry already be set).
470 //
471 // This is used as the backend for state updates, which include a new title,
472 // or the dedicated set title message. It returns true if the new title is
473 // different and was therefore updated.
[email protected]10f417c52011-12-28 21:04:23474 bool UpdateTitleForEntry(content::NavigationEntryImpl* entry,
475 const string16& title);
[email protected]0dd3a0ab2011-02-18 08:17:44476
477 // Causes the TabContents to navigate in the right renderer to |entry|, which
478 // must be already part of the entries in the navigation controller.
479 // This does not change the NavigationController state.
[email protected]10f417c52011-12-28 21:04:23480 bool NavigateToEntry(const content::NavigationEntryImpl& entry,
[email protected]71fde352011-12-29 03:29:56481 content::NavigationController::ReloadType reload_type);
[email protected]0dd3a0ab2011-02-18 08:17:44482
[email protected]796931a92011-08-10 01:32:14483 // Sets the history for this tab_contents to |history_length| entries, and
484 // moves the current page_id to the last entry in the list if it's valid.
485 // This is mainly used when a prerendered page is swapped into the current
[email protected]9e1ad4b2011-08-14 16:49:19486 // tab. The method is virtual for testing.
[email protected]b6583592012-01-25 19:52:33487 virtual void SetHistoryLengthAndPrune(
488 const content::SiteInstance* site_instance,
489 int merge_history_length,
490 int32 minimum_page_id);
[email protected]796931a92011-08-10 01:32:14491
[email protected]0dd3a0ab2011-02-18 08:17:44492 // Misc non-view stuff -------------------------------------------------------
493
494 // Helper functions for sending notifications.
495 void NotifySwapped();
496 void NotifyConnected();
497 void NotifyDisconnected();
498
[email protected]be1f56ab2011-12-22 06:55:31499 void SetEncoding(const std::string& encoding);
500
[email protected]81898992011-06-14 22:15:00501 // Stores random bits of data for others to associate with this object.
502 // WARNING: this needs to be deleted after NavigationController.
[email protected]45644f62011-11-23 00:58:23503 base::PropertyBag property_bag_;
[email protected]81898992011-06-14 22:15:00504
[email protected]0dd3a0ab2011-02-18 08:17:44505 // Data for core operation ---------------------------------------------------
506
507 // Delegate for notifying our owner about stuff. Not owned by us.
[email protected]674bc592011-12-20 23:00:42508 content::WebContentsDelegate* delegate_;
[email protected]0dd3a0ab2011-02-18 08:17:44509
510 // Handles the back/forward list and loading.
[email protected]d202a7c2012-01-04 07:53:47511 NavigationControllerImpl controller_;
[email protected]0dd3a0ab2011-02-18 08:17:44512
513 // The corresponding view.
[email protected]8643e6d2012-01-18 20:26:10514 scoped_ptr<content::WebContentsView> view_;
[email protected]0dd3a0ab2011-02-18 08:17:44515
[email protected]996042972011-11-08 22:43:59516 // A list of observers notified when page state changes. Weak references.
517 // This MUST be listed above render_manager_ since at destruction time the
518 // latter might cause RenderViewHost's destructor to call us and we might use
519 // the observer list then.
[email protected]d8c660432011-12-22 20:51:25520 ObserverList<content::WebContentsObserver> observers_;
[email protected]996042972011-11-08 22:43:59521
[email protected]0dd3a0ab2011-02-18 08:17:44522 // Helper classes ------------------------------------------------------------
523
524 // Manages creation and swapping of render views.
525 RenderViewHostManager render_manager_;
526
[email protected]483623eb2011-10-25 09:30:00527 // Manages injecting Java objects into all RenderViewHosts associated with
528 // this TabContents.
529 scoped_ptr<JavaBridgeDispatcherHostManager>
530 java_bridge_dispatcher_host_manager_;
531
[email protected]c7dd2f62011-07-18 15:57:59532 // SavePackage, lazily created.
533 scoped_refptr<SavePackage> save_package_;
534
[email protected]0dd3a0ab2011-02-18 08:17:44535 // Data for loading state ----------------------------------------------------
536
537 // Indicates whether we're currently loading a resource.
538 bool is_loading_;
539
540 // Indicates if the tab is considered crashed.
541 base::TerminationStatus crashed_status_;
542 int crashed_error_code_;
543
[email protected]be1f56ab2011-12-22 06:55:31544 // Whether this tab contents is waiting for a first-response for the
545 // main resource of the page. This controls whether the throbber state is
546 // "waiting" or "loading."
[email protected]0dd3a0ab2011-02-18 08:17:44547 bool waiting_for_response_;
548
[email protected]74ce1ad2011-12-16 21:51:46549 // Map of SiteInstance ID to max page ID for this tab. A page ID is specific
550 // to a given tab and SiteInstance, and must be valid for the lifetime of the
551 // TabContents.
552 std::map<int32, int32> max_page_ids_;
[email protected]0dd3a0ab2011-02-18 08:17:44553
554 // System time at which the current load was started.
555 base::TimeTicks current_load_start_;
556
557 // The current load state and the URL associated with it.
[email protected]9c235f042011-08-10 22:28:21558 net::LoadStateWithParam load_state_;
[email protected]0dd3a0ab2011-02-18 08:17:44559 string16 load_state_host_;
560 // Upload progress, for displaying in the status bar.
561 // Set to zero when there is no significant upload happening.
562 uint64 upload_size_;
563 uint64 upload_position_;
564
565 // Data for current page -----------------------------------------------------
566
[email protected]987fc3a2011-05-26 14:18:09567 // When a title cannot be taken from any entry, this title will be used.
568 string16 page_title_when_no_navigation_entry_;
569
[email protected]0dd3a0ab2011-02-18 08:17:44570 // When a navigation occurs, we record its contents MIME type. It can be
571 // used to check whether we can do something for some special contents.
572 std::string contents_mime_type_;
573
574 // Character encoding.
575 std::string encoding_;
576
[email protected]0dd3a0ab2011-02-18 08:17:44577 // True if this is a secure page which displayed insecure content.
578 bool displayed_insecure_content_;
579
[email protected]0dd3a0ab2011-02-18 08:17:44580 // Data for misc internal state ----------------------------------------------
581
[email protected]be1f56ab2011-12-22 06:55:31582 // Whether the tab contents is currently being screenshotted by the
583 // DraggedTabController.
[email protected]0dd3a0ab2011-02-18 08:17:44584 bool capturing_contents_;
585
586 // See getter above.
587 bool is_being_destroyed_;
588
589 // Indicates whether we should notify about disconnection of this
590 // TabContents. This is used to ensure disconnection notifications only
591 // happen if a connection notification has happened and that they happen only
592 // once.
593 bool notify_disconnection_;
594
[email protected]2e5b90c2011-08-16 21:11:55595 // Pointer to the JavaScript dialog creator, lazily assigned. Used because the
596 // delegate of this TabContents is nulled before its destructor is called.
597 content::JavaScriptDialogCreator* dialog_creator_;
598
[email protected]0dd3a0ab2011-02-18 08:17:44599#if defined(OS_WIN)
600 // Handle to an event that's set when the page is showing a message box (or
601 // equivalent constrained window). Plugin processes check this to know if
602 // they should pump messages then.
603 base::win::ScopedHandle message_box_active_;
604#endif
605
[email protected]0dd3a0ab2011-02-18 08:17:44606 // Set to true when there is an active "before unload" dialog. When true,
607 // we've forced the throbber to start in Navigate, and we need to remember to
608 // turn it off in OnJavaScriptMessageBoxClosed if the navigation is canceled.
609 bool is_showing_before_unload_dialog_;
610
[email protected]0dd3a0ab2011-02-18 08:17:44611 // Settings that get passed to the renderer process.
[email protected]daf82f82011-10-31 22:35:31612 content::RendererPreferences renderer_preferences_;
[email protected]0dd3a0ab2011-02-18 08:17:44613
614 // If this tab was created from a renderer using window.open, this will be
615 // non-NULL and represent the WebUI of the opening renderer.
[email protected]01ec4ec2012-01-18 04:13:47616 content::WebUI::TypeID opener_web_ui_type_;
[email protected]0dd3a0ab2011-02-18 08:17:44617
618 // The time that we started to create the new tab page.
619 base::TimeTicks new_tab_start_time_;
620
621 // The time that we started to close the tab.
622 base::TimeTicks tab_close_start_time_;
623
624 // The time that this tab was last selected.
625 base::TimeTicks last_selected_time_;
626
[email protected]0dd3a0ab2011-02-18 08:17:44627 // See description above setter.
628 bool closed_by_user_gesture_;
629
630 // Minimum/maximum zoom percent.
631 int minimum_zoom_percent_;
632 int maximum_zoom_percent_;
633 // If true, the default zoom limits have been overriden for this tab, in which
634 // case we don't want saved settings to apply to it and we don't want to
635 // remember it.
636 bool temporary_zoom_settings_;
637
[email protected]bcd2815602012-01-14 18:17:23638 // The intrinsic size of the page.
639 gfx::Size preferred_size_;
640
[email protected]0dd3a0ab2011-02-18 08:17:44641 // Content restrictions, used to disable print/copy etc based on content's
642 // (full-page plugins for now only) permissions.
643 int content_restrictions_;
644
[email protected]32ded2212011-11-10 18:51:43645 // Our view type. Default is VIEW_TYPE_TAB_CONTENTS.
646 content::ViewType view_type_;
647
[email protected]0dd3a0ab2011-02-18 08:17:44648 DISALLOW_COPY_AND_ASSIGN(TabContents);
649};
650
651#endif // CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_H_