blob: 63c0b6517bfea33eb01665c1747f12ca9ffa49c7 [file] [log] [blame]
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/external_protocol_dialog_delegate.h"
#include "chrome/browser/external_protocol/external_protocol_handler.h"
#include "chrome/grit/chromium_strings.h"
#include "chrome/grit/generated_resources.h"
#include "components/strings/grit/components_strings.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/text_elider.h"
namespace {
const size_t kMaxCommandSize = 32;
base::string16 ElideCommandName(const base::string16& command_name) {
base::string16 elided_command;
gfx::ElideString(command_name, kMaxCommandSize, &elided_command);
return elided_command;
}
} // namespace
ExternalProtocolDialogDelegate::ExternalProtocolDialogDelegate(
const GURL& url,
int render_process_host_id,
int tab_contents_id)
: ProtocolDialogDelegate(url),
render_process_host_id_(render_process_host_id),
tab_contents_id_(tab_contents_id),
program_name_(shell_integration::GetApplicationNameForProtocol(url)) {}
ExternalProtocolDialogDelegate::~ExternalProtocolDialogDelegate() {
}
base::string16 ExternalProtocolDialogDelegate::GetDialogButtonLabel(
ui::DialogButton button) const {
if (button == ui::DIALOG_BUTTON_OK) {
return l10n_util::GetStringFUTF16(IDS_EXTERNAL_PROTOCOL_OK_BUTTON_TEXT,
ElideCommandName(program_name_));
}
return l10n_util::GetStringUTF16(IDS_CANCEL);
}
base::string16 ExternalProtocolDialogDelegate::GetMessageText() const {
return base::string16();
}
base::string16 ExternalProtocolDialogDelegate::GetCheckboxText() const {
return l10n_util::GetStringFUTF16(IDS_EXTERNAL_PROTOCOL_CHECKBOX_TEXT,
ElideCommandName(program_name_));
}
base::string16 ExternalProtocolDialogDelegate::GetTitleText() const {
return l10n_util::GetStringFUTF16(IDS_EXTERNAL_PROTOCOL_TITLE,
ElideCommandName(program_name_));
}
void ExternalProtocolDialogDelegate::DoAccept(const GURL& url,
bool dont_block) const {
if (dont_block) {
ExternalProtocolHandler::SetBlockState(url.scheme(),
ExternalProtocolHandler::DONT_BLOCK);
}
ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(
url, render_process_host_id_, tab_contents_id_);
}
void ExternalProtocolDialogDelegate::DoCancel(const GURL& url,
bool dont_block) const {
if (dont_block) {
ExternalProtocolHandler::SetBlockState(url.scheme(),
ExternalProtocolHandler::BLOCK);
}
}