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