blob: 892c62d0952c9630f0f21bbc01cd72487b8a7457 [file] [log] [blame]
[email protected]0dd3a0ab2011-02-18 08:17:441// Copyright (c) 2011 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_H_
6#define CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_H_
7#pragma once
8
9#include <deque>
10#include <map>
11#include <string>
[email protected]0dd3a0ab2011-02-18 08:17:4412
[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]0dd3a0ab2011-02-18 08:17:4421#include "content/browser/tab_contents/navigation_controller.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]674bc592011-12-20 23:00:4256 // Flags passed to the WebContentsDelegate.NavigationStateChanged to tell it
[email protected]0dd3a0ab2011-02-18 08:17:4457 // what has changed. Combine them to update more than one thing.
58 enum InvalidateTypes {
59 INVALIDATE_URL = 1 << 0, // The URL has changed.
60 INVALIDATE_TAB = 1 << 1, // The favicon, app icon, or crashed
61 // state changed.
62 INVALIDATE_LOAD = 1 << 2, // The loading state has changed.
63 INVALIDATE_PAGE_ACTIONS = 1 << 3, // Page action icons have changed.
[email protected]93f230e02011-06-01 14:40:0064 INVALIDATE_TITLE = 1 << 4, // The title changed.
[email protected]0dd3a0ab2011-02-18 08:17:4465 };
66
67 // |base_tab_contents| is used if we want to size the new tab contents view
68 // based on an existing tab contents view. This can be NULL if not needed.
69 //
70 // The session storage namespace parameter allows multiple render views and
71 // tab contentses to share the same session storage (part of the WebStorage
72 // spec) space. This is useful when restoring tabs, but most callers should
73 // pass in NULL which will cause a new SessionStorageNamespace to be created.
[email protected]3d7474ff2011-07-27 17:47:3774 TabContents(content::BrowserContext* browser_context,
[email protected]0dd3a0ab2011-02-18 08:17:4475 SiteInstance* site_instance,
76 int routing_id,
77 const TabContents* base_tab_contents,
78 SessionStorageNamespace* session_storage_namespace);
79 virtual ~TabContents();
80
[email protected]c7dd2f62011-07-18 15:57:5981 // Returns the SavePackage which manages the page saving job. May be NULL.
82 SavePackage* save_package() const { return save_package_.get(); }
83
[email protected]74ce1ad2011-12-16 21:51:4684 // Updates the max page ID for the current SiteInstance in this TabContents
85 // to be at least |page_id|.
[email protected]0dd3a0ab2011-02-18 08:17:4486 void UpdateMaxPageID(int32 page_id);
87
[email protected]74ce1ad2011-12-16 21:51:4688 // Updates the max page ID for the given SiteInstance in this TabContents
89 // to be at least |page_id|.
90 void UpdateMaxPageIDForSiteInstance(SiteInstance* site_instance,
91 int32 page_id);
92
[email protected]0dd3a0ab2011-02-18 08:17:4493 // Called by the NavigationController to cause the TabContents to navigate to
94 // the current pending entry. The NavigationController should be called back
[email protected]9a7e68c2011-05-26 17:35:5095 // with RendererDidNavigate on success or DiscardPendingEntry on failure.
96 // The callbacks can be inside of this function, or at some future time.
[email protected]0dd3a0ab2011-02-18 08:17:4497 //
98 // The entry has a PageID of -1 if newly created (corresponding to navigation
99 // to a new URL).
100 //
101 // If this method returns false, then the navigation is discarded (equivalent
102 // to calling DiscardPendingEntry on the NavigationController).
[email protected]0bfbf882011-12-22 18:19:27103 bool NavigateToPendingEntry(
[email protected]0dd3a0ab2011-02-18 08:17:44104 NavigationController::ReloadType reload_type);
105
[email protected]0dd3a0ab2011-02-18 08:17:44106 // Sets the passed passed interstitial as the currently showing interstitial.
107 // |interstitial_page| should be non NULL (use the remove_interstitial_page
108 // method to unset the interstitial) and no interstitial page should be set
109 // when there is already a non NULL interstitial page set.
110 void set_interstitial_page(InterstitialPage* interstitial_page) {
111 render_manager_.set_interstitial_page(interstitial_page);
112 }
113
114 // Unsets the currently showing interstitial.
115 void remove_interstitial_page() {
116 render_manager_.remove_interstitial_page();
117 }
118
[email protected]1fd1a502011-03-30 16:55:56119 void set_opener_web_ui_type(WebUI::TypeID opener_web_ui_type) {
[email protected]0dd3a0ab2011-02-18 08:17:44120 opener_web_ui_type_ = opener_web_ui_type;
121 }
122
[email protected]276b37a22011-11-08 20:45:46123 JavaBridgeDispatcherHostManager* java_bridge_dispatcher_host_manager() const {
124 return java_bridge_dispatcher_host_manager_.get();
125 }
126
[email protected]58f5d562011-12-20 17:13:03127 // content::WebContents ------------------------------------------------------
[email protected]6934a702011-12-20 00:04:51128 virtual const base::PropertyBag* GetPropertyBag() const OVERRIDE;
129 virtual base::PropertyBag* GetPropertyBag() OVERRIDE;
[email protected]674bc592011-12-20 23:00:42130 virtual content::WebContentsDelegate* GetDelegate() OVERRIDE;
131 virtual void SetDelegate(content::WebContentsDelegate* delegate) OVERRIDE;
[email protected]f5fa20e2011-12-21 22:35:56132 virtual NavigationController& GetController() OVERRIDE;
133 virtual const NavigationController& GetController() const OVERRIDE;
[email protected]627e0512011-12-21 22:55:30134 virtual content::BrowserContext* GetBrowserContext() const OVERRIDE;
[email protected]f5fa20e2011-12-21 22:35:56135 virtual void SetViewType(content::ViewType type) OVERRIDE;
[email protected]ea049a02011-12-25 21:37:09136 virtual content::ViewType GetViewType() const OVERRIDE;
[email protected]f5fa20e2011-12-21 22:35:56137 virtual content::RenderProcessHost* GetRenderProcessHost() const OVERRIDE;
[email protected]151a63d2011-12-20 22:32:52138 virtual RenderViewHost* GetRenderViewHost() const OVERRIDE;
[email protected]d487beefe2011-12-21 05:41:21139 virtual RenderWidgetHostView* GetRenderWidgetHostView() const OVERRIDE;
140 virtual TabContentsView* GetView() const OVERRIDE;
[email protected]be1f56ab2011-12-22 06:55:31141 virtual WebUI* GetWebUI() const OVERRIDE;
142 virtual WebUI* GetCommittedWebUI() const OVERRIDE;
143 virtual const string16& GetTitle() const OVERRIDE;
144 virtual int32 GetMaxPageID() OVERRIDE;
145 virtual int32 GetMaxPageIDForSiteInstance(
146 SiteInstance* site_instance) OVERRIDE;
147 virtual SiteInstance* GetSiteInstance() const OVERRIDE;
148 virtual SiteInstance* GetPendingSiteInstance() const OVERRIDE;
149 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;
170 virtual RenderViewHostManager* GetRenderManagerForTesting() OVERRIDE;
[email protected]0bfbf882011-12-22 18:19:27171 virtual void Stop() OVERRIDE;
172 virtual TabContents* Clone() OVERRIDE;
173 virtual void ShowPageInfo(const GURL& url,
174 const NavigationEntry::SSLStatus& ssl,
175 bool show_history) OVERRIDE;
176 virtual void AddNewContents(TabContents* new_contents,
177 WindowOpenDisposition disposition,
178 const gfx::Rect& initial_pos,
179 bool user_gesture) OVERRIDE;
180 virtual gfx::NativeView GetContentNativeView() const OVERRIDE;
181 virtual gfx::NativeView GetNativeView() const OVERRIDE;
182 virtual void GetContainerBounds(gfx::Rect* out) const OVERRIDE;
183 virtual void Focus() OVERRIDE;
184 virtual void FocusThroughTabTraversal(bool reverse) OVERRIDE;
185 virtual bool ShowingInterstitialPage() const OVERRIDE;
186 virtual InterstitialPage* GetInterstitialPage() const OVERRIDE;
187 virtual void OnSavePage() OVERRIDE;
188 virtual bool SavePage(const FilePath& main_file,
189 const FilePath& dir_path,
190 SavePackage::SavePackageType save_type) OVERRIDE;
191 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;
213 virtual int GetContentRestrictions() const OVERRIDE;
214 virtual WebUI::TypeID GetWebUITypeForCurrentState() OVERRIDE;
215 virtual WebUI* GetWebUIForCurrentState() OVERRIDE;
216 virtual bool GotResponseToLockMouseRequest(bool allowed) OVERRIDE;
217
218 // Implementation of PageNavigator.
219
220 // Deprecated. Please use the one-argument variant instead.
221 // TODO(adriansc): Remove this method once refactoring changed all call sites.
222 virtual TabContents* OpenURL(const GURL& url,
223 const GURL& referrer,
224 WindowOpenDisposition disposition,
225 content::PageTransition transition) OVERRIDE;
226
227 virtual TabContents* OpenURL(const OpenURLParams& params) OVERRIDE;
[email protected]151a63d2011-12-20 22:32:52228
[email protected]952a68e2011-11-17 00:36:10229 // RenderViewHostDelegate ----------------------------------------------------
230
231 virtual RenderViewHostDelegate::View* GetViewDelegate() OVERRIDE;
232 virtual RenderViewHostDelegate::RendererManagement*
233 GetRendererManagementDelegate() OVERRIDE;
[email protected]be1f56ab2011-12-22 06:55:31234 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
235 virtual const GURL& GetURL() const OVERRIDE;
[email protected]952a68e2011-11-17 00:36:10236 virtual TabContents* GetAsTabContents() OVERRIDE;
[email protected]768c5472011-12-26 19:06:17237 virtual WebContents* GetAsWebContents() OVERRIDE;
[email protected]952a68e2011-11-17 00:36:10238 virtual content::ViewType GetRenderViewType() const OVERRIDE;
239 virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE;
240 virtual void RenderViewReady(RenderViewHost* render_view_host) OVERRIDE;
241 virtual void RenderViewGone(RenderViewHost* render_view_host,
242 base::TerminationStatus status,
243 int error_code) OVERRIDE;
244 virtual void RenderViewDeleted(RenderViewHost* render_view_host) OVERRIDE;
245 virtual void DidNavigate(
246 RenderViewHost* render_view_host,
247 const ViewHostMsg_FrameNavigate_Params& params) OVERRIDE;
248 virtual void UpdateState(RenderViewHost* render_view_host,
249 int32 page_id,
250 const std::string& state) OVERRIDE;
251 virtual void UpdateTitle(RenderViewHost* render_view_host,
252 int32 page_id,
253 const string16& title,
254 base::i18n::TextDirection title_direction) OVERRIDE;
255 virtual void UpdateEncoding(RenderViewHost* render_view_host,
256 const std::string& encoding) OVERRIDE;
257 virtual void UpdateTargetURL(int32 page_id, const GURL& url) OVERRIDE;
258 virtual void Close(RenderViewHost* render_view_host) OVERRIDE;
259 virtual void RequestMove(const gfx::Rect& new_bounds) OVERRIDE;
260 virtual void SwappedOut(RenderViewHost* render_view_host) OVERRIDE;
261 virtual void DidStartLoading() OVERRIDE;
262 virtual void DidStopLoading() OVERRIDE;
263 virtual void DidCancelLoading() OVERRIDE;
264 virtual void DidChangeLoadProgress(double progress) OVERRIDE;
265 virtual void DocumentAvailableInMainFrame(
266 RenderViewHost* render_view_host) OVERRIDE;
267 virtual void DocumentOnLoadCompletedInMainFrame(
268 RenderViewHost* render_view_host,
269 int32 page_id) OVERRIDE;
270 virtual void RequestOpenURL(const GURL& url,
[email protected]445e1042011-12-03 21:03:15271 const content::Referrer& referrer,
[email protected]952a68e2011-11-17 00:36:10272 WindowOpenDisposition disposition,
273 int64 source_frame_id) OVERRIDE;
[email protected]4ad5d77d2011-12-03 02:00:48274 virtual void RequestTransferURL(
275 const GURL& url,
[email protected]bce1f1c2011-12-05 15:11:58276 const content::Referrer& referrer,
[email protected]4ad5d77d2011-12-03 02:00:48277 WindowOpenDisposition disposition,
278 int64 source_frame_id,
279 const GlobalRequestID& transferred_global_request_id) OVERRIDE;
[email protected]952a68e2011-11-17 00:36:10280 virtual void RunJavaScriptMessage(const RenderViewHost* rvh,
281 const string16& message,
282 const string16& default_prompt,
283 const GURL& frame_url,
[email protected]269f86d2011-12-07 02:43:47284 ui::JavascriptMessageType type,
[email protected]952a68e2011-11-17 00:36:10285 IPC::Message* reply_msg,
286 bool* did_suppress_message) OVERRIDE;
287 virtual void RunBeforeUnloadConfirm(const RenderViewHost* rvh,
288 const string16& message,
289 IPC::Message* reply_msg) OVERRIDE;
290 virtual content::RendererPreferences GetRendererPrefs(
291 content::BrowserContext* browser_context) const OVERRIDE;
292 virtual WebPreferences GetWebkitPrefs() OVERRIDE;
293 virtual void OnUserGesture() OVERRIDE;
294 virtual void OnIgnoredUIEvent() OVERRIDE;
295 virtual void RendererUnresponsive(RenderViewHost* render_view_host,
296 bool is_during_unload) OVERRIDE;
297 virtual void RendererResponsive(RenderViewHost* render_view_host) OVERRIDE;
298 virtual void LoadStateChanged(const GURL& url,
299 const net::LoadStateWithParam& load_state,
300 uint64 upload_position,
301 uint64 upload_size) OVERRIDE;
302 virtual void WorkerCrashed() OVERRIDE;
303 virtual void Activate() OVERRIDE;
304 virtual void Deactivate() OVERRIDE;
305 virtual void LostCapture() OVERRIDE;
306 virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
307 bool* is_keyboard_shortcut) OVERRIDE;
308 virtual void HandleKeyboardEvent(
309 const NativeWebKeyboardEvent& event) OVERRIDE;
310 virtual void HandleMouseDown() OVERRIDE;
311 virtual void HandleMouseUp() OVERRIDE;
312 virtual void HandleMouseActivate() OVERRIDE;
[email protected]edc64de2011-11-17 20:07:38313 virtual void RunFileChooser(
314 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23315 const content::FileChooserParams& params) OVERRIDE;
[email protected]952a68e2011-11-17 00:36:10316 virtual void ToggleFullscreenMode(bool enter_fullscreen) OVERRIDE;
317 virtual bool IsFullscreenForCurrentTab() const OVERRIDE;
318 virtual void UpdatePreferredSize(const gfx::Size& pref_size) OVERRIDE;
319 virtual void WebUISend(RenderViewHost* render_view_host,
320 const GURL& source_url,
321 const std::string& name,
322 const base::ListValue& args) OVERRIDE;
323 virtual void RequestToLockMouse() OVERRIDE;
324 virtual void LostMouseLock() OVERRIDE;
325
[email protected]0bfbf882011-12-22 18:19:27326 // RenderViewHostManager::Delegate -------------------------------------------
327
328 virtual bool CreateRenderViewForRenderManager(
329 RenderViewHost* render_view_host) OVERRIDE;
330 virtual void BeforeUnloadFiredFromRenderManager(
331 bool proceed,
332 bool* proceed_to_fire_unload) OVERRIDE;
333 virtual void DidStartLoadingFromRenderManager(
334 RenderViewHost* render_view_host) OVERRIDE;
335 virtual void RenderViewGoneFromRenderManager(
336 RenderViewHost* render_view_host) OVERRIDE;
337 virtual void UpdateRenderViewSizeForRenderManager() OVERRIDE;
338 virtual void NotifySwappedFromRenderManager() OVERRIDE;
339 virtual NavigationController& GetControllerForRenderManager() OVERRIDE;
340 virtual WebUI* CreateWebUIForRenderManager(const GURL& url) OVERRIDE;
341 virtual NavigationEntry*
342 GetLastCommittedNavigationEntryForRenderManager() OVERRIDE;
343 virtual bool FocusLocationBarByDefault() OVERRIDE;
344 virtual void SetFocusToLocationBar(bool select_all) OVERRIDE;
345 virtual void CreateViewAndSetSizeForRVH(RenderViewHost* rvh) OVERRIDE;
346
347 // Overridden from JavaScriptDialogDelegate:
348 virtual void OnDialogClosed(IPC::Message* reply_msg,
349 bool success,
350 const string16& user_input) OVERRIDE;
351 virtual gfx::NativeWindow GetDialogRootWindow() const OVERRIDE;
352 virtual void OnDialogShown() OVERRIDE;
353
[email protected]0dd3a0ab2011-02-18 08:17:44354 protected:
[email protected]d8c660432011-12-22 20:51:25355 friend class content::WebContentsObserver;
[email protected]553602e12011-04-05 17:01:18356
357 // Add and remove observers for page navigation notifications. Adding or
358 // removing multiple times has no effect. The order in which notifications
359 // are sent to observers is undefined. Clients must be sure to remove the
360 // observer before they go away.
[email protected]d8c660432011-12-22 20:51:25361 void AddObserver(content::WebContentsObserver* observer);
362 void RemoveObserver(content::WebContentsObserver* observer);
[email protected]553602e12011-04-05 17:01:18363
[email protected]0dd3a0ab2011-02-18 08:17:44364 private:
365 friend class NavigationController;
[email protected]0dd3a0ab2011-02-18 08:17:44366
367 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, NoJSMessageOnInterstitials);
368 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, UpdateTitle);
369 FRIEND_TEST_ALL_PREFIXES(TabContentsTest, CrossSiteCantPreemptAfterUnload);
370 FRIEND_TEST_ALL_PREFIXES(FormStructureBrowserTest, HTMLFiles);
371 FRIEND_TEST_ALL_PREFIXES(NavigationControllerTest, HistoryNavigate);
372 FRIEND_TEST_ALL_PREFIXES(RenderViewHostManagerTest, PageDoesBackAndReload);
373
374 // Temporary until the view/contents separation is complete.
375 friend class TabContentsView;
[email protected]9a56a0d2011-05-13 19:03:31376#if defined(TOOLKIT_VIEWS)
[email protected]7e2cef52011-04-11 21:47:23377 friend class TabContentsViewViews;
[email protected]0dd3a0ab2011-02-18 08:17:44378#elif defined(OS_MACOSX)
379 friend class TabContentsViewMac;
380#elif defined(TOOLKIT_USES_GTK)
381 friend class TabContentsViewGtk;
382#endif
383
384 // So InterstitialPage can access SetIsLoading.
385 friend class InterstitialPage;
386
387 // TODO(brettw) TestTabContents shouldn't exist!
388 friend class TestTabContents;
389
[email protected]0dd3a0ab2011-02-18 08:17:44390 // Message handlers.
[email protected]8b5af492011-11-28 21:50:58391 void OnRegisterIntentService(const string16& action,
[email protected]63c239322011-10-31 23:56:30392 const string16& type,
393 const string16& href,
394 const string16& title,
395 const string16& disposition);
[email protected]678105012011-12-09 04:01:21396 void OnWebIntentDispatch(const webkit_glue::WebIntentData& intent,
[email protected]63c239322011-10-31 23:56:30397 int intent_id);
[email protected]0dd3a0ab2011-02-18 08:17:44398 void OnDidStartProvisionalLoadForFrame(int64 frame_id,
399 bool main_frame,
[email protected]57b9396c2011-10-07 19:11:59400 const GURL& opener_url,
[email protected]0dd3a0ab2011-02-18 08:17:44401 const GURL& url);
402 void OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]57b9396c2011-10-07 19:11:59403 const GURL& opener_url,
[email protected]0dd3a0ab2011-02-18 08:17:44404 const GURL& source_url,
405 const GURL& target_url);
[email protected]d7b175e2011-10-11 15:31:58406 void OnDidFailProvisionalLoadWithError(
407 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params);
[email protected]0dd3a0ab2011-02-18 08:17:44408 void OnDidLoadResourceFromMemoryCache(const GURL& url,
[email protected]70435962011-08-02 20:13:28409 const std::string& security_info,
410 const std::string& http_request,
411 ResourceType::Type resource_type);
[email protected]0dd3a0ab2011-02-18 08:17:44412 void OnDidDisplayInsecureContent();
413 void OnDidRunInsecureContent(const std::string& security_origin,
414 const GURL& target_url);
415 void OnDocumentLoadedInFrame(int64 frame_id);
[email protected]1a55c5be2011-11-29 11:36:31416 void OnDidFinishLoad(int64 frame_id,
417 const GURL& validated_url,
418 bool is_main_frame);
419 void OnDidFailLoadWithError(int64 frame_id,
420 const GURL& validated_url,
421 bool is_main_frame,
422 int error_code,
423 const string16& error_description);
[email protected]0dd3a0ab2011-02-18 08:17:44424 void OnUpdateContentRestrictions(int restrictions);
[email protected]0dd3a0ab2011-02-18 08:17:44425 void OnGoToEntryAtOffset(int offset);
[email protected]216813952011-05-19 22:21:26426 void OnUpdateZoomLimits(int minimum_percent,
427 int maximum_percent,
428 bool remember);
[email protected]0bfbf882011-12-22 18:19:27429 void OnSaveURL(const GURL& url);
[email protected]3a29a6e2011-08-24 18:26:21430 void OnEnumerateDirectory(int request_id, const FilePath& path);
[email protected]7d189022011-08-25 22:54:20431 void OnJSOutOfMemory();
432 void OnRegisterProtocolHandler(const std::string& protocol,
433 const GURL& url,
434 const string16& title);
[email protected]b888919c2011-09-02 00:32:16435 void OnFindReply(int request_id, int number_of_matches,
436 const gfx::Rect& selection_rect, int active_match_ordinal,
437 bool final_update);
[email protected]d952a052011-09-06 18:42:45438 void OnCrashedPlugin(const FilePath& plugin_path);
[email protected]7fc4bbb2011-09-08 21:23:10439 void OnAppCacheAccessed(const GURL& manifest_url, bool blocked_by_policy);
[email protected]0dd3a0ab2011-02-18 08:17:44440
441 // Changes the IsLoading state and notifies delegate as needed
442 // |details| is used to provide details on the load that just finished
443 // (but can be null if not applicable). Can be overridden.
444 void SetIsLoading(bool is_loading,
445 LoadNotificationDetails* details);
446
[email protected]0dd3a0ab2011-02-18 08:17:44447 // Called by derived classes to indicate that we're no longer waiting for a
448 // response. This won't actually update the throbber, but it will get picked
449 // up at the next animation step if the throbber is going.
450 void SetNotWaitingForResponse() { waiting_for_response_ = false; }
451
[email protected]0dd3a0ab2011-02-18 08:17:44452 // Navigation helpers --------------------------------------------------------
453 //
454 // These functions are helpers for Navigate() and DidNavigate().
455
456 // Handles post-navigation tasks in DidNavigate AFTER the entry has been
457 // committed to the navigation controller. Note that the navigation entry is
458 // not provided since it may be invalid/changed after being committed. The
459 // current navigation entry is in the NavigationController at this point.
460 void DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:13461 const content::LoadCommittedDetails& details,
[email protected]0dd3a0ab2011-02-18 08:17:44462 const ViewHostMsg_FrameNavigate_Params& params);
463 void DidNavigateAnyFramePostCommit(
464 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:13465 const content::LoadCommittedDetails& details,
[email protected]0dd3a0ab2011-02-18 08:17:44466 const ViewHostMsg_FrameNavigate_Params& params);
467
[email protected]74ce1ad2011-12-16 21:51:46468 // If our controller was restored, update the max page ID associated with the
469 // given RenderViewHost to be larger than the number of restored entries.
470 // This is called in CreateRenderView before any navigations in the RenderView
471 // have begun, to prevent any races in updating RenderView::next_page_id.
472 void UpdateMaxPageIDIfNecessary(RenderViewHost* rvh);
[email protected]0dd3a0ab2011-02-18 08:17:44473
[email protected]0dd3a0ab2011-02-18 08:17:44474 // Saves the given title to the navigation entry and does associated work. It
475 // will update history and the view for the new title, and also synthesize
476 // titles for file URLs that have none (so we require that the URL of the
477 // entry already be set).
478 //
479 // This is used as the backend for state updates, which include a new title,
480 // or the dedicated set title message. It returns true if the new title is
481 // different and was therefore updated.
[email protected]acafd272011-07-26 17:35:57482 bool UpdateTitleForEntry(NavigationEntry* entry, const string16& title);
[email protected]0dd3a0ab2011-02-18 08:17:44483
484 // Causes the TabContents to navigate in the right renderer to |entry|, which
485 // must be already part of the entries in the navigation controller.
486 // This does not change the NavigationController state.
[email protected]dd11de52011-11-03 22:54:27487 bool NavigateToEntry(const NavigationEntry& entry,
[email protected]0dd3a0ab2011-02-18 08:17:44488 NavigationController::ReloadType reload_type);
489
[email protected]796931a92011-08-10 01:32:14490 // Sets the history for this tab_contents to |history_length| entries, and
491 // moves the current page_id to the last entry in the list if it's valid.
492 // This is mainly used when a prerendered page is swapped into the current
[email protected]9e1ad4b2011-08-14 16:49:19493 // tab. The method is virtual for testing.
494 virtual void SetHistoryLengthAndPrune(const SiteInstance* site_instance,
495 int merge_history_length,
496 int32 minimum_page_id);
[email protected]796931a92011-08-10 01:32:14497
[email protected]0dd3a0ab2011-02-18 08:17:44498 // Misc non-view stuff -------------------------------------------------------
499
500 // Helper functions for sending notifications.
501 void NotifySwapped();
502 void NotifyConnected();
503 void NotifyDisconnected();
504
[email protected]be1f56ab2011-12-22 06:55:31505 void SetEncoding(const std::string& encoding);
506
[email protected]81898992011-06-14 22:15:00507 // Stores random bits of data for others to associate with this object.
508 // WARNING: this needs to be deleted after NavigationController.
[email protected]45644f62011-11-23 00:58:23509 base::PropertyBag property_bag_;
[email protected]81898992011-06-14 22:15:00510
[email protected]0dd3a0ab2011-02-18 08:17:44511 // Data for core operation ---------------------------------------------------
512
513 // Delegate for notifying our owner about stuff. Not owned by us.
[email protected]674bc592011-12-20 23:00:42514 content::WebContentsDelegate* delegate_;
[email protected]0dd3a0ab2011-02-18 08:17:44515
516 // Handles the back/forward list and loading.
517 NavigationController controller_;
518
519 // The corresponding view.
520 scoped_ptr<TabContentsView> view_;
521
[email protected]996042972011-11-08 22:43:59522 // A list of observers notified when page state changes. Weak references.
523 // This MUST be listed above render_manager_ since at destruction time the
524 // latter might cause RenderViewHost's destructor to call us and we might use
525 // the observer list then.
[email protected]d8c660432011-12-22 20:51:25526 ObserverList<content::WebContentsObserver> observers_;
[email protected]996042972011-11-08 22:43:59527
[email protected]0dd3a0ab2011-02-18 08:17:44528 // Helper classes ------------------------------------------------------------
529
530 // Manages creation and swapping of render views.
531 RenderViewHostManager render_manager_;
532
[email protected]483623eb2011-10-25 09:30:00533 // Manages injecting Java objects into all RenderViewHosts associated with
534 // this TabContents.
535 scoped_ptr<JavaBridgeDispatcherHostManager>
536 java_bridge_dispatcher_host_manager_;
537
[email protected]c7dd2f62011-07-18 15:57:59538 // SavePackage, lazily created.
539 scoped_refptr<SavePackage> save_package_;
540
[email protected]0dd3a0ab2011-02-18 08:17:44541 // Data for loading state ----------------------------------------------------
542
543 // Indicates whether we're currently loading a resource.
544 bool is_loading_;
545
546 // Indicates if the tab is considered crashed.
547 base::TerminationStatus crashed_status_;
548 int crashed_error_code_;
549
[email protected]be1f56ab2011-12-22 06:55:31550 // Whether this tab contents is waiting for a first-response for the
551 // main resource of the page. This controls whether the throbber state is
552 // "waiting" or "loading."
[email protected]0dd3a0ab2011-02-18 08:17:44553 bool waiting_for_response_;
554
[email protected]74ce1ad2011-12-16 21:51:46555 // Map of SiteInstance ID to max page ID for this tab. A page ID is specific
556 // to a given tab and SiteInstance, and must be valid for the lifetime of the
557 // TabContents.
558 std::map<int32, int32> max_page_ids_;
[email protected]0dd3a0ab2011-02-18 08:17:44559
560 // System time at which the current load was started.
561 base::TimeTicks current_load_start_;
562
563 // The current load state and the URL associated with it.
[email protected]9c235f042011-08-10 22:28:21564 net::LoadStateWithParam load_state_;
[email protected]0dd3a0ab2011-02-18 08:17:44565 string16 load_state_host_;
566 // Upload progress, for displaying in the status bar.
567 // Set to zero when there is no significant upload happening.
568 uint64 upload_size_;
569 uint64 upload_position_;
570
571 // Data for current page -----------------------------------------------------
572
[email protected]987fc3a2011-05-26 14:18:09573 // When a title cannot be taken from any entry, this title will be used.
574 string16 page_title_when_no_navigation_entry_;
575
[email protected]0dd3a0ab2011-02-18 08:17:44576 // When a navigation occurs, we record its contents MIME type. It can be
577 // used to check whether we can do something for some special contents.
578 std::string contents_mime_type_;
579
580 // Character encoding.
581 std::string encoding_;
582
[email protected]0dd3a0ab2011-02-18 08:17:44583 // True if this is a secure page which displayed insecure content.
584 bool displayed_insecure_content_;
585
[email protected]0dd3a0ab2011-02-18 08:17:44586 // Data for misc internal state ----------------------------------------------
587
[email protected]be1f56ab2011-12-22 06:55:31588 // Whether the tab contents is currently being screenshotted by the
589 // DraggedTabController.
[email protected]0dd3a0ab2011-02-18 08:17:44590 bool capturing_contents_;
591
592 // See getter above.
593 bool is_being_destroyed_;
594
595 // Indicates whether we should notify about disconnection of this
596 // TabContents. This is used to ensure disconnection notifications only
597 // happen if a connection notification has happened and that they happen only
598 // once.
599 bool notify_disconnection_;
600
[email protected]2e5b90c2011-08-16 21:11:55601 // Pointer to the JavaScript dialog creator, lazily assigned. Used because the
602 // delegate of this TabContents is nulled before its destructor is called.
603 content::JavaScriptDialogCreator* dialog_creator_;
604
[email protected]0dd3a0ab2011-02-18 08:17:44605#if defined(OS_WIN)
606 // Handle to an event that's set when the page is showing a message box (or
607 // equivalent constrained window). Plugin processes check this to know if
608 // they should pump messages then.
609 base::win::ScopedHandle message_box_active_;
610#endif
611
[email protected]0dd3a0ab2011-02-18 08:17:44612 // Set to true when there is an active "before unload" dialog. When true,
613 // we've forced the throbber to start in Navigate, and we need to remember to
614 // turn it off in OnJavaScriptMessageBoxClosed if the navigation is canceled.
615 bool is_showing_before_unload_dialog_;
616
[email protected]0dd3a0ab2011-02-18 08:17:44617 // Settings that get passed to the renderer process.
[email protected]daf82f82011-10-31 22:35:31618 content::RendererPreferences renderer_preferences_;
[email protected]0dd3a0ab2011-02-18 08:17:44619
620 // If this tab was created from a renderer using window.open, this will be
621 // non-NULL and represent the WebUI of the opening renderer.
[email protected]1fd1a502011-03-30 16:55:56622 WebUI::TypeID opener_web_ui_type_;
[email protected]0dd3a0ab2011-02-18 08:17:44623
624 // The time that we started to create the new tab page.
625 base::TimeTicks new_tab_start_time_;
626
627 // The time that we started to close the tab.
628 base::TimeTicks tab_close_start_time_;
629
630 // The time that this tab was last selected.
631 base::TimeTicks last_selected_time_;
632
[email protected]0dd3a0ab2011-02-18 08:17:44633 // See description above setter.
634 bool closed_by_user_gesture_;
635
636 // Minimum/maximum zoom percent.
637 int minimum_zoom_percent_;
638 int maximum_zoom_percent_;
639 // If true, the default zoom limits have been overriden for this tab, in which
640 // case we don't want saved settings to apply to it and we don't want to
641 // remember it.
642 bool temporary_zoom_settings_;
643
[email protected]0dd3a0ab2011-02-18 08:17:44644 // Content restrictions, used to disable print/copy etc based on content's
645 // (full-page plugins for now only) permissions.
646 int content_restrictions_;
647
[email protected]32ded2212011-11-10 18:51:43648 // Our view type. Default is VIEW_TYPE_TAB_CONTENTS.
649 content::ViewType view_type_;
650
[email protected]0dd3a0ab2011-02-18 08:17:44651 DISALLOW_COPY_AND_ASSIGN(TabContents);
652};
653
654#endif // CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_H_