OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/views/sad_tab_view.h" | 5 #include "chrome/browser/ui/views/sad_tab_view.h" |
6 | 6 |
7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/browser/google/google_util.h" | 9 #include "chrome/browser/google/google_util.h" |
| 10 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/browser/ui/webui/bug_report_ui.h" |
| 12 #include "chrome/browser/userfeedback/proto/extension.pb.h" |
10 #include "chrome/common/url_constants.h" | 13 #include "chrome/common/url_constants.h" |
11 #include "content/browser/tab_contents/tab_contents.h" | 14 #include "content/browser/tab_contents/tab_contents.h" |
12 #include "content/browser/tab_contents/tab_contents_delegate.h" | 15 #include "content/browser/tab_contents/tab_contents_delegate.h" |
13 #include "grit/generated_resources.h" | 16 #include "grit/generated_resources.h" |
14 #include "grit/locale_settings.h" | 17 #include "grit/locale_settings.h" |
15 #include "grit/theme_resources.h" | 18 #include "grit/theme_resources.h" |
16 #include "third_party/skia/include/effects/SkGradientShader.h" | 19 #include "third_party/skia/include/effects/SkGradientShader.h" |
17 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
18 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
19 #include "ui/gfx/canvas.h" | 22 #include "ui/gfx/canvas.h" |
(...skipping 25 matching lines...) Expand all Loading... |
45 static const int kTitleFontSizeDelta = 1; | 48 static const int kTitleFontSizeDelta = 1; |
46 static const int kMessageFontSizeDelta = 0; | 49 static const int kMessageFontSizeDelta = 0; |
47 #else | 50 #else |
48 static const int kTitleFontSizeDelta = 2; | 51 static const int kTitleFontSizeDelta = 2; |
49 static const int kMessageFontSizeDelta = 1; | 52 static const int kMessageFontSizeDelta = 1; |
50 #endif | 53 #endif |
51 | 54 |
52 SadTabView::SadTabView(TabContents* tab_contents, Kind kind) | 55 SadTabView::SadTabView(TabContents* tab_contents, Kind kind) |
53 : tab_contents_(tab_contents), | 56 : tab_contents_(tab_contents), |
54 learn_more_link_(NULL), | 57 learn_more_link_(NULL), |
| 58 feedback_link_(NULL), |
55 kind_(kind), | 59 kind_(kind), |
56 painted_(false) { | 60 painted_(false) { |
57 DCHECK(tab_contents); | 61 DCHECK(tab_contents); |
58 | 62 |
59 // Sometimes the user will never see this tab, so keep track of the total | 63 // Sometimes the user will never see this tab, so keep track of the total |
60 // number of creation events to compare to display events. | 64 // number of creation events to compare to display events. |
61 UMA_HISTOGRAM_COUNTS("SadTab.Created", kind); | 65 UMA_HISTOGRAM_COUNTS("SadTab.Created", kind); |
62 | 66 |
63 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 67 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
64 title_font_ = new gfx::Font( | 68 title_font_ = new gfx::Font( |
(...skipping 10 matching lines...) Expand all Loading... |
75 message_ = l10n_util::GetStringUTF16( | 79 message_ = l10n_util::GetStringUTF16( |
76 kind == CRASHED ? IDS_SAD_TAB_MESSAGE : IDS_KILLED_TAB_MESSAGE); | 80 kind == CRASHED ? IDS_SAD_TAB_MESSAGE : IDS_KILLED_TAB_MESSAGE); |
77 | 81 |
78 if (tab_contents != NULL) { | 82 if (tab_contents != NULL) { |
79 learn_more_link_ = | 83 learn_more_link_ = |
80 new views::Link(UTF16ToWide(l10n_util::GetStringUTF16(IDS_LEARN_MORE))); | 84 new views::Link(UTF16ToWide(l10n_util::GetStringUTF16(IDS_LEARN_MORE))); |
81 learn_more_link_->SetFont(*message_font_); | 85 learn_more_link_->SetFont(*message_font_); |
82 learn_more_link_->SetNormalColor(kLinkColor); | 86 learn_more_link_->SetNormalColor(kLinkColor); |
83 learn_more_link_->set_listener(this); | 87 learn_more_link_->set_listener(this); |
84 AddChildView(learn_more_link_); | 88 AddChildView(learn_more_link_); |
| 89 |
| 90 if (kind == KILLED) { |
| 91 feedback_link_ = new views::Link( |
| 92 UTF16ToWide(l10n_util::GetStringUTF16(IDS_KILLED_TAB_FEEDBACK_LINK))); |
| 93 feedback_link_->SetFont(*message_font_); |
| 94 feedback_link_->SetNormalColor(kLinkColor); |
| 95 feedback_link_->set_listener(this); |
| 96 AddChildView(feedback_link_); |
| 97 } |
85 } | 98 } |
86 } | 99 } |
87 | 100 |
88 SadTabView::~SadTabView() {} | 101 SadTabView::~SadTabView() {} |
89 | 102 |
90 void SadTabView::OnPaint(gfx::Canvas* canvas) { | 103 void SadTabView::OnPaint(gfx::Canvas* canvas) { |
91 if (!painted_) { | 104 if (!painted_) { |
92 // User actually saw the error, keep track for user experience stats. | 105 // User actually saw the error, keep track for user experience stats. |
93 UMA_HISTOGRAM_COUNTS("SadTab.Displayed", kind_); | 106 UMA_HISTOGRAM_COUNTS("SadTab.Displayed", kind_); |
94 painted_ = true; | 107 painted_ = true; |
(...skipping 15 matching lines...) Expand all Loading... |
110 canvas->DrawStringInt(title_, *title_font_, kTitleColor, | 123 canvas->DrawStringInt(title_, *title_font_, kTitleColor, |
111 title_bounds_.x(), title_bounds_.y(), | 124 title_bounds_.x(), title_bounds_.y(), |
112 title_bounds_.width(), title_bounds_.height(), | 125 title_bounds_.width(), title_bounds_.height(), |
113 gfx::Canvas::TEXT_ALIGN_CENTER); | 126 gfx::Canvas::TEXT_ALIGN_CENTER); |
114 | 127 |
115 canvas->DrawStringInt(message_, *message_font_, | 128 canvas->DrawStringInt(message_, *message_font_, |
116 kMessageColor, message_bounds_.x(), message_bounds_.y(), | 129 kMessageColor, message_bounds_.x(), message_bounds_.y(), |
117 message_bounds_.width(), message_bounds_.height(), | 130 message_bounds_.width(), message_bounds_.height(), |
118 kMessageFlags); | 131 kMessageFlags); |
119 | 132 |
120 if (learn_more_link_ != NULL) | 133 if (learn_more_link_ != NULL) { |
121 learn_more_link_->SetBounds(link_bounds_.x(), link_bounds_.y(), | 134 learn_more_link_->SetBounds( |
122 link_bounds_.width(), link_bounds_.height()); | 135 learn_more_bounds_.x(), learn_more_bounds_.y(), |
| 136 learn_more_bounds_.width(), learn_more_bounds_.height()); |
| 137 } |
| 138 if (feedback_link_ != NULL) { |
| 139 feedback_link_->SetBounds( |
| 140 feedback_bounds_.x(), feedback_bounds_.y(), |
| 141 feedback_bounds_.width(), feedback_bounds_.height()); |
| 142 } |
123 } | 143 } |
124 | 144 |
125 void SadTabView::Layout() { | 145 void SadTabView::Layout() { |
126 int icon_width = sad_tab_bitmap_->width(); | 146 int icon_width = sad_tab_bitmap_->width(); |
127 int icon_height = sad_tab_bitmap_->height(); | 147 int icon_height = sad_tab_bitmap_->height(); |
128 int icon_x = (width() - icon_width) / 2; | 148 int icon_x = (width() - icon_width) / 2; |
129 int icon_y = ((height() - icon_height) / 2) + kSadTabOffset; | 149 int icon_y = ((height() - icon_height) / 2) + kSadTabOffset; |
130 icon_bounds_.SetRect(icon_x, icon_y, icon_width, icon_height); | 150 icon_bounds_.SetRect(icon_x, icon_y, icon_width, icon_height); |
131 | 151 |
132 int title_x = (width() - title_width_) / 2; | 152 int title_x = (width() - title_width_) / 2; |
133 int title_y = icon_bounds_.bottom() + kIconTitleSpacing; | 153 int title_y = icon_bounds_.bottom() + kIconTitleSpacing; |
134 int title_height = title_font_->GetHeight(); | 154 int title_height = title_font_->GetHeight(); |
135 title_bounds_.SetRect(title_x, title_y, title_width_, title_height); | 155 title_bounds_.SetRect(title_x, title_y, title_width_, title_height); |
136 | 156 |
137 int message_width = static_cast<int>(width() * kMessageSize); | 157 int message_width = static_cast<int>(width() * kMessageSize); |
138 int message_height = 0; | 158 int message_height = 0; |
139 gfx::CanvasSkia::SizeStringInt(message_, | 159 gfx::CanvasSkia::SizeStringInt(message_, |
140 *message_font_, &message_width, | 160 *message_font_, &message_width, |
141 &message_height, kMessageFlags); | 161 &message_height, kMessageFlags); |
142 int message_x = (width() - message_width) / 2; | 162 int message_x = (width() - message_width) / 2; |
143 int message_y = title_bounds_.bottom() + kTitleMessageSpacing; | 163 int message_y = title_bounds_.bottom() + kTitleMessageSpacing; |
144 message_bounds_.SetRect(message_x, message_y, message_width, message_height); | 164 message_bounds_.SetRect(message_x, message_y, message_width, message_height); |
| 165 int bottom = message_bounds_.bottom(); |
145 | 166 |
146 if (learn_more_link_ != NULL) { | 167 if (learn_more_link_ != NULL) { |
147 gfx::Size sz = learn_more_link_->GetPreferredSize(); | 168 gfx::Size sz = learn_more_link_->GetPreferredSize(); |
148 gfx::Insets insets = learn_more_link_->GetInsets(); | 169 gfx::Insets insets = learn_more_link_->GetInsets(); |
149 link_bounds_.SetRect((width() - sz.width()) / 2, | 170 learn_more_bounds_.SetRect((width() - sz.width()) / 2, |
150 message_bounds_.bottom() + kTitleMessageSpacing - | 171 bottom + kTitleMessageSpacing - insets.top(), |
151 insets.top(), sz.width(), sz.height()); | 172 sz.width(), |
| 173 sz.height()); |
| 174 bottom = learn_more_bounds_.bottom(); |
| 175 } |
| 176 |
| 177 if (feedback_link_ != NULL) { |
| 178 gfx::Size sz = feedback_link_->GetPreferredSize(); |
| 179 gfx::Insets insets = feedback_link_->GetInsets(); |
| 180 feedback_bounds_.SetRect((width() - sz.width()) / 2, |
| 181 bottom + kTitleMessageSpacing - insets.top(), |
| 182 sz.width(), |
| 183 sz.height()); |
152 } | 184 } |
153 } | 185 } |
154 | 186 |
155 void SadTabView::LinkClicked(views::Link* source, int event_flags) { | 187 void SadTabView::LinkClicked(views::Link* source, int event_flags) { |
156 if (tab_contents_ != NULL && source == learn_more_link_) { | 188 if (tab_contents_ != NULL && source == learn_more_link_) { |
157 GURL help_url = | 189 GURL help_url = |
158 google_util::AppendGoogleLocaleParam(GURL(kind_ == CRASHED ? | 190 google_util::AppendGoogleLocaleParam(GURL(kind_ == CRASHED ? |
159 chrome::kCrashReasonURL : | 191 chrome::kCrashReasonURL : |
160 chrome::kKillReasonURL)); | 192 chrome::kKillReasonURL)); |
161 tab_contents_->OpenURL(help_url, GURL(), CURRENT_TAB, PageTransition::LINK); | 193 tab_contents_->OpenURL(help_url, GURL(), CURRENT_TAB, PageTransition::LINK); |
| 194 } else if (tab_contents_ != NULL && source == feedback_link_) { |
| 195 browser::ShowHtmlBugReportView( |
| 196 Browser::GetBrowserForController(&tab_contents_->controller(), NULL), |
| 197 l10n_util::GetStringUTF8(IDS_KILLED_TAB_FEEDBACK_MESSAGE), |
| 198 userfeedback::ChromeOsData_ChromeOsCategory_CRASH); |
162 } | 199 } |
163 } | 200 } |
OLD | NEW |