web_contents.h revision 7d4cd473f85ac64c3747c96c277f9e506a0d2246
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h"
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/callback_forward.h"
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/process_util.h"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/strings/string16.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/supports_user_data.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/common/content_export.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/navigation_controller.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/page_navigator.h"
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/save_page_type.h"
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/web_ui.h"
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ipc/ipc_sender.h"
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "third_party/skia/include/core/SkColor.h"
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/window_open_disposition.h"
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/native_widget_types.h"
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/size.h"
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace base {
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class TimeTicks;
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace gfx {
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Rect;
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Size;
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace net {
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct LoadStateWithParam;
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace content {
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class BrowserContext;
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class InterstitialPage;
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class PageState;
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class RenderProcessHost;
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class RenderViewHost;
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class RenderWidgetHostView;
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class SiteInstance;
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WebContentsDelegate;
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WebContentsView;
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct RendererPreferences;
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// WebContents is the core class in content/. A WebContents renders web content
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// (usually HTML) in a rectangular area.
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Instantiating one is simple:
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//   scoped_ptr<content::WebContents> web_contents(
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//       content::WebContents::Create(
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//           content::WebContents::CreateParams(browser_context)));
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//   gfx::NativeView view = web_contents->GetView()->GetNativeView();
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//   // |view| is an HWND, NSView*, GtkWidget*, etc.; insert it into the view
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//   // hierarchy wherever it needs to go.
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// That's it; go to your kitchen, grab a scone, and chill. WebContents will do
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// all the multi-process stuff behind the scenes. More details are at
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// http://www.chromium.org/developers/design-documents/multi-process-architecture .
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Each WebContents has exactly one NavigationController; each
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// NavigationController belongs to one WebContents. The NavigationController can
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// be obtained from GetController(), and is used to load URLs into the
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// WebContents, navigate it backwards/forwards, etc. See navigation_controller.h
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// for more details.
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WebContents : public PageNavigator,
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    public IPC::Sender,
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    public base::SupportsUserData {
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
74c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  struct CONTENT_EXPORT CreateParams {
75c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    explicit CreateParams(BrowserContext* context);
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    CreateParams(BrowserContext* context, SiteInstance* site);
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    BrowserContext* browser_context;
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    SiteInstance* site_instance;
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    int routing_id;
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    int main_frame_routing_id;
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Initial size of the new WebContent's view. Can be (0, 0) if not needed.
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    gfx::Size initial_size;
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Used to specify the location context which display the new view should
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // belong. This can be NULL if not needed.
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    gfx::NativeView context;
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Creates a new WebContents.
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CONTENT_EXPORT static WebContents* Create(const CreateParams& params);
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Similar to Create() above but should be used when you need to prepopulate
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the SessionStorageNamespaceMap of the WebContents. This can happen if
96a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  // you duplicate a WebContents, try to reconstitute it from a saved state,
97a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  // or when you create a new WebContents based on another one (eg., when
98a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  // servicing a window.open() call).
99a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  //
100a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  // You do not want to call this. If you think you do, make sure you completely
101a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  // understand when SessionStorageNamespace objects should be cloned, why
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // they should not be shared by multiple WebContents, and what bad things
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // can happen if you share the object.
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CONTENT_EXPORT static WebContents* CreateWithSessionStorage(
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const CreateParams& params,
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const SessionStorageNamespaceMap& session_storage_namespace_map);
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Adds/removes a callback called on creation of each new WebContents.
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  typedef base::Callback<void(WebContents*)> CreatedCallback;
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CONTENT_EXPORT static void AddCreatedCallback(
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const CreatedCallback& callback);
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CONTENT_EXPORT static void RemoveCreatedCallback(
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const CreatedCallback& callback);
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns a WebContents that wraps the RenderViewHost, or NULL if the
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // render view host's delegate isn't a WebContents.
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CONTENT_EXPORT static WebContents* FromRenderViewHost(
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const RenderViewHost* rvh);
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~WebContents() {}
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Intrinsic tab state -------------------------------------------------------
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Gets/Sets the delegate.
1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual WebContentsDelegate* GetDelegate() = 0;
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void SetDelegate(WebContentsDelegate* delegate) = 0;
1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Gets the controller for this WebContents.
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual NavigationController& GetController() = 0;
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual const NavigationController& GetController() const = 0;
131
132  // Returns the user browser context associated with this WebContents (via the
133  // NavigationController).
134  virtual content::BrowserContext* GetBrowserContext() const = 0;
135
136  // Gets the URL that is currently being displayed, if there is one.
137  // This method is deprecated. DO NOT USE! Pick either |GetActiveURL| or
138  // |GetLastCommittedURL| as appropriate.
139  virtual const GURL& GetURL() const = 0;
140
141  // Gets the URL currently being displayed in the URL bar, if there is one.
142  // This URL might be a pending navigation that hasn't committed yet, so it is
143  // not guaranteed to match the current page in this WebContents. A typical
144  // example of this is interstitials, which show the URL of the new/loading
145  // page (active) but the security context is of the old page (last committed).
146  virtual const GURL& GetActiveURL() const = 0;
147
148  // Gets the last committed URL. It represents the current page that is
149  // displayed in  this WebContents. It represents the current security
150  // context.
151  virtual const GURL& GetLastCommittedURL() const = 0;
152
153  // Return the currently active RenderProcessHost and RenderViewHost. Each of
154  // these may change over time.
155  virtual RenderProcessHost* GetRenderProcessHost() const = 0;
156
157  // Gets the current RenderViewHost for this tab.
158  virtual RenderViewHost* GetRenderViewHost() const = 0;
159
160  typedef base::Callback<void(RenderViewHost* /* render_view_host */,
161                              int /* x */,
162                              int /* y */)> GetRenderViewHostCallback;
163  // Gets the RenderViewHost at coordinates (|x|, |y|) for this WebContents via
164  // |callback|.
165  // This can be different than the current RenderViewHost if there is a
166  // BrowserPlugin at the specified position.
167  virtual void GetRenderViewHostAtPosition(
168      int x,
169      int y,
170      const GetRenderViewHostCallback& callback) = 0;
171
172  // Returns the WebContents embedding this WebContents, if any.
173  // If this is a top-level WebContents then it returns NULL.
174  virtual WebContents* GetEmbedderWebContents() const = 0;
175
176  // Gets the instance ID of the current WebContents if it is embedded
177  // within a BrowserPlugin. The instance ID of a WebContents uniquely
178  // identifies it within its embedder WebContents.
179  virtual int GetEmbeddedInstanceID() const = 0;
180
181  // Gets the current RenderViewHost's routing id. Returns
182  // MSG_ROUTING_NONE when there is no RenderViewHost.
183  virtual int GetRoutingID() const = 0;
184
185  // Returns the currently active RenderWidgetHostView. This may change over
186  // time and can be NULL (during setup and teardown).
187  virtual content::RenderWidgetHostView* GetRenderWidgetHostView() const = 0;
188
189  // The WebContentsView will never change and is guaranteed non-NULL.
190  virtual WebContentsView* GetView() const = 0;
191
192  // Create a WebUI page for the given url. In most cases, this doesn't need to
193  // be called by embedders since content will create its own WebUI objects as
194  // necessary. However if the embedder wants to create its own WebUI object and
195  // keep track of it manually, it can use this.
196  virtual WebUI* CreateWebUI(const GURL& url) = 0;
197
198  // Returns the committed WebUI if one exists, otherwise the pending one.
199  virtual WebUI* GetWebUI() const = 0;
200  virtual WebUI* GetCommittedWebUI() const = 0;
201
202  // Allows overriding the user agent used for NavigationEntries it owns.
203  virtual void SetUserAgentOverride(const std::string& override) = 0;
204  virtual const std::string& GetUserAgentOverride() const = 0;
205
206#if defined(OS_WIN) && defined(USE_AURA)
207  virtual void SetParentNativeViewAccessible(
208      gfx::NativeViewAccessible accessible_parent) = 0;
209#endif
210
211  // Tab navigation state ------------------------------------------------------
212
213  // Returns the current navigation properties, which if a navigation is
214  // pending may be provisional (e.g., the navigation could result in a
215  // download, in which case the URL would revert to what it was previously).
216  virtual const string16& GetTitle() const = 0;
217
218  // The max page ID for any page that the current SiteInstance has loaded in
219  // this WebContents.  Page IDs are specific to a given SiteInstance and
220  // WebContents, corresponding to a specific RenderView in the renderer.
221  // Page IDs increase with each new page that is loaded by a tab.
222  virtual int32 GetMaxPageID() = 0;
223
224  // The max page ID for any page that the given SiteInstance has loaded in
225  // this WebContents.
226  virtual int32 GetMaxPageIDForSiteInstance(SiteInstance* site_instance) = 0;
227
228  // Returns the SiteInstance associated with the current page.
229  virtual SiteInstance* GetSiteInstance() const = 0;
230
231  // Returns the SiteInstance for the pending navigation, if any.  Otherwise
232  // returns the current SiteInstance.
233  virtual SiteInstance* GetPendingSiteInstance() const = 0;
234
235  // Return whether this WebContents is loading a resource.
236  virtual bool IsLoading() const = 0;
237
238  // Returns whether this WebContents is waiting for a first-response for the
239  // main resource of the page.
240  virtual bool IsWaitingForResponse() const = 0;
241
242  // Return the current load state and the URL associated with it.
243  virtual const net::LoadStateWithParam& GetLoadState() const = 0;
244  virtual const string16& GetLoadStateHost() const = 0;
245
246  // Return the upload progress.
247  virtual uint64 GetUploadSize() const = 0;
248  virtual uint64 GetUploadPosition() const = 0;
249
250  // Returns a set of the site URLs currently committed in this tab.
251  virtual std::set<GURL> GetSitesInTab() const = 0;
252
253  // Return the character encoding of the page.
254  virtual const std::string& GetEncoding() const = 0;
255
256  // True if this is a secure page which displayed insecure content.
257  virtual bool DisplayedInsecureContent() const = 0;
258
259  // Internal state ------------------------------------------------------------
260
261  // Indicates whether the WebContents is being captured (e.g., for screenshots
262  // or mirroring).  Increment calls must be balanced with an equivalent number
263  // of decrement calls.
264  virtual void IncrementCapturerCount() = 0;
265  virtual void DecrementCapturerCount() = 0;
266
267  // Indicates whether this tab should be considered crashed. The setter will
268  // also notify the delegate when the flag is changed.
269  virtual bool IsCrashed() const  = 0;
270  virtual void SetIsCrashed(base::TerminationStatus status, int error_code) = 0;
271
272  virtual base::TerminationStatus GetCrashedStatus() const = 0;
273
274  // Whether the tab is in the process of being destroyed.
275  virtual bool IsBeingDestroyed() const = 0;
276
277  // Convenience method for notifying the delegate of a navigation state
278  // change. See InvalidateType enum.
279  virtual void NotifyNavigationStateChanged(unsigned changed_flags) = 0;
280
281  // Get the last time that the WebContents was made visible with WasShown()
282  virtual base::TimeTicks GetLastSelectedTime() const = 0;
283
284  // Invoked when the WebContents becomes shown/hidden.
285  virtual void WasShown() = 0;
286  virtual void WasHidden() = 0;
287
288  // Returns true if the before unload and unload listeners need to be
289  // fired. The value of this changes over time. For example, if true and the
290  // before unload listener is executed and allows the user to exit, then this
291  // returns false.
292  virtual bool NeedToFireBeforeUnload() = 0;
293
294  // Commands ------------------------------------------------------------------
295
296  // Stop any pending navigation.
297  virtual void Stop() = 0;
298
299  // Creates a new WebContents with the same state as this one. The returned
300  // heap-allocated pointer is owned by the caller.
301  virtual WebContents* Clone() = 0;
302
303  // Views and focus -----------------------------------------------------------
304  // Focuses the first (last if |reverse| is true) element in the page.
305  // Invoked when this tab is getting the focus through tab traversal (|reverse|
306  // is true when using Shift-Tab).
307  virtual void FocusThroughTabTraversal(bool reverse) = 0;
308
309  // Interstitials -------------------------------------------------------------
310
311  // Various other systems need to know about our interstitials.
312  virtual bool ShowingInterstitialPage() const = 0;
313
314  // Returns the currently showing interstitial, NULL if no interstitial is
315  // showing.
316  virtual InterstitialPage* GetInterstitialPage() const = 0;
317
318  // Misc state & callbacks ----------------------------------------------------
319
320  // Check whether we can do the saving page operation this page given its MIME
321  // type.
322  virtual bool IsSavable() = 0;
323
324  // Prepare for saving the current web page to disk.
325  virtual void OnSavePage() = 0;
326
327  // Save page with the main HTML file path, the directory for saving resources,
328  // and the save type: HTML only or complete web page. Returns true if the
329  // saving process has been initiated successfully.
330  virtual bool SavePage(const base::FilePath& main_file,
331                        const base::FilePath& dir_path,
332                        SavePageType save_type) = 0;
333
334  // Generate an MHTML representation of the current page in the given file.
335  virtual void GenerateMHTML(
336      const base::FilePath& file,
337      const base::Callback<void(
338          const base::FilePath& /* path to the MHTML file */,
339          int64 /* size of the file */)>& callback) = 0;
340
341  // Returns true if the active NavigationEntry's page_id equals page_id.
342  virtual bool IsActiveEntry(int32 page_id) = 0;
343
344  // Returns the contents MIME type after a navigation.
345  virtual const std::string& GetContentsMimeType() const = 0;
346
347  // Returns true if this WebContents will notify about disconnection.
348  virtual bool WillNotifyDisconnection() const = 0;
349
350  // Override the encoding and reload the page by sending down
351  // ViewMsg_SetPageEncoding to the renderer. |UpdateEncoding| is kinda
352  // the opposite of this, by which 'browser' is notified of
353  // the encoding of the current tab from 'renderer' (determined by
354  // auto-detect, http header, meta, bom detection, etc).
355  virtual void SetOverrideEncoding(const std::string& encoding) = 0;
356
357  // Remove any user-defined override encoding and reload by sending down
358  // ViewMsg_ResetPageEncodingToDefault to the renderer.
359  virtual void ResetOverrideEncoding() = 0;
360
361  // Returns the settings which get passed to the renderer.
362  virtual content::RendererPreferences* GetMutableRendererPrefs() = 0;
363
364  // Tells the tab to close now. The tab will take care not to close until it's
365  // out of nested message loops.
366  virtual void Close() = 0;
367
368  // A render view-originated drag has ended. Informs the render view host and
369  // WebContentsDelegate.
370  virtual void SystemDragEnded() = 0;
371
372  // Notification the user has made a gesture while focus was on the
373  // page. This is used to avoid uninitiated user downloads (aka carpet
374  // bombing), see DownloadRequestLimiter for details.
375  virtual void UserGestureDone() = 0;
376
377  // Indicates if this tab was explicitly closed by the user (control-w, close
378  // tab menu item...). This is false for actions that indirectly close the tab,
379  // such as closing the window.  The setter is maintained by TabStripModel, and
380  // the getter only useful from within TAB_CLOSED notification
381  virtual void SetClosedByUserGesture(bool value) = 0;
382  virtual bool GetClosedByUserGesture() const = 0;
383
384  // Gets the zoom level for this tab.
385  virtual double GetZoomLevel() const = 0;
386
387  // Gets the zoom percent for this tab.
388  virtual int GetZoomPercent(bool* enable_increment,
389                             bool* enable_decrement) const = 0;
390
391  // Opens view-source tab for this contents.
392  virtual void ViewSource() = 0;
393
394  virtual void ViewFrameSource(const GURL& url,
395                               const PageState& page_state)= 0;
396
397  // Gets the minimum/maximum zoom percent.
398  virtual int GetMinimumZoomPercent() const = 0;
399  virtual int GetMaximumZoomPercent() const = 0;
400
401  // Gets the preferred size of the contents.
402  virtual gfx::Size GetPreferredSize() const = 0;
403
404  // Get the content restrictions (see content::ContentRestriction).
405  virtual int GetContentRestrictions() const = 0;
406
407  // Called when the reponse to a pending mouse lock request has arrived.
408  // Returns true if |allowed| is true and the mouse has been successfully
409  // locked.
410  virtual bool GotResponseToLockMouseRequest(bool allowed) = 0;
411
412  // Called when the user has selected a color in the color chooser.
413  virtual void DidChooseColorInColorChooser(SkColor color) = 0;
414
415  // Called when the color chooser has ended.
416  virtual void DidEndColorChooser() = 0;
417
418  // Returns true if the location bar should be focused by default rather than
419  // the page contents. The view calls this function when the tab is focused
420  // to see what it should do.
421  virtual bool FocusLocationBarByDefault() = 0;
422
423  // Does this have an opener associated with it?
424  virtual bool HasOpener() const = 0;
425
426  typedef base::Callback<void(int, /* id */
427                              int, /* HTTP status code */
428                              const GURL&, /* image_url */
429                              int,  /* requested_size */
430                              const std::vector<SkBitmap>& /* bitmaps*/)>
431      ImageDownloadCallback;
432
433  // Sends a request to download the given image |url| and returns the unique
434  // id of the download request. When the download is finished, |callback| will
435  // be called with the bitmaps received from the renderer. If |is_favicon| is
436  // true, the cookies are not sent and not accepted during download. Note that
437  // |image_size| is a hint for images with multiple sizes. The downloaded image
438  // is not resized to the given image_size. If 0 is passed, the first frame of
439  // the image is returned.
440  virtual int DownloadImage(const GURL& url,
441                            bool is_favicon,
442                            int image_size,
443                            const ImageDownloadCallback& callback) = 0;
444
445 private:
446  // This interface should only be implemented inside content.
447  friend class WebContentsImpl;
448  WebContents() {}
449};
450
451}  // namespace content
452
453#endif  // CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_H_
454