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/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "chrome/browser/external_protocol/external_protocol_handler.h" | 11 #include "chrome/browser/external_protocol/external_protocol_handler.h" |
12 #include "chrome/browser/shell_integration.h" | 12 #include "chrome/browser/shell_integration.h" |
13 #include "chrome/grit/chromium_strings.h" | 13 #include "chrome/grit/chromium_strings.h" |
14 #include "chrome/grit/generated_resources.h" | 14 #include "chrome/grit/generated_resources.h" |
| 15 #include "components/strings/grit/components_strings.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 /////////////////////////////////////////////////////////////////////////////// |
19 // ExternalProtocolHandler | 20 // ExternalProtocolHandler |
20 | 21 |
21 // static | 22 // static |
22 void ExternalProtocolHandler::RunExternalProtocolDialog( | 23 void ExternalProtocolHandler::RunExternalProtocolDialog( |
23 const GURL& url, int render_process_host_id, int routing_id, | 24 const GURL& url, int render_process_host_id, int routing_id, |
24 ui::PageTransition page_transition, bool has_user_gesture) { | 25 ui::PageTransition page_transition, bool has_user_gesture) { |
(...skipping 29 matching lines...) Expand all 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:l10n_util::GetNSStringWithFixup(IDS_CANCEL)]; |
70 l10n_util::GetNSStringWithFixup( | |
71 IDS_EXTERNAL_PROTOCOL_CANCEL_BUTTON_TEXT)]; | |
72 | |
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 | 72 |
95 [alert_ setShowsSuppressionButton:YES]; | 73 [alert_ setShowsSuppressionButton:YES]; |
96 [[alert_ suppressionButton] setTitle: | 74 [[alert_ suppressionButton] |
97 l10n_util::GetNSStringWithFixup(IDS_EXTERNAL_PROTOCOL_CHECKBOX_TEXT)]; | 75 setTitle:l10n_util::GetNSStringFWithFixup( |
| 76 IDS_EXTERNAL_PROTOCOL_CHECKBOX_TEXT, appName)]; |
98 | 77 |
99 [alert_ beginSheetModalForWindow:nil // nil here makes it app-modal | 78 [alert_ beginSheetModalForWindow:nil // nil here makes it app-modal |
100 modalDelegate:self | 79 modalDelegate:self |
101 didEndSelector:@selector(alertEnded:returnCode:contextInfo:) | 80 didEndSelector:@selector(alertEnded:returnCode:contextInfo:) |
102 contextInfo:nil]; | 81 contextInfo:nil]; |
103 | 82 |
104 return self; | 83 return self; |
105 } | 84 } |
106 | 85 |
107 - (void)dealloc { | 86 - (void)dealloc { |
(...skipping 12 matching lines...) Expand all Loading... |
120 blockState = ExternalProtocolHandler::DONT_BLOCK; | 99 blockState = ExternalProtocolHandler::DONT_BLOCK; |
121 break; | 100 break; |
122 case NSAlertSecondButtonReturn: | 101 case NSAlertSecondButtonReturn: |
123 blockState = ExternalProtocolHandler::BLOCK; | 102 blockState = ExternalProtocolHandler::BLOCK; |
124 break; | 103 break; |
125 default: | 104 default: |
126 NOTREACHED(); | 105 NOTREACHED(); |
127 } | 106 } |
128 | 107 |
129 // Set the "don't warn me again" info. | 108 // Set the "don't warn me again" info. |
130 if ([[alert_ suppressionButton] state] == NSOnState) | 109 if ([[alert_ suppressionButton] state] == NSOnState) { |
131 ExternalProtocolHandler::SetBlockState(url_.scheme(), blockState); | 110 ExternalProtocolHandler::SetBlockState(url_.scheme(), blockState); |
| 111 ExternalProtocolHandler::RecordMetrics(true); |
| 112 } else { |
| 113 ExternalProtocolHandler::RecordMetrics(false); |
| 114 } |
132 | 115 |
133 if (blockState == ExternalProtocolHandler::DONT_BLOCK) { | 116 if (blockState == ExternalProtocolHandler::DONT_BLOCK) { |
134 UMA_HISTOGRAM_LONG_TIMES("clickjacking.launch_url", | 117 UMA_HISTOGRAM_LONG_TIMES("clickjacking.launch_url", |
135 base::Time::Now() - creation_time_); | 118 base::Time::Now() - creation_time_); |
136 | 119 |
137 ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck( | 120 ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck( |
138 url_, render_process_host_id_, routing_id_); | 121 url_, render_process_host_id_, routing_id_); |
139 } | 122 } |
140 | 123 |
141 [self autorelease]; | 124 [self autorelease]; |
142 } | 125 } |
143 | 126 |
144 @end | 127 @end |
OLD | NEW |