OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/sad_tab_helper.h" | 5 #include "chrome/browser/ui/sad_tab_helper.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "chrome/browser/browser_shutdown.h" | 8 #include "chrome/browser/browser_shutdown.h" |
| 9 #include "chrome/browser/ui/sad_tab_types.h" |
9 #include "content/public/browser/notification_source.h" | 10 #include "content/public/browser/notification_source.h" |
10 #include "content/public/browser/notification_types.h" | 11 #include "content/public/browser/notification_types.h" |
11 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
12 #include "content/public/browser/web_contents_view.h" | 13 #include "content/public/browser/web_contents_view.h" |
13 | 14 |
14 #if defined(OS_MACOSX) | 15 #if defined(OS_MACOSX) |
15 #include "chrome/browser/ui/cocoa/tab_contents/sad_tab_controller.h" | 16 #include "chrome/browser/ui/cocoa/tab_contents/sad_tab_controller.h" |
16 #elif defined(TOOLKIT_VIEWS) | 17 #elif defined(TOOLKIT_VIEWS) |
17 #include "chrome/browser/ui/views/sad_tab_view.h" | 18 #include "chrome/browser/ui/views/sad_tab_view.h" |
18 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
19 #elif defined(TOOLKIT_GTK) | 20 #elif defined(TOOLKIT_GTK) |
20 | |
21 #include <gtk/gtk.h> | 21 #include <gtk/gtk.h> |
22 | 22 |
23 #include "chrome/browser/ui/gtk/sad_tab_gtk.h" | 23 #include "chrome/browser/ui/gtk/sad_tab_gtk.h" |
24 #include "chrome/browser/ui/gtk/tab_contents/chrome_web_contents_view_delegate_g
tk.h" | 24 #include "chrome/browser/ui/gtk/tab_contents/chrome_web_contents_view_delegate_g
tk.h" |
25 #endif | 25 #endif |
26 | 26 |
27 using content::WebContents; | 27 SadTabHelper::SadTabHelper(content::WebContents* web_contents) |
28 | |
29 SadTabHelper::SadTabHelper(WebContents* web_contents) | |
30 : content::WebContentsObserver(web_contents) { | 28 : content::WebContentsObserver(web_contents) { |
31 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_CONNECTED, | 29 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_CONNECTED, |
32 content::Source<WebContents>(web_contents)); | 30 content::Source<content::WebContents>(web_contents)); |
33 } | 31 } |
34 | 32 |
35 SadTabHelper::~SadTabHelper() { | 33 SadTabHelper::~SadTabHelper() { |
36 } | 34 } |
37 | 35 |
| 36 bool SadTabHelper::HasSadTab() const { |
| 37 return sad_tab_.get() != NULL; |
| 38 } |
| 39 |
38 void SadTabHelper::RenderViewGone(base::TerminationStatus status) { | 40 void SadTabHelper::RenderViewGone(base::TerminationStatus status) { |
39 // Only show the sad tab if we're not in browser shutdown, so that WebContents | 41 // Only show the sad tab if we're not in browser shutdown, so that WebContents |
40 // objects that are not in a browser (e.g., HTML dialogs) and thus are | 42 // objects that are not in a browser (e.g., HTML dialogs) and thus are |
41 // visible do not flash a sad tab page. | 43 // visible do not flash a sad tab page. |
42 if (browser_shutdown::GetShutdownType() != browser_shutdown::NOT_VALID) | 44 if (browser_shutdown::GetShutdownType() != browser_shutdown::NOT_VALID) |
43 return; | 45 return; |
44 | 46 |
45 // Don't build the sad tab view when the termination status is normal. | 47 // Don't build the sad tab view when the termination status is normal. |
46 if (status == base::TERMINATION_STATUS_NORMAL_TERMINATION) | 48 if (status == base::TERMINATION_STATUS_NORMAL_TERMINATION) |
47 return; | 49 return; |
(...skipping 30 matching lines...) Expand all Loading... |
78 sad_tab_.reset(); | 80 sad_tab_.reset(); |
79 } | 81 } |
80 break; | 82 break; |
81 | 83 |
82 default: | 84 default: |
83 NOTREACHED() << "Got a notification we didn't register for."; | 85 NOTREACHED() << "Got a notification we didn't register for."; |
84 } | 86 } |
85 } | 87 } |
86 | 88 |
87 void SadTabHelper::InstallSadTab(base::TerminationStatus status) { | 89 void SadTabHelper::InstallSadTab(base::TerminationStatus status) { |
| 90 #if defined(TOOLKIT_VIEWS) || defined(TOOLKIT_GTK) |
| 91 chrome::SadTabKind kind = |
| 92 (status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED) ? |
| 93 chrome::SAD_TAB_KIND_KILLED : chrome::SAD_TAB_KIND_CRASHED; |
| 94 #endif |
88 #if defined(OS_MACOSX) | 95 #if defined(OS_MACOSX) |
89 sad_tab_.reset( | 96 sad_tab_.reset( |
90 sad_tab_controller_mac::CreateSadTabController(web_contents())); | 97 sad_tab_controller_mac::CreateSadTabController(web_contents())); |
91 #elif defined(TOOLKIT_VIEWS) | 98 #elif defined(TOOLKIT_VIEWS) |
92 SadTabView::Kind kind = | |
93 status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED ? | |
94 SadTabView::KILLED : SadTabView::CRASHED; | |
95 views::Widget::InitParams sad_tab_params( | 99 views::Widget::InitParams sad_tab_params( |
96 views::Widget::InitParams::TYPE_CONTROL); | 100 views::Widget::InitParams::TYPE_CONTROL); |
97 // It is not possible to create a native_widget_win that has no parent in | 101 // It is not possible to create a native_widget_win that has no parent in |
98 // and later re-parent it. | 102 // and later re-parent it. |
99 // TODO(avi): This is a cheat. Can this be made cleaner? | 103 // TODO(avi): This is a cheat. Can this be made cleaner? |
100 sad_tab_params.parent = web_contents()->GetView()->GetNativeView(); | 104 sad_tab_params.parent = web_contents()->GetView()->GetNativeView(); |
101 #if defined(OS_WIN) && !defined(USE_AURA) | 105 #if defined(OS_WIN) && !defined(USE_AURA) |
102 // Crash data indicates we can get here when the parent is no longer valid. | 106 // Crash data indicates we can get here when the parent is no longer valid. |
103 // Attempting to create a child window with a bogus parent crashes. So, we | 107 // Attempting to create a child window with a bogus parent crashes. So, we |
104 // don't show a sad tab in this case in hopes the tab is in the process of | 108 // don't show a sad tab in this case in hopes the tab is in the process of |
105 // shutting down. | 109 // shutting down. |
106 if (!IsWindow(sad_tab_params.parent)) | 110 if (!IsWindow(sad_tab_params.parent)) |
107 return; | 111 return; |
108 #endif | 112 #endif |
109 sad_tab_params.ownership = | 113 sad_tab_params.ownership = |
110 views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 114 views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
111 sad_tab_.reset(new views::Widget); | 115 sad_tab_.reset(new views::Widget); |
112 sad_tab_->Init(sad_tab_params); | 116 sad_tab_->Init(sad_tab_params); |
113 sad_tab_->SetContentsView(new SadTabView(web_contents(), kind)); | 117 sad_tab_->SetContentsView(new SadTabView(web_contents(), kind)); |
114 | 118 |
115 views::Widget::ReparentNativeView( | 119 views::Widget::ReparentNativeView( |
116 sad_tab_->GetNativeView(), web_contents()->GetView()->GetNativeView()); | 120 sad_tab_->GetNativeView(), web_contents()->GetView()->GetNativeView()); |
117 gfx::Rect bounds; | 121 gfx::Rect bounds; |
118 web_contents()->GetView()->GetContainerBounds(&bounds); | 122 web_contents()->GetView()->GetContainerBounds(&bounds); |
119 sad_tab_->SetBounds(gfx::Rect(bounds.size())); | 123 sad_tab_->SetBounds(gfx::Rect(bounds.size())); |
120 #elif defined(TOOLKIT_GTK) | 124 #elif defined(TOOLKIT_GTK) |
121 sad_tab_.reset(new SadTabGtk( | 125 sad_tab_.reset(new SadTabGtk(web_contents(), kind)); |
122 web_contents(), | |
123 status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED | |
124 ? SadTabGtk::KILLED | |
125 : SadTabGtk::CRASHED)); | |
126 GtkWidget* expanded_container = | 126 GtkWidget* expanded_container = |
127 ChromeWebContentsViewDelegateGtk::GetFor(web_contents())-> | 127 ChromeWebContentsViewDelegateGtk::GetFor(web_contents())-> |
128 expanded_container(); | 128 expanded_container(); |
129 gtk_container_add(GTK_CONTAINER(expanded_container), sad_tab_->widget()); | 129 gtk_container_add(GTK_CONTAINER(expanded_container), sad_tab_->widget()); |
130 gtk_widget_show(sad_tab_->widget()); | 130 gtk_widget_show(sad_tab_->widget()); |
131 #else | 131 #else |
132 #error Unknown platform | 132 #error Unknown platform |
133 #endif | 133 #endif |
134 } | 134 } |
135 | |
136 bool SadTabHelper::HasSadTab() { | |
137 return sad_tab_.get() != NULL; | |
138 } | |
OLD | NEW |