Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/common/renderer_configuration_struct_traits.h" | |
| 6 | |
| 7 namespace mojo { | |
| 8 | |
| 9 // static | |
| 10 | |
| 11 chrome::mojom::ContentSetting | |
| 12 EnumTraits<chrome::mojom::ContentSetting, ContentSetting>::ToMojom( | |
| 13 ContentSetting setting) { | |
| 14 switch (setting) { | |
| 15 case CONTENT_SETTING_DEFAULT: | |
| 16 return chrome::mojom::ContentSetting::CONTENT_SETTING_DEFAULT; | |
| 17 case CONTENT_SETTING_ALLOW: | |
| 18 return chrome::mojom::ContentSetting::CONTENT_SETTING_ALLOW; | |
| 19 case CONTENT_SETTING_BLOCK: | |
| 20 return chrome::mojom::ContentSetting::CONTENT_SETTING_BLOCK; | |
| 21 case CONTENT_SETTING_ASK: | |
| 22 return chrome::mojom::ContentSetting::CONTENT_SETTING_ASK; | |
| 23 case CONTENT_SETTING_SESSION_ONLY: | |
| 24 return chrome::mojom::ContentSetting::CONTENT_SETTING_SESSION_ONLY; | |
| 25 case CONTENT_SETTING_DETECT_IMPORTANT_CONTENT: | |
| 26 return chrome::mojom::ContentSetting:: | |
| 27 CONTENT_SETTING_DETECT_IMPORTANT_CONTENT; | |
| 28 // XXX: Should we really catch the "NUM_SETTINGS" dummy value that defines | |
|
Sam McNally
2016/12/19 00:17:51
I think I would leave it out of the mojom enum ent
nigeltao1
2016/12/22 04:09:46
Done.
| |
| 29 // a convenient constant for the number of enum values, not a semantically | |
| 30 // valid enum value in its own right? Ditto below. | |
| 31 case CONTENT_SETTING_NUM_SETTINGS: | |
| 32 return chrome::mojom::ContentSetting::CONTENT_SETTING_NUM_SETTINGS; | |
| 33 default: | |
|
Sam McNally
2016/12/19 00:17:51
Put the catchall outside the switch instead of usi
nigeltao1
2016/12/22 04:09:46
Done.
| |
| 34 // XXX: The NOTREACHED here mimics the one in | |
| 35 // ui/base/mojo/window_open_disposition_enum_traits.h | |
| 36 // | |
| 37 // Can we really assert NOTREACHED if Mojo messages can come from | |
| 38 // malicious renderers? Ditto below. | |
|
Sam McNally
2016/12/19 00:17:51
Yes. This NOTREACHED would be hit in the sender of
nigeltao1
2016/12/22 04:09:46
Acknowledged.
| |
| 39 NOTREACHED(); | |
| 40 return chrome::mojom::ContentSetting::CONTENT_SETTING_DEFAULT; | |
| 41 } | |
| 42 } | |
| 43 | |
| 44 // static | |
| 45 bool EnumTraits<chrome::mojom::ContentSetting, ContentSetting>::FromMojom( | |
| 46 chrome::mojom::ContentSetting setting, | |
| 47 ContentSetting* out) { | |
| 48 switch (setting) { | |
| 49 case chrome::mojom::ContentSetting::CONTENT_SETTING_DEFAULT: | |
| 50 *out = CONTENT_SETTING_DEFAULT; | |
| 51 return true; | |
| 52 case chrome::mojom::ContentSetting::CONTENT_SETTING_ALLOW: | |
| 53 *out = CONTENT_SETTING_ALLOW; | |
| 54 return true; | |
| 55 case chrome::mojom::ContentSetting::CONTENT_SETTING_BLOCK: | |
| 56 *out = CONTENT_SETTING_BLOCK; | |
| 57 return true; | |
| 58 case chrome::mojom::ContentSetting::CONTENT_SETTING_ASK: | |
| 59 *out = CONTENT_SETTING_ASK; | |
| 60 return true; | |
| 61 case chrome::mojom::ContentSetting::CONTENT_SETTING_SESSION_ONLY: | |
| 62 *out = CONTENT_SETTING_SESSION_ONLY; | |
| 63 return true; | |
| 64 case chrome::mojom::ContentSetting:: | |
| 65 CONTENT_SETTING_DETECT_IMPORTANT_CONTENT: | |
| 66 *out = CONTENT_SETTING_DETECT_IMPORTANT_CONTENT; | |
| 67 return true; | |
| 68 case chrome::mojom::ContentSetting::CONTENT_SETTING_NUM_SETTINGS: | |
| 69 *out = CONTENT_SETTING_NUM_SETTINGS; | |
| 70 return true; | |
| 71 default: | |
| 72 NOTREACHED(); | |
|
Sam McNally
2016/12/19 00:17:51
Again, move this out of the switch. I think it mak
nigeltao1
2016/12/22 04:09:45
Done.
| |
| 73 return false; | |
| 74 } | |
| 75 } | |
| 76 | |
| 77 // Note that the {primary,secondary}_pattern methods aren't simple getters. | |
| 78 // They serialize the ContentSettingsPattern to a string. | |
| 79 | |
| 80 // static | |
| 81 const std::string | |
|
Sam McNally
2016/12/19 00:17:51
This is inefficient. This accessor is called twice
nigeltao1
2016/12/22 04:09:45
No longer applicable, as I serialize the underlyin
| |
| 82 StructTraits<chrome::mojom::ContentSettingPatternSourceDataView, | |
| 83 ContentSettingPatternSource>:: | |
| 84 primary_pattern(const ContentSettingPatternSource& r) { | |
| 85 return r.primary_pattern.ToString(); | |
| 86 } | |
| 87 | |
| 88 // static | |
| 89 const std::string | |
| 90 StructTraits<chrome::mojom::ContentSettingPatternSourceDataView, | |
| 91 ContentSettingPatternSource>:: | |
| 92 secondary_pattern(const ContentSettingPatternSource& r) { | |
| 93 return r.secondary_pattern.ToString(); | |
| 94 } | |
| 95 | |
| 96 // static | |
| 97 ContentSetting StructTraits<chrome::mojom::ContentSettingPatternSourceDataView, | |
| 98 ContentSettingPatternSource>:: | |
| 99 setting(const ContentSettingPatternSource& r) { | |
| 100 return r.setting; | |
| 101 } | |
| 102 | |
| 103 // static | |
| 104 const std::string& StructTraits< | |
| 105 chrome::mojom::ContentSettingPatternSourceDataView, | |
| 106 ContentSettingPatternSource>::source(const ContentSettingPatternSource& r) { | |
| 107 return r.source; | |
| 108 } | |
| 109 | |
| 110 // static | |
| 111 bool StructTraits<chrome::mojom::ContentSettingPatternSourceDataView, | |
| 112 ContentSettingPatternSource>:: | |
| 113 incognito(const ContentSettingPatternSource& r) { | |
| 114 return r.incognito; | |
| 115 } | |
| 116 | |
| 117 // static | |
| 118 bool StructTraits<chrome::mojom::ContentSettingPatternSourceDataView, | |
| 119 ContentSettingPatternSource>:: | |
| 120 Read(chrome::mojom::ContentSettingPatternSourceDataView data, | |
| 121 ContentSettingPatternSource* out) { | |
| 122 std::string primary_pattern; | |
| 123 std::string secondary_pattern; | |
| 124 if (!data.ReadPrimaryPattern(&primary_pattern) || | |
| 125 !data.ReadSecondaryPattern(&secondary_pattern) || | |
| 126 !data.ReadSetting(&out->setting) || !data.ReadSource(&out->source)) | |
| 127 return false; | |
| 128 out->primary_pattern = ContentSettingsPattern::FromString(primary_pattern); | |
| 129 out->secondary_pattern = | |
| 130 ContentSettingsPattern::FromString(secondary_pattern); | |
| 131 out->incognito = data.incognito(); | |
| 132 return true; | |
| 133 } | |
| 134 | |
| 135 // static | |
| 136 const std::vector<ContentSettingPatternSource>& StructTraits< | |
| 137 chrome::mojom::RendererContentSettingRulesDataView, | |
| 138 RendererContentSettingRules>::image_rules(const RendererContentSettingRules& | |
| 139 r) { | |
| 140 return r.image_rules; | |
| 141 } | |
| 142 | |
| 143 // static | |
| 144 const std::vector<ContentSettingPatternSource>& | |
| 145 StructTraits<chrome::mojom::RendererContentSettingRulesDataView, | |
| 146 RendererContentSettingRules>:: | |
| 147 script_rules(const RendererContentSettingRules& r) { | |
| 148 return r.script_rules; | |
| 149 } | |
| 150 | |
| 151 // static | |
| 152 const std::vector<ContentSettingPatternSource>& | |
| 153 StructTraits<chrome::mojom::RendererContentSettingRulesDataView, | |
| 154 RendererContentSettingRules>:: | |
| 155 autoplay_rules(const RendererContentSettingRules& r) { | |
| 156 return r.autoplay_rules; | |
| 157 } | |
| 158 | |
| 159 // static | |
| 160 bool StructTraits<chrome::mojom::RendererContentSettingRulesDataView, | |
| 161 RendererContentSettingRules>:: | |
| 162 Read(chrome::mojom::RendererContentSettingRulesDataView data, | |
| 163 RendererContentSettingRules* out) { | |
| 164 return data.ReadImageRules(&out->image_rules) && | |
| 165 data.ReadScriptRules(&out->script_rules) && | |
| 166 data.ReadAutoplayRules(&out->autoplay_rules); | |
| 167 } | |
| 168 | |
| 169 } // namespace mojo | |
| OLD | NEW |