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 "base/observer_list.h"
12 #include "content/public/browser/notification_observer.h"
13 #include "content/public/browser/notification_registrar.h"
14 #include "content/public/browser/web_contents_delegate.h"
15 #include "content/public/browser/web_contents_observer.h"
16 #include "extensions/browser/deferred_start_render_host.h"
17 #include "ui/base/window_open_disposition.h"
23 class SessionStorageNamespace
;
27 namespace extensions
{
28 class ExtensionHostDelegate
;
31 // This class maintains a WebContents used in the background. It can host a
32 // renderer, but does not have any visible display.
33 // TODO(atwilson): Unify this with background pages; http://crbug.com/77790
34 class BackgroundContents
: public extensions::DeferredStartRenderHost
,
35 public content::WebContentsDelegate
,
36 public content::WebContentsObserver
,
37 public content::NotificationObserver
{
41 // Called by AddNewContents(). Asks the delegate to attach the opened
42 // WebContents to a suitable container (e.g. browser) or to show it if it's
43 // a popup window. If |was_blocked| is non-NULL, then |*was_blocked| will be
44 // set to true if the popup gets blocked, and left unchanged otherwise.
45 virtual void AddWebContents(content::WebContents
* new_contents
,
46 WindowOpenDisposition disposition
,
47 const gfx::Rect
& initial_rect
,
49 bool* was_blocked
) = 0;
52 virtual ~Delegate() {}
56 content::SiteInstance
* site_instance
,
58 int main_frame_routing_id
,
60 const std::string
& partition_id
,
61 content::SessionStorageNamespace
* session_storage_namespace
);
62 ~BackgroundContents() override
;
64 content::WebContents
* web_contents() const { return web_contents_
.get(); }
65 virtual const GURL
& GetURL() const;
67 // Adds this BackgroundContents to the queue of RenderViews to create.
68 void CreateRenderViewSoon(const GURL
& url
);
70 // content::WebContentsDelegate implementation:
71 void CloseContents(content::WebContents
* source
) override
;
72 bool ShouldSuppressDialogs(content::WebContents
* source
) override
;
73 void DidNavigateMainFramePostCommit(content::WebContents
* tab
) override
;
74 void AddNewContents(content::WebContents
* source
,
75 content::WebContents
* new_contents
,
76 WindowOpenDisposition disposition
,
77 const gfx::Rect
& initial_rect
,
79 bool* was_blocked
) override
;
80 bool IsNeverVisible(content::WebContents
* web_contents
) override
;
82 // content::WebContentsObserver implementation:
83 void RenderProcessGone(base::TerminationStatus status
) override
;
84 void DidStartLoading(content::RenderViewHost
* render_view_host
) override
;
85 void DidStopLoading(content::RenderViewHost
* render_view_host
) override
;
87 // content::NotificationObserver
88 void Observe(int type
,
89 const content::NotificationSource
& source
,
90 const content::NotificationDetails
& details
) override
;
93 // Exposed for testing.
97 // extensions::DeferredStartRenderHost implementation:
98 void CreateRenderViewNow() override
;
99 void AddDeferredStartRenderHostObserver(
100 extensions::DeferredStartRenderHostObserver
* observer
) override
;
101 void RemoveDeferredStartRenderHostObserver(
102 extensions::DeferredStartRenderHostObserver
* observer
) override
;
104 // The delegate for this BackgroundContents.
107 // Delegate for choosing an ExtensionHostQueue.
108 scoped_ptr
<extensions::ExtensionHostDelegate
> extension_host_delegate_
;
111 scoped_ptr
<content::WebContents
> web_contents_
;
112 content::NotificationRegistrar registrar_
;
113 ObserverList
<extensions::DeferredStartRenderHostObserver
>
114 deferred_start_render_host_observer_list_
;
116 // The initial URL to load.
119 DISALLOW_COPY_AND_ASSIGN(BackgroundContents
);
122 // This is the data sent out as the details with BACKGROUND_CONTENTS_OPENED.
123 struct BackgroundContentsOpenedDetails
{
124 // The BackgroundContents object that has just been opened.
125 BackgroundContents
* contents
;
127 // The name of the parent frame for these contents.
128 const base::string16
& frame_name
;
130 // The ID of the parent application (if any).
131 const base::string16
& application_id
;
134 #endif // CHROME_BROWSER_BACKGROUND_BACKGROUND_CONTENTS_H_