Adding instrumentation to locate the source of jankiness
[chromium-blink-merge.git] / chrome / browser / ui / webui / options / content_settings_handler.h
blob7a494d5585ed1b2430dc0efa94fa38233cc76a17
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 "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;
26 namespace options {
28 class ContentSettingsHandler : public OptionsPageUIHandler,
29 public content_settings::Observer,
30 public content::NotificationObserver,
31 public PepperFlashSettingsManager::Client {
32 public:
33 ContentSettingsHandler();
34 virtual ~ContentSettingsHandler();
36 // OptionsPageUIHandler implementation.
37 virtual void GetLocalizedValues(
38 base::DictionaryValue* localized_strings) override;
39 virtual void InitializeHandler() override;
40 virtual void InitializePage() override;
41 virtual void RegisterMessages() override;
43 // content_settings::Observer implementation.
44 virtual void OnContentSettingChanged(
45 const ContentSettingsPattern& primary_pattern,
46 const ContentSettingsPattern& secondary_pattern,
47 ContentSettingsType content_type,
48 std::string resource_identifier) override;
50 // content::NotificationObserver implementation.
51 virtual void Observe(int type,
52 const content::NotificationSource& source,
53 const content::NotificationDetails& details) override;
55 // PepperFlashSettingsManager::Client implementation.
56 virtual void OnGetPermissionSettingsCompleted(
57 uint32 request_id,
58 bool success,
59 PP_Flash_BrowserOperations_Permission default_permission,
60 const ppapi::FlashSiteSettings& sites) override;
62 // Gets a string identifier for the group name, for use in HTML.
63 static std::string ContentSettingsTypeToGroupName(ContentSettingsType type);
65 private:
66 // Used to determine whether we should show links to Flash camera and
67 // microphone settings.
68 struct MediaSettingsInfo {
69 MediaSettingsInfo();
70 ~MediaSettingsInfo();
72 // Cached Pepper Flash settings.
73 ContentSetting flash_default_setting;
74 MediaExceptions flash_exceptions;
75 bool flash_settings_initialized;
76 uint32_t last_flash_refresh_request_id;
78 // Whether the links to Flash settings pages are showed.
79 bool show_flash_default_link;
80 bool show_flash_exceptions_link;
82 // Cached Chrome media settings.
83 ContentSetting default_setting;
84 bool policy_disable_audio;
85 bool policy_disable_video;
86 bool default_setting_initialized;
87 MediaExceptions exceptions;
88 bool exceptions_initialized;
91 // Used by ShowFlashMediaLink() to specify which link to show/hide.
92 enum LinkType {
93 DEFAULT_SETTING = 0,
94 EXCEPTIONS,
97 // Functions that call into the page -----------------------------------------
99 // Updates the page with the default settings (allow, ask, block, etc.)
100 void UpdateSettingDefaultFromModel(ContentSettingsType type);
102 // Updates the media radio buttons according to the enabled split prefs.
103 void UpdateMediaSettingsView();
105 // Clobbers and rebuilds the specific content setting type exceptions table.
106 void UpdateExceptionsViewFromModel(ContentSettingsType type);
108 // Clobbers and rebuilds the specific content setting type exceptions
109 // OTR table.
110 void UpdateOTRExceptionsViewFromModel(ContentSettingsType type);
112 // Clobbers and rebuilds all the exceptions tables in the page (both normal
113 // and OTR tables).
114 void UpdateAllExceptionsViewsFromModel();
116 // As above, but only OTR tables.
117 void UpdateAllOTRExceptionsViewsFromModel();
119 // Clobbers and rebuilds just the geolocation exception table.
120 void UpdateGeolocationExceptionsView();
122 // Clobbers and rebuilds just the desktop notification exception table.
123 void UpdateNotificationExceptionsView();
125 // Clobbers and rebuilds just the Media device exception table.
126 void UpdateMediaExceptionsView();
128 // Clobbers and rebuilds just the MIDI SysEx exception table.
129 void UpdateMIDISysExExceptionsView();
131 // Clobbers and rebuilds just the zoom levels exception table.
132 void UpdateZoomLevelsExceptionsView();
134 // Clobbers and rebuilds an exception table that's managed by the host content
135 // settings map.
136 void UpdateExceptionsViewFromHostContentSettingsMap(ContentSettingsType type);
138 // As above, but acts on the OTR table for the content setting type.
139 void UpdateExceptionsViewFromOTRHostContentSettingsMap(
140 ContentSettingsType type);
142 // Updates the radio buttons for enabling / disabling handlers.
143 void UpdateHandlersEnabledRadios();
145 // Removes one geolocation exception. |args| contains the parameters passed to
146 // RemoveException().
147 void RemoveGeolocationException(const base::ListValue* args);
149 // Removes one notification exception. |args| contains the parameters passed
150 // to RemoveException().
151 void RemoveNotificationException(const base::ListValue* args);
153 // Removes one media camera and microphone exception. |args| contains the
154 // parameters passed to RemoveException().
155 void RemoveMediaException(const base::ListValue* args);
157 // Removes one exception of |type| from the host content settings map. |args|
158 // contains the parameters passed to RemoveException().
159 void RemoveExceptionFromHostContentSettingsMap(
160 const base::ListValue* args,
161 ContentSettingsType type);
163 // Removes one zoom level exception. |args| contains the parameters passed to
164 // RemoveException().
165 void RemoveZoomLevelException(const base::ListValue* args);
167 // Callbacks used by the page ------------------------------------------------
169 // Sets the default value for a specific content type. |args| includes the
170 // content type and a string describing the new default the user has
171 // chosen.
172 void SetContentFilter(const base::ListValue* args);
174 // Removes the given row from the table. The first entry in |args| is the
175 // content type, and the rest of the arguments depend on the content type
176 // to be removed.
177 void RemoveException(const base::ListValue* args);
179 // Changes the value of an exception. Called after the user is done editing an
180 // exception.
181 void SetException(const base::ListValue* args);
183 // Called to decide whether a given pattern is valid, or if it should be
184 // rejected. Called while the user is editing an exception pattern.
185 void CheckExceptionPatternValidity(const base::ListValue* args);
187 // Utility functions ---------------------------------------------------------
189 // Applies content settings whitelists to reduce breakage / user confusion.
190 void ApplyWhitelist(ContentSettingsType content_type,
191 ContentSetting default_setting);
193 // Gets the HostContentSettingsMap for the normal profile.
194 HostContentSettingsMap* GetContentSettingsMap();
196 // Gets the HostContentSettingsMap for the incognito profile, or NULL if there
197 // is no active incognito session.
198 HostContentSettingsMap* GetOTRContentSettingsMap();
200 // Gets the default setting in string form. If |provider_id| is not NULL, the
201 // id of the provider which provided the default setting is assigned to it.
202 std::string GetSettingDefaultFromModel(ContentSettingsType type,
203 std::string* provider_id);
205 // Gets the ProtocolHandlerRegistry for the normal profile.
206 ProtocolHandlerRegistry* GetProtocolHandlerRegistry();
208 void RefreshFlashMediaSettings();
210 // Fills in |exceptions| with Values for the given |type| from |map|.
211 void GetExceptionsFromHostContentSettingsMap(
212 const HostContentSettingsMap* map,
213 ContentSettingsType type,
214 base::ListValue* exceptions);
216 void OnPepperFlashPrefChanged();
218 // content::HostZoomMap subscription.
219 void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change);
221 void ShowFlashMediaLink(LinkType link_type, bool show);
223 void UpdateFlashMediaLinksVisibility();
225 void UpdateProtectedContentExceptionsButton();
227 // Member variables ---------------------------------------------------------
229 content::NotificationRegistrar notification_registrar_;
230 PrefChangeRegistrar pref_change_registrar_;
231 scoped_ptr<PepperFlashSettingsManager> flash_settings_manager_;
232 MediaSettingsInfo media_settings_;
233 scoped_ptr<content::HostZoomMap::Subscription> host_zoom_map_subscription_;
234 ScopedObserver<HostContentSettingsMap, content_settings::Observer> observer_;
236 DISALLOW_COPY_AND_ASSIGN(ContentSettingsHandler);
239 } // namespace options
241 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_CONTENT_SETTINGS_HANDLER_H_