NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / ui / webui / options / content_settings_handler.h
blobb5453de115d34cfb0750cb047df179716d9f6fef
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/notification_observer.h"
18 #include "content/public/browser/notification_registrar.h"
20 class HostContentSettingsMap;
21 class ProtocolHandlerRegistry;
23 namespace options {
25 class ContentSettingsHandler : public OptionsPageUIHandler,
26 public content::NotificationObserver,
27 public PepperFlashSettingsManager::Client {
28 public:
29 ContentSettingsHandler();
30 virtual ~ContentSettingsHandler();
32 // OptionsPageUIHandler implementation.
33 virtual void GetLocalizedValues(
34 base::DictionaryValue* localized_strings) OVERRIDE;
35 virtual void InitializeHandler() OVERRIDE;
36 virtual void InitializePage() OVERRIDE;
37 virtual void RegisterMessages() OVERRIDE;
39 // content::NotificationObserver implementation.
40 virtual void Observe(int type,
41 const content::NotificationSource& source,
42 const content::NotificationDetails& details) OVERRIDE;
44 // PepperFlashSettingsManager::Client implementation.
45 virtual void OnGetPermissionSettingsCompleted(
46 uint32 request_id,
47 bool success,
48 PP_Flash_BrowserOperations_Permission default_permission,
49 const ppapi::FlashSiteSettings& sites) OVERRIDE;
51 // Gets a string identifier for the group name, for use in HTML.
52 static std::string ContentSettingsTypeToGroupName(ContentSettingsType type);
54 private:
55 // Used to determine whether we should show links to Flash camera and
56 // microphone settings.
57 struct MediaSettingsInfo {
58 MediaSettingsInfo();
59 ~MediaSettingsInfo();
61 // Cached Pepper Flash settings.
62 ContentSetting flash_default_setting;
63 MediaExceptions flash_exceptions;
64 bool flash_settings_initialized;
65 uint32_t last_flash_refresh_request_id;
67 // Whether the links to Flash settings pages are showed.
68 bool show_flash_default_link;
69 bool show_flash_exceptions_link;
71 // Cached Chrome media settings.
72 ContentSetting default_setting;
73 bool policy_disable_audio;
74 bool policy_disable_video;
75 bool default_setting_initialized;
76 MediaExceptions exceptions;
77 bool exceptions_initialized;
80 // Used by ShowFlashMediaLink() to specify which link to show/hide.
81 enum LinkType {
82 DEFAULT_SETTING = 0,
83 EXCEPTIONS,
86 // Functions that call into the page -----------------------------------------
88 // Updates the page with the default settings (allow, ask, block, etc.)
89 void UpdateSettingDefaultFromModel(ContentSettingsType type);
91 // Updates the media radio buttons according to the enabled split prefs.
92 void UpdateMediaSettingsView();
94 // Clobbers and rebuilds the specific content setting type exceptions table.
95 void UpdateExceptionsViewFromModel(ContentSettingsType type);
96 // Clobbers and rebuilds the specific content setting type exceptions
97 // OTR table.
98 void UpdateOTRExceptionsViewFromModel(ContentSettingsType type);
99 // Clobbers and rebuilds all the exceptions tables in the page (both normal
100 // and OTR tables).
101 void UpdateAllExceptionsViewsFromModel();
102 // As above, but only OTR tables.
103 void UpdateAllOTRExceptionsViewsFromModel();
104 // Clobbers and rebuilds just the geolocation exception table.
105 void UpdateGeolocationExceptionsView();
106 // Clobbers and rebuilds just the desktop notification exception table.
107 void UpdateNotificationExceptionsView();
108 // Clobbers and rebuilds just the Media device exception table.
109 void UpdateMediaExceptionsView();
110 // Clobbers and rebuilds just the MIDI SysEx exception table.
111 void UpdateMIDISysExExceptionsView();
112 // Clobbers and rebuilds an exception table that's managed by the host content
113 // settings map.
114 void UpdateExceptionsViewFromHostContentSettingsMap(ContentSettingsType type);
115 // As above, but acts on the OTR table for the content setting type.
116 void UpdateExceptionsViewFromOTRHostContentSettingsMap(
117 ContentSettingsType type);
118 // Updates the radio buttons for enabling / disabling handlers.
119 void UpdateHandlersEnabledRadios();
120 // Removes one geolocation exception.
121 void RemoveGeolocationException(const base::ListValue* args,
122 size_t arg_index);
123 // Removes one notification exception.
124 void RemoveNotificationException(const base::ListValue* args,
125 size_t arg_index);
126 // Removes one media camera and microphone exception.
127 void RemoveMediaException(const base::ListValue* args, size_t arg_index);
128 // Removes one exception of |type| from the host content settings map.
129 void RemoveExceptionFromHostContentSettingsMap(
130 const base::ListValue* args,
131 size_t arg_index,
132 ContentSettingsType type);
134 // Callbacks used by the page ------------------------------------------------
136 // Sets the default value for a specific content type. |args| includes the
137 // content type and a string describing the new default the user has
138 // chosen.
139 void SetContentFilter(const base::ListValue* args);
141 // Removes the given row from the table. The first entry in |args| is the
142 // content type, and the rest of the arguments depend on the content type
143 // to be removed.
144 void RemoveException(const base::ListValue* args);
146 // Changes the value of an exception. Called after the user is done editing an
147 // exception.
148 void SetException(const base::ListValue* args);
150 // Called to decide whether a given pattern is valid, or if it should be
151 // rejected. Called while the user is editing an exception pattern.
152 void CheckExceptionPatternValidity(const base::ListValue* args);
154 // Utility functions ---------------------------------------------------------
156 // Applies content settings whitelists to reduce breakage / user confusion.
157 void ApplyWhitelist(ContentSettingsType content_type,
158 ContentSetting default_setting);
160 // Gets the HostContentSettingsMap for the normal profile.
161 HostContentSettingsMap* GetContentSettingsMap();
163 // Gets the HostContentSettingsMap for the incognito profile, or NULL if there
164 // is no active incognito session.
165 HostContentSettingsMap* GetOTRContentSettingsMap();
167 // Gets the default setting in string form. If |provider_id| is not NULL, the
168 // id of the provider which provided the default setting is assigned to it.
169 std::string GetSettingDefaultFromModel(ContentSettingsType type,
170 std::string* provider_id);
172 // Gets the ProtocolHandlerRegistry for the normal profile.
173 ProtocolHandlerRegistry* GetProtocolHandlerRegistry();
175 void RefreshFlashMediaSettings();
177 // Fills in |exceptions| with Values for the given |type| from |map|.
178 void GetExceptionsFromHostContentSettingsMap(
179 const HostContentSettingsMap* map,
180 ContentSettingsType type,
181 base::ListValue* exceptions);
183 void OnPepperFlashPrefChanged();
185 void ShowFlashMediaLink(LinkType link_type, bool show);
187 void UpdateFlashMediaLinksVisibility();
189 void UpdateProtectedContentExceptionsButton();
191 // Member variables ---------------------------------------------------------
193 content::NotificationRegistrar notification_registrar_;
194 PrefChangeRegistrar pref_change_registrar_;
195 scoped_ptr<PepperFlashSettingsManager> flash_settings_manager_;
196 MediaSettingsInfo media_settings_;
198 DISALLOW_COPY_AND_ASSIGN(ContentSettingsHandler);
201 } // namespace options
203 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_CONTENT_SETTINGS_HANDLER_H_