This source file includes following definitions.
- type_
- ShouldIncludeExtension
- AcknowledgeExtension
- PerformAction
- GetTitle
- GetMessageBody
- GetOverflowText
- GetLearnMoreLabel
- GetLearnMoreUrl
- GetActionButtonLabel
- GetDismissButtonLabel
- ShouldShowExtensionList
- LogExtensionCount
- LogAction
- type_
- ShouldShow
- CloseOnDeactivate
#include "chrome/browser/extensions/settings_api_bubble_controller.h"
#include "base/metrics/histogram.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/settings_api_helpers.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/startup/startup_browser_creator.h"
#include "chrome/common/extensions/manifest_handlers/settings_overrides_handler.h"
#include "chrome/common/url_constants.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
using extensions::ExtensionMessageBubbleController;
using extensions::SettingsApiBubbleController;
using extensions::SettingsOverrides;
namespace {
class SettingsApiBubbleDelegate
: public extensions::ExtensionMessageBubbleController::Delegate {
public:
explicit SettingsApiBubbleDelegate(ExtensionService* service,
Profile* profile,
extensions::SettingsApiOverrideType type);
virtual ~SettingsApiBubbleDelegate();
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 LogExtensionCount(size_t count) OVERRIDE;
virtual void LogAction(
extensions::ExtensionMessageBubbleController::BubbleAction action)
OVERRIDE;
private:
ExtensionService* service_;
Profile* profile_;
extensions::SettingsApiOverrideType type_;
std::string extension_id_;
DISALLOW_COPY_AND_ASSIGN(SettingsApiBubbleDelegate);
};
SettingsApiBubbleDelegate::SettingsApiBubbleDelegate(
ExtensionService* service,
Profile* profile,
extensions::SettingsApiOverrideType type)
: service_(service), profile_(profile), type_(type) {}
SettingsApiBubbleDelegate::~SettingsApiBubbleDelegate() {}
bool SettingsApiBubbleDelegate::ShouldIncludeExtension(
const std::string& extension_id) {
using extensions::ExtensionRegistry;
ExtensionRegistry* registry = ExtensionRegistry::Get(profile_);
const extensions::Extension* extension =
registry->GetExtensionById(extension_id, ExtensionRegistry::ENABLED);
if (!extension)
return false;
extensions::ExtensionPrefs* prefs = extensions::ExtensionPrefs::Get(profile_);
if (prefs->HasSettingsApiBubbleBeenAcknowledged(extension_id))
return false;
const extensions::Extension* override = NULL;
switch (type_) {
case extensions::BUBBLE_TYPE_HOME_PAGE:
override = extensions::OverridesHomepage(profile_, NULL);
break;
case extensions::BUBBLE_TYPE_STARTUP_PAGES:
override = extensions::OverridesStartupPages(profile_, NULL);
break;
case extensions::BUBBLE_TYPE_SEARCH_ENGINE:
override = extensions::OverridesSearchEngine(profile_, NULL);
break;
}
if (!override || override->id() != extension->id())
return false;
extension_id_ = extension_id;
return true;
}
void SettingsApiBubbleDelegate::AcknowledgeExtension(
const std::string& extension_id,
ExtensionMessageBubbleController::BubbleAction user_action) {
if (user_action != ExtensionMessageBubbleController::ACTION_EXECUTE) {
extensions::ExtensionPrefs* prefs =
extensions::ExtensionPrefs::Get(profile_);
prefs->SetSettingsApiBubbleBeenAcknowledged(extension_id, true);
}
}
void SettingsApiBubbleDelegate::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 SettingsApiBubbleDelegate::GetTitle() const {
switch (type_) {
case extensions::BUBBLE_TYPE_HOME_PAGE:
return l10n_util::GetStringUTF16(
IDS_EXTENSIONS_SETTINGS_API_TITLE_HOME_PAGE_BUBBLE);
case extensions::BUBBLE_TYPE_STARTUP_PAGES:
return l10n_util::GetStringUTF16(
IDS_EXTENSIONS_SETTINGS_API_TITLE_STARTUP_PAGES_BUBBLE);
case extensions::BUBBLE_TYPE_SEARCH_ENGINE:
return l10n_util::GetStringUTF16(
IDS_EXTENSIONS_SETTINGS_API_TITLE_SEARCH_ENGINE_BUBBLE);
}
NOTREACHED();
return base::string16();
}
base::string16 SettingsApiBubbleDelegate::GetMessageBody() const {
using extensions::ExtensionRegistry;
ExtensionRegistry* registry = ExtensionRegistry::Get(profile_);
const extensions::Extension* extension =
registry->GetExtensionById(extension_id_, ExtensionRegistry::ENABLED);
const SettingsOverrides* settings =
extension ? SettingsOverrides::Get(extension) : NULL;
if (!extension || !settings) {
NOTREACHED();
return base::string16();
}
bool home_change = settings->homepage != NULL;
bool startup_change = !settings->startup_pages.empty();
bool search_change = settings->search_engine != NULL;
base::string16 body;
switch (type_) {
case extensions::BUBBLE_TYPE_HOME_PAGE:
body = l10n_util::GetStringUTF16(
IDS_EXTENSIONS_SETTINGS_API_FIRST_LINE_HOME_PAGE);
if (startup_change && search_change) {
body += l10n_util::GetStringUTF16(
IDS_EXTENSIONS_SETTINGS_API_SECOND_LINE_START_AND_SEARCH);
} else if (startup_change) {
body += l10n_util::GetStringUTF16(
IDS_EXTENSIONS_SETTINGS_API_SECOND_LINE_START_PAGES);
} else if (search_change) {
body += l10n_util::GetStringUTF16(
IDS_EXTENSIONS_SETTINGS_API_SECOND_LINE_SEARCH_ENGINE);
}
break;
case extensions::BUBBLE_TYPE_STARTUP_PAGES:
body = l10n_util::GetStringUTF16(
IDS_EXTENSIONS_SETTINGS_API_FIRST_LINE_START_PAGES);
if (home_change && search_change) {
body += l10n_util::GetStringUTF16(
IDS_EXTENSIONS_SETTINGS_API_SECOND_LINE_HOME_AND_SEARCH);
} else if (home_change) {
body += l10n_util::GetStringUTF16(
IDS_EXTENSIONS_SETTINGS_API_SECOND_LINE_HOME_PAGE);
} else if (search_change) {
body += l10n_util::GetStringUTF16(
IDS_EXTENSIONS_SETTINGS_API_SECOND_LINE_SEARCH_ENGINE);
}
break;
case extensions::BUBBLE_TYPE_SEARCH_ENGINE:
body = l10n_util::GetStringUTF16(
IDS_EXTENSIONS_SETTINGS_API_FIRST_LINE_SEARCH_ENGINE);
if (startup_change && home_change) {
body += l10n_util::GetStringUTF16(
IDS_EXTENSIONS_SETTINGS_API_SECOND_LINE_START_AND_HOME);
} else if (startup_change) {
body += l10n_util::GetStringUTF16(
IDS_EXTENSIONS_SETTINGS_API_SECOND_LINE_START_PAGES);
} else if (home_change) {
body += l10n_util::GetStringUTF16(
IDS_EXTENSIONS_SETTINGS_API_SECOND_LINE_HOME_PAGE);
}
break;
}
if (!body.empty())
body += l10n_util::GetStringUTF16(
IDS_EXTENSIONS_SETTINGS_API_THIRD_LINE_CONFIRMATION);
return body;
}
base::string16 SettingsApiBubbleDelegate::GetOverflowText(
const base::string16& overflow_count) const {
NOTREACHED();
return base::string16();
}
base::string16 SettingsApiBubbleDelegate::GetLearnMoreLabel() const {
return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
}
GURL SettingsApiBubbleDelegate::GetLearnMoreUrl() const {
return GURL(chrome::kSettingsApiLearnMoreURL);
}
base::string16 SettingsApiBubbleDelegate::GetActionButtonLabel() const {
return l10n_util::GetStringUTF16(
IDS_EXTENSIONS_SETTINGS_API_RESTORE_SETTINGS);
}
base::string16 SettingsApiBubbleDelegate::GetDismissButtonLabel() const {
return l10n_util::GetStringUTF16(IDS_EXTENSIONS_SETTINGS_API_KEEP_CHANGES);
}
bool SettingsApiBubbleDelegate::ShouldShowExtensionList() const {
return false;
}
void SettingsApiBubbleDelegate::LogExtensionCount(size_t count) {
UMA_HISTOGRAM_COUNTS_100("SettingsApiBubble.ExtensionCount", count);
}
void SettingsApiBubbleDelegate::LogAction(
ExtensionMessageBubbleController::BubbleAction action) {
UMA_HISTOGRAM_ENUMERATION("SettingsApiBubble.UserSelection",
action,
ExtensionMessageBubbleController::ACTION_BOUNDARY);
}
}
namespace extensions {
SettingsApiBubbleController::SettingsApiBubbleController(
Profile* profile,
SettingsApiOverrideType type)
: ExtensionMessageBubbleController(
new SettingsApiBubbleDelegate(
ExtensionSystem::Get(profile)->extension_service(),
profile,
type),
profile),
profile_(profile),
type_(type) {}
SettingsApiBubbleController::~SettingsApiBubbleController() {}
bool SettingsApiBubbleController::ShouldShow(const std::string& extension_id) {
extensions::ExtensionPrefs* prefs = extensions::ExtensionPrefs::Get(profile_);
if (prefs->HasSettingsApiBubbleBeenAcknowledged(extension_id))
return false;
if (!delegate()->ShouldIncludeExtension(extension_id))
return false;
if (type_ == BUBBLE_TYPE_STARTUP_PAGES)
return profile_->GetLastSessionExitType() != Profile::EXIT_CRASHED;
return true;
}
bool SettingsApiBubbleController::CloseOnDeactivate() {
return type_ != BUBBLE_TYPE_STARTUP_PAGES;
}
}