Home | History | Annotate | Download | only in ui
      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       program_name_(ShellIntegration::GetApplicationNameForProtocol(url)) {
     26 }
     27 
     28 ExternalProtocolDialogDelegate::~ExternalProtocolDialogDelegate() {
     29 }
     30 
     31 base::string16 ExternalProtocolDialogDelegate::GetMessageText() const {
     32   const int kMaxUrlWithoutSchemeSize = 256;
     33   const int kMaxCommandSize = 256;
     34   base::string16 elided_url_without_scheme;
     35   base::string16 elided_command;
     36   gfx::ElideString(base::ASCIIToUTF16(url().possibly_invalid_spec()),
     37                   kMaxUrlWithoutSchemeSize, &elided_url_without_scheme);
     38   gfx::ElideString(program_name_, kMaxCommandSize, &elided_command);
     39 
     40   base::string16 message_text = l10n_util::GetStringFUTF16(
     41       IDS_EXTERNAL_PROTOCOL_INFORMATION,
     42       base::ASCIIToUTF16(url().scheme() + ":"),
     43       elided_url_without_scheme) + base::ASCIIToUTF16("\n\n");
     44 
     45   message_text += l10n_util::GetStringFUTF16(
     46       IDS_EXTERNAL_PROTOCOL_APPLICATION_TO_LAUNCH,
     47       elided_command) + base::ASCIIToUTF16("\n\n");
     48 
     49   message_text += l10n_util::GetStringUTF16(IDS_EXTERNAL_PROTOCOL_WARNING);
     50   return message_text;
     51 }
     52 
     53 base::string16 ExternalProtocolDialogDelegate::GetCheckboxText() const {
     54   return l10n_util::GetStringUTF16(IDS_EXTERNAL_PROTOCOL_CHECKBOX_TEXT);
     55 }
     56 
     57 base::string16 ExternalProtocolDialogDelegate::GetTitleText() const {
     58   return l10n_util::GetStringUTF16(IDS_EXTERNAL_PROTOCOL_TITLE);
     59 }
     60 
     61 void ExternalProtocolDialogDelegate::DoAccept(
     62     const GURL& url,
     63     bool dont_block) const {
     64   if (dont_block) {
     65       ExternalProtocolHandler::SetBlockState(
     66           url.scheme(), ExternalProtocolHandler::DONT_BLOCK);
     67   }
     68 
     69   ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(
     70       url, render_process_host_id_, tab_contents_id_);
     71 }
     72 
     73 void ExternalProtocolDialogDelegate::DoCancel(
     74     const GURL& url,
     75     bool dont_block) const {
     76   if (dont_block) {
     77       ExternalProtocolHandler::SetBlockState(
     78           url.scheme(), ExternalProtocolHandler::BLOCK);
     79   }
     80 }
     81