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" | 10 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/browser/ui/webui/bug_report_ui.h" | 11 #include "chrome/browser/ui/webui/bug_report_ui.h" |
12 #include "chrome/browser/userfeedback/proto/extension.pb.h" | 12 #include "chrome/browser/userfeedback/proto/extension.pb.h" |
13 #include "chrome/common/url_constants.h" | 13 #include "chrome/common/url_constants.h" |
14 #include "content/browser/tab_contents/tab_contents.h" | 14 #include "content/public/browser/web_contents.h" |
15 #include "grit/generated_resources.h" | 15 #include "grit/generated_resources.h" |
16 #include "grit/theme_resources.h" | 16 #include "grit/theme_resources.h" |
17 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
18 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
19 #include "ui/gfx/font.h" | 19 #include "ui/gfx/font.h" |
20 #include "ui/views/controls/button/text_button.h" | 20 #include "ui/views/controls/button/text_button.h" |
21 #include "ui/views/controls/image_view.h" | 21 #include "ui/views/controls/image_view.h" |
22 #include "ui/views/controls/label.h" | 22 #include "ui/views/controls/label.h" |
23 #include "ui/views/controls/link.h" | 23 #include "ui/views/controls/link.h" |
24 #include "ui/views/layout/grid_layout.h" | 24 #include "ui/views/layout/grid_layout.h" |
25 | 25 |
| 26 using content::WebContents; |
| 27 |
26 static const int kPadding = 20; | 28 static const int kPadding = 20; |
27 static const float kMessageSize = 0.65f; | 29 static const float kMessageSize = 0.65f; |
28 static const SkColor kTextColor = SK_ColorWHITE; | 30 static const SkColor kTextColor = SK_ColorWHITE; |
29 static const SkColor kCrashColor = SkColorSetRGB(35, 48, 64); | 31 static const SkColor kCrashColor = SkColorSetRGB(35, 48, 64); |
30 static const SkColor kKillColor = SkColorSetRGB(57, 48, 88); | 32 static const SkColor kKillColor = SkColorSetRGB(57, 48, 88); |
31 | 33 |
32 // Font size correction. | 34 // Font size correction. |
33 #if defined(CROS_FONTS_USING_BCI) | 35 #if defined(CROS_FONTS_USING_BCI) |
34 static const int kTitleFontSizeDelta = 1; | 36 static const int kTitleFontSizeDelta = 1; |
35 static const int kMessageFontSizeDelta = 0; | 37 static const int kMessageFontSizeDelta = 0; |
36 #else | 38 #else |
37 static const int kTitleFontSizeDelta = 2; | 39 static const int kTitleFontSizeDelta = 2; |
38 static const int kMessageFontSizeDelta = 1; | 40 static const int kMessageFontSizeDelta = 1; |
39 #endif | 41 #endif |
40 | 42 |
41 SadTabView::SadTabView(TabContents* tab_contents, Kind kind) | 43 SadTabView::SadTabView(WebContents* web_contents, Kind kind) |
42 : tab_contents_(tab_contents), | 44 : web_contents_(web_contents), |
43 kind_(kind), | 45 kind_(kind), |
44 painted_(false), | 46 painted_(false), |
45 base_font_(ResourceBundle::GetSharedInstance().GetFont( | 47 base_font_(ResourceBundle::GetSharedInstance().GetFont( |
46 ResourceBundle::BaseFont)), | 48 ResourceBundle::BaseFont)), |
47 message_(NULL), | 49 message_(NULL), |
48 help_link_(NULL), | 50 help_link_(NULL), |
49 feedback_link_(NULL), | 51 feedback_link_(NULL), |
50 reload_button_(NULL) { | 52 reload_button_(NULL) { |
51 DCHECK(tab_contents); | 53 DCHECK(web_contents); |
52 | 54 |
53 // Sometimes the user will never see this tab, so keep track of the total | 55 // Sometimes the user will never see this tab, so keep track of the total |
54 // number of creation events to compare to display events. | 56 // number of creation events to compare to display events. |
55 UMA_HISTOGRAM_COUNTS("SadTab.Created", kind_); | 57 UMA_HISTOGRAM_COUNTS("SadTab.Created", kind_); |
56 | 58 |
57 // Set the background color. | 59 // Set the background color. |
58 set_background(views::Background::CreateSolidBackground( | 60 set_background(views::Background::CreateSolidBackground( |
59 (kind_ == CRASHED) ? kCrashColor : kKillColor)); | 61 (kind_ == CRASHED) ? kCrashColor : kKillColor)); |
60 } | 62 } |
61 | 63 |
62 SadTabView::~SadTabView() {} | 64 SadTabView::~SadTabView() {} |
63 | 65 |
64 void SadTabView::LinkClicked(views::Link* source, int event_flags) { | 66 void SadTabView::LinkClicked(views::Link* source, int event_flags) { |
65 DCHECK(tab_contents_); | 67 DCHECK(web_contents_); |
66 if (source == help_link_) { | 68 if (source == help_link_) { |
67 GURL help_url = | 69 GURL help_url = |
68 google_util::AppendGoogleLocaleParam(GURL(kind_ == CRASHED ? | 70 google_util::AppendGoogleLocaleParam(GURL(kind_ == CRASHED ? |
69 chrome::kCrashReasonURL : | 71 chrome::kCrashReasonURL : |
70 chrome::kKillReasonURL)); | 72 chrome::kKillReasonURL)); |
71 tab_contents_->OpenURL(OpenURLParams( | 73 web_contents_->OpenURL(OpenURLParams( |
72 help_url, | 74 help_url, |
73 content::Referrer(), | 75 content::Referrer(), |
74 CURRENT_TAB, | 76 CURRENT_TAB, |
75 content::PAGE_TRANSITION_LINK, | 77 content::PAGE_TRANSITION_LINK, |
76 false /* is renderer initiated */)); | 78 false /* is renderer initiated */)); |
77 } else if (source == feedback_link_) { | 79 } else if (source == feedback_link_) { |
78 browser::ShowHtmlBugReportView( | 80 browser::ShowHtmlBugReportView( |
79 Browser::GetBrowserForController(&tab_contents_->GetController(), NULL), | 81 Browser::GetBrowserForController(&web_contents_->GetController(), NULL), |
80 l10n_util::GetStringUTF8(IDS_KILLED_TAB_FEEDBACK_MESSAGE), | 82 l10n_util::GetStringUTF8(IDS_KILLED_TAB_FEEDBACK_MESSAGE), |
81 userfeedback::ChromeOsData_ChromeOsCategory_CRASH); | 83 userfeedback::ChromeOsData_ChromeOsCategory_CRASH); |
82 } | 84 } |
83 } | 85 } |
84 | 86 |
85 void SadTabView::ButtonPressed(views::Button* source, | 87 void SadTabView::ButtonPressed(views::Button* source, |
86 const views::Event& event) { | 88 const views::Event& event) { |
87 DCHECK(tab_contents_); | 89 DCHECK(web_contents_); |
88 DCHECK(source == reload_button_); | 90 DCHECK(source == reload_button_); |
89 tab_contents_->GetController().Reload(true); | 91 web_contents_->GetController().Reload(true); |
90 } | 92 } |
91 | 93 |
92 void SadTabView::Layout() { | 94 void SadTabView::Layout() { |
93 // Specify the maximum message width explicitly. | 95 // Specify the maximum message width explicitly. |
94 message_->SizeToFit(static_cast<int>(width() * kMessageSize)); | 96 message_->SizeToFit(static_cast<int>(width() * kMessageSize)); |
95 View::Layout(); | 97 View::Layout(); |
96 } | 98 } |
97 | 99 |
98 void SadTabView::ViewHierarchyChanged(bool is_add, | 100 void SadTabView::ViewHierarchyChanged(bool is_add, |
99 views::View* parent, | 101 views::View* parent, |
(...skipping 22 matching lines...) Expand all Loading... |
122 title->SetFont(base_font_.DeriveFont(kTitleFontSizeDelta, gfx::Font::BOLD)); | 124 title->SetFont(base_font_.DeriveFont(kTitleFontSizeDelta, gfx::Font::BOLD)); |
123 layout->StartRowWithPadding(0, column_set_id, 0, kPadding); | 125 layout->StartRowWithPadding(0, column_set_id, 0, kPadding); |
124 layout->AddView(title); | 126 layout->AddView(title); |
125 | 127 |
126 message_ = CreateLabel(l10n_util::GetStringUTF16( | 128 message_ = CreateLabel(l10n_util::GetStringUTF16( |
127 (kind_ == CRASHED) ? IDS_SAD_TAB_MESSAGE : IDS_KILLED_TAB_MESSAGE)); | 129 (kind_ == CRASHED) ? IDS_SAD_TAB_MESSAGE : IDS_KILLED_TAB_MESSAGE)); |
128 message_->SetMultiLine(true); | 130 message_->SetMultiLine(true); |
129 layout->StartRowWithPadding(0, column_set_id, 0, kPadding); | 131 layout->StartRowWithPadding(0, column_set_id, 0, kPadding); |
130 layout->AddView(message_); | 132 layout->AddView(message_); |
131 | 133 |
132 if (tab_contents_) { | 134 if (web_contents_) { |
133 layout->StartRowWithPadding(0, column_set_id, 0, kPadding); | 135 layout->StartRowWithPadding(0, column_set_id, 0, kPadding); |
134 reload_button_ = new views::TextButton( | 136 reload_button_ = new views::TextButton( |
135 this, | 137 this, |
136 l10n_util::GetStringUTF16(IDS_SAD_TAB_RELOAD_LABEL)); | 138 l10n_util::GetStringUTF16(IDS_SAD_TAB_RELOAD_LABEL)); |
137 reload_button_->set_border(new views::TextButtonNativeThemeBorder( | 139 reload_button_->set_border(new views::TextButtonNativeThemeBorder( |
138 reload_button_)); | 140 reload_button_)); |
139 layout->AddView(reload_button_); | 141 layout->AddView(reload_button_); |
140 | 142 |
141 help_link_ = CreateLink(l10n_util::GetStringUTF16( | 143 help_link_ = CreateLink(l10n_util::GetStringUTF16( |
142 (kind_ == CRASHED) ? IDS_SAD_TAB_HELP_LINK : IDS_LEARN_MORE)); | 144 (kind_ == CRASHED) ? IDS_SAD_TAB_HELP_LINK : IDS_LEARN_MORE)); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 views::Link* SadTabView::CreateLink(const string16& text) { | 196 views::Link* SadTabView::CreateLink(const string16& text) { |
195 views::Link* link = new views::Link(text); | 197 views::Link* link = new views::Link(text); |
196 link->SetFont(base_font_.DeriveFont(kMessageFontSizeDelta)); | 198 link->SetFont(base_font_.DeriveFont(kMessageFontSizeDelta)); |
197 link->SetBackgroundColor(background()->get_color()); | 199 link->SetBackgroundColor(background()->get_color()); |
198 link->SetEnabledColor(kTextColor); | 200 link->SetEnabledColor(kTextColor); |
199 link->set_listener(this); | 201 link->set_listener(this); |
200 return link; | 202 return link; |
201 } | 203 } |
202 | 204 |
203 | 205 |
OLD | NEW |