1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_TAB_CONTENTS_BACKGROUND_CONTENTS_H_
6 #define CHROME_BROWSER_TAB_CONTENTS_BACKGROUND_CONTENTS_H_
10 #include "base/memory/scoped_ptr.h"
11 #include "content/public/browser/notification_observer.h"
12 #include "content/public/browser/notification_registrar.h"
13 #include "content/public/browser/web_contents_delegate.h"
14 #include "content/public/browser/web_contents_observer.h"
15 #include "ui/base/window_open_disposition.h"
20 class SessionStorageNamespace
;
24 // This class consumes WebContents. It can host a renderer, but does not
25 // have any visible display.
26 class BackgroundContents
: public content::WebContentsDelegate
,
27 public content::WebContentsObserver
,
28 public content::NotificationObserver
{
32 // Called by AddNewContents(). Asks the delegate to attach the opened
33 // WebContents to a suitable container (e.g. browser) or to show it if it's
34 // a popup window. If |was_blocked| is non-NULL, then |*was_blocked| will be
35 // set to true if the popup gets blocked, and left unchanged otherwise.
36 virtual void AddWebContents(content::WebContents
* new_contents
,
37 WindowOpenDisposition disposition
,
38 const gfx::Rect
& initial_pos
,
40 bool* was_blocked
) = 0;
43 virtual ~Delegate() {}
47 content::SiteInstance
* site_instance
,
50 const std::string
& partition_id
,
51 content::SessionStorageNamespace
* session_storage_namespace
);
52 virtual ~BackgroundContents();
54 content::WebContents
* web_contents() const { return web_contents_
.get(); }
55 virtual const GURL
& GetURL() const;
57 // content::WebContentsDelegate implementation:
58 virtual void CloseContents(content::WebContents
* source
) OVERRIDE
;
59 virtual bool ShouldSuppressDialogs() OVERRIDE
;
60 virtual void DidNavigateMainFramePostCommit(
61 content::WebContents
* tab
) OVERRIDE
;
62 virtual void AddNewContents(content::WebContents
* source
,
63 content::WebContents
* new_contents
,
64 WindowOpenDisposition disposition
,
65 const gfx::Rect
& initial_pos
,
67 bool* was_blocked
) OVERRIDE
;
69 // content::WebContentsObserver implementation:
70 virtual void RenderProcessGone(base::TerminationStatus status
) OVERRIDE
;
72 // content::NotificationObserver
73 virtual void Observe(int type
,
74 const content::NotificationSource
& source
,
75 const content::NotificationDetails
& details
) OVERRIDE
;
78 // Exposed for testing.
82 // The delegate for this BackgroundContents.
86 scoped_ptr
<content::WebContents
> web_contents_
;
87 content::NotificationRegistrar registrar_
;
89 DISALLOW_COPY_AND_ASSIGN(BackgroundContents
);
92 // This is the data sent out as the details with BACKGROUND_CONTENTS_OPENED.
93 struct BackgroundContentsOpenedDetails
{
94 // The BackgroundContents object that has just been opened.
95 BackgroundContents
* contents
;
97 // The name of the parent frame for these contents.
98 const base::string16
& frame_name
;
100 // The ID of the parent application (if any).
101 const base::string16
& application_id
;
104 #endif // CHROME_BROWSER_TAB_CONTENTS_BACKGROUND_CONTENTS_H_