• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "chrome/browser/extensions/extension_error_ui.h"
6 
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"
15 
16 namespace extensions {
17 
18 namespace {
19 
GenerateMessageSection(const ExtensionSet & extensions,int extension_template_message_id,int app_template_message_id)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;
26 
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');
34   }
35   return message;
36 }
37 
38 }  // namespace
39 
ExtensionErrorUI(Delegate * delegate)40 ExtensionErrorUI::ExtensionErrorUI(Delegate* delegate) : delegate_(delegate) {}
41 
~ExtensionErrorUI()42 ExtensionErrorUI::~ExtensionErrorUI() {}
43 
GetBubbleViewMessages()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);
49   }
50   return std::vector<base::string16>(1, message_);
51 }
52 
GetBubbleViewTitle()53 base::string16 ExtensionErrorUI::GetBubbleViewTitle() {
54   return l10n_util::GetStringUTF16(IDS_EXTENSION_ALERT_TITLE);
55 }
56 
GetBubbleViewAcceptButtonLabel()57 base::string16 ExtensionErrorUI::GetBubbleViewAcceptButtonLabel() {
58   return l10n_util::GetStringUTF16(IDS_EXTENSION_ALERT_ITEM_OK);
59 }
60 
GetBubbleViewCancelButtonLabel()61 base::string16 ExtensionErrorUI::GetBubbleViewCancelButtonLabel() {
62   return l10n_util::GetStringUTF16(IDS_EXTENSION_ALERT_ITEM_DETAILS);
63 }
64 
BubbleViewDidClose()65 void ExtensionErrorUI::BubbleViewDidClose() {
66   delegate_->OnAlertClosed();
67 }
68 
BubbleViewAcceptButtonPressed()69 void ExtensionErrorUI::BubbleViewAcceptButtonPressed() {
70   delegate_->OnAlertAccept();
71 }
72 
BubbleViewCancelButtonPressed()73 void ExtensionErrorUI::BubbleViewCancelButtonPressed() {
74   delegate_->OnAlertDetails();
75 }
76 
GenerateMessage()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);
84 }
85 
86 }  // namespace extensions
87