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( 34 "SoftwareReporter.PromptUsage", value, SRT_PROMPT_MAX); 35 } 36 37 } // namespace 38 39 // SRTGlobalError ------------------------------------------------------------ 40 41 SRTGlobalError::SRTGlobalError(GlobalErrorService* global_error_service) 42 : global_error_service_(global_error_service) { 43 DCHECK(global_error_service_); 44 } 45 46 SRTGlobalError::~SRTGlobalError() { 47 } 48 49 bool SRTGlobalError::HasMenuItem() { 50 return true; 51 } 52 53 int SRTGlobalError::MenuItemCommandID() { 54 return IDC_SHOW_SRT_BUBBLE; 55 } 56 57 base::string16 SRTGlobalError::MenuItemLabel() { 58 return l10n_util::GetStringUTF16(IDS_SRT_MENU_ITEM); 59 } 60 61 void SRTGlobalError::ExecuteMenuItem(Browser* browser) { 62 // The menu item should never get executed while the bubble is shown, unless 63 // we eventually change it to NOT close on deactivate. 64 DCHECK(ShouldCloseOnDeactivate()); 65 DCHECK(GetBubbleView() == NULL); 66 ShowBubbleView(browser); 67 } 68 69 void SRTGlobalError::ShowBubbleView(Browser* browser) { 70 RecordSRTPromptHistogram(SRT_PROMPT_SHOWN); 71 GlobalErrorWithStandardBubble::ShowBubbleView(browser); 72 } 73 74 base::string16 SRTGlobalError::GetBubbleViewTitle() { 75 return l10n_util::GetStringUTF16(IDS_SRT_BUBBLE_TITLE); 76 } 77 78 std::vector<base::string16> SRTGlobalError::GetBubbleViewMessages() { 79 std::vector<base::string16> messages; 80 messages.push_back(l10n_util::GetStringUTF16(IDS_SRT_BUBBLE_TEXT)); 81 return messages; 82 } 83 84 base::string16 SRTGlobalError::GetBubbleViewAcceptButtonLabel() { 85 return l10n_util::GetStringUTF16(IDS_SRT_BUBBLE_DOWNLOAD_BUTTON_TEXT); 86 } 87 88 base::string16 SRTGlobalError::GetBubbleViewCancelButtonLabel() { 89 return l10n_util::GetStringUTF16(IDS_NO_THANKS); 90 } 91 92 void SRTGlobalError::OnBubbleViewDidClose(Browser* browser) { 93 } 94 95 void SRTGlobalError::BubbleViewAcceptButtonPressed(Browser* browser) { 96 RecordSRTPromptHistogram(SRT_PROMPT_ACCEPTED); 97 browser->OpenURL(content::OpenURLParams(GURL(kSRTDownloadURL), 98 content::Referrer(), 99 NEW_FOREGROUND_TAB, 100 ui::PAGE_TRANSITION_LINK, 101 false)); 102 DismissGlobalError(); 103 } 104 105 void SRTGlobalError::BubbleViewCancelButtonPressed(Browser* browser) { 106 RecordSRTPromptHistogram(SRT_PROMPT_DENIED); 107 DismissGlobalError(); 108 } 109 110 bool SRTGlobalError::ShouldCloseOnDeactivate() const { 111 return false; 112 } 113 114 void SRTGlobalError::DismissGlobalError() { 115 global_error_service_->RemoveGlobalError(this); 116 delete this; 117 } 118