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/metrics/user_metrics.h" |
7 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
9 #include "chrome/browser/lifetime/application_lifetime.h" | 10 #include "chrome/browser/lifetime/application_lifetime.h" |
10 #include "chrome/browser/upgrade_detector.h" | 11 #include "chrome/browser/upgrade_detector.h" |
11 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
12 #include "chrome/grit/chromium_strings.h" | 13 #include "chrome/grit/chromium_strings.h" |
13 #include "chrome/grit/generated_resources.h" | 14 #include "chrome/grit/generated_resources.h" |
14 #include "chrome/grit/locale_settings.h" | 15 #include "chrome/grit/locale_settings.h" |
15 #include "chrome/grit/theme_resources.h" | 16 #include "chrome/grit/theme_resources.h" |
16 #include "components/prefs/pref_service.h" | 17 #include "components/prefs/pref_service.h" |
17 #include "content/public/browser/user_metrics.h" | |
18 #include "ui/accessibility/ax_node_data.h" | 18 #include "ui/accessibility/ax_node_data.h" |
19 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
20 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
21 #include "ui/views/bubble/bubble_frame_view.h" | 21 #include "ui/views/bubble/bubble_frame_view.h" |
22 #include "ui/views/controls/label.h" | 22 #include "ui/views/controls/label.h" |
23 #include "ui/views/layout/fill_layout.h" | 23 #include "ui/views/layout/fill_layout.h" |
24 #include "ui/views/widget/widget.h" | 24 #include "ui/views/widget/widget.h" |
25 | 25 |
26 using base::UserMetricsAction; | 26 using base::UserMetricsAction; |
27 | 27 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 // The user has already interacted with the bubble and chosen a path. | 60 // The user has already interacted with the bubble and chosen a path. |
61 GetWidget()->Close(); | 61 GetWidget()->Close(); |
62 return; | 62 return; |
63 } | 63 } |
64 | 64 |
65 int seconds = GetRemainingTime(); | 65 int seconds = GetRemainingTime(); |
66 if (seconds <= 0) { | 66 if (seconds <= 0) { |
67 // Time's up! | 67 // Time's up! |
68 upgrade_detector->acknowledge_critical_update(); | 68 upgrade_detector->acknowledge_critical_update(); |
69 | 69 |
70 content::RecordAction( | 70 base::RecordAction(UserMetricsAction("CriticalNotification_AutoRestart")); |
71 UserMetricsAction("CriticalNotification_AutoRestart")); | |
72 refresh_timer_.Stop(); | 71 refresh_timer_.Stop(); |
73 chrome::AttemptRestart(); | 72 chrome::AttemptRestart(); |
74 } | 73 } |
75 | 74 |
76 // Update the counter. It may seem counter-intuitive to update the message | 75 // Update the counter. It may seem counter-intuitive to update the message |
77 // after we attempt restart, but remember that shutdown may be aborted by | 76 // after we attempt restart, but remember that shutdown may be aborted by |
78 // an onbeforeunload handler, leaving the bubble up when the browser should | 77 // an onbeforeunload handler, leaving the bubble up when the browser should |
79 // have restarted (giving the user another chance). | 78 // have restarted (giving the user another chance). |
80 GetBubbleFrameView()->UpdateWindowTitle(); | 79 GetBubbleFrameView()->UpdateWindowTitle(); |
81 } | 80 } |
82 | 81 |
83 base::string16 CriticalNotificationBubbleView::GetWindowTitle() const { | 82 base::string16 CriticalNotificationBubbleView::GetWindowTitle() const { |
84 int seconds = GetRemainingTime(); | 83 int seconds = GetRemainingTime(); |
85 return seconds > 0 ? l10n_util::GetPluralStringFUTF16( | 84 return seconds > 0 ? l10n_util::GetPluralStringFUTF16( |
86 IDS_CRITICAL_NOTIFICATION_HEADLINE, seconds) | 85 IDS_CRITICAL_NOTIFICATION_HEADLINE, seconds) |
87 : l10n_util::GetStringUTF16( | 86 : l10n_util::GetStringUTF16( |
88 IDS_CRITICAL_NOTIFICATION_HEADLINE_ALTERNATE); | 87 IDS_CRITICAL_NOTIFICATION_HEADLINE_ALTERNATE); |
89 } | 88 } |
90 | 89 |
91 void CriticalNotificationBubbleView::WindowClosing() { | 90 void CriticalNotificationBubbleView::WindowClosing() { |
92 refresh_timer_.Stop(); | 91 refresh_timer_.Stop(); |
93 } | 92 } |
94 | 93 |
95 bool CriticalNotificationBubbleView::Cancel() { | 94 bool CriticalNotificationBubbleView::Cancel() { |
96 UpgradeDetector::GetInstance()->acknowledge_critical_update(); | 95 UpgradeDetector::GetInstance()->acknowledge_critical_update(); |
97 content::RecordAction(UserMetricsAction("CriticalNotification_Ignore")); | 96 base::RecordAction(UserMetricsAction("CriticalNotification_Ignore")); |
98 // If the counter reaches 0, we set a restart flag that must be cleared if | 97 // If the counter reaches 0, we set a restart flag that must be cleared if |
99 // the user selects, for example, "Stay on this page" during an | 98 // the user selects, for example, "Stay on this page" during an |
100 // onbeforeunload handler. | 99 // onbeforeunload handler. |
101 PrefService* prefs = g_browser_process->local_state(); | 100 PrefService* prefs = g_browser_process->local_state(); |
102 if (prefs->HasPrefPath(prefs::kRestartLastSessionOnShutdown)) | 101 if (prefs->HasPrefPath(prefs::kRestartLastSessionOnShutdown)) |
103 prefs->ClearPref(prefs::kRestartLastSessionOnShutdown); | 102 prefs->ClearPref(prefs::kRestartLastSessionOnShutdown); |
104 return true; | 103 return true; |
105 } | 104 } |
106 | 105 |
107 bool CriticalNotificationBubbleView::Accept() { | 106 bool CriticalNotificationBubbleView::Accept() { |
108 UpgradeDetector::GetInstance()->acknowledge_critical_update(); | 107 UpgradeDetector::GetInstance()->acknowledge_critical_update(); |
109 content::RecordAction(UserMetricsAction("CriticalNotification_Restart")); | 108 base::RecordAction(UserMetricsAction("CriticalNotification_Restart")); |
110 chrome::AttemptRestart(); | 109 chrome::AttemptRestart(); |
111 return true; | 110 return true; |
112 } | 111 } |
113 | 112 |
114 base::string16 CriticalNotificationBubbleView::GetDialogButtonLabel( | 113 base::string16 CriticalNotificationBubbleView::GetDialogButtonLabel( |
115 ui::DialogButton button) const { | 114 ui::DialogButton button) const { |
116 return l10n_util::GetStringUTF16(button == ui::DIALOG_BUTTON_CANCEL | 115 return l10n_util::GetStringUTF16(button == ui::DIALOG_BUTTON_CANCEL |
117 ? IDS_CRITICAL_NOTIFICATION_DISMISS | 116 ? IDS_CRITICAL_NOTIFICATION_DISMISS |
118 : IDS_CRITICAL_NOTIFICATION_RESTART); | 117 : IDS_CRITICAL_NOTIFICATION_RESTART); |
119 } | 118 } |
120 | 119 |
121 void CriticalNotificationBubbleView::Init() { | 120 void CriticalNotificationBubbleView::Init() { |
122 bubble_created_ = base::TimeTicks::Now(); | 121 bubble_created_ = base::TimeTicks::Now(); |
123 | 122 |
124 SetLayoutManager(new views::FillLayout()); | 123 SetLayoutManager(new views::FillLayout()); |
125 | 124 |
126 views::Label* message = new views::Label(); | 125 views::Label* message = new views::Label(); |
127 message->SetMultiLine(true); | 126 message->SetMultiLine(true); |
128 message->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 127 message->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
129 message->SetText(l10n_util::GetStringUTF16(IDS_CRITICAL_NOTIFICATION_TEXT)); | 128 message->SetText(l10n_util::GetStringUTF16(IDS_CRITICAL_NOTIFICATION_TEXT)); |
130 message->SizeToFit(views::Widget::GetLocalizedContentsWidth( | 129 message->SizeToFit(views::Widget::GetLocalizedContentsWidth( |
131 IDS_CRUCIAL_NOTIFICATION_BUBBLE_WIDTH_CHARS)); | 130 IDS_CRUCIAL_NOTIFICATION_BUBBLE_WIDTH_CHARS)); |
132 AddChildView(message); | 131 AddChildView(message); |
133 | 132 |
134 refresh_timer_.Start(FROM_HERE, | 133 refresh_timer_.Start(FROM_HERE, |
135 base::TimeDelta::FromMilliseconds(kRefreshBubbleEvery), | 134 base::TimeDelta::FromMilliseconds(kRefreshBubbleEvery), |
136 this, &CriticalNotificationBubbleView::OnCountdown); | 135 this, &CriticalNotificationBubbleView::OnCountdown); |
137 | 136 |
138 content::RecordAction(UserMetricsAction("CriticalNotificationShown")); | 137 base::RecordAction(UserMetricsAction("CriticalNotificationShown")); |
139 } | 138 } |
140 | 139 |
141 void CriticalNotificationBubbleView::GetAccessibleNodeData( | 140 void CriticalNotificationBubbleView::GetAccessibleNodeData( |
142 ui::AXNodeData* node_data) { | 141 ui::AXNodeData* node_data) { |
143 node_data->role = ui::AX_ROLE_ALERT; | 142 node_data->role = ui::AX_ROLE_ALERT; |
144 } | 143 } |
145 | 144 |
146 void CriticalNotificationBubbleView::ViewHierarchyChanged( | 145 void CriticalNotificationBubbleView::ViewHierarchyChanged( |
147 const ViewHierarchyChangedDetails& details) { | 146 const ViewHierarchyChangedDetails& details) { |
148 if (details.is_add && details.child == this) | 147 if (details.is_add && details.child == this) |
149 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); | 148 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); |
150 } | 149 } |
OLD | NEW |