Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / webui / options / content_settings_handler.h
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.
4
5 #ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS_CONTENT_SETTINGS_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS_CONTENT_SETTINGS_HANDLER_H_
7
8 #include <string>
9
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"
22
23 class HostContentSettingsMap;
24 class ProtocolHandlerRegistry;
25
26 namespace options {
27
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();
35
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;
42
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;
49
50   // content::NotificationObserver implementation.
51   virtual void Observe(int type,
52                        const content::NotificationSource& source,
53                        const content::NotificationDetails& details) OVERRIDE;
54
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;
61
62   // Gets a string identifier for the group name, for use in HTML.
63   static std::string ContentSettingsTypeToGroupName(ContentSettingsType type);
64
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();
71
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;
77
78     // Whether the links to Flash settings pages are showed.
79     bool show_flash_default_link;
80     bool show_flash_exceptions_link;
81
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;
89   };
90
91   // Used by ShowFlashMediaLink() to specify which link to show/hide.
92   enum LinkType {
93     DEFAULT_SETTING = 0,
94     EXCEPTIONS,
95   };
96
97   // Functions that call into the page -----------------------------------------
98
99   // Updates the page with the default settings (allow, ask, block, etc.)
100   void UpdateSettingDefaultFromModel(ContentSettingsType type);
101
102   // Updates the media radio buttons according to the enabled split prefs.
103   void UpdateMediaSettingsView();
104
105   // Clobbers and rebuilds the specific content setting type exceptions table.
106   void UpdateExceptionsViewFromModel(ContentSettingsType type);
107
108   // Clobbers and rebuilds the specific content setting type exceptions
109   // OTR table.
110   void UpdateOTRExceptionsViewFromModel(ContentSettingsType type);
111
112   // Clobbers and rebuilds all the exceptions tables in the page (both normal
113   // and OTR tables).
114   void UpdateAllExceptionsViewsFromModel();
115
116   // As above, but only OTR tables.
117   void UpdateAllOTRExceptionsViewsFromModel();
118
119   // Clobbers and rebuilds just the geolocation exception table.
120   void UpdateGeolocationExceptionsView();
121
122   // Clobbers and rebuilds just the desktop notification exception table.
123   void UpdateNotificationExceptionsView();
124
125   // Clobbers and rebuilds just the Media device exception table.
126   void UpdateMediaExceptionsView();
127
128   // Clobbers and rebuilds just the MIDI SysEx exception table.
129   void UpdateMIDISysExExceptionsView();
130
131   // Clobbers and rebuilds just the zoom levels exception table.
132   void UpdateZoomLevelsExceptionsView();
133
134   // Clobbers and rebuilds an exception table that's managed by the host content
135   // settings map.
136   void UpdateExceptionsViewFromHostContentSettingsMap(ContentSettingsType type);
137
138   // As above, but acts on the OTR table for the content setting type.
139   void UpdateExceptionsViewFromOTRHostContentSettingsMap(
140       ContentSettingsType type);
141
142   // Updates the radio buttons for enabling / disabling handlers.
143   void UpdateHandlersEnabledRadios();
144
145   // Removes one geolocation exception. |args| contains the parameters passed to
146   // RemoveException().
147   void RemoveGeolocationException(const base::ListValue* args);
148
149   // Removes one notification exception. |args| contains the parameters passed
150   // to RemoveException().
151   void RemoveNotificationException(const base::ListValue* args);
152
153   // Removes one media camera and microphone exception. |args| contains the
154   // parameters passed to RemoveException().
155   void RemoveMediaException(const base::ListValue* args);
156
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);
162
163   // Removes one zoom level exception. |args| contains the parameters passed to
164   // RemoveException().
165   void RemoveZoomLevelException(const base::ListValue* args);
166
167   // Callbacks used by the page ------------------------------------------------
168
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);
173
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);
178
179   // Changes the value of an exception. Called after the user is done editing an
180   // exception.
181   void SetException(const base::ListValue* args);
182
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);
186
187   // Utility functions ---------------------------------------------------------
188
189   // Applies content settings whitelists to reduce breakage / user confusion.
190   void ApplyWhitelist(ContentSettingsType content_type,
191                       ContentSetting default_setting);
192
193   // Gets the HostContentSettingsMap for the normal profile.
194   HostContentSettingsMap* GetContentSettingsMap();
195
196   // Gets the HostContentSettingsMap for the incognito profile, or NULL if there
197   // is no active incognito session.
198   HostContentSettingsMap* GetOTRContentSettingsMap();
199
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);
204
205   // Gets the ProtocolHandlerRegistry for the normal profile.
206   ProtocolHandlerRegistry* GetProtocolHandlerRegistry();
207
208   void RefreshFlashMediaSettings();
209
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);
215
216   void OnPepperFlashPrefChanged();
217
218   // content::HostZoomMap subscription.
219   void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change);
220
221   void ShowFlashMediaLink(LinkType link_type, bool show);
222
223   void UpdateFlashMediaLinksVisibility();
224
225   void UpdateProtectedContentExceptionsButton();
226
227   // Member variables ---------------------------------------------------------
228
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_;
235
236   DISALLOW_COPY_AND_ASSIGN(ContentSettingsHandler);
237 };
238
239 }  // namespace options
240
241 #endif  // CHROME_BROWSER_UI_WEBUI_OPTIONS_CONTENT_SETTINGS_HANDLER_H_