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/critical_notification_bubble_view.h" | 5 #include "chrome/browser/ui/views/critical_notification_bubble_view.h" |
6 | 6 |
7 #include "base/strings/string_number_conversions.h" | |
8 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/lifetime/application_lifetime.h" | 9 #include "chrome/browser/lifetime/application_lifetime.h" |
11 #include "chrome/browser/upgrade_detector.h" | 10 #include "chrome/browser/upgrade_detector.h" |
12 #include "chrome/common/pref_names.h" | 11 #include "chrome/common/pref_names.h" |
13 #include "chrome/grit/chromium_strings.h" | 12 #include "chrome/grit/chromium_strings.h" |
14 #include "chrome/grit/generated_resources.h" | 13 #include "chrome/grit/generated_resources.h" |
15 #include "chrome/grit/locale_settings.h" | 14 #include "chrome/grit/locale_settings.h" |
16 #include "components/prefs/pref_service.h" | 15 #include "components/prefs/pref_service.h" |
17 #include "content/public/browser/user_metrics.h" | 16 #include "content/public/browser/user_metrics.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 | 75 |
77 // Update the counter. It may seem counter-intuitive to update the message | 76 // Update the counter. It may seem counter-intuitive to update the message |
78 // after we attempt restart, but remember that shutdown may be aborted by | 77 // after we attempt restart, but remember that shutdown may be aborted by |
79 // an onbeforeunload handler, leaving the bubble up when the browser should | 78 // an onbeforeunload handler, leaving the bubble up when the browser should |
80 // have restarted (giving the user another chance). | 79 // have restarted (giving the user another chance). |
81 GetBubbleFrameView()->UpdateWindowTitle(); | 80 GetBubbleFrameView()->UpdateWindowTitle(); |
82 } | 81 } |
83 | 82 |
84 base::string16 CriticalNotificationBubbleView::GetWindowTitle() const { | 83 base::string16 CriticalNotificationBubbleView::GetWindowTitle() const { |
85 int seconds = GetRemainingTime(); | 84 int seconds = GetRemainingTime(); |
86 return seconds > 0 ? l10n_util::GetStringFUTF16( | 85 return seconds > 0 ? l10n_util::GetPluralStringFUTF16( |
87 IDS_CRITICAL_NOTIFICATION_HEADLINE, | 86 IDS_CRITICAL_NOTIFICATION_HEADLINE, seconds) |
88 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME), | 87 : l10n_util::GetStringUTF16( |
89 base::IntToString16(seconds)) | 88 IDS_CRITICAL_NOTIFICATION_HEADLINE_ALTERNATE); |
90 : l10n_util::GetStringFUTF16( | |
91 IDS_CRITICAL_NOTIFICATION_HEADLINE_ALTERNATE, | |
92 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); | |
93 } | 89 } |
94 | 90 |
95 gfx::ImageSkia CriticalNotificationBubbleView::GetWindowIcon() { | 91 gfx::ImageSkia CriticalNotificationBubbleView::GetWindowIcon() { |
96 return *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 92 return *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
97 IDR_UPDATE_MENU_SEVERITY_HIGH); | 93 IDR_UPDATE_MENU_SEVERITY_HIGH); |
98 } | 94 } |
99 | 95 |
100 bool CriticalNotificationBubbleView::ShouldShowWindowIcon() const { | 96 bool CriticalNotificationBubbleView::ShouldShowWindowIcon() const { |
101 return true; | 97 return true; |
102 } | 98 } |
(...skipping 29 matching lines...) Expand all Loading... |
132 } | 128 } |
133 | 129 |
134 void CriticalNotificationBubbleView::Init() { | 130 void CriticalNotificationBubbleView::Init() { |
135 bubble_created_ = base::TimeTicks::Now(); | 131 bubble_created_ = base::TimeTicks::Now(); |
136 | 132 |
137 SetLayoutManager(new views::FillLayout()); | 133 SetLayoutManager(new views::FillLayout()); |
138 | 134 |
139 views::Label* message = new views::Label(); | 135 views::Label* message = new views::Label(); |
140 message->SetMultiLine(true); | 136 message->SetMultiLine(true); |
141 message->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 137 message->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
142 message->SetText(l10n_util::GetStringFUTF16(IDS_CRITICAL_NOTIFICATION_TEXT, | 138 message->SetText(l10n_util::GetStringUTF16(IDS_CRITICAL_NOTIFICATION_TEXT)); |
143 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); | |
144 message->SizeToFit(views::Widget::GetLocalizedContentsWidth( | 139 message->SizeToFit(views::Widget::GetLocalizedContentsWidth( |
145 IDS_CRUCIAL_NOTIFICATION_BUBBLE_WIDTH_CHARS)); | 140 IDS_CRUCIAL_NOTIFICATION_BUBBLE_WIDTH_CHARS)); |
146 AddChildView(message); | 141 AddChildView(message); |
147 | 142 |
148 refresh_timer_.Start(FROM_HERE, | 143 refresh_timer_.Start(FROM_HERE, |
149 base::TimeDelta::FromMilliseconds(kRefreshBubbleEvery), | 144 base::TimeDelta::FromMilliseconds(kRefreshBubbleEvery), |
150 this, &CriticalNotificationBubbleView::OnCountdown); | 145 this, &CriticalNotificationBubbleView::OnCountdown); |
151 | 146 |
152 content::RecordAction(UserMetricsAction("CriticalNotificationShown")); | 147 content::RecordAction(UserMetricsAction("CriticalNotificationShown")); |
153 } | 148 } |
154 | 149 |
155 void CriticalNotificationBubbleView::GetAccessibleState( | 150 void CriticalNotificationBubbleView::GetAccessibleState( |
156 ui::AXViewState* state) { | 151 ui::AXViewState* state) { |
157 state->role = ui::AX_ROLE_ALERT; | 152 state->role = ui::AX_ROLE_ALERT; |
158 } | 153 } |
159 | 154 |
160 void CriticalNotificationBubbleView::ViewHierarchyChanged( | 155 void CriticalNotificationBubbleView::ViewHierarchyChanged( |
161 const ViewHierarchyChangedDetails& details) { | 156 const ViewHierarchyChangedDetails& details) { |
162 if (details.is_add && details.child == this) | 157 if (details.is_add && details.child == this) |
163 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); | 158 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); |
164 } | 159 } |
OLD | NEW |