This source file includes following definitions.
- IsImportantWarning
- flags_
- ControlGroup
- Find
- GetExplanationText
- GetOkButtonText
- GetCancelButtonText
- text_only
- ShouldHighlightText
- ShouldHighlightBackground
- show_details_link
- show_checkboxes
- should_show_expandable_permission_list
- should_show_inline_explanations
- GetInlineExplanation
#include "base/basictypes.h"
#include "base/logging.h"
#include "base/metrics/field_trial.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/stringprintf.h"
#include "chrome/browser/extensions/extension_install_prompt_experiment.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
namespace {
const char kExperimentName[] = "ExtensionPermissionDialog";
const char kGroupPrefix[] = "Group";
enum GroupFlag {
NONE = 0,
TEXT_ONLY = 1 << 0,
INLINE_EXPLANATIONS = 1 << 1,
SHOULD_HIGHLIGHT_TEXT = 1 << 2,
SHOULD_HIGHLIGHT_BACKGROUND = 1 << 3,
SHOULD_HIGHLIGHT_ALL_PERMISSIONS = 1 << 4,
SHOULD_SHOW_DETAILS_LINK = 1 << 5,
EXPANDABLE_PERMISSION_LIST = 1 << 6,
SHOULD_SHOW_CHECKBOXES = 1 << 7
};
const unsigned int kGroupFlags[] = {
NONE,
TEXT_ONLY,
TEXT_ONLY,
TEXT_ONLY,
TEXT_ONLY,
TEXT_ONLY,
INLINE_EXPLANATIONS,
SHOULD_SHOW_DETAILS_LINK | INLINE_EXPLANATIONS,
SHOULD_SHOW_DETAILS_LINK | EXPANDABLE_PERMISSION_LIST,
SHOULD_HIGHLIGHT_TEXT,
SHOULD_HIGHLIGHT_BACKGROUND,
SHOULD_HIGHLIGHT_BACKGROUND | SHOULD_HIGHLIGHT_ALL_PERMISSIONS,
SHOULD_SHOW_CHECKBOXES
};
const size_t kGroupCount = arraysize(kGroupFlags);
const struct TextParams {
int text_id;
int ok_text_id;
int cancel_text_id;
} kTextParams[] = {
{
IDS_EXTENSION_PROMPT_EXPERIMENT_EXPLANATION1,
IDS_EXTENSION_PROMPT_EXPERIMENT_INSTALL_BUTTON_TRUST,
IDS_CANCEL,
},
{
IDS_EXTENSION_PROMPT_EXPERIMENT_EXPLANATION2,
IDS_EXTENSION_PROMPT_EXPERIMENT_INSTALL_BUTTON_YES,
IDS_EXTENSION_PROMPT_EXPERIMENT_INSTALL_BUTTON_NOPE
},
{
IDS_EXTENSION_PROMPT_EXPERIMENT_EXPLANATION3,
IDS_EXTENSION_PROMPT_EXPERIMENT_INSTALL_BUTTON_SURE,
IDS_EXTENSION_PROMPT_EXPERIMENT_INSTALL_BUTTON_NOPE
},
{
IDS_EXTENSION_PROMPT_EXPERIMENT_EXPLANATION4,
IDS_EXTENSION_PROMPT_INSTALL_BUTTON,
IDS_CANCEL
},
{
IDS_EXTENSION_PROMPT_EXPERIMENT_EXPLANATION5,
IDS_EXTENSION_PROMPT_EXPERIMENT_INSTALL_BUTTON_TRUST2,
IDS_EXTENSION_PROMPT_EXPERIMENT_INSTALL_BUTTON_NOPE
}
};
const struct PermissionExplanations {
int warning_msg_id;
int extra_explanation_id;
} kPermissionExplanations[] = {
{
IDS_EXTENSION_PROMPT_WARNING_FULL_ACCESS,
IDS_EXTENSION_PROMPT_WARNING_FULL_ACCESS_EXPLANATION
},
{
IDS_EXTENSION_PROMPT_WARNING_ALL_HOSTS,
IDS_EXTENSION_PROMPT_WARNING_ALL_HOSTS_EXPLANATION
}
};
const int kHighlightedWarnings[] = {
IDS_EXTENSION_PROMPT_WARNING_FULL_ACCESS,
IDS_EXTENSION_PROMPT_WARNING_ALL_HOSTS,
IDS_EXTENSION_PROMPT_WARNING_BOOKMARKS,
IDS_EXTENSION_PROMPT_WARNING_CONTENT_SETTINGS,
IDS_EXTENSION_PROMPT_WARNING_BROWSING_HISTORY,
IDS_EXTENSION_PROMPT_WARNING_INPUT,
IDS_EXTENSION_PROMPT_WARNING_MANAGEMENT,
IDS_EXTENSION_PROMPT_WARNING_TABS,
IDS_EXTENSION_PROMPT_WARNING_DEBUGGER
};
bool IsImportantWarning(const base::string16& message) {
for (size_t i = 0; i < arraysize(kHighlightedWarnings); ++i) {
if (message == l10n_util::GetStringUTF16(kHighlightedWarnings[i]))
return true;
}
return false;
}
}
ExtensionInstallPromptExperiment::ExtensionInstallPromptExperiment(
unsigned int group_id, unsigned int flags)
: group_id_(group_id),
flags_(flags) {
}
ExtensionInstallPromptExperiment::~ExtensionInstallPromptExperiment() {
}
ExtensionInstallPromptExperiment*
ExtensionInstallPromptExperiment::ControlGroup() {
return new ExtensionInstallPromptExperiment(0, kGroupFlags[0]);
}
ExtensionInstallPromptExperiment*
ExtensionInstallPromptExperiment::Find() {
base::FieldTrial* trial = base::FieldTrialList::Find(kExperimentName);
unsigned int group_id = 0;
if (trial) {
std::vector<std::string> tokens;
base::SplitString(trial->group_name().c_str(), '_', &tokens);
if (tokens.size() == 2 && tokens[0] == kGroupPrefix) {
base::StringToUint(tokens[1], &group_id);
if (group_id >= kGroupCount)
group_id = 0;
}
}
return new ExtensionInstallPromptExperiment(group_id, kGroupFlags[group_id]);
}
base::string16 ExtensionInstallPromptExperiment::GetExplanationText() const {
DCHECK(group_id_ > 0 && group_id_ - 1 < arraysize(kTextParams));
return l10n_util::GetStringUTF16(kTextParams[group_id_ - 1].text_id);
}
base::string16 ExtensionInstallPromptExperiment::GetOkButtonText() const {
DCHECK(group_id_ > 0 && group_id_ - 1 < arraysize(kTextParams));
return l10n_util::GetStringUTF16(kTextParams[group_id_ - 1].ok_text_id);
}
base::string16 ExtensionInstallPromptExperiment::GetCancelButtonText() const {
DCHECK(group_id_ > 0 && group_id_ - 1 < arraysize(kTextParams));
return l10n_util::GetStringUTF16(kTextParams[group_id_ - 1].cancel_text_id);
}
bool ExtensionInstallPromptExperiment::text_only() const {
return (flags_ & TEXT_ONLY) != 0;
}
bool ExtensionInstallPromptExperiment::ShouldHighlightText(
const base::string16& message) const {
return (flags_ & SHOULD_HIGHLIGHT_TEXT) != 0 && IsImportantWarning(message);
}
bool ExtensionInstallPromptExperiment::ShouldHighlightBackground(
const base::string16& message) const {
return (flags_ & SHOULD_HIGHLIGHT_BACKGROUND) != 0 &&
((flags_ & SHOULD_HIGHLIGHT_ALL_PERMISSIONS) != 0 ||
IsImportantWarning(message));
}
bool ExtensionInstallPromptExperiment::show_details_link() const {
return (flags_ & SHOULD_SHOW_DETAILS_LINK) != 0;
}
bool ExtensionInstallPromptExperiment::show_checkboxes() const {
return (flags_ & SHOULD_SHOW_CHECKBOXES) != 0;
}
bool ExtensionInstallPromptExperiment::should_show_expandable_permission_list()
const {
return (flags_ & EXPANDABLE_PERMISSION_LIST) != 0;
}
bool ExtensionInstallPromptExperiment::should_show_inline_explanations() const {
return (flags_ & INLINE_EXPLANATIONS) != 0;
}
base::string16 ExtensionInstallPromptExperiment::GetInlineExplanation(
const base::string16& message) const {
for (size_t i = 0; i < arraysize(kPermissionExplanations); ++i) {
if (message == l10n_util::GetStringUTF16(
kPermissionExplanations[i].warning_msg_id)) {
return l10n_util::GetStringUTF16(
kPermissionExplanations[i].extra_explanation_id);
}
}
return base::string16();
}