OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/safe_browsing/srt_global_error.h" | |
6 | |
7 #include "base/callback.h" | |
8 #include "base/metrics/histogram.h" | |
9 #include "chrome/app/chrome_command_ids.h" | |
10 #include "chrome/browser/ui/browser.h" | |
11 #include "chrome/browser/ui/global_error/global_error_service.h" | |
12 #include "grit/chromium_strings.h" | |
13 #include "grit/generated_resources.h" | |
14 #include "grit/google_chrome_strings.h" | |
15 #include "ui/base/l10n/l10n_util.h" | |
16 | |
17 namespace { | |
18 // The download link of the Software Removal Tool. | |
19 const char kSRTDownloadURL[] = "https://www.google.com/chrome/srt/"; | |
robertshield
2014/09/24 13:02:12
should some of this file be #if defined(GOOGLE_CHR
MAD
2014/09/24 20:40:35
Hum, but then, which value do we put here? Actuall
| |
20 | |
21 // Enum values for the SRTPrompt histogram. Don't change order, always add | |
22 // to the end, and adjust SRT_PROMPT_MAX. | |
23 enum SRTPromptHistogramValue { | |
24 SRT_PROMPT_SHOWN = 0, | |
25 SRT_PROMPT_ACCEPTED = 1, | |
26 SRT_PROMPT_DENIED = 2, | |
27 SRT_PROMPT_MAX = 3, | |
gab
2014/09/24 16:22:37
Do not explicitly label SRT_PROMPT_MAX (let it be
MAD
2014/09/24 20:40:35
Done.
| |
28 }; | |
29 | |
30 void RecordSRTPromptHistogram(SRTPromptHistogramValue value) { | |
31 UMA_HISTOGRAM_ENUMERATION("SRTPrompt", value, SRT_PROMPT_MAX); | |
32 } | |
33 | |
34 } // namespace | |
35 | |
36 // SRTGlobalError ------------------------------------------------------------ | |
37 | |
38 SRTGlobalError::SRTGlobalError(GlobalErrorService* global_error_service) | |
39 : global_error_service_(global_error_service) { | |
40 DCHECK(global_error_service_); | |
41 } | |
42 | |
43 SRTGlobalError::~SRTGlobalError() { | |
44 } | |
45 | |
46 // static | |
47 bool SRTGlobalError::IsSupportedOnPlatform() { | |
gab
2014/09/24 16:22:37
Are there any callers of this method? Shouldn't th
MAD
2014/09/24 20:40:36
Good point, this was a leftover from the profile r
| |
48 // The Software Removal Tool only runs on windows. | |
49 #if defined(OS_WIN) | |
50 return true; | |
51 #else | |
52 return false; | |
53 #endif | |
54 } | |
55 | |
56 bool SRTGlobalError::HasMenuItem() { | |
57 return true; | |
58 } | |
59 | |
60 int SRTGlobalError::MenuItemCommandID() { | |
61 return IDC_SHOW_SRT_BUBBLE; | |
62 } | |
63 | |
64 base::string16 SRTGlobalError::MenuItemLabel() { | |
65 return l10n_util::GetStringUTF16(IDS_SRT_MENU_ITEM); | |
66 } | |
67 | |
68 void SRTGlobalError::ExecuteMenuItem(Browser* browser) { | |
69 ShowBubbleView(browser); | |
engedy
2014/09/24 13:37:15
Showing more than one instance of the bubble is un
MAD
2014/09/24 20:40:36
Since the bubble is closed when it loses focus, th
| |
70 } | |
71 | |
72 void SRTGlobalError::ShowBubbleView(Browser* browser) { | |
73 RecordSRTPromptHistogram(SRT_PROMPT_SHOWN); | |
74 GlobalErrorWithStandardBubble::ShowBubbleView(browser); | |
75 } | |
76 | |
77 base::string16 SRTGlobalError::GetBubbleViewTitle() { | |
78 return l10n_util::GetStringUTF16(IDS_SRT_BUBBLE_TITLE); | |
79 } | |
80 | |
81 std::vector<base::string16> SRTGlobalError::GetBubbleViewMessages() { | |
82 std::vector<base::string16> messages; | |
83 messages.push_back(l10n_util::GetStringUTF16(IDS_SRT_BUBBLE_TEXT)); | |
84 return messages; | |
85 } | |
86 | |
87 base::string16 SRTGlobalError::GetBubbleViewAcceptButtonLabel() { | |
88 return l10n_util::GetStringUTF16(IDS_SRT_BUBBLE_DOWNLOAD_BUTTON_TEXT); | |
89 } | |
90 | |
91 base::string16 SRTGlobalError::GetBubbleViewCancelButtonLabel() { | |
92 return l10n_util::GetStringUTF16(IDS_NO_THANKS); | |
93 } | |
94 | |
95 void SRTGlobalError::OnBubbleViewDidClose(Browser* browser) { | |
96 } | |
97 | |
98 void SRTGlobalError::BubbleViewAcceptButtonPressed(Browser* browser) { | |
99 RecordSRTPromptHistogram(SRT_PROMPT_ACCEPTED); | |
100 browser->OpenURL(content::OpenURLParams(GURL(kSRTDownloadURL), | |
101 content::Referrer(), | |
102 NEW_FOREGROUND_TAB, | |
103 ui::PAGE_TRANSITION_LINK, | |
104 false)); | |
105 DismissGlobalError(); | |
106 } | |
107 | |
108 void SRTGlobalError::BubbleViewCancelButtonPressed(Browser* browser) { | |
109 RecordSRTPromptHistogram(SRT_PROMPT_DENIED); | |
110 DismissGlobalError(); | |
111 } | |
112 | |
113 void SRTGlobalError::DismissGlobalError() { | |
114 global_error_service_->RemoveGlobalError(this); | |
115 | |
116 // Even though OnBubbleViewDidClose will be called asynchronously when the | |
117 // bubble actually gets closed by RemoveGlobalError, we can safely suicide | |
robertshield
2014/09/24 13:02:12
totally ignorable grammar nit: s/suicide/commit su
MAD
2014/09/24 20:40:35
Done.
| |
118 // here since the bubble holds on a weak pointer of the global error. This | |
119 // way, if the destruction of the bubble UI ever gets changed to be | |
120 // synchronous, we'll still be OK. | |
gab
2014/09/24 16:22:36
This comment should not be necessary. All your cod
MAD
2014/09/24 20:40:35
Actually, this comment was added to explain the st
| |
121 delete this; | |
122 } | |
OLD | NEW |