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