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_win.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 // TODO(mad): Should we only have the bubble show up on official Chrome build? |
| 20 const char kSRTDownloadURL[] = "https://www.google.com/chrome/srt/"; |
| 21 |
| 22 // Enum values for the SRTPrompt histogram. Don't change order, always add |
| 23 // to the end, before SRT_PROMPT_MAX, of course. |
| 24 enum SRTPromptHistogramValue { |
| 25 SRT_PROMPT_SHOWN = 0, |
| 26 SRT_PROMPT_ACCEPTED = 1, |
| 27 SRT_PROMPT_DENIED = 2, |
| 28 |
| 29 SRT_PROMPT_MAX, |
| 30 }; |
| 31 |
| 32 void RecordSRTPromptHistogram(SRTPromptHistogramValue value) { |
| 33 UMA_HISTOGRAM_ENUMERATION("SRTPrompt", value, SRT_PROMPT_MAX); |
| 34 } |
| 35 |
| 36 } // namespace |
| 37 |
| 38 // SRTGlobalError ------------------------------------------------------------ |
| 39 |
| 40 SRTGlobalError::SRTGlobalError(GlobalErrorService* global_error_service) |
| 41 : global_error_service_(global_error_service) { |
| 42 DCHECK(global_error_service_); |
| 43 } |
| 44 |
| 45 SRTGlobalError::~SRTGlobalError() { |
| 46 } |
| 47 |
| 48 bool SRTGlobalError::HasMenuItem() { |
| 49 return true; |
| 50 } |
| 51 |
| 52 int SRTGlobalError::MenuItemCommandID() { |
| 53 return IDC_SHOW_SRT_BUBBLE; |
| 54 } |
| 55 |
| 56 base::string16 SRTGlobalError::MenuItemLabel() { |
| 57 return l10n_util::GetStringUTF16(IDS_SRT_MENU_ITEM); |
| 58 } |
| 59 |
| 60 void SRTGlobalError::ExecuteMenuItem(Browser* browser) { |
| 61 // The menu item should never get executed while the bubble is shown, unless |
| 62 // we eventually change it to NOT close on deactivate. |
| 63 DCHECK(ShouldCloseOnDeactivate()); |
| 64 DCHECK(GetBubbleView() == NULL); |
| 65 ShowBubbleView(browser); |
| 66 } |
| 67 |
| 68 void SRTGlobalError::ShowBubbleView(Browser* browser) { |
| 69 RecordSRTPromptHistogram(SRT_PROMPT_SHOWN); |
| 70 GlobalErrorWithStandardBubble::ShowBubbleView(browser); |
| 71 } |
| 72 |
| 73 base::string16 SRTGlobalError::GetBubbleViewTitle() { |
| 74 return l10n_util::GetStringUTF16(IDS_SRT_BUBBLE_TITLE); |
| 75 } |
| 76 |
| 77 std::vector<base::string16> SRTGlobalError::GetBubbleViewMessages() { |
| 78 std::vector<base::string16> messages; |
| 79 messages.push_back(l10n_util::GetStringUTF16(IDS_SRT_BUBBLE_TEXT)); |
| 80 return messages; |
| 81 } |
| 82 |
| 83 base::string16 SRTGlobalError::GetBubbleViewAcceptButtonLabel() { |
| 84 return l10n_util::GetStringUTF16(IDS_SRT_BUBBLE_DOWNLOAD_BUTTON_TEXT); |
| 85 } |
| 86 |
| 87 base::string16 SRTGlobalError::GetBubbleViewCancelButtonLabel() { |
| 88 return l10n_util::GetStringUTF16(IDS_NO_THANKS); |
| 89 } |
| 90 |
| 91 void SRTGlobalError::OnBubbleViewDidClose(Browser* browser) { |
| 92 } |
| 93 |
| 94 void SRTGlobalError::BubbleViewAcceptButtonPressed(Browser* browser) { |
| 95 RecordSRTPromptHistogram(SRT_PROMPT_ACCEPTED); |
| 96 browser->OpenURL(content::OpenURLParams(GURL(kSRTDownloadURL), |
| 97 content::Referrer(), |
| 98 NEW_FOREGROUND_TAB, |
| 99 ui::PAGE_TRANSITION_LINK, |
| 100 false)); |
| 101 DismissGlobalError(); |
| 102 } |
| 103 |
| 104 void SRTGlobalError::BubbleViewCancelButtonPressed(Browser* browser) { |
| 105 RecordSRTPromptHistogram(SRT_PROMPT_DENIED); |
| 106 DismissGlobalError(); |
| 107 } |
| 108 |
| 109 void SRTGlobalError::DismissGlobalError() { |
| 110 global_error_service_->RemoveGlobalError(this); |
| 111 delete this; |
| 112 } |
OLD | NEW |