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 "chrome/browser/pepper_flash_settings_manager.h"
13 #include "chrome/browser/ui/webui/options/options_ui.h"
14 #include "chrome/browser/ui/webui/options/pepper_flash_content_settings_utils.h"
15 #include "chrome/common/content_settings.h"
16 #include "chrome/common/content_settings_types.h"
17 #include "content/public/browser/notification_observer.h"
18 #include "content/public/browser/notification_registrar.h"
20 class HostContentSettingsMap
;
21 class ProtocolHandlerRegistry
;
25 class ContentSettingsHandler
: public OptionsPageUIHandler
,
26 public PepperFlashSettingsManager::Client
{
28 ContentSettingsHandler();
29 virtual ~ContentSettingsHandler();
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
;
38 // content::NotificationObserver implementation.
39 virtual void Observe(int type
,
40 const content::NotificationSource
& source
,
41 const content::NotificationDetails
& details
) OVERRIDE
;
43 // PepperFlashSettingsManager::Client implementation.
44 virtual void OnGetPermissionSettingsCompleted(
47 PP_Flash_BrowserOperations_Permission default_permission
,
48 const ppapi::FlashSiteSettings
& sites
) OVERRIDE
;
50 // Gets a string identifier for the group name, for use in HTML.
51 static std::string
ContentSettingsTypeToGroupName(ContentSettingsType type
);
54 // Used to determine whether we should show links to Flash camera and
55 // microphone settings.
56 struct MediaSettingsInfo
{
60 // Cached Pepper Flash settings.
61 ContentSetting flash_default_setting
;
62 MediaExceptions flash_exceptions
;
63 bool flash_settings_initialized
;
64 uint32_t last_flash_refresh_request_id
;
66 // Whether the links to Flash settings pages are showed.
67 bool show_flash_default_link
;
68 bool show_flash_exceptions_link
;
70 // Cached Chrome media settings.
71 ContentSetting default_setting
;
72 bool policy_disable_audio
;
73 bool policy_disable_video
;
74 bool default_setting_initialized
;
75 MediaExceptions exceptions
;
76 bool exceptions_initialized
;
79 // Used by ShowFlashMediaLink() to specify which link to show/hide.
85 // Functions that call into the page -----------------------------------------
87 // Updates the page with the default settings (allow, ask, block, etc.)
88 void UpdateSettingDefaultFromModel(ContentSettingsType type
);
90 // Updates the media radio buttons according to the enabled split prefs.
91 void UpdateMediaSettingsView();
93 // Clobbers and rebuilds the specific content setting type exceptions table.
94 void UpdateExceptionsViewFromModel(ContentSettingsType type
);
95 // Clobbers and rebuilds the specific content setting type exceptions
97 void UpdateOTRExceptionsViewFromModel(ContentSettingsType type
);
98 // Clobbers and rebuilds all the exceptions tables in the page (both normal
100 void UpdateAllExceptionsViewsFromModel();
101 // As above, but only OTR tables.
102 void UpdateAllOTRExceptionsViewsFromModel();
103 // Clobbers and rebuilds just the geolocation exception table.
104 void UpdateGeolocationExceptionsView();
105 // Clobbers and rebuilds just the desktop notification exception table.
106 void UpdateNotificationExceptionsView();
107 // Clobbers and rebuilds just the Media device exception table.
108 void UpdateMediaExceptionsView();
109 // Clobbers and rebuilds just the MIDI SysEx exception table.
110 void UpdateMIDISysExExceptionsView();
111 // Clobbers and rebuilds an exception table that's managed by the host content
113 void UpdateExceptionsViewFromHostContentSettingsMap(ContentSettingsType type
);
114 // As above, but acts on the OTR table for the content setting type.
115 void UpdateExceptionsViewFromOTRHostContentSettingsMap(
116 ContentSettingsType type
);
117 // Updates the radio buttons for enabling / disabling handlers.
118 void UpdateHandlersEnabledRadios();
119 // Removes one geolocation exception.
120 void RemoveGeolocationException(const base::ListValue
* args
,
122 // Removes one notification exception.
123 void RemoveNotificationException(const base::ListValue
* args
,
125 // Removes one media camera and microphone exception.
126 void RemoveMediaException(const base::ListValue
* args
, size_t arg_index
);
127 // Removes one exception of |type| from the host content settings map.
128 void RemoveExceptionFromHostContentSettingsMap(
129 const base::ListValue
* args
,
131 ContentSettingsType type
);
133 // Callbacks used by the page ------------------------------------------------
135 // Sets the default value for a specific content type. |args| includes the
136 // content type and a string describing the new default the user has
138 void SetContentFilter(const base::ListValue
* args
);
140 // Removes the given row from the table. The first entry in |args| is the
141 // content type, and the rest of the arguments depend on the content type
143 void RemoveException(const base::ListValue
* args
);
145 // Changes the value of an exception. Called after the user is done editing an
147 void SetException(const base::ListValue
* args
);
149 // Called to decide whether a given pattern is valid, or if it should be
150 // rejected. Called while the user is editing an exception pattern.
151 void CheckExceptionPatternValidity(const base::ListValue
* args
);
153 // Utility functions ---------------------------------------------------------
155 // Applies content settings whitelists to reduce breakage / user confusion.
156 void ApplyWhitelist(ContentSettingsType content_type
,
157 ContentSetting default_setting
);
159 // Gets the HostContentSettingsMap for the normal profile.
160 HostContentSettingsMap
* GetContentSettingsMap();
162 // Gets the HostContentSettingsMap for the incognito profile, or NULL if there
163 // is no active incognito session.
164 HostContentSettingsMap
* GetOTRContentSettingsMap();
166 // Gets the default setting in string form. If |provider_id| is not NULL, the
167 // id of the provider which provided the default setting is assigned to it.
168 std::string
GetSettingDefaultFromModel(ContentSettingsType type
,
169 std::string
* provider_id
);
171 // Gets the ProtocolHandlerRegistry for the normal profile.
172 ProtocolHandlerRegistry
* GetProtocolHandlerRegistry();
174 void RefreshFlashMediaSettings();
176 // Fills in |exceptions| with Values for the given |type| from |map|.
177 void GetExceptionsFromHostContentSettingsMap(
178 const HostContentSettingsMap
* map
,
179 ContentSettingsType type
,
180 base::ListValue
* exceptions
);
182 void OnPepperFlashPrefChanged();
184 void ShowFlashMediaLink(LinkType link_type
, bool show
);
186 void UpdateFlashMediaLinksVisibility();
188 void UpdateProtectedContentExceptionsButton();
190 // Member variables ---------------------------------------------------------
192 content::NotificationRegistrar notification_registrar_
;
193 PrefChangeRegistrar pref_change_registrar_
;
194 scoped_ptr
<PepperFlashSettingsManager
> flash_settings_manager_
;
195 MediaSettingsInfo media_settings_
;
197 DISALLOW_COPY_AND_ASSIGN(ContentSettingsHandler
);
200 } // namespace options
202 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_CONTENT_SETTINGS_HANDLER_H_