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