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.
5 #ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS_CONTENT_SETTINGS_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS_CONTENT_SETTINGS_HANDLER_H_
10 #include "base/memory/scoped_ptr.h"
11 #include "base/prefs/pref_change_registrar.h"
12 #include "base/scoped_observer.h"
13 #include "chrome/browser/pepper_flash_settings_manager.h"
14 #include "chrome/browser/ui/webui/options/options_ui.h"
15 #include "chrome/browser/ui/webui/options/pepper_flash_content_settings_utils.h"
16 #include "components/content_settings/core/browser/content_settings_observer.h"
17 #include "components/content_settings/core/common/content_settings.h"
18 #include "components/content_settings/core/common/content_settings_types.h"
19 #include "content/public/browser/host_zoom_map.h"
20 #include "content/public/browser/notification_observer.h"
21 #include "content/public/browser/notification_registrar.h"
23 class HostContentSettingsMap;
24 class ProtocolHandlerRegistry;
28 class ContentSettingsHandler : public OptionsPageUIHandler,
29 public content_settings::Observer,
30 public content::NotificationObserver,
31 public PepperFlashSettingsManager::Client {
33 ContentSettingsHandler();
34 ~ContentSettingsHandler() override;
36 // OptionsPageUIHandler implementation.
37 void GetLocalizedValues(base::DictionaryValue* localized_strings) override;
38 void InitializeHandler() override;
39 void InitializePage() override;
40 void RegisterMessages() override;
42 // content_settings::Observer implementation.
43 void OnContentSettingChanged(const ContentSettingsPattern& primary_pattern,
44 const ContentSettingsPattern& secondary_pattern,
45 ContentSettingsType content_type,
46 std::string resource_identifier) override;
48 // content::NotificationObserver implementation.
49 void Observe(int type,
50 const content::NotificationSource& source,
51 const content::NotificationDetails& details) override;
53 // PepperFlashSettingsManager::Client implementation.
54 void OnGetPermissionSettingsCompleted(
57 PP_Flash_BrowserOperations_Permission default_permission,
58 const ppapi::FlashSiteSettings& sites) override;
60 // Gets a string identifier for the group name, for use in HTML.
61 static std::string ContentSettingsTypeToGroupName(ContentSettingsType type);
64 // Used to determine whether we should show links to Flash camera and
65 // microphone settings.
66 struct MediaSettingsInfo {
70 // Cached Pepper Flash settings.
71 ContentSetting flash_default_setting;
72 MediaExceptions flash_exceptions;
73 bool flash_settings_initialized;
74 uint32_t last_flash_refresh_request_id;
76 // Whether the links to Flash settings pages are showed.
77 bool show_flash_default_link;
78 bool show_flash_exceptions_link;
80 // Cached Chrome media settings.
81 ContentSetting default_setting;
82 bool policy_disable_audio;
83 bool policy_disable_video;
84 bool default_setting_initialized;
85 MediaExceptions exceptions;
86 bool exceptions_initialized;
89 // Used by ShowFlashMediaLink() to specify which link to show/hide.
95 // Functions that call into the page -----------------------------------------
97 // Updates the page with the default settings (allow, ask, block, etc.)
98 void UpdateSettingDefaultFromModel(ContentSettingsType type);
100 // Updates the media radio buttons according to the enabled split prefs.
101 void UpdateMediaSettingsView();
103 // Clobbers and rebuilds the specific content setting type exceptions table.
104 void UpdateExceptionsViewFromModel(ContentSettingsType type);
106 // Clobbers and rebuilds the specific content setting type exceptions
108 void UpdateOTRExceptionsViewFromModel(ContentSettingsType type);
110 // Clobbers and rebuilds all the exceptions tables in the page (both normal
112 void UpdateAllExceptionsViewsFromModel();
114 // As above, but only OTR tables.
115 void UpdateAllOTRExceptionsViewsFromModel();
117 // Clobbers and rebuilds just the geolocation exception table.
118 void UpdateGeolocationExceptionsView();
120 // Clobbers and rebuilds just the desktop notification exception table.
121 void UpdateNotificationExceptionsView();
123 // Clobbers and rebuilds just the Media device exception table.
124 void UpdateMediaExceptionsView();
126 // Clobbers and rebuilds just the MIDI SysEx exception table.
127 void UpdateMIDISysExExceptionsView();
129 // Clobbers and rebuilds just the zoom levels exception table.
130 void UpdateZoomLevelsExceptionsView();
132 // Clobbers and rebuilds an exception table that's managed by the host content
134 void UpdateExceptionsViewFromHostContentSettingsMap(ContentSettingsType type);
136 // As above, but acts on the OTR table for the content setting type.
137 void UpdateExceptionsViewFromOTRHostContentSettingsMap(
138 ContentSettingsType type);
140 // Updates the radio buttons for enabling / disabling handlers.
141 void UpdateHandlersEnabledRadios();
143 // Removes one geolocation exception. |args| contains the parameters passed to
144 // RemoveException().
145 void RemoveGeolocationException(const base::ListValue* args);
147 // Removes one notification exception. |args| contains the parameters passed
148 // to RemoveException().
149 void RemoveNotificationException(const base::ListValue* args);
151 // Removes one media camera and microphone exception. |args| contains the
152 // parameters passed to RemoveException().
153 void RemoveMediaException(const base::ListValue* args);
155 // Removes one exception of |type| from the host content settings map. |args|
156 // contains the parameters passed to RemoveException().
157 void RemoveExceptionFromHostContentSettingsMap(
158 const base::ListValue* args,
159 ContentSettingsType type);
161 // Removes one zoom level exception. |args| contains the parameters passed to
162 // RemoveException().
163 void RemoveZoomLevelException(const base::ListValue* args);
165 // Callbacks used by the page ------------------------------------------------
167 // Sets the default value for a specific content type. |args| includes the
168 // content type and a string describing the new default the user has
170 void SetContentFilter(const base::ListValue* args);
172 // Removes the given row from the table. The first entry in |args| is the
173 // content type, and the rest of the arguments depend on the content type
175 void RemoveException(const base::ListValue* args);
177 // Changes the value of an exception. Called after the user is done editing an
179 void SetException(const base::ListValue* args);
181 // Called to decide whether a given pattern is valid, or if it should be
182 // rejected. Called while the user is editing an exception pattern.
183 void CheckExceptionPatternValidity(const base::ListValue* args);
185 // Utility functions ---------------------------------------------------------
187 // Applies content settings whitelists to reduce breakage / user confusion.
188 void ApplyWhitelist(ContentSettingsType content_type,
189 ContentSetting default_setting);
191 // Gets the HostContentSettingsMap for the normal profile.
192 HostContentSettingsMap* GetContentSettingsMap();
194 // Gets the HostContentSettingsMap for the incognito profile, or NULL if there
195 // is no active incognito session.
196 HostContentSettingsMap* GetOTRContentSettingsMap();
198 // Gets the default setting in string form. If |provider_id| is not NULL, the
199 // id of the provider which provided the default setting is assigned to it.
200 std::string GetSettingDefaultFromModel(ContentSettingsType type,
201 std::string* provider_id);
203 // Gets the ProtocolHandlerRegistry for the normal profile.
204 ProtocolHandlerRegistry* GetProtocolHandlerRegistry();
206 void RefreshFlashMediaSettings();
208 // Fills in |exceptions| with Values for the given |type| from |map|.
209 void GetExceptionsFromHostContentSettingsMap(
210 const HostContentSettingsMap* map,
211 ContentSettingsType type,
212 base::ListValue* exceptions);
214 void OnPepperFlashPrefChanged();
216 // content::HostZoomMap subscription.
217 void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change);
219 void ShowFlashMediaLink(LinkType link_type, bool show);
221 void UpdateFlashMediaLinksVisibility();
223 void UpdateProtectedContentExceptionsButton();
225 // Member variables ---------------------------------------------------------
227 content::NotificationRegistrar notification_registrar_;
228 PrefChangeRegistrar pref_change_registrar_;
229 scoped_ptr<PepperFlashSettingsManager> flash_settings_manager_;
230 MediaSettingsInfo media_settings_;
231 scoped_ptr<content::HostZoomMap::Subscription> host_zoom_map_subscription_;
232 ScopedObserver<HostContentSettingsMap, content_settings::Observer> observer_;
234 DISALLOW_COPY_AND_ASSIGN(ContentSettingsHandler);
237 } // namespace options
239 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_CONTENT_SETTINGS_HANDLER_H_