Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / chrome / browser / ui / webui / options / content_settings_handler.h
blob7ae81cb30b015f6d407d9b049f40a9468a8bc0fa
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 ~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(
55 uint32 request_id,
56 bool success,
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);
63 private:
64 // Used to determine whether we should show links to Flash camera and
65 // microphone settings.
66 struct MediaSettingsInfo {
67 MediaSettingsInfo();
68 ~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_audio_setting;
82 ContentSetting default_video_setting;
83 bool policy_disable_audio;
84 bool policy_disable_video;
85 bool default_settings_initialized;
86 MediaExceptions exceptions;
87 bool exceptions_initialized;
90 // Used by ShowFlashMediaLink() to specify which link to show/hide.
91 enum LinkType {
92 DEFAULT_SETTING = 0,
93 EXCEPTIONS,
96 // Functions that call into the page -----------------------------------------
98 // Updates the page with the default settings (allow, ask, block, etc.)
99 void UpdateSettingDefaultFromModel(ContentSettingsType type);
101 // Updates the media radio buttons according to the enabled split prefs.
102 void UpdateMediaSettingsView();
104 // Clobbers and rebuilds the specific content setting type exceptions table.
105 void UpdateExceptionsViewFromModel(ContentSettingsType type);
107 // Clobbers and rebuilds the specific content setting type exceptions
108 // OTR table.
109 void UpdateOTRExceptionsViewFromModel(ContentSettingsType type);
111 // Clobbers and rebuilds all the exceptions tables in the page (both normal
112 // and OTR tables).
113 void UpdateAllExceptionsViewsFromModel();
115 // As above, but only OTR tables.
116 void UpdateAllOTRExceptionsViewsFromModel();
118 // Clobbers and rebuilds just the geolocation exception table.
119 void UpdateGeolocationExceptionsView();
121 // Clobbers and rebuilds just the desktop notification exception table.
122 void UpdateNotificationExceptionsView();
124 // Clobbers and rebuilds just the Media device exception table.
125 void UpdateMediaExceptionsView();
127 // Clobbers and rebuilds just the MIDI SysEx exception table.
128 void UpdateMIDISysExExceptionsView();
130 // Modifies the zoom level exceptions list to display correct chrome
131 // signin page entry. When the legacy (non-WebView-based) signin page
132 // goes away, this function can be removed.
133 void AdjustZoomLevelsListForSigninPageIfNecessary(
134 content::HostZoomMap::ZoomLevelVector* zoom_levels);
136 // Clobbers and rebuilds just the zoom levels exception table.
137 void UpdateZoomLevelsExceptionsView();
139 // Clobbers and rebuilds an exception table that's managed by the host content
140 // settings map.
141 void UpdateExceptionsViewFromHostContentSettingsMap(ContentSettingsType type);
143 // As above, but acts on the OTR table for the content setting type.
144 void UpdateExceptionsViewFromOTRHostContentSettingsMap(
145 ContentSettingsType type);
147 // Updates the radio buttons for enabling / disabling handlers.
148 void UpdateHandlersEnabledRadios();
150 // Removes one geolocation exception. |args| contains the parameters passed to
151 // RemoveException().
152 void RemoveGeolocationException(const base::ListValue* args);
154 // Removes one notification exception. |args| contains the parameters passed
155 // to RemoveException().
156 void RemoveNotificationException(const base::ListValue* args);
158 // Removes one media camera and microphone exception. |args| contains the
159 // parameters passed to RemoveException().
160 void RemoveMediaException(const base::ListValue* args);
162 // Removes one exception of |type| from the host content settings map. |args|
163 // contains the parameters passed to RemoveException().
164 void RemoveExceptionFromHostContentSettingsMap(
165 const base::ListValue* args,
166 ContentSettingsType type);
168 // Removes one zoom level exception. |args| contains the parameters passed to
169 // RemoveException().
170 void RemoveZoomLevelException(const base::ListValue* args);
172 // Callbacks used by the page ------------------------------------------------
174 // Sets the default value for a specific content type. |args| includes the
175 // content type and a string describing the new default the user has
176 // chosen.
177 void SetContentFilter(const base::ListValue* args);
179 // Removes the given row from the table. The first entry in |args| is the
180 // content type, and the rest of the arguments depend on the content type
181 // to be removed.
182 void RemoveException(const base::ListValue* args);
184 // Changes the value of an exception. Called after the user is done editing an
185 // exception.
186 void SetException(const base::ListValue* args);
188 // Called to decide whether a given pattern is valid, or if it should be
189 // rejected. Called while the user is editing an exception pattern.
190 void CheckExceptionPatternValidity(const base::ListValue* args);
192 // Utility functions ---------------------------------------------------------
194 // Applies content settings whitelists to reduce breakage / user confusion.
195 void ApplyWhitelist(ContentSettingsType content_type,
196 ContentSetting default_setting);
198 // Gets the HostContentSettingsMap for the normal profile.
199 HostContentSettingsMap* GetContentSettingsMap();
201 // Gets the HostContentSettingsMap for the incognito profile, or NULL if there
202 // is no active incognito session.
203 HostContentSettingsMap* GetOTRContentSettingsMap();
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 scoped_ptr<content::HostZoomMap::Subscription>
235 signin_host_zoom_map_subscription_;
236 ScopedObserver<HostContentSettingsMap, content_settings::Observer> observer_;
238 DISALLOW_COPY_AND_ASSIGN(ContentSettingsHandler);
241 } // namespace options
243 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_CONTENT_SETTINGS_HANDLER_H_