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 #include "chrome/browser/custom_handlers/register_protocol_handler_infobar_deleg
ate.h" | 5 #include "chrome/browser/custom_handlers/register_protocol_handler_infobar_deleg
ate.h" |
6 | 6 |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "chrome/browser/api/infobars/infobar_service.h" | 8 #include "chrome/browser/api/infobars/infobar_service.h" |
9 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 9 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
10 #include "chrome/common/url_constants.h" | 10 #include "chrome/common/url_constants.h" |
11 #include "content/public/browser/user_metrics.h" | 11 #include "content/public/browser/user_metrics.h" |
12 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
13 #include "grit/generated_resources.h" | 13 #include "grit/generated_resources.h" |
14 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
15 | 15 |
16 using content::OpenURLParams; | 16 using content::OpenURLParams; |
17 using content::Referrer; | 17 using content::Referrer; |
18 using content::UserMetricsAction; | 18 using content::UserMetricsAction; |
19 | 19 |
20 RegisterProtocolHandlerInfoBarDelegate::RegisterProtocolHandlerInfoBarDelegate( | 20 // static |
| 21 void RegisterProtocolHandlerInfoBarDelegate::Create( |
21 InfoBarService* infobar_service, | 22 InfoBarService* infobar_service, |
22 ProtocolHandlerRegistry* registry, | 23 ProtocolHandlerRegistry* registry, |
23 const ProtocolHandler& handler) | 24 const ProtocolHandler& handler) { |
24 : ConfirmInfoBarDelegate(infobar_service), | 25 content::RecordAction( |
25 registry_(registry), | 26 content::UserMetricsAction("RegisterProtocolHandler.InfoBar_Shown")); |
26 handler_(handler) { | 27 |
| 28 scoped_ptr<InfoBarDelegate> infobar( |
| 29 new RegisterProtocolHandlerInfoBarDelegate(infobar_service, registry, |
| 30 handler)); |
| 31 |
| 32 for (size_t i = 0; i < infobar_service->GetInfoBarCount(); ++i) { |
| 33 RegisterProtocolHandlerInfoBarDelegate* existing_delegate = |
| 34 infobar_service->GetInfoBarDelegateAt(i)-> |
| 35 AsRegisterProtocolHandlerInfoBarDelegate(); |
| 36 if ((existing_delegate != NULL) && |
| 37 existing_delegate->handler_.IsEquivalent(handler)) { |
| 38 infobar_service->ReplaceInfoBar(existing_delegate, infobar.Pass()); |
| 39 return; |
| 40 } |
| 41 } |
| 42 |
| 43 infobar_service->AddInfoBar(infobar.Pass()); |
27 } | 44 } |
28 | 45 |
29 InfoBarDelegate::InfoBarAutomationType | 46 InfoBarDelegate::InfoBarAutomationType |
30 RegisterProtocolHandlerInfoBarDelegate::GetInfoBarAutomationType() const { | 47 RegisterProtocolHandlerInfoBarDelegate::GetInfoBarAutomationType() const { |
31 return RPH_INFOBAR; | 48 return RPH_INFOBAR; |
32 } | 49 } |
33 | 50 |
34 InfoBarDelegate::Type | 51 InfoBarDelegate::Type |
35 RegisterProtocolHandlerInfoBarDelegate::GetInfoBarType() const { | 52 RegisterProtocolHandlerInfoBarDelegate::GetInfoBarType() const { |
36 return PAGE_ACTION_TYPE; | 53 return PAGE_ACTION_TYPE; |
37 } | 54 } |
38 | 55 |
39 string16 RegisterProtocolHandlerInfoBarDelegate::GetMessageText() const { | 56 string16 RegisterProtocolHandlerInfoBarDelegate::GetMessageText() const { |
40 ProtocolHandler old_handler = registry_->GetHandlerFor(handler_.protocol()); | 57 ProtocolHandler old_handler = registry_->GetHandlerFor(handler_.protocol()); |
41 return !old_handler.IsEmpty() ? | 58 return !old_handler.IsEmpty() ? |
42 l10n_util::GetStringFUTF16(IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM_REPLACE, | 59 l10n_util::GetStringFUTF16(IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM_REPLACE, |
43 handler_.title(), UTF8ToUTF16(handler_.url().host()), | 60 handler_.title(), UTF8ToUTF16(handler_.url().host()), |
44 GetProtocolName(handler_), old_handler.title()) : | 61 GetProtocolName(handler_), old_handler.title()) : |
45 l10n_util::GetStringFUTF16(IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM, | 62 l10n_util::GetStringFUTF16(IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM, |
46 handler_.title(), UTF8ToUTF16(handler_.url().host()), | 63 handler_.title(), UTF8ToUTF16(handler_.url().host()), |
47 GetProtocolName(handler_)); | 64 GetProtocolName(handler_)); |
48 } | 65 } |
49 | 66 |
| 67 RegisterProtocolHandlerInfoBarDelegate::RegisterProtocolHandlerInfoBarDelegate( |
| 68 InfoBarService* infobar_service, |
| 69 ProtocolHandlerRegistry* registry, |
| 70 const ProtocolHandler& handler) |
| 71 : ConfirmInfoBarDelegate(infobar_service), |
| 72 registry_(registry), |
| 73 handler_(handler) { |
| 74 } |
| 75 |
50 string16 RegisterProtocolHandlerInfoBarDelegate::GetProtocolName( | 76 string16 RegisterProtocolHandlerInfoBarDelegate::GetProtocolName( |
51 const ProtocolHandler& handler) const { | 77 const ProtocolHandler& handler) const { |
52 if (handler.protocol() == "mailto") | 78 if (handler.protocol() == "mailto") |
53 return l10n_util::GetStringUTF16(IDS_REGISTER_PROTOCOL_HANDLER_MAILTO_NAME); | 79 return l10n_util::GetStringUTF16(IDS_REGISTER_PROTOCOL_HANDLER_MAILTO_NAME); |
54 if (handler.protocol() == "webcal") | 80 if (handler.protocol() == "webcal") |
55 return l10n_util::GetStringUTF16(IDS_REGISTER_PROTOCOL_HANDLER_WEBCAL_NAME); | 81 return l10n_util::GetStringUTF16(IDS_REGISTER_PROTOCOL_HANDLER_WEBCAL_NAME); |
56 return UTF8ToUTF16(handler.protocol()); | 82 return UTF8ToUTF16(handler.protocol()); |
57 } | 83 } |
58 | 84 |
59 string16 RegisterProtocolHandlerInfoBarDelegate::GetButtonLabel( | 85 string16 RegisterProtocolHandlerInfoBarDelegate::GetButtonLabel( |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 OpenURLParams params( | 120 OpenURLParams params( |
95 GURL(chrome::kLearnMoreRegisterProtocolHandlerURL), | 121 GURL(chrome::kLearnMoreRegisterProtocolHandlerURL), |
96 Referrer(), | 122 Referrer(), |
97 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, | 123 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, |
98 content::PAGE_TRANSITION_LINK, | 124 content::PAGE_TRANSITION_LINK, |
99 false); | 125 false); |
100 owner()->GetWebContents()->OpenURL(params); | 126 owner()->GetWebContents()->OpenURL(params); |
101 return false; | 127 return false; |
102 } | 128 } |
103 | 129 |
104 bool RegisterProtocolHandlerInfoBarDelegate::IsReplacedBy( | |
105 RegisterProtocolHandlerInfoBarDelegate* delegate) { | |
106 return handler_.IsEquivalent(delegate->handler_); | |
107 } | |
108 | |
109 RegisterProtocolHandlerInfoBarDelegate* | 130 RegisterProtocolHandlerInfoBarDelegate* |
110 RegisterProtocolHandlerInfoBarDelegate:: | 131 RegisterProtocolHandlerInfoBarDelegate:: |
111 AsRegisterProtocolHandlerInfoBarDelegate() { | 132 AsRegisterProtocolHandlerInfoBarDelegate() { |
112 return this; | 133 return this; |
113 } | 134 } |
OLD | NEW |