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