OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS2_CONTENT_SETTINGS_HANDLER_H_ | |
6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS2_CONTENT_SETTINGS_HANDLER_H_ | |
7 | |
8 #include <map> | |
9 #include <string> | |
10 | |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "chrome/browser/pepper_flash_settings_manager.h" | |
13 #include "chrome/browser/prefs/pref_change_registrar.h" | |
14 #include "chrome/browser/ui/webui/options2/options_ui.h" | |
15 #include "chrome/common/content_settings_types.h" | |
16 #include "chrome/common/content_settings.h" | |
17 #include "content/public/browser/notification_observer.h" | |
18 #include "content/public/browser/notification_registrar.h" | |
19 | |
20 class HostContentSettingsMap; | |
21 class ProtocolHandlerRegistry; | |
22 | |
23 namespace options { | |
24 | |
25 class ContentSettingsHandler : public OptionsPageUIHandler, | |
26 public PepperFlashSettingsManager::Client { | |
27 public: | |
28 ContentSettingsHandler(); | |
29 virtual ~ContentSettingsHandler(); | |
30 | |
31 // OptionsPageUIHandler implementation. | |
32 virtual void GetLocalizedValues( | |
33 base::DictionaryValue* localized_strings) OVERRIDE; | |
34 virtual void InitializeHandler() OVERRIDE; | |
35 virtual void InitializePage() OVERRIDE; | |
36 virtual void RegisterMessages() OVERRIDE; | |
37 | |
38 // content::NotificationObserver implementation. | |
39 virtual void Observe(int type, | |
40 const content::NotificationSource& source, | |
41 const content::NotificationDetails& details) OVERRIDE; | |
42 | |
43 // PepperFlashSettingsManager::Client implementation. | |
44 virtual void OnGetPermissionSettingsCompleted( | |
45 uint32 request_id, | |
46 bool success, | |
47 PP_Flash_BrowserOperations_Permission default_permission, | |
48 const ppapi::FlashSiteSettings& sites) OVERRIDE; | |
49 | |
50 // Gets a string identifier for the group name, for use in HTML. | |
51 static std::string ContentSettingsTypeToGroupName(ContentSettingsType type); | |
52 | |
53 private: | |
54 // Extends ContentSettingsType with some other types that will be also | |
55 // displayed in the content settings UI. | |
56 class ExContentSettingsType; | |
57 struct ExContentSettingsTypeNameEntry; | |
58 | |
59 struct CachedPepperFlashSettings { | |
60 CachedPepperFlashSettings(); | |
61 ~CachedPepperFlashSettings(); | |
62 | |
63 PP_Flash_BrowserOperations_Permission default_permission; | |
64 | |
65 typedef std::map<std::string, PP_Flash_BrowserOperations_Permission> | |
66 SiteMap; | |
67 SiteMap sites; | |
68 | |
69 bool initialized; | |
70 uint32_t last_refresh_request_id; | |
71 }; | |
72 | |
73 // Functions that call into the page ----------------------------------------- | |
74 | |
75 // Updates the page with the default settings (allow, ask, block, etc.) | |
76 void UpdateSettingDefaultFromModel(const ExContentSettingsType& type); | |
77 | |
78 // Clobbers and rebuilds the specific content setting type exceptions table. | |
79 void UpdateExceptionsViewFromModel(const ExContentSettingsType& type); | |
80 // Clobbers and rebuilds the specific content setting type exceptions | |
81 // OTR table. | |
82 void UpdateOTRExceptionsViewFromModel( | |
83 const ExContentSettingsType& type); | |
84 // Clobbers and rebuilds all the exceptions tables in the page (both normal | |
85 // and OTR tables). | |
86 void UpdateAllExceptionsViewsFromModel(); | |
87 // As above, but only OTR tables. | |
88 void UpdateAllOTRExceptionsViewsFromModel(); | |
89 // Clobbers and rebuilds just the geolocation exception table. | |
90 void UpdateGeolocationExceptionsView(); | |
91 // Clobbers and rebuilds just the desktop notification exception table. | |
92 void UpdateNotificationExceptionsView(); | |
93 // Clobbers and rebuilds just the Pepper Flash camera and microphone exception | |
94 // table. | |
95 void UpdateFlashCameraMicExceptionsView(); | |
96 // Clobbers and rebuilds just the Media Stream device exception table. | |
97 void UpdateMediaStreamExceptionsView(); | |
98 // Clobbers and rebuilds an exception table that's managed by the host content | |
99 // settings map. | |
100 void UpdateExceptionsViewFromHostContentSettingsMap(ContentSettingsType type); | |
101 // As above, but acts on the OTR table for the content setting type. | |
102 void UpdateExceptionsViewFromOTRHostContentSettingsMap( | |
103 ContentSettingsType type); | |
104 // Updates the radio buttons for enabling / disabling handlers. | |
105 void UpdateHandlersEnabledRadios(); | |
106 // Removes one geolocation exception. | |
107 void RemoveGeolocationException(const base::ListValue* args, | |
108 size_t arg_index); | |
109 // Removes one notification exception. | |
110 void RemoveNotificationException(const base::ListValue* args, | |
111 size_t arg_index); | |
112 // Removes one Pepper Flash camera and microphone exception. | |
113 void RemoveFlashCameraMicException(const base::ListValue* args, | |
114 size_t arg_index); | |
115 // Removes one exception of |type| from the host content settings map. | |
116 void RemoveExceptionFromHostContentSettingsMap( | |
117 const base::ListValue* args, | |
118 size_t arg_index, | |
119 const ExContentSettingsType& type); | |
120 | |
121 // Callbacks used by the page ------------------------------------------------ | |
122 | |
123 // Sets the default value for a specific content type. |args| includes the | |
124 // content type and a string describing the new default the user has | |
125 // chosen. | |
126 void SetContentFilter(const base::ListValue* args); | |
127 | |
128 // Removes the given row from the table. The first entry in |args| is the | |
129 // content type, and the rest of the arguments depend on the content type | |
130 // to be removed. | |
131 void RemoveException(const base::ListValue* args); | |
132 | |
133 // Changes the value of an exception. Called after the user is done editing an | |
134 // exception. | |
135 void SetException(const base::ListValue* args); | |
136 | |
137 // Called to decide whether a given pattern is valid, or if it should be | |
138 // rejected. Called while the user is editing an exception pattern. | |
139 void CheckExceptionPatternValidity(const base::ListValue* args); | |
140 | |
141 // Utility functions --------------------------------------------------------- | |
142 | |
143 // Applies content settings whitelists to reduce breakage / user confusion. | |
144 void ApplyWhitelist(ContentSettingsType content_type, | |
145 ContentSetting default_setting); | |
146 | |
147 // Gets the HostContentSettingsMap for the normal profile. | |
148 HostContentSettingsMap* GetContentSettingsMap(); | |
149 | |
150 // Gets the HostContentSettingsMap for the incognito profile, or NULL if there | |
151 // is no active incognito session. | |
152 HostContentSettingsMap* GetOTRContentSettingsMap(); | |
153 | |
154 // Gets the default setting in string form. If |provider_id| is not NULL, the | |
155 // id of the provider which provided the default setting is assigned to it. | |
156 std::string GetSettingDefaultFromModel(const ExContentSettingsType& type, | |
157 std::string* provider_id); | |
158 | |
159 // Gets the ProtocolHandlerRegistry for the normal profile. | |
160 ProtocolHandlerRegistry* GetProtocolHandlerRegistry(); | |
161 | |
162 // The method does nothing if |force| is false and the cache has been | |
163 // initialized. | |
164 void RefreshFlashSettingsCache(bool force); | |
165 | |
166 static ExContentSettingsType ExContentSettingsTypeFromGroupName( | |
167 const std::string& name); | |
168 static std::string ExContentSettingsTypeToGroupName( | |
169 const ExContentSettingsType& type); | |
170 | |
171 // Member variables --------------------------------------------------------- | |
172 | |
173 content::NotificationRegistrar notification_registrar_; | |
174 PrefChangeRegistrar pref_change_registrar_; | |
175 scoped_ptr<PepperFlashSettingsManager> flash_settings_manager_; | |
176 CachedPepperFlashSettings flash_cameramic_settings_; | |
177 | |
178 static const ExContentSettingsTypeNameEntry | |
179 kExContentSettingsTypeGroupNames[]; | |
180 | |
181 DISALLOW_COPY_AND_ASSIGN(ContentSettingsHandler); | |
182 }; | |
183 | |
184 } // namespace options | |
185 | |
186 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS2_CONTENT_SETTINGS_HANDLER_H_ | |
OLD | NEW |