1 // Copyright (c) 2012 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_UI_SAD_TAB_HELPER_H_
6 #define CHROME_BROWSER_UI_SAD_TAB_HELPER_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.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_observer.h"
14 #include "content/public/browser/web_contents_user_data.h"
16 #if defined(OS_MACOSX)
17 #include "base/mac/foundation_util.h"
20 #if defined(OS_MACOSX)
21 class SadTabController
;
22 #elif defined(TOOLKIT_VIEWS)
26 #elif defined(TOOLKIT_GTK)
30 // Per-tab class to manage sad tab views.
31 class SadTabHelper
: public content::WebContentsObserver
,
32 public content::NotificationObserver
,
33 public content::WebContentsUserData
<SadTabHelper
> {
35 virtual ~SadTabHelper();
37 // Platform specific function to determine if there is a current sad tab page.
38 bool HasSadTab() const;
40 #if defined(TOOLKIT_VIEWS)
41 views::Widget
* sad_tab() { return sad_tab_
.get(); }
45 explicit SadTabHelper(content::WebContents
* web_contents
);
46 friend class content::WebContentsUserData
<SadTabHelper
>;
48 // Platform specific function to get an instance of the sad tab page.
49 void InstallSadTab(base::TerminationStatus status
);
51 // Overridden from content::WebContentsObserver:
52 virtual void RenderViewGone(base::TerminationStatus status
) OVERRIDE
;
54 // Overridden from content::NotificationObserver:
55 virtual void Observe(int type
,
56 const content::NotificationSource
& source
,
57 const content::NotificationDetails
& details
) OVERRIDE
;
59 // Used to get notifications about renderers coming and going.
60 content::NotificationRegistrar registrar_
;
62 // The platform views used to render the sad tab, non-NULL if visible.
63 #if defined(OS_MACOSX)
64 class ScopedPtrRelease
{
66 inline void operator()(void* x
) const {
67 base::mac::NSObjectRelease(x
);
70 scoped_ptr_malloc
<SadTabController
, ScopedPtrRelease
> sad_tab_
;
71 #elif defined(TOOLKIT_VIEWS)
72 scoped_ptr
<views::Widget
> sad_tab_
;
73 #elif defined(TOOLKIT_GTK)
74 scoped_ptr
<SadTabGtk
> sad_tab_
;
77 DISALLOW_COPY_AND_ASSIGN(SadTabHelper
);
80 #endif // CHROME_BROWSER_UI_SAD_TAB_HELPER_H_