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[] = "http://www.google.com/chrome/srt/"; | |
engedy
2014/09/24 10:14:45
We should explicitly use HTTPS here, as www.google
MAD
2014/09/24 11:12:33
Done.
| |
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, | |
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 } | |
41 | |
42 SRTGlobalError::~SRTGlobalError() { | |
43 } | |
44 | |
45 // static | |
46 bool SRTGlobalError::IsSupportedOnPlatform() { | |
47 // The Software Removal Tool only runs on windows. | |
48 #if defined(OS_WIN) | |
49 return true; | |
50 #else | |
51 return false; | |
52 #endif | |
53 } | |
54 | |
55 bool SRTGlobalError::HasMenuItem() { | |
56 return true; | |
57 } | |
58 | |
59 int SRTGlobalError::MenuItemCommandID() { | |
60 return IDC_SHOW_SRT_BUBBLE; | |
61 } | |
62 | |
63 base::string16 SRTGlobalError::MenuItemLabel() { | |
64 return l10n_util::GetStringUTF16(IDS_SRT_MENU_ITEM); | |
65 } | |
66 | |
67 void SRTGlobalError::ExecuteMenuItem(Browser* browser) { | |
68 ShowBubbleView(browser); | |
69 } | |
70 | |
71 void SRTGlobalError::ShowBubbleView(Browser* browser) { | |
72 RecordSRTPromptHistogram(SRT_PROMPT_SHOWN); | |
73 GlobalErrorWithStandardBubble::ShowBubbleView(browser); | |
74 } | |
75 | |
76 base::string16 SRTGlobalError::GetBubbleViewTitle() { | |
77 return l10n_util::GetStringUTF16(IDS_SRT_BUBBLE_TITLE); | |
78 } | |
79 | |
80 std::vector<base::string16> SRTGlobalError::GetBubbleViewMessages() { | |
81 std::vector<base::string16> messages; | |
82 messages.push_back(l10n_util::GetStringUTF16(IDS_SRT_BUBBLE_TEXT)); | |
83 return messages; | |
84 } | |
85 | |
86 base::string16 SRTGlobalError::GetBubbleViewAcceptButtonLabel() { | |
87 return l10n_util::GetStringUTF16(IDS_SRT_BUBBLE_DOWNLOAD_BUTTON_TEXT); | |
88 } | |
89 | |
90 base::string16 SRTGlobalError::GetBubbleViewCancelButtonLabel() { | |
91 return l10n_util::GetStringUTF16(IDS_NO_THANKS); | |
92 } | |
93 | |
94 void SRTGlobalError::OnBubbleViewDidClose(Browser* browser) { | |
95 // If the bubble closes and the error has been dismissed, it can be destroyed. | |
96 if (!global_error_service_) | |
97 delete this; | |
98 } | |
99 | |
100 void SRTGlobalError::BubbleViewAcceptButtonPressed(Browser* browser) { | |
101 RecordSRTPromptHistogram(SRT_PROMPT_ACCEPTED); | |
102 browser->OpenURL(content::OpenURLParams(GURL(kSRTDownloadURL), | |
103 content::Referrer(), | |
104 NEW_FOREGROUND_TAB, | |
105 ui::PAGE_TRANSITION_LINK, | |
106 false)); | |
107 DismissGlobalError(); | |
108 } | |
109 | |
110 void SRTGlobalError::BubbleViewCancelButtonPressed(Browser* browser) { | |
111 RecordSRTPromptHistogram(SRT_PROMPT_DENIED); | |
112 DismissGlobalError(); | |
113 } | |
114 | |
115 void SRTGlobalError::DismissGlobalError() { | |
116 if (global_error_service_) { | |
117 global_error_service_->RemoveGlobalError(this); | |
engedy
2014/09/24 10:14:45
I am unsure about the details of the GlobalErrorBu
MAD
2014/09/24 11:12:33
Actually, the call to Close the Widget is synchron
| |
118 global_error_service_ = NULL; | |
119 } | |
120 } | |
OLD | NEW |