Index: chrome/browser/extensions/dev_mode_bubble_controller_delegate.cc |
diff --git a/chrome/browser/extensions/dev_mode_bubble_controller_delegate.cc b/chrome/browser/extensions/dev_mode_bubble_controller_delegate.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ab220c8df3645918df7af330c738db1b64e038f7 |
--- /dev/null |
+++ b/chrome/browser/extensions/dev_mode_bubble_controller_delegate.cc |
@@ -0,0 +1,180 @@ |
+// Copyright (c) 2013 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/dev_mode_bubble_controller_delegate.h" |
+ |
+#include "base/bind.h" |
+#include "base/metrics/histogram.h" |
+#include "base/strings/utf_string_conversions.h" |
+#include "chrome/browser/chrome_notification_types.h" |
+#include "chrome/browser/extensions/extension_action_manager.h" |
+#include "chrome/browser/extensions/extension_message_bubble.h" |
+#include "chrome/browser/extensions/extension_prefs.h" |
+#include "chrome/browser/extensions/extension_service.h" |
+#include "chrome/browser/ui/browser.h" |
+#include "chrome/browser/ui/browser_finder.h" |
+#include "chrome/common/url_constants.h" |
+#include "content/public/browser/notification_service.h" |
+#include "content/public/browser/user_metrics.h" |
+#include "grit/chromium_strings.h" |
+#include "grit/generated_resources.h" |
+#include "ui/base/l10n/l10n_util.h" |
+ |
+namespace { |
+ |
+static base::LazyInstance<extensions::ProfileKeyedAPIFactory< |
+ extensions::DevModeBubbleControllerDelegate> > |
+g_factory = LAZY_INSTANCE_INITIALIZER; |
+ |
+} // namespace |
+ |
+namespace extensions { |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
+// DevModeBubbleControllerDelegate |
+ |
+DevModeBubbleControllerDelegate::DevModeBubbleControllerDelegate( |
+ Profile* profile) |
+ : controller_(new ExtensionMessageBubbleController(this, profile)), |
+ service_(extensions::ExtensionSystem::Get(profile)->extension_service()), |
+ profile_(profile) { |
+} |
+ |
+DevModeBubbleControllerDelegate::~DevModeBubbleControllerDelegate() { |
+} |
+ |
+// static |
+ProfileKeyedAPIFactory<DevModeBubbleControllerDelegate>* |
+DevModeBubbleControllerDelegate::GetFactoryInstance() { |
+ return &g_factory.Get(); |
+} |
+ |
+// static |
+DevModeBubbleControllerDelegate* DevModeBubbleControllerDelegate::Get( |
+ Profile* profile) { |
+ return ProfileKeyedAPIFactory< |
+ DevModeBubbleControllerDelegate>::GetForProfile(profile); |
+} |
+ |
+bool DevModeBubbleControllerDelegate::IsDevModeExtension( |
+ const Extension* extension) const { |
+ return extension->location() == Manifest::UNPACKED || |
+ extension->location() == Manifest::COMMAND_LINE; |
+} |
+ |
+void DevModeBubbleControllerDelegate::Show(ExtensionMessageBubble* bubble) { |
+ controller_->Show(bubble); |
+} |
+ |
+bool DevModeBubbleControllerDelegate::ShowingBubble() const { |
+ return controller_->showing_bubble(); |
+} |
+ |
+bool DevModeBubbleControllerDelegate::HasExtensionList() const { |
+ return controller_->HasExtensionList(); |
+} |
+ |
+std::vector<string16> |
+DevModeBubbleControllerDelegate::GetExtensionList() const { |
+ return controller_->GetExtensionList(); |
+} |
+ |
+const ExtensionIdList& |
+DevModeBubbleControllerDelegate::GetExtensionIdList() const { |
+ return controller_->extension_id_list(); |
+} |
+ |
+bool DevModeBubbleControllerDelegate::ShouldIncludeExtension( |
+ const std::string& extension_id) { |
+ const Extension* extension = service_->GetExtensionById(extension_id, false); |
+ if (!extension) |
+ return false; |
+ if (!IsDevModeExtension(extension)) |
+ return false; |
+ return true; |
+} |
+ |
+void DevModeBubbleControllerDelegate::AcknowledgeExtension( |
+ const std::string& extension_id, |
+ ExtensionMessageBubbleController::BubbleAction user_action) { |
+ if (user_action == ExtensionMessageBubbleController::ACTION_EXECUTE) |
+ return; // Extension is gone, no further action required. |
+ |
+ // We'll need to let the browser action know that the state has been updated |
+ // so the highlighting on the badge can be removed (if the extension has a |
+ // browser action). |
+ const Extension* extension = service_->GetExtensionById(extension_id, false); |
+ if (!extension) |
+ return; |
+ ExtensionAction* action = ExtensionActionManager::Get(profile_)-> |
+ GetBrowserAction(*extension); |
+ if (!action) |
+ return; |
+ |
+ content::NotificationService::current()->Notify( |
+ chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_UPDATED, |
+ content::Source<ExtensionAction>(action), |
+ content::Details<Profile>(profile_)); |
+} |
+ |
+void DevModeBubbleControllerDelegate::PerformAction( |
+ const ExtensionIdList& list) { |
+ for (size_t i = 0; i < list.size(); ++i) |
+ service_->DisableExtension(list[i], Extension::DISABLE_USER_ACTION); |
+} |
+ |
+string16 DevModeBubbleControllerDelegate::GetTitle() const { |
+ return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE_DEVELOPER_MODE_TITLE); |
+} |
+ |
+string16 DevModeBubbleControllerDelegate::GetMessageBody() const { |
+ return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE_DEVELOPER_MODE_BODY); |
+} |
+ |
+string16 DevModeBubbleControllerDelegate::GetOverflowText( |
+ const string16& overflow_count) const { |
+ return l10n_util::GetStringFUTF16( |
+ IDS_EXTENSIONS_SUSPICIOUS_DISABLED_AND_N_MORE, |
+ overflow_count); |
+} |
+ |
+string16 DevModeBubbleControllerDelegate::GetLearnMoreLabel() const { |
+ return l10n_util::GetStringUTF16(IDS_LEARN_MORE); |
+} |
+ |
+GURL DevModeBubbleControllerDelegate::GetLearnMoreUrl() const { |
+ return GURL(chrome::kChromeUIExtensionsURL); |
+} |
+ |
+string16 DevModeBubbleControllerDelegate::GetActionButtonLabel() const { |
+ return l10n_util::GetStringUTF16(IDS_DISABLE); |
+} |
+ |
+string16 DevModeBubbleControllerDelegate::GetDismissButtonLabel() const { |
+ return l10n_util::GetStringUTF16(IDS_CANCEL); |
+} |
+ |
+bool DevModeBubbleControllerDelegate::ShouldShowExtensionList() const { |
+ return true; |
+} |
+ |
+void DevModeBubbleControllerDelegate::LogExtensionCount(size_t count) { |
+ UMA_HISTOGRAM_COUNTS_100( |
+ "DevModeExtensionBubble.ExtensionsInDevModeCount", count); |
+} |
+ |
+void DevModeBubbleControllerDelegate::LogAction( |
+ ExtensionMessageBubbleController::BubbleAction action) { |
+ UMA_HISTOGRAM_ENUMERATION( |
+ "DevModeExtensionBubble.UserSelection", |
+ action, ExtensionMessageBubbleController::ACTION_BOUNDARY); |
+} |
+ |
+template <> |
+void ProfileKeyedAPIFactory< |
+ DevModeBubbleControllerDelegate>::DeclareFactoryDependencies() { |
+ DependsOn(extensions::ExtensionSystemFactory::GetInstance()); |
+} |
+ |
+} // namespace extensions |