web_contents_impl.h revision 116680a4aac90f2aa7413d9095a592090648e557
1// Copyright (c) 2012 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_WEB_CONTENTS_WEB_CONTENTS_IMPL_H_
6#define CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_IMPL_H_
7
8#include <map>
9#include <set>
10#include <string>
11
12#include "base/compiler_specific.h"
13#include "base/gtest_prod_util.h"
14#include "base/memory/scoped_ptr.h"
15#include "base/observer_list.h"
16#include "base/process/process.h"
17#include "base/values.h"
18#include "content/browser/frame_host/frame_tree.h"
19#include "content/browser/frame_host/navigation_controller_delegate.h"
20#include "content/browser/frame_host/navigation_controller_impl.h"
21#include "content/browser/frame_host/navigator_delegate.h"
22#include "content/browser/frame_host/render_frame_host_delegate.h"
23#include "content/browser/frame_host/render_frame_host_manager.h"
24#include "content/browser/renderer_host/render_view_host_delegate.h"
25#include "content/browser/renderer_host/render_widget_host_delegate.h"
26#include "content/common/accessibility_mode_enums.h"
27#include "content/common/content_export.h"
28#include "content/public/browser/color_chooser.h"
29#include "content/public/browser/notification_observer.h"
30#include "content/public/browser/notification_registrar.h"
31#include "content/public/browser/web_contents.h"
32#include "content/public/common/page_transition_types.h"
33#include "content/public/common/renderer_preferences.h"
34#include "content/public/common/resource_type.h"
35#include "content/public/common/three_d_api_types.h"
36#include "net/base/load_states.h"
37#include "third_party/WebKit/public/web/WebDragOperation.h"
38#include "ui/gfx/rect_f.h"
39#include "ui/gfx/size.h"
40
41struct BrowserPluginHostMsg_ResizeGuest_Params;
42struct ViewHostMsg_DateTimeDialogValue_Params;
43struct ViewMsg_PostMessage_Params;
44
45namespace content {
46class BrowserPluginEmbedder;
47class BrowserPluginGuest;
48class BrowserPluginGuestManager;
49class DateTimeChooserAndroid;
50class DownloadItem;
51class GeolocationDispatcherHost;
52class InterstitialPageImpl;
53class JavaScriptDialogManager;
54class MidiDispatcherHost;
55class PowerSaveBlocker;
56class RenderViewHost;
57class RenderViewHostDelegateView;
58class RenderViewHostImpl;
59class RenderWidgetHostImpl;
60class SavePackage;
61class ScreenOrientationDispatcherHost;
62class SiteInstance;
63class TestWebContents;
64class WebContentsDelegate;
65class WebContentsImpl;
66class WebContentsObserver;
67class WebContentsView;
68class WebContentsViewDelegate;
69struct AXEventNotificationDetails;
70struct ColorSuggestion;
71struct FaviconURL;
72struct LoadNotificationDetails;
73struct ResourceRedirectDetails;
74struct ResourceRequestDetails;
75
76// Factory function for the implementations that content knows about. Takes
77// ownership of |delegate|.
78WebContentsView* CreateWebContentsView(
79    WebContentsImpl* web_contents,
80    WebContentsViewDelegate* delegate,
81    RenderViewHostDelegateView** render_view_host_delegate_view);
82
83class CONTENT_EXPORT WebContentsImpl
84    : public NON_EXPORTED_BASE(WebContents),
85      public NON_EXPORTED_BASE(RenderFrameHostDelegate),
86      public RenderViewHostDelegate,
87      public RenderWidgetHostDelegate,
88      public RenderFrameHostManager::Delegate,
89      public NotificationObserver,
90      public NON_EXPORTED_BASE(NavigationControllerDelegate),
91      public NON_EXPORTED_BASE(NavigatorDelegate) {
92 public:
93  virtual ~WebContentsImpl();
94
95  static WebContentsImpl* CreateWithOpener(
96      const WebContents::CreateParams& params,
97      WebContentsImpl* opener);
98
99  static std::vector<WebContentsImpl*> GetAllWebContents();
100
101  // Returns the opener WebContentsImpl, if any. This can be set to null if the
102  // opener is closed or the page clears its window.opener.
103  WebContentsImpl* opener() const { return opener_; }
104
105  // Creates a swapped out RenderView. This is used by the browser plugin to
106  // create a swapped out RenderView in the embedder render process for the
107  // guest, to expose the guest's window object to the embedder.
108  // This returns the routing ID of the newly created swapped out RenderView.
109  int CreateSwappedOutRenderView(SiteInstance* instance);
110
111  // Complex initialization here. Specifically needed to avoid having
112  // members call back into our virtual functions in the constructor.
113  virtual void Init(const WebContents::CreateParams& params);
114
115  // Returns the SavePackage which manages the page saving job. May be NULL.
116  SavePackage* save_package() const { return save_package_.get(); }
117
118#if defined(OS_ANDROID)
119  // In Android WebView, the RenderView needs created even there is no
120  // navigation entry, this allows Android WebViews to use
121  // javascript: URLs that load into the DOMWindow before the first page
122  // load. This is not safe to do in any context that a web page could get a
123  // reference to the DOMWindow before the first page load.
124  bool CreateRenderViewForInitialEmptyDocument();
125#endif
126
127  // Expose the render manager for testing.
128  // TODO(creis): Remove this now that we can get to it via FrameTreeNode.
129  RenderFrameHostManager* GetRenderManagerForTesting();
130
131  // Returns guest browser plugin object, or NULL if this WebContents is not a
132  // guest.
133  BrowserPluginGuest* GetBrowserPluginGuest() const;
134
135  // Sets a BrowserPluginGuest object for this WebContents. If this WebContents
136  // has a BrowserPluginGuest then that implies that it is being hosted by
137  // a BrowserPlugin object in an embedder renderer process.
138  void SetBrowserPluginGuest(BrowserPluginGuest* guest);
139
140  // Returns embedder browser plugin object, or NULL if this WebContents is not
141  // an embedder.
142  BrowserPluginEmbedder* GetBrowserPluginEmbedder() const;
143
144  // Gets the current fullscreen render widget's routing ID. Returns
145  // MSG_ROUTING_NONE when there is no fullscreen render widget.
146  int GetFullscreenWidgetRoutingID() const;
147
148  // Invoked when visible SSL state (as defined by SSLStatus) changes.
149  void DidChangeVisibleSSLState();
150
151  // Informs the render view host and the BrowserPluginEmbedder, if present, of
152  // a Drag Source End.
153  void DragSourceEndedAt(int client_x, int client_y, int screen_x,
154      int screen_y, blink::WebDragOperation operation);
155
156  // A response has been received for a resource request.
157  void DidGetResourceResponseStart(
158      const ResourceRequestDetails& details);
159
160  // A redirect was received while requesting a resource.
161  void DidGetRedirectForResourceRequest(
162      RenderViewHost* render_view_host,
163      const ResourceRedirectDetails& details);
164
165  WebContentsView* GetView() const;
166
167  GeolocationDispatcherHost* geolocation_dispatcher_host() {
168    return geolocation_dispatcher_host_.get();
169  }
170
171  ScreenOrientationDispatcherHost* screen_orientation_dispatcher_host() {
172    return screen_orientation_dispatcher_host_.get();
173  }
174
175  bool should_normally_be_visible() { return should_normally_be_visible_; }
176
177  // Broadcasts the mode change to all frames.
178  void SetAccessibilityMode(AccessibilityMode mode);
179
180  // Adds the given accessibility mode to the current accessibility mode
181  // bitmap.
182  void AddAccessibilityMode(AccessibilityMode mode);
183
184  // Removes the given accessibility mode from the current accessibility
185  // mode bitmap, managing the bits that are shared with other modes such
186  // that a bit will only be turned off when all modes that depend on it
187  // have been removed.
188  void RemoveAccessibilityMode(AccessibilityMode mode);
189
190  // WebContents ------------------------------------------------------
191  virtual WebContentsDelegate* GetDelegate() OVERRIDE;
192  virtual void SetDelegate(WebContentsDelegate* delegate) OVERRIDE;
193  virtual NavigationControllerImpl& GetController() OVERRIDE;
194  virtual const NavigationControllerImpl& GetController() const OVERRIDE;
195  virtual BrowserContext* GetBrowserContext() const OVERRIDE;
196  virtual const GURL& GetURL() const OVERRIDE;
197  virtual const GURL& GetVisibleURL() const OVERRIDE;
198  virtual const GURL& GetLastCommittedURL() const OVERRIDE;
199  virtual RenderProcessHost* GetRenderProcessHost() const OVERRIDE;
200  virtual RenderFrameHost* GetMainFrame() OVERRIDE;
201  virtual RenderFrameHost* GetFocusedFrame() OVERRIDE;
202  virtual void ForEachFrame(
203      const base::Callback<void(RenderFrameHost*)>& on_frame) OVERRIDE;
204  virtual void SendToAllFrames(IPC::Message* message) OVERRIDE;
205  virtual RenderViewHost* GetRenderViewHost() const OVERRIDE;
206  virtual int GetRoutingID() const OVERRIDE;
207  virtual RenderWidgetHostView* GetRenderWidgetHostView() const OVERRIDE;
208  virtual RenderWidgetHostView* GetFullscreenRenderWidgetHostView() const
209      OVERRIDE;
210  virtual WebUI* CreateWebUI(const GURL& url) OVERRIDE;
211  virtual WebUI* GetWebUI() const OVERRIDE;
212  virtual WebUI* GetCommittedWebUI() const OVERRIDE;
213  virtual void SetUserAgentOverride(const std::string& override) OVERRIDE;
214  virtual const std::string& GetUserAgentOverride() const OVERRIDE;
215  virtual void EnableTreeOnlyAccessibilityMode() OVERRIDE;
216  virtual bool IsTreeOnlyAccessibilityModeForTesting() const OVERRIDE;
217  virtual bool IsFullAccessibilityModeForTesting() const OVERRIDE;
218#if defined(OS_WIN)
219  virtual void SetParentNativeViewAccessible(
220      gfx::NativeViewAccessible accessible_parent) OVERRIDE;
221#endif
222  virtual const base::string16& GetTitle() const OVERRIDE;
223  virtual int32 GetMaxPageID() OVERRIDE;
224  virtual int32 GetMaxPageIDForSiteInstance(
225      SiteInstance* site_instance) OVERRIDE;
226  virtual SiteInstance* GetSiteInstance() const OVERRIDE;
227  virtual SiteInstance* GetPendingSiteInstance() const OVERRIDE;
228  virtual bool IsLoading() const OVERRIDE;
229  virtual bool IsLoadingToDifferentDocument() const OVERRIDE;
230  virtual bool IsWaitingForResponse() const OVERRIDE;
231  virtual const net::LoadStateWithParam& GetLoadState() const OVERRIDE;
232  virtual const base::string16& GetLoadStateHost() const OVERRIDE;
233  virtual uint64 GetUploadSize() const OVERRIDE;
234  virtual uint64 GetUploadPosition() const OVERRIDE;
235  virtual std::set<GURL> GetSitesInTab() const OVERRIDE;
236  virtual const std::string& GetEncoding() const OVERRIDE;
237  virtual bool DisplayedInsecureContent() const OVERRIDE;
238  virtual void IncrementCapturerCount(const gfx::Size& capture_size) OVERRIDE;
239  virtual void DecrementCapturerCount() OVERRIDE;
240  virtual int GetCapturerCount() const OVERRIDE;
241  virtual bool IsCrashed() const OVERRIDE;
242  virtual void SetIsCrashed(base::TerminationStatus status,
243                            int error_code) OVERRIDE;
244  virtual base::TerminationStatus GetCrashedStatus() const OVERRIDE;
245  virtual bool IsBeingDestroyed() const OVERRIDE;
246  virtual void NotifyNavigationStateChanged(unsigned changed_flags) OVERRIDE;
247  virtual base::TimeTicks GetLastActiveTime() const OVERRIDE;
248  virtual void WasShown() OVERRIDE;
249  virtual void WasHidden() OVERRIDE;
250  virtual bool NeedToFireBeforeUnload() OVERRIDE;
251  virtual void DispatchBeforeUnload(bool for_cross_site_transition) OVERRIDE;
252  virtual void Stop() OVERRIDE;
253  virtual WebContents* Clone() OVERRIDE;
254  virtual void ReloadFocusedFrame(bool ignore_cache) OVERRIDE;
255  virtual void Undo() OVERRIDE;
256  virtual void Redo() OVERRIDE;
257  virtual void Cut() OVERRIDE;
258  virtual void Copy() OVERRIDE;
259  virtual void CopyToFindPboard() OVERRIDE;
260  virtual void Paste() OVERRIDE;
261  virtual void PasteAndMatchStyle() OVERRIDE;
262  virtual void Delete() OVERRIDE;
263  virtual void SelectAll() OVERRIDE;
264  virtual void Unselect() OVERRIDE;
265  virtual void Replace(const base::string16& word) OVERRIDE;
266  virtual void ReplaceMisspelling(const base::string16& word) OVERRIDE;
267  virtual void NotifyContextMenuClosed(
268      const CustomContextMenuContext& context) OVERRIDE;
269  virtual void ExecuteCustomContextMenuCommand(
270      int action, const CustomContextMenuContext& context) OVERRIDE;
271  virtual gfx::NativeView GetNativeView() OVERRIDE;
272  virtual gfx::NativeView GetContentNativeView() OVERRIDE;
273  virtual gfx::NativeWindow GetTopLevelNativeWindow() OVERRIDE;
274  virtual gfx::Rect GetContainerBounds() OVERRIDE;
275  virtual gfx::Rect GetViewBounds() OVERRIDE;
276  virtual DropData* GetDropData() OVERRIDE;
277  virtual void Focus() OVERRIDE;
278  virtual void SetInitialFocus() OVERRIDE;
279  virtual void StoreFocus() OVERRIDE;
280  virtual void RestoreFocus() OVERRIDE;
281  virtual void FocusThroughTabTraversal(bool reverse) OVERRIDE;
282  virtual bool ShowingInterstitialPage() const OVERRIDE;
283  virtual InterstitialPage* GetInterstitialPage() const OVERRIDE;
284  virtual bool IsSavable() OVERRIDE;
285  virtual void OnSavePage() OVERRIDE;
286  virtual bool SavePage(const base::FilePath& main_file,
287                        const base::FilePath& dir_path,
288                        SavePageType save_type) OVERRIDE;
289  virtual void SaveFrame(const GURL& url,
290                         const Referrer& referrer) OVERRIDE;
291  virtual void GenerateMHTML(
292      const base::FilePath& file,
293      const base::Callback<void(int64)>& callback)
294          OVERRIDE;
295  virtual const std::string& GetContentsMimeType() const OVERRIDE;
296  virtual bool WillNotifyDisconnection() const OVERRIDE;
297  virtual void SetOverrideEncoding(const std::string& encoding) OVERRIDE;
298  virtual void ResetOverrideEncoding() OVERRIDE;
299  virtual RendererPreferences* GetMutableRendererPrefs() OVERRIDE;
300  virtual void Close() OVERRIDE;
301  virtual void SystemDragEnded() OVERRIDE;
302  virtual void UserGestureDone() OVERRIDE;
303  virtual void SetClosedByUserGesture(bool value) OVERRIDE;
304  virtual bool GetClosedByUserGesture() const OVERRIDE;
305  virtual void ViewSource() OVERRIDE;
306  virtual void ViewFrameSource(const GURL& url,
307                               const PageState& page_state) OVERRIDE;
308  virtual int GetMinimumZoomPercent() const OVERRIDE;
309  virtual int GetMaximumZoomPercent() const OVERRIDE;
310  virtual gfx::Size GetPreferredSize() const OVERRIDE;
311  virtual bool GotResponseToLockMouseRequest(bool allowed) OVERRIDE;
312  virtual bool HasOpener() const OVERRIDE;
313  virtual void DidChooseColorInColorChooser(SkColor color) OVERRIDE;
314  virtual void DidEndColorChooser() OVERRIDE;
315  virtual int DownloadImage(const GURL& url,
316                            bool is_favicon,
317                            uint32_t max_bitmap_size,
318                            const ImageDownloadCallback& callback) OVERRIDE;
319  virtual bool IsSubframe() const OVERRIDE;
320  virtual void Find(int request_id,
321                    const base::string16& search_text,
322                    const blink::WebFindOptions& options) OVERRIDE;
323  virtual void StopFinding(StopFindAction action) OVERRIDE;
324  virtual void InsertCSS(const std::string& css) OVERRIDE;
325#if defined(OS_ANDROID)
326  virtual base::android::ScopedJavaLocalRef<jobject> GetJavaWebContents()
327      OVERRIDE;
328#elif defined(OS_MACOSX)
329  virtual void SetAllowOverlappingViews(bool overlapping) OVERRIDE;
330  virtual bool GetAllowOverlappingViews() OVERRIDE;
331  virtual void SetAllowOtherViews(bool allow) OVERRIDE;
332  virtual bool GetAllowOtherViews() OVERRIDE;
333#endif
334
335  // Implementation of PageNavigator.
336  virtual WebContents* OpenURL(const OpenURLParams& params) OVERRIDE;
337
338  // Implementation of IPC::Sender.
339  virtual bool Send(IPC::Message* message) OVERRIDE;
340
341  // RenderFrameHostDelegate ---------------------------------------------------
342  virtual bool OnMessageReceived(RenderFrameHost* render_frame_host,
343                                 const IPC::Message& message) OVERRIDE;
344  virtual const GURL& GetMainFrameLastCommittedURL() const OVERRIDE;
345  virtual void RenderFrameCreated(RenderFrameHost* render_frame_host) OVERRIDE;
346  virtual void RenderFrameDeleted(RenderFrameHost* render_frame_host) OVERRIDE;
347  virtual void DidStartLoading(RenderFrameHost* render_frame_host,
348                               bool to_different_document) OVERRIDE;
349  virtual void SwappedOut(RenderFrameHost* render_frame_host) OVERRIDE;
350  virtual void DidDeferAfterResponseStarted() OVERRIDE;
351  virtual bool WillHandleDeferAfterResponseStarted() OVERRIDE;
352  virtual void WorkerCrashed(RenderFrameHost* render_frame_host) OVERRIDE;
353  virtual void ShowContextMenu(RenderFrameHost* render_frame_host,
354                               const ContextMenuParams& params) OVERRIDE;
355  virtual void RunJavaScriptMessage(RenderFrameHost* render_frame_host,
356                                    const base::string16& message,
357                                    const base::string16& default_prompt,
358                                    const GURL& frame_url,
359                                    JavaScriptMessageType type,
360                                    IPC::Message* reply_msg) OVERRIDE;
361  virtual void RunBeforeUnloadConfirm(RenderFrameHost* render_frame_host,
362                                      const base::string16& message,
363                                      bool is_reload,
364                                      IPC::Message* reply_msg) OVERRIDE;
365  virtual void DidAccessInitialDocument() OVERRIDE;
366  virtual void DidDisownOpener(RenderFrameHost* render_frame_host) OVERRIDE;
367  virtual void DocumentOnLoadCompleted(
368      RenderFrameHost* render_frame_host) OVERRIDE;
369  virtual void UpdateTitle(RenderFrameHost* render_frame_host,
370                           int32 page_id,
371                           const base::string16& title,
372                           base::i18n::TextDirection title_direction) OVERRIDE;
373  virtual void UpdateEncoding(RenderFrameHost* render_frame_host,
374                              const std::string& encoding) OVERRIDE;
375  virtual WebContents* GetAsWebContents() OVERRIDE;
376  virtual bool IsNeverVisible() OVERRIDE;
377  virtual AccessibilityMode GetAccessibilityMode() const OVERRIDE;
378  virtual void AccessibilityEventReceived(
379      const std::vector<AXEventNotificationDetails>& details) OVERRIDE;
380#if defined(OS_WIN)
381  virtual gfx::NativeViewAccessible GetParentNativeViewAccessible() OVERRIDE;
382#endif
383
384  // RenderViewHostDelegate ----------------------------------------------------
385  virtual RenderViewHostDelegateView* GetDelegateView() OVERRIDE;
386  virtual bool OnMessageReceived(RenderViewHost* render_view_host,
387                                 const IPC::Message& message) OVERRIDE;
388  // RenderFrameHostDelegate has the same method, so list it there because this
389  // interface is going away.
390  // virtual WebContents* GetAsWebContents() OVERRIDE;
391  virtual gfx::Rect GetRootWindowResizerRect() const OVERRIDE;
392  virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE;
393  virtual void RenderViewReady(RenderViewHost* render_view_host) OVERRIDE;
394  virtual void RenderViewTerminated(RenderViewHost* render_view_host,
395                                    base::TerminationStatus status,
396                                    int error_code) OVERRIDE;
397  virtual void RenderViewDeleted(RenderViewHost* render_view_host) OVERRIDE;
398  virtual void UpdateState(RenderViewHost* render_view_host,
399                           int32 page_id,
400                           const PageState& page_state) OVERRIDE;
401  virtual void UpdateTargetURL(int32 page_id, const GURL& url) OVERRIDE;
402  virtual void Close(RenderViewHost* render_view_host) OVERRIDE;
403  virtual void RequestMove(const gfx::Rect& new_bounds) OVERRIDE;
404  virtual void DidCancelLoading() OVERRIDE;
405  virtual void DocumentAvailableInMainFrame(
406      RenderViewHost* render_view_host) OVERRIDE;
407  virtual void RouteCloseEvent(RenderViewHost* rvh) OVERRIDE;
408  virtual void RouteMessageEvent(
409      RenderViewHost* rvh,
410      const ViewMsg_PostMessage_Params& params) OVERRIDE;
411  virtual bool AddMessageToConsole(int32 level,
412                                   const base::string16& message,
413                                   int32 line_no,
414                                   const base::string16& source_id) OVERRIDE;
415  virtual RendererPreferences GetRendererPrefs(
416      BrowserContext* browser_context) const OVERRIDE;
417  virtual WebPreferences GetWebkitPrefs() OVERRIDE;
418  virtual void OnUserGesture() OVERRIDE;
419  virtual void OnIgnoredUIEvent() OVERRIDE;
420  virtual void RendererUnresponsive(RenderViewHost* render_view_host,
421                                    bool is_during_beforeunload,
422                                    bool is_during_unload) OVERRIDE;
423  virtual void RendererResponsive(RenderViewHost* render_view_host) OVERRIDE;
424  virtual void LoadStateChanged(const GURL& url,
425                                const net::LoadStateWithParam& load_state,
426                                uint64 upload_position,
427                                uint64 upload_size) OVERRIDE;
428  virtual void Activate() OVERRIDE;
429  virtual void Deactivate() OVERRIDE;
430  virtual void LostCapture() OVERRIDE;
431  virtual void HandleMouseDown() OVERRIDE;
432  virtual void HandleMouseUp() OVERRIDE;
433  virtual void HandlePointerActivate() OVERRIDE;
434  virtual void HandleGestureBegin() OVERRIDE;
435  virtual void HandleGestureEnd() OVERRIDE;
436  virtual void RunFileChooser(
437      RenderViewHost* render_view_host,
438      const FileChooserParams& params) OVERRIDE;
439  virtual void ToggleFullscreenMode(bool enter_fullscreen) OVERRIDE;
440  virtual bool IsFullscreenForCurrentTab() const OVERRIDE;
441  virtual void UpdatePreferredSize(const gfx::Size& pref_size) OVERRIDE;
442  virtual void ResizeDueToAutoResize(const gfx::Size& new_size) OVERRIDE;
443  virtual void RequestToLockMouse(bool user_gesture,
444                                  bool last_unlocked_by_target) OVERRIDE;
445  virtual void LostMouseLock() OVERRIDE;
446  virtual void CreateNewWindow(
447      int render_process_id,
448      int route_id,
449      int main_frame_route_id,
450      const ViewHostMsg_CreateWindow_Params& params,
451      SessionStorageNamespace* session_storage_namespace) OVERRIDE;
452  virtual void CreateNewWidget(int render_process_id,
453                               int route_id,
454                               blink::WebPopupType popup_type) OVERRIDE;
455  virtual void CreateNewFullscreenWidget(int render_process_id,
456                                         int route_id) OVERRIDE;
457  virtual void ShowCreatedWindow(int route_id,
458                                 WindowOpenDisposition disposition,
459                                 const gfx::Rect& initial_pos,
460                                 bool user_gesture) OVERRIDE;
461  virtual void ShowCreatedWidget(int route_id,
462                                 const gfx::Rect& initial_pos) OVERRIDE;
463  virtual void ShowCreatedFullscreenWidget(int route_id) OVERRIDE;
464  virtual void RequestMediaAccessPermission(
465      const MediaStreamRequest& request,
466      const MediaResponseCallback& callback) OVERRIDE;
467  virtual SessionStorageNamespace* GetSessionStorageNamespace(
468      SiteInstance* instance) OVERRIDE;
469  virtual SessionStorageNamespaceMap GetSessionStorageNamespaceMap() OVERRIDE;
470  virtual FrameTree* GetFrameTree() OVERRIDE;
471
472  // NavigatorDelegate ---------------------------------------------------------
473
474  virtual void DidStartProvisionalLoad(
475      RenderFrameHostImpl* render_frame_host,
476      const GURL& validated_url,
477      bool is_error_page,
478      bool is_iframe_srcdoc) OVERRIDE;
479  virtual void DidFailProvisionalLoadWithError(
480      RenderFrameHostImpl* render_frame_host,
481      const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params)
482      OVERRIDE;
483  virtual void DidFailLoadWithError(
484      RenderFrameHostImpl* render_frame_host,
485      const GURL& url,
486      int error_code,
487      const base::string16& error_description) OVERRIDE;
488  virtual void DidRedirectProvisionalLoad(
489      RenderFrameHostImpl* render_frame_host,
490      const GURL& validated_target_url) OVERRIDE;
491  virtual void DidCommitProvisionalLoad(
492      RenderFrameHostImpl* render_frame_host,
493      const GURL& url,
494      PageTransition transition_type) OVERRIDE;
495  virtual void DidNavigateMainFramePreCommit(
496      bool navigation_is_within_page) OVERRIDE;
497  virtual void DidNavigateMainFramePostCommit(
498      const LoadCommittedDetails& details,
499      const FrameHostMsg_DidCommitProvisionalLoad_Params& params) OVERRIDE;
500  virtual void DidNavigateAnyFramePostCommit(
501      RenderFrameHostImpl* render_frame_host,
502      const LoadCommittedDetails& details,
503      const FrameHostMsg_DidCommitProvisionalLoad_Params& params) OVERRIDE;
504  virtual void SetMainFrameMimeType(const std::string& mime_type) OVERRIDE;
505  virtual bool CanOverscrollContent() const OVERRIDE;
506  virtual void NotifyChangedNavigationState(
507      InvalidateTypes changed_flags) OVERRIDE;
508  virtual void AboutToNavigateRenderFrame(
509      RenderFrameHostImpl* render_frame_host) OVERRIDE;
510  virtual void DidStartNavigationToPendingEntry(
511      RenderFrameHostImpl* render_frame_host,
512      const GURL& url,
513      NavigationController::ReloadType reload_type) OVERRIDE;
514  virtual void RequestOpenURL(RenderFrameHostImpl* render_frame_host,
515                              const OpenURLParams& params) OVERRIDE;
516  virtual bool ShouldPreserveAbortedURLs() OVERRIDE;
517
518  // RenderWidgetHostDelegate --------------------------------------------------
519
520  virtual void RenderWidgetDeleted(
521      RenderWidgetHostImpl* render_widget_host) OVERRIDE;
522  virtual bool PreHandleKeyboardEvent(
523      const NativeWebKeyboardEvent& event,
524      bool* is_keyboard_shortcut) OVERRIDE;
525  virtual void HandleKeyboardEvent(
526      const NativeWebKeyboardEvent& event) OVERRIDE;
527  virtual bool HandleWheelEvent(
528      const blink::WebMouseWheelEvent& event) OVERRIDE;
529  virtual bool PreHandleGestureEvent(
530      const blink::WebGestureEvent& event) OVERRIDE;
531  virtual bool HandleGestureEvent(
532      const blink::WebGestureEvent& event) OVERRIDE;
533  virtual void DidSendScreenRects(RenderWidgetHostImpl* rwh) OVERRIDE;
534  virtual void OnTouchEmulationEnabled(bool enabled) OVERRIDE;
535  virtual BrowserAccessibilityManager* GetRootBrowserAccessibilityManager()
536      OVERRIDE;
537  virtual BrowserAccessibilityManager*
538      GetOrCreateRootBrowserAccessibilityManager() OVERRIDE;
539
540  // RenderFrameHostManager::Delegate ------------------------------------------
541
542  virtual bool CreateRenderViewForRenderManager(
543      RenderViewHost* render_view_host,
544      int opener_route_id,
545      int proxy_routing_id,
546      bool for_main_frame) OVERRIDE;
547  virtual void BeforeUnloadFiredFromRenderManager(
548      bool proceed, const base::TimeTicks& proceed_time,
549      bool* proceed_to_fire_unload) OVERRIDE;
550  virtual void RenderProcessGoneFromRenderManager(
551      RenderViewHost* render_view_host) OVERRIDE;
552  virtual void UpdateRenderViewSizeForRenderManager() OVERRIDE;
553  virtual void CancelModalDialogsForRenderManager() OVERRIDE;
554  virtual void NotifySwappedFromRenderManager(RenderFrameHost* old_host,
555                                              RenderFrameHost* new_host,
556                                              bool is_main_frame) OVERRIDE;
557  virtual int CreateOpenerRenderViewsForRenderManager(
558      SiteInstance* instance) OVERRIDE;
559  virtual NavigationControllerImpl&
560      GetControllerForRenderManager() OVERRIDE;
561  virtual WebUIImpl* CreateWebUIForRenderManager(const GURL& url) OVERRIDE;
562  virtual NavigationEntry*
563      GetLastCommittedNavigationEntryForRenderManager() OVERRIDE;
564  virtual bool FocusLocationBarByDefault() OVERRIDE;
565  virtual void SetFocusToLocationBar(bool select_all) OVERRIDE;
566  virtual void CreateViewAndSetSizeForRVH(RenderViewHost* rvh) OVERRIDE;
567  virtual bool IsHidden() OVERRIDE;
568
569  // NotificationObserver ------------------------------------------------------
570
571  virtual void Observe(int type,
572                       const NotificationSource& source,
573                       const NotificationDetails& details) OVERRIDE;
574
575  // NavigationControllerDelegate ----------------------------------------------
576
577  virtual WebContents* GetWebContents() OVERRIDE;
578  virtual void NotifyNavigationEntryCommitted(
579      const LoadCommittedDetails& load_details) OVERRIDE;
580
581  // Invoked before a form repost warning is shown.
582  virtual void NotifyBeforeFormRepostWarningShow() OVERRIDE;
583
584  // Activate this WebContents and show a form repost warning.
585  virtual void ActivateAndShowRepostFormWarningDialog() OVERRIDE;
586
587  // Whether the initial empty page of this view has been accessed by another
588  // page, making it unsafe to show the pending URL. Always false after the
589  // first commit.
590  virtual bool HasAccessedInitialDocument() OVERRIDE;
591
592  // Updates the max page ID for the current SiteInstance in this
593  // WebContentsImpl to be at least |page_id|.
594  virtual void UpdateMaxPageID(int32 page_id) OVERRIDE;
595
596  // Updates the max page ID for the given SiteInstance in this WebContentsImpl
597  // to be at least |page_id|.
598  virtual void UpdateMaxPageIDForSiteInstance(SiteInstance* site_instance,
599                                              int32 page_id) OVERRIDE;
600
601  // Copy the current map of SiteInstance ID to max page ID from another tab.
602  // This is necessary when this tab adopts the NavigationEntries from
603  // |web_contents|.
604  virtual void CopyMaxPageIDsFrom(WebContents* web_contents) OVERRIDE;
605
606  // Called by the NavigationController to cause the WebContentsImpl to navigate
607  // to the current pending entry. The NavigationController should be called
608  // back with RendererDidNavigate on success or DiscardPendingEntry on failure.
609  // The callbacks can be inside of this function, or at some future time.
610  //
611  // The entry has a PageID of -1 if newly created (corresponding to navigation
612  // to a new URL).
613  //
614  // If this method returns false, then the navigation is discarded (equivalent
615  // to calling DiscardPendingEntry on the NavigationController).
616  virtual bool NavigateToPendingEntry(
617      NavigationController::ReloadType reload_type) OVERRIDE;
618
619  // Sets the history for this WebContentsImpl to |history_length| entries, and
620  // moves the current page_id to the last entry in the list if it's valid.
621  // This is mainly used when a prerendered page is swapped into the current
622  // tab. The method is virtual for testing.
623  virtual void SetHistoryLengthAndPrune(
624      const SiteInstance* site_instance,
625      int merge_history_length,
626      int32 minimum_page_id) OVERRIDE;
627
628  // Called by InterstitialPageImpl when it creates a RenderFrameHost.
629  virtual void RenderFrameForInterstitialPageCreated(
630      RenderFrameHost* render_frame_host) OVERRIDE;
631
632  // Sets the passed interstitial as the currently showing interstitial.
633  // No interstitial page should already be attached.
634  virtual void AttachInterstitialPage(
635      InterstitialPageImpl* interstitial_page) OVERRIDE;
636
637  // Unsets the currently showing interstitial.
638  virtual void DetachInterstitialPage() OVERRIDE;
639
640  // Changes the IsLoading state and notifies the delegate as needed.
641  // |details| is used to provide details on the load that just finished
642  // (but can be null if not applicable).
643  virtual void SetIsLoading(RenderViewHost* render_view_host,
644                            bool is_loading,
645                            bool to_different_document,
646                            LoadNotificationDetails* details) OVERRIDE;
647
648  typedef base::Callback<void(WebContents*)> CreatedCallback;
649
650  // Requests the renderer to select the region between two points in the
651  // currently focused frame.
652  void SelectRange(const gfx::Point& start, const gfx::Point& end);
653
654  // Notifies the main frame that it can continue navigation (if it was deferred
655  // immediately at first response).
656  void ResumeResponseDeferredAtStart();
657
658 private:
659  friend class TestNavigationObserver;
660  friend class WebContentsAddedObserver;
661  friend class WebContentsObserver;
662  friend class WebContents;  // To implement factory methods.
663
664  FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, NoJSMessageOnInterstitials);
665  FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, UpdateTitle);
666  FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, FindOpenerRVHWhenPending);
667  FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest,
668                           CrossSiteCantPreemptAfterUnload);
669  FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, PendingContents);
670  FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, FrameTreeShape);
671  FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, GetLastActiveTime);
672  FRIEND_TEST_ALL_PREFIXES(FormStructureBrowserTest, HTMLFiles);
673  FRIEND_TEST_ALL_PREFIXES(NavigationControllerTest, HistoryNavigate);
674  FRIEND_TEST_ALL_PREFIXES(RenderFrameHostManagerTest, PageDoesBackAndReload);
675  FRIEND_TEST_ALL_PREFIXES(SitePerProcessBrowserTest, CrossSiteIframe);
676
677  // So InterstitialPageImpl can access SetIsLoading.
678  friend class InterstitialPageImpl;
679
680  // TODO(brettw) TestWebContents shouldn't exist!
681  friend class TestWebContents;
682
683  class DestructionObserver;
684
685  // See WebContents::Create for a description of these parameters.
686  WebContentsImpl(BrowserContext* browser_context,
687                  WebContentsImpl* opener);
688
689  // Add and remove observers for page navigation notifications. The order in
690  // which notifications are sent to observers is undefined. Clients must be
691  // sure to remove the observer before they go away.
692  void AddObserver(WebContentsObserver* observer);
693  void RemoveObserver(WebContentsObserver* observer);
694
695  // Clears this tab's opener if it has been closed.
696  void OnWebContentsDestroyed(WebContentsImpl* web_contents);
697
698  // Creates and adds to the map a destruction observer watching |web_contents|.
699  // No-op if such an observer already exists.
700  void AddDestructionObserver(WebContentsImpl* web_contents);
701
702  // Deletes and removes from the map a destruction observer
703  // watching |web_contents|. No-op if there is no such observer.
704  void RemoveDestructionObserver(WebContentsImpl* web_contents);
705
706  // Traverses all the RenderFrameHosts in the FrameTree and creates a set
707  // all the unique RenderWidgetHostViews.
708  std::set<RenderWidgetHostView*> GetRenderWidgetHostViewsInTree();
709
710  // Callback function when showing JavaScript dialogs.  Takes in a routing ID
711  // pair to identify the RenderFrameHost that opened the dialog, because it's
712  // possible for the RenderFrameHost to be deleted by the time this is called.
713  void OnDialogClosed(int render_process_id,
714                      int render_frame_id,
715                      IPC::Message* reply_msg,
716                      bool dialog_was_suppressed,
717                      bool success,
718                      const base::string16& user_input);
719
720  // Callback function when requesting permission to access the PPAPI broker.
721  // |result| is true if permission was granted.
722  void OnPpapiBrokerPermissionResult(int routing_id, bool result);
723
724  bool OnMessageReceived(RenderViewHost* render_view_host,
725                         RenderFrameHost* render_frame_host,
726                         const IPC::Message& message);
727
728  // IPC message handlers.
729  void OnThemeColorChanged(SkColor theme_color);
730  void OnDidLoadResourceFromMemoryCache(const GURL& url,
731                                        const std::string& security_info,
732                                        const std::string& http_request,
733                                        const std::string& mime_type,
734                                        ResourceType::Type resource_type);
735  void OnDidDisplayInsecureContent();
736  void OnDidRunInsecureContent(const std::string& security_origin,
737                               const GURL& target_url);
738  void OnDidDetectXSS(int32 page_id, const GURL& url, bool blocked_entire_page);
739  void OnDocumentLoadedInFrame();
740  void OnDidFinishLoad(const GURL& url);
741  void OnDidStartLoading(bool to_different_document);
742  void OnDidStopLoading();
743  void OnDidChangeLoadProgress(double load_progress);
744  void OnGoToEntryAtOffset(int offset);
745  void OnUpdateZoomLimits(int minimum_percent,
746                          int maximum_percent);
747  void OnEnumerateDirectory(int request_id, const base::FilePath& path);
748
749  void OnRegisterProtocolHandler(const std::string& protocol,
750                                 const GURL& url,
751                                 const base::string16& title,
752                                 bool user_gesture);
753  void OnUnregisterProtocolHandler(const std::string& protocol,
754                                   const GURL& url,
755                                   bool user_gesture);
756  void OnFindReply(int request_id,
757                   int number_of_matches,
758                   const gfx::Rect& selection_rect,
759                   int active_match_ordinal,
760                   bool final_update);
761#if defined(OS_ANDROID)
762  void OnFindMatchRectsReply(int version,
763                             const std::vector<gfx::RectF>& rects,
764                             const gfx::RectF& active_rect);
765
766  void OnOpenDateTimeDialog(
767      const ViewHostMsg_DateTimeDialogValue_Params& value);
768#endif
769  void OnPepperPluginHung(int plugin_child_id,
770                          const base::FilePath& path,
771                          bool is_hung);
772  void OnPluginCrashed(const base::FilePath& plugin_path,
773                       base::ProcessId plugin_pid);
774  void OnDomOperationResponse(const std::string& json_string,
775                              int automation_id);
776  void OnAppCacheAccessed(const GURL& manifest_url, bool blocked_by_policy);
777  void OnOpenColorChooser(int color_chooser_id,
778                          SkColor color,
779                          const std::vector<ColorSuggestion>& suggestions);
780  void OnEndColorChooser(int color_chooser_id);
781  void OnSetSelectedColorInColorChooser(int color_chooser_id, SkColor color);
782  void OnWebUISend(const GURL& source_url,
783                   const std::string& name,
784                   const base::ListValue& args);
785  void OnRequestPpapiBrokerPermission(int routing_id,
786                                      const GURL& url,
787                                      const base::FilePath& plugin_path);
788  void OnBrowserPluginMessage(const IPC::Message& message);
789  void OnDidDownloadImage(int id,
790                          int http_status_code,
791                          const GURL& image_url,
792                          const std::vector<SkBitmap>& bitmaps,
793                          const std::vector<gfx::Size>& original_bitmap_sizes);
794  void OnUpdateFaviconURL(const std::vector<FaviconURL>& candidates);
795  void OnFirstVisuallyNonEmptyPaint();
796  void OnMediaPlayingNotification(int64 player_cookie,
797                                  bool has_video,
798                                  bool has_audio);
799  void OnMediaPausedNotification(int64 player_cookie);
800  void OnShowValidationMessage(const gfx::Rect& anchor_in_root_view,
801                               const base::string16& main_text,
802                               const base::string16& sub_text);
803  void OnHideValidationMessage();
804  void OnMoveValidationMessage(const gfx::Rect& anchor_in_root_view);
805
806  // Called by derived classes to indicate that we're no longer waiting for a
807  // response. This won't actually update the throbber, but it will get picked
808  // up at the next animation step if the throbber is going.
809  void SetNotWaitingForResponse() { waiting_for_response_ = false; }
810
811  // Navigation helpers --------------------------------------------------------
812  //
813  // These functions are helpers for Navigate() and DidNavigate().
814
815  // Handles post-navigation tasks in DidNavigate AFTER the entry has been
816  // committed to the navigation controller. Note that the navigation entry is
817  // not provided since it may be invalid/changed after being committed. The
818  // current navigation entry is in the NavigationController at this point.
819
820  // If our controller was restored, update the max page ID associated with the
821  // given RenderViewHost to be larger than the number of restored entries.
822  // This is called in CreateRenderView before any navigations in the RenderView
823  // have begun, to prevent any races in updating RenderView::next_page_id.
824  void UpdateMaxPageIDIfNecessary(RenderViewHost* rvh);
825
826  // Saves the given title to the navigation entry and does associated work. It
827  // will update history and the view for the new title, and also synthesize
828  // titles for file URLs that have none (so we require that the URL of the
829  // entry already be set).
830  //
831  // This is used as the backend for state updates, which include a new title,
832  // or the dedicated set title message. It returns true if the new title is
833  // different and was therefore updated.
834  bool UpdateTitleForEntry(NavigationEntryImpl* entry,
835                           const base::string16& title);
836
837  // Recursively creates swapped out RenderViews for this tab's opener chain
838  // (including this tab) in the given SiteInstance, allowing other tabs to send
839  // cross-process JavaScript calls to their opener(s).  Returns the route ID of
840  // this tab's RenderView for |instance|.
841  int CreateOpenerRenderViews(SiteInstance* instance);
842
843  // Helper for CreateNewWidget/CreateNewFullscreenWidget.
844  void CreateNewWidget(int render_process_id,
845                       int route_id,
846                       bool is_fullscreen,
847                       blink::WebPopupType popup_type);
848
849  // Helper for ShowCreatedWidget/ShowCreatedFullscreenWidget.
850  void ShowCreatedWidget(int route_id,
851                         bool is_fullscreen,
852                         const gfx::Rect& initial_pos);
853
854  // Finds the new RenderWidgetHost and returns it. Note that this can only be
855  // called once as this call also removes it from the internal map.
856  RenderWidgetHostView* GetCreatedWidget(int route_id);
857
858  // Finds the new WebContentsImpl by route_id, initializes it for
859  // renderer-initiated creation, and returns it. Note that this can only be
860  // called once as this call also removes it from the internal map.
861  WebContentsImpl* GetCreatedWindow(int route_id);
862
863  // Tracking loading progress -------------------------------------------------
864
865  // Resets the tracking state of the current load.
866  void ResetLoadProgressState();
867
868  // Calculates the progress of the current load and notifies the delegate.
869  void SendLoadProgressChanged();
870
871  // Called once when the last frame on the page has stopped loading.
872  void DidStopLoading(RenderFrameHost* render_frame_host);
873
874  // Misc non-view stuff -------------------------------------------------------
875
876  // Helper functions for sending notifications.
877  void NotifyViewSwapped(RenderViewHost* old_host, RenderViewHost* new_host);
878  void NotifyFrameSwapped(RenderFrameHost* old_host, RenderFrameHost* new_host);
879  void NotifyDisconnected();
880
881  void SetEncoding(const std::string& encoding);
882
883  // TODO(creis): This should take in a FrameTreeNode to know which node's
884  // render manager to return.  For now, we just return the root's.
885  RenderFrameHostManager* GetRenderManager() const;
886
887  RenderViewHostImpl* GetRenderViewHostImpl();
888
889  // Removes browser plugin embedder if there is one.
890  void RemoveBrowserPluginEmbedder();
891
892  // Clear |render_frame_host|'s PowerSaveBlockers.
893  void ClearPowerSaveBlockers(RenderFrameHost* render_frame_host);
894
895  // Clear all PowerSaveBlockers, leave power_save_blocker_ empty.
896  void ClearAllPowerSaveBlockers();
897
898  // Helper function to invoke WebContentsDelegate::GetSizeForNewRenderView().
899  gfx::Size GetSizeForNewRenderView();
900
901  void OnFrameRemoved(RenderFrameHost* render_frame_host);
902
903  // Helper method that's called whenever |preferred_size_| or
904  // |preferred_size_for_capture_| changes, to propagate the new value to the
905  // |delegate_|.
906  void OnPreferredSizeChanged(const gfx::Size& old_size);
907
908  // Adds/removes a callback called on creation of each new WebContents.
909  // Deprecated, about to remove.
910  static void AddCreatedCallback(const CreatedCallback& callback);
911  static void RemoveCreatedCallback(const CreatedCallback& callback);
912
913  // Data for core operation ---------------------------------------------------
914
915  // Delegate for notifying our owner about stuff. Not owned by us.
916  WebContentsDelegate* delegate_;
917
918  // Handles the back/forward list and loading.
919  NavigationControllerImpl controller_;
920
921  // The corresponding view.
922  scoped_ptr<WebContentsView> view_;
923
924  // The view of the RVHD. Usually this is our WebContentsView implementation,
925  // but if an embedder uses a different WebContentsView, they'll need to
926  // provide this.
927  RenderViewHostDelegateView* render_view_host_delegate_view_;
928
929  // Tracks created WebContentsImpl objects that have not been shown yet. They
930  // are identified by the route ID passed to CreateNewWindow.
931  typedef std::map<int, WebContentsImpl*> PendingContents;
932  PendingContents pending_contents_;
933
934  // These maps hold on to the widgets that we created on behalf of the renderer
935  // that haven't shown yet.
936  typedef std::map<int, RenderWidgetHostView*> PendingWidgetViews;
937  PendingWidgetViews pending_widget_views_;
938
939  typedef std::map<WebContentsImpl*, DestructionObserver*> DestructionObservers;
940  DestructionObservers destruction_observers_;
941
942  // A list of observers notified when page state changes. Weak references.
943  // This MUST be listed above frame_tree_ since at destruction time the
944  // latter might cause RenderViewHost's destructor to call us and we might use
945  // the observer list then.
946  ObserverList<WebContentsObserver> observers_;
947
948  // The tab that opened this tab, if any.  Will be set to null if the opener
949  // is closed.
950  WebContentsImpl* opener_;
951
952  // True if this tab was opened by another tab. This is not unset if the opener
953  // is closed.
954  bool created_with_opener_;
955
956#if defined(OS_WIN)
957  gfx::NativeViewAccessible accessible_parent_;
958#endif
959
960  // Helper classes ------------------------------------------------------------
961
962  // Maps the RenderFrameHost to its media_player_cookie and PowerSaveBlocker
963  // pairs. Key is the RenderFrameHost, value is the map which maps
964  // player_cookie on to PowerSaveBlocker.
965  typedef std::map<RenderFrameHost*, std::map<int64, PowerSaveBlocker*> >
966      PowerSaveBlockerMap;
967  PowerSaveBlockerMap power_save_blockers_;
968
969  // Manages the frame tree of the page and process swaps in each node.
970  FrameTree frame_tree_;
971
972  // SavePackage, lazily created.
973  scoped_refptr<SavePackage> save_package_;
974
975  // Data for loading state ----------------------------------------------------
976
977  // Indicates whether we're currently loading a resource.
978  bool is_loading_;
979
980  // Indicates whether the current load is to a different document. Only valid
981  // if is_loading_ is true.
982  bool is_load_to_different_document_;
983
984  // Indicates if the tab is considered crashed.
985  base::TerminationStatus crashed_status_;
986  int crashed_error_code_;
987
988  // Whether this WebContents is waiting for a first-response for the
989  // main resource of the page. This controls whether the throbber state is
990  // "waiting" or "loading."
991  bool waiting_for_response_;
992
993  // Map of SiteInstance ID to max page ID for this tab. A page ID is specific
994  // to a given tab and SiteInstance, and must be valid for the lifetime of the
995  // WebContentsImpl.
996  std::map<int32, int32> max_page_ids_;
997
998  // The current load state and the URL associated with it.
999  net::LoadStateWithParam load_state_;
1000  base::string16 load_state_host_;
1001
1002  // LoadingProgressMap maps FrameTreeNode IDs to a double representing that
1003  // frame's completion (from 0 to 1).
1004  typedef base::hash_map<int64, double> LoadingProgressMap;
1005  LoadingProgressMap loading_progresses_;
1006  double loading_total_progress_;
1007
1008  base::TimeTicks loading_last_progress_update_;
1009
1010  base::WeakPtrFactory<WebContentsImpl> loading_weak_factory_;
1011
1012  // Counter to track how many frames have sent start notifications but not
1013  // stop notifications.
1014  int loading_frames_in_progress_;
1015
1016  // Upload progress, for displaying in the status bar.
1017  // Set to zero when there is no significant upload happening.
1018  uint64 upload_size_;
1019  uint64 upload_position_;
1020
1021  // Data for current page -----------------------------------------------------
1022
1023  // When a title cannot be taken from any entry, this title will be used.
1024  base::string16 page_title_when_no_navigation_entry_;
1025
1026  // When a navigation occurs, we record its contents MIME type. It can be
1027  // used to check whether we can do something for some special contents.
1028  std::string contents_mime_type_;
1029
1030  // The last reported character encoding, not canonicalized.
1031  std::string last_reported_encoding_;
1032
1033  // The canonicalized character encoding.
1034  std::string canonical_encoding_;
1035
1036  // True if this is a secure page which displayed insecure content.
1037  bool displayed_insecure_content_;
1038
1039  // Whether the initial empty page has been accessed by another page, making it
1040  // unsafe to show the pending URL. Usually false unless another window tries
1041  // to modify the blank page.  Always false after the first commit.
1042  bool has_accessed_initial_document_;
1043
1044  // Data for misc internal state ----------------------------------------------
1045
1046  // When > 0, the WebContents is currently being captured (e.g., for
1047  // screenshots or mirroring); and the underlying RenderWidgetHost should not
1048  // be told it is hidden.
1049  int capturer_count_;
1050
1051  // Tracks whether RWHV should be visible once capturer_count_ becomes zero.
1052  bool should_normally_be_visible_;
1053
1054  // See getter above.
1055  bool is_being_destroyed_;
1056
1057  // Indicates whether we should notify about disconnection of this
1058  // WebContentsImpl. This is used to ensure disconnection notifications only
1059  // happen if a connection notification has happened and that they happen only
1060  // once.
1061  bool notify_disconnection_;
1062
1063  // Pointer to the JavaScript dialog manager, lazily assigned. Used because the
1064  // delegate of this WebContentsImpl is nulled before its destructor is called.
1065  JavaScriptDialogManager* dialog_manager_;
1066
1067  // Set to true when there is an active "before unload" dialog.  When true,
1068  // we've forced the throbber to start in Navigate, and we need to remember to
1069  // turn it off in OnJavaScriptMessageBoxClosed if the navigation is canceled.
1070  bool is_showing_before_unload_dialog_;
1071
1072  // Settings that get passed to the renderer process.
1073  RendererPreferences renderer_preferences_;
1074
1075  // The time that this WebContents was last made active. The initial value is
1076  // the WebContents creation time.
1077  base::TimeTicks last_active_time_;
1078
1079  // See description above setter.
1080  bool closed_by_user_gesture_;
1081
1082  // Minimum/maximum zoom percent.
1083  int minimum_zoom_percent_;
1084  int maximum_zoom_percent_;
1085
1086  // The raw accumulated zoom value and the actual zoom increments made for an
1087  // an in-progress pinch gesture.
1088  float totalPinchGestureAmount_;
1089  int currentPinchZoomStepDelta_;
1090
1091  // The intrinsic size of the page.
1092  gfx::Size preferred_size_;
1093
1094  // The preferred size for content screen capture.  When |capturer_count_| > 0,
1095  // this overrides |preferred_size_|.
1096  gfx::Size preferred_size_for_capture_;
1097
1098#if defined(OS_ANDROID)
1099  // Date time chooser opened by this tab.
1100  // Only used in Android since all other platforms use a multi field UI.
1101  scoped_ptr<DateTimeChooserAndroid> date_time_chooser_;
1102#endif
1103
1104  // Holds information about a current color chooser dialog, if one is visible.
1105  struct ColorChooserInfo {
1106    ColorChooserInfo(int render_process_id,
1107                     int render_frame_id,
1108                     ColorChooser* chooser,
1109                     int identifier);
1110    ~ColorChooserInfo();
1111
1112    int render_process_id;
1113    int render_frame_id;
1114
1115    // Color chooser that was opened by this tab.
1116    scoped_ptr<ColorChooser> chooser;
1117
1118    // A unique identifier for the current color chooser.  Identifiers are
1119    // unique across a renderer process.  This avoids race conditions in
1120    // synchronizing the browser and renderer processes.  For example, if a
1121    // renderer closes one chooser and opens another, and simultaneously the
1122    // user picks a color in the first chooser, the IDs can be used to drop the
1123    // "chose a color" message rather than erroneously tell the renderer that
1124    // the user picked a color in the second chooser.
1125    int identifier;
1126  };
1127
1128  scoped_ptr<ColorChooserInfo> color_chooser_info_;
1129
1130  // Manages the embedder state for browser plugins, if this WebContents is an
1131  // embedder; NULL otherwise.
1132  scoped_ptr<BrowserPluginEmbedder> browser_plugin_embedder_;
1133  // Manages the guest state for browser plugin, if this WebContents is a guest;
1134  // NULL otherwise.
1135  scoped_ptr<BrowserPluginGuest> browser_plugin_guest_;
1136
1137  // This must be at the end, or else we might get notifications and use other
1138  // member variables that are gone.
1139  NotificationRegistrar registrar_;
1140
1141  // Used during IPC message dispatching from the RenderView/RenderFrame so that
1142  // the handlers can get a pointer to the RVH through which the message was
1143  // received.
1144  RenderViewHost* render_view_message_source_;
1145  RenderFrameHost* render_frame_message_source_;
1146
1147  // All live RenderWidgetHostImpls that are created by this object and may
1148  // outlive it.
1149  std::set<RenderWidgetHostImpl*> created_widgets_;
1150
1151  // Routing id of the shown fullscreen widget or MSG_ROUTING_NONE otherwise.
1152  int fullscreen_widget_routing_id_;
1153
1154  // At the time the fullscreen widget was being shut down, did it have focus?
1155  // This is used to restore focus to the WebContentsView after both: 1) the
1156  // fullscreen widget is destroyed, and 2) the WebContentsDelegate has
1157  // completed making layout changes to effect an exit from fullscreen mode.
1158  bool fullscreen_widget_had_focus_at_shutdown_;
1159
1160  // Maps the ids of pending image downloads to their callbacks
1161  typedef std::map<int, ImageDownloadCallback> ImageDownloadMap;
1162  ImageDownloadMap image_download_map_;
1163
1164  // Whether this WebContents is responsible for displaying a subframe in a
1165  // different process from its parent page.
1166  bool is_subframe_;
1167
1168  // Whether touch emulation is enabled in RenderWidgetHost.
1169  bool touch_emulation_enabled_;
1170
1171  // Whether the last JavaScript dialog shown was suppressed. Used for testing.
1172  bool last_dialog_suppressed_;
1173
1174  scoped_ptr<GeolocationDispatcherHost> geolocation_dispatcher_host_;
1175
1176  scoped_ptr<MidiDispatcherHost> midi_dispatcher_host_;
1177
1178  scoped_ptr<ScreenOrientationDispatcherHost>
1179      screen_orientation_dispatcher_host_;
1180
1181  // The accessibility mode for all frames. This is queried when each frame
1182  // is created, and broadcast to all frames when it changes.
1183  AccessibilityMode accessibility_mode_;
1184
1185  DISALLOW_COPY_AND_ASSIGN(WebContentsImpl);
1186};
1187
1188}  // namespace content
1189
1190#endif  // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_IMPL_H_
1191