15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/extensions/extension_error_ui.h" 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/logging.h" 8868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/string16.h" 9868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h" 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/extensions/extension_service.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/global_error/global_error.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "grit/chromium_strings.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "grit/generated_resources.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/l10n/l10n_util.h" 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using extensions::ExtensionIdSet; 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ExtensionErrorUI::ExtensionErrorUI(ExtensionService* extension_service) 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : extension_service_(extension_service), 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) external_extension_ids_(new ExtensionIdSet), 212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) blacklisted_extension_ids_(new ExtensionIdSet) { 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(extension_service_); 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ExtensionErrorUI::~ExtensionErrorUI() { 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ExtensionErrorUI::AddExternalExtension(const std::string& id) { 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) external_extension_ids_->insert(id); 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ExtensionErrorUI::AddBlacklistedExtension(const std::string& id) { 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) blacklisted_extension_ids_->insert(id); 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 36d57369da7c6519fef57db42085f7b42d4c8845c1Torne (Richard Coles)base::string16 ExtensionErrorUI::GenerateMessageSection( 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ExtensionIdSet* extensions, 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int extension_template_message_id, 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int app_template_message_id) { 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CHECK(extensions); 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CHECK(extension_template_message_id); 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CHECK(app_template_message_id); 43a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 message; 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (ExtensionIdSet::const_iterator iter = extensions->begin(); 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) iter != extensions->end(); ++iter) { 472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const extensions::Extension* e = 482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) extension_service_->GetInstalledExtension(*iter); 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) message += l10n_util::GetStringFUTF16( 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) e->is_app() ? app_template_message_id : extension_template_message_id, 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) UTF8ToUTF16(e->name())) + char16('\n'); 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return message; 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 56d57369da7c6519fef57db42085f7b42d4c8845c1Torne (Richard Coles)base::string16 ExtensionErrorUI::GenerateMessage() { 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return GenerateMessageSection(external_extension_ids_.get(), 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) IDS_EXTENSION_ALERT_ITEM_EXTERNAL, 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) IDS_APP_ALERT_ITEM_EXTERNAL) + 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GenerateMessageSection(blacklisted_extension_ids_.get(), 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) IDS_EXTENSION_ALERT_ITEM_BLACKLISTED, 622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) IDS_APP_ALERT_ITEM_BLACKLISTED); 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 65d57369da7c6519fef57db42085f7b42d4c8845c1Torne (Richard Coles)std::vector<base::string16> ExtensionErrorUI::GetBubbleViewMessages() { 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (message_.empty()) { 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) message_ = GenerateMessage(); 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (message_[message_.size()-1] == '\n') 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) message_.resize(message_.size()-1); 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 71d57369da7c6519fef57db42085f7b42d4c8845c1Torne (Richard Coles) return std::vector<base::string16>(1, message_); 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 74d57369da7c6519fef57db42085f7b42d4c8845c1Torne (Richard Coles)base::string16 ExtensionErrorUI::GetBubbleViewTitle() { 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return l10n_util::GetStringUTF16(IDS_EXTENSION_ALERT_TITLE); 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 78d57369da7c6519fef57db42085f7b42d4c8845c1Torne (Richard Coles)base::string16 ExtensionErrorUI::GetBubbleViewAcceptButtonLabel() { 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return l10n_util::GetStringUTF16(IDS_EXTENSION_ALERT_ITEM_OK); 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 82d57369da7c6519fef57db42085f7b42d4c8845c1Torne (Richard Coles)base::string16 ExtensionErrorUI::GetBubbleViewCancelButtonLabel() { 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return l10n_util::GetStringUTF16(IDS_EXTENSION_ALERT_ITEM_DETAILS); 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ExtensionErrorUI::BubbleViewDidClose() { 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This call deletes ExtensionErrorUI object referenced by this. 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension_service_->HandleExtensionAlertClosed(); 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ExtensionErrorUI::BubbleViewAcceptButtonPressed() { 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension_service_->HandleExtensionAlertAccept(); 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ExtensionErrorUI::BubbleViewCancelButtonPressed() { 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension_service_->HandleExtensionAlertDetails(); 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 98