Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / ui / webui / options / content_settings_handler.h
blob892c46d1e3f385d756f8666d952512416b8862b1
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_
8 #include <string>
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/host_zoom_map.h"
18 #include "content/public/browser/notification_observer.h"
19 #include "content/public/browser/notification_registrar.h"
21 class HostContentSettingsMap;
22 class ProtocolHandlerRegistry;
24 namespace options {
26 class ContentSettingsHandler : public OptionsPageUIHandler,
27 public content::NotificationObserver,
28 public PepperFlashSettingsManager::Client {
29 public:
30 ContentSettingsHandler();
31 virtual ~ContentSettingsHandler();
33 // OptionsPageUIHandler implementation.
34 virtual void GetLocalizedValues(
35 base::DictionaryValue* localized_strings) OVERRIDE;
36 virtual void InitializeHandler() OVERRIDE;
37 virtual void InitializePage() OVERRIDE;
38 virtual void RegisterMessages() OVERRIDE;
40 // content::NotificationObserver implementation.
41 virtual void Observe(int type,
42 const content::NotificationSource& source,
43 const content::NotificationDetails& details) OVERRIDE;
45 // PepperFlashSettingsManager::Client implementation.
46 virtual void OnGetPermissionSettingsCompleted(
47 uint32 request_id,
48 bool success,
49 PP_Flash_BrowserOperations_Permission default_permission,
50 const ppapi::FlashSiteSettings& sites) OVERRIDE;
52 // Gets a string identifier for the group name, for use in HTML.
53 static std::string ContentSettingsTypeToGroupName(ContentSettingsType type);
55 private:
56 // Used to determine whether we should show links to Flash camera and
57 // microphone settings.
58 struct MediaSettingsInfo {
59 MediaSettingsInfo();
60 ~MediaSettingsInfo();
62 // Cached Pepper Flash settings.
63 ContentSetting flash_default_setting;
64 MediaExceptions flash_exceptions;
65 bool flash_settings_initialized;
66 uint32_t last_flash_refresh_request_id;
68 // Whether the links to Flash settings pages are showed.
69 bool show_flash_default_link;
70 bool show_flash_exceptions_link;
72 // Cached Chrome media settings.
73 ContentSetting default_setting;
74 bool policy_disable_audio;
75 bool policy_disable_video;
76 bool default_setting_initialized;
77 MediaExceptions exceptions;
78 bool exceptions_initialized;
81 // Used by ShowFlashMediaLink() to specify which link to show/hide.
82 enum LinkType {
83 DEFAULT_SETTING = 0,
84 EXCEPTIONS,
87 // Functions that call into the page -----------------------------------------
89 // Updates the page with the default settings (allow, ask, block, etc.)
90 void UpdateSettingDefaultFromModel(ContentSettingsType type);
92 // Updates the media radio buttons according to the enabled split prefs.
93 void UpdateMediaSettingsView();
95 // Clobbers and rebuilds the specific content setting type exceptions table.
96 void UpdateExceptionsViewFromModel(ContentSettingsType type);
98 // Clobbers and rebuilds the specific content setting type exceptions
99 // OTR table.
100 void UpdateOTRExceptionsViewFromModel(ContentSettingsType type);
102 // Clobbers and rebuilds all the exceptions tables in the page (both normal
103 // and OTR tables).
104 void UpdateAllExceptionsViewsFromModel();
106 // As above, but only OTR tables.
107 void UpdateAllOTRExceptionsViewsFromModel();
109 // Clobbers and rebuilds just the geolocation exception table.
110 void UpdateGeolocationExceptionsView();
112 // Clobbers and rebuilds just the desktop notification exception table.
113 void UpdateNotificationExceptionsView();
115 // Clobbers and rebuilds just the Media device exception table.
116 void UpdateMediaExceptionsView();
118 // Clobbers and rebuilds just the MIDI SysEx exception table.
119 void UpdateMIDISysExExceptionsView();
121 // Clobbers and rebuilds just the zoom levels exception table.
122 void UpdateZoomLevelsExceptionsView();
124 // Clobbers and rebuilds an exception table that's managed by the host content
125 // settings map.
126 void UpdateExceptionsViewFromHostContentSettingsMap(ContentSettingsType type);
128 // As above, but acts on the OTR table for the content setting type.
129 void UpdateExceptionsViewFromOTRHostContentSettingsMap(
130 ContentSettingsType type);
132 // Updates the radio buttons for enabling / disabling handlers.
133 void UpdateHandlersEnabledRadios();
135 // Removes one geolocation exception. |args| contains the parameters passed to
136 // RemoveException().
137 void RemoveGeolocationException(const base::ListValue* args);
139 // Removes one notification exception. |args| contains the parameters passed
140 // to RemoveException().
141 void RemoveNotificationException(const base::ListValue* args);
143 // Removes one media camera and microphone exception. |args| contains the
144 // parameters passed to RemoveException().
145 void RemoveMediaException(const base::ListValue* args);
147 // Removes one exception of |type| from the host content settings map. |args|
148 // contains the parameters passed to RemoveException().
149 void RemoveExceptionFromHostContentSettingsMap(
150 const base::ListValue* args,
151 ContentSettingsType type);
153 // Removes one zoom level exception. |args| contains the parameters passed to
154 // RemoveException().
155 void RemoveZoomLevelException(const base::ListValue* args);
157 // Callbacks used by the page ------------------------------------------------
159 // Sets the default value for a specific content type. |args| includes the
160 // content type and a string describing the new default the user has
161 // chosen.
162 void SetContentFilter(const base::ListValue* args);
164 // Removes the given row from the table. The first entry in |args| is the
165 // content type, and the rest of the arguments depend on the content type
166 // to be removed.
167 void RemoveException(const base::ListValue* args);
169 // Changes the value of an exception. Called after the user is done editing an
170 // exception.
171 void SetException(const base::ListValue* args);
173 // Called to decide whether a given pattern is valid, or if it should be
174 // rejected. Called while the user is editing an exception pattern.
175 void CheckExceptionPatternValidity(const base::ListValue* args);
177 // Utility functions ---------------------------------------------------------
179 // Applies content settings whitelists to reduce breakage / user confusion.
180 void ApplyWhitelist(ContentSettingsType content_type,
181 ContentSetting default_setting);
183 // Gets the HostContentSettingsMap for the normal profile.
184 HostContentSettingsMap* GetContentSettingsMap();
186 // Gets the HostContentSettingsMap for the incognito profile, or NULL if there
187 // is no active incognito session.
188 HostContentSettingsMap* GetOTRContentSettingsMap();
190 // Gets the default setting in string form. If |provider_id| is not NULL, the
191 // id of the provider which provided the default setting is assigned to it.
192 std::string GetSettingDefaultFromModel(ContentSettingsType type,
193 std::string* provider_id);
195 // Gets the ProtocolHandlerRegistry for the normal profile.
196 ProtocolHandlerRegistry* GetProtocolHandlerRegistry();
198 void RefreshFlashMediaSettings();
200 // Fills in |exceptions| with Values for the given |type| from |map|.
201 void GetExceptionsFromHostContentSettingsMap(
202 const HostContentSettingsMap* map,
203 ContentSettingsType type,
204 base::ListValue* exceptions);
206 void OnPepperFlashPrefChanged();
208 // content::HostZoomMap subscription.
209 void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change);
211 void ShowFlashMediaLink(LinkType link_type, bool show);
213 void UpdateFlashMediaLinksVisibility();
215 void UpdateProtectedContentExceptionsButton();
217 // Member variables ---------------------------------------------------------
219 content::NotificationRegistrar notification_registrar_;
220 PrefChangeRegistrar pref_change_registrar_;
221 scoped_ptr<PepperFlashSettingsManager> flash_settings_manager_;
222 MediaSettingsInfo media_settings_;
223 scoped_ptr<content::HostZoomMap::Subscription> host_zoom_map_subscription_;
225 DISALLOW_COPY_AND_ASSIGN(ContentSettingsHandler);
228 } // namespace options
230 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_CONTENT_SETTINGS_HANDLER_H_