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
;
68 virtual bool IsNeverVisible(content::WebContents
* web_contents
) OVERRIDE
;
70 // content::WebContentsObserver implementation:
71 virtual void RenderProcessGone(base::TerminationStatus status
) OVERRIDE
;
73 // content::NotificationObserver
74 virtual void Observe(int type
,
75 const content::NotificationSource
& source
,
76 const content::NotificationDetails
& details
) OVERRIDE
;
79 // Exposed for testing.
83 // The delegate for this BackgroundContents.
87 scoped_ptr
<content::WebContents
> web_contents_
;
88 content::NotificationRegistrar registrar_
;
90 DISALLOW_COPY_AND_ASSIGN(BackgroundContents
);
93 // This is the data sent out as the details with BACKGROUND_CONTENTS_OPENED.
94 struct BackgroundContentsOpenedDetails
{
95 // The BackgroundContents object that has just been opened.
96 BackgroundContents
* contents
;
98 // The name of the parent frame for these contents.
99 const base::string16
& frame_name
;
101 // The ID of the parent application (if any).
102 const base::string16
& application_id
;
105 #endif // CHROME_BROWSER_TAB_CONTENTS_BACKGROUND_CONTENTS_H_