Index: chrome/browser/extensions/ntp_controlled_bubble_controller.cc |
diff --git a/chrome/browser/extensions/ntp_controlled_bubble_controller.cc b/chrome/browser/extensions/ntp_controlled_bubble_controller.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..590a249bd590f909e5cdbd30e324f3c729606d33 |
--- /dev/null |
+++ b/chrome/browser/extensions/ntp_controlled_bubble_controller.cc |
@@ -0,0 +1,203 @@ |
+// Copyright (c) 2014 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/ntp_controlled_bubble_controller.h" |
+ |
+#include "base/metrics/histogram.h" |
+#include "chrome/browser/extensions/extension_service.h" |
+#include "chrome/browser/profiles/profile.h" |
+#include "chrome/common/url_constants.h" |
+#include "extensions/browser/extension_registry.h" |
+#include "extensions/browser/extension_system.h" |
+#include "grit/generated_resources.h" |
+#include "ui/base/l10n/l10n_util.h" |
+ |
+using extensions::ExtensionMessageBubbleController; |
+using extensions::NtpControlledBubbleController; |
+ |
+namespace { |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
+// NtpControlledBubbleDelegate |
+ |
+class NtpControlledBubbleDelegate |
+ : public extensions::ExtensionMessageBubbleController::Delegate { |
+ public: |
+ NtpControlledBubbleDelegate(ExtensionService* service, Profile* profile); |
+ virtual ~NtpControlledBubbleDelegate(); |
+ |
+ // ExtensionMessageBubbleController::Delegate methods. |
+ virtual bool ShouldIncludeExtension(const std::string& extension_id) OVERRIDE; |
+ virtual void AcknowledgeExtension( |
+ const std::string& extension_id, |
+ extensions::ExtensionMessageBubbleController::BubbleAction |
+ user_action) OVERRIDE; |
+ virtual void PerformAction(const extensions::ExtensionIdList& list) OVERRIDE; |
+ virtual base::string16 GetTitle() const OVERRIDE; |
+ virtual base::string16 GetMessageBody() const OVERRIDE; |
+ virtual base::string16 GetOverflowText( |
+ const base::string16& overflow_count) const OVERRIDE; |
+ virtual base::string16 GetLearnMoreLabel() const OVERRIDE; |
+ virtual GURL GetLearnMoreUrl() const OVERRIDE; |
+ virtual base::string16 GetActionButtonLabel() const OVERRIDE; |
+ virtual base::string16 GetDismissButtonLabel() const OVERRIDE; |
+ virtual bool ShouldShowExtensionList() const OVERRIDE; |
+ virtual void RestrictToSingleExtension( |
+ const std::string& extension_id) OVERRIDE; |
+ virtual void LogExtensionCount(size_t count) OVERRIDE; |
+ virtual void LogAction( |
+ extensions::ExtensionMessageBubbleController::BubbleAction |
+ action) OVERRIDE; |
+ |
+ private: |
+ // Our extension service. Weak, not owned by us. |
+ ExtensionService* service_; |
+ |
+ // A weak pointer to the profile we are associated with. Not owned by us. |
+ Profile* profile_; |
+ |
+ // The ID of the extension we are showing the bubble for. |
+ std::string extension_id_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(NtpControlledBubbleDelegate); |
+}; |
+ |
+NtpControlledBubbleDelegate::NtpControlledBubbleDelegate( |
+ ExtensionService* service, |
+ Profile* profile) |
+ : service_(service), profile_(profile) {} |
+ |
+NtpControlledBubbleDelegate::~NtpControlledBubbleDelegate() {} |
+ |
+bool NtpControlledBubbleDelegate::ShouldIncludeExtension( |
+ const std::string& extension_id) { |
+ if (!extension_id_.empty() && extension_id_ != extension_id) |
+ return false; |
+ |
+ using extensions::ExtensionRegistry; |
+ ExtensionRegistry* registry = ExtensionRegistry::Get(profile_); |
+ const extensions::Extension* extension = |
+ registry->GetExtensionById(extension_id, ExtensionRegistry::ENABLED); |
+ if (!extension) |
+ return false; // The extension provided is no longer enabled. |
+ |
+ extensions::ExtensionPrefs* prefs = extensions::ExtensionPrefs::Get(profile_); |
+ if (prefs->HasNtpControlledBubbleBeenAcknowledged(extension_id)) |
+ return false; |
+ |
+ return true; |
+} |
+ |
+void NtpControlledBubbleDelegate::AcknowledgeExtension( |
+ const std::string& extension_id, |
+ ExtensionMessageBubbleController::BubbleAction user_action) { |
+ if (user_action != ExtensionMessageBubbleController::ACTION_EXECUTE) { |
+ extensions::ExtensionPrefs* prefs = |
+ extensions::ExtensionPrefs::Get(profile_); |
+ prefs->SetNtpControlledBubbleBeenAcknowledged(extension_id, true); |
+ } |
+} |
+ |
+void NtpControlledBubbleDelegate::PerformAction( |
+ const extensions::ExtensionIdList& list) { |
+ for (size_t i = 0; i < list.size(); ++i) { |
+ service_->DisableExtension(list[i], |
+ extensions::Extension::DISABLE_USER_ACTION); |
+ } |
+} |
+ |
+base::string16 NtpControlledBubbleDelegate::GetTitle() const { |
+ return l10n_util::GetStringUTF16( |
+ IDS_EXTENSIONS_NTP_CONTROLLED_TITLE_HOME_PAGE_BUBBLE); |
+} |
+ |
+base::string16 NtpControlledBubbleDelegate::GetMessageBody() const { |
+ base::string16 body = |
+ l10n_util::GetStringUTF16(IDS_EXTENSIONS_NTP_CONTROLLED_FIRST_LINE); |
+ body += l10n_util::GetStringUTF16( |
+ IDS_EXTENSIONS_SETTINGS_API_THIRD_LINE_CONFIRMATION); |
+ return body; |
+} |
+ |
+base::string16 NtpControlledBubbleDelegate::GetOverflowText( |
+ const base::string16& overflow_count) const { |
+ // Does not have more than one extension in the list at a time. |
+ NOTREACHED(); |
+ return base::string16(); |
+} |
+ |
+base::string16 NtpControlledBubbleDelegate::GetLearnMoreLabel() const { |
+ return l10n_util::GetStringUTF16(IDS_LEARN_MORE); |
+} |
+ |
+GURL NtpControlledBubbleDelegate::GetLearnMoreUrl() const { |
+ // TODO(finnur): Rename the const when things settle down (since it is used in |
+ // more places than for the Settings API bubble now). |
+ return GURL(chrome::kSettingsApiLearnMoreURL); |
+} |
+ |
+base::string16 NtpControlledBubbleDelegate::GetActionButtonLabel() const { |
+ // TODO(finnur): Rename the const when things settle down (since it is used in |
+ // more places than for the Settings API bubble now). |
+ return l10n_util::GetStringUTF16( |
+ IDS_EXTENSIONS_SETTINGS_API_RESTORE_SETTINGS); |
+} |
+ |
+base::string16 NtpControlledBubbleDelegate::GetDismissButtonLabel() const { |
+ // TODO(finnur): Rename the const when things settle down (since it is used in |
+ // more places than for the Settings API bubble now). |
+ return l10n_util::GetStringUTF16(IDS_EXTENSIONS_SETTINGS_API_KEEP_CHANGES); |
+} |
+ |
+bool NtpControlledBubbleDelegate::ShouldShowExtensionList() const { |
+ return false; |
+} |
+ |
+void NtpControlledBubbleDelegate::RestrictToSingleExtension( |
Yoyo Zhou
2014/04/23 00:08:35
Considering the lifetime of NtpControlledBubbleCon
|
+ const std::string& extension_id) { |
+ extension_id_ = extension_id; |
+} |
+ |
+void NtpControlledBubbleDelegate::LogExtensionCount(size_t count) { |
+ UMA_HISTOGRAM_COUNTS_100("NtpControlledBubble.ExtensionCount", count); |
+} |
+ |
+void NtpControlledBubbleDelegate::LogAction( |
+ ExtensionMessageBubbleController::BubbleAction action) { |
+ UMA_HISTOGRAM_ENUMERATION("NtpControlledBubble.UserSelection", |
+ action, |
+ ExtensionMessageBubbleController::ACTION_BOUNDARY); |
+} |
+ |
+} // namespace |
+ |
+namespace extensions { |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
+// NtpControlledBubbleController |
+ |
+NtpControlledBubbleController::NtpControlledBubbleController(Profile* profile) |
+ : ExtensionMessageBubbleController( |
+ new NtpControlledBubbleDelegate( |
+ ExtensionSystem::Get(profile)->extension_service(), |
+ profile), |
+ profile), |
+ profile_(profile) {} |
+ |
+NtpControlledBubbleController::~NtpControlledBubbleController() {} |
+ |
+bool NtpControlledBubbleController::ShouldShow( |
+ const std::string& extension_id) { |
+ if (!delegate()->ShouldIncludeExtension(extension_id)) |
+ return false; |
+ |
+ delegate()->RestrictToSingleExtension(extension_id); |
+ return true; |
+} |
+ |
+bool NtpControlledBubbleController::CloseOnDeactivate() { |
+ return true; |
+} |
+ |
+} // namespace extensions |