1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
// Copyright (c) 2011 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/extension_content_settings_helpers.h"
#include "base/basictypes.h"
#include "base/logging.h"
namespace {
const char* const kContentSettingsTypeNames[] = {
"cookies",
"images",
"javascript",
"plugins",
"popups",
"location",
"notifications",
};
COMPILE_ASSERT(arraysize(kContentSettingsTypeNames) <=
CONTENT_SETTINGS_NUM_TYPES,
content_settings_type_names_size_invalid);
const char* const kContentSettingNames[] = {
"default",
"allow",
"block",
"ask",
"session_only",
};
COMPILE_ASSERT(arraysize(kContentSettingNames) <=
CONTENT_SETTING_NUM_SETTINGS,
content_setting_names_size_invalid);
} // namespace
namespace extension_content_settings_helpers {
ContentSettingsType StringToContentSettingsType(
const std::string& content_type) {
for (size_t type = 0; type < arraysize(kContentSettingsTypeNames); ++type) {
if (content_type == kContentSettingsTypeNames[type])
return static_cast<ContentSettingsType>(type);
}
return CONTENT_SETTINGS_TYPE_DEFAULT;
}
const char* ContentSettingsTypeToString(ContentSettingsType type) {
size_t index = static_cast<size_t>(type);
DCHECK_LT(index, arraysize(kContentSettingsTypeNames));
return kContentSettingsTypeNames[index];
}
bool StringToContentSetting(const std::string& setting_str,
ContentSetting* setting) {
for (size_t type = 0; type < arraysize(kContentSettingNames); ++type) {
if (setting_str == kContentSettingNames[type]) {
*setting = static_cast<ContentSetting>(type);
return true;
}
}
return false;
}
const char* ContentSettingToString(ContentSetting setting) {
size_t index = static_cast<size_t>(setting);
DCHECK_LT(index, arraysize(kContentSettingNames));
return kContentSettingNames[index];
}
} // namespace extension_content_settings_helpers
|