blob: dd1cb8b138a24968b39d05111d80a65036f99a13 [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]9f76c1e2012-03-05 15:15:5836class RenderViewHostImpl;
[email protected]a53209b2012-01-20 16:48:1637class SavePackage;
[email protected]adbfb8df2012-02-24 01:19:4338class SessionStorageNamespaceImpl;
[email protected]d7b175e2011-10-11 15:31:5839struct ViewHostMsg_DidFailProvisionalLoadWithError_Params;
[email protected]daf82f82011-10-31 22:35:3140
[email protected]e582fdd2011-12-20 16:48:1741namespace content {
42class DownloadItem;
[email protected]b6583592012-01-25 19:52:3343class SiteInstance;
[email protected]51da7e32012-01-30 19:24:5244class JavaScriptDialogCreator;
[email protected]674bc592011-12-20 23:00:4245class WebContentsDelegate;
[email protected]51da7e32012-01-30 19:24:5246class WebContentsObserver;
[email protected]8643e6d2012-01-18 20:26:1047class WebContentsView;
[email protected]e582fdd2011-12-20 16:48:1748}
49
[email protected]daf82f82011-10-31 22:35:3150namespace webkit_glue {
51struct WebIntentData;
52}
[email protected]0dd3a0ab2011-02-18 08:17:4453
[email protected]01d65172011-12-25 04:39:3054class CONTENT_EXPORT TabContents
55 : public NON_EXPORTED_BASE(content::WebContents),
[email protected]b0b67cf2012-01-18 21:59:5756 public content::RenderViewHostDelegate,
[email protected]51da7e32012-01-30 19:24:5257 public RenderViewHostManager::Delegate {
[email protected]0dd3a0ab2011-02-18 08:17:4458 public:
[email protected]a81343d232011-12-27 07:39:2059 // See WebContents::Create for a description of these parameters.
[email protected]3d7474ff2011-07-27 17:47:3760 TabContents(content::BrowserContext* browser_context,
[email protected]b6583592012-01-25 19:52:3361 content::SiteInstance* site_instance,
[email protected]0dd3a0ab2011-02-18 08:17:4462 int routing_id,
63 const TabContents* base_tab_contents,
[email protected]adbfb8df2012-02-24 01:19:4364 SessionStorageNamespaceImpl* session_storage_namespace);
[email protected]0dd3a0ab2011-02-18 08:17:4465 virtual ~TabContents();
66
[email protected]64d69de42012-02-06 00:19:5467 // Returns the content specific prefs for the given RVH.
68 static WebPreferences GetWebkitPrefs(RenderViewHost* rvh, const GURL& url);
69
[email protected]c7dd2f62011-07-18 15:57:5970 // Returns the SavePackage which manages the page saving job. May be NULL.
71 SavePackage* save_package() const { return save_package_.get(); }
72
[email protected]74ce1ad2011-12-16 21:51:4673 // Updates the max page ID for the current SiteInstance in this TabContents
74 // to be at least |page_id|.
[email protected]0dd3a0ab2011-02-18 08:17:4475 void UpdateMaxPageID(int32 page_id);
76
[email protected]74ce1ad2011-12-16 21:51:4677 // Updates the max page ID for the given SiteInstance in this TabContents
78 // to be at least |page_id|.
[email protected]b6583592012-01-25 19:52:3379 void UpdateMaxPageIDForSiteInstance(content::SiteInstance* site_instance,
[email protected]74ce1ad2011-12-16 21:51:4680 int32 page_id);
81
[email protected]91854cd2012-01-10 19:43:5782 // Copy the current map of SiteInstance ID to max page ID from another tab.
83 // This is necessary when this tab adopts the NavigationEntries from
84 // |tab_contents|.
85 void CopyMaxPageIDsFrom(TabContents* tab_contents);
86
[email protected]0dd3a0ab2011-02-18 08:17:4487 // Called by the NavigationController to cause the TabContents to navigate to
88 // the current pending entry. The NavigationController should be called back
[email protected]9a7e68c2011-05-26 17:35:5089 // with RendererDidNavigate on success or DiscardPendingEntry on failure.
90 // The callbacks can be inside of this function, or at some future time.
[email protected]0dd3a0ab2011-02-18 08:17:4491 //
92 // The entry has a PageID of -1 if newly created (corresponding to navigation
93 // to a new URL).
94 //
95 // If this method returns false, then the navigation is discarded (equivalent
96 // to calling DiscardPendingEntry on the NavigationController).
[email protected]0bfbf882011-12-22 18:19:2797 bool NavigateToPendingEntry(
[email protected]71fde352011-12-29 03:29:5698 content::NavigationController::ReloadType reload_type);
[email protected]0dd3a0ab2011-02-18 08:17:4499
[email protected]0dd3a0ab2011-02-18 08:17:44100 // Sets the passed passed interstitial as the currently showing interstitial.
101 // |interstitial_page| should be non NULL (use the remove_interstitial_page
102 // method to unset the interstitial) and no interstitial page should be set
103 // when there is already a non NULL interstitial page set.
[email protected]cadaec52012-02-08 21:53:13104 void set_interstitial_page(InterstitialPageImpl* interstitial_page) {
[email protected]0dd3a0ab2011-02-18 08:17:44105 render_manager_.set_interstitial_page(interstitial_page);
106 }
107
108 // Unsets the currently showing interstitial.
109 void remove_interstitial_page() {
110 render_manager_.remove_interstitial_page();
111 }
112
[email protected]01ec4ec2012-01-18 04:13:47113 void set_opener_web_ui_type(content::WebUI::TypeID opener_web_ui_type) {
[email protected]0dd3a0ab2011-02-18 08:17:44114 opener_web_ui_type_ = opener_web_ui_type;
115 }
116
[email protected]276b37a22011-11-08 20:45:46117 JavaBridgeDispatcherHostManager* java_bridge_dispatcher_host_manager() const {
118 return java_bridge_dispatcher_host_manager_.get();
119 }
120
[email protected]cdcb1dee2012-01-04 00:46:20121 // Like GetController from WebContents, but returns the concrete object.
[email protected]d202a7c2012-01-04 07:53:47122 NavigationControllerImpl& GetControllerImpl();
[email protected]cdcb1dee2012-01-04 00:46:20123
[email protected]765187182012-01-11 23:59:28124 // Expose the render manager for testing.
125 RenderViewHostManager* GetRenderManagerForTesting();
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]cdcb1dee2012-01-04 00:46:20132 virtual content::NavigationController& GetController() OVERRIDE;
133 virtual const content::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]5626b0892012-02-20 14:46:58139 virtual content::RenderWidgetHostView*
140 GetRenderWidgetHostView() const OVERRIDE;
[email protected]8643e6d2012-01-18 20:26:10141 virtual content::WebContentsView* GetView() const OVERRIDE;
[email protected]01ec4ec2012-01-18 04:13:47142 virtual content::WebUI* CreateWebUI(const GURL& url) OVERRIDE;
143 virtual content::WebUI* GetWebUI() const OVERRIDE;
144 virtual content::WebUI* GetCommittedWebUI() const OVERRIDE;
[email protected]be1f56ab2011-12-22 06:55:31145 virtual const string16& GetTitle() const OVERRIDE;
146 virtual int32 GetMaxPageID() OVERRIDE;
147 virtual int32 GetMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33148 content::SiteInstance* site_instance) OVERRIDE;
149 virtual content::SiteInstance* GetSiteInstance() const OVERRIDE;
150 virtual content::SiteInstance* GetPendingSiteInstance() const OVERRIDE;
[email protected]be1f56ab2011-12-22 06:55:31151 virtual bool IsLoading() const OVERRIDE;
152 virtual bool IsWaitingForResponse() const OVERRIDE;
153 virtual const net::LoadStateWithParam& GetLoadState() const OVERRIDE;
154 virtual const string16& GetLoadStateHost() const OVERRIDE;
155 virtual uint64 GetUploadSize() const OVERRIDE;
156 virtual uint64 GetUploadPosition() const OVERRIDE;
157 virtual const std::string& GetEncoding() const OVERRIDE;
158 virtual bool DisplayedInsecureContent() const OVERRIDE;
159 virtual void SetCapturingContents(bool cap) OVERRIDE;
160 virtual bool IsCrashed() const OVERRIDE;
161 virtual void SetIsCrashed(base::TerminationStatus status,
162 int error_code) OVERRIDE;
163 virtual base::TerminationStatus GetCrashedStatus() const OVERRIDE;
164 virtual bool IsBeingDestroyed() const OVERRIDE;
165 virtual void NotifyNavigationStateChanged(unsigned changed_flags) OVERRIDE;
166 virtual void DidBecomeSelected() OVERRIDE;
167 virtual base::TimeTicks GetLastSelectedTime() const OVERRIDE;
168 virtual void WasHidden() OVERRIDE;
169 virtual void ShowContents() OVERRIDE;
170 virtual void HideContents() OVERRIDE;
171 virtual bool NeedToFireBeforeUnload() OVERRIDE;
[email protected]0bfbf882011-12-22 18:19:27172 virtual void Stop() OVERRIDE;
[email protected]d9083482012-01-06 00:38:46173 virtual content::WebContents* Clone() OVERRIDE;
[email protected]2a6bc3e2011-12-28 23:51:33174 virtual void AddNewContents(content::WebContents* new_contents,
[email protected]0bfbf882011-12-22 18:19:27175 WindowOpenDisposition disposition,
176 const gfx::Rect& initial_pos,
177 bool user_gesture) OVERRIDE;
178 virtual gfx::NativeView GetContentNativeView() const OVERRIDE;
179 virtual gfx::NativeView GetNativeView() const OVERRIDE;
180 virtual void GetContainerBounds(gfx::Rect* out) const OVERRIDE;
181 virtual void Focus() OVERRIDE;
182 virtual void FocusThroughTabTraversal(bool reverse) OVERRIDE;
183 virtual bool ShowingInterstitialPage() const OVERRIDE;
[email protected]cadaec52012-02-08 21:53:13184 virtual content::InterstitialPage* GetInterstitialPage() const OVERRIDE;
[email protected]a53209b2012-01-20 16:48:16185 virtual bool IsSavable() OVERRIDE;
[email protected]0bfbf882011-12-22 18:19:27186 virtual void OnSavePage() OVERRIDE;
187 virtual bool SavePage(const FilePath& main_file,
188 const FilePath& dir_path,
[email protected]a53209b2012-01-20 16:48:16189 content::SavePageType save_type) OVERRIDE;
[email protected]aa4f3972012-03-01 18:12:12190 virtual void GenerateMHTML(
191 const FilePath& file,
192 const base::Callback<void(const FilePath&, int64)>& callback) OVERRIDE;
[email protected]0bfbf882011-12-22 18:19:27193 virtual bool IsActiveEntry(int32 page_id) OVERRIDE;
194
195 virtual const std::string& GetContentsMimeType() const OVERRIDE;
196 virtual bool WillNotifyDisconnection() const OVERRIDE;
197 virtual void SetOverrideEncoding(const std::string& encoding) OVERRIDE;
198 virtual void ResetOverrideEncoding() OVERRIDE;
199 virtual content::RendererPreferences* GetMutableRendererPrefs() OVERRIDE;
200 virtual void SetNewTabStartTime(const base::TimeTicks& time) OVERRIDE;
201 virtual base::TimeTicks GetNewTabStartTime() const OVERRIDE;
202 virtual void OnCloseStarted() OVERRIDE;
203 virtual bool ShouldAcceptDragAndDrop() const OVERRIDE;
204 virtual void SystemDragEnded() OVERRIDE;
205 virtual void SetClosedByUserGesture(bool value) OVERRIDE;
206 virtual bool GetClosedByUserGesture() const OVERRIDE;
207 virtual double GetZoomLevel() const OVERRIDE;
208 virtual int GetZoomPercent(bool* enable_increment,
209 bool* enable_decrement) OVERRIDE;
210 virtual void ViewSource() OVERRIDE;
211 virtual void ViewFrameSource(const GURL& url,
212 const std::string& content_state) OVERRIDE;
213 virtual int GetMinimumZoomPercent() const OVERRIDE;
214 virtual int GetMaximumZoomPercent() const OVERRIDE;
[email protected]bcd2815602012-01-14 18:17:23215 virtual gfx::Size GetPreferredSize() const OVERRIDE;
[email protected]0bfbf882011-12-22 18:19:27216 virtual int GetContentRestrictions() const OVERRIDE;
[email protected]01ec4ec2012-01-18 04:13:47217 virtual content::WebUI::TypeID GetWebUITypeForCurrentState() OVERRIDE;
218 virtual content::WebUI* GetWebUIForCurrentState() OVERRIDE;
[email protected]0bfbf882011-12-22 18:19:27219 virtual bool GotResponseToLockMouseRequest(bool allowed) OVERRIDE;
220
221 // Implementation of PageNavigator.
[email protected]e5d549d2011-12-28 01:29:20222 virtual content::WebContents* OpenURL(
223 const content::OpenURLParams& params) OVERRIDE;
[email protected]151a63d2011-12-20 22:32:52224
[email protected]952a68e2011-11-17 00:36:10225 // RenderViewHostDelegate ----------------------------------------------------
226
[email protected]b0b67cf2012-01-18 21:59:57227 virtual content::RenderViewHostDelegate::View* GetViewDelegate() OVERRIDE;
228 virtual content::RenderViewHostDelegate::RendererManagement*
[email protected]952a68e2011-11-17 00:36:10229 GetRendererManagementDelegate() OVERRIDE;
[email protected]be1f56ab2011-12-22 06:55:31230 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
231 virtual const GURL& GetURL() const OVERRIDE;
[email protected]768c5472011-12-26 19:06:17232 virtual WebContents* GetAsWebContents() OVERRIDE;
[email protected]952a68e2011-11-17 00:36:10233 virtual content::ViewType GetRenderViewType() const OVERRIDE;
[email protected]b7a756d42012-01-23 18:08:17234 virtual gfx::Rect GetRootWindowResizerRect() const OVERRIDE;
[email protected]952a68e2011-11-17 00:36:10235 virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE;
236 virtual void RenderViewReady(RenderViewHost* render_view_host) OVERRIDE;
237 virtual void RenderViewGone(RenderViewHost* render_view_host,
238 base::TerminationStatus status,
239 int error_code) OVERRIDE;
240 virtual void RenderViewDeleted(RenderViewHost* render_view_host) OVERRIDE;
241 virtual void DidNavigate(
242 RenderViewHost* render_view_host,
243 const ViewHostMsg_FrameNavigate_Params& params) OVERRIDE;
244 virtual void UpdateState(RenderViewHost* render_view_host,
245 int32 page_id,
246 const std::string& state) OVERRIDE;
247 virtual void UpdateTitle(RenderViewHost* render_view_host,
248 int32 page_id,
249 const string16& title,
250 base::i18n::TextDirection title_direction) OVERRIDE;
251 virtual void UpdateEncoding(RenderViewHost* render_view_host,
252 const std::string& encoding) OVERRIDE;
253 virtual void UpdateTargetURL(int32 page_id, const GURL& url) OVERRIDE;
254 virtual void Close(RenderViewHost* render_view_host) OVERRIDE;
255 virtual void RequestMove(const gfx::Rect& new_bounds) OVERRIDE;
256 virtual void SwappedOut(RenderViewHost* render_view_host) OVERRIDE;
257 virtual void DidStartLoading() OVERRIDE;
258 virtual void DidStopLoading() OVERRIDE;
259 virtual void DidCancelLoading() OVERRIDE;
260 virtual void DidChangeLoadProgress(double progress) OVERRIDE;
261 virtual void DocumentAvailableInMainFrame(
262 RenderViewHost* render_view_host) OVERRIDE;
263 virtual void DocumentOnLoadCompletedInMainFrame(
264 RenderViewHost* render_view_host,
265 int32 page_id) OVERRIDE;
266 virtual void RequestOpenURL(const GURL& url,
[email protected]445e1042011-12-03 21:03:15267 const content::Referrer& referrer,
[email protected]952a68e2011-11-17 00:36:10268 WindowOpenDisposition disposition,
269 int64 source_frame_id) OVERRIDE;
[email protected]4ad5d77d2011-12-03 02:00:48270 virtual void RequestTransferURL(
271 const GURL& url,
[email protected]bce1f1c2011-12-05 15:11:58272 const content::Referrer& referrer,
[email protected]4ad5d77d2011-12-03 02:00:48273 WindowOpenDisposition disposition,
274 int64 source_frame_id,
[email protected]e5d549d2011-12-28 01:29:20275 const content::GlobalRequestID& transferred_global_request_id) OVERRIDE;
[email protected]fedec012012-01-28 03:09:34276 virtual void RunJavaScriptMessage(RenderViewHost* rvh,
[email protected]952a68e2011-11-17 00:36:10277 const string16& message,
278 const string16& default_prompt,
279 const GURL& frame_url,
[email protected]269f86d2011-12-07 02:43:47280 ui::JavascriptMessageType type,
[email protected]952a68e2011-11-17 00:36:10281 IPC::Message* reply_msg,
282 bool* did_suppress_message) OVERRIDE;
[email protected]fedec012012-01-28 03:09:34283 virtual void RunBeforeUnloadConfirm(RenderViewHost* rvh,
[email protected]952a68e2011-11-17 00:36:10284 const string16& message,
[email protected]3b3301f62012-02-29 04:32:32285 bool is_reload,
[email protected]952a68e2011-11-17 00:36:10286 IPC::Message* reply_msg) OVERRIDE;
287 virtual content::RendererPreferences GetRendererPrefs(
288 content::BrowserContext* browser_context) const OVERRIDE;
289 virtual WebPreferences GetWebkitPrefs() OVERRIDE;
290 virtual void OnUserGesture() OVERRIDE;
291 virtual void OnIgnoredUIEvent() OVERRIDE;
292 virtual void RendererUnresponsive(RenderViewHost* render_view_host,
293 bool is_during_unload) OVERRIDE;
294 virtual void RendererResponsive(RenderViewHost* render_view_host) OVERRIDE;
295 virtual void LoadStateChanged(const GURL& url,
296 const net::LoadStateWithParam& load_state,
297 uint64 upload_position,
298 uint64 upload_size) OVERRIDE;
299 virtual void WorkerCrashed() OVERRIDE;
300 virtual void Activate() OVERRIDE;
301 virtual void Deactivate() OVERRIDE;
302 virtual void LostCapture() OVERRIDE;
303 virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
304 bool* is_keyboard_shortcut) OVERRIDE;
305 virtual void HandleKeyboardEvent(
306 const NativeWebKeyboardEvent& event) OVERRIDE;
307 virtual void HandleMouseDown() OVERRIDE;
308 virtual void HandleMouseUp() OVERRIDE;
309 virtual void HandleMouseActivate() OVERRIDE;
[email protected]edc64de2011-11-17 20:07:38310 virtual void RunFileChooser(
311 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23312 const content::FileChooserParams& params) OVERRIDE;
[email protected]952a68e2011-11-17 00:36:10313 virtual void ToggleFullscreenMode(bool enter_fullscreen) OVERRIDE;
314 virtual bool IsFullscreenForCurrentTab() const OVERRIDE;
315 virtual void UpdatePreferredSize(const gfx::Size& pref_size) OVERRIDE;
[email protected]61e2b3cc2012-03-02 16:13:34316 virtual void ResizeDueToAutoResize(const gfx::Size& new_size) OVERRIDE;
[email protected]952a68e2011-11-17 00:36:10317 virtual void WebUISend(RenderViewHost* render_view_host,
318 const GURL& source_url,
319 const std::string& name,
320 const base::ListValue& args) OVERRIDE;
321 virtual void RequestToLockMouse() OVERRIDE;
322 virtual void LostMouseLock() OVERRIDE;
323
[email protected]0bfbf882011-12-22 18:19:27324 // RenderViewHostManager::Delegate -------------------------------------------
325
326 virtual bool CreateRenderViewForRenderManager(
327 RenderViewHost* render_view_host) OVERRIDE;
328 virtual void BeforeUnloadFiredFromRenderManager(
329 bool proceed,
330 bool* proceed_to_fire_unload) OVERRIDE;
331 virtual void DidStartLoadingFromRenderManager(
332 RenderViewHost* render_view_host) OVERRIDE;
333 virtual void RenderViewGoneFromRenderManager(
334 RenderViewHost* render_view_host) OVERRIDE;
335 virtual void UpdateRenderViewSizeForRenderManager() OVERRIDE;
336 virtual void NotifySwappedFromRenderManager() OVERRIDE;
[email protected]d202a7c2012-01-04 07:53:47337 virtual NavigationControllerImpl& GetControllerForRenderManager() OVERRIDE;
[email protected]d2353452012-01-19 19:53:56338 virtual WebUIImpl* CreateWebUIForRenderManager(const GURL& url) OVERRIDE;
[email protected]ad23a092011-12-28 07:02:04339 virtual content::NavigationEntry*
[email protected]0bfbf882011-12-22 18:19:27340 GetLastCommittedNavigationEntryForRenderManager() OVERRIDE;
341 virtual bool FocusLocationBarByDefault() OVERRIDE;
342 virtual void SetFocusToLocationBar(bool select_all) OVERRIDE;
343 virtual void CreateViewAndSetSizeForRVH(RenderViewHost* rvh) 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)
[email protected]eb668c92012-02-06 15:35:29370 friend class WebContentsViewMac;
[email protected]0dd3a0ab2011-02-18 08:17:44371#elif defined(TOOLKIT_USES_GTK)
372 friend class TabContentsViewGtk;
373#endif
374
[email protected]cadaec52012-02-08 21:53:13375 // So InterstitialPageImpl can access SetIsLoading.
376 friend class InterstitialPageImpl;
[email protected]0dd3a0ab2011-02-18 08:17:44377
378 // TODO(brettw) TestTabContents shouldn't exist!
379 friend class TestTabContents;
380
[email protected]51da7e32012-01-30 19:24:52381 // Callback function when showing JS dialogs.
382 void OnDialogClosed(RenderViewHost* rvh,
383 IPC::Message* reply_msg,
384 bool success,
385 const string16& user_input);
386
[email protected]0dd3a0ab2011-02-18 08:17:44387 // Message handlers.
[email protected]8b5af492011-11-28 21:50:58388 void OnRegisterIntentService(const string16& action,
[email protected]63c239322011-10-31 23:56:30389 const string16& type,
390 const string16& href,
391 const string16& title,
392 const string16& disposition);
[email protected]678105012011-12-09 04:01:21393 void OnWebIntentDispatch(const webkit_glue::WebIntentData& intent,
[email protected]63c239322011-10-31 23:56:30394 int intent_id);
[email protected]0dd3a0ab2011-02-18 08:17:44395 void OnDidStartProvisionalLoadForFrame(int64 frame_id,
396 bool main_frame,
[email protected]57b9396c2011-10-07 19:11:59397 const GURL& opener_url,
[email protected]0dd3a0ab2011-02-18 08:17:44398 const GURL& url);
399 void OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]57b9396c2011-10-07 19:11:59400 const GURL& opener_url,
[email protected]0dd3a0ab2011-02-18 08:17:44401 const GURL& source_url,
402 const GURL& target_url);
[email protected]d7b175e2011-10-11 15:31:58403 void OnDidFailProvisionalLoadWithError(
404 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params);
[email protected]0dd3a0ab2011-02-18 08:17:44405 void OnDidLoadResourceFromMemoryCache(const GURL& url,
[email protected]70435962011-08-02 20:13:28406 const std::string& security_info,
407 const std::string& http_request,
408 ResourceType::Type resource_type);
[email protected]0dd3a0ab2011-02-18 08:17:44409 void OnDidDisplayInsecureContent();
410 void OnDidRunInsecureContent(const std::string& security_origin,
411 const GURL& target_url);
412 void OnDocumentLoadedInFrame(int64 frame_id);
[email protected]1a55c5be2011-11-29 11:36:31413 void OnDidFinishLoad(int64 frame_id,
414 const GURL& validated_url,
415 bool is_main_frame);
416 void OnDidFailLoadWithError(int64 frame_id,
417 const GURL& validated_url,
418 bool is_main_frame,
419 int error_code,
420 const string16& error_description);
[email protected]0dd3a0ab2011-02-18 08:17:44421 void OnUpdateContentRestrictions(int restrictions);
[email protected]0dd3a0ab2011-02-18 08:17:44422 void OnGoToEntryAtOffset(int offset);
[email protected]216813952011-05-19 22:21:26423 void OnUpdateZoomLimits(int minimum_percent,
424 int maximum_percent,
425 bool remember);
[email protected]0bfbf882011-12-22 18:19:27426 void OnSaveURL(const GURL& url);
[email protected]3a29a6e2011-08-24 18:26:21427 void OnEnumerateDirectory(int request_id, const FilePath& path);
[email protected]7d189022011-08-25 22:54:20428 void OnJSOutOfMemory();
[email protected]b7a756d42012-01-23 18:08:17429
[email protected]7d189022011-08-25 22:54:20430 void OnRegisterProtocolHandler(const std::string& protocol,
431 const GURL& url,
432 const string16& title);
[email protected]b888919c2011-09-02 00:32:16433 void OnFindReply(int request_id, int number_of_matches,
434 const gfx::Rect& selection_rect, int active_match_ordinal,
435 bool final_update);
[email protected]d952a052011-09-06 18:42:45436 void OnCrashedPlugin(const FilePath& plugin_path);
[email protected]7fc4bbb2011-09-08 21:23:10437 void OnAppCacheAccessed(const GURL& manifest_url, bool blocked_by_policy);
[email protected]0dd3a0ab2011-02-18 08:17:44438
439 // Changes the IsLoading state and notifies delegate as needed
440 // |details| is used to provide details on the load that just finished
441 // (but can be null if not applicable). Can be overridden.
442 void SetIsLoading(bool is_loading,
443 LoadNotificationDetails* details);
444
[email protected]0dd3a0ab2011-02-18 08:17:44445 // Called by derived classes to indicate that we're no longer waiting for a
446 // response. This won't actually update the throbber, but it will get picked
447 // up at the next animation step if the throbber is going.
448 void SetNotWaitingForResponse() { waiting_for_response_ = false; }
449
[email protected]0dd3a0ab2011-02-18 08:17:44450 // Navigation helpers --------------------------------------------------------
451 //
452 // These functions are helpers for Navigate() and DidNavigate().
453
454 // Handles post-navigation tasks in DidNavigate AFTER the entry has been
455 // committed to the navigation controller. Note that the navigation entry is
456 // not provided since it may be invalid/changed after being committed. The
457 // current navigation entry is in the NavigationController at this point.
458 void DidNavigateMainFramePostCommit(
[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 void DidNavigateAnyFramePostCommit(
462 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:13463 const content::LoadCommittedDetails& details,
[email protected]0dd3a0ab2011-02-18 08:17:44464 const ViewHostMsg_FrameNavigate_Params& params);
465
[email protected]74ce1ad2011-12-16 21:51:46466 // If our controller was restored, update the max page ID associated with the
467 // given RenderViewHost to be larger than the number of restored entries.
468 // This is called in CreateRenderView before any navigations in the RenderView
469 // have begun, to prevent any races in updating RenderView::next_page_id.
470 void UpdateMaxPageIDIfNecessary(RenderViewHost* rvh);
[email protected]0dd3a0ab2011-02-18 08:17:44471
[email protected]0dd3a0ab2011-02-18 08:17:44472 // Saves the given title to the navigation entry and does associated work. It
473 // will update history and the view for the new title, and also synthesize
474 // titles for file URLs that have none (so we require that the URL of the
475 // entry already be set).
476 //
477 // This is used as the backend for state updates, which include a new title,
478 // or the dedicated set title message. It returns true if the new title is
479 // different and was therefore updated.
[email protected]10f417c52011-12-28 21:04:23480 bool UpdateTitleForEntry(content::NavigationEntryImpl* entry,
481 const string16& title);
[email protected]0dd3a0ab2011-02-18 08:17:44482
483 // Causes the TabContents to navigate in the right renderer to |entry|, which
484 // must be already part of the entries in the navigation controller.
485 // This does not change the NavigationController state.
[email protected]10f417c52011-12-28 21:04:23486 bool NavigateToEntry(const content::NavigationEntryImpl& entry,
[email protected]71fde352011-12-29 03:29:56487 content::NavigationController::ReloadType reload_type);
[email protected]0dd3a0ab2011-02-18 08:17:44488
[email protected]796931a92011-08-10 01:32:14489 // Sets the history for this tab_contents to |history_length| entries, and
490 // moves the current page_id to the last entry in the list if it's valid.
491 // This is mainly used when a prerendered page is swapped into the current
[email protected]9e1ad4b2011-08-14 16:49:19492 // tab. The method is virtual for testing.
[email protected]b6583592012-01-25 19:52:33493 virtual void SetHistoryLengthAndPrune(
494 const content::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]27678b2a2012-02-04 22:09:14507 // Save a URL to the local filesystem.
[email protected]e30d68d2012-02-09 00:06:26508 void SaveURL(const GURL& url, const GURL& referrer, bool is_main_frame);
[email protected]27678b2a2012-02-04 22:09:14509
[email protected]9f76c1e2012-03-05 15:15:58510 RenderViewHostImpl* GetRenderViewHostImpl();
511
[email protected]81898992011-06-14 22:15:00512 // Stores random bits of data for others to associate with this object.
513 // WARNING: this needs to be deleted after NavigationController.
[email protected]45644f62011-11-23 00:58:23514 base::PropertyBag property_bag_;
[email protected]81898992011-06-14 22:15:00515
[email protected]0dd3a0ab2011-02-18 08:17:44516 // Data for core operation ---------------------------------------------------
517
518 // Delegate for notifying our owner about stuff. Not owned by us.
[email protected]674bc592011-12-20 23:00:42519 content::WebContentsDelegate* delegate_;
[email protected]0dd3a0ab2011-02-18 08:17:44520
521 // Handles the back/forward list and loading.
[email protected]d202a7c2012-01-04 07:53:47522 NavigationControllerImpl controller_;
[email protected]0dd3a0ab2011-02-18 08:17:44523
524 // The corresponding view.
[email protected]8643e6d2012-01-18 20:26:10525 scoped_ptr<content::WebContentsView> view_;
[email protected]0dd3a0ab2011-02-18 08:17:44526
[email protected]996042972011-11-08 22:43:59527 // A list of observers notified when page state changes. Weak references.
528 // This MUST be listed above render_manager_ since at destruction time the
529 // latter might cause RenderViewHost's destructor to call us and we might use
530 // the observer list then.
[email protected]d8c660432011-12-22 20:51:25531 ObserverList<content::WebContentsObserver> observers_;
[email protected]996042972011-11-08 22:43:59532
[email protected]0dd3a0ab2011-02-18 08:17:44533 // Helper classes ------------------------------------------------------------
534
535 // Manages creation and swapping of render views.
536 RenderViewHostManager render_manager_;
537
[email protected]483623eb2011-10-25 09:30:00538 // Manages injecting Java objects into all RenderViewHosts associated with
539 // this TabContents.
540 scoped_ptr<JavaBridgeDispatcherHostManager>
541 java_bridge_dispatcher_host_manager_;
542
[email protected]c7dd2f62011-07-18 15:57:59543 // SavePackage, lazily created.
544 scoped_refptr<SavePackage> save_package_;
545
[email protected]0dd3a0ab2011-02-18 08:17:44546 // Data for loading state ----------------------------------------------------
547
548 // Indicates whether we're currently loading a resource.
549 bool is_loading_;
550
551 // Indicates if the tab is considered crashed.
552 base::TerminationStatus crashed_status_;
553 int crashed_error_code_;
554
[email protected]be1f56ab2011-12-22 06:55:31555 // Whether this tab contents is waiting for a first-response for the
556 // main resource of the page. This controls whether the throbber state is
557 // "waiting" or "loading."
[email protected]0dd3a0ab2011-02-18 08:17:44558 bool waiting_for_response_;
559
[email protected]74ce1ad2011-12-16 21:51:46560 // Map of SiteInstance ID to max page ID for this tab. A page ID is specific
561 // to a given tab and SiteInstance, and must be valid for the lifetime of the
562 // TabContents.
563 std::map<int32, int32> max_page_ids_;
[email protected]0dd3a0ab2011-02-18 08:17:44564
565 // System time at which the current load was started.
566 base::TimeTicks current_load_start_;
567
568 // The current load state and the URL associated with it.
[email protected]9c235f042011-08-10 22:28:21569 net::LoadStateWithParam load_state_;
[email protected]0dd3a0ab2011-02-18 08:17:44570 string16 load_state_host_;
571 // Upload progress, for displaying in the status bar.
572 // Set to zero when there is no significant upload happening.
573 uint64 upload_size_;
574 uint64 upload_position_;
575
576 // Data for current page -----------------------------------------------------
577
[email protected]987fc3a2011-05-26 14:18:09578 // When a title cannot be taken from any entry, this title will be used.
579 string16 page_title_when_no_navigation_entry_;
580
[email protected]0dd3a0ab2011-02-18 08:17:44581 // When a navigation occurs, we record its contents MIME type. It can be
582 // used to check whether we can do something for some special contents.
583 std::string contents_mime_type_;
584
585 // Character encoding.
586 std::string encoding_;
587
[email protected]0dd3a0ab2011-02-18 08:17:44588 // True if this is a secure page which displayed insecure content.
589 bool displayed_insecure_content_;
590
[email protected]0dd3a0ab2011-02-18 08:17:44591 // Data for misc internal state ----------------------------------------------
592
[email protected]be1f56ab2011-12-22 06:55:31593 // Whether the tab contents is currently being screenshotted by the
594 // DraggedTabController.
[email protected]0dd3a0ab2011-02-18 08:17:44595 bool capturing_contents_;
596
597 // See getter above.
598 bool is_being_destroyed_;
599
600 // Indicates whether we should notify about disconnection of this
601 // TabContents. This is used to ensure disconnection notifications only
602 // happen if a connection notification has happened and that they happen only
603 // once.
604 bool notify_disconnection_;
605
[email protected]2e5b90c2011-08-16 21:11:55606 // Pointer to the JavaScript dialog creator, lazily assigned. Used because the
607 // delegate of this TabContents is nulled before its destructor is called.
608 content::JavaScriptDialogCreator* dialog_creator_;
609
[email protected]0dd3a0ab2011-02-18 08:17:44610#if defined(OS_WIN)
611 // Handle to an event that's set when the page is showing a message box (or
612 // equivalent constrained window). Plugin processes check this to know if
613 // they should pump messages then.
614 base::win::ScopedHandle message_box_active_;
615#endif
616
[email protected]0dd3a0ab2011-02-18 08:17:44617 // Set to true when there is an active "before unload" dialog. When true,
618 // we've forced the throbber to start in Navigate, and we need to remember to
619 // turn it off in OnJavaScriptMessageBoxClosed if the navigation is canceled.
620 bool is_showing_before_unload_dialog_;
621
[email protected]0dd3a0ab2011-02-18 08:17:44622 // Settings that get passed to the renderer process.
[email protected]daf82f82011-10-31 22:35:31623 content::RendererPreferences renderer_preferences_;
[email protected]0dd3a0ab2011-02-18 08:17:44624
625 // If this tab was created from a renderer using window.open, this will be
626 // non-NULL and represent the WebUI of the opening renderer.
[email protected]01ec4ec2012-01-18 04:13:47627 content::WebUI::TypeID opener_web_ui_type_;
[email protected]0dd3a0ab2011-02-18 08:17:44628
629 // The time that we started to create the new tab page.
630 base::TimeTicks new_tab_start_time_;
631
632 // The time that we started to close the tab.
633 base::TimeTicks tab_close_start_time_;
634
635 // The time that this tab was last selected.
636 base::TimeTicks last_selected_time_;
637
[email protected]0dd3a0ab2011-02-18 08:17:44638 // See description above setter.
639 bool closed_by_user_gesture_;
640
641 // Minimum/maximum zoom percent.
642 int minimum_zoom_percent_;
643 int maximum_zoom_percent_;
644 // If true, the default zoom limits have been overriden for this tab, in which
645 // case we don't want saved settings to apply to it and we don't want to
646 // remember it.
647 bool temporary_zoom_settings_;
648
[email protected]bcd2815602012-01-14 18:17:23649 // The intrinsic size of the page.
650 gfx::Size preferred_size_;
651
[email protected]0dd3a0ab2011-02-18 08:17:44652 // Content restrictions, used to disable print/copy etc based on content's
653 // (full-page plugins for now only) permissions.
654 int content_restrictions_;
655
[email protected]32ded2212011-11-10 18:51:43656 // Our view type. Default is VIEW_TYPE_TAB_CONTENTS.
657 content::ViewType view_type_;
658
[email protected]0dd3a0ab2011-02-18 08:17:44659 DISALLOW_COPY_AND_ASSIGN(TabContents);
660};
661
662#endif // CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_H_