Chromium Code Reviews| Index: chrome/browser/extensions/extension_global_error.cc |
| diff --git a/chrome/browser/extensions/extension_global_error.cc b/chrome/browser/extensions/extension_global_error.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7ef6b84a715952c213fd6a413e06d86e2e60d828 |
| --- /dev/null |
| +++ b/chrome/browser/extensions/extension_global_error.cc |
| @@ -0,0 +1,156 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/extensions/extension_global_error.h" |
| + |
| +#include "base/logging.h" |
| +#include "base/string16.h" |
| +#include "base/utf_string_conversions.h" |
| +#include "chrome/browser/extensions/extension_service.h" |
| +#include "chrome/browser/ui/global_error.h" |
| +#include "grit/generated_resources.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| + |
| +ExtensionGlobalError::ExtensionGlobalError( |
| + ExtensionService* extension_service) |
| + : extension_service_(extension_service), |
| + external_extension_ids_(new ExtensionIdSet), |
| + blacklisted_extension_ids_(new ExtensionIdSet), |
| + orphaned_extension_ids_(new ExtensionIdSet) { |
| +} |
| + |
| +ExtensionGlobalError::~ExtensionGlobalError() { |
| +} |
| + |
| +void ExtensionGlobalError::AddExternalExtension(const std::string& id) { |
| + external_extension_ids_->insert(id); |
| +} |
| + |
| +void ExtensionGlobalError::AddBlacklistedExtension(const std::string& id) { |
| + blacklisted_extension_ids_->insert(id); |
| +} |
| + |
| +void ExtensionGlobalError::AddOrphanedExtension(const std::string& id) { |
| + orphaned_extension_ids_->insert(id); |
| +} |
| + |
| +const ExtensionIdSet* |
| +ExtensionGlobalError::get_external_extension_ids() const { |
| + return external_extension_ids_.get(); |
| +} |
| + |
| +const ExtensionIdSet* |
| +ExtensionGlobalError::get_blacklisted_extension_ids() const { |
| + return blacklisted_extension_ids_.get(); |
| +} |
| + |
| +const ExtensionIdSet* |
| +ExtensionGlobalError::get_orphaned_extension_ids() const { |
| + return orphaned_extension_ids_.get(); |
| +} |
|
asargent_no_longer_on_chrome
2011/10/07 21:25:34
Simple getters like the 3 above can be inlined in
|
| + |
| +void ExtensionGlobalError::set_accept_callback( |
| + ExtensionGlobalErrorCallback callback) { |
| + accept_callback_ = callback; |
| +} |
| + |
| +void ExtensionGlobalError::set_cancel_callback( |
| + ExtensionGlobalErrorCallback callback) { |
| + cancel_callback_ = callback; |
| +} |
| + |
| +void ExtensionGlobalError::set_closed_callback( |
| + ExtensionGlobalErrorCallback callback) { |
| + cancel_callback_ = callback; |
| +} |
| + |
| +bool ExtensionGlobalError::HasBadge() { |
| + return false; |
| +} |
| + |
| +bool ExtensionGlobalError::HasMenuItem() { |
| + return false; |
| +} |
| + |
| +int ExtensionGlobalError::MenuItemCommandID() { |
| + NOTREACHED(); |
| + return 0; |
| +} |
| + |
| +string16 ExtensionGlobalError::MenuItemLabel() { |
| + NOTREACHED(); |
| + return NULL; |
| +} |
| + |
| +void ExtensionGlobalError::ExecuteMenuItem(Browser* browser) { |
| + NOTREACHED(); |
| +} |
| + |
| +bool ExtensionGlobalError::HasBubbleView() { |
| + return true; |
| +} |
| + |
| +string16 ExtensionGlobalError::GetBubbleViewTitle() { |
| + return l10n_util::GetStringUTF16(IDS_EXTENSION_NOTIFICATION_TITLE); |
| +} |
| + |
| +string16 ExtensionGlobalError::GenerateMessageSection( |
| + const ExtensionIdSet* extensions, |
| + int template_message_id) { |
| + DCHECK(extensions); |
|
asargent_no_longer_on_chrome
2011/10/07 21:25:34
Might as well make this a CHECK instead of DCHECK,
|
| + DCHECK(template_message_id); |
| + string16 message; |
| + |
| + for (ExtensionIdSet::const_iterator iter = extensions->begin(); |
| + iter != extensions->end(); ++iter) { |
| + const Extension* e = extension_service_->GetExtensionById(*iter, true); |
| + message += l10n_util::GetStringFUTF16(template_message_id, |
| + string16(ASCIIToUTF16(e->name()))); |
| + } |
| + return message; |
| +} |
| + |
| +string16 ExtensionGlobalError::GenerateMessage() { |
| + return l10n_util::GetStringFUTF16( |
| + IDS_EXTENSION_NOTIFICATION_BODY_TEMPLATE, |
| + GenerateMessageSection(external_extension_ids_.get(), |
| + IDS_EXTENSION_NOTIFICATION_ITEM_EXTERNAL) + |
| + GenerateMessageSection(blacklisted_extension_ids_.get(), |
| + IDS_EXTENSION_NOTIFICATION_ITEM_EXTERNAL) + |
| + GenerateMessageSection(orphaned_extension_ids_.get(), |
| + IDS_EXTENSION_NOTIFICATION_ITEM_EXTERNAL)); |
| +} |
| + |
| +string16 ExtensionGlobalError::GetBubbleViewMessage() { |
| + if (message_.empty()) { |
| + message_ = GenerateMessage(); |
| + } |
| + return message_; |
| +} |
| + |
| +string16 ExtensionGlobalError::GetBubbleViewAcceptButtonLabel() { |
| + return l10n_util::GetStringUTF16(IDS_EXTENSION_NOTIFICATION_ITEM_OK); |
| +} |
| + |
| +string16 ExtensionGlobalError::GetBubbleViewCancelButtonLabel() { |
| + return l10n_util::GetStringUTF16(IDS_EXTENSION_NOTIFICATION_ITEM_DETAILS); |
| +} |
| + |
| +void ExtensionGlobalError::BubbleViewDidClose() { |
| + if (!closed_callback_.is_null()) { |
| + closed_callback_.Run(*this); |
| + } |
| +} |
| + |
| +void ExtensionGlobalError::BubbleViewAcceptButtonPressed() { |
| + if (!accept_callback_.is_null()) { |
| + accept_callback_.Run(*this); |
| + } |
| +} |
| + |
| +void ExtensionGlobalError::BubbleViewCancelButtonPressed() { |
| + if (!cancel_callback_.is_null()) { |
| + cancel_callback_.Run(*this); |
| + } |
| +} |