web_contents.h revision c2e0dbddbe15c98d52c4786dac06cb8952a8ae6d
13551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
23551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
33551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// found in the LICENSE file.
43551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
53551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#ifndef CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_H_
63551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#define CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_H_
73551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
83551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "base/basictypes.h"
93551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "base/callback_forward.h"
103551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "base/process_util.h"
113551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "base/string16.h"
123551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "base/supports_user_data.h"
133551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "content/common/content_export.h"
1458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "content/public/browser/navigation_controller.h"
1558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "content/public/browser/page_navigator.h"
1658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "content/public/browser/save_page_type.h"
17effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "content/public/browser/web_ui.h"
1858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "ipc/ipc_sender.h"
1958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "third_party/skia/include/core/SkColor.h"
203551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "ui/base/window_open_disposition.h"
213551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "ui/gfx/native_widget_types.h"
223551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "ui/gfx/size.h"
233551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
243551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)namespace base {
253551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)class TimeTicks;
263551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)}
273551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
283551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)namespace gfx {
293551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)class Rect;
303551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)class Size;
313551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)}
323551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
333551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)namespace net {
343551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)struct LoadStateWithParam;
353551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)}
363551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
373551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)namespace content {
383551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
393551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)class BrowserContext;
4058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)class InterstitialPage;
4158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)class RenderProcessHost;
4258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)class RenderViewHost;
4358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)class RenderWidgetHostView;
4458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)class SiteInstance;
4558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)class WebContentsDelegate;
463551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)class WebContentsView;
473551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)struct RendererPreferences;
483551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
493551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// WebContents is the core class in content/. A WebContents renders web content
503551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// (usually HTML) in a rectangular area.
5168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)//
523551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// Instantiating one is simple:
533551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)//   scoped_ptr<content::WebContents> web_contents(
543551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)//       content::WebContents::Create(
553551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)//           content::WebContents::CreateParams(browser_context)));
563551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)//   gfx::NativeView view = web_contents->GetView()->GetNativeView();
573551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)//   // |view| is an HWND, NSView*, GtkWidget*, etc.; insert it into the view
583551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)//   // hierarchy wherever it needs to go.
593551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)//
603551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// That's it; go to your kitchen, grab a scone, and chill. WebContents will do
6168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)// all the multi-process stuff behind the scenes. More details are at
6268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)// http://www.chromium.org/developers/design-documents/multi-process-architecture .
63a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)//
6468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)// Each WebContents has exactly one NavigationController; each
655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// NavigationController belongs to one WebContents. The NavigationController can
665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// be obtained from GetController(), and is used to load URLs into the
675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// WebContents, navigate it backwards/forwards, etc. See navigation_controller.h
685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// for more details.
695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class WebContents : public PageNavigator,
70f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                    public IPC::Sender,
71f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                    public base::SupportsUserData {
72f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) public:
73f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  struct CONTENT_EXPORT CreateParams {
74f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    explicit CreateParams(BrowserContext* context);
753551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    CreateParams(BrowserContext* context, SiteInstance* site);
763551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
773551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    BrowserContext* browser_context;
783551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    SiteInstance* site_instance;
793551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    int routing_id;
808bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
818bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    // Initial size of the new WebContent's view. Can be (0, 0) if not needed.
828bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    gfx::Size initial_size;
838bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
848bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    // Used to specify the location context which display the new view should
8546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    // belong. This can be NULL if not needed.
8646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    gfx::NativeView context;
8746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  };
883551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
893551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // Creates a new WebContents.
903551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  CONTENT_EXPORT static WebContents* Create(const CreateParams& params);
913551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
923551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // Similar to Create() above but should be used when you need to prepopulate
935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // the SessionStorageNamespaceMap of the WebContents. This can happen if
945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // you duplicate a WebContents, try to reconstitute it from a saved state,
955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // or when you create a new WebContents based on another one (eg., when
965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // servicing a window.open() call).
9746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  //
9846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // You do not want to call this. If you think you do, make sure you completely
9946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // understand when SessionStorageNamespace objects should be cloned, why
10046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // they should not be shared by multiple WebContents, and what bad things
1013551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // can happen if you share the object.
1023551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  CONTENT_EXPORT static WebContents* CreateWithSessionStorage(
1033551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      const CreateParams& params,
1043551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      const SessionStorageNamespaceMap& session_storage_namespace_map);
1053551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
1063551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // Returns a WebContents that wraps the RenderViewHost, or NULL if the
1073551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // render view host's delegate isn't a WebContents.
1083551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  CONTENT_EXPORT static WebContents* FromRenderViewHost(
1093551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      const RenderViewHost* rvh);
1103551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
1113551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  virtual ~WebContents() {}
1123551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
1135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Intrinsic tab state -------------------------------------------------------
1145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Gets/Sets the delegate.
1163551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  virtual WebContentsDelegate* GetDelegate() = 0;
1173551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  virtual void SetDelegate(WebContentsDelegate* delegate) = 0;
1183551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
1193551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // Gets the controller for this WebContents.
12068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  virtual NavigationController& GetController() = 0;
1213551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  virtual const NavigationController& GetController() const = 0;
1223551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
1233551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // Returns the user browser context associated with this WebContents (via the
1243551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // NavigationController).
1253551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  virtual content::BrowserContext* GetBrowserContext() const = 0;
126a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
127a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Gets the URL that is currently being displayed, if there is one.
128a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual const GURL& GetURL() const = 0;
129a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
130a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Return the currently active RenderProcessHost and RenderViewHost. Each of
131f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // these may change over time.
132f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual RenderProcessHost* GetRenderProcessHost() const = 0;
133f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
134f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Gets the current RenderViewHost for this tab.
135f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual RenderViewHost* GetRenderViewHost() const = 0;
1363551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
1373551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  typedef base::Callback<void(RenderViewHost* /* render_view_host */,
1383551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)                              int /* x */,
1393551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)                              int /* y */)> GetRenderViewHostCallback;
1403551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // Gets the RenderViewHost at coordinates (|x|, |y|) for this WebContents via
1415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // |callback|.
1425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // This can be different than the current RenderViewHost if there is a
1435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // BrowserPlugin at the specified position.
1445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void GetRenderViewHostAtPosition(
1455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      int x,
1463551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      int y,
1473551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      const GetRenderViewHostCallback& callback) = 0;
1483551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
1493551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // Returns the WebContents embedding this WebContents, if any.
1503551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // If this is a top-level WebContents then it returns NULL.
151a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual WebContents* GetEmbedderWebContents() const = 0;
152a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
1533551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // Gets the instance ID of the current WebContents if it is embedded
1545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // within a BrowserPlugin. The instance ID of a WebContents uniquely
1555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // identifies it within its embedder WebContents.
1565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual int GetEmbeddedInstanceID() const = 0;
1575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Gets the current RenderViewHost's routing id. Returns
1595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // MSG_ROUTING_NONE when there is no RenderViewHost.
1605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual int GetRoutingID() const = 0;
1615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1623551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // Returns the currently active RenderWidgetHostView. This may change over
163cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // time and can be NULL (during setup and teardown).
164cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual content::RenderWidgetHostView* GetRenderWidgetHostView() const = 0;
1653551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
1663551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // The WebContentsView will never change and is guaranteed non-NULL.
1673551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  virtual WebContentsView* GetView() const = 0;
1683551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
169  // Create a WebUI page for the given url. In most cases, this doesn't need to
170  // be called by embedders since content will create its own WebUI objects as
171  // necessary. However if the embedder wants to create its own WebUI object and
172  // keep track of it manually, it can use this.
173  virtual WebUI* CreateWebUI(const GURL& url) = 0;
174
175  // Returns the committed WebUI if one exists, otherwise the pending one.
176  virtual WebUI* GetWebUI() const = 0;
177  virtual WebUI* GetCommittedWebUI() const = 0;
178
179  // Allows overriding the user agent used for NavigationEntries it owns.
180  virtual void SetUserAgentOverride(const std::string& override) = 0;
181  virtual const std::string& GetUserAgentOverride() const = 0;
182
183#if defined(OS_WIN) && defined(USE_AURA)
184  virtual void SetParentNativeViewAccessible(
185      gfx::NativeViewAccessible accessible_parent) = 0;
186#endif
187
188  // Tab navigation state ------------------------------------------------------
189
190  // Returns the current navigation properties, which if a navigation is
191  // pending may be provisional (e.g., the navigation could result in a
192  // download, in which case the URL would revert to what it was previously).
193  virtual const string16& GetTitle() const = 0;
194
195  // The max page ID for any page that the current SiteInstance has loaded in
196  // this WebContents.  Page IDs are specific to a given SiteInstance and
197  // WebContents, corresponding to a specific RenderView in the renderer.
198  // Page IDs increase with each new page that is loaded by a tab.
199  virtual int32 GetMaxPageID() = 0;
200
201  // The max page ID for any page that the given SiteInstance has loaded in
202  // this WebContents.
203  virtual int32 GetMaxPageIDForSiteInstance(SiteInstance* site_instance) = 0;
204
205  // Returns the SiteInstance associated with the current page.
206  virtual SiteInstance* GetSiteInstance() const = 0;
207
208  // Returns the SiteInstance for the pending navigation, if any.  Otherwise
209  // returns the current SiteInstance.
210  virtual SiteInstance* GetPendingSiteInstance() const = 0;
211
212  // Return whether this WebContents is loading a resource.
213  virtual bool IsLoading() const = 0;
214
215  // Returns whether this WebContents is waiting for a first-response for the
216  // main resource of the page.
217  virtual bool IsWaitingForResponse() const = 0;
218
219  // Return the current load state and the URL associated with it.
220  virtual const net::LoadStateWithParam& GetLoadState() const = 0;
221  virtual const string16& GetLoadStateHost() const = 0;
222
223  // Return the upload progress.
224  virtual uint64 GetUploadSize() const = 0;
225  virtual uint64 GetUploadPosition() const = 0;
226
227  // Return the character encoding of the page.
228  virtual const std::string& GetEncoding() const = 0;
229
230  // True if this is a secure page which displayed insecure content.
231  virtual bool DisplayedInsecureContent() const = 0;
232
233  // Internal state ------------------------------------------------------------
234
235  // Indicates whether the WebContents is being captured (e.g., for screenshots
236  // or mirroring).  Increment calls must be balanced with an equivalent number
237  // of decrement calls.
238  virtual void IncrementCapturerCount() = 0;
239  virtual void DecrementCapturerCount() = 0;
240
241  // Indicates whether this tab should be considered crashed. The setter will
242  // also notify the delegate when the flag is changed.
243  virtual bool IsCrashed() const  = 0;
244  virtual void SetIsCrashed(base::TerminationStatus status, int error_code) = 0;
245
246  virtual base::TerminationStatus GetCrashedStatus() const = 0;
247
248  // Whether the tab is in the process of being destroyed.
249  virtual bool IsBeingDestroyed() const = 0;
250
251  // Convenience method for notifying the delegate of a navigation state
252  // change. See InvalidateType enum.
253  virtual void NotifyNavigationStateChanged(unsigned changed_flags) = 0;
254
255  // Get the last time that the WebContents was made visible with WasShown()
256  virtual base::TimeTicks GetLastSelectedTime() const = 0;
257
258  // Invoked when the WebContents becomes shown/hidden.
259  virtual void WasShown() = 0;
260  virtual void WasHidden() = 0;
261
262  // Returns true if the before unload and unload listeners need to be
263  // fired. The value of this changes over time. For example, if true and the
264  // before unload listener is executed and allows the user to exit, then this
265  // returns false.
266  virtual bool NeedToFireBeforeUnload() = 0;
267
268  // Commands ------------------------------------------------------------------
269
270  // Stop any pending navigation.
271  virtual void Stop() = 0;
272
273  // Creates a new WebContents with the same state as this one. The returned
274  // heap-allocated pointer is owned by the caller.
275  virtual WebContents* Clone() = 0;
276
277  // Views and focus -----------------------------------------------------------
278  // Focuses the first (last if |reverse| is true) element in the page.
279  // Invoked when this tab is getting the focus through tab traversal (|reverse|
280  // is true when using Shift-Tab).
281  virtual void FocusThroughTabTraversal(bool reverse) = 0;
282
283  // Interstitials -------------------------------------------------------------
284
285  // Various other systems need to know about our interstitials.
286  virtual bool ShowingInterstitialPage() const = 0;
287
288  // Returns the currently showing interstitial, NULL if no interstitial is
289  // showing.
290  virtual InterstitialPage* GetInterstitialPage() const = 0;
291
292  // Misc state & callbacks ----------------------------------------------------
293
294  // Check whether we can do the saving page operation this page given its MIME
295  // type.
296  virtual bool IsSavable() = 0;
297
298  // Prepare for saving the current web page to disk.
299  virtual void OnSavePage() = 0;
300
301  // Save page with the main HTML file path, the directory for saving resources,
302  // and the save type: HTML only or complete web page. Returns true if the
303  // saving process has been initiated successfully.
304  virtual bool SavePage(const base::FilePath& main_file,
305                        const base::FilePath& dir_path,
306                        SavePageType save_type) = 0;
307
308  // Generate an MHTML representation of the current page in the given file.
309  virtual void GenerateMHTML(
310      const base::FilePath& file,
311      const base::Callback<void(
312          const base::FilePath& /* path to the MHTML file */,
313          int64 /* size of the file */)>& callback) = 0;
314
315  // Returns true if the active NavigationEntry's page_id equals page_id.
316  virtual bool IsActiveEntry(int32 page_id) = 0;
317
318  // Returns the contents MIME type after a navigation.
319  virtual const std::string& GetContentsMimeType() const = 0;
320
321  // Returns true if this WebContents will notify about disconnection.
322  virtual bool WillNotifyDisconnection() const = 0;
323
324  // Override the encoding and reload the page by sending down
325  // ViewMsg_SetPageEncoding to the renderer. |UpdateEncoding| is kinda
326  // the opposite of this, by which 'browser' is notified of
327  // the encoding of the current tab from 'renderer' (determined by
328  // auto-detect, http header, meta, bom detection, etc).
329  virtual void SetOverrideEncoding(const std::string& encoding) = 0;
330
331  // Remove any user-defined override encoding and reload by sending down
332  // ViewMsg_ResetPageEncodingToDefault to the renderer.
333  virtual void ResetOverrideEncoding() = 0;
334
335  // Returns the settings which get passed to the renderer.
336  virtual content::RendererPreferences* GetMutableRendererPrefs() = 0;
337
338  // Set the time when we started to create the new tab page.  This time is
339  // from before we created this WebContents.
340  virtual void SetNewTabStartTime(const base::TimeTicks& time) = 0;
341  virtual base::TimeTicks GetNewTabStartTime() const = 0;
342
343  // Tells the tab to close now. The tab will take care not to close until it's
344  // out of nested message loops.
345  virtual void Close() = 0;
346
347  // Notification that tab closing has started.  This can be called multiple
348  // times, subsequent calls are ignored.
349  virtual void OnCloseStarted() = 0;
350
351  // A render view-originated drag has ended. Informs the render view host and
352  // WebContentsDelegate.
353  virtual void SystemDragEnded() = 0;
354
355  // Notification the user has made a gesture while focus was on the
356  // page. This is used to avoid uninitiated user downloads (aka carpet
357  // bombing), see DownloadRequestLimiter for details.
358  virtual void UserGestureDone() = 0;
359
360  // Indicates if this tab was explicitly closed by the user (control-w, close
361  // tab menu item...). This is false for actions that indirectly close the tab,
362  // such as closing the window.  The setter is maintained by TabStripModel, and
363  // the getter only useful from within TAB_CLOSED notification
364  virtual void SetClosedByUserGesture(bool value) = 0;
365  virtual bool GetClosedByUserGesture() const = 0;
366
367  // Gets the zoom level for this tab.
368  virtual double GetZoomLevel() const = 0;
369
370  // Gets the zoom percent for this tab.
371  virtual int GetZoomPercent(bool* enable_increment,
372                             bool* enable_decrement) const = 0;
373
374  // Opens view-source tab for this contents.
375  virtual void ViewSource() = 0;
376
377  virtual void ViewFrameSource(const GURL& url,
378                               const std::string& content_state)= 0;
379
380  // Gets the minimum/maximum zoom percent.
381  virtual int GetMinimumZoomPercent() const = 0;
382  virtual int GetMaximumZoomPercent() const = 0;
383
384  // Gets the preferred size of the contents.
385  virtual gfx::Size GetPreferredSize() const = 0;
386
387  // Get the content restrictions (see content::ContentRestriction).
388  virtual int GetContentRestrictions() const = 0;
389
390  // Called when the reponse to a pending mouse lock request has arrived.
391  // Returns true if |allowed| is true and the mouse has been successfully
392  // locked.
393  virtual bool GotResponseToLockMouseRequest(bool allowed) = 0;
394
395  // Called when the user has selected a color in the color chooser.
396  virtual void DidChooseColorInColorChooser(int color_chooser_id,
397                                            SkColor color) = 0;
398
399  // Called when the color chooser has ended.
400  virtual void DidEndColorChooser(int color_chooser_id) = 0;
401
402  // Returns true if the location bar should be focused by default rather than
403  // the page contents. The view calls this function when the tab is focused
404  // to see what it should do.
405  virtual bool FocusLocationBarByDefault() = 0;
406
407  // Does this have an opener associated with it?
408  virtual bool HasOpener() const = 0;
409
410  typedef base::Callback<void(int, /* id */
411                              const GURL&, /* image_url */
412                              int,  /* requested_size */
413                              const std::vector<SkBitmap>& /* bitmaps*/)>
414      ImageDownloadCallback;
415
416  // Sends a request to download the given image |url| and returns the unique
417  // id of the download request. When the download is finished, |callback| will
418  // be called with the bitmaps received from the renderer. If |is_favicon| is
419  // true, the cookies are not sent and not accepted during download. Note that
420  // |image_size| is a hint for images with multiple sizes. The downloaded image
421  // is not resized to the given image_size. If 0 is passed, the first frame of
422  // the image is returned.
423  virtual int DownloadImage(const GURL& url,
424                            bool is_favicon,
425                            int image_size,
426                            const ImageDownloadCallback& callback) = 0;
427
428 private:
429  // This interface should only be implemented inside content.
430  friend class WebContentsImpl;
431  WebContents() {}
432};
433
434}  // namespace content
435
436#endif  // CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_H_
437