1 // Copyright (c) 2013 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/ui/external_protocol_dialog_delegate.h" 6 7 #include <string> 8 9 #include "base/strings/utf_string_conversions.h" 10 #include "base/threading/thread.h" 11 #include "base/threading/thread_restrictions.h" 12 #include "chrome/browser/external_protocol/external_protocol_handler.h" 13 #include "grit/chromium_strings.h" 14 #include "grit/generated_resources.h" 15 #include "ui/base/l10n/l10n_util.h" 16 #include "ui/gfx/text_elider.h" 17 18 ExternalProtocolDialogDelegate::ExternalProtocolDialogDelegate( 19 const GURL& url, 20 int render_process_host_id, 21 int tab_contents_id) 22 : ProtocolDialogDelegate(url), 23 render_process_host_id_(render_process_host_id), 24 tab_contents_id_(tab_contents_id) { 25 } 26 27 ExternalProtocolDialogDelegate::~ExternalProtocolDialogDelegate() { 28 } 29 30 base::string16 ExternalProtocolDialogDelegate::GetMessageText() const { 31 const int kMaxUrlWithoutSchemeSize = 256; 32 const int kMaxCommandSize = 256; 33 // TODO(calamity): Look up the command in ExternalProtocolHandler and pass it 34 // into the constructor. Will require simultaneous change of 35 // ExternalProtocolHandler::RunExternalProtocolDialog across all platforms. 36 base::string16 command = 37 UTF8ToUTF16(ShellIntegration::GetApplicationForProtocol(url())); 38 base::string16 elided_url_without_scheme; 39 base::string16 elided_command; 40 gfx::ElideString(ASCIIToUTF16(url().possibly_invalid_spec()), 41 kMaxUrlWithoutSchemeSize, &elided_url_without_scheme); 42 gfx::ElideString(command, kMaxCommandSize, &elided_command); 43 44 base::string16 message_text = l10n_util::GetStringFUTF16( 45 IDS_EXTERNAL_PROTOCOL_INFORMATION, 46 ASCIIToUTF16(url().scheme() + ":"), 47 elided_url_without_scheme) + ASCIIToUTF16("\n\n"); 48 49 message_text += l10n_util::GetStringFUTF16( 50 IDS_EXTERNAL_PROTOCOL_APPLICATION_TO_LAUNCH, 51 elided_command) + ASCIIToUTF16("\n\n"); 52 53 message_text += l10n_util::GetStringUTF16(IDS_EXTERNAL_PROTOCOL_WARNING); 54 return message_text; 55 } 56 57 base::string16 ExternalProtocolDialogDelegate::GetCheckboxText() const { 58 return l10n_util::GetStringUTF16(IDS_EXTERNAL_PROTOCOL_CHECKBOX_TEXT); 59 } 60 61 base::string16 ExternalProtocolDialogDelegate::GetTitleText() const { 62 return l10n_util::GetStringUTF16(IDS_EXTERNAL_PROTOCOL_TITLE); 63 } 64 65 void ExternalProtocolDialogDelegate::DoAccept( 66 const GURL& url, 67 bool dont_block) const { 68 if (dont_block) { 69 ExternalProtocolHandler::SetBlockState( 70 url.scheme(), ExternalProtocolHandler::DONT_BLOCK); 71 } 72 73 ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck( 74 url, render_process_host_id_, tab_contents_id_); 75 } 76 77 void ExternalProtocolDialogDelegate::DoCancel( 78 const GURL& url, 79 bool dont_block) const { 80 if (dont_block) { 81 ExternalProtocolHandler::SetBlockState( 82 url.scheme(), ExternalProtocolHandler::BLOCK); 83 } 84 } 85