Add more checks to investigate SupervisedUserPrefStore crash at startup.
[chromium-blink-merge.git] / chrome / browser / background / background_contents.h
blobb4a94c4f55819f21b819378302021034d398d263
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_
8 #include <string>
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"
17 #include "url/gurl.h"
19 class Profile;
21 namespace content {
22 class SessionStorageNamespace;
23 class SiteInstance;
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 {
37 public:
38 class Delegate {
39 public:
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,
47 bool user_gesture,
48 bool* was_blocked) = 0;
50 protected:
51 virtual ~Delegate() {}
54 BackgroundContents(
55 content::SiteInstance* site_instance,
56 int routing_id,
57 int main_frame_routing_id,
58 Delegate* delegate,
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,
77 bool user_gesture,
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;
89 protected:
90 // Exposed for testing.
91 BackgroundContents();
93 private:
94 // DeferredStartRenderHost implementation:
95 void CreateRenderViewNow() override;
97 // The delegate for this BackgroundContents.
98 Delegate* delegate_;
100 // Delegate for choosing an ExtensionHostQueue.
101 scoped_ptr<extensions::ExtensionHostDelegate> extension_host_delegate_;
103 Profile* profile_;
104 scoped_ptr<content::WebContents> web_contents_;
105 content::NotificationRegistrar registrar_;
107 // The initial URL to load.
108 GURL initial_url_;
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_