| Index: chrome/browser/extensions/dev_mode_bubble_controller.cc
|
| diff --git a/chrome/browser/extensions/dev_mode_bubble_controller.cc b/chrome/browser/extensions/dev_mode_bubble_controller.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..4b57a749462d36e3e63ff931aaaffc5372922669
|
| --- /dev/null
|
| +++ b/chrome/browser/extensions/dev_mode_bubble_controller.cc
|
| @@ -0,0 +1,113 @@
|
| +// 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.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::DevModeBubbleController> >
|
| +g_factory = LAZY_INSTANCE_INITIALIZER;
|
| +
|
| +} // namespace
|
| +
|
| +namespace extensions {
|
| +
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// DevModeBubbleController
|
| +
|
| +DevModeBubbleController::DevModeBubbleController(
|
| + Profile* profile)
|
| + : ExtensionMessageBubbleController(DEV_MODE_EXTENSIONS, profile) {
|
| +}
|
| +
|
| +DevModeBubbleController::~DevModeBubbleController() {
|
| +}
|
| +
|
| +// static
|
| +ProfileKeyedAPIFactory<DevModeBubbleController>*
|
| +DevModeBubbleController::GetFactoryInstance() {
|
| + return &g_factory.Get();
|
| +}
|
| +
|
| +// static
|
| +DevModeBubbleController* DevModeBubbleController::Get(Profile* profile) {
|
| + return ProfileKeyedAPIFactory<
|
| + DevModeBubbleController>::GetForProfile(profile);
|
| +}
|
| +
|
| +bool DevModeBubbleController::ShouldIncludeExtension(
|
| + const std::string& extension_id) {
|
| + const Extension* extension = service_->GetExtensionById(extension_id, false);
|
| + ExtensionPrefs* prefs = service_->extension_prefs();
|
| + if (!extension)
|
| + return false;
|
| + if (!extension->IsDevModeExtension())
|
| + return false;
|
| + return !prefs->HasDevModeBeenAcknowledged(extension_id);
|
| +}
|
| +
|
| +void DevModeBubbleController::AcknowledgeExtension(
|
| + const std::string& extension_id) {
|
| + // Clicking Learn More closes the bubble without taking action. In that case
|
| + // we don't want to acknowledge the extension but instead show the bubble
|
| + // again on next startup. Also, since we want to show the bubble again when
|
| + // the extension gets disabled by the bubble and enabled by the user, we might
|
| + // as well skip the writing of the acknowledged flag here.
|
| + if (user_action_ == ACTION_LEARN_MORE || user_action_ == ACTION_EXECUTE)
|
| + return;
|
| +
|
| + // User clicked cancel, that means we need to record that they don't want to
|
| + // be notified about this extension again.
|
| + ExtensionPrefs* prefs = service_->extension_prefs();
|
| + prefs->SetDevModeAcknowledged(extension_id, true);
|
| +
|
| + // 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 DevModeBubbleController::PerformAction() {
|
| + for (size_t i = 0; i < extension_list_.size(); ++i) {
|
| + service_->DisableExtension(
|
| + extension_list_[i], Extension::DISABLE_USER_ACTION);
|
| + }
|
| +}
|
| +
|
| +template <>
|
| +void ProfileKeyedAPIFactory<
|
| + DevModeBubbleController>::DeclareFactoryDependencies() {
|
| + DependsOn(extensions::ExtensionSystemFactory::GetInstance());
|
| +}
|
| +
|
| +} // namespace extensions
|
|
|