• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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/custom_handlers/register_protocol_handler_infobar_delegate.h"
6 
7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
9 #include "grit/generated_resources.h"
10 #include "ui/base/l10n/l10n_util.h"
11 
RegisterProtocolHandlerInfoBarDelegate(TabContents * tab_contents,ProtocolHandlerRegistry * registry,ProtocolHandler * handler)12 RegisterProtocolHandlerInfoBarDelegate::RegisterProtocolHandlerInfoBarDelegate(
13     TabContents* tab_contents,
14     ProtocolHandlerRegistry* registry,
15     ProtocolHandler* handler)
16     : ConfirmInfoBarDelegate(tab_contents),
17       tab_contents_(tab_contents),
18       registry_(registry),
19       handler_(handler) {
20 }
21 
ShouldExpire(const NavigationController::LoadCommittedDetails & details) const22 bool RegisterProtocolHandlerInfoBarDelegate::ShouldExpire(
23     const NavigationController::LoadCommittedDetails& details) const {
24   // The user has submitted a form, causing the page to navigate elsewhere. We
25   // don't want the infobar to be expired at this point, because the user won't
26   // get a chance to answer the question.
27   return false;
28 }
29 
InfoBarClosed()30 void RegisterProtocolHandlerInfoBarDelegate::InfoBarClosed() {
31   delete this;
32 }
33 
34 InfoBarDelegate::Type
GetInfoBarType() const35     RegisterProtocolHandlerInfoBarDelegate::GetInfoBarType() const {
36   return PAGE_ACTION_TYPE;
37 }
38 
GetMessageText() const39 string16 RegisterProtocolHandlerInfoBarDelegate::GetMessageText() const {
40   ProtocolHandler* old_handler = registry_->GetHandlerFor(handler_->protocol());
41   return old_handler ?
42       l10n_util::GetStringFUTF16(IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM_REPLACE,
43           handler_->title(), UTF8ToUTF16(handler_->url().host()),
44           UTF8ToUTF16(handler_->protocol()), old_handler->title()) :
45       l10n_util::GetStringFUTF16(IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM,
46           handler_->title(), UTF8ToUTF16(handler_->url().host()),
47           UTF8ToUTF16(handler_->protocol()));
48 }
49 
GetButtonLabel(InfoBarButton button) const50 string16 RegisterProtocolHandlerInfoBarDelegate::GetButtonLabel(
51     InfoBarButton button) const {
52   return (button == BUTTON_OK) ?
53       l10n_util::GetStringFUTF16(IDS_REGISTER_PROTOCOL_HANDLER_ACCEPT,
54                                  handler_->title()) :
55       l10n_util::GetStringUTF16(IDS_REGISTER_PROTOCOL_HANDLER_DENY);
56 }
57 
Accept()58 bool RegisterProtocolHandlerInfoBarDelegate::Accept() {
59   registry_->OnAcceptRegisterProtocolHandler(handler_);
60   return true;
61 }
62 
Cancel()63 bool RegisterProtocolHandlerInfoBarDelegate::Cancel() {
64   registry_->OnDenyRegisterProtocolHandler(handler_);
65   return true;
66 }
67 
GetLinkText()68 string16 RegisterProtocolHandlerInfoBarDelegate::GetLinkText() {
69   // TODO(koz): Make this a 'learn more' link.
70   return string16();
71 }
72 
LinkClicked(WindowOpenDisposition disposition)73 bool RegisterProtocolHandlerInfoBarDelegate::LinkClicked(
74     WindowOpenDisposition disposition) {
75   return false;
76 }
77