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