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