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
3 // found in the LICENSE file.
5 #include "chrome/browser/extensions/extension_error_ui.h"
7 #include "base/logging.h"
8 #include "base/strings/string16.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/ui/global_error/global_error.h"
11 #include "extensions/common/extension.h"
12 #include "extensions/common/extension_set.h"
13 #include "grit/chromium_strings.h"
14 #include "grit/generated_resources.h"
15 #include "ui/base/l10n/l10n_util.h"
17 namespace extensions
{
21 base::string16
GenerateMessageSection(const ExtensionSet
& extensions
,
22 int extension_template_message_id
,
23 int app_template_message_id
) {
24 CHECK(extension_template_message_id
);
25 CHECK(app_template_message_id
);
26 base::string16 message
;
28 for (ExtensionSet::const_iterator iter
= extensions
.begin();
29 iter
!= extensions
.end();
31 message
+= l10n_util::GetStringFUTF16(
32 (*iter
)->is_app() ? app_template_message_id
33 : extension_template_message_id
,
34 base::UTF8ToUTF16((*iter
)->name())) + base::char16('\n');
41 ExtensionErrorUI::ExtensionErrorUI(Delegate
* delegate
) : delegate_(delegate
) {}
43 ExtensionErrorUI::~ExtensionErrorUI() {}
45 std::vector
<base::string16
> ExtensionErrorUI::GetBubbleViewMessages() {
46 if (message_
.empty()) {
47 message_
= GenerateMessage();
48 if (message_
[message_
.size()-1] == '\n')
49 message_
.resize(message_
.size()-1);
51 return std::vector
<base::string16
>(1, message_
);
54 base::string16
ExtensionErrorUI::GetBubbleViewTitle() {
55 return l10n_util::GetStringUTF16(IDS_EXTENSION_ALERT_TITLE
);
58 base::string16
ExtensionErrorUI::GetBubbleViewAcceptButtonLabel() {
59 return l10n_util::GetStringUTF16(IDS_EXTENSION_ALERT_ITEM_OK
);
62 base::string16
ExtensionErrorUI::GetBubbleViewCancelButtonLabel() {
63 return l10n_util::GetStringUTF16(IDS_EXTENSION_ALERT_ITEM_DETAILS
);
66 void ExtensionErrorUI::BubbleViewDidClose() {
67 delegate_
->OnAlertClosed();
70 void ExtensionErrorUI::BubbleViewAcceptButtonPressed() {
71 delegate_
->OnAlertAccept();
74 void ExtensionErrorUI::BubbleViewCancelButtonPressed() {
75 delegate_
->OnAlertDetails();
78 base::string16
ExtensionErrorUI::GenerateMessage() {
79 return GenerateMessageSection(delegate_
->GetExternalExtensions(),
80 IDS_EXTENSION_ALERT_ITEM_EXTERNAL
,
81 IDS_APP_ALERT_ITEM_EXTERNAL
) +
82 GenerateMessageSection(delegate_
->GetBlacklistedExtensions(),
83 IDS_EXTENSION_ALERT_ITEM_BLACKLISTED
,
84 IDS_APP_ALERT_ITEM_BLACKLISTED
);
87 } // namespace extensions