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 "base/values.h"
14 #include "chrome/browser/pepper_flash_settings_manager.h"
15 #include "chrome/browser/ui/webui/options/options_ui.h"
16 #include "chrome/browser/ui/webui/options/pepper_flash_content_settings_utils.h"
17 #include "components/content_settings/core/browser/content_settings_observer.h"
18 #include "components/content_settings/core/common/content_settings.h"
19 #include "components/content_settings/core/common/content_settings_types.h"
20 #include "content/public/browser/host_zoom_map.h"
21 #include "content/public/browser/notification_observer.h"
22 #include "content/public/browser/notification_registrar.h"
24 class HostContentSettingsMap
;
25 class ProtocolHandlerRegistry
;
29 class ContentSettingsHandler
: public OptionsPageUIHandler
,
30 public content_settings::Observer
,
31 public content::NotificationObserver
,
32 public PepperFlashSettingsManager::Client
{
34 ContentSettingsHandler();
35 ~ContentSettingsHandler() override
;
37 // OptionsPageUIHandler implementation.
38 void GetLocalizedValues(base::DictionaryValue
* localized_strings
) override
;
39 void InitializeHandler() override
;
40 void InitializePage() override
;
41 void RegisterMessages() override
;
43 // content_settings::Observer implementation.
44 void OnContentSettingChanged(const ContentSettingsPattern
& primary_pattern
,
45 const ContentSettingsPattern
& secondary_pattern
,
46 ContentSettingsType content_type
,
47 std::string resource_identifier
) override
;
49 // content::NotificationObserver implementation.
50 void Observe(int type
,
51 const content::NotificationSource
& source
,
52 const content::NotificationDetails
& details
) override
;
54 // PepperFlashSettingsManager::Client implementation.
55 void OnGetPermissionSettingsCompleted(
58 PP_Flash_BrowserOperations_Permission default_permission
,
59 const ppapi::FlashSiteSettings
& sites
) override
;
61 // Gets a string identifier for the group name, for use in HTML.
62 static std::string
ContentSettingsTypeToGroupName(ContentSettingsType type
);
65 // Used to determine whether we should show links to Flash camera and
66 // microphone settings.
67 class MediaSettingsInfo
{
72 // Cached Pepper Flash settings.
77 ContentSetting default_setting
;
78 MediaExceptions exceptions
;
80 uint32_t last_refresh_request_id
;
87 // Whether the links to Flash settings pages are showed.
88 bool show_flash_default_link
;
89 bool show_flash_exceptions_link
;
91 // Cached Chrome media settings.
92 ContentSetting default_setting
;
94 bool default_setting_initialized
;
95 MediaExceptions exceptions
;
96 bool exceptions_initialized
;
99 ForOneType
& forType(ContentSettingsType type
);
100 ForFlash
& forFlash();
103 ForOneType mic_settings_
;
104 ForOneType camera_settings_
;
105 ForFlash flash_settings_
;
107 DISALLOW_COPY_AND_ASSIGN(MediaSettingsInfo
);
110 // Used by ShowFlashMediaLink() to specify which link to show/hide.
116 // Functions that call into the page -----------------------------------------
118 // Updates the page with the default settings (allow, ask, block, etc.)
119 void UpdateSettingDefaultFromModel(ContentSettingsType type
);
121 // Compares the microphone or camera |type| default settings with Flash
122 // and updates the Flash links' visibility accordingly.
123 void UpdateMediaSettingsFromPrefs(ContentSettingsType type
);
125 // Clobbers and rebuilds the specific content setting type exceptions table.
126 void UpdateExceptionsViewFromModel(ContentSettingsType type
);
128 // Clobbers and rebuilds the specific content setting type exceptions
130 void UpdateOTRExceptionsViewFromModel(ContentSettingsType type
);
132 // Clobbers and rebuilds all the exceptions tables in the page (both normal
134 void UpdateAllExceptionsViewsFromModel();
136 // As above, but only OTR tables.
137 void UpdateAllOTRExceptionsViewsFromModel();
139 // Clobbers and rebuilds just the geolocation exception table.
140 void UpdateGeolocationExceptionsView();
142 // Clobbers and rebuilds just the desktop notification exception table.
143 void UpdateNotificationExceptionsView();
145 // Compares the exceptions of the camera or microphone |type| with its Flash
146 // counterparts and updates the Flash links' visibility accordingly.
147 void CompareMediaExceptionsWithFlash(ContentSettingsType type
);
149 // Clobbers and rebuilds just the MIDI SysEx exception table.
150 void UpdateMIDISysExExceptionsView();
152 // Modifies the zoom level exceptions list to display correct chrome
153 // signin page entry. When the legacy (non-WebView-based) signin page
154 // goes away, this function can be removed.
155 void AdjustZoomLevelsListForSigninPageIfNecessary(
156 content::HostZoomMap::ZoomLevelVector
* zoom_levels
);
158 // Clobbers and rebuilds just the zoom levels exception table.
159 void UpdateZoomLevelsExceptionsView();
161 // Clobbers and rebuilds an exception table that's managed by the host content
163 void UpdateExceptionsViewFromHostContentSettingsMap(ContentSettingsType type
);
165 // As above, but acts on the OTR table for the content setting type.
166 void UpdateExceptionsViewFromOTRHostContentSettingsMap(
167 ContentSettingsType type
);
169 // Updates the radio buttons for enabling / disabling handlers.
170 void UpdateHandlersEnabledRadios();
172 // Removes one geolocation exception. |args| contains the parameters passed to
173 // RemoveException().
174 void RemoveGeolocationException(const base::ListValue
* args
);
176 // Removes one notification exception. |args| contains the parameters passed
177 // to RemoveException().
178 void RemoveNotificationException(const base::ListValue
* args
);
180 // Removes one exception of |type| from the host content settings map. |args|
181 // contains the parameters passed to RemoveException().
182 void RemoveExceptionFromHostContentSettingsMap(
183 const base::ListValue
* args
,
184 ContentSettingsType type
);
186 // Removes one zoom level exception. |args| contains the parameters passed to
187 // RemoveException().
188 void RemoveZoomLevelException(const base::ListValue
* args
);
190 // Callbacks used by the page ------------------------------------------------
192 // Sets the default value for a specific content type. |args| includes the
193 // content type and a string describing the new default the user has
195 void SetContentFilter(const base::ListValue
* args
);
197 // Removes the given row from the table. The first entry in |args| is the
198 // content type, and the rest of the arguments depend on the content type
200 void RemoveException(const base::ListValue
* args
);
202 // Changes the value of an exception. Called after the user is done editing an
204 void SetException(const base::ListValue
* args
);
206 // Called to decide whether a given pattern is valid, or if it should be
207 // rejected. Called while the user is editing an exception pattern.
208 void CheckExceptionPatternValidity(const base::ListValue
* args
);
210 // Utility functions ---------------------------------------------------------
212 // Applies content settings whitelists to reduce breakage / user confusion.
213 void ApplyWhitelist(ContentSettingsType content_type
,
214 ContentSetting default_setting
);
216 // Gets the HostContentSettingsMap for the normal profile.
217 HostContentSettingsMap
* GetContentSettingsMap();
219 // Gets the HostContentSettingsMap for the incognito profile, or NULL if there
220 // is no active incognito session.
221 HostContentSettingsMap
* GetOTRContentSettingsMap();
223 // Gets the ProtocolHandlerRegistry for the normal profile.
224 ProtocolHandlerRegistry
* GetProtocolHandlerRegistry();
226 void RefreshFlashMediaSettings();
228 // Returns exceptions constructed from the policy-set allowed URLs
229 // for the content settings |type| mic or camera.
230 scoped_ptr
<base::ListValue
> GetPolicyAllowedUrls(ContentSettingsType type
);
232 // Fills in |exceptions| with Values for the given |type| from |map|.
233 void GetExceptionsFromHostContentSettingsMap(
234 const HostContentSettingsMap
* map
,
235 ContentSettingsType type
,
236 base::ListValue
* exceptions
);
238 void OnPepperFlashPrefChanged();
240 // content::HostZoomMap subscription.
241 void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange
& change
);
243 void ShowFlashMediaLink(
244 LinkType link_type
, ContentSettingsType content_type
, bool show
);
246 void UpdateFlashMediaLinksVisibility(ContentSettingsType type
);
248 void UpdateMediaDeviceDropdownVisibility(ContentSettingsType type
);
250 void UpdateProtectedContentExceptionsButton();
252 // Member variables ---------------------------------------------------------
254 content::NotificationRegistrar notification_registrar_
;
255 PrefChangeRegistrar pref_change_registrar_
;
256 scoped_ptr
<PepperFlashSettingsManager
> flash_settings_manager_
;
257 scoped_ptr
<MediaSettingsInfo
> media_settings_
;
258 scoped_ptr
<content::HostZoomMap::Subscription
> host_zoom_map_subscription_
;
259 scoped_ptr
<content::HostZoomMap::Subscription
>
260 signin_host_zoom_map_subscription_
;
261 ScopedObserver
<HostContentSettingsMap
, content_settings::Observer
> observer_
;
263 DISALLOW_COPY_AND_ASSIGN(ContentSettingsHandler
);
266 } // namespace options
268 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_CONTENT_SETTINGS_HANDLER_H_