| OLD | NEW |
| (Empty) |
| 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_global_error.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "base/string16.h" | |
| 9 #include "base/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" | |
| 15 | |
| 16 using extensions::ExtensionIdSet; | |
| 17 | |
| 18 ExtensionGlobalError::ExtensionGlobalError(ExtensionService* extension_service) | |
| 19 : extension_service_(extension_service), | |
| 20 external_extension_ids_(new ExtensionIdSet), | |
| 21 blacklisted_extension_ids_(new ExtensionIdSet), | |
| 22 orphaned_extension_ids_(new ExtensionIdSet) { | |
| 23 DCHECK(extension_service_); | |
| 24 } | |
| 25 | |
| 26 ExtensionGlobalError::~ExtensionGlobalError() { | |
| 27 } | |
| 28 | |
| 29 void ExtensionGlobalError::AddExternalExtension(const std::string& id) { | |
| 30 external_extension_ids_->insert(id); | |
| 31 } | |
| 32 | |
| 33 void ExtensionGlobalError::AddBlacklistedExtension(const std::string& id) { | |
| 34 blacklisted_extension_ids_->insert(id); | |
| 35 } | |
| 36 | |
| 37 void ExtensionGlobalError::AddOrphanedExtension(const std::string& id) { | |
| 38 orphaned_extension_ids_->insert(id); | |
| 39 } | |
| 40 | |
| 41 bool ExtensionGlobalError::HasBadge() { | |
| 42 return false; | |
| 43 } | |
| 44 | |
| 45 bool ExtensionGlobalError::HasMenuItem() { | |
| 46 return false; | |
| 47 } | |
| 48 | |
| 49 int ExtensionGlobalError::MenuItemCommandID() { | |
| 50 NOTREACHED(); | |
| 51 return 0; | |
| 52 } | |
| 53 | |
| 54 string16 ExtensionGlobalError::MenuItemLabel() { | |
| 55 NOTREACHED(); | |
| 56 return NULL; | |
| 57 } | |
| 58 | |
| 59 void ExtensionGlobalError::ExecuteMenuItem(Browser* browser) { | |
| 60 NOTREACHED(); | |
| 61 } | |
| 62 | |
| 63 bool ExtensionGlobalError::HasBubbleView() { | |
| 64 return true; | |
| 65 } | |
| 66 | |
| 67 string16 ExtensionGlobalError::GetBubbleViewTitle() { | |
| 68 return l10n_util::GetStringUTF16(IDS_EXTENSION_ALERT_TITLE); | |
| 69 } | |
| 70 | |
| 71 string16 ExtensionGlobalError::GenerateMessageSection( | |
| 72 const ExtensionIdSet* extensions, | |
| 73 int template_message_id) { | |
| 74 CHECK(extensions); | |
| 75 CHECK(template_message_id); | |
| 76 string16 message; | |
| 77 | |
| 78 for (ExtensionIdSet::const_iterator iter = extensions->begin(); | |
| 79 iter != extensions->end(); ++iter) { | |
| 80 const extensions::Extension* e = extension_service_->GetExtensionById(*iter, | |
| 81 true); | |
| 82 message += l10n_util::GetStringFUTF16(template_message_id, | |
| 83 string16(ASCIIToUTF16(e->name()))); | |
| 84 } | |
| 85 return message; | |
| 86 } | |
| 87 | |
| 88 string16 ExtensionGlobalError::GenerateMessage() { | |
| 89 return GenerateMessageSection(external_extension_ids_.get(), | |
| 90 IDS_EXTENSION_ALERT_ITEM_EXTERNAL) + | |
| 91 GenerateMessageSection(blacklisted_extension_ids_.get(), | |
| 92 IDS_EXTENSION_ALERT_ITEM_BLACKLISTED) + | |
| 93 GenerateMessageSection(orphaned_extension_ids_.get(), | |
| 94 IDS_EXTENSION_ALERT_ITEM_ORPHANED); | |
| 95 } | |
| 96 | |
| 97 string16 ExtensionGlobalError::GetBubbleViewMessage() { | |
| 98 if (message_.empty()) { | |
| 99 message_ = GenerateMessage(); | |
| 100 if (message_[message_.size()-1] == '\n') | |
| 101 message_.resize(message_.size()-1); | |
| 102 } | |
| 103 return message_; | |
| 104 } | |
| 105 | |
| 106 string16 ExtensionGlobalError::GetBubbleViewAcceptButtonLabel() { | |
| 107 return l10n_util::GetStringUTF16(IDS_EXTENSION_ALERT_ITEM_OK); | |
| 108 } | |
| 109 | |
| 110 string16 ExtensionGlobalError::GetBubbleViewCancelButtonLabel() { | |
| 111 return l10n_util::GetStringUTF16(IDS_EXTENSION_ALERT_ITEM_DETAILS); | |
| 112 } | |
| 113 | |
| 114 void ExtensionGlobalError::OnBubbleViewDidClose(Browser* browser) { | |
| 115 extension_service_->HandleExtensionAlertClosed(); | |
| 116 } | |
| 117 | |
| 118 void ExtensionGlobalError::BubbleViewAcceptButtonPressed(Browser* browser) { | |
| 119 extension_service_->HandleExtensionAlertAccept(); | |
| 120 } | |
| 121 | |
| 122 void ExtensionGlobalError::BubbleViewCancelButtonPressed(Browser* browser) { | |
| 123 extension_service_->HandleExtensionAlertDetails(browser); | |
| 124 } | |
| OLD | NEW |