| 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/views/sad_tab_view.h" | 5 #include "chrome/browser/ui/views/sad_tab_view.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/feedback/feedback_util.h" | 12 #include "chrome/browser/feedback/feedback_util.h" |
| 13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/browser/ui/browser_finder.h" | 14 #include "chrome/browser/ui/browser_finder.h" |
| 15 #include "chrome/browser/ui/chrome_pages.h" | 15 #include "chrome/browser/ui/chrome_pages.h" |
| 16 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
| 17 #include "content/public/browser/navigation_controller.h" | 17 #include "content/public/browser/navigation_controller.h" |
| 18 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
| 19 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
| 20 #include "grit/theme_resources.h" | 20 #include "grit/theme_resources.h" |
| 21 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
| 22 #include "ui/base/resource/resource_bundle.h" | 22 #include "ui/base/resource/resource_bundle.h" |
| 23 #include "ui/gfx/font.h" | |
| 24 #include "ui/views/controls/button/text_button.h" | 23 #include "ui/views/controls/button/text_button.h" |
| 25 #include "ui/views/controls/image_view.h" | 24 #include "ui/views/controls/image_view.h" |
| 26 #include "ui/views/controls/label.h" | 25 #include "ui/views/controls/label.h" |
| 27 #include "ui/views/controls/link.h" | 26 #include "ui/views/controls/link.h" |
| 28 #include "ui/views/layout/grid_layout.h" | 27 #include "ui/views/layout/grid_layout.h" |
| 29 | 28 |
| 30 using content::OpenURLParams; | 29 using content::OpenURLParams; |
| 31 using content::WebContents; | 30 using content::WebContents; |
| 32 | 31 |
| 33 namespace { | 32 namespace { |
| 34 | 33 |
| 35 const int kPadding = 20; | 34 const int kPadding = 20; |
| 36 const float kMessageSize = 0.65f; | 35 const float kMessageSize = 0.65f; |
| 37 const SkColor kTextColor = SK_ColorWHITE; | 36 const SkColor kTextColor = SK_ColorWHITE; |
| 38 const SkColor kCrashColor = SkColorSetRGB(35, 48, 64); | 37 const SkColor kCrashColor = SkColorSetRGB(35, 48, 64); |
| 39 const SkColor kKillColor = SkColorSetRGB(57, 48, 88); | 38 const SkColor kKillColor = SkColorSetRGB(57, 48, 88); |
| 40 | 39 |
| 41 const char kCategoryTagCrash[] = "Crash"; | 40 const char kCategoryTagCrash[] = "Crash"; |
| 42 | 41 |
| 43 // Font size correction. | |
| 44 const int kTitleFontSizeDelta = 2; | |
| 45 const int kMessageFontSizeDelta = 1; | |
| 46 | |
| 47 // Name of the experiment to run. | 42 // Name of the experiment to run. |
| 48 const char kExperiment[] = "LowMemoryMargin"; | 43 const char kExperiment[] = "LowMemoryMargin"; |
| 49 | 44 |
| 50 #define EXPERIMENT_CUSTOM_COUNTS(name, sample, min, max, buckets) \ | 45 #define EXPERIMENT_CUSTOM_COUNTS(name, sample, min, max, buckets) \ |
| 51 { \ | 46 { \ |
| 52 UMA_HISTOGRAM_CUSTOM_COUNTS(name, sample, min, max, buckets); \ | 47 UMA_HISTOGRAM_CUSTOM_COUNTS(name, sample, min, max, buckets); \ |
| 53 if (base::FieldTrialList::TrialExists(kExperiment)) \ | 48 if (base::FieldTrialList::TrialExists(kExperiment)) \ |
| 54 UMA_HISTOGRAM_CUSTOM_COUNTS( \ | 49 UMA_HISTOGRAM_CUSTOM_COUNTS( \ |
| 55 base::FieldTrial::MakeName(name, kExperiment), \ | 50 base::FieldTrial::MakeName(name, kExperiment), \ |
| 56 sample, min, max, buckets); \ | 51 sample, min, max, buckets); \ |
| 57 } | 52 } |
| 58 | 53 |
| 59 } // namespace | 54 } // namespace |
| 60 | 55 |
| 61 SadTabView::SadTabView(WebContents* web_contents, chrome::SadTabKind kind) | 56 SadTabView::SadTabView(WebContents* web_contents, chrome::SadTabKind kind) |
| 62 : web_contents_(web_contents), | 57 : web_contents_(web_contents), |
| 63 kind_(kind), | 58 kind_(kind), |
| 64 painted_(false), | 59 painted_(false), |
| 65 base_font_(ui::ResourceBundle::GetSharedInstance().GetFont( | |
| 66 ui::ResourceBundle::BaseFont)), | |
| 67 message_(NULL), | 60 message_(NULL), |
| 68 help_link_(NULL), | 61 help_link_(NULL), |
| 69 feedback_link_(NULL), | 62 feedback_link_(NULL), |
| 70 reload_button_(NULL) { | 63 reload_button_(NULL) { |
| 71 DCHECK(web_contents); | 64 DCHECK(web_contents); |
| 72 | 65 |
| 73 // Sometimes the user will never see this tab, so keep track of the total | 66 // Sometimes the user will never see this tab, so keep track of the total |
| 74 // number of creation events to compare to display events. | 67 // number of creation events to compare to display events. |
| 75 // TODO(jamescook): Remove this after R20 stable. Keep it for now so we can | 68 // TODO(jamescook): Remove this after R20 stable. Keep it for now so we can |
| 76 // compare R20 to earlier versions. | 69 // compare R20 to earlier versions. |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 | 147 |
| 155 views::ImageView* image = new views::ImageView(); | 148 views::ImageView* image = new views::ImageView(); |
| 156 image->SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 149 image->SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 157 (kind_ == chrome::SAD_TAB_KIND_CRASHED) ? IDR_SAD_TAB : IDR_KILLED_TAB)); | 150 (kind_ == chrome::SAD_TAB_KIND_CRASHED) ? IDR_SAD_TAB : IDR_KILLED_TAB)); |
| 158 layout->StartRowWithPadding(0, column_set_id, 1, kPadding); | 151 layout->StartRowWithPadding(0, column_set_id, 1, kPadding); |
| 159 layout->AddView(image); | 152 layout->AddView(image); |
| 160 | 153 |
| 161 views::Label* title = CreateLabel(l10n_util::GetStringUTF16( | 154 views::Label* title = CreateLabel(l10n_util::GetStringUTF16( |
| 162 (kind_ == chrome::SAD_TAB_KIND_CRASHED) ? | 155 (kind_ == chrome::SAD_TAB_KIND_CRASHED) ? |
| 163 IDS_SAD_TAB_TITLE : IDS_KILLED_TAB_TITLE)); | 156 IDS_SAD_TAB_TITLE : IDS_KILLED_TAB_TITLE)); |
| 164 title->SetFont(base_font_.DeriveFont(kTitleFontSizeDelta, gfx::Font::BOLD)); | 157 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 158 title->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont)); |
| 165 layout->StartRowWithPadding(0, column_set_id, 0, kPadding); | 159 layout->StartRowWithPadding(0, column_set_id, 0, kPadding); |
| 166 layout->AddView(title); | 160 layout->AddView(title); |
| 167 | 161 |
| 168 message_ = CreateLabel(l10n_util::GetStringUTF16( | 162 message_ = CreateLabel(l10n_util::GetStringUTF16( |
| 169 (kind_ == chrome::SAD_TAB_KIND_CRASHED) ? | 163 (kind_ == chrome::SAD_TAB_KIND_CRASHED) ? |
| 170 IDS_SAD_TAB_MESSAGE : IDS_KILLED_TAB_MESSAGE)); | 164 IDS_SAD_TAB_MESSAGE : IDS_KILLED_TAB_MESSAGE)); |
| 171 message_->SetMultiLine(true); | 165 message_->SetMultiLine(true); |
| 172 layout->StartRowWithPadding(0, column_set_id, 0, kPadding); | 166 layout->StartRowWithPadding(0, column_set_id, 0, kPadding); |
| 173 layout->AddView(message_); | 167 layout->AddView(message_); |
| 174 | 168 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 default: | 238 default: |
| 245 NOTREACHED(); | 239 NOTREACHED(); |
| 246 } | 240 } |
| 247 painted_ = true; | 241 painted_ = true; |
| 248 } | 242 } |
| 249 View::OnPaint(canvas); | 243 View::OnPaint(canvas); |
| 250 } | 244 } |
| 251 | 245 |
| 252 views::Label* SadTabView::CreateLabel(const string16& text) { | 246 views::Label* SadTabView::CreateLabel(const string16& text) { |
| 253 views::Label* label = new views::Label(text); | 247 views::Label* label = new views::Label(text); |
| 254 label->SetFont(base_font_.DeriveFont(kMessageFontSizeDelta)); | |
| 255 label->SetBackgroundColor(background()->get_color()); | 248 label->SetBackgroundColor(background()->get_color()); |
| 256 label->SetEnabledColor(kTextColor); | 249 label->SetEnabledColor(kTextColor); |
| 257 return label; | 250 return label; |
| 258 } | 251 } |
| 259 | 252 |
| 260 views::Link* SadTabView::CreateLink(const string16& text) { | 253 views::Link* SadTabView::CreateLink(const string16& text) { |
| 261 views::Link* link = new views::Link(text); | 254 views::Link* link = new views::Link(text); |
| 262 link->SetFont(base_font_.DeriveFont(kMessageFontSizeDelta)); | |
| 263 link->SetBackgroundColor(background()->get_color()); | 255 link->SetBackgroundColor(background()->get_color()); |
| 264 link->SetEnabledColor(kTextColor); | 256 link->SetEnabledColor(kTextColor); |
| 265 link->set_listener(this); | 257 link->set_listener(this); |
| 266 return link; | 258 return link; |
| 267 } | 259 } |
| OLD | NEW |