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/extensions/extension_service.h"
11 #include "chrome/browser/ui/global_error/global_error.h"
12 #include "grit/chromium_strings.h"
13 #include "grit/generated_resources.h"
14 #include "ui/base/l10n/l10n_util.h"
16 using extensions::ExtensionIdSet
;
18 ExtensionErrorUI::ExtensionErrorUI(ExtensionService
* extension_service
)
19 : extension_service_(extension_service
),
20 external_extension_ids_(new ExtensionIdSet
),
21 blacklisted_extension_ids_(new ExtensionIdSet
) {
22 DCHECK(extension_service_
);
25 ExtensionErrorUI::~ExtensionErrorUI() {
28 void ExtensionErrorUI::AddExternalExtension(const std::string
& id
) {
29 external_extension_ids_
->insert(id
);
32 void ExtensionErrorUI::AddBlacklistedExtension(const std::string
& id
) {
33 blacklisted_extension_ids_
->insert(id
);
36 base::string16
ExtensionErrorUI::GenerateMessageSection(
37 const ExtensionIdSet
* extensions
,
38 int extension_template_message_id
,
39 int app_template_message_id
) {
41 CHECK(extension_template_message_id
);
42 CHECK(app_template_message_id
);
43 base::string16 message
;
45 for (ExtensionIdSet::const_iterator iter
= extensions
->begin();
46 iter
!= extensions
->end(); ++iter
) {
47 const extensions::Extension
* e
=
48 extension_service_
->GetInstalledExtension(*iter
);
49 message
+= l10n_util::GetStringFUTF16(
50 e
->is_app() ? app_template_message_id
: extension_template_message_id
,
51 base::UTF8ToUTF16(e
->name())) + base::char16('\n');
56 base::string16
ExtensionErrorUI::GenerateMessage() {
57 return GenerateMessageSection(external_extension_ids_
.get(),
58 IDS_EXTENSION_ALERT_ITEM_EXTERNAL
,
59 IDS_APP_ALERT_ITEM_EXTERNAL
) +
60 GenerateMessageSection(blacklisted_extension_ids_
.get(),
61 IDS_EXTENSION_ALERT_ITEM_BLACKLISTED
,
62 IDS_APP_ALERT_ITEM_BLACKLISTED
);
65 std::vector
<base::string16
> ExtensionErrorUI::GetBubbleViewMessages() {
66 if (message_
.empty()) {
67 message_
= GenerateMessage();
68 if (message_
[message_
.size()-1] == '\n')
69 message_
.resize(message_
.size()-1);
71 return std::vector
<base::string16
>(1, message_
);
74 base::string16
ExtensionErrorUI::GetBubbleViewTitle() {
75 return l10n_util::GetStringUTF16(IDS_EXTENSION_ALERT_TITLE
);
78 base::string16
ExtensionErrorUI::GetBubbleViewAcceptButtonLabel() {
79 return l10n_util::GetStringUTF16(IDS_EXTENSION_ALERT_ITEM_OK
);
82 base::string16
ExtensionErrorUI::GetBubbleViewCancelButtonLabel() {
83 return l10n_util::GetStringUTF16(IDS_EXTENSION_ALERT_ITEM_DETAILS
);
86 void ExtensionErrorUI::BubbleViewDidClose() {
87 // This call deletes ExtensionErrorUI object referenced by this.
88 extension_service_
->HandleExtensionAlertClosed();
91 void ExtensionErrorUI::BubbleViewAcceptButtonPressed() {
92 extension_service_
->HandleExtensionAlertAccept();
95 void ExtensionErrorUI::BubbleViewCancelButtonPressed() {
96 extension_service_
->HandleExtensionAlertDetails();