Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_UI_WEBUI_SITE_SETTINGS_HELPER_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_SITE_SETTINGS_HELPER_H_ |
| 6 #define CHROME_BROWSER_UI_WEBUI_SITE_SETTINGS_HELPER_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_SITE_SETTINGS_HELPER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "components/content_settings/core/common/content_settings.h" | 12 #include "components/content_settings/core/common/content_settings.h" |
| 13 #include "components/content_settings/core/common/content_settings_pattern.h" | 13 #include "components/content_settings/core/common/content_settings_pattern.h" |
| 14 #include "components/content_settings/core/common/content_settings_types.h" | 14 #include "components/content_settings/core/common/content_settings_types.h" |
| 15 #include "content/public/browser/web_ui.h" | 15 #include "content/public/browser/web_ui.h" |
| 16 | 16 |
| 17 class ChooserContextBase; | |
| 17 class HostContentSettingsMap; | 18 class HostContentSettingsMap; |
| 19 class Profile; | |
| 18 | 20 |
| 19 namespace base { | 21 namespace base { |
| 20 class DictionaryValue; | 22 class DictionaryValue; |
| 21 class ListValue; | 23 class ListValue; |
| 22 } | 24 } |
| 23 | 25 |
| 24 namespace site_settings { | 26 namespace site_settings { |
| 25 | 27 |
| 26 // Maps from a secondary pattern to a setting. | 28 // Maps from a secondary pattern to a setting. |
| 27 typedef std::map<ContentSettingsPattern, ContentSetting> | 29 typedef std::map<ContentSettingsPattern, ContentSetting> |
| 28 OnePatternSettings; | 30 OnePatternSettings; |
| 29 // Maps from a primary pattern/source pair to a OnePatternSettings. All the | 31 // Maps from a primary pattern/source pair to a OnePatternSettings. All the |
| 30 // mappings in OnePatternSettings share the given primary pattern and source. | 32 // mappings in OnePatternSettings share the given primary pattern and source. |
| 31 typedef std::map<std::pair<ContentSettingsPattern, std::string>, | 33 typedef std::map<std::pair<ContentSettingsPattern, std::string>, |
| 32 OnePatternSettings> | 34 OnePatternSettings> |
| 33 AllPatternsSettings; | 35 AllPatternsSettings; |
| 34 | 36 |
| 35 extern const char kSetting[]; | 37 extern const char kSetting[]; |
| 36 extern const char kOrigin[]; | 38 extern const char kOrigin[]; |
| 37 extern const char kPolicyProviderId[]; | 39 extern const char kPolicyProviderId[]; |
| 38 extern const char kSource[]; | 40 extern const char kSource[]; |
| 39 extern const char kEmbeddingOrigin[]; | 41 extern const char kEmbeddingOrigin[]; |
| 40 extern const char kPreferencesSource[]; | 42 extern const char kPreferencesSource[]; |
| 41 | 43 |
| 44 // Group types. | |
| 45 extern const char kGroupTypeUsb[]; | |
| 46 | |
| 42 // Returns whether a group name has been registered for the given type. | 47 // Returns whether a group name has been registered for the given type. |
| 43 bool HasRegisteredGroupName(ContentSettingsType type); | 48 bool HasRegisteredGroupName(ContentSettingsType type); |
| 44 | 49 |
| 45 // Gets a content settings type from the group name identifier. | 50 // Gets a content settings type from the group name identifier. |
| 46 ContentSettingsType ContentSettingsTypeFromGroupName(const std::string& name); | 51 ContentSettingsType ContentSettingsTypeFromGroupName(const std::string& name); |
| 47 | 52 |
| 48 // Gets a string identifier for the group name. | 53 // Gets a string identifier for the group name. |
| 49 std::string ContentSettingsTypeToGroupName(ContentSettingsType type); | 54 std::string ContentSettingsTypeToGroupName(ContentSettingsType type); |
| 50 | 55 |
| 51 // Fills in |exceptions| with Values for the given |type| from |map|. | 56 // Fills in |exceptions| with Values for the given |type| from |map|. |
| 52 void GetExceptionsFromHostContentSettingsMap( | 57 void GetExceptionsFromHostContentSettingsMap( |
| 53 const HostContentSettingsMap* map, | 58 const HostContentSettingsMap* map, |
| 54 ContentSettingsType type, | 59 ContentSettingsType type, |
| 55 content::WebUI* web_ui, | 60 content::WebUI* web_ui, |
| 56 base::ListValue* exceptions); | 61 base::ListValue* exceptions); |
| 57 | 62 |
| 58 // Returns exceptions constructed from the policy-set allowed URLs | 63 // Returns exceptions constructed from the policy-set allowed URLs |
| 59 // for the content settings |type| mic or camera. | 64 // for the content settings |type| mic or camera. |
| 60 void GetPolicyAllowedUrls( | 65 void GetPolicyAllowedUrls( |
| 61 ContentSettingsType type, | 66 ContentSettingsType type, |
| 62 std::vector<std::unique_ptr<base::DictionaryValue>>* exceptions, | 67 std::vector<std::unique_ptr<base::DictionaryValue>>* exceptions, |
| 63 content::WebUI* web_ui); | 68 content::WebUI* web_ui); |
| 64 | 69 |
| 70 // This struct is declared early so that it can used by functions below. | |
|
dschuyler
2016/08/11 23:28:07
I'd rather this comment said something about what
Finnur
2016/08/12 13:11:26
Took a stab at it.
| |
| 71 struct ChooserTypeNameEntry { | |
| 72 ContentSettingsType type; | |
| 73 ChooserContextBase* (*get_context)(Profile*); | |
| 74 const char* name; | |
| 75 const char* ui_name_key; | |
| 76 }; | |
| 77 | |
| 78 ChooserContextBase* GetUsbChooserContext(Profile* profile); | |
| 79 | |
| 80 struct ContentSettingsTypeNameEntry { | |
| 81 ContentSettingsType type; | |
| 82 const char* name; | |
| 83 }; | |
| 84 | |
| 85 const ContentSettingsTypeNameEntry kContentSettingsTypeGroupNames[] = { | |
| 86 {CONTENT_SETTINGS_TYPE_COOKIES, "cookies"}, | |
| 87 {CONTENT_SETTINGS_TYPE_IMAGES, "images"}, | |
| 88 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, "javascript"}, | |
| 89 {CONTENT_SETTINGS_TYPE_PLUGINS, "plugins"}, | |
| 90 {CONTENT_SETTINGS_TYPE_POPUPS, "popups"}, | |
| 91 {CONTENT_SETTINGS_TYPE_GEOLOCATION, "location"}, | |
| 92 {CONTENT_SETTINGS_TYPE_NOTIFICATIONS, "notifications"}, | |
| 93 {CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, "auto-select-certificate"}, | |
| 94 {CONTENT_SETTINGS_TYPE_FULLSCREEN, "fullscreen"}, | |
| 95 {CONTENT_SETTINGS_TYPE_MOUSELOCK, "mouselock"}, | |
| 96 {CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, "register-protocol-handler"}, | |
| 97 {CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, "media-stream-mic"}, | |
| 98 {CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, "media-stream-camera"}, | |
| 99 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, "ppapi-broker"}, | |
| 100 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, "multiple-automatic-downloads"}, | |
| 101 {CONTENT_SETTINGS_TYPE_MIDI_SYSEX, "midi-sysex"}, | |
| 102 {CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS, "ssl-cert-decisions"}, | |
| 103 #if defined(OS_CHROMEOS) | |
| 104 {CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER, "protectedContent"}, | |
| 105 #endif | |
| 106 {CONTENT_SETTINGS_TYPE_KEYGEN, "keygen"}, | |
| 107 {CONTENT_SETTINGS_TYPE_BACKGROUND_SYNC, "background-sync"}, | |
| 108 }; | |
| 109 | |
| 110 const ChooserTypeNameEntry kChooserTypeGroupNames[] = { | |
| 111 {CONTENT_SETTINGS_TYPE_USB_CHOOSER_DATA, &GetUsbChooserContext, | |
| 112 kGroupTypeUsb, "name"}, | |
| 113 }; | |
| 114 | |
| 115 const ChooserTypeNameEntry* ChooserTypeFromGroupName(const std::string& name); | |
| 116 | |
| 117 // Fills in |exceptions| with Values for the given |type| from |map|. | |
| 118 void GetChooserExceptionsFromProfile( | |
| 119 Profile* profile, | |
| 120 bool incognito, | |
| 121 const ChooserTypeNameEntry& chooser_type, | |
| 122 base::ListValue* exceptions); | |
| 123 | |
| 65 } // namespace site_settings | 124 } // namespace site_settings |
| 66 | 125 |
| 67 #endif // CHROME_BROWSER_UI_WEBUI_SITE_SETTINGS_HELPER_H_ | 126 #endif // CHROME_BROWSER_UI_WEBUI_SITE_SETTINGS_HELPER_H_ |
| OLD | NEW |