| 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.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "chrome/browser/external_protocol/external_protocol_handler.h" | 12 #include "chrome/browser/external_protocol/external_protocol_handler.h" |
| 13 #include "grit/chromium_strings.h" | 13 #include "grit/chromium_strings.h" |
| 14 #include "grit/generated_resources.h" | 14 #include "grit/generated_resources.h" |
| 15 #include "ui/base/l10n/l10n_util_mac.h" | 15 #include "ui/base/l10n/l10n_util_mac.h" |
| 16 #include "ui/gfx/text_elider.h" | 16 #include "ui/gfx/text_elider.h" |
| 17 | 17 |
| 18 /////////////////////////////////////////////////////////////////////////////// | 18 /////////////////////////////////////////////////////////////////////////////// |
| 19 // ExternalProtocolHandler | 19 // ExternalProtocolHandler |
| 20 | 20 |
| 21 // static | 21 // static |
| 22 void ExternalProtocolHandler::RunExternalProtocolDialog( | 22 void ExternalProtocolHandler::RunExternalProtocolDialog( |
| 23 const GURL& url, int render_process_host_id, int routing_id) { | 23 const GURL& url, int render_process_host_id, int routing_id) { |
| 24 [[ExternalProtocolDialogController alloc] initWithGURL:&url]; | 24 [[ExternalProtocolDialogController alloc] initWithGURL:&url |
| 25 renderProcessHostId:render_process_host_id |
| 26 routingId:routing_id]; |
| 25 } | 27 } |
| 26 | 28 |
| 27 /////////////////////////////////////////////////////////////////////////////// | 29 /////////////////////////////////////////////////////////////////////////////// |
| 28 // ExternalProtocolDialogController | 30 // ExternalProtocolDialogController |
| 29 | 31 |
| 30 @interface ExternalProtocolDialogController(Private) | 32 @interface ExternalProtocolDialogController(Private) |
| 31 - (void)alertEnded:(NSAlert *)alert | 33 - (void)alertEnded:(NSAlert *)alert |
| 32 returnCode:(int)returnCode | 34 returnCode:(int)returnCode |
| 33 contextInfo:(void*)contextInfo; | 35 contextInfo:(void*)contextInfo; |
| 34 - (string16)appNameForProtocol; | 36 - (string16)appNameForProtocol; |
| 35 @end | 37 @end |
| 36 | 38 |
| 37 @implementation ExternalProtocolDialogController | 39 @implementation ExternalProtocolDialogController |
| 38 - (id)initWithGURL:(const GURL*)url { | 40 - (id)initWithGURL:(const GURL*)url |
| 41 renderProcessHostId:(int)renderProcessHostId |
| 42 routingId:(int)routingId { |
| 39 DCHECK_EQ(base::MessageLoop::TYPE_UI, base::MessageLoop::current()->type()); | 43 DCHECK_EQ(base::MessageLoop::TYPE_UI, base::MessageLoop::current()->type()); |
| 40 | 44 |
| 41 if (!(self = [super init])) | 45 if (!(self = [super init])) |
| 42 return nil; | 46 return nil; |
| 43 | 47 |
| 44 url_ = *url; | 48 url_ = *url; |
| 49 render_process_host_id_ = renderProcessHostId; |
| 50 routing_id_ = routingId; |
| 45 creation_time_ = base::Time::Now(); | 51 creation_time_ = base::Time::Now(); |
| 46 | 52 |
| 47 base::string16 appName = [self appNameForProtocol]; | 53 base::string16 appName = [self appNameForProtocol]; |
| 48 if (appName.length() == 0) { | 54 if (appName.length() == 0) { |
| 49 // No registered apps for this protocol; give up and go home. | 55 // No registered apps for this protocol; give up and go home. |
| 50 [self autorelease]; | 56 [self autorelease]; |
| 51 return nil; | 57 return nil; |
| 52 } | 58 } |
| 53 | 59 |
| 54 alert_ = [[NSAlert alloc] init]; | 60 alert_ = [[NSAlert alloc] init]; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 } | 126 } |
| 121 | 127 |
| 122 // Set the "don't warn me again" info. | 128 // Set the "don't warn me again" info. |
| 123 if ([[alert_ suppressionButton] state] == NSOnState) | 129 if ([[alert_ suppressionButton] state] == NSOnState) |
| 124 ExternalProtocolHandler::SetBlockState(url_.scheme(), blockState); | 130 ExternalProtocolHandler::SetBlockState(url_.scheme(), blockState); |
| 125 | 131 |
| 126 if (blockState == ExternalProtocolHandler::DONT_BLOCK) { | 132 if (blockState == ExternalProtocolHandler::DONT_BLOCK) { |
| 127 UMA_HISTOGRAM_LONG_TIMES("clickjacking.launch_url", | 133 UMA_HISTOGRAM_LONG_TIMES("clickjacking.launch_url", |
| 128 base::Time::Now() - creation_time_); | 134 base::Time::Now() - creation_time_); |
| 129 | 135 |
| 130 ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(url_); | 136 ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck( |
| 137 url_, render_process_host_id_, routing_id_); |
| 131 } | 138 } |
| 132 | 139 |
| 133 [self autorelease]; | 140 [self autorelease]; |
| 134 } | 141 } |
| 135 | 142 |
| 136 - (string16)appNameForProtocol { | 143 - (string16)appNameForProtocol { |
| 137 NSURL* url = [NSURL URLWithString: | 144 NSURL* url = [NSURL URLWithString: |
| 138 base::SysUTF8ToNSString(url_.possibly_invalid_spec())]; | 145 base::SysUTF8ToNSString(url_.possibly_invalid_spec())]; |
| 139 CFURLRef openingApp = NULL; | 146 CFURLRef openingApp = NULL; |
| 140 OSStatus status = LSGetApplicationForURL((CFURLRef)url, | 147 OSStatus status = LSGetApplicationForURL((CFURLRef)url, |
| 141 kLSRolesAll, | 148 kLSRolesAll, |
| 142 NULL, | 149 NULL, |
| 143 &openingApp); | 150 &openingApp); |
| 144 if (status != noErr) { | 151 if (status != noErr) { |
| 145 // likely kLSApplicationNotFoundErr | 152 // likely kLSApplicationNotFoundErr |
| 146 return base::string16(); | 153 return base::string16(); |
| 147 } | 154 } |
| 148 NSString* appPath = [(NSURL*)openingApp path]; | 155 NSString* appPath = [(NSURL*)openingApp path]; |
| 149 CFRelease(openingApp); // NOT A BUG; LSGetApplicationForURL retains for us | 156 CFRelease(openingApp); // NOT A BUG; LSGetApplicationForURL retains for us |
| 150 NSString* appDisplayName = | 157 NSString* appDisplayName = |
| 151 [[NSFileManager defaultManager] displayNameAtPath:appPath]; | 158 [[NSFileManager defaultManager] displayNameAtPath:appPath]; |
| 152 | 159 |
| 153 return base::SysNSStringToUTF16(appDisplayName); | 160 return base::SysNSStringToUTF16(appDisplayName); |
| 154 } | 161 } |
| 155 | 162 |
| 156 @end | 163 @end |
| OLD | NEW |