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