| 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 #import "chrome/browser/ui/cocoa/external_protocol_dialog.h" | 5 #import "chrome/browser/ui/cocoa/external_protocol_dialog.h" |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
| 9 #include "base/metrics/sparse_histogram.h" |
| 9 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 11 #include "chrome/browser/external_protocol/external_protocol_handler.h" | 12 #include "chrome/browser/external_protocol/external_protocol_handler.h" |
| 12 #include "chrome/browser/shell_integration.h" | 13 #include "chrome/browser/shell_integration.h" |
| 13 #include "chrome/grit/chromium_strings.h" | 14 #include "chrome/grit/chromium_strings.h" |
| 14 #include "chrome/grit/generated_resources.h" | 15 #include "chrome/grit/generated_resources.h" |
| 15 #include "ui/base/l10n/l10n_util_mac.h" | 16 #include "ui/base/l10n/l10n_util_mac.h" |
| 16 #include "ui/gfx/text_elider.h" | 17 #include "ui/gfx/text_elider.h" |
| 17 | 18 |
| 18 /////////////////////////////////////////////////////////////////////////////// | 19 /////////////////////////////////////////////////////////////////////////////// |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 shell_integration::GetApplicationNameForProtocol(url_); | 55 shell_integration::GetApplicationNameForProtocol(url_); |
| 55 if (appName.length() == 0) { | 56 if (appName.length() == 0) { |
| 56 // No registered apps for this protocol; give up and go home. | 57 // No registered apps for this protocol; give up and go home. |
| 57 [self autorelease]; | 58 [self autorelease]; |
| 58 return nil; | 59 return nil; |
| 59 } | 60 } |
| 60 | 61 |
| 61 alert_ = [[NSAlert alloc] init]; | 62 alert_ = [[NSAlert alloc] init]; |
| 62 | 63 |
| 63 [alert_ setMessageText: | 64 [alert_ setMessageText: |
| 64 l10n_util::GetNSStringWithFixup(IDS_EXTERNAL_PROTOCOL_TITLE)]; | 65 l10n_util::GetNSStringFWithFixup(IDS_EXTERNAL_PROTOCOL_TITLE, appName)]; |
| 65 | 66 |
| 66 NSButton* allowButton = [alert_ addButtonWithTitle: | 67 NSButton* allowButton = [alert_ |
| 67 l10n_util::GetNSStringWithFixup(IDS_EXTERNAL_PROTOCOL_OK_BUTTON_TEXT)]; | 68 addButtonWithTitle:l10n_util::GetNSStringFWithFixup( |
| 69 IDS_EXTERNAL_PROTOCOL_OK_BUTTON_TEXT, appName)]; |
| 68 [allowButton setKeyEquivalent:@""]; // disallow as default | 70 [allowButton setKeyEquivalent:@""]; // disallow as default |
| 69 [alert_ addButtonWithTitle: | 71 [alert_ addButtonWithTitle: |
| 70 l10n_util::GetNSStringWithFixup( | 72 l10n_util::GetNSStringWithFixup( |
| 71 IDS_EXTERNAL_PROTOCOL_CANCEL_BUTTON_TEXT)]; | 73 IDS_EXTERNAL_PROTOCOL_CANCEL_BUTTON_TEXT)]; |
| 72 | 74 |
| 73 const size_t kMaxUrlWithoutSchemeSize = 256; | |
| 74 base::string16 elided_url_without_scheme; | |
| 75 gfx::ElideString(base::ASCIIToUTF16(url_.possibly_invalid_spec()), | |
| 76 kMaxUrlWithoutSchemeSize, &elided_url_without_scheme); | |
| 77 | |
| 78 NSString* urlString = l10n_util::GetNSStringFWithFixup( | |
| 79 IDS_EXTERNAL_PROTOCOL_INFORMATION, | |
| 80 base::ASCIIToUTF16(url_.scheme() + ":"), | |
| 81 elided_url_without_scheme); | |
| 82 NSString* appString = l10n_util::GetNSStringFWithFixup( | |
| 83 IDS_EXTERNAL_PROTOCOL_APPLICATION_TO_LAUNCH, | |
| 84 appName); | |
| 85 NSString* warningString = | |
| 86 l10n_util::GetNSStringWithFixup(IDS_EXTERNAL_PROTOCOL_WARNING); | |
| 87 NSString* informativeText = | |
| 88 [NSString stringWithFormat:@"%@\n\n%@\n\n%@", | |
| 89 urlString, | |
| 90 appString, | |
| 91 warningString]; | |
| 92 | |
| 93 [alert_ setInformativeText:informativeText]; | |
| 94 | |
| 95 [alert_ setShowsSuppressionButton:YES]; | 75 [alert_ setShowsSuppressionButton:YES]; |
| 96 [[alert_ suppressionButton] setTitle: | 76 [[alert_ suppressionButton] |
| 97 l10n_util::GetNSStringWithFixup(IDS_EXTERNAL_PROTOCOL_CHECKBOX_TEXT)]; | 77 setTitle:l10n_util::GetNSStringFWithFixup( |
| 78 IDS_EXTERNAL_PROTOCOL_CHECKBOX_TEXT, appName)]; |
| 98 | 79 |
| 99 [alert_ beginSheetModalForWindow:nil // nil here makes it app-modal | 80 [alert_ beginSheetModalForWindow:nil // nil here makes it app-modal |
| 100 modalDelegate:self | 81 modalDelegate:self |
| 101 didEndSelector:@selector(alertEnded:returnCode:contextInfo:) | 82 didEndSelector:@selector(alertEnded:returnCode:contextInfo:) |
| 102 contextInfo:nil]; | 83 contextInfo:nil]; |
| 103 | 84 |
| 104 return self; | 85 return self; |
| 105 } | 86 } |
| 106 | 87 |
| 107 - (void)dealloc { | 88 - (void)dealloc { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 120 blockState = ExternalProtocolHandler::DONT_BLOCK; | 101 blockState = ExternalProtocolHandler::DONT_BLOCK; |
| 121 break; | 102 break; |
| 122 case NSAlertSecondButtonReturn: | 103 case NSAlertSecondButtonReturn: |
| 123 blockState = ExternalProtocolHandler::BLOCK; | 104 blockState = ExternalProtocolHandler::BLOCK; |
| 124 break; | 105 break; |
| 125 default: | 106 default: |
| 126 NOTREACHED(); | 107 NOTREACHED(); |
| 127 } | 108 } |
| 128 | 109 |
| 129 // Set the "don't warn me again" info. | 110 // Set the "don't warn me again" info. |
| 130 if ([[alert_ suppressionButton] state] == NSOnState) | 111 if ([[alert_ suppressionButton] state] == NSOnState) { |
| 131 ExternalProtocolHandler::SetBlockState(url_.scheme(), blockState); | 112 ExternalProtocolHandler::SetBlockState(url_.scheme(), blockState); |
| 113 UMA_HISTOGRAM_SPARSE_SLOWLY( |
| 114 ExternalProtocolHandler::kRememberCheckedHistogram, 1); |
| 115 } else { |
| 116 UMA_HISTOGRAM_SPARSE_SLOWLY( |
| 117 ExternalProtocolHandler::kRememberCheckedHistogram, 0); |
| 118 } |
| 132 | 119 |
| 133 if (blockState == ExternalProtocolHandler::DONT_BLOCK) { | 120 if (blockState == ExternalProtocolHandler::DONT_BLOCK) { |
| 134 UMA_HISTOGRAM_LONG_TIMES("clickjacking.launch_url", | 121 UMA_HISTOGRAM_LONG_TIMES("clickjacking.launch_url", |
| 135 base::Time::Now() - creation_time_); | 122 base::Time::Now() - creation_time_); |
| 136 | 123 |
| 137 ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck( | 124 ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck( |
| 138 url_, render_process_host_id_, routing_id_); | 125 url_, render_process_host_id_, routing_id_); |
| 139 } | 126 } |
| 140 | 127 |
| 141 [self autorelease]; | 128 [self autorelease]; |
| 142 } | 129 } |
| 143 | 130 |
| 144 @end | 131 @end |
| OLD | NEW |