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_BACKGROUND_BACKGROUND_CONTENTS_H_
6 #define CHROME_BROWSER_BACKGROUND_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 "extensions/browser/deferred_start_render_host.h"
16 #include "ui/base/window_open_disposition.h"
22 class SessionStorageNamespace
;
26 namespace extensions
{
27 class ExtensionHostDelegate
;
30 // This class maintains a WebContents used in the background. It can host a
31 // renderer, but does not have any visible display.
32 // TODO(atwilson): Unify this with background pages; http://crbug.com/77790
33 class BackgroundContents
: public extensions::DeferredStartRenderHost
,
34 public content::WebContentsDelegate
,
35 public content::WebContentsObserver
,
36 public content::NotificationObserver
{
40 // Called by AddNewContents(). Asks the delegate to attach the opened
41 // WebContents to a suitable container (e.g. browser) or to show it if it's
42 // a popup window. If |was_blocked| is non-NULL, then |*was_blocked| will be
43 // set to true if the popup gets blocked, and left unchanged otherwise.
44 virtual void AddWebContents(content::WebContents
* new_contents
,
45 WindowOpenDisposition disposition
,
46 const gfx::Rect
& initial_rect
,
48 bool* was_blocked
) = 0;
51 virtual ~Delegate() {}
55 content::SiteInstance
* site_instance
,
57 int main_frame_routing_id
,
59 const std::string
& partition_id
,
60 content::SessionStorageNamespace
* session_storage_namespace
);
61 ~BackgroundContents() override
;
63 content::WebContents
* web_contents() const { return web_contents_
.get(); }
64 virtual const GURL
& GetURL() const;
66 // Adds this BackgroundContents to the queue of RenderViews to create.
67 void CreateRenderViewSoon(const GURL
& url
);
69 // content::WebContentsDelegate implementation:
70 void CloseContents(content::WebContents
* source
) override
;
71 bool ShouldSuppressDialogs(content::WebContents
* source
) override
;
72 void DidNavigateMainFramePostCommit(content::WebContents
* tab
) override
;
73 void AddNewContents(content::WebContents
* source
,
74 content::WebContents
* new_contents
,
75 WindowOpenDisposition disposition
,
76 const gfx::Rect
& initial_rect
,
78 bool* was_blocked
) override
;
79 bool IsNeverVisible(content::WebContents
* web_contents
) override
;
81 // content::WebContentsObserver implementation:
82 void RenderProcessGone(base::TerminationStatus status
) override
;
84 // content::NotificationObserver
85 void Observe(int type
,
86 const content::NotificationSource
& source
,
87 const content::NotificationDetails
& details
) override
;
90 // Exposed for testing.
94 // DeferredStartRenderHost implementation:
95 void CreateRenderViewNow() override
;
97 // The delegate for this BackgroundContents.
100 // Delegate for choosing an ExtensionHostQueue.
101 scoped_ptr
<extensions::ExtensionHostDelegate
> extension_host_delegate_
;
104 scoped_ptr
<content::WebContents
> web_contents_
;
105 content::NotificationRegistrar registrar_
;
107 // The initial URL to load.
110 DISALLOW_COPY_AND_ASSIGN(BackgroundContents
);
113 // This is the data sent out as the details with BACKGROUND_CONTENTS_OPENED.
114 struct BackgroundContentsOpenedDetails
{
115 // The BackgroundContents object that has just been opened.
116 BackgroundContents
* contents
;
118 // The name of the parent frame for these contents.
119 const base::string16
& frame_name
;
121 // The ID of the parent application (if any).
122 const base::string16
& application_id
;
125 #endif // CHROME_BROWSER_BACKGROUND_BACKGROUND_CONTENTS_H_