Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / extensions / extension_error_ui.cc
blobca170d80cd260a2093b57c5d452ea33e22419f16
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 "chrome/grit/generated_resources.h"
12 #include "extensions/common/extension.h"
13 #include "extensions/common/extension_set.h"
14 #include "ui/base/l10n/l10n_util.h"
16 namespace extensions {
18 namespace {
20 base::string16 GenerateMessageSection(const ExtensionSet& extensions,
21 int extension_template_message_id,
22 int app_template_message_id) {
23 CHECK(extension_template_message_id);
24 CHECK(app_template_message_id);
25 base::string16 message;
27 for (ExtensionSet::const_iterator iter = extensions.begin();
28 iter != extensions.end();
29 ++iter) {
30 message += l10n_util::GetStringFUTF16(
31 (*iter)->is_app() ? app_template_message_id
32 : extension_template_message_id,
33 base::UTF8ToUTF16((*iter)->name())) + base::char16('\n');
35 return message;
38 } // namespace
40 ExtensionErrorUI::ExtensionErrorUI(Delegate* delegate) : delegate_(delegate) {}
42 ExtensionErrorUI::~ExtensionErrorUI() {}
44 std::vector<base::string16> ExtensionErrorUI::GetBubbleViewMessages() {
45 if (message_.empty()) {
46 message_ = GenerateMessage();
47 if (message_[message_.size()-1] == '\n')
48 message_.resize(message_.size()-1);
50 return std::vector<base::string16>(1, message_);
53 base::string16 ExtensionErrorUI::GetBubbleViewTitle() {
54 return l10n_util::GetStringUTF16(IDS_EXTENSION_ALERT_TITLE);
57 base::string16 ExtensionErrorUI::GetBubbleViewAcceptButtonLabel() {
58 return l10n_util::GetStringUTF16(IDS_EXTENSION_ALERT_ITEM_OK);
61 base::string16 ExtensionErrorUI::GetBubbleViewCancelButtonLabel() {
62 return l10n_util::GetStringUTF16(IDS_EXTENSION_ALERT_ITEM_DETAILS);
65 void ExtensionErrorUI::BubbleViewDidClose() {
66 delegate_->OnAlertClosed();
69 void ExtensionErrorUI::BubbleViewAcceptButtonPressed() {
70 delegate_->OnAlertAccept();
73 void ExtensionErrorUI::BubbleViewCancelButtonPressed() {
74 delegate_->OnAlertDetails();
77 base::string16 ExtensionErrorUI::GenerateMessage() {
78 return GenerateMessageSection(delegate_->GetExternalExtensions(),
79 IDS_EXTENSION_ALERT_ITEM_EXTERNAL,
80 IDS_APP_ALERT_ITEM_EXTERNAL) +
81 GenerateMessageSection(delegate_->GetBlacklistedExtensions(),
82 IDS_EXTENSION_ALERT_ITEM_BLACKLISTED,
83 IDS_APP_ALERT_ITEM_BLACKLISTED);
86 } // namespace extensions