Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: chrome/browser/ui/sad_tab_observer.cc

Issue 8477042: Move Sad Tab implementation out of the TabContentsViews. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: mac unit test Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #include "chrome/browser/ui/sad_tab_observer.h"
6
7 #include "chrome/browser/browser_shutdown.h"
8 #include "content/browser/tab_contents/tab_contents.h"
9 #include "content/browser/tab_contents/tab_contents_view.h"
10 #include "content/public/browser/notification_source.h"
11 #include "content/public/browser/notification_types.h"
12
13 #if defined(OS_MACOSX)
14 #include "chrome/browser/ui/cocoa/tab_contents/sad_tab_controller.h"
15 #elif defined(TOOLKIT_VIEWS)
16 #include "chrome/browser/ui/views/sad_tab_view.h"
17 #include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h"
18 #elif defined(TOOLKIT_GTK)
19 #include "chrome/browser/ui/gtk/sad_tab_gtk.h"
20 #endif
21
22 SadTabObserver::SadTabObserver(TabContents* tab_contents)
23 : TabContentsObserver(tab_contents) {
24 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_CONNECTED,
25 content::Source<TabContents>(tab_contents));
26 }
27
28 SadTabObserver::~SadTabObserver() {
29 }
30
31 void SadTabObserver::RenderViewGone(base::TerminationStatus status) {
32 // Only show the sad tab if we're not in browser shutdown, so that TabContents
33 // objects that are not in a browser (e.g., HTML dialogs) and thus are
34 // visible do not flash a sad tab page.
35 if (browser_shutdown::GetShutdownType() != browser_shutdown::NOT_VALID)
36 return;
37
38 if (HasSadTab())
39 return;
40
41 gfx::NativeView view = AcquireSadTab(status);
42 tab_contents()->view()->InstallOverlayView(view);
43 }
44
45 void SadTabObserver::Observe(int type,
46 const content::NotificationSource& source,
47 const content::NotificationDetails& details) {
48 switch (type) {
49 case content::NOTIFICATION_TAB_CONTENTS_CONNECTED:
50 if (HasSadTab()) {
51 tab_contents()->view()->RemoveOverlayView();
52 ReleaseSadTab();
53 }
54 break;
55
56 default:
57 NOTREACHED() << "Got a notification we didn't register for.";
58 }
59 }
60
61 #if defined(OS_MACOSX)
62 gfx::NativeView SadTabObserver::AcquireSadTab(base::TerminationStatus status) {
63 sad_tab_.reset(
64 sad_tab_controller_mac::CreateSadTabController(tab_contents()));
65 return sad_tab_controller_mac::ViewOfSadTabController(sad_tab_.get());
66 }
67
68 void SadTabObserver::ReleaseSadTab() {
jam 2011/11/14 19:56:28 this function and below are duplicated for all thr
69 sad_tab_.reset();
70 }
71
72 bool SadTabObserver::HasSadTab() {
73 return sad_tab_.get();
74 }
75 #elif defined(TOOLKIT_VIEWS)
76 gfx::NativeView SadTabObserver::AcquireSadTab(base::TerminationStatus status) {
77 SadTabView::Kind kind =
78 status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED ?
79 SadTabView::KILLED : SadTabView::CRASHED;
80 views::Widget::InitParams sad_tab_params(
81 views::Widget::InitParams::TYPE_CONTROL);
82 // It is not possible to create a widget that has no parent, and later
83 // re-parent it. TODO(avi): This is a cheat. Can this be made cleaner?
84 sad_tab_params.parent_widget =
85 static_cast<TabContentsViewViews*>(tab_contents()->view());
86 sad_tab_params.ownership =
87 views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
88 sad_tab_.reset(new views::Widget);
89 sad_tab_->Init(sad_tab_params);
90 sad_tab_->SetContentsView(new SadTabView(tab_contents(), kind));
91 return sad_tab_->GetNativeView();
92 }
93
94 void SadTabObserver::ReleaseSadTab() {
95 sad_tab_.reset();
96 }
97
98 bool SadTabObserver::HasSadTab() {
99 return sad_tab_.get() != NULL;
100 }
101 #elif defined(TOOLKIT_GTK)
102 gfx::NativeView SadTabObserver::AcquireSadTab(base::TerminationStatus status) {
103 sad_tab_.reset(new SadTabGtk(
104 tab_contents(),
105 status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED
106 ? SadTabGtk::KILLED
107 : SadTabGtk::CRASHED));
108 return sad_tab_->widget();
109 }
110
111 void SadTabObserver::ReleaseSadTab() {
112 sad_tab_.reset();
113 }
114
115 bool SadTabObserver::HasSadTab() {
116 return sad_tab_.get();
117 }
118 #else
119 #error Unknown platform
120 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698